xref: /dpdk/drivers/net/thunderx/base/nicvf_mbox.c (revision e7133f8fb39f506dc1eef02c2927acda949ca000)
1aaf4363eSJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
2aaf4363eSJerin Jacob  * Copyright(c) 2016 Cavium, Inc
3966e225cSJerin Jacob  */
4966e225cSJerin Jacob 
5966e225cSJerin Jacob #include <assert.h>
6966e225cSJerin Jacob #include <unistd.h>
7966e225cSJerin Jacob #include <stdio.h>
8966e225cSJerin Jacob #include <stdlib.h>
9966e225cSJerin Jacob 
10966e225cSJerin Jacob #include "nicvf_plat.h"
11966e225cSJerin Jacob 
12966e225cSJerin Jacob #define NICVF_MBOX_PF_RESPONSE_DELAY_US   (1000)
13966e225cSJerin Jacob 
14966e225cSJerin Jacob static const char *mbox_message[NIC_MBOX_MSG_MAX] =  {
15966e225cSJerin Jacob 	[NIC_MBOX_MSG_INVALID]            = "NIC_MBOX_MSG_INVALID",
16966e225cSJerin Jacob 	[NIC_MBOX_MSG_READY]              = "NIC_MBOX_MSG_READY",
17966e225cSJerin Jacob 	[NIC_MBOX_MSG_ACK]                = "NIC_MBOX_MSG_ACK",
18966e225cSJerin Jacob 	[NIC_MBOX_MSG_NACK]               = "NIC_MBOX_MSG_ACK",
19966e225cSJerin Jacob 	[NIC_MBOX_MSG_QS_CFG]             = "NIC_MBOX_MSG_QS_CFG",
20966e225cSJerin Jacob 	[NIC_MBOX_MSG_RQ_CFG]             = "NIC_MBOX_MSG_RQ_CFG",
21966e225cSJerin Jacob 	[NIC_MBOX_MSG_SQ_CFG]             = "NIC_MBOX_MSG_SQ_CFG",
22966e225cSJerin Jacob 	[NIC_MBOX_MSG_RQ_DROP_CFG]        = "NIC_MBOX_MSG_RQ_DROP_CFG",
23966e225cSJerin Jacob 	[NIC_MBOX_MSG_SET_MAC]            = "NIC_MBOX_MSG_SET_MAC",
24966e225cSJerin Jacob 	[NIC_MBOX_MSG_SET_MAX_FRS]        = "NIC_MBOX_MSG_SET_MAX_FRS",
25966e225cSJerin Jacob 	[NIC_MBOX_MSG_CPI_CFG]            = "NIC_MBOX_MSG_CPI_CFG",
26966e225cSJerin Jacob 	[NIC_MBOX_MSG_RSS_SIZE]           = "NIC_MBOX_MSG_RSS_SIZE",
27966e225cSJerin Jacob 	[NIC_MBOX_MSG_RSS_CFG]            = "NIC_MBOX_MSG_RSS_CFG",
28966e225cSJerin Jacob 	[NIC_MBOX_MSG_RSS_CFG_CONT]       = "NIC_MBOX_MSG_RSS_CFG_CONT",
29966e225cSJerin Jacob 	[NIC_MBOX_MSG_RQ_BP_CFG]          = "NIC_MBOX_MSG_RQ_BP_CFG",
30966e225cSJerin Jacob 	[NIC_MBOX_MSG_RQ_SW_SYNC]         = "NIC_MBOX_MSG_RQ_SW_SYNC",
31966e225cSJerin Jacob 	[NIC_MBOX_MSG_BGX_LINK_CHANGE]    = "NIC_MBOX_MSG_BGX_LINK_CHANGE",
32966e225cSJerin Jacob 	[NIC_MBOX_MSG_ALLOC_SQS]          = "NIC_MBOX_MSG_ALLOC_SQS",
33966e225cSJerin Jacob 	[NIC_MBOX_MSG_LOOPBACK]           = "NIC_MBOX_MSG_LOOPBACK",
34966e225cSJerin Jacob 	[NIC_MBOX_MSG_RESET_STAT_COUNTER] = "NIC_MBOX_MSG_RESET_STAT_COUNTER",
35966e225cSJerin Jacob 	[NIC_MBOX_MSG_CFG_DONE]           = "NIC_MBOX_MSG_CFG_DONE",
36966e225cSJerin Jacob 	[NIC_MBOX_MSG_SHUTDOWN]           = "NIC_MBOX_MSG_SHUTDOWN",
37966e225cSJerin Jacob };
38966e225cSJerin Jacob 
39f2fc83b4SThomas Monjalon static inline const char * __rte_unused
40966e225cSJerin Jacob nicvf_mbox_msg_str(int msg)
41966e225cSJerin Jacob {
42966e225cSJerin Jacob 	assert(msg >= 0 && msg < NIC_MBOX_MSG_MAX);
43966e225cSJerin Jacob 	/* undefined messages */
44966e225cSJerin Jacob 	if (mbox_message[msg] == NULL)
45966e225cSJerin Jacob 		msg = 0;
46966e225cSJerin Jacob 	return mbox_message[msg];
47966e225cSJerin Jacob }
48966e225cSJerin Jacob 
49966e225cSJerin Jacob static inline void
50966e225cSJerin Jacob nicvf_mbox_send_msg_to_pf_raw(struct nicvf *nic, struct nic_mbx *mbx)
51966e225cSJerin Jacob {
52966e225cSJerin Jacob 	uint64_t *mbx_data;
53966e225cSJerin Jacob 	uint64_t mbx_addr;
54966e225cSJerin Jacob 	int i;
55966e225cSJerin Jacob 
56966e225cSJerin Jacob 	mbx_addr = NIC_VF_PF_MAILBOX_0_1;
57966e225cSJerin Jacob 	mbx_data = (uint64_t *)mbx;
58966e225cSJerin Jacob 	for (i = 0; i < NIC_PF_VF_MAILBOX_SIZE; i++) {
59966e225cSJerin Jacob 		nicvf_reg_write(nic, mbx_addr, *mbx_data);
60966e225cSJerin Jacob 		mbx_data++;
61966e225cSJerin Jacob 		mbx_addr += sizeof(uint64_t);
62966e225cSJerin Jacob 	}
63966e225cSJerin Jacob 	nicvf_mbox_log("msg sent %s (VF%d)",
64966e225cSJerin Jacob 			nicvf_mbox_msg_str(mbx->msg.msg), nic->vf_id);
65966e225cSJerin Jacob }
66966e225cSJerin Jacob 
67966e225cSJerin Jacob static inline void
68966e225cSJerin Jacob nicvf_mbox_send_async_msg_to_pf(struct nicvf *nic, struct nic_mbx *mbx)
69966e225cSJerin Jacob {
70966e225cSJerin Jacob 	nicvf_mbox_send_msg_to_pf_raw(nic, mbx);
71966e225cSJerin Jacob 	/* Messages without ack are racy!*/
72966e225cSJerin Jacob 	nicvf_delay_us(NICVF_MBOX_PF_RESPONSE_DELAY_US);
73966e225cSJerin Jacob }
74966e225cSJerin Jacob 
75966e225cSJerin Jacob static inline int
76966e225cSJerin Jacob nicvf_mbox_send_msg_to_pf(struct nicvf *nic, struct nic_mbx *mbx)
77966e225cSJerin Jacob {
78966e225cSJerin Jacob 	long timeout;
79966e225cSJerin Jacob 	long sleep = 10;
80966e225cSJerin Jacob 	int i, retry = 5;
81966e225cSJerin Jacob 
82966e225cSJerin Jacob 	for (i = 0; i < retry; i++) {
83966e225cSJerin Jacob 		nic->pf_acked = false;
84966e225cSJerin Jacob 		nic->pf_nacked = false;
85966e225cSJerin Jacob 		nicvf_smp_wmb();
86966e225cSJerin Jacob 
87966e225cSJerin Jacob 		nicvf_mbox_send_msg_to_pf_raw(nic, mbx);
8832423e46SHarman Kalra 
8932423e46SHarman Kalra 		/* Handling case if mbox is called inside interrupt context,
9032423e46SHarman Kalra 		 * Eg if hotplug attach/detach request is initiated from
9132423e46SHarman Kalra 		 * secondary and primary handles the request in interrupt
9232423e46SHarman Kalra 		 * context as part of multprocess framework.
9332423e46SHarman Kalra 		 */
9432423e46SHarman Kalra 		if (rte_thread_is_intr()) {
9532423e46SHarman Kalra 			nicvf_delay_us(NICVF_MBOX_PF_RESPONSE_DELAY_US);
9632423e46SHarman Kalra 			nicvf_reg_poll_interrupts(nic);
9732423e46SHarman Kalra 		}
9832423e46SHarman Kalra 
99966e225cSJerin Jacob 		/* Give some time to get PF response */
100966e225cSJerin Jacob 		nicvf_delay_us(NICVF_MBOX_PF_RESPONSE_DELAY_US);
101966e225cSJerin Jacob 		timeout = NIC_MBOX_MSG_TIMEOUT;
102966e225cSJerin Jacob 		while (timeout > 0) {
103966e225cSJerin Jacob 			/* Periodic poll happens from nicvf_interrupt() */
104966e225cSJerin Jacob 			nicvf_smp_rmb();
105966e225cSJerin Jacob 
106966e225cSJerin Jacob 			if (nic->pf_nacked)
107966e225cSJerin Jacob 				return -EINVAL;
108966e225cSJerin Jacob 			if (nic->pf_acked)
109966e225cSJerin Jacob 				return 0;
110966e225cSJerin Jacob 
111966e225cSJerin Jacob 			nicvf_delay_us(NICVF_MBOX_PF_RESPONSE_DELAY_US);
112966e225cSJerin Jacob 			timeout -= sleep;
113966e225cSJerin Jacob 		}
11432423e46SHarman Kalra 	}
115966e225cSJerin Jacob 	nicvf_log_error("PF didn't ack to msg 0x%02x %s VF%d (%d/%d)",
116966e225cSJerin Jacob 			mbx->msg.msg, nicvf_mbox_msg_str(mbx->msg.msg),
117966e225cSJerin Jacob 			nic->vf_id, i, retry);
118966e225cSJerin Jacob 	return -EBUSY;
119966e225cSJerin Jacob }
120966e225cSJerin Jacob 
121966e225cSJerin Jacob 
122966e225cSJerin Jacob int
123966e225cSJerin Jacob nicvf_handle_mbx_intr(struct nicvf *nic)
124966e225cSJerin Jacob {
125966e225cSJerin Jacob 	struct nic_mbx mbx;
126966e225cSJerin Jacob 	uint64_t *mbx_data = (uint64_t *)&mbx;
127966e225cSJerin Jacob 	uint64_t mbx_addr = NIC_VF_PF_MAILBOX_0_1;
128966e225cSJerin Jacob 	size_t i;
129966e225cSJerin Jacob 
130966e225cSJerin Jacob 	for (i = 0; i < NIC_PF_VF_MAILBOX_SIZE; i++) {
131966e225cSJerin Jacob 		*mbx_data = nicvf_reg_read(nic, mbx_addr);
132966e225cSJerin Jacob 		mbx_data++;
133966e225cSJerin Jacob 		mbx_addr += sizeof(uint64_t);
134966e225cSJerin Jacob 	}
135966e225cSJerin Jacob 
136966e225cSJerin Jacob 	/* Overwrite the message so we won't receive it again */
137966e225cSJerin Jacob 	nicvf_reg_write(nic, NIC_VF_PF_MAILBOX_0_1, 0x0);
138966e225cSJerin Jacob 
139966e225cSJerin Jacob 	nicvf_mbox_log("msg received id=0x%hhx %s (VF%d)", mbx.msg.msg,
140966e225cSJerin Jacob 			nicvf_mbox_msg_str(mbx.msg.msg), nic->vf_id);
141966e225cSJerin Jacob 
142966e225cSJerin Jacob 	switch (mbx.msg.msg) {
143966e225cSJerin Jacob 	case NIC_MBOX_MSG_READY:
144966e225cSJerin Jacob 		nic->vf_id = mbx.nic_cfg.vf_id & 0x7F;
145966e225cSJerin Jacob 		nic->tns_mode = mbx.nic_cfg.tns_mode & 0x7F;
146966e225cSJerin Jacob 		nic->node = mbx.nic_cfg.node_id;
147966e225cSJerin Jacob 		nic->sqs_mode = mbx.nic_cfg.sqs_mode;
148966e225cSJerin Jacob 		nic->loopback_supported = mbx.nic_cfg.loopback_supported;
149966e225cSJerin Jacob 		ether_addr_copy((struct ether_addr *)mbx.nic_cfg.mac_addr,
150966e225cSJerin Jacob 				(struct ether_addr *)nic->mac_addr);
151966e225cSJerin Jacob 		nic->pf_acked = true;
152966e225cSJerin Jacob 		break;
153966e225cSJerin Jacob 	case NIC_MBOX_MSG_ACK:
154966e225cSJerin Jacob 		nic->pf_acked = true;
155966e225cSJerin Jacob 		break;
156966e225cSJerin Jacob 	case NIC_MBOX_MSG_NACK:
157966e225cSJerin Jacob 		nic->pf_nacked = true;
158966e225cSJerin Jacob 		break;
1592d5a4b62SJerin Jacob 	case NIC_MBOX_MSG_RSS_SIZE:
160966e225cSJerin Jacob 		nic->rss_info.rss_size = mbx.rss_size.ind_tbl_size;
161966e225cSJerin Jacob 		nic->pf_acked = true;
162966e225cSJerin Jacob 		break;
163966e225cSJerin Jacob 	case NIC_MBOX_MSG_BGX_LINK_CHANGE:
164966e225cSJerin Jacob 		nic->link_up = mbx.link_status.link_up;
165966e225cSJerin Jacob 		nic->duplex = mbx.link_status.duplex;
166966e225cSJerin Jacob 		nic->speed = mbx.link_status.speed;
167966e225cSJerin Jacob 		nic->pf_acked = true;
168966e225cSJerin Jacob 		break;
1692d5a4b62SJerin Jacob 	case NIC_MBOX_MSG_ALLOC_SQS:
17010b0e74fSKamil Rytarowski 		assert_primary(nic);
17110b0e74fSKamil Rytarowski 		if (mbx.sqs_alloc.qs_count != nic->sqs_count) {
17210b0e74fSKamil Rytarowski 			nicvf_log_error("Received %" PRIu8 "/%" PRIu8
17310b0e74fSKamil Rytarowski 			                " secondary qsets",
17410b0e74fSKamil Rytarowski 			                mbx.sqs_alloc.qs_count,
17510b0e74fSKamil Rytarowski 			                nic->sqs_count);
17610b0e74fSKamil Rytarowski 			abort();
17710b0e74fSKamil Rytarowski 		}
17810b0e74fSKamil Rytarowski 		for (i = 0; i < mbx.sqs_alloc.qs_count; i++) {
17910b0e74fSKamil Rytarowski 			if (mbx.sqs_alloc.svf[i] != nic->snicvf[i]->vf_id) {
18010b0e74fSKamil Rytarowski 				nicvf_log_error("Received secondary qset[%zu] "
18110b0e74fSKamil Rytarowski 				                "ID %" PRIu8 " expected %"
18210b0e74fSKamil Rytarowski 				                PRIu8, i, mbx.sqs_alloc.svf[i],
18310b0e74fSKamil Rytarowski 				                nic->snicvf[i]->vf_id);
18410b0e74fSKamil Rytarowski 				abort();
18510b0e74fSKamil Rytarowski 			}
18610b0e74fSKamil Rytarowski 		}
18710b0e74fSKamil Rytarowski 		nic->pf_acked = true;
18810b0e74fSKamil Rytarowski 		break;
189966e225cSJerin Jacob 	default:
190966e225cSJerin Jacob 		nicvf_log_error("Invalid message from PF, msg_id=0x%hhx %s",
191966e225cSJerin Jacob 				mbx.msg.msg, nicvf_mbox_msg_str(mbx.msg.msg));
192966e225cSJerin Jacob 		break;
193966e225cSJerin Jacob 	}
194966e225cSJerin Jacob 	nicvf_smp_wmb();
195966e225cSJerin Jacob 
196966e225cSJerin Jacob 	return mbx.msg.msg;
197966e225cSJerin Jacob }
198966e225cSJerin Jacob 
199966e225cSJerin Jacob /*
200966e225cSJerin Jacob  * Checks if VF is able to communicate with PF
201966e225cSJerin Jacob  * and also gets the VNIC number this VF is associated to.
202966e225cSJerin Jacob  */
203966e225cSJerin Jacob int
204966e225cSJerin Jacob nicvf_mbox_check_pf_ready(struct nicvf *nic)
205966e225cSJerin Jacob {
206966e225cSJerin Jacob 	struct nic_mbx mbx = { .msg = {.msg = NIC_MBOX_MSG_READY} };
207966e225cSJerin Jacob 
208966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
209966e225cSJerin Jacob }
210966e225cSJerin Jacob 
211966e225cSJerin Jacob int
212966e225cSJerin Jacob nicvf_mbox_set_mac_addr(struct nicvf *nic,
213966e225cSJerin Jacob 			const uint8_t mac[NICVF_MAC_ADDR_SIZE])
214966e225cSJerin Jacob {
215*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
216966e225cSJerin Jacob 	int i;
217966e225cSJerin Jacob 
218966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_SET_MAC;
219966e225cSJerin Jacob 	mbx.mac.vf_id = nic->vf_id;
220966e225cSJerin Jacob 	for (i = 0; i < 6; i++)
221966e225cSJerin Jacob 		mbx.mac.mac_addr[i] = mac[i];
222966e225cSJerin Jacob 
223966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
224966e225cSJerin Jacob }
225966e225cSJerin Jacob 
226966e225cSJerin Jacob int
227966e225cSJerin Jacob nicvf_mbox_config_cpi(struct nicvf *nic, uint32_t qcnt)
228966e225cSJerin Jacob {
229*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
230966e225cSJerin Jacob 
231966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_CPI_CFG;
232966e225cSJerin Jacob 	mbx.cpi_cfg.vf_id = nic->vf_id;
233966e225cSJerin Jacob 	mbx.cpi_cfg.cpi_alg = nic->cpi_alg;
234966e225cSJerin Jacob 	mbx.cpi_cfg.rq_cnt = qcnt;
235966e225cSJerin Jacob 
236966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
237966e225cSJerin Jacob }
238966e225cSJerin Jacob 
239966e225cSJerin Jacob int
240966e225cSJerin Jacob nicvf_mbox_get_rss_size(struct nicvf *nic)
241966e225cSJerin Jacob {
242*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
243966e225cSJerin Jacob 
244966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_RSS_SIZE;
245966e225cSJerin Jacob 	mbx.rss_size.vf_id = nic->vf_id;
246966e225cSJerin Jacob 
247966e225cSJerin Jacob 	/* Result will be stored in nic->rss_info.rss_size */
248966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
249966e225cSJerin Jacob }
250966e225cSJerin Jacob 
251966e225cSJerin Jacob int
252966e225cSJerin Jacob nicvf_mbox_config_rss(struct nicvf *nic)
253966e225cSJerin Jacob {
254*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
255966e225cSJerin Jacob 	struct nicvf_rss_reta_info *rss = &nic->rss_info;
256966e225cSJerin Jacob 	size_t tot_len = rss->rss_size;
257966e225cSJerin Jacob 	size_t cur_len;
258966e225cSJerin Jacob 	size_t cur_idx = 0;
259966e225cSJerin Jacob 	size_t i;
260966e225cSJerin Jacob 
261966e225cSJerin Jacob 	mbx.rss_cfg.vf_id = nic->vf_id;
262966e225cSJerin Jacob 	mbx.rss_cfg.hash_bits = rss->hash_bits;
263966e225cSJerin Jacob 	mbx.rss_cfg.tbl_len = 0;
264966e225cSJerin Jacob 	mbx.rss_cfg.tbl_offset = 0;
265966e225cSJerin Jacob 
266966e225cSJerin Jacob 	while (cur_idx < tot_len) {
267966e225cSJerin Jacob 		cur_len = nicvf_min(tot_len - cur_idx,
268966e225cSJerin Jacob 				(size_t)RSS_IND_TBL_LEN_PER_MBX_MSG);
269966e225cSJerin Jacob 		mbx.msg.msg = (cur_idx > 0) ?
270966e225cSJerin Jacob 			NIC_MBOX_MSG_RSS_CFG_CONT : NIC_MBOX_MSG_RSS_CFG;
271966e225cSJerin Jacob 		mbx.rss_cfg.tbl_offset = cur_idx;
272966e225cSJerin Jacob 		mbx.rss_cfg.tbl_len = cur_len;
273966e225cSJerin Jacob 		for (i = 0; i < cur_len; i++)
274966e225cSJerin Jacob 			mbx.rss_cfg.ind_tbl[i] = rss->ind_tbl[cur_idx++];
275966e225cSJerin Jacob 
276966e225cSJerin Jacob 		if (nicvf_mbox_send_msg_to_pf(nic, &mbx))
277966e225cSJerin Jacob 			return NICVF_ERR_RSS_TBL_UPDATE;
278966e225cSJerin Jacob 	}
279966e225cSJerin Jacob 
280966e225cSJerin Jacob 	return 0;
281966e225cSJerin Jacob }
282966e225cSJerin Jacob 
283966e225cSJerin Jacob int
284966e225cSJerin Jacob nicvf_mbox_rq_config(struct nicvf *nic, uint16_t qidx,
285966e225cSJerin Jacob 		     struct pf_rq_cfg *pf_rq_cfg)
286966e225cSJerin Jacob {
287*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
288966e225cSJerin Jacob 
289966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_RQ_CFG;
290966e225cSJerin Jacob 	mbx.rq.qs_num = nic->vf_id;
291966e225cSJerin Jacob 	mbx.rq.rq_num = qidx;
292966e225cSJerin Jacob 	mbx.rq.cfg = pf_rq_cfg->value;
293966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
294966e225cSJerin Jacob }
295966e225cSJerin Jacob 
296966e225cSJerin Jacob int
297966e225cSJerin Jacob nicvf_mbox_sq_config(struct nicvf *nic, uint16_t qidx)
298966e225cSJerin Jacob {
299*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
300966e225cSJerin Jacob 
301966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_SQ_CFG;
302966e225cSJerin Jacob 	mbx.sq.qs_num = nic->vf_id;
303966e225cSJerin Jacob 	mbx.sq.sq_num = qidx;
304966e225cSJerin Jacob 	mbx.sq.sqs_mode = nic->sqs_mode;
305966e225cSJerin Jacob 	mbx.sq.cfg = (nic->vf_id << 3) | qidx;
306966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
307966e225cSJerin Jacob }
308966e225cSJerin Jacob 
309966e225cSJerin Jacob int
310966e225cSJerin Jacob nicvf_mbox_qset_config(struct nicvf *nic, struct pf_qs_cfg *qs_cfg)
311966e225cSJerin Jacob {
312*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
313966e225cSJerin Jacob 
3145ba41107SJerin Jacob #if NICVF_BYTE_ORDER == NICVF_BIG_ENDIAN
315966e225cSJerin Jacob 	qs_cfg->be = 1;
316966e225cSJerin Jacob #endif
317966e225cSJerin Jacob 	/* Send a mailbox msg to PF to config Qset */
318966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_QS_CFG;
319966e225cSJerin Jacob 	mbx.qs.num = nic->vf_id;
32010b0e74fSKamil Rytarowski 	mbx.qs.sqs_count = nic->sqs_count;
321966e225cSJerin Jacob 	mbx.qs.cfg = qs_cfg->value;
322966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
323966e225cSJerin Jacob }
324966e225cSJerin Jacob 
325966e225cSJerin Jacob int
32610b0e74fSKamil Rytarowski nicvf_mbox_request_sqs(struct nicvf *nic)
32710b0e74fSKamil Rytarowski {
328*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
32910b0e74fSKamil Rytarowski 	size_t i;
33010b0e74fSKamil Rytarowski 
33110b0e74fSKamil Rytarowski 	assert_primary(nic);
33210b0e74fSKamil Rytarowski 	assert(nic->sqs_count > 0);
33310b0e74fSKamil Rytarowski 	assert(nic->sqs_count <= MAX_SQS_PER_VF);
33410b0e74fSKamil Rytarowski 
33510b0e74fSKamil Rytarowski 	mbx.sqs_alloc.msg = NIC_MBOX_MSG_ALLOC_SQS;
33610b0e74fSKamil Rytarowski 	mbx.sqs_alloc.spec = 1;
33710b0e74fSKamil Rytarowski 	mbx.sqs_alloc.qs_count = nic->sqs_count;
33810b0e74fSKamil Rytarowski 
33910b0e74fSKamil Rytarowski 	/* Set no of Rx/Tx queues in each of the SQsets */
34010b0e74fSKamil Rytarowski 	for (i = 0; i < nic->sqs_count; i++)
34110b0e74fSKamil Rytarowski 		mbx.sqs_alloc.svf[i] = nic->snicvf[i]->vf_id;
34210b0e74fSKamil Rytarowski 
34310b0e74fSKamil Rytarowski 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
34410b0e74fSKamil Rytarowski }
34510b0e74fSKamil Rytarowski 
34610b0e74fSKamil Rytarowski int
347966e225cSJerin Jacob nicvf_mbox_rq_drop_config(struct nicvf *nic, uint16_t qidx, bool enable)
348966e225cSJerin Jacob {
349*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
350966e225cSJerin Jacob 	struct pf_rq_drop_cfg *drop_cfg;
351966e225cSJerin Jacob 
352966e225cSJerin Jacob 	/* Enable CQ drop to reserve sufficient CQEs for all tx packets */
353966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_RQ_DROP_CFG;
354966e225cSJerin Jacob 	mbx.rq.qs_num = nic->vf_id;
355966e225cSJerin Jacob 	mbx.rq.rq_num = qidx;
356966e225cSJerin Jacob 	drop_cfg = (struct pf_rq_drop_cfg *)&mbx.rq.cfg;
357966e225cSJerin Jacob 	drop_cfg->value = 0;
358966e225cSJerin Jacob 	if (enable) {
359966e225cSJerin Jacob 		drop_cfg->cq_red = 1;
360966e225cSJerin Jacob 		drop_cfg->cq_drop = 2;
361966e225cSJerin Jacob 	}
362966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
363966e225cSJerin Jacob }
364966e225cSJerin Jacob 
365966e225cSJerin Jacob int
366966e225cSJerin Jacob nicvf_mbox_update_hw_max_frs(struct nicvf *nic, uint16_t mtu)
367966e225cSJerin Jacob {
368*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
369966e225cSJerin Jacob 
370966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_SET_MAX_FRS;
371966e225cSJerin Jacob 	mbx.frs.max_frs = mtu;
372966e225cSJerin Jacob 	mbx.frs.vf_id = nic->vf_id;
373966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
374966e225cSJerin Jacob }
375966e225cSJerin Jacob 
376966e225cSJerin Jacob int
377966e225cSJerin Jacob nicvf_mbox_rq_sync(struct nicvf *nic)
378966e225cSJerin Jacob {
379*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
380966e225cSJerin Jacob 
381966e225cSJerin Jacob 	/* Make sure all packets in the pipeline are written back into mem */
382966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_RQ_SW_SYNC;
383966e225cSJerin Jacob 	mbx.rq.cfg = 0;
384966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
385966e225cSJerin Jacob }
386966e225cSJerin Jacob 
387966e225cSJerin Jacob int
388966e225cSJerin Jacob nicvf_mbox_rq_bp_config(struct nicvf *nic, uint16_t qidx, bool enable)
389966e225cSJerin Jacob {
390*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
391966e225cSJerin Jacob 
392966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_RQ_BP_CFG;
393966e225cSJerin Jacob 	mbx.rq.qs_num = nic->vf_id;
394966e225cSJerin Jacob 	mbx.rq.rq_num = qidx;
395966e225cSJerin Jacob 	mbx.rq.cfg = 0;
396966e225cSJerin Jacob 	if (enable)
397966e225cSJerin Jacob 		mbx.rq.cfg = (1ULL << 63) | (1ULL << 62) | (nic->vf_id << 0);
398966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
399966e225cSJerin Jacob }
400966e225cSJerin Jacob 
401966e225cSJerin Jacob int
402966e225cSJerin Jacob nicvf_mbox_loopback_config(struct nicvf *nic, bool enable)
403966e225cSJerin Jacob {
404*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
405966e225cSJerin Jacob 
406966e225cSJerin Jacob 	mbx.lbk.msg = NIC_MBOX_MSG_LOOPBACK;
407966e225cSJerin Jacob 	mbx.lbk.vf_id = nic->vf_id;
408966e225cSJerin Jacob 	mbx.lbk.enable = enable;
409966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
410966e225cSJerin Jacob }
411966e225cSJerin Jacob 
412966e225cSJerin Jacob int
413966e225cSJerin Jacob nicvf_mbox_reset_stat_counters(struct nicvf *nic, uint16_t rx_stat_mask,
414966e225cSJerin Jacob 			       uint8_t tx_stat_mask, uint16_t rq_stat_mask,
415966e225cSJerin Jacob 			       uint16_t sq_stat_mask)
416966e225cSJerin Jacob {
417*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
418966e225cSJerin Jacob 
419966e225cSJerin Jacob 	mbx.reset_stat.msg = NIC_MBOX_MSG_RESET_STAT_COUNTER;
420966e225cSJerin Jacob 	mbx.reset_stat.rx_stat_mask = rx_stat_mask;
421966e225cSJerin Jacob 	mbx.reset_stat.tx_stat_mask = tx_stat_mask;
422966e225cSJerin Jacob 	mbx.reset_stat.rq_stat_mask = rq_stat_mask;
423966e225cSJerin Jacob 	mbx.reset_stat.sq_stat_mask = sq_stat_mask;
424966e225cSJerin Jacob 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
425966e225cSJerin Jacob }
426966e225cSJerin Jacob 
427b8d96c71SHarman Kalra int
428b8d96c71SHarman Kalra nicvf_mbox_set_link_up_down(struct nicvf *nic, bool enable)
429b8d96c71SHarman Kalra {
430*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
431b8d96c71SHarman Kalra 
432b8d96c71SHarman Kalra 	mbx.lbk.msg = NIC_MBOX_MSG_SET_LINK;
433b8d96c71SHarman Kalra 	mbx.lbk.vf_id = nic->vf_id;
434b8d96c71SHarman Kalra 	mbx.lbk.enable = enable;
435b8d96c71SHarman Kalra 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
436b8d96c71SHarman Kalra }
4378f79c43fSHarman Kalra 
4388f79c43fSHarman Kalra 
4398f79c43fSHarman Kalra int
4408f79c43fSHarman Kalra nicvf_mbox_change_mode(struct nicvf *nic, struct change_link_mode *cfg)
4418f79c43fSHarman Kalra {
442*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
4438f79c43fSHarman Kalra 
4448f79c43fSHarman Kalra 	mbx.mode.msg = NIC_MBOX_MSG_CHANGE_MODE;
4458f79c43fSHarman Kalra 	mbx.mode.vf_id = nic->vf_id;
4468f79c43fSHarman Kalra 	mbx.mode.speed = cfg->speed;
4478f79c43fSHarman Kalra 	mbx.mode.duplex = cfg->duplex;
4488f79c43fSHarman Kalra 	mbx.mode.autoneg = cfg->autoneg;
4498f79c43fSHarman Kalra 	mbx.mode.qlm_mode = cfg->qlm_mode;
4508f79c43fSHarman Kalra 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
4518f79c43fSHarman Kalra }
4528f79c43fSHarman Kalra 
453966e225cSJerin Jacob void
454966e225cSJerin Jacob nicvf_mbox_shutdown(struct nicvf *nic)
455966e225cSJerin Jacob {
456*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
457966e225cSJerin Jacob 
458966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_SHUTDOWN;
459966e225cSJerin Jacob 	nicvf_mbox_send_msg_to_pf(nic, &mbx);
460966e225cSJerin Jacob }
461966e225cSJerin Jacob 
462966e225cSJerin Jacob void
463966e225cSJerin Jacob nicvf_mbox_cfg_done(struct nicvf *nic)
464966e225cSJerin Jacob {
465*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
466966e225cSJerin Jacob 
467966e225cSJerin Jacob 	mbx.msg.msg = NIC_MBOX_MSG_CFG_DONE;
468966e225cSJerin Jacob 	nicvf_mbox_send_async_msg_to_pf(nic, &mbx);
469966e225cSJerin Jacob }
4701f7b83b8SHanumanth Pothula 
4711f7b83b8SHanumanth Pothula void
4721f7b83b8SHanumanth Pothula nicvf_mbox_link_change(struct nicvf *nic)
4731f7b83b8SHanumanth Pothula {
474*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
4751f7b83b8SHanumanth Pothula 
4761f7b83b8SHanumanth Pothula 	mbx.msg.msg = NIC_MBOX_MSG_BGX_LINK_CHANGE;
4771f7b83b8SHanumanth Pothula 	nicvf_mbox_send_async_msg_to_pf(nic, &mbx);
4781f7b83b8SHanumanth Pothula }
479a32d2f5cSHanumanth Pothula 
480a32d2f5cSHanumanth Pothula void
481a32d2f5cSHanumanth Pothula nicvf_mbox_reset_xcast(struct nicvf *nic)
482a32d2f5cSHanumanth Pothula {
483*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
484a32d2f5cSHanumanth Pothula 
485a32d2f5cSHanumanth Pothula 	mbx.msg.msg = NIC_MBOX_MSG_RESET_XCAST;
486a32d2f5cSHanumanth Pothula 	nicvf_mbox_send_msg_to_pf(nic, &mbx);
487a32d2f5cSHanumanth Pothula }
48844a86354SHanumanth Pothula 
48944a86354SHanumanth Pothula int
49044a86354SHanumanth Pothula nicvf_mbox_set_xcast(struct nicvf *nic, uint8_t  mode, uint64_t mac)
49144a86354SHanumanth Pothula {
492*e7133f8fSStephen Hemminger 	struct nic_mbx mbx = { };
49344a86354SHanumanth Pothula 
49444a86354SHanumanth Pothula 	mbx.xcast.msg = NIC_MBOX_MSG_SET_XCAST;
49544a86354SHanumanth Pothula 	mbx.xcast.mode = mode;
49644a86354SHanumanth Pothula 	mbx.xcast.mac = mac;
49744a86354SHanumanth Pothula 
49844a86354SHanumanth Pothula 	return nicvf_mbox_send_msg_to_pf(nic, &mbx);
49944a86354SHanumanth Pothula }
500