2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2010-2016 Freescale Semiconductor Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the above-listed copyright holders nor the
18 * names of any contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
43 #include <sys/ioctl.h>
45 #include <net/if_arp.h>
49 #include <rte_malloc.h>
51 #include <rte_dpaa_logs.h>
54 /* Structure contains information about all the interfaces given by user
57 struct netcfg_interface *netcfg_interface;
59 /* This data structure contaings all configurations information
60 * related to usages of DPA devices.
62 struct netcfg_info *netcfg;
63 /* fd to open a socket for making ioctl request to disable/enable shared
68 #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
70 dump_netcfg(struct netcfg_info *cfg_ptr)
74 printf(".......... DPAA Configuration ..........\n\n");
76 /* Network interfaces */
77 printf("Network interfaces: %d\n", cfg_ptr->num_ethports);
78 for (i = 0; i < cfg_ptr->num_ethports; i++) {
79 struct fman_if_bpool *bpool;
80 struct fm_eth_port_cfg *p_cfg = &cfg_ptr->port_cfg[i];
81 struct fman_if *__if = p_cfg->fman_if;
83 printf("\n+ Fman %d, MAC %d (%s);\n",
84 __if->fman_idx, __if->mac_idx,
85 (__if->mac_type == fman_mac_1g) ? "1G" : "10G");
87 printf("\tmac_addr: %02x:%02x:%02x:%02x:%02x:%02x\n",
88 (&__if->mac_addr)->addr_bytes[0],
89 (&__if->mac_addr)->addr_bytes[1],
90 (&__if->mac_addr)->addr_bytes[2],
91 (&__if->mac_addr)->addr_bytes[3],
92 (&__if->mac_addr)->addr_bytes[4],
93 (&__if->mac_addr)->addr_bytes[5]);
95 printf("\ttx_channel_id: 0x%02x\n",
98 printf("\tfqid_rx_def: 0x%x\n", p_cfg->rx_def);
99 printf("\tfqid_rx_err: 0x%x\n", __if->fqid_rx_err);
101 printf("\tfqid_tx_err: 0x%x\n", __if->fqid_tx_err);
102 printf("\tfqid_tx_confirm: 0x%x\n", __if->fqid_tx_confirm);
103 fman_if_for_each_bpool(bpool, __if)
104 printf("\tbuffer pool: (bpid=%d, count=%"PRId64
105 " size=%"PRId64", addr=0x%"PRIx64")\n",
106 bpool->bpid, bpool->count, bpool->size,
110 #endif /* RTE_LIBRTE_DPAA_DEBUG_DRIVER */
113 get_num_netcfg_interfaces(char *str)
120 pch = strtok(str, ",");
121 while (pch != NULL) {
123 pch = strtok(NULL, ",");
131 struct fman_if *__if;
133 uint8_t num_ports = 0;
134 uint8_t num_cfg_ports = 0;
137 /* Extract dpa configuration from fman driver and FMC configuration
138 * for command-line interfaces.
141 /* Open a basic socket to enable/disable shared
144 skfd = socket(AF_PACKET, SOCK_RAW, 0);
145 if (unlikely(skfd < 0)) {
146 error(0, errno, "%s(): open(SOCK_RAW)", __func__);
150 /* Initialise the Fman driver */
151 _errno = fman_init();
153 DPAA_BUS_LOG(ERR, "FMAN driver init failed (%d)", errno);
159 /* Number of MAC ports */
160 list_for_each_entry(__if, fman_if_list, node)
164 DPAA_BUS_LOG(ERR, "FMAN ports not available");
167 /* Allocate space for all enabled mac ports */
168 size = sizeof(*netcfg) +
169 (num_ports * sizeof(struct fm_eth_port_cfg));
171 netcfg = calloc(1, size);
172 if (unlikely(netcfg == NULL)) {
173 DPAA_BUS_LOG(ERR, "Unable to allocat mem for netcfg");
177 netcfg->num_ethports = num_ports;
179 list_for_each_entry(__if, fman_if_list, node) {
180 struct fm_eth_port_cfg *cfg = &netcfg->port_cfg[idx];
181 /* Hook in the fman driver interface */
183 cfg->rx_def = __if->fqid_rx_def;
188 if (!num_cfg_ports) {
189 DPAA_BUS_LOG(ERR, "No FMAN ports found");
191 } else if (num_ports != num_cfg_ports)
192 netcfg->num_ethports = num_cfg_ports;
206 netcfg_release(struct netcfg_info *cfg_ptr)
209 /* Close socket for shared interfaces */