1a237650cdceda986041164b7ddbbf2122c9ed51
[dpdk.git] / drivers / net / sfc / sfc_mcdi.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2016-2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #include "sfc_efx_mcdi.h"
11
12 #include "sfc.h"
13 #include "sfc_debug.h"
14 #include "sfc_log.h"
15 #include "sfc_ev.h"
16
17 static sfc_efx_mcdi_dma_alloc_cb sfc_mcdi_dma_alloc;
18 static int
19 sfc_mcdi_dma_alloc(void *cookie, const char *name, size_t len,
20                    efsys_mem_t *esmp)
21 {
22         const struct sfc_adapter *sa = cookie;
23
24         return sfc_dma_alloc(sa, name, 0, len, sa->socket_id, esmp);
25 }
26
27 static sfc_efx_mcdi_dma_free_cb sfc_mcdi_dma_free;
28 static void
29 sfc_mcdi_dma_free(void *cookie, efsys_mem_t *esmp)
30 {
31         const struct sfc_adapter *sa = cookie;
32
33         sfc_dma_free(sa, esmp);
34 }
35
36 static sfc_efx_mcdi_sched_restart_cb sfc_mcdi_sched_restart;
37 static void
38 sfc_mcdi_sched_restart(void *cookie)
39 {
40         struct sfc_adapter *sa = cookie;
41
42         sfc_schedule_restart(sa);
43 }
44
45 static sfc_efx_mcdi_mgmt_evq_poll_cb sfc_mcdi_mgmt_evq_poll;
46 static void
47 sfc_mcdi_mgmt_evq_poll(void *cookie)
48 {
49         struct sfc_adapter *sa = cookie;
50
51         sfc_ev_mgmt_qpoll(sa);
52 }
53
54 static const struct sfc_efx_mcdi_ops sfc_mcdi_ops = {
55         .dma_alloc      = sfc_mcdi_dma_alloc,
56         .dma_free       = sfc_mcdi_dma_free,
57         .sched_restart  = sfc_mcdi_sched_restart,
58         .mgmt_evq_poll  = sfc_mcdi_mgmt_evq_poll,
59 };
60
61 int
62 sfc_mcdi_init(struct sfc_adapter *sa)
63 {
64         uint32_t logtype;
65
66         sfc_log_init(sa, "entry");
67
68         logtype = sfc_register_logtype(&sa->priv.shared->pci_addr,
69                                        SFC_LOGTYPE_MCDI_STR,
70                                        RTE_LOG_NOTICE);
71
72         return sfc_efx_mcdi_init(&sa->mcdi, logtype,
73                                  sa->priv.shared->log_prefix, sa->nic,
74                                  &sfc_mcdi_ops, sa);
75 }
76
77 void
78 sfc_mcdi_fini(struct sfc_adapter *sa)
79 {
80         sfc_log_init(sa, "entry");
81         sfc_efx_mcdi_fini(&sa->mcdi);
82 }