From: Jason Gunthorpe <jgg@xxxxxxxxxxxx> This is done with a sed script. The glibc version automatically optimally handles constant values, so no need for the special constant version. Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx> --- include/ibdiag_sa.h | 7 +++++-- src/ibsendtrap.c | 44 ++++++++++++++++++++++---------------------- src/saquery.c | 8 ++++---- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/include/ibdiag_sa.h b/include/ibdiag_sa.h index 368a8294dc82a7..886e963cf7ef36 100644 --- a/include/ibdiag_sa.h +++ b/include/ibdiag_sa.h @@ -70,10 +70,13 @@ void *sa_get_query_rec(void *mad, unsigned i); void sa_report_err(int status); /* Macros for setting query values and ComponentMasks */ -#define cl_hton8(x) (x) +static inline uint8_t htobe8(uint8_t val) +{ + return val; +} #define CHECK_AND_SET_VAL(val, size, comp_with, target, name, mask) \ if ((int##size##_t) val != (int##size##_t) comp_with) { \ - target = cl_hton##size((uint##size##_t) val); \ + target = htobe##size((uint##size##_t) val); \ comp_mask |= IB_##name##_COMPMASK_##mask; \ } diff --git a/src/ibsendtrap.c b/src/ibsendtrap.c index 4459b1658417bd..b6751a957c9183 100644 --- a/src/ibsendtrap.c +++ b/src/ibsendtrap.c @@ -77,20 +77,20 @@ static uint32_t get_cap_mask(ib_portid_t * port) static void build_trap145(ib_mad_notice_attr_t * n, ib_portid_t * port) { n->generic_type = 0x80 | IB_NOTICE_TYPE_INFO; - n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port)); - n->g_or_v.generic.trap_num = cl_hton16(145); - n->issuer_lid = cl_hton16((uint16_t) port->lid); - n->data_details.ntc_145.new_sys_guid = cl_hton64(0x1234567812345678); + n->g_or_v.generic.prod_type_lsb = htobe16(get_node_type(port)); + n->g_or_v.generic.trap_num = htobe16(145); + n->issuer_lid = htobe16((uint16_t) port->lid); + n->data_details.ntc_145.new_sys_guid = htobe64(0x1234567812345678); } static void build_trap144_local(ib_mad_notice_attr_t * n, ib_portid_t * port) { n->generic_type = 0x80 | IB_NOTICE_TYPE_INFO; - n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port)); - n->g_or_v.generic.trap_num = cl_hton16(144); - n->issuer_lid = cl_hton16((uint16_t) port->lid); + n->g_or_v.generic.prod_type_lsb = htobe16(get_node_type(port)); + n->g_or_v.generic.trap_num = htobe16(144); + n->issuer_lid = htobe16((uint16_t) port->lid); n->data_details.ntc_144.lid = n->issuer_lid; - n->data_details.ntc_144.new_cap_mask = cl_hton32(get_cap_mask(port)); + n->data_details.ntc_144.new_cap_mask = htobe32(get_cap_mask(port)); n->data_details.ntc_144.local_changes = TRAP_144_MASK_OTHER_LOCAL_CHANGES; } @@ -113,9 +113,9 @@ static void build_trap144_linkspeed(ib_mad_notice_attr_t * n, static void build_trap129(ib_mad_notice_attr_t * n, ib_portid_t * port) { n->generic_type = 0x80 | IB_NOTICE_TYPE_URGENT; - n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port)); - n->g_or_v.generic.trap_num = cl_hton16(129); - n->issuer_lid = cl_hton16((uint16_t) port->lid); + n->g_or_v.generic.prod_type_lsb = htobe16(get_node_type(port)); + n->g_or_v.generic.trap_num = htobe16(129); + n->issuer_lid = htobe16((uint16_t) port->lid); n->data_details.ntc_129_131.lid = n->issuer_lid; n->data_details.ntc_129_131.pad = 0; n->data_details.ntc_129_131.port_num = (uint8_t) error_port; @@ -124,9 +124,9 @@ static void build_trap129(ib_mad_notice_attr_t * n, ib_portid_t * port) static void build_trap256_local(ib_mad_notice_attr_t * n, ib_portid_t * port) { n->generic_type = 0x80 | IB_NOTICE_TYPE_SECURITY; - n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port)); - n->g_or_v.generic.trap_num = cl_hton16(256); - n->issuer_lid = cl_hton16((uint16_t) port->lid); + n->g_or_v.generic.prod_type_lsb = htobe16(get_node_type(port)); + n->g_or_v.generic.trap_num = htobe16(256); + n->issuer_lid = htobe16((uint16_t) port->lid); n->data_details.ntc_256.lid = n->issuer_lid; n->data_details.ntc_256.dr_slid = 0xffff; n->data_details.ntc_256.method = 1; @@ -155,14 +155,14 @@ static void build_trap257_258(ib_mad_notice_attr_t * n, ib_portid_t * port, uint16_t trap_num) { n->generic_type = 0x80 | IB_NOTICE_TYPE_SECURITY; - n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port)); - n->g_or_v.generic.trap_num = cl_hton16(trap_num); - n->issuer_lid = cl_hton16((uint16_t) port->lid); - n->data_details.ntc_257_258.lid1 = cl_hton16(1); - n->data_details.ntc_257_258.lid2 = cl_hton16(2); - n->data_details.ntc_257_258.key = cl_hton32(0x12345678); - n->data_details.ntc_257_258.qp1 = cl_hton32(0x010101); - n->data_details.ntc_257_258.qp2 = cl_hton32(0x020202); + n->g_or_v.generic.prod_type_lsb = htobe16(get_node_type(port)); + n->g_or_v.generic.trap_num = htobe16(trap_num); + n->issuer_lid = htobe16((uint16_t) port->lid); + n->data_details.ntc_257_258.lid1 = htobe16(1); + n->data_details.ntc_257_258.lid2 = htobe16(2); + n->data_details.ntc_257_258.key = htobe32(0x12345678); + n->data_details.ntc_257_258.qp1 = htobe32(0x010101); + n->data_details.ntc_257_258.qp2 = htobe32(0x020202); n->data_details.ntc_257_258.gid1.unicast.prefix = be64toh(0xf8c0000000000001); n->data_details.ntc_257_258.gid1.unicast.interface_id = be64toh(0x1111222233334444); n->data_details.ntc_257_258.gid2.unicast.prefix = be64toh(0xf8c0000000000001); diff --git a/src/saquery.c b/src/saquery.c index 9ecd5f5332b263..40492a619c73f4 100644 --- a/src/saquery.c +++ b/src/saquery.c @@ -1058,7 +1058,7 @@ static int query_path_records(const struct query_cmd *q, struct sa_handle * h, CHECK_AND_SET_VAL(p->dlid, 16, 0, pr.dlid, PR, DLID); CHECK_AND_SET_VAL(p->hop_limit, 32, -1, pr.hop_flow_raw, PR, HOPLIMIT); CHECK_AND_SET_VAL(p->flow_label, 8, 0, flow, PR, FLOWLABEL); - pr.hop_flow_raw |= cl_hton32(flow << 8); + pr.hop_flow_raw |= htobe32(flow << 8); CHECK_AND_SET_VAL(p->tclass, 8, 0, pr.tclass, PR, TCLASS); CHECK_AND_SET_VAL(p->reversible, 8, -1, reversible, PR, REVERSIBLE); CHECK_AND_SET_VAL(p->numb_path, 8, -1, pr.num_path, PR, NUMBPATH); @@ -1066,7 +1066,7 @@ static int query_path_records(const struct query_cmd *q, struct sa_handle * h, CHECK_AND_SET_VAL(p->pkey, 16, 0, pr.pkey, PR, PKEY); CHECK_AND_SET_VAL(p->sl, 16, -1, pr.qos_class_sl, PR, SL); CHECK_AND_SET_VAL((p->qos_class << 4), 16, -1, qos_class, PR, QOS_CLASS); - pr.qos_class_sl = (pr.qos_class_sl & CL_HTON16(IB_PATH_REC_SL_MASK)) | + pr.qos_class_sl = (pr.qos_class_sl & htobe16(IB_PATH_REC_SL_MASK)) | qos_class; CHECK_AND_SET_VAL_AND_SEL(p->mtu, pr.mtu, PR, MTU, SELEC); CHECK_AND_SET_VAL_AND_SEL(p->rate, pr.rate, PR, RATE, SELEC); @@ -1418,9 +1418,9 @@ static int query_mft_records(const struct query_cmd *q, struct sa_handle * h, memset(&mftr, 0, sizeof(mftr)); CHECK_AND_SET_VAL(lid, 16, 0, mftr.lid, MFTR, LID); CHECK_AND_SET_VAL(block, 16, -1, mftr.position_block_num, MFTR, BLOCK); - mftr.position_block_num &= cl_hton16(IB_MCAST_BLOCK_ID_MASK_HO); + mftr.position_block_num &= htobe16(IB_MCAST_BLOCK_ID_MASK_HO); CHECK_AND_SET_VAL(position, 8, -1, pos, MFTR, POSITION); - mftr.position_block_num |= cl_hton16(pos << 12); + mftr.position_block_num |= htobe16(pos << 12); return get_and_dump_any_records(h, IB_SA_ATTR_MFTRECORD, 0, comp_mask, &mftr, sizeof(mftr), dump_one_mft_record, p); -- 2.21.0