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
sfc_mcdi_dma_alloc(void * cookie,const char * name,size_t len,efsys_mem_t * esmp)19 sfc_mcdi_dma_alloc(void *cookie, const char *name, size_t len,
20 efsys_mem_t *esmp)
21 {
22 struct sfc_adapter *sa = cookie;
23
24 return sfc_dma_alloc(sa, name, 0, EFX_NIC_DMA_ADDR_MCDI_BUF, len,
25 sa->socket_id, esmp);
26 }
27
28 static sfc_efx_mcdi_dma_free_cb sfc_mcdi_dma_free;
29 static void
sfc_mcdi_dma_free(void * cookie,efsys_mem_t * esmp)30 sfc_mcdi_dma_free(void *cookie, efsys_mem_t *esmp)
31 {
32 const struct sfc_adapter *sa = cookie;
33
34 sfc_dma_free(sa, esmp);
35 }
36
37 static sfc_efx_mcdi_sched_restart_cb sfc_mcdi_sched_restart;
38 static void
sfc_mcdi_sched_restart(void * cookie)39 sfc_mcdi_sched_restart(void *cookie)
40 {
41 struct sfc_adapter *sa = cookie;
42
43 sfc_schedule_restart(sa);
44 }
45
46 static sfc_efx_mcdi_mgmt_evq_poll_cb sfc_mcdi_mgmt_evq_poll;
47 static void
sfc_mcdi_mgmt_evq_poll(void * cookie)48 sfc_mcdi_mgmt_evq_poll(void *cookie)
49 {
50 struct sfc_adapter *sa = cookie;
51
52 sfc_ev_mgmt_qpoll(sa);
53 }
54
55 static const struct sfc_efx_mcdi_ops sfc_mcdi_ops = {
56 .dma_alloc = sfc_mcdi_dma_alloc,
57 .dma_free = sfc_mcdi_dma_free,
58 .sched_restart = sfc_mcdi_sched_restart,
59 .mgmt_evq_poll = sfc_mcdi_mgmt_evq_poll,
60 };
61
62 int
sfc_mcdi_init(struct sfc_adapter * sa)63 sfc_mcdi_init(struct sfc_adapter *sa)
64 {
65 uint32_t logtype;
66
67 sfc_log_init(sa, "entry");
68
69 logtype = sfc_register_logtype(&sa->priv.shared->pci_addr,
70 SFC_LOGTYPE_MCDI_STR,
71 RTE_LOG_NOTICE);
72
73 return sfc_efx_mcdi_init(&sa->mcdi, logtype,
74 sa->priv.shared->log_prefix, sa->nic,
75 &sfc_mcdi_ops, sa);
76 }
77
78 void
sfc_mcdi_fini(struct sfc_adapter * sa)79 sfc_mcdi_fini(struct sfc_adapter *sa)
80 {
81 sfc_log_init(sa, "entry");
82 sfc_efx_mcdi_fini(&sa->mcdi);
83 }
84