Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | <:copyright-BRCM:2016:DUAL/GPL:standard |
| 3 | |
| 4 | Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Unless you and Broadcom execute a separate written software license |
| 8 | agreement governing use of this software, this software is licensed |
| 9 | to you under the terms of the GNU General Public License version 2 |
| 10 | (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 11 | with the following added to such license: |
| 12 | |
| 13 | As a special exception, the copyright holders of this software give |
| 14 | you permission to link this software with independent modules, and |
| 15 | to copy and distribute the resulting executable under terms of your |
| 16 | choice, provided that you also meet, for each linked independent |
| 17 | module, the terms and conditions of the license of that module. |
| 18 | An independent module is a module which is not derived from this |
| 19 | software. The special exception does not apply to any modifications |
| 20 | of the software. |
| 21 | |
| 22 | Not withstanding the above, under no circumstances may you combine |
| 23 | this software in any way with any other Broadcom software provided |
| 24 | under a license other than the GPL, without Broadcom's express prior |
| 25 | written consent. |
| 26 | |
| 27 | :> |
| 28 | */ |
| 29 | |
| 30 | #ifndef BCMTR_HEADER_H_ |
| 31 | #define BCMTR_HEADER_H_ |
| 32 | |
| 33 | #include <bcmolt_buf.h> |
| 34 | #include <bcmolt_msg_pack.h> |
| 35 | |
| 36 | /** Endianess of numbers written to the transport buffer. |
| 37 | * Currently bcmolt_buf service doesn't support setting |
| 38 | * endianness dynamically. Transport buffer direction must be the same |
| 39 | * as selected at compile time in bcmolt_buf.h |
| 40 | */ |
| 41 | #define BCMTR_BUF_ENDIAN BCMOLT_BUF_ENDIAN_FIXED |
| 42 | |
| 43 | #define BCMTR_ENDIAN_CPU_TO_BUF_U32(n) BCMOLT_BUF_ENDIAN_CPU_TO_BUF(U32, n) |
| 44 | #define BCMTR_ENDIAN_BUF_TO_CPU_U32(n) BCMOLT_BUF_ENDIAN_BUF_TO_CPU(U32, n) |
| 45 | |
| 46 | /** Transport header. |
| 47 | * Inserted in each packet transmitted on the line |
| 48 | */ |
| 49 | typedef struct bcmtr_hdr |
| 50 | { |
| 51 | bcmolt_msg_dir dir; /**< Message direction: request/response */ |
| 52 | bcmos_bool more_fragments; /**< TRUE=more fragments to follow */ |
| 53 | bcmos_bool auto_proxy_reg; /**< TRUE=message is auto / proxy registration */ |
| 54 | bcmos_bool auto_proxy_unreg;/**< TRUE=message is auto / proxy un-registration */ |
| 55 | uint8_t instance; /**< Message instance */ |
| 56 | bcmolt_group_id msg_id; /**< Message id: object+group+subgroup */ |
| 57 | uint16_t corr_tag; /**< correlation tag */ |
| 58 | uint16_t frag_number; /**< fragment number */ |
| 59 | } bcmtr_hdr; |
| 60 | |
| 61 | #define BCMTR_HDR_SIZE 8 |
| 62 | |
| 63 | /* Shifts and widths of transport header fields */ |
| 64 | #define BCMTR_HDR_DIR_S 31 |
| 65 | #define BCMTR_HDR_DIR_W 1 |
| 66 | #define BCMTR_HDR_REG_S 26 |
| 67 | #define BCMTR_HDR_REG_W 1 |
| 68 | #define BCMTR_HDR_UNREG_S 25 |
| 69 | #define BCMTR_HDR_UNREG_W 1 |
| 70 | #define BCMTR_HDR_MORE_FRAGS_S 24 |
| 71 | #define BCMTR_HDR_MORE_FRAGS_W 1 |
| 72 | #define BCMTR_HDR_INSTANCE_S 16 |
| 73 | #define BCMTR_HDR_INSTANCE_W 8 |
| 74 | #define BCMTR_HDR_MSG_ID_S 0 |
| 75 | #define BCMTR_HDR_MSG_ID_W 16 |
| 76 | #define BCMTR_HDR_CORR_TAG_S 16 |
| 77 | #define BCMTR_HDR_CORR_TAG_W 16 |
| 78 | #define BCMTR_HDR_FRAG_S 0 |
| 79 | #define BCMTR_HDR_FRAG_W 16 |
| 80 | |
| 81 | /* Pack transport header |
| 82 | * |
| 83 | * \param[in] hdr Unpacked transport header |
| 84 | * \param[out] packed_hdr Packed header |
| 85 | */ |
| 86 | static inline void bcmtr_header_pack(const bcmtr_hdr *hdr, uint8_t *packed_hdr) |
| 87 | { |
| 88 | uint32_t w[2]; |
| 89 | |
| 90 | w[0] = (hdr->dir << BCMTR_HDR_DIR_S) | |
| 91 | (hdr->more_fragments << BCMTR_HDR_MORE_FRAGS_S) | |
| 92 | (hdr->instance << BCMTR_HDR_INSTANCE_S) | |
| 93 | (hdr->auto_proxy_reg << BCMTR_HDR_REG_S) | |
| 94 | (hdr->auto_proxy_unreg << BCMTR_HDR_UNREG_S) | |
| 95 | hdr->msg_id; |
| 96 | w[1] = (hdr->corr_tag << BCMTR_HDR_CORR_TAG_S) | hdr->frag_number; |
| 97 | w[0] = BCMTR_ENDIAN_CPU_TO_BUF_U32(w[0]); |
| 98 | w[1] = BCMTR_ENDIAN_CPU_TO_BUF_U32(w[1]); |
| 99 | memcpy(packed_hdr, w, BCMTR_HDR_SIZE); |
| 100 | } |
| 101 | |
| 102 | /* Unpack transport header |
| 103 | * |
| 104 | * \param[in] packed_hdr Packed header |
| 105 | * \param[out] hdr Unpacked transport header |
| 106 | * Buffer current pointer is incremented by the header side. |
| 107 | */ |
| 108 | static inline void bcmtr_header_unpack(const uint8_t *packed_hdr, bcmtr_hdr *hdr) |
| 109 | { |
| 110 | uint32_t w[2]; |
| 111 | memcpy(w, packed_hdr, BCMTR_HDR_SIZE); |
| 112 | w[0] = BCMTR_ENDIAN_BUF_TO_CPU_U32(w[0]); |
| 113 | w[1] = BCMTR_ENDIAN_BUF_TO_CPU_U32(w[1]); |
| 114 | hdr->dir = BCM_FIELD_GET(w[0], BCMTR_HDR_DIR); |
| 115 | hdr->more_fragments = BCM_FIELD_GET(w[0], BCMTR_HDR_MORE_FRAGS); |
| 116 | hdr->instance = BCM_FIELD_GET(w[0], BCMTR_HDR_INSTANCE); |
| 117 | hdr->msg_id = BCM_FIELD_GET(w[0], BCMTR_HDR_MSG_ID); |
| 118 | hdr->auto_proxy_reg = BCM_FIELD_GET(w[0], BCMTR_HDR_REG); |
| 119 | hdr->auto_proxy_unreg = BCM_FIELD_GET(w[0], BCMTR_HDR_UNREG); |
| 120 | hdr->corr_tag = BCM_FIELD_GET(w[1], BCMTR_HDR_CORR_TAG); |
| 121 | hdr->frag_number = BCM_FIELD_GET(w[1], BCMTR_HDR_FRAG); |
| 122 | } |
| 123 | |
| 124 | /* Fill transport header |
| 125 | */ |
| 126 | static inline bcmos_errno bcmtr_header_fill(const bcmolt_msg *msg, bcmtr_hdr *hdr) |
| 127 | { |
| 128 | bcmos_errno err; |
| 129 | |
| 130 | hdr->dir = msg->dir; |
| 131 | hdr->more_fragments = BCMOS_FALSE; |
| 132 | err = bcmolt_group_id_combine(msg->obj_type, msg->group, msg->subgroup, &hdr->msg_id); |
| 133 | if (err) |
| 134 | return err; |
| 135 | hdr->instance = bcmolt_msg_instance(msg); |
| 136 | hdr->corr_tag = msg->corr_tag; |
| 137 | hdr->frag_number = 0; |
| 138 | return BCM_ERR_OK; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | #endif /* BCMTR_HEADER_H_ */ |