xref: /freebsd/sys/dev/mana/shm_channel.c (revision fdafd315)
1ce110ea1SWei Hu /*-
2ce110ea1SWei Hu  * SPDX-License-Identifier: BSD-2-Clause
3ce110ea1SWei Hu  *
4ce110ea1SWei Hu  * Copyright (c) 2021 Microsoft Corp.
5ce110ea1SWei Hu  * All rights reserved.
6ce110ea1SWei Hu  *
7ce110ea1SWei Hu  * Redistribution and use in source and binary forms, with or without
8ce110ea1SWei Hu  * modification, are permitted provided that the following conditions
9ce110ea1SWei Hu  * are met:
10ce110ea1SWei Hu  *
11ce110ea1SWei Hu  * 1. Redistributions of source code must retain the above copyright
12ce110ea1SWei Hu  *    notice, this list of conditions and the following disclaimer.
13ce110ea1SWei Hu  *
14ce110ea1SWei Hu  * 2. Redistributions in binary form must reproduce the above copyright
15ce110ea1SWei Hu  *    notice, this list of conditions and the following disclaimer in the
16ce110ea1SWei Hu  *    documentation and/or other materials provided with the distribution.
17ce110ea1SWei Hu  *
18ce110ea1SWei Hu  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19ce110ea1SWei Hu  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20ce110ea1SWei Hu  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21ce110ea1SWei Hu  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22ce110ea1SWei Hu  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23ce110ea1SWei Hu  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24ce110ea1SWei Hu  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25ce110ea1SWei Hu  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26ce110ea1SWei Hu  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27ce110ea1SWei Hu  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28ce110ea1SWei Hu  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29ce110ea1SWei Hu  */
30fdafd315SWarner Losh 
31ce110ea1SWei Hu #include <sys/param.h>
32ce110ea1SWei Hu #include <sys/types.h>
33ce110ea1SWei Hu #include <sys/systm.h>
34ce110ea1SWei Hu #include <sys/bus.h>
35ce110ea1SWei Hu 
36ce110ea1SWei Hu #include "mana.h"
37ce110ea1SWei Hu #include "shm_channel.h"
38ce110ea1SWei Hu #include "gdma_util.h"
39ce110ea1SWei Hu 
40ce110ea1SWei Hu #define PAGE_FRAME_L48_WIDTH_BYTES 6
41ce110ea1SWei Hu #define PAGE_FRAME_L48_WIDTH_BITS (PAGE_FRAME_L48_WIDTH_BYTES * 8)
42ce110ea1SWei Hu #define PAGE_FRAME_L48_MASK 0x0000FFFFFFFFFFFF
43ce110ea1SWei Hu #define PAGE_FRAME_H4_WIDTH_BITS 4
44ce110ea1SWei Hu #define VECTOR_MASK 0xFFFF
45ce110ea1SWei Hu #define SHMEM_VF_RESET_STATE ((uint32_t)-1)
46ce110ea1SWei Hu 
47ce110ea1SWei Hu #define SMC_MSG_TYPE_ESTABLISH_HWC 1
48ce110ea1SWei Hu #define SMC_MSG_TYPE_ESTABLISH_HWC_VERSION 0
49ce110ea1SWei Hu 
50ce110ea1SWei Hu #define SMC_MSG_TYPE_DESTROY_HWC 2
51ce110ea1SWei Hu #define SMC_MSG_TYPE_DESTROY_HWC_VERSION 0
52ce110ea1SWei Hu 
53ce110ea1SWei Hu #define SMC_MSG_DIRECTION_REQUEST 0
54ce110ea1SWei Hu #define SMC_MSG_DIRECTION_RESPONSE 1
55ce110ea1SWei Hu 
56ce110ea1SWei Hu /* Structures labeled with "HW DATA" are exchanged with the hardware. All of
57ce110ea1SWei Hu  * them are naturally aligned and hence don't need __packed.
58ce110ea1SWei Hu  */
59ce110ea1SWei Hu 
60ce110ea1SWei Hu /* Shared memory channel protocol header
61ce110ea1SWei Hu  *
62ce110ea1SWei Hu  * msg_type: set on request and response; response matches request.
63ce110ea1SWei Hu  * msg_version: newer PF writes back older response (matching request)
64ce110ea1SWei Hu  *  older PF acts on latest version known and sets that version in result
65ce110ea1SWei Hu  *  (less than request).
66ce110ea1SWei Hu  * direction: 0 for request, VF->PF; 1 for response, PF->VF.
67ce110ea1SWei Hu  * status: 0 on request,
68ce110ea1SWei Hu  *   operation result on response (success = 0, failure = 1 or greater).
69ce110ea1SWei Hu  * reset_vf: If set on either establish or destroy request, indicates perform
70ce110ea1SWei Hu  *  FLR before/after the operation.
71ce110ea1SWei Hu  * owner_is_pf: 1 indicates PF owned, 0 indicates VF owned.
72ce110ea1SWei Hu  */
73ce110ea1SWei Hu union smc_proto_hdr {
74ce110ea1SWei Hu 	uint32_t as_uint32;
75ce110ea1SWei Hu 
76ce110ea1SWei Hu 	struct {
77ce110ea1SWei Hu 		uint8_t msg_type	: 3;
78ce110ea1SWei Hu 		uint8_t msg_version	: 3;
79ce110ea1SWei Hu 		uint8_t reserved_1	: 1;
80ce110ea1SWei Hu 		uint8_t direction	: 1;
81ce110ea1SWei Hu 
82ce110ea1SWei Hu 		uint8_t status;
83ce110ea1SWei Hu 
84ce110ea1SWei Hu 		uint8_t reserved_2;
85ce110ea1SWei Hu 
86ce110ea1SWei Hu 		uint8_t reset_vf	: 1;
87ce110ea1SWei Hu 		uint8_t reserved_3	: 6;
88ce110ea1SWei Hu 		uint8_t owner_is_pf	: 1;
89ce110ea1SWei Hu 	};
90ce110ea1SWei Hu }; /* HW DATA */
91ce110ea1SWei Hu 
92ce110ea1SWei Hu #define SMC_APERTURE_BITS 256
93ce110ea1SWei Hu #define SMC_BASIC_UNIT (sizeof(uint32_t))
94ce110ea1SWei Hu #define SMC_APERTURE_DWORDS (SMC_APERTURE_BITS / (SMC_BASIC_UNIT * 8))
95ce110ea1SWei Hu #define SMC_LAST_DWORD (SMC_APERTURE_DWORDS - 1)
96ce110ea1SWei Hu 
97ce110ea1SWei Hu static int
mana_smc_poll_register(void __iomem * base,bool reset)98ce110ea1SWei Hu mana_smc_poll_register(void __iomem *base, bool reset)
99ce110ea1SWei Hu {
100ce110ea1SWei Hu 	void __iomem *ptr = (uint8_t *)base + SMC_LAST_DWORD * SMC_BASIC_UNIT;
101ce110ea1SWei Hu 	volatile uint32_t last_dword;
102ce110ea1SWei Hu 	int i;
103ce110ea1SWei Hu 
104ce110ea1SWei Hu 	/* Poll the hardware for the ownership bit. This should be pretty fast,
105ce110ea1SWei Hu 	 * but let's do it in a loop just in case the hardware or the PF
106ce110ea1SWei Hu 	 * driver are temporarily busy.
107ce110ea1SWei Hu 	 */
108ce110ea1SWei Hu 	for (i = 0; i < 20 * 1000; i++)  {
109ce110ea1SWei Hu 		last_dword = readl(ptr);
110ce110ea1SWei Hu 
111ce110ea1SWei Hu 		/* shmem reads as 0xFFFFFFFF in the reset case */
112ce110ea1SWei Hu 		if (reset && last_dword == SHMEM_VF_RESET_STATE)
113ce110ea1SWei Hu 			return 0;
114ce110ea1SWei Hu 
115ce110ea1SWei Hu 		/* If bit_31 is set, the PF currently owns the SMC. */
116ce110ea1SWei Hu 		if (!(last_dword & BIT(31)))
117ce110ea1SWei Hu 			return 0;
118ce110ea1SWei Hu 
119ce110ea1SWei Hu 		DELAY(1000);
120ce110ea1SWei Hu 	}
121ce110ea1SWei Hu 
122ce110ea1SWei Hu 	return ETIMEDOUT;
123ce110ea1SWei Hu }
124ce110ea1SWei Hu 
125ce110ea1SWei Hu static int
mana_smc_read_response(struct shm_channel * sc,uint32_t msg_type,uint32_t msg_version,bool reset_vf)126ce110ea1SWei Hu mana_smc_read_response(struct shm_channel *sc, uint32_t msg_type,
127ce110ea1SWei Hu     uint32_t msg_version, bool reset_vf)
128ce110ea1SWei Hu {
129ce110ea1SWei Hu 	void __iomem *base = sc->base;
130ce110ea1SWei Hu 	union smc_proto_hdr hdr;
131ce110ea1SWei Hu 	int err;
132ce110ea1SWei Hu 
133ce110ea1SWei Hu 	/* Wait for PF to respond. */
134ce110ea1SWei Hu 	err = mana_smc_poll_register(base, reset_vf);
135ce110ea1SWei Hu 	if (err)
136ce110ea1SWei Hu 		return err;
137ce110ea1SWei Hu 
138ce110ea1SWei Hu 	hdr.as_uint32 =
139ce110ea1SWei Hu 	    readl((uint8_t *)base + SMC_LAST_DWORD * SMC_BASIC_UNIT);
140ce110ea1SWei Hu 	mana_dbg(NULL, "shm response 0x%x\n", hdr.as_uint32);
141ce110ea1SWei Hu 
142ce110ea1SWei Hu 	if (reset_vf && hdr.as_uint32 == SHMEM_VF_RESET_STATE)
143ce110ea1SWei Hu 		return 0;
144ce110ea1SWei Hu 
145ce110ea1SWei Hu 	/* Validate protocol fields from the PF driver */
146ce110ea1SWei Hu 	if (hdr.msg_type != msg_type || hdr.msg_version > msg_version ||
147ce110ea1SWei Hu 	    hdr.direction != SMC_MSG_DIRECTION_RESPONSE) {
148ce110ea1SWei Hu 		device_printf(sc->dev,
149ce110ea1SWei Hu 		    "Wrong SMC response 0x%x, type=%d, ver=%d\n",
150ce110ea1SWei Hu 		    hdr.as_uint32, msg_type, msg_version);
151ce110ea1SWei Hu 		return EPROTO;
152ce110ea1SWei Hu 	}
153ce110ea1SWei Hu 
154ce110ea1SWei Hu 	/* Validate the operation result */
155ce110ea1SWei Hu 	if (hdr.status != 0) {
156ce110ea1SWei Hu 		device_printf(sc->dev,
157ce110ea1SWei Hu 		    "SMC operation failed: 0x%x\n", hdr.status);
158ce110ea1SWei Hu 		return EPROTO;
159ce110ea1SWei Hu 	}
160ce110ea1SWei Hu 
161ce110ea1SWei Hu 	return 0;
162ce110ea1SWei Hu }
163ce110ea1SWei Hu 
164ce110ea1SWei Hu void
mana_smc_init(struct shm_channel * sc,device_t dev,void __iomem * base)165ce110ea1SWei Hu mana_smc_init(struct shm_channel *sc, device_t dev, void __iomem *base)
166ce110ea1SWei Hu {
167ce110ea1SWei Hu 	sc->dev = dev;
168ce110ea1SWei Hu 	sc->base = base;
169ce110ea1SWei Hu }
170ce110ea1SWei Hu 
171ce110ea1SWei Hu int
mana_smc_setup_hwc(struct shm_channel * sc,bool reset_vf,uint64_t eq_addr,uint64_t cq_addr,uint64_t rq_addr,uint64_t sq_addr,uint32_t eq_msix_index)172ce110ea1SWei Hu mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, uint64_t eq_addr,
173ce110ea1SWei Hu     uint64_t cq_addr, uint64_t rq_addr, uint64_t sq_addr,
174ce110ea1SWei Hu     uint32_t eq_msix_index)
175ce110ea1SWei Hu {
176ce110ea1SWei Hu 	union smc_proto_hdr *hdr;
177ce110ea1SWei Hu 	uint16_t all_addr_h4bits = 0;
178ce110ea1SWei Hu 	uint16_t frame_addr_seq = 0;
179ce110ea1SWei Hu 	uint64_t frame_addr = 0;
180ce110ea1SWei Hu 	uint8_t shm_buf[32];
181ce110ea1SWei Hu 	uint64_t *shmem;
182ce110ea1SWei Hu 	uint32_t *dword;
183ce110ea1SWei Hu 	uint8_t *ptr;
184ce110ea1SWei Hu 	int err;
185ce110ea1SWei Hu 	int i;
186ce110ea1SWei Hu 
187ce110ea1SWei Hu 	/* Ensure VF already has possession of shared memory */
188ce110ea1SWei Hu 	err = mana_smc_poll_register(sc->base, false);
189ce110ea1SWei Hu 	if (err) {
190ce110ea1SWei Hu 		device_printf(sc->dev,
191ce110ea1SWei Hu 		    "Timeout when setting up HWC: %d\n", err);
192ce110ea1SWei Hu 		return err;
193ce110ea1SWei Hu 	}
194ce110ea1SWei Hu 
195ce110ea1SWei Hu 	if (!IS_ALIGNED(eq_addr, PAGE_SIZE) ||
196ce110ea1SWei Hu 	    !IS_ALIGNED(cq_addr, PAGE_SIZE) ||
197ce110ea1SWei Hu 	    !IS_ALIGNED(rq_addr, PAGE_SIZE) ||
198ce110ea1SWei Hu 	    !IS_ALIGNED(sq_addr, PAGE_SIZE))
199ce110ea1SWei Hu 		return EINVAL;
200ce110ea1SWei Hu 
201ce110ea1SWei Hu 	if ((eq_msix_index & VECTOR_MASK) != eq_msix_index)
202ce110ea1SWei Hu 		return EINVAL;
203ce110ea1SWei Hu 
204ce110ea1SWei Hu 	/* Scheme for packing four addresses and extra info into 256 bits.
205ce110ea1SWei Hu 	 *
206ce110ea1SWei Hu 	 * Addresses must be page frame aligned, so only frame address bits
207ce110ea1SWei Hu 	 * are transferred.
208ce110ea1SWei Hu 	 *
209ce110ea1SWei Hu 	 * 52-bit frame addresses are split into the lower 48 bits and upper
210ce110ea1SWei Hu 	 * 4 bits. Lower 48 bits of 4 address are written sequentially from
211ce110ea1SWei Hu 	 * the start of the 256-bit shared memory region followed by 16 bits
212ce110ea1SWei Hu 	 * containing the upper 4 bits of the 4 addresses in sequence.
213ce110ea1SWei Hu 	 *
214ce110ea1SWei Hu 	 * A 16 bit EQ vector number fills out the next-to-last 32-bit dword.
215ce110ea1SWei Hu 	 *
216ce110ea1SWei Hu 	 * The final 32-bit dword is used for protocol control information as
217ce110ea1SWei Hu 	 * defined in smc_proto_hdr.
218ce110ea1SWei Hu 	 */
219ce110ea1SWei Hu 
220ce110ea1SWei Hu 	memset(shm_buf, 0, sizeof(shm_buf));
221ce110ea1SWei Hu 	ptr = shm_buf;
222ce110ea1SWei Hu 
223ce110ea1SWei Hu 	/* EQ addr: low 48 bits of frame address */
224ce110ea1SWei Hu 	shmem = (uint64_t *)ptr;
225ce110ea1SWei Hu 	frame_addr = PHYS_PFN(eq_addr);
226ce110ea1SWei Hu 	*shmem = frame_addr & PAGE_FRAME_L48_MASK;
227ce110ea1SWei Hu 	all_addr_h4bits |= (frame_addr >> PAGE_FRAME_L48_WIDTH_BITS) <<
228ce110ea1SWei Hu 		(frame_addr_seq++ * PAGE_FRAME_H4_WIDTH_BITS);
229ce110ea1SWei Hu 	ptr += PAGE_FRAME_L48_WIDTH_BYTES;
230ce110ea1SWei Hu 
231ce110ea1SWei Hu 	/* CQ addr: low 48 bits of frame address */
232ce110ea1SWei Hu 	shmem = (uint64_t *)ptr;
233ce110ea1SWei Hu 	frame_addr = PHYS_PFN(cq_addr);
234ce110ea1SWei Hu 	*shmem = frame_addr & PAGE_FRAME_L48_MASK;
235ce110ea1SWei Hu 	all_addr_h4bits |= (frame_addr >> PAGE_FRAME_L48_WIDTH_BITS) <<
236ce110ea1SWei Hu 		(frame_addr_seq++ * PAGE_FRAME_H4_WIDTH_BITS);
237ce110ea1SWei Hu 	ptr += PAGE_FRAME_L48_WIDTH_BYTES;
238ce110ea1SWei Hu 
239ce110ea1SWei Hu 	/* RQ addr: low 48 bits of frame address */
240ce110ea1SWei Hu 	shmem = (uint64_t *)ptr;
241ce110ea1SWei Hu 	frame_addr = PHYS_PFN(rq_addr);
242ce110ea1SWei Hu 	*shmem = frame_addr & PAGE_FRAME_L48_MASK;
243ce110ea1SWei Hu 	all_addr_h4bits |= (frame_addr >> PAGE_FRAME_L48_WIDTH_BITS) <<
244ce110ea1SWei Hu 		(frame_addr_seq++ * PAGE_FRAME_H4_WIDTH_BITS);
245ce110ea1SWei Hu 	ptr += PAGE_FRAME_L48_WIDTH_BYTES;
246ce110ea1SWei Hu 
247ce110ea1SWei Hu 	/* SQ addr: low 48 bits of frame address */
248ce110ea1SWei Hu 	shmem = (uint64_t *)ptr;
249ce110ea1SWei Hu 	frame_addr = PHYS_PFN(sq_addr);
250ce110ea1SWei Hu 	*shmem = frame_addr & PAGE_FRAME_L48_MASK;
251ce110ea1SWei Hu 	all_addr_h4bits |= (frame_addr >> PAGE_FRAME_L48_WIDTH_BITS) <<
252ce110ea1SWei Hu 		(frame_addr_seq++ * PAGE_FRAME_H4_WIDTH_BITS);
253ce110ea1SWei Hu 	ptr += PAGE_FRAME_L48_WIDTH_BYTES;
254ce110ea1SWei Hu 
255ce110ea1SWei Hu 	/* High 4 bits of the four frame addresses */
256ce110ea1SWei Hu 	*((uint16_t *)ptr) = all_addr_h4bits;
257ce110ea1SWei Hu 	ptr += sizeof(uint16_t);
258ce110ea1SWei Hu 
259ce110ea1SWei Hu 	/* EQ MSIX vector number */
260ce110ea1SWei Hu 	*((uint16_t *)ptr) = (uint16_t)eq_msix_index;
261ce110ea1SWei Hu 	ptr += sizeof(uint16_t);
262ce110ea1SWei Hu 
263ce110ea1SWei Hu 	/* 32-bit protocol header in final dword */
264ce110ea1SWei Hu 	*((uint32_t *)ptr) = 0;
265ce110ea1SWei Hu 
266ce110ea1SWei Hu 	hdr = (union smc_proto_hdr *)ptr;
267ce110ea1SWei Hu 	hdr->msg_type = SMC_MSG_TYPE_ESTABLISH_HWC;
268ce110ea1SWei Hu 	hdr->msg_version = SMC_MSG_TYPE_ESTABLISH_HWC_VERSION;
269ce110ea1SWei Hu 	hdr->direction = SMC_MSG_DIRECTION_REQUEST;
270ce110ea1SWei Hu 	hdr->reset_vf = reset_vf;
271ce110ea1SWei Hu 
272ce110ea1SWei Hu 	/* Write 256-message buffer to shared memory (final 32-bit write
273ce110ea1SWei Hu 	 * triggers HW to set possession bit to PF).
274ce110ea1SWei Hu 	 */
275ce110ea1SWei Hu 	dword = (uint32_t *)shm_buf;
276ce110ea1SWei Hu 	for (i = 0; i < SMC_APERTURE_DWORDS; i++) {
277ce110ea1SWei Hu 		mana_dbg(NULL, "write shm_buf %d, val: 0x%x\n",
278ce110ea1SWei Hu 		    i, *dword);
279ce110ea1SWei Hu 		writel((char *)sc->base + i * SMC_BASIC_UNIT, *dword++);
280ce110ea1SWei Hu 	}
281ce110ea1SWei Hu 
282ce110ea1SWei Hu 	/* Read shmem response (polling for VF possession) and validate.
283ce110ea1SWei Hu 	 * For setup, waiting for response on shared memory is not strictly
284ce110ea1SWei Hu 	 * necessary, since wait occurs later for results to appear in EQE's.
285ce110ea1SWei Hu 	 */
286ce110ea1SWei Hu 	err = mana_smc_read_response(sc, SMC_MSG_TYPE_ESTABLISH_HWC,
287ce110ea1SWei Hu 	    SMC_MSG_TYPE_ESTABLISH_HWC_VERSION, reset_vf);
288ce110ea1SWei Hu 	if (err) {
289ce110ea1SWei Hu 		device_printf(sc->dev,
290ce110ea1SWei Hu 		    "Error when setting up HWC: %d\n", err);
291ce110ea1SWei Hu 		return err;
292ce110ea1SWei Hu 	}
293ce110ea1SWei Hu 
294ce110ea1SWei Hu 	return 0;
295ce110ea1SWei Hu }
296ce110ea1SWei Hu 
297ce110ea1SWei Hu int
mana_smc_teardown_hwc(struct shm_channel * sc,bool reset_vf)298ce110ea1SWei Hu mana_smc_teardown_hwc(struct shm_channel *sc, bool reset_vf)
299ce110ea1SWei Hu {
300ce110ea1SWei Hu 	union smc_proto_hdr hdr = {};
301ce110ea1SWei Hu 	int err;
302ce110ea1SWei Hu 
303ce110ea1SWei Hu 	/* Ensure already has possession of shared memory */
304ce110ea1SWei Hu 	err = mana_smc_poll_register(sc->base, false);
305ce110ea1SWei Hu 	if (err) {
306ce110ea1SWei Hu 		device_printf(sc->dev, "Timeout when tearing down HWC\n");
307ce110ea1SWei Hu 		return err;
308ce110ea1SWei Hu 	}
309ce110ea1SWei Hu 
310ce110ea1SWei Hu 	/* Set up protocol header for HWC destroy message */
311ce110ea1SWei Hu 	hdr.msg_type = SMC_MSG_TYPE_DESTROY_HWC;
312ce110ea1SWei Hu 	hdr.msg_version = SMC_MSG_TYPE_DESTROY_HWC_VERSION;
313ce110ea1SWei Hu 	hdr.direction = SMC_MSG_DIRECTION_REQUEST;
314ce110ea1SWei Hu 	hdr.reset_vf = reset_vf;
315ce110ea1SWei Hu 
316ce110ea1SWei Hu 	/* Write message in high 32 bits of 256-bit shared memory, causing HW
317ce110ea1SWei Hu 	 * to set possession bit to PF.
318ce110ea1SWei Hu 	 */
319ce110ea1SWei Hu 	writel((char *)sc->base + SMC_LAST_DWORD * SMC_BASIC_UNIT,
320ce110ea1SWei Hu 	    hdr.as_uint32);
321ce110ea1SWei Hu 
322ce110ea1SWei Hu 	/* Read shmem response (polling for VF possession) and validate.
323ce110ea1SWei Hu 	 * For teardown, waiting for response is required to ensure hardware
324ce110ea1SWei Hu 	 * invalidates MST entries before software frees memory.
325ce110ea1SWei Hu 	 */
326ce110ea1SWei Hu 	err = mana_smc_read_response(sc, SMC_MSG_TYPE_DESTROY_HWC,
327ce110ea1SWei Hu 	    SMC_MSG_TYPE_DESTROY_HWC_VERSION, reset_vf);
328ce110ea1SWei Hu 	if (err) {
329ce110ea1SWei Hu 		device_printf(sc->dev,
330ce110ea1SWei Hu 		    "Error when tearing down HWC: %d\n", err);
331ce110ea1SWei Hu 		return err;
332ce110ea1SWei Hu 	}
333ce110ea1SWei Hu 
334ce110ea1SWei Hu 	return 0;
335ce110ea1SWei Hu }
336