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 rc = efx_mac_filter_set(sa->nic, B_TRUE, B_TRUE, B_TRUE, B_TRUE);
108 goto fail_mac_filter_set;
110 efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask,
111 sizeof(port->mac_stats_mask));
113 /* Update MAC stats using periodic DMA.
114 * Common code always uses 1000ms update period, so period_ms
115 * parameter only needs to be non-zero to start updates.
117 sfc_log_init(sa, "request MAC stats DMA'ing");
118 rc = efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem,
121 goto fail_mac_stats_periodic;
123 sfc_log_init(sa, "disable MAC drain");
124 rc = efx_mac_drain(sa->nic, B_FALSE);
128 sfc_log_init(sa, "done");
132 (void)efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem,
135 fail_mac_stats_periodic:
139 fail_phy_adv_cap_set:
141 efx_port_fini(sa->nic);
144 efx_filter_fini(sa->nic);
147 sfc_log_init(sa, "failed %d", rc);
152 sfc_port_stop(struct sfc_adapter *sa)
154 sfc_log_init(sa, "entry");
156 efx_mac_drain(sa->nic, B_TRUE);
158 (void)efx_mac_stats_periodic(sa->nic, &sa->port.mac_stats_dma_mem,
161 efx_port_fini(sa->nic);
162 efx_filter_fini(sa->nic);
164 sfc_log_init(sa, "done");
168 sfc_port_init(struct sfc_adapter *sa)
170 const struct rte_eth_dev_data *dev_data = sa->eth_dev->data;
171 struct sfc_port *port = &sa->port;
174 sfc_log_init(sa, "entry");
176 /* Enable flow control by default */
177 port->flow_ctrl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
178 port->flow_ctrl_autoneg = B_TRUE;
180 if (dev_data->dev_conf.rxmode.jumbo_frame)
181 port->pdu = dev_data->dev_conf.rxmode.max_rx_pkt_len;
183 port->pdu = EFX_MAC_PDU(dev_data->mtu);
185 rte_spinlock_init(&port->mac_stats_lock);
188 port->mac_stats_buf = rte_calloc_socket("mac_stats_buf", EFX_MAC_NSTATS,
191 if (port->mac_stats_buf == NULL)
192 goto fail_mac_stats_buf_alloc;
194 rc = sfc_dma_alloc(sa, "mac_stats", 0, EFX_MAC_STATS_SIZE,
195 sa->socket_id, &port->mac_stats_dma_mem);
197 goto fail_mac_stats_dma_alloc;
199 sfc_log_init(sa, "done");
202 fail_mac_stats_dma_alloc:
203 rte_free(port->mac_stats_buf);
204 fail_mac_stats_buf_alloc:
205 sfc_log_init(sa, "failed %d", rc);
210 sfc_port_fini(struct sfc_adapter *sa)
212 struct sfc_port *port = &sa->port;
214 sfc_log_init(sa, "entry");
216 sfc_dma_free(sa, &port->mac_stats_dma_mem);
217 rte_free(port->mac_stats_buf);
219 sfc_log_init(sa, "done");
223 sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
224 struct rte_eth_link *link_info)
226 SFC_ASSERT(link_mode < EFX_LINK_NMODES);
228 memset(link_info, 0, sizeof(*link_info));
229 if ((link_mode == EFX_LINK_DOWN) || (link_mode == EFX_LINK_UNKNOWN))
230 link_info->link_status = ETH_LINK_DOWN;
232 link_info->link_status = ETH_LINK_UP;
236 link_info->link_speed = ETH_SPEED_NUM_10M;
237 link_info->link_duplex = ETH_LINK_HALF_DUPLEX;
240 link_info->link_speed = ETH_SPEED_NUM_10M;
241 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
243 case EFX_LINK_100HDX:
244 link_info->link_speed = ETH_SPEED_NUM_100M;
245 link_info->link_duplex = ETH_LINK_HALF_DUPLEX;
247 case EFX_LINK_100FDX:
248 link_info->link_speed = ETH_SPEED_NUM_100M;
249 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
251 case EFX_LINK_1000HDX:
252 link_info->link_speed = ETH_SPEED_NUM_1G;
253 link_info->link_duplex = ETH_LINK_HALF_DUPLEX;
255 case EFX_LINK_1000FDX:
256 link_info->link_speed = ETH_SPEED_NUM_1G;
257 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
259 case EFX_LINK_10000FDX:
260 link_info->link_speed = ETH_SPEED_NUM_10G;
261 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
263 case EFX_LINK_40000FDX:
264 link_info->link_speed = ETH_SPEED_NUM_40G;
265 link_info->link_duplex = ETH_LINK_FULL_DUPLEX;
270 case EFX_LINK_UNKNOWN:
272 link_info->link_speed = ETH_SPEED_NUM_NONE;
273 link_info->link_duplex = 0;
277 link_info->link_autoneg = ETH_LINK_AUTONEG;