2 * Copyright (c) 2016 Solarflare Communications Inc.
5 * This software was jointly developed between OKTET Labs (under contract
6 * for Solarflare) and Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <rte_ethdev.h>
37 #include "sfc_debug.h"
39 #include "sfc_kvargs.h"
43 sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
45 struct sfc_adapter *sa = dev->data->dev_private;
47 sfc_log_init(sa, "entry");
49 dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
53 sfc_dev_configure(struct rte_eth_dev *dev)
55 struct rte_eth_dev_data *dev_data = dev->data;
56 struct sfc_adapter *sa = dev_data->dev_private;
59 sfc_log_init(sa, "entry n_rxq=%u n_txq=%u",
60 dev_data->nb_rx_queues, dev_data->nb_tx_queues);
64 case SFC_ADAPTER_CONFIGURED:
66 SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED);
68 case SFC_ADAPTER_INITIALIZED:
69 rc = sfc_configure(sa);
72 sfc_err(sa, "unexpected adapter state %u to configure",
77 sfc_adapter_unlock(sa);
79 sfc_log_init(sa, "done %d", rc);
85 sfc_dev_close(struct rte_eth_dev *dev)
87 struct sfc_adapter *sa = dev->data->dev_private;
89 sfc_log_init(sa, "entry");
93 case SFC_ADAPTER_CONFIGURED:
95 SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED);
97 case SFC_ADAPTER_INITIALIZED:
100 sfc_err(sa, "unexpected adapter state %u on close", sa->state);
103 sfc_adapter_unlock(sa);
105 sfc_log_init(sa, "done");
108 static const struct eth_dev_ops sfc_eth_dev_ops = {
109 .dev_configure = sfc_dev_configure,
110 .dev_close = sfc_dev_close,
111 .dev_infos_get = sfc_dev_infos_get,
115 sfc_eth_dev_init(struct rte_eth_dev *dev)
117 struct sfc_adapter *sa = dev->data->dev_private;
118 struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(dev);
120 const efx_nic_cfg_t *encp;
121 const struct ether_addr *from;
123 /* Required for logging */
126 /* Copy PCI device info to the dev->data */
127 rte_eth_copy_pci_info(dev, pci_dev);
129 rc = sfc_kvargs_parse(sa);
131 goto fail_kvargs_parse;
133 rc = sfc_kvargs_process(sa, SFC_KVARG_DEBUG_INIT,
134 sfc_kvarg_bool_handler, &sa->debug_init);
136 goto fail_kvarg_debug_init;
138 sfc_log_init(sa, "entry");
140 dev->data->mac_addrs = rte_zmalloc("sfc", ETHER_ADDR_LEN, 0);
141 if (dev->data->mac_addrs == NULL) {
146 sfc_adapter_lock_init(sa);
147 sfc_adapter_lock(sa);
149 sfc_log_init(sa, "attaching");
154 encp = efx_nic_cfg_get(sa->nic);
157 * The arguments are really reverse order in comparison to
158 * Linux kernel. Copy from NIC config to Ethernet device data.
160 from = (const struct ether_addr *)(encp->enc_mac_addr);
161 ether_addr_copy(from, &dev->data->mac_addrs[0]);
163 dev->dev_ops = &sfc_eth_dev_ops;
165 sfc_adapter_unlock(sa);
167 sfc_log_init(sa, "done");
171 sfc_adapter_unlock(sa);
172 sfc_adapter_lock_fini(sa);
173 rte_free(dev->data->mac_addrs);
174 dev->data->mac_addrs = NULL;
177 fail_kvarg_debug_init:
178 sfc_kvargs_cleanup(sa);
181 sfc_log_init(sa, "failed %d", rc);
187 sfc_eth_dev_uninit(struct rte_eth_dev *dev)
189 struct sfc_adapter *sa = dev->data->dev_private;
191 sfc_log_init(sa, "entry");
193 sfc_adapter_lock(sa);
197 rte_free(dev->data->mac_addrs);
198 dev->data->mac_addrs = NULL;
202 sfc_kvargs_cleanup(sa);
204 sfc_adapter_unlock(sa);
205 sfc_adapter_lock_fini(sa);
207 sfc_log_init(sa, "done");
209 /* Required for logging, so cleanup last */
214 static const struct rte_pci_id pci_id_sfc_efx_map[] = {
215 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE) },
216 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT) },
217 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD) },
218 { .vendor_id = 0 /* sentinel */ }
221 static struct eth_driver sfc_efx_pmd = {
223 .id_table = pci_id_sfc_efx_map,
225 RTE_PCI_DRV_NEED_MAPPING,
226 .probe = rte_eth_dev_pci_probe,
227 .remove = rte_eth_dev_pci_remove,
229 .eth_dev_init = sfc_eth_dev_init,
230 .eth_dev_uninit = sfc_eth_dev_uninit,
231 .dev_private_size = sizeof(struct sfc_adapter),
234 RTE_PMD_REGISTER_PCI(net_sfc_efx, sfc_efx_pmd.pci_drv);
235 RTE_PMD_REGISTER_PCI_TABLE(net_sfc_efx, pci_id_sfc_efx_map);
236 RTE_PMD_REGISTER_PARAM_STRING(net_sfc_efx,
237 SFC_KVARG_DEBUG_INIT "=" SFC_KVARG_VALUES_BOOL);