4 * Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Freescale Semiconductor, Inc nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/types.h>
42 #include <sys/syscall.h>
44 #include <rte_config.h>
45 #include <rte_byteorder.h>
46 #include <rte_common.h>
47 #include <rte_interrupts.h>
49 #include <rte_debug.h>
51 #include <rte_atomic.h>
52 #include <rte_branch_prediction.h>
53 #include <rte_memory.h>
54 #include <rte_memzone.h>
55 #include <rte_tailq.h>
57 #include <rte_alarm.h>
58 #include <rte_ether.h>
59 #include <rte_ethdev.h>
60 #include <rte_malloc.h>
63 #include <rte_dpaa_bus.h>
64 #include <rte_dpaa_logs.h>
66 #include <dpaa_ethdev.h>
68 /* Keep track of whether QMAN and BMAN have been globally initialized */
69 static int is_global_init;
72 dpaa_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
74 PMD_INIT_FUNC_TRACE();
79 static int dpaa_eth_dev_start(struct rte_eth_dev *dev)
81 PMD_INIT_FUNC_TRACE();
83 /* Change tx callback to the real one */
84 dev->tx_pkt_burst = NULL;
89 static void dpaa_eth_dev_stop(struct rte_eth_dev *dev)
91 dev->tx_pkt_burst = NULL;
94 static void dpaa_eth_dev_close(struct rte_eth_dev *dev __rte_unused)
96 PMD_INIT_FUNC_TRACE();
99 static struct eth_dev_ops dpaa_devops = {
100 .dev_configure = dpaa_eth_dev_configure,
101 .dev_start = dpaa_eth_dev_start,
102 .dev_stop = dpaa_eth_dev_stop,
103 .dev_close = dpaa_eth_dev_close,
106 /* Initialise a network interface */
108 dpaa_dev_init(struct rte_eth_dev *eth_dev)
111 struct rte_dpaa_device *dpaa_device;
112 struct dpaa_if *dpaa_intf;
114 PMD_INIT_FUNC_TRACE();
116 /* For secondary processes, the primary has done all the work */
117 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
120 dpaa_device = DEV_TO_DPAA_DEVICE(eth_dev->device);
121 dev_id = dpaa_device->id.dev_id;
122 dpaa_intf = eth_dev->data->dev_private;
124 dpaa_intf->name = dpaa_device->name;
126 dpaa_intf->ifid = dev_id;
128 eth_dev->dev_ops = &dpaa_devops;
134 dpaa_dev_uninit(struct rte_eth_dev *dev)
136 struct dpaa_if *dpaa_intf = dev->data->dev_private;
138 PMD_INIT_FUNC_TRACE();
140 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
144 DPAA_PMD_WARN("Already closed or not started");
148 dpaa_eth_dev_close(dev);
151 dev->rx_pkt_burst = NULL;
152 dev->tx_pkt_burst = NULL;
158 rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv,
159 struct rte_dpaa_device *dpaa_dev)
163 struct rte_eth_dev *eth_dev;
165 PMD_INIT_FUNC_TRACE();
167 /* In case of secondary process, the device is already configured
168 * and no further action is required, except portal initialization
169 * and verifying secondary attachment to port name.
171 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
172 eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
178 if (!is_global_init) {
179 /* One time load of Qman/Bman drivers */
180 ret = qman_global_init();
182 DPAA_PMD_ERR("QMAN initialization failed: %d",
186 ret = bman_global_init();
188 DPAA_PMD_ERR("BMAN initialization failed: %d",
196 ret = rte_dpaa_portal_init((void *)1);
198 DPAA_PMD_ERR("Unable to initialize portal");
202 eth_dev = rte_eth_dev_allocate(dpaa_dev->name);
206 eth_dev->data->dev_private = rte_zmalloc(
207 "ethdev private structure",
208 sizeof(struct dpaa_if),
209 RTE_CACHE_LINE_SIZE);
210 if (!eth_dev->data->dev_private) {
211 DPAA_PMD_ERR("Cannot allocate memzone for port data");
212 rte_eth_dev_release_port(eth_dev);
216 eth_dev->device = &dpaa_dev->device;
217 eth_dev->device->driver = &dpaa_drv->driver;
218 dpaa_dev->eth_dev = eth_dev;
220 /* Invoke PMD device initialization function */
221 diag = dpaa_dev_init(eth_dev);
225 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
226 rte_free(eth_dev->data->dev_private);
228 rte_eth_dev_release_port(eth_dev);
233 rte_dpaa_remove(struct rte_dpaa_device *dpaa_dev)
235 struct rte_eth_dev *eth_dev;
237 PMD_INIT_FUNC_TRACE();
239 eth_dev = dpaa_dev->eth_dev;
240 dpaa_dev_uninit(eth_dev);
242 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
243 rte_free(eth_dev->data->dev_private);
245 rte_eth_dev_release_port(eth_dev);
250 static struct rte_dpaa_driver rte_dpaa_pmd = {
251 .drv_type = FSL_DPAA_ETH,
252 .probe = rte_dpaa_probe,
253 .remove = rte_dpaa_remove,
256 RTE_PMD_REGISTER_DPAA(net_dpaa, rte_dpaa_pmd);