astlpc: Use enums instead of hardcoded numbers
This makes it slightly easier to read the code.
Change-Id: Iab8df93fc330fda4b89d2a77922ca73f7a7ad1a1
Signed-off-by: Rashmica Gupta <rashmica@linux.ibm.com>
diff --git a/astlpc.c b/astlpc.c
index 0281099..6842ae1 100644
--- a/astlpc.c
+++ b/astlpc.c
@@ -41,6 +41,13 @@
#endif
+enum mctp_astlpc_cmd {
+ cmd_initialise = 0x00,
+ cmd_tx_begin = 0x01,
+ cmd_rx_complete = 0x02,
+ cmd_dummy_value = 0xff,
+};
+
enum mctp_astlpc_buffer_state {
/*
* Prior to "Channel Ready" we mark the buffers as "idle" to catch illegal accesses. In this
@@ -353,7 +360,7 @@
* So, write a dummy value of 0xff to ODR, which will ensure that an
* interrupt is triggered, and can be ignored by the host.
*/
- data = 0xff;
+ data = cmd_dummy_value;
rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, status);
if (rc) {
@@ -784,7 +791,7 @@
}
static int mctp_astlpc_kcs_send(struct mctp_binding_astlpc *astlpc,
- uint8_t data)
+ enum mctp_astlpc_cmd data)
{
uint8_t status;
int rc;
@@ -842,7 +849,7 @@
astlpc->layout.tx.state = buffer_state_prepared;
- rc = mctp_astlpc_kcs_send(astlpc, 0x1);
+ rc = mctp_astlpc_kcs_send(astlpc, cmd_tx_begin);
if (!rc)
astlpc->layout.tx.state = buffer_state_released;
@@ -1016,7 +1023,7 @@
/* Inform the other side of the MCTP interface that we have read
* the packet off the bus before handling the contents of the packet.
*/
- if (!mctp_astlpc_kcs_send(astlpc, 0x2))
+ if (!mctp_astlpc_kcs_send(astlpc, cmd_rx_complete))
astlpc->layout.rx.state = buffer_state_released;
hdr = mctp_pktbuf_hdr(pkt);
@@ -1141,11 +1148,11 @@
int rc;
if (astlpc->layout.rx.state == buffer_state_prepared)
- if (!mctp_astlpc_kcs_send(astlpc, 0x2))
+ if (!mctp_astlpc_kcs_send(astlpc, cmd_rx_complete))
astlpc->layout.rx.state = buffer_state_released;
if (astlpc->layout.tx.state == buffer_state_prepared)
- if (!mctp_astlpc_kcs_send(astlpc, 0x1))
+ if (!mctp_astlpc_kcs_send(astlpc, cmd_tx_begin))
astlpc->layout.tx.state = buffer_state_released;
rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, &status);
@@ -1167,17 +1174,18 @@
astlpc_prdebug(astlpc, "%s: data: 0x%hhx", __func__, data);
- if (!astlpc->proto->version && !(data == 0x0 || data == 0xff)) {
+ if (!astlpc->proto->version &&
+ !(data == cmd_initialise || data == cmd_dummy_value)) {
astlpc_prwarn(astlpc, "Invalid message for binding state: 0x%x",
data);
return 0;
}
switch (data) {
- case 0x0:
+ case cmd_initialise:
mctp_astlpc_init_channel(astlpc);
break;
- case 0x1:
+ case cmd_tx_begin:
if (astlpc->layout.rx.state != buffer_state_released) {
astlpc_prerr(
astlpc,
@@ -1187,7 +1195,7 @@
}
mctp_astlpc_rx_start(astlpc);
break;
- case 0x2:
+ case cmd_rx_complete:
if (astlpc->layout.tx.state != buffer_state_released) {
astlpc_prerr(
astlpc,
@@ -1197,7 +1205,7 @@
}
mctp_astlpc_tx_complete(astlpc);
break;
- case 0xff:
+ case cmd_dummy_value:
/* No responsibilities for the BMC on 0xff */
if (astlpc->mode == MCTP_BINDING_ASTLPC_MODE_HOST) {
rc = mctp_astlpc_update_channel(astlpc, status);
@@ -1211,7 +1219,7 @@
/* Handle silent loss of bmc-ready */
if (astlpc->mode == MCTP_BINDING_ASTLPC_MODE_HOST) {
- if (!(status & KCS_STATUS_BMC_READY && data == 0xff))
+ if (!(status & KCS_STATUS_BMC_READY && data == cmd_dummy_value))
return mctp_astlpc_update_channel(astlpc, status);
}