1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Huawei Technologies Co., Ltd
5 #include "hinic_compat.h"
7 #include "hinic_pmd_hwdev.h"
8 #include "hinic_pmd_hwif.h"
9 #include "hinic_pmd_mgmt.h"
10 #include "hinic_pmd_mbox.h"
12 #define BUF_OUT_DEFAULT_SIZE 1
14 #define MAX_PF_MGMT_BUF_SIZE 2048UL
16 #define MGMT_MSG_SIZE_MIN 20
17 #define MGMT_MSG_SIZE_STEP 16
18 #define MGMT_MSG_RSVD_FOR_DEV 8
20 #define MGMT_MSG_TIMEOUT 5000 /* millisecond */
22 #define SYNC_MSG_ID_MASK 0x1FF
23 #define ASYNC_MSG_ID_MASK 0x1FF
24 #define ASYNC_MSG_FLAG 0x200
26 #define MSG_NO_RESP 0xFFFF
28 #define MAX_MSG_SZ 2016
30 #define MSG_SZ_IS_VALID(in_size) ((in_size) <= MAX_MSG_SZ)
32 #define SYNC_MSG_ID(pf_to_mgmt) ((pf_to_mgmt)->sync_msg_id)
34 #define SYNC_MSG_ID_INC(pf_to_mgmt) (SYNC_MSG_ID(pf_to_mgmt) = \
35 (SYNC_MSG_ID(pf_to_mgmt) + 1) & SYNC_MSG_ID_MASK)
37 #define ASYNC_MSG_ID(pf_to_mgmt) ((pf_to_mgmt)->async_msg_id)
39 #define ASYNC_MSG_ID_INC(pf_to_mgmt) (ASYNC_MSG_ID(pf_to_mgmt) = \
40 ((ASYNC_MSG_ID(pf_to_mgmt) + 1) & ASYNC_MSG_ID_MASK) \
43 #define HINIC_SEQ_ID_MAX_VAL 42
44 #define HINIC_MSG_SEG_LEN 48
46 #define GET_CURR_AEQ_ELEM(eq) GET_AEQ_ELEM((eq), (eq)->cons_idx)
48 #define EQ_ELEM_DESC_TYPE_SHIFT 0
49 #define EQ_ELEM_DESC_SRC_SHIFT 7
50 #define EQ_ELEM_DESC_SIZE_SHIFT 8
51 #define EQ_ELEM_DESC_WRAPPED_SHIFT 31
53 #define EQ_ELEM_DESC_TYPE_MASK 0x7FU
54 #define EQ_ELEM_DESC_SRC_MASK 0x1U
55 #define EQ_ELEM_DESC_SIZE_MASK 0xFFU
56 #define EQ_ELEM_DESC_WRAPPED_MASK 0x1U
58 #define EQ_MSIX_RESEND_TIMER_CLEAR 1
60 #define EQ_ELEM_DESC_GET(val, member) \
61 (((val) >> EQ_ELEM_DESC_##member##_SHIFT) & \
62 EQ_ELEM_DESC_##member##_MASK)
64 #define HINIC_MGMT_CHANNEL_STATUS_SHIFT 0x0
65 #define HINIC_MGMT_CHANNEL_STATUS_MASK 0x1
67 #define HINIC_GET_MGMT_CHANNEL_STATUS(val, member) \
68 (((val) >> HINIC_##member##_SHIFT) & HINIC_##member##_MASK)
70 #define HINIC_MSG_TO_MGMT_MAX_LEN 2016
73 * mgmt_msg_len - calculate the total message length
74 * @msg_data_len: the length of the message data
75 * Return: the total message length
77 static u16 mgmt_msg_len(u16 msg_data_len)
79 /* u64 - the size of the header */
80 u16 msg_size = (u16)(MGMT_MSG_RSVD_FOR_DEV + sizeof(u64) +
83 if (msg_size > MGMT_MSG_SIZE_MIN)
84 msg_size = MGMT_MSG_SIZE_MIN +
85 ALIGN((msg_size - MGMT_MSG_SIZE_MIN),
88 msg_size = MGMT_MSG_SIZE_MIN;
94 * prepare_header - prepare the header of the message
95 * @pf_to_mgmt: PF to MGMT channel
96 * @header: pointer of the header to prepare
97 * @msg_len: the length of the message
98 * @mod: module in the chip that will get the message
99 * @ack_type: the type to response
100 * @direction: the direction of the original message
101 * @cmd: the command to do
102 * @msg_id: message id
104 static void prepare_header(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
105 u64 *header, int msg_len, enum hinic_mod_type mod,
106 enum hinic_msg_ack_type ack_type,
107 enum hinic_msg_direction_type direction,
110 struct hinic_hwif *hwif = pf_to_mgmt->hwdev->hwif;
112 *header = HINIC_MSG_HEADER_SET(msg_len, MSG_LEN) |
113 HINIC_MSG_HEADER_SET(mod, MODULE) |
114 HINIC_MSG_HEADER_SET(msg_len, SEG_LEN) |
115 HINIC_MSG_HEADER_SET(ack_type, NO_ACK) |
116 HINIC_MSG_HEADER_SET(0, ASYNC_MGMT_TO_PF) |
117 HINIC_MSG_HEADER_SET(0, SEQID) |
118 HINIC_MSG_HEADER_SET(LAST_SEGMENT, LAST) |
119 HINIC_MSG_HEADER_SET(direction, DIRECTION) |
120 HINIC_MSG_HEADER_SET(cmd, CMD) |
121 HINIC_MSG_HEADER_SET(HINIC_PCI_INTF_IDX(hwif), PCI_INTF_IDX) |
122 HINIC_MSG_HEADER_SET(hwif->attr.port_to_port_idx, P2P_IDX) |
123 HINIC_MSG_HEADER_SET(msg_id, MSG_ID);
127 * prepare_mgmt_cmd - prepare the mgmt command
128 * @mgmt_cmd: pointer to the command to prepare
129 * @header: pointer of the header to prepare
130 * @msg: the data of the message
131 * @msg_len: the length of the message
133 static void prepare_mgmt_cmd(u8 *mgmt_cmd, u64 *header, void *msg,
136 memset(mgmt_cmd, 0, MGMT_MSG_RSVD_FOR_DEV);
138 mgmt_cmd += MGMT_MSG_RSVD_FOR_DEV;
139 memcpy(mgmt_cmd, header, sizeof(*header));
141 mgmt_cmd += sizeof(*header);
142 memcpy(mgmt_cmd, msg, msg_len);
146 * alloc_recv_msg - allocate received message memory
147 * @recv_msg: pointer that will hold the allocated data
148 * Return: 0 - success, negative - failure
150 static int alloc_recv_msg(struct hinic_recv_msg *recv_msg)
154 recv_msg->msg = kzalloc(MAX_PF_MGMT_BUF_SIZE, GFP_KERNEL);
155 if (!recv_msg->msg) {
156 PMD_DRV_LOG(ERR, "Allocate recv msg buf failed");
160 recv_msg->buf_out = kzalloc(MAX_PF_MGMT_BUF_SIZE, GFP_KERNEL);
161 if (!recv_msg->buf_out) {
162 PMD_DRV_LOG(ERR, "Allocate recv msg output buf failed");
164 goto alloc_buf_out_err;
170 kfree(recv_msg->msg);
175 * free_recv_msg - free received message memory
176 * @recv_msg: pointer that holds the allocated data
178 static void free_recv_msg(struct hinic_recv_msg *recv_msg)
180 kfree(recv_msg->buf_out);
181 kfree(recv_msg->msg);
185 * alloc_msg_buf - allocate all the message buffers of PF to MGMT channel
186 * @pf_to_mgmt: PF to MGMT channel
187 * Return: 0 - success, negative - failure
189 static int alloc_msg_buf(struct hinic_msg_pf_to_mgmt *pf_to_mgmt)
193 err = alloc_recv_msg(&pf_to_mgmt->recv_msg_from_mgmt);
195 PMD_DRV_LOG(ERR, "Allocate recv msg failed");
199 err = alloc_recv_msg(&pf_to_mgmt->recv_resp_msg_from_mgmt);
201 PMD_DRV_LOG(ERR, "Allocate resp recv msg failed");
202 goto alloc_msg_for_resp_err;
205 pf_to_mgmt->async_msg_buf = kzalloc(MAX_PF_MGMT_BUF_SIZE, GFP_KERNEL);
206 if (!pf_to_mgmt->async_msg_buf) {
207 PMD_DRV_LOG(ERR, "Allocate async msg buf failed");
209 goto async_msg_buf_err;
212 pf_to_mgmt->sync_msg_buf = kzalloc(MAX_PF_MGMT_BUF_SIZE, GFP_KERNEL);
213 if (!pf_to_mgmt->sync_msg_buf) {
214 PMD_DRV_LOG(ERR, "Allocate sync msg buf failed");
216 goto sync_msg_buf_err;
222 kfree(pf_to_mgmt->async_msg_buf);
225 free_recv_msg(&pf_to_mgmt->recv_resp_msg_from_mgmt);
227 alloc_msg_for_resp_err:
228 free_recv_msg(&pf_to_mgmt->recv_msg_from_mgmt);
234 * free_msg_buf - free all the message buffers of PF to MGMT channel
235 * @pf_to_mgmt: PF to MGMT channel
236 * Return: 0 - success, negative - failure
238 static void free_msg_buf(struct hinic_msg_pf_to_mgmt *pf_to_mgmt)
240 kfree(pf_to_mgmt->sync_msg_buf);
241 kfree(pf_to_mgmt->async_msg_buf);
243 free_recv_msg(&pf_to_mgmt->recv_resp_msg_from_mgmt);
244 free_recv_msg(&pf_to_mgmt->recv_msg_from_mgmt);
247 static int hinic_get_mgmt_channel_status(void *hwdev)
249 struct hinic_hwif *hwif = ((struct hinic_hwdev *)hwdev)->hwif;
252 if (hinic_func_type((struct hinic_hwdev *)hwdev) == TYPE_VF)
255 val = hinic_hwif_read_reg(hwif, HINIC_ICPL_RESERVD_ADDR);
257 return HINIC_GET_MGMT_CHANNEL_STATUS(val, MGMT_CHANNEL_STATUS);
261 * send_msg_to_mgmt_async - send async message
262 * @pf_to_mgmt: PF to MGMT channel
263 * @mod: module in the chip that will get the message
264 * @cmd: command of the message
265 * @msg: the data of the message
266 * @msg_len: the length of the message
267 * @direction: the direction of the original message
268 * @resp_msg_id: message id of response
269 * Return: 0 - success, negative - failure
271 static int send_msg_to_mgmt_async(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
272 enum hinic_mod_type mod, u8 cmd,
273 void *msg, u16 msg_len,
274 enum hinic_msg_direction_type direction,
277 void *mgmt_cmd = pf_to_mgmt->async_msg_buf;
278 struct hinic_api_cmd_chain *chain;
280 u16 cmd_size = mgmt_msg_len(msg_len);
282 if (direction == HINIC_MSG_RESPONSE)
283 prepare_header(pf_to_mgmt, &header, msg_len, mod, HINIC_MSG_ACK,
284 direction, cmd, resp_msg_id);
286 prepare_header(pf_to_mgmt, &header, msg_len, mod, HINIC_MSG_ACK,
287 direction, cmd, ASYNC_MSG_ID(pf_to_mgmt));
289 prepare_mgmt_cmd((u8 *)mgmt_cmd, &header, msg, msg_len);
291 chain = pf_to_mgmt->cmd_chain[HINIC_API_CMD_WRITE_ASYNC_TO_MGMT_CPU];
293 return hinic_api_cmd_write(chain, HINIC_NODE_ID_MGMT_HOST, mgmt_cmd,
298 * send_msg_to_mgmt_sync - send async message
299 * @pf_to_mgmt: PF to MGMT channel
300 * @mod: module in the chip that will get the message
301 * @cmd: command of the message
303 * @msg_len: the msg data length
304 * @ack_type: indicate mgmt command whether need ack or not
305 * @direction: the direction of the original message
306 * @resp_msg_id: msg id to response for
307 * Return: 0 - success, negative - failure
309 static int send_msg_to_mgmt_sync(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
310 enum hinic_mod_type mod, u8 cmd,
311 void *msg, u16 msg_len,
312 enum hinic_msg_ack_type ack_type,
313 enum hinic_msg_direction_type direction,
314 __rte_unused u16 resp_msg_id)
316 void *mgmt_cmd = pf_to_mgmt->sync_msg_buf;
317 struct hinic_api_cmd_chain *chain;
319 u16 cmd_size = mgmt_msg_len(msg_len);
321 /* If fw is hot active, return failed */
322 if (hinic_get_mgmt_channel_status(pf_to_mgmt->hwdev)) {
323 if (mod == HINIC_MOD_COMM || mod == HINIC_MOD_L2NIC)
324 return HINIC_DEV_BUSY_ACTIVE_FW;
329 if (direction == HINIC_MSG_RESPONSE)
330 prepare_header(pf_to_mgmt, &header, msg_len, mod, ack_type,
331 direction, cmd, resp_msg_id);
333 prepare_header(pf_to_mgmt, &header, msg_len, mod, ack_type,
334 direction, cmd, SYNC_MSG_ID(pf_to_mgmt));
336 prepare_mgmt_cmd((u8 *)mgmt_cmd, &header, msg, msg_len);
338 chain = pf_to_mgmt->cmd_chain[HINIC_API_CMD_PMD_WRITE_TO_MGMT];
340 return hinic_api_cmd_write(chain, HINIC_NODE_ID_MGMT_HOST,
345 * hinic_pf_to_mgmt_init - initialize PF to MGMT channel
346 * @hwdev: the pointer to the private hardware device object
347 * Return: 0 - success, negative - failure
349 static int hinic_pf_to_mgmt_init(struct hinic_hwdev *hwdev)
351 struct hinic_msg_pf_to_mgmt *pf_to_mgmt;
354 pf_to_mgmt = kzalloc(sizeof(*pf_to_mgmt), GFP_KERNEL);
356 PMD_DRV_LOG(ERR, "Allocate pf to mgmt mem failed");
360 hwdev->pf_to_mgmt = pf_to_mgmt;
361 pf_to_mgmt->hwdev = hwdev;
363 err = hinic_mutex_init(&pf_to_mgmt->sync_msg_mutex, NULL);
367 err = alloc_msg_buf(pf_to_mgmt);
369 PMD_DRV_LOG(ERR, "Allocate msg buffers failed");
370 goto alloc_msg_buf_err;
373 err = hinic_api_cmd_init(hwdev, pf_to_mgmt->cmd_chain);
375 PMD_DRV_LOG(ERR, "Init the api cmd chains failed");
376 goto api_cmd_init_err;
382 free_msg_buf(pf_to_mgmt);
385 hinic_mutex_destroy(&pf_to_mgmt->sync_msg_mutex);
394 * hinic_pf_to_mgmt_free - free PF to MGMT channel
395 * @hwdev: the pointer to the private hardware device object
397 static void hinic_pf_to_mgmt_free(struct hinic_hwdev *hwdev)
399 struct hinic_msg_pf_to_mgmt *pf_to_mgmt = hwdev->pf_to_mgmt;
401 hinic_api_cmd_free(pf_to_mgmt->cmd_chain);
402 free_msg_buf(pf_to_mgmt);
403 hinic_mutex_destroy(&pf_to_mgmt->sync_msg_mutex);
408 hinic_pf_to_mgmt_sync(struct hinic_hwdev *hwdev,
409 enum hinic_mod_type mod, u8 cmd, void *buf_in, u16 in_size,
410 void *buf_out, u16 *out_size, u32 timeout)
412 struct hinic_msg_pf_to_mgmt *pf_to_mgmt = hwdev->pf_to_mgmt;
413 struct hinic_recv_msg *recv_msg;
417 err = hinic_mutex_lock(&pf_to_mgmt->sync_msg_mutex);
421 SYNC_MSG_ID_INC(pf_to_mgmt);
422 recv_msg = &pf_to_mgmt->recv_resp_msg_from_mgmt;
424 err = send_msg_to_mgmt_sync(pf_to_mgmt, mod, cmd, buf_in, in_size,
425 HINIC_MSG_ACK, HINIC_MSG_DIRECT_SEND,
428 PMD_DRV_LOG(ERR, "Send msg to mgmt failed");
429 goto unlock_sync_msg;
432 timeo = msecs_to_jiffies(timeout ? timeout : MGMT_MSG_TIMEOUT);
433 for (i = 0; i < pf_to_mgmt->rx_aeq->poll_retry_nr; i++) {
434 err = hinic_aeq_poll_msg(pf_to_mgmt->rx_aeq, timeo, NULL);
436 PMD_DRV_LOG(ERR, "Poll mgmt rsp timeout, mod=%d cmd=%d msg_id=%u rc=%d",
437 mod, cmd, pf_to_mgmt->sync_msg_id, err);
439 hinic_dump_aeq_info(hwdev);
440 goto unlock_sync_msg;
442 if (mod == recv_msg->mod && cmd == recv_msg->cmd &&
443 recv_msg->msg_id == pf_to_mgmt->sync_msg_id) {
444 /* the expected response polled */
447 PMD_DRV_LOG(ERR, "AEQ[%d] poll(mod=%d, cmd=%d, msg_id=%u) an "
448 "unexpected(mod=%d, cmd=%d, msg_id=%u) response",
449 pf_to_mgmt->rx_aeq->q_id, mod, cmd,
450 pf_to_mgmt->sync_msg_id, recv_msg->mod,
451 recv_msg->cmd, recv_msg->msg_id);
455 if (i == pf_to_mgmt->rx_aeq->poll_retry_nr) {
456 PMD_DRV_LOG(ERR, "Get %d unexpected mgmt rsp from AEQ[%d], poll mgmt rsp failed",
457 i, pf_to_mgmt->rx_aeq->q_id);
459 goto unlock_sync_msg;
463 if (recv_msg->msg_len && buf_out && out_size) {
464 if (recv_msg->msg_len <= *out_size) {
465 memcpy(buf_out, recv_msg->msg,
467 *out_size = recv_msg->msg_len;
469 PMD_DRV_LOG(ERR, "Mgmt rsp's msg len: %u overflow.",
478 (void)hinic_mutex_unlock(&pf_to_mgmt->sync_msg_mutex);
482 int hinic_msg_to_mgmt_sync(void *hwdev, enum hinic_mod_type mod, u8 cmd,
483 void *buf_in, u16 in_size,
484 void *buf_out, u16 *out_size, u32 timeout)
486 int rc = HINIC_ERROR;
488 if (!hwdev || in_size > HINIC_MSG_TO_MGMT_MAX_LEN)
491 if (hinic_func_type(hwdev) == TYPE_VF) {
492 rc = hinic_mbox_to_pf(hwdev, mod, cmd, buf_in, in_size,
493 buf_out, out_size, timeout);
495 rc = hinic_pf_to_mgmt_sync(hwdev, mod, cmd, buf_in, in_size,
496 buf_out, out_size, timeout);
502 int hinic_msg_to_mgmt_no_ack(void *hwdev, enum hinic_mod_type mod, u8 cmd,
503 void *buf_in, u16 in_size)
505 struct hinic_msg_pf_to_mgmt *pf_to_mgmt =
506 ((struct hinic_hwdev *)hwdev)->pf_to_mgmt;
509 if (!MSG_SZ_IS_VALID(in_size)) {
510 PMD_DRV_LOG(ERR, "Mgmt msg buffer size is invalid");
514 err = hinic_mutex_lock(&pf_to_mgmt->sync_msg_mutex);
518 err = send_msg_to_mgmt_sync(pf_to_mgmt, mod, cmd, buf_in, in_size,
519 HINIC_MSG_NO_ACK, HINIC_MSG_DIRECT_SEND,
522 (void)hinic_mutex_unlock(&pf_to_mgmt->sync_msg_mutex);
527 static bool check_mgmt_seq_id_and_seg_len(struct hinic_recv_msg *recv_msg,
528 u8 seq_id, u8 seg_len, u16 msg_id)
530 if (seq_id > HINIC_SEQ_ID_MAX_VAL || seg_len > HINIC_MSG_SEG_LEN)
534 recv_msg->seq_id = seq_id;
535 recv_msg->msg_id = msg_id;
537 if ((seq_id != recv_msg->seq_id + 1) ||
538 msg_id != recv_msg->msg_id) {
539 recv_msg->seq_id = 0;
542 recv_msg->seq_id = seq_id;
549 * hinic_mgmt_recv_msg_handler - handler for message from mgmt cpu
550 * @pf_to_mgmt: PF to MGMT channel
551 * @recv_msg: received message details
552 * @param: customized parameter
554 static void hinic_mgmt_recv_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
555 struct hinic_recv_msg *recv_msg,
558 void *buf_out = recv_msg->buf_out;
561 switch (recv_msg->mod) {
563 hinic_comm_async_event_handle(pf_to_mgmt->hwdev,
564 recv_msg->cmd, recv_msg->msg,
568 case HINIC_MOD_L2NIC:
569 hinic_l2nic_async_event_handle(pf_to_mgmt->hwdev, param,
570 recv_msg->cmd, recv_msg->msg,
574 case HINIC_MOD_HILINK:
575 hinic_hilink_async_event_handle(pf_to_mgmt->hwdev,
576 recv_msg->cmd, recv_msg->msg,
581 PMD_DRV_LOG(ERR, "No handler, mod: %d", recv_msg->mod);
585 if (!recv_msg->async_mgmt_to_pf) {
587 out_size = BUF_OUT_DEFAULT_SIZE;
589 /* MGMT sent sync msg, send the response */
590 (void)send_msg_to_mgmt_async(pf_to_mgmt, recv_msg->mod,
591 recv_msg->cmd, buf_out, out_size,
598 * recv_mgmt_msg_handler - handler a message from mgmt cpu
599 * @pf_to_mgmt: PF to MGMT channel
600 * @header: the header of the message
601 * @recv_msg: received message details
602 * @param: customized parameter
603 * Return: 0 when aeq is response message, -1 default result,
604 * and when wrong message or not last message
606 static int recv_mgmt_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
607 u8 *header, struct hinic_recv_msg *recv_msg,
610 u64 msg_header = *((u64 *)header);
611 void *msg_body = header + sizeof(msg_header);
617 seq_id = HINIC_MSG_HEADER_GET(msg_header, SEQID);
618 seq_len = HINIC_MSG_HEADER_GET(msg_header, SEG_LEN);
619 front_id = recv_msg->seq_id;
620 msg_id = HINIC_MSG_HEADER_GET(msg_header, MSG_ID);
622 if (!check_mgmt_seq_id_and_seg_len(recv_msg, seq_id, seq_len, msg_id)) {
624 "Mgmt msg sequence and segment check failed, "
625 "func id: 0x%x, front id: 0x%x, current id: 0x%x, seg len: 0x%x "
626 "front msg_id: %d, cur msg_id: %d",
627 hinic_global_func_id(pf_to_mgmt->hwdev),
628 front_id, seq_id, seq_len, recv_msg->msg_id, msg_id);
632 dest_msg = (u8 *)recv_msg->msg + seq_id * HINIC_MSG_SEG_LEN;
633 memcpy(dest_msg, msg_body, seq_len);
635 if (!HINIC_MSG_HEADER_GET(msg_header, LAST))
638 recv_msg->cmd = HINIC_MSG_HEADER_GET(msg_header, CMD);
639 recv_msg->mod = HINIC_MSG_HEADER_GET(msg_header, MODULE);
640 recv_msg->async_mgmt_to_pf = HINIC_MSG_HEADER_GET(msg_header,
642 recv_msg->msg_len = HINIC_MSG_HEADER_GET(msg_header, MSG_LEN);
643 recv_msg->msg_id = HINIC_MSG_HEADER_GET(msg_header, MSG_ID);
645 if (HINIC_MSG_HEADER_GET(msg_header, DIRECTION) == HINIC_MSG_RESPONSE)
648 hinic_mgmt_recv_msg_handler(pf_to_mgmt, recv_msg, param);
654 * hinic_mgmt_msg_aeqe_handler - handler for a mgmt message event
655 * @hwdev: the pointer to the private hardware device object
656 * @header: the header of the message
658 * @param: customized parameter
659 * Return: 0 when aeq is response message,
660 * -1 default result, and when wrong message or not last message
662 static int hinic_mgmt_msg_aeqe_handler(void *hwdev, u8 *header,
663 __rte_unused u8 size, void *param)
665 struct hinic_msg_pf_to_mgmt *pf_to_mgmt =
666 ((struct hinic_hwdev *)hwdev)->pf_to_mgmt;
667 struct hinic_recv_msg *recv_msg;
669 recv_msg = (HINIC_MSG_HEADER_GET(*(u64 *)header, DIRECTION) ==
670 HINIC_MSG_DIRECT_SEND) ?
671 &pf_to_mgmt->recv_msg_from_mgmt :
672 &pf_to_mgmt->recv_resp_msg_from_mgmt;
674 return recv_mgmt_msg_handler(pf_to_mgmt, header, recv_msg, param);
677 static int hinic_handle_aeqe(void *handle, enum hinic_aeq_type event,
678 u8 *data, u8 size, void *param)
683 case HINIC_MSG_FROM_MGMT_CPU:
684 rc = hinic_mgmt_msg_aeqe_handler(handle, data, size, param);
686 case HINIC_MBX_FROM_FUNC:
687 rc = hinic_mbox_func_aeqe_handler(handle, data, size, param);
690 PMD_DRV_LOG(ERR, "Unknown event type: 0x%x, size: %d",
700 * hinic_aeq_poll_msg - poll one or continue aeqe, and call dedicated process
701 * @eq: aeq of the chip
702 * @timeout: 0 - poll all aeqe in eq, used in interrupt mode,
703 * > 0 - poll aeq until get aeqe with 'last' field set to 1,
704 * used in polling mode.
705 * @param: customized parameter
706 * Return: 0 - Success, EIO - poll timeout, ENODEV - swe not support
708 int hinic_aeq_poll_msg(struct hinic_eq *eq, u32 timeout, void *param)
710 struct hinic_aeq_elem *aeqe_pos;
711 enum hinic_aeq_type event;
715 int done = HINIC_ERROR;
719 for (i = 0; ((timeout == 0) && (i < eq->eq_len)) ||
720 ((timeout > 0) && (done != HINIC_OK) && (i < eq->eq_len)); i++) {
722 end = jiffies + msecs_to_jiffies(timeout);
724 aeqe_pos = GET_CURR_AEQ_ELEM(eq);
727 /* Data in HW is in Big endian Format */
728 aeqe_desc = be32_to_cpu(aeqe_pos->desc);
730 /* HW updates wrapped bit,
731 * when it adds eq element event
733 if (EQ_ELEM_DESC_GET(aeqe_desc, WRAPPED)
741 } while (time_before(jiffies, end));
743 if (err != HINIC_OK) /*poll time out*/
746 event = EQ_ELEM_DESC_GET(aeqe_desc, TYPE);
747 if (EQ_ELEM_DESC_GET(aeqe_desc, SRC)) {
748 PMD_DRV_LOG(ERR, "AEQ sw event not support %d", event);
752 size = EQ_ELEM_DESC_GET(aeqe_desc, SIZE);
753 done = hinic_handle_aeqe(eq->hwdev, event,
759 if (eq->cons_idx == eq->eq_len) {
761 eq->wrapped = !eq->wrapped;
770 int hinic_comm_pf_to_mgmt_init(struct hinic_hwdev *hwdev)
774 /* VF do not support send msg to mgmt directly */
775 if (hinic_func_type(hwdev) == TYPE_VF)
778 rc = hinic_pf_to_mgmt_init(hwdev);
782 hwdev->pf_to_mgmt->rx_aeq = &hwdev->aeqs->aeq[HINIC_MGMT_RSP_AEQN];
787 void hinic_comm_pf_to_mgmt_free(struct hinic_hwdev *hwdev)
789 /* VF do not support send msg to mgmt directly */
790 if (hinic_func_type(hwdev) == TYPE_VF)
793 hinic_pf_to_mgmt_free(hwdev);
796 void hinic_dev_handle_aeq_event(struct hinic_hwdev *hwdev, void *param)
798 struct hinic_eq *aeq = &hwdev->aeqs->aeq[0];
800 /* clear resend timer cnt register */
801 hinic_misx_intr_clear_resend_bit(hwdev, aeq->eq_irq.msix_entry_idx,
802 EQ_MSIX_RESEND_TIMER_CLEAR);
803 (void)hinic_aeq_poll_msg(aeq, 0, param);