#define HCLGEVF_MBX_MATCH_ID_START 1 staticvoid hclgevf_reset_mbx_resp_status(struct hclgevf_dev *hdev)
{ /* this function should be called with mbx_resp.mbx_mutex held * to protect the received_response from race condition
*/
hdev->mbx_resp.received_resp = false;
hdev->mbx_resp.origin_mbx_msg = 0;
hdev->mbx_resp.resp_status = 0;
hdev->mbx_resp.match_id++; /* Update match_id and ensure the value of match_id is not zero */ if (hdev->mbx_resp.match_id == 0)
hdev->mbx_resp.match_id = HCLGEVF_MBX_MATCH_ID_START;
memset(hdev->mbx_resp.additional_info, 0, HCLGE_MBX_MAX_RESP_DATA_SIZE);
}
/* hclgevf_get_mbx_resp: used to get a response from PF after VF sends a mailbox * message to PF. * @hdev: pointer to struct hclgevf_dev * @code0: the message opcode VF send to PF. * @code1: the message sub-opcode VF send to PF. * @resp_data: pointer to store response data from PF to VF. * @resp_len: the length of resp_data from PF to VF.
*/ staticint hclgevf_get_mbx_resp(struct hclgevf_dev *hdev, u16 code0, u16 code1,
u8 *resp_data, u16 resp_len)
{ #define HCLGEVF_MAX_TRY_TIMES 500 #define HCLGEVF_SLEEP_USECOND 1000 struct hclgevf_mbx_resp_status *mbx_resp;
u16 r_code0, r_code1; int i = 0;
while ((!hdev->mbx_resp.received_resp) && (i < HCLGEVF_MAX_TRY_TIMES)) { if (test_bit(HCLGE_COMM_STATE_CMD_DISABLE,
&hdev->hw.hw.comm_state)) return -EIO;
/* ensure additional_info will be seen after received_resp */
smp_rmb();
if (i >= HCLGEVF_MAX_TRY_TIMES) {
dev_err(&hdev->pdev->dev, "VF could not get mbx(%u,%u) resp(=%d) from PF in %d tries\n",
code0, code1, hdev->mbx_resp.received_resp, i); return -EIO;
}
if (mbx_resp->resp_status) return mbx_resp->resp_status;
if (resp_data)
memcpy(resp_data, &mbx_resp->additional_info[0], resp_len);
hclgevf_reset_mbx_resp_status(hdev);
if (!(r_code0 == code0 && r_code1 == code1 && !mbx_resp->resp_status)) {
dev_err(&hdev->pdev->dev, "VF could not match resp code(code0=%u,code1=%u), %d\n",
code0, code1, mbx_resp->resp_status);
dev_err(&hdev->pdev->dev, "VF could not match resp r_code(r_code0=%u,r_code1=%u)\n",
r_code0, r_code1); return -EIO;
}
/* ensure additional_info will be seen before setting received_resp */
smp_wmb();
if (match_id) { /* If match_id is not zero, it means PF support match_id. * if the match_id is right, VF get the right response, or * ignore the response. and driver will clear hdev->mbx_resp * when send next message which need response.
*/ if (match_id == resp->match_id)
resp->received_resp = true;
} else {
resp->received_resp = true;
}
}
staticvoid hclgevf_handle_mbx_msg(struct hclgevf_dev *hdev, struct hclge_mbx_pf_to_vf_cmd *req)
{ /* we will drop the async msg if we find ARQ as full * and continue with next message
*/ if (atomic_read(&hdev->arq.count) >=
HCLGE_MBX_MAX_ARQ_MSG_NUM) {
dev_warn(&hdev->pdev->dev, "Async Q full, dropping msg(%u)\n",
le16_to_cpu(req->msg.code)); return;
}
/* tail the async message in arq */
memcpy(hdev->arq.msg_q[hdev->arq.tail], &req->msg,
HCLGE_MBX_MAX_ARQ_MSG_SIZE * sizeof(u16));
hclge_mbx_tail_ptr_move_arq(hdev->arq);
atomic_inc(&hdev->arq.count);
while (!hclgevf_cmd_crq_empty(&hdev->hw)) { if (test_bit(HCLGE_COMM_STATE_CMD_DISABLE,
&hdev->hw.hw.comm_state)) {
dev_info(&hdev->pdev->dev, "vf crq need init\n"); return;
}
/* synchronous messages are time critical and need preferential * treatment. Therefore, we need to acknowledge all the sync * responses as quickly as possible so that waiting tasks do not * timeout and simultaneously queue the async messages for later * prcessing in context of mailbox task i.e. the slow path.
*/ switch (code) { case HCLGE_MBX_PF_VF_RESP:
hclgevf_handle_mbx_response(hdev, req); break; case HCLGE_MBX_LINK_STAT_CHANGE: case HCLGE_MBX_ASSERTING_RESET: case HCLGE_MBX_LINK_STAT_MODE: case HCLGE_MBX_PUSH_VLAN_INFO: case HCLGE_MBX_PUSH_PROMISC_INFO:
hclgevf_handle_mbx_msg(hdev, req); break; default:
dev_err(&hdev->pdev->dev, "VF received unsupported(%u) mbx msg from PF\n",
code); break;
}
crq->desc[crq->next_to_use].flag = 0;
hclge_mbx_ring_ptr_move_crq(crq);
}
/* Write back CMDQ_RQ header pointer, M7 need this pointer */
hclgevf_write_dev(&hdev->hw, HCLGE_COMM_NIC_CRQ_HEAD_REG,
crq->next_to_use);
}
staticvoid hclgevf_parse_promisc_info(struct hclgevf_dev *hdev,
u16 promisc_info)
{ if (!promisc_info)
dev_info(&hdev->pdev->dev, "Promisc mode is closed by host for being untrusted.\n");
}
/* process all the async queue messages */ while (tail != hdev->arq.head) { if (test_bit(HCLGE_COMM_STATE_CMD_DISABLE,
&hdev->hw.hw.comm_state)) {
dev_info(&hdev->pdev->dev, "vf crq need init in async\n"); return;
}
/* update upper layer with new link link status */
hclgevf_update_speed_duplex(hdev, speed, duplex);
hclgevf_update_link_status(hdev, link_status);
if (flag & HCLGE_MBX_PUSH_LINK_STATUS_EN)
set_bit(HCLGEVF_STATE_PF_PUSH_LINK_STATUS,
&hdev->state);
break; case HCLGE_MBX_LINK_STAT_MODE:
link_mode = (struct hclge_mbx_link_mode *)(msg_q + 1);
idx = le16_to_cpu(link_mode->idx); if (idx)
hdev->hw.mac.supported =
le64_to_cpu(link_mode->link_mode); else
hdev->hw.mac.advertising =
le64_to_cpu(link_mode->link_mode); break; case HCLGE_MBX_ASSERTING_RESET: /* PF has asserted reset hence VF should go in pending * state and poll for the hardware reset status till it * has been completely reset. After this stack should * eventually be re-initialized.
*/
reset_type =
(enum hnae3_reset_type)le16_to_cpu(msg_q[1]);
set_bit(reset_type, &hdev->reset_pending);
set_bit(HCLGEVF_RESET_PENDING, &hdev->reset_state);
hclgevf_reset_task_schedule(hdev);
break; case HCLGE_MBX_PUSH_VLAN_INFO:
vlan_info =
(struct hclge_mbx_port_base_vlan *)(msg_q + 1);
state = le16_to_cpu(vlan_info->state);
hclgevf_update_port_base_vlan_info(hdev, state,
vlan_info); break; case HCLGE_MBX_PUSH_PROMISC_INFO:
hclgevf_parse_promisc_info(hdev, le16_to_cpu(msg_q[1])); break; default:
dev_err(&hdev->pdev->dev, "fetched unsupported(%u) message from arq\n",
opcode); break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.