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.
36 * Update MAC statistics in the buffer.
42 * @retval EAGAIN Try again
43 * @retval ENOMEM Memory allocation failure
46 sfc_port_update_mac_stats(struct sfc_adapter *sa)
48 struct sfc_port *port = &sa->port;
51 SFC_ASSERT(rte_spinlock_is_locked(&port->mac_stats_lock));
53 if (sa->state != SFC_ADAPTER_STARTED)
56 rc = efx_mac_stats_update(sa->nic, &port->mac_stats_dma_mem,
57 port->mac_stats_buf, NULL);
65 sfc_port_start(struct sfc_adapter *sa)
67 struct sfc_port *port = &sa->port;
70 sfc_log_init(sa, "entry");
72 sfc_log_init(sa, "init filters");
73 rc = efx_filter_init(sa->nic);
75 goto fail_filter_init;
77 sfc_log_init(sa, "init port");
78 rc = efx_port_init(sa->nic);
82 sfc_log_init(sa, "set flow control to %#x autoneg=%u",
83 port->flow_ctrl, port->flow_ctrl_autoneg);
84 rc = efx_mac_fcntl_set(sa->nic, port->flow_ctrl,
85 port->flow_ctrl_autoneg);
87 goto fail_mac_fcntl_set;
89 sfc_log_init(sa, "set phy adv caps to %#x", port->phy_adv_cap);
90 rc = efx_phy_adv_cap_set(sa->nic, port->phy_adv_cap);
92 goto fail_phy_adv_cap_set;
94 sfc_log_init(sa, "set MAC PDU %u", (unsigned int)port->pdu);
95 rc = efx_mac_pdu_set(sa->nic, port->pdu);
97 goto fail_mac_pdu_set;
99 sfc_log_init(sa, "set MAC address");
100 rc = efx_mac_addr_set(sa->nic,
101 sa->eth_dev->data->mac_addrs[0].addr_bytes);
103 goto fail_mac_addr_set;
105 sfc_log_init(sa, "set MAC filters");
106 port->promisc = (sa->eth_dev->data->promiscuous != 0) ?
108 port->allmulti = (sa->eth_dev->data->all_multicast != 0) ?
110 rc = sfc_set_rx_mode(sa);
112 goto fail_mac_filter_set;
114 efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask,
115 sizeof(port->mac_stats_mask));
117 /* Update MAC stats using periodic DMA.
118 * Common code always uses 1000ms update period, so period_ms
119 * parameter only needs to be non-zero to start updates.
121 sfc_log_init(sa, "request MAC stats DMA'ing");
122 rc = efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem,
125 goto fail_mac_stats_periodic;
127 sfc_log_init(sa, "disable MAC drain");
128 rc = efx_mac_drain(sa->nic, B_FALSE);
132 sfc_log_init(sa, "done");
136 (void)efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem,
139 fail_mac_stats_periodic:
143 fail_phy_adv_cap_set:
145 efx_port_fini(sa->nic);
148 efx_filter_fini(sa->nic);
151 sfc_log_init(sa, "failed %d", rc);
156 sfc_port_stop(struct sfc_adapter *sa)
158 sfc_log_init(sa, "entry");
160 efx_mac_drain(sa->nic, B_TRUE);
162 (void)efx_mac_stats_periodic(sa->nic, &sa->port.mac_stats_dma_mem,
165 efx_port_fini(sa->nic);
166 efx_filter_fini(sa->nic);
168 sfc_log_init(sa, "done");
172 sfc_port_init(struct sfc_adapter *sa)
174 const struct rte_eth_dev_data *dev_data = sa->eth_dev->data;
175 struct sfc_port *port = &sa->port;
178 sfc_log_init(sa, "entry");
180 /* Enable flow control by default */
181 port->flow_ctrl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
182 port->flow_ctrl_autoneg = B_TRUE;
184 if (dev_data->dev_conf.rxmode.jumbo_frame)
185 port->pdu = dev_data->dev_conf.rxmode.max_rx_pkt_len;
187 port->pdu = EFX_MAC_PDU(dev_data->mtu);
189 rte_spinlock_init(&port->mac_stats_lock);
192 port->mac_stats_buf = rte_calloc_socket("mac_stats_buf", EFX_MAC_NSTATS,
195 if (port->mac_stats_buf == NULL)
196 goto fail_mac_stats_buf_alloc;
198 rc = sfc_dma_alloc(sa, "mac_stats", 0, EFX_MAC_STATS_SIZE,
199 sa->socket_id, &port->mac_stats_dma_mem);
201 goto fail_mac_stats_dma_alloc;
203 sfc_log_init(sa, "done");
206 fail_mac_stats_dma_alloc:
207 rte_free(port->mac_stats_buf);
208 fail_mac_stats_buf_alloc:
209 sfc_log_init(sa, "failed %d", rc);
214 sfc_port_fini(struct sfc_adapter *sa)
216 struct sfc_port *port = &sa->port;
218 sfc_log_init(sa, "entry");
220 sfc_dma_free(sa, &port->mac_stats_dma_mem);
221 rte_free(port->mac_stats_buf);
223 sfc_log_init(sa, "done");
227 sfc_set_rx_mode(struct sfc_adapter *sa)
229 struct sfc_port *port = &sa->port;
232 rc = efx_mac_filter_set(sa->nic, port->promisc, B_TRUE,
233 port->promisc || port->allmulti, B_TRUE);
239 sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
240 struct rte_eth_link *link_info)
242 SFC_ASSERT(link_mode < EFX_LINK_NMODES);
244 memset(link_info, 0, sizeof(*link_info));
245 if ((link_mode == EFX_LINK_DOWN) || (link_mode == EFX_LINK_UNKNOWN))
246 link_info->link_status = ETH_LINK_DOWN;
248 link_info->link_status = ETH_LINK_UP;
252 link_info->link_speed = ETH_SPEED_NUM_10M;
253 link_info->link_duplex = ETH_LINK_HALF_DUPLEX;
256 link_info->link_speed = ETH_SPEED_NUM_10M;
257 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
259 case EFX_LINK_100HDX:
260 link_info->link_speed = ETH_SPEED_NUM_100M;
261 link_info->link_duplex = ETH_LINK_HALF_DUPLEX;
263 case EFX_LINK_100FDX:
264 link_info->link_speed = ETH_SPEED_NUM_100M;
265 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
267 case EFX_LINK_1000HDX:
268 link_info->link_speed = ETH_SPEED_NUM_1G;
269 link_info->link_duplex = ETH_LINK_HALF_DUPLEX;
271 case EFX_LINK_1000FDX:
272 link_info->link_speed = ETH_SPEED_NUM_1G;
273 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
275 case EFX_LINK_10000FDX:
276 link_info->link_speed = ETH_SPEED_NUM_10G;
277 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
279 case EFX_LINK_40000FDX:
280 link_info->link_speed = ETH_SPEED_NUM_40G;
281 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
286 case EFX_LINK_UNKNOWN:
288 link_info->link_speed = ETH_SPEED_NUM_NONE;
289 link_info->link_duplex = 0;
293 link_info->link_autoneg = ETH_LINK_AUTONEG;