1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2020-2021 Xilinx, Inc.
11 #if EFSYS_OPT_RIVERHEAD
12 static const efx_virtio_ops_t __efx_virtio_rhead_ops = {
13 rhead_virtio_qstart, /* evo_virtio_qstart */
14 rhead_virtio_qstop, /* evo_virtio_qstop */
15 rhead_virtio_get_doorbell_offset, /* evo_get_doorbell_offset */
16 rhead_virtio_get_features, /* evo_get_features */
17 rhead_virtio_verify_features, /* evo_verify_features */
19 #endif /* EFSYS_OPT_RIVERHEAD */
21 __checkReturn efx_rc_t
25 const efx_virtio_ops_t *evop;
28 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
29 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
30 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_VIRTIO));
32 switch (enp->en_family) {
33 #if EFSYS_OPT_RIVERHEAD
34 case EFX_FAMILY_RIVERHEAD:
35 evop = &__efx_virtio_rhead_ops;
37 #endif /* EFSYS_OPT_RIVERHEAD */
46 enp->en_mod_flags |= EFX_MOD_VIRTIO;
51 EFSYS_PROBE1(fail1, efx_rc_t, rc);
54 enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
63 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
64 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
65 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
68 enp->en_mod_flags &= ~EFX_MOD_VIRTIO;
71 __checkReturn efx_rc_t
74 __deref_out efx_virtio_vq_t **evvpp)
76 const efx_virtio_ops_t *evop = enp->en_evop;
77 efx_virtio_vq_t *evvp;
80 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
81 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
83 /* Allocate a virtqueue object */
84 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
90 evvp->evv_magic = EFX_VQ_MAGIC;
92 evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
99 EFSYS_PROBE1(fail1, efx_rc_t, rc);
104 __checkReturn efx_rc_t
106 __in efx_virtio_vq_t *evvp,
107 __in efx_virtio_vq_cfg_t *evvcp,
108 __in_opt efx_virtio_vq_dyncfg_t *evvdp)
110 const efx_virtio_ops_t *evop;
113 if ((evvcp == NULL) || (evvp == NULL)) {
118 if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_INITIALIZED) {
123 evop = evvp->evv_enp->en_evop;
129 if ((rc = evop->evo_virtio_qstart(evvp, evvcp, evvdp)) != 0)
132 evvp->evv_type = evvcp->evvc_type;
133 evvp->evv_target_vf = evvcp->evvc_target_vf;
134 evvp->evv_state = EFX_VIRTIO_VQ_STATE_STARTED;
145 EFSYS_PROBE1(fail1, efx_rc_t, rc);
150 __checkReturn efx_rc_t
152 __in efx_virtio_vq_t *evvp,
153 __out_opt efx_virtio_vq_dyncfg_t *evvdp)
156 const efx_virtio_ops_t *evop;
167 EFSYS_ASSERT3U(evvp->evv_magic, ==, EFX_VQ_MAGIC);
168 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
169 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
176 if (evvp->evv_state != EFX_VIRTIO_VQ_STATE_STARTED) {
181 if ((rc = evop->evo_virtio_qstop(evvp, evvdp)) != 0)
184 evvp->evv_state = EFX_VIRTIO_VQ_STATE_INITIALIZED;
195 EFSYS_PROBE1(fail1, efx_rc_t, rc);
202 __in efx_virtio_vq_t *evvp)
211 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
213 if (evvp->evv_state == EFX_VIRTIO_VQ_STATE_INITIALIZED) {
214 /* Free the virtqueue object */
215 EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_virtio_vq_t), evvp);
219 __checkReturn efx_rc_t
220 efx_virtio_get_doorbell_offset(
221 __in efx_virtio_vq_t *evvp,
222 __out uint32_t *offsetp)
225 const efx_virtio_ops_t *evop;
228 if ((evvp == NULL) || (offsetp == NULL)) {
236 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
237 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
244 if ((rc = evop->evo_get_doorbell_offset(evvp, offsetp)) != 0)
254 EFSYS_PROBE1(fail1, efx_rc_t, rc);
259 __checkReturn efx_rc_t
260 efx_virtio_get_features(
262 __in efx_virtio_device_type_t type,
263 __out uint64_t *featuresp)
265 const efx_virtio_ops_t *evop = enp->en_evop;
268 if (featuresp == NULL) {
273 if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
278 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
279 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
286 if ((rc = evop->evo_get_features(enp, type, featuresp)) != 0)
298 EFSYS_PROBE1(fail1, efx_rc_t, rc);
303 __checkReturn efx_rc_t
304 efx_virtio_verify_features(
306 __in efx_virtio_device_type_t type,
307 __in uint64_t features)
309 const efx_virtio_ops_t *evop = enp->en_evop;
312 if (type >= EFX_VIRTIO_DEVICE_NTYPES) {
317 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
318 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_VIRTIO);
325 if ((rc = evop->evo_verify_features(enp, type, features)) != 0)
335 EFSYS_PROBE1(fail1, efx_rc_t, rc);
340 #endif /* EFSYS_OPT_VIRTIO */