src/dpdk/drivers/net/bnxt/bnxt_hwrm.c
static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
				  uint32_t msg_len, bool use_kong_mb)
{
	unsigned int i;
	struct input *req = msg;
	struct output *resp = bp->hwrm_cmd_resp_addr;
	uint32_t *data = msg;
	uint8_t *bar;
	uint8_t *valid;
	uint16_t max_req_len = bp->max_req_len;
	struct hwrm_short_input short_input = { 0 };
	uint16_t bar_offset = use_kong_mb ?
		GRCPF_REG_KONG_CHANNEL_OFFSET : GRCPF_REG_CHIMP_CHANNEL_OFFSET;
	uint16_t mb_trigger_offset = use_kong_mb ?
		GRCPF_REG_KONG_COMM_TRIGGER : GRCPF_REG_CHIMP_COMM_TRIGGER;
	uint32_t timeout;

	/* Do not send HWRM commands to firmware in error state */
	if (bp->flags & BNXT_FLAG_FATAL_ERROR)
		return 0;

	timeout = bp->hwrm_cmd_timeout;

	if (bp->flags & BNXT_FLAG_SHORT_CMD ||
	    msg_len > bp->max_req_len) {
		void *short_cmd_req = bp->hwrm_short_cmd_req_addr;

		memset(short_cmd_req, 0, bp->hwrm_max_ext_req_len);
		memcpy(short_cmd_req, req, msg_len);

		short_input.req_type = rte_cpu_to_le_16(req->req_type);
		short_input.signature = rte_cpu_to_le_16(
					HWRM_SHORT_INPUT_SIGNATURE_SHORT_CMD);
		short_input.size = rte_cpu_to_le_16(msg_len);
		short_input.req_addr =
			rte_cpu_to_le_64(bp->hwrm_short_cmd_req_dma_addr);

		data = (uint32_t *)&short_input;
		msg_len = sizeof(short_input);

		max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
	}

	/* Write request msg to hwrm channel */
	for (i = 0; i < msg_len; i += 4) {
		bar = (uint8_t *)bp->bar0 + bar_offset + i;
		rte_write32(*data, bar);
		data++;
	}

	/* Zero the rest of the request space */
	for (; i < max_req_len; i += 4) {
		bar = (uint8_t *)bp->bar0 + bar_offset + i;
		rte_write32(0, bar);
	}

	/* Ring channel doorbell */
	bar = (uint8_t *)bp->bar0 + mb_trigger_offset;
	rte_write32(1, bar);
	/*
	 * Make sure the channel doorbell ring command complete before
	 * reading the response to avoid getting stale or invalid
	 * responses.
	 */
	rte_io_mb();

	/* Poll for the valid bit */
	for (i = 0; i < timeout; i++) {
		/* Sanity check on the resp->resp_len */
		rte_io_rmb();
		if (resp->resp_len && resp->resp_len <= bp->max_resp_len) {
			/* Last byte of resp contains the valid key */
			valid = (uint8_t *)resp + resp->resp_len - 1;
			if (*valid == HWRM_RESP_VALID_KEY)
				break;
		}
		rte_delay_us(1);
	}

	if (i >= timeout) {
		/* Suppress VER_GET timeout messages during reset recovery */
		if (bp->flags & BNXT_FLAG_FW_RESET &&
		    rte_cpu_to_le_16(req->req_type) == HWRM_VER_GET)
			return -ETIMEDOUT;

		PMD_DRV_LOG(ERR,
			    "Error(timeout) sending msg 0x%04x, seq_id %d\n",
			    req->req_type, req->seq_id);
		return -ETIMEDOUT;
	}
	return 0;
}
/*
 * HWRM Functions (sent to HWRM)
 * These are named bnxt_hwrm_*() and return 0 on success or -110 if the
 * HWRM command times out, or a negative error code if the HWRM
 * command was failed by the FW.
 */
HWRM Functions (sent to HWRM)
These are named bnxt_hwrm_*() and return 0 on success or -110 if the
HWRM command times out, or a negative error code if the HWRM
command was failed by the FW.
HWRM Functions ( sent to HWRM ) These are named bnxt_hwrm_ * () and return 0 on success or - 110 if the HWRM command times out or a negative error code if the HWRM command was failed by the FW .
static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
				  uint32_t msg_len, bool use_kong_mb)
{
	unsigned int i;
	struct input *req = msg;
	struct output *resp = bp->hwrm_cmd_resp_addr;
	uint32_t *data = msg;
	uint8_t *bar;
	uint8_t *valid;
	uint16_t max_req_len = bp->max_req_len;
	struct hwrm_short_input short_input = { 0 };
	uint16_t bar_offset = use_kong_mb ?
		GRCPF_REG_KONG_CHANNEL_OFFSET : GRCPF_REG_CHIMP_CHANNEL_OFFSET;
	uint16_t mb_trigger_offset = use_kong_mb ?
		GRCPF_REG_KONG_COMM_TRIGGER : GRCPF_REG_CHIMP_COMM_TRIGGER;
	uint32_t timeout;
	if (bp->flags & BNXT_FLAG_FATAL_ERROR)
		return 0;
	timeout = bp->hwrm_cmd_timeout;
	if (bp->flags & BNXT_FLAG_SHORT_CMD ||
	    msg_len > bp->max_req_len) {
		void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
		memset(short_cmd_req, 0, bp->hwrm_max_ext_req_len);
		memcpy(short_cmd_req, req, msg_len);
		short_input.req_type = rte_cpu_to_le_16(req->req_type);
		short_input.signature = rte_cpu_to_le_16(
					HWRM_SHORT_INPUT_SIGNATURE_SHORT_CMD);
		short_input.size = rte_cpu_to_le_16(msg_len);
		short_input.req_addr =
			rte_cpu_to_le_64(bp->hwrm_short_cmd_req_dma_addr);
		data = (uint32_t *)&short_input;
		msg_len = sizeof(short_input);
		max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
	}
	for (i = 0; i < msg_len; i += 4) {
		bar = (uint8_t *)bp->bar0 + bar_offset + i;
		rte_write32(*data, bar);
		data++;
	}
	for (; i < max_req_len; i += 4) {
		bar = (uint8_t *)bp->bar0 + bar_offset + i;
		rte_write32(0, bar);
	}
	bar = (uint8_t *)bp->bar0 + mb_trigger_offset;
	rte_write32(1, bar);
	rte_io_mb();
	for (i = 0; i < timeout; i++) {
		rte_io_rmb();
		if (resp->resp_len && resp->resp_len <= bp->max_resp_len) {
			valid = (uint8_t *)resp + resp->resp_len - 1;
			if (*valid == HWRM_RESP_VALID_KEY)
				break;
		}
		rte_delay_us(1);
	}
	if (i >= timeout) {
		if (bp->flags & BNXT_FLAG_FW_RESET &&
		    rte_cpu_to_le_16(req->req_type) == HWRM_VER_GET)
			return -ETIMEDOUT;
		PMD_DRV_LOG(ERR,
			    "Error(timeout) sending msg 0x%04x, seq_id %d\n",
			    req->req_type, req->seq_id);
		return -ETIMEDOUT;
	}
	return 0;
}
static int bnxt_hwrm_send_message ( struct bnxt * bp , void * msg , uint32_t msg_len , bool use_kong_mb ) { unsigned int i ; struct input * req = msg ; struct output * resp = bp -> hwrm_cmd_resp_addr ; uint32_t * data = msg ; uint8_t * bar ; uint8_t * valid ; uint16_t max_req_len = bp -> max_req_len ; struct hwrm_short_input short_input = { 0 } ; uint16_t bar_offset = use_kong_mb ? GRCPF_REG_KONG_CHANNEL_OFFSET : GRCPF_REG_CHIMP_CHANNEL_OFFSET ; uint16_t mb_trigger_offset = use_kong_mb ? GRCPF_REG_KONG_COMM_TRIGGER : GRCPF_REG_CHIMP_COMM_TRIGGER ; uint32_t timeout ; if ( bp -> flags & BNXT_FLAG_FATAL_ERROR ) return 0 ; timeout = bp -> hwrm_cmd_timeout ; if ( bp -> flags & BNXT_FLAG_SHORT_CMD || msg_len > bp -> max_req_len ) { void * short_cmd_req = bp -> hwrm_short_cmd_req_addr ; memset ( short_cmd_req , 0 , bp -> hwrm_max_ext_req_len ) ; memcpy ( short_cmd_req , req , msg_len ) ; short_input . req_type = rte_cpu_to_le_16 ( req -> req_type ) ; short_input . signature = rte_cpu_to_le_16 ( HWRM_SHORT_INPUT_SIGNATURE_SHORT_CMD ) ; short_input . size = rte_cpu_to_le_16 ( msg_len ) ; short_input . req_addr = rte_cpu_to_le_64 ( bp -> hwrm_short_cmd_req_dma_addr ) ; data = ( uint32_t * ) & short_input ; msg_len = sizeof ( short_input ) ; max_req_len = BNXT_HWRM_SHORT_REQ_LEN ; } for ( i = 0 ; i < msg_len ; i += 4 ) { bar = ( uint8_t * ) bp -> bar0 + bar_offset + i ; rte_write32 ( * data , bar ) ; data ++ ; } for ( ; i < max_req_len ; i += 4 ) { bar = ( uint8_t * ) bp -> bar0 + bar_offset + i ; rte_write32 ( 0 , bar ) ; } bar = ( uint8_t * ) bp -> bar0 + mb_trigger_offset ; rte_write32 ( 1 , bar ) ; rte_io_mb ( ) ; for ( i = 0 ; i < timeout ; i ++ ) { rte_io_rmb ( ) ; if ( resp -> resp_len && resp -> resp_len <= bp -> max_resp_len ) { valid = ( uint8_t * ) resp + resp -> resp_len - 1 ; if ( * valid == HWRM_RESP_VALID_KEY ) break ; } rte_delay_us ( 1 ) ; } if ( i >= timeout ) { if ( bp -> flags & BNXT_FLAG_FW_RESET && rte_cpu_to_le_16 ( req -> req_type ) == HWRM_VER_GET ) return - ETIMEDOUT ; PMD_DRV_LOG ( ERR , " \n " , req -> req_type , req -> seq_id ) ; return - ETIMEDOUT ; } return 0 ; }
HWRM Functions (sent to HWRM)
 These are named bnxt_hwrm_*() and return 0 on success or -110 if the
 HWRM command times out, or a negative error code if the HWRM
 command was failed by the FW.
HWRM Functions ( sent to HWRM ) These are named bnxt_hwrm_ * () and return 0 on success or - 110 if the HWRM command times out or a negative error code if the HWRM command was failed by the FW .
/* Do not send HWRM commands to firmware in error state */ /* Write request msg to hwrm channel */ /* Zero the rest of the request space */ /* Ring channel doorbell */ /*
	 * Make sure the channel doorbell ring command complete before
	 * reading the response to avoid getting stale or invalid
	 * responses.
	 */ /* Poll for the valid bit */ /* Sanity check on the resp->resp_len */ /* Last byte of resp contains the valid key */ /* Suppress VER_GET timeout messages during reset recovery */