Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <stdarg.h>
10 : :
11 : : #include <rte_common.h>
12 : : #include <rte_interrupts.h>
13 : : #include <rte_byteorder.h>
14 : : #include <rte_debug.h>
15 : : #include <rte_pci.h>
16 : : #include <bus_pci_driver.h>
17 : : #include <rte_ether.h>
18 : : #include <ethdev_driver.h>
19 : : #include <ethdev_pci.h>
20 : : #include <rte_memory.h>
21 : : #include <rte_eal.h>
22 : : #include <rte_malloc.h>
23 : : #include <dev_driver.h>
24 : :
25 : : #include "e1000_logs.h"
26 : : #include "base/e1000_api.h"
27 : : #include "e1000_ethdev.h"
28 : :
29 : : #define EM_EIAC 0x000DC
30 : :
31 : : #define PMD_ROUNDUP(x,y) (((x) + (y) - 1)/(y) * (y))
32 : :
33 : :
34 : : static int eth_em_configure(struct rte_eth_dev *dev);
35 : : static int eth_em_start(struct rte_eth_dev *dev);
36 : : static int eth_em_stop(struct rte_eth_dev *dev);
37 : : static int eth_em_close(struct rte_eth_dev *dev);
38 : : static int eth_em_promiscuous_enable(struct rte_eth_dev *dev);
39 : : static int eth_em_promiscuous_disable(struct rte_eth_dev *dev);
40 : : static int eth_em_allmulticast_enable(struct rte_eth_dev *dev);
41 : : static int eth_em_allmulticast_disable(struct rte_eth_dev *dev);
42 : : static int eth_em_link_update(struct rte_eth_dev *dev,
43 : : int wait_to_complete);
44 : : static int eth_em_stats_get(struct rte_eth_dev *dev,
45 : : struct rte_eth_stats *rte_stats, struct eth_queue_stats *qstats);
46 : : static int eth_em_stats_reset(struct rte_eth_dev *dev);
47 : : static int eth_em_infos_get(struct rte_eth_dev *dev,
48 : : struct rte_eth_dev_info *dev_info);
49 : : static int eth_em_flow_ctrl_get(struct rte_eth_dev *dev,
50 : : struct rte_eth_fc_conf *fc_conf);
51 : : static int eth_em_flow_ctrl_set(struct rte_eth_dev *dev,
52 : : struct rte_eth_fc_conf *fc_conf);
53 : : static int eth_em_interrupt_setup(struct rte_eth_dev *dev);
54 : : static int eth_em_rxq_interrupt_setup(struct rte_eth_dev *dev);
55 : : static int eth_em_interrupt_get_status(struct rte_eth_dev *dev);
56 : : static int eth_em_interrupt_action(struct rte_eth_dev *dev,
57 : : struct rte_intr_handle *handle);
58 : : static void eth_em_interrupt_handler(void *param);
59 : :
60 : : static int em_hw_init(struct e1000_hw *hw);
61 : : static int em_hardware_init(struct e1000_hw *hw);
62 : : static void em_hw_control_acquire(struct e1000_hw *hw);
63 : : static void em_hw_control_release(struct e1000_hw *hw);
64 : : static void em_init_manageability(struct e1000_hw *hw);
65 : : static void em_release_manageability(struct e1000_hw *hw);
66 : :
67 : : static int eth_em_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
68 : :
69 : : static int eth_em_vlan_filter_set(struct rte_eth_dev *dev,
70 : : uint16_t vlan_id, int on);
71 : : static int eth_em_vlan_offload_set(struct rte_eth_dev *dev, int mask);
72 : : static void em_vlan_hw_filter_enable(struct rte_eth_dev *dev);
73 : : static void em_vlan_hw_filter_disable(struct rte_eth_dev *dev);
74 : : static void em_vlan_hw_strip_enable(struct rte_eth_dev *dev);
75 : : static void em_vlan_hw_strip_disable(struct rte_eth_dev *dev);
76 : :
77 : : /*
78 : : static void eth_em_vlan_filter_set(struct rte_eth_dev *dev,
79 : : uint16_t vlan_id, int on);
80 : : */
81 : :
82 : : static int eth_em_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
83 : : static int eth_em_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);
84 : : static void em_lsc_intr_disable(struct e1000_hw *hw);
85 : : static void em_rxq_intr_enable(struct e1000_hw *hw);
86 : : static void em_rxq_intr_disable(struct e1000_hw *hw);
87 : :
88 : : static int eth_em_led_on(struct rte_eth_dev *dev);
89 : : static int eth_em_led_off(struct rte_eth_dev *dev);
90 : :
91 : : static int em_get_rx_buffer_size(struct e1000_hw *hw);
92 : : static int eth_em_rar_set(struct rte_eth_dev *dev,
93 : : struct rte_ether_addr *mac_addr,
94 : : uint32_t index, uint32_t pool);
95 : : static void eth_em_rar_clear(struct rte_eth_dev *dev, uint32_t index);
96 : : static int eth_em_default_mac_addr_set(struct rte_eth_dev *dev,
97 : : struct rte_ether_addr *addr);
98 : :
99 : : static int eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
100 : : struct rte_ether_addr *mc_addr_set,
101 : : uint32_t nb_mc_addr);
102 : :
103 : : #define EM_FC_PAUSE_TIME 0x0680
104 : : #define EM_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
105 : : #define EM_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
106 : :
107 : : static enum e1000_fc_mode em_fc_setting = e1000_fc_full;
108 : :
109 : : /*
110 : : * The set of PCI devices this driver supports
111 : : */
112 : : static const struct rte_pci_id pci_id_em_map[] = {
113 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82540EM) },
114 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82545EM_COPPER) },
115 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82545EM_FIBER) },
116 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82546EB_COPPER) },
117 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82546EB_FIBER) },
118 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82546EB_QUAD_COPPER) },
119 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_COPPER) },
120 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_FIBER) },
121 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_SERDES) },
122 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_SERDES_DUAL) },
123 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_SERDES_QUAD) },
124 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_QUAD_COPPER) },
125 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571PT_QUAD_COPPER) },
126 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_QUAD_FIBER) },
127 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_QUAD_COPPER_LP) },
128 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82572EI_COPPER) },
129 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82572EI_FIBER) },
130 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82572EI_SERDES) },
131 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82572EI) },
132 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82573L) },
133 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82574L) },
134 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82574LA) },
135 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82583V) },
136 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH2_LV_LM) },
137 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LPT_I217_LM) },
138 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LPT_I217_V) },
139 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LPTLP_I218_LM) },
140 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LPTLP_I218_V) },
141 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_I218_LM2) },
142 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_I218_V2) },
143 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_I218_LM3) },
144 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_I218_V3) },
145 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_LM) },
146 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_V) },
147 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_LM2) },
148 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_V2) },
149 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LBG_I219_LM3) },
150 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_LM4) },
151 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_V4) },
152 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_LM5) },
153 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_V5) },
154 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CNP_I219_LM6) },
155 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CNP_I219_V6) },
156 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CNP_I219_LM7) },
157 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CNP_I219_V7) },
158 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ICP_I219_LM8) },
159 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ICP_I219_V8) },
160 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ICP_I219_LM9) },
161 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ICP_I219_V9) },
162 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CMP_I219_LM10) },
163 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CMP_I219_V10) },
164 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CMP_I219_LM11) },
165 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CMP_I219_V11) },
166 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CMP_I219_LM12) },
167 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CMP_I219_V12) },
168 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_TGP_I219_LM13) },
169 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_TGP_I219_V13) },
170 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_TGP_I219_LM14) },
171 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_TGP_I219_V14) },
172 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_TGP_I219_LM15) },
173 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_TGP_I219_V15) },
174 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ADL_I219_LM16) },
175 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ADL_I219_V16) },
176 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ADL_I219_LM17) },
177 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ADL_I219_V17) },
178 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_MTP_I219_LM18) },
179 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_MTP_I219_V18) },
180 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_MTP_I219_LM19) },
181 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_MTP_I219_V19) },
182 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LNL_I219_LM20) },
183 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LNL_I219_V20) },
184 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_RPL_I219_LM22) },
185 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_RPL_I219_V22) },
186 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_RPL_I219_LM23) },
187 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_RPL_I219_V23) },
188 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ARL_I219_LM24) },
189 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_ARL_I219_V24) },
190 : : { .vendor_id = 0, /* sentinel */ },
191 : : };
192 : :
193 : : static const struct eth_dev_ops eth_em_ops = {
194 : : .dev_configure = eth_em_configure,
195 : : .dev_start = eth_em_start,
196 : : .dev_stop = eth_em_stop,
197 : : .dev_close = eth_em_close,
198 : : .promiscuous_enable = eth_em_promiscuous_enable,
199 : : .promiscuous_disable = eth_em_promiscuous_disable,
200 : : .allmulticast_enable = eth_em_allmulticast_enable,
201 : : .allmulticast_disable = eth_em_allmulticast_disable,
202 : : .link_update = eth_em_link_update,
203 : : .stats_get = eth_em_stats_get,
204 : : .stats_reset = eth_em_stats_reset,
205 : : .dev_infos_get = eth_em_infos_get,
206 : : .mtu_set = eth_em_mtu_set,
207 : : .vlan_filter_set = eth_em_vlan_filter_set,
208 : : .vlan_offload_set = eth_em_vlan_offload_set,
209 : : .rx_queue_setup = eth_em_rx_queue_setup,
210 : : .rx_queue_release = eth_em_rx_queue_release,
211 : : .tx_queue_setup = eth_em_tx_queue_setup,
212 : : .tx_queue_release = eth_em_tx_queue_release,
213 : : .rx_queue_intr_enable = eth_em_rx_queue_intr_enable,
214 : : .rx_queue_intr_disable = eth_em_rx_queue_intr_disable,
215 : : .dev_led_on = eth_em_led_on,
216 : : .dev_led_off = eth_em_led_off,
217 : : .flow_ctrl_get = eth_em_flow_ctrl_get,
218 : : .flow_ctrl_set = eth_em_flow_ctrl_set,
219 : : .mac_addr_set = eth_em_default_mac_addr_set,
220 : : .mac_addr_add = eth_em_rar_set,
221 : : .mac_addr_remove = eth_em_rar_clear,
222 : : .set_mc_addr_list = eth_em_set_mc_addr_list,
223 : : .rxq_info_get = em_rxq_info_get,
224 : : .txq_info_get = em_txq_info_get,
225 : : };
226 : :
227 : :
228 : : /**
229 : : * eth_em_dev_is_ich8 - Check for ICH8 device
230 : : * @hw: pointer to the HW structure
231 : : *
232 : : * return TRUE for ICH8, otherwise FALSE
233 : : **/
234 : : static bool
235 : 0 : eth_em_dev_is_ich8(struct e1000_hw *hw)
236 : : {
237 : 0 : DEBUGFUNC("eth_em_dev_is_ich8");
238 : :
239 [ # # ]: 0 : switch (hw->device_id) {
240 : : case E1000_DEV_ID_PCH2_LV_LM:
241 : : case E1000_DEV_ID_PCH_LPT_I217_LM:
242 : : case E1000_DEV_ID_PCH_LPT_I217_V:
243 : : case E1000_DEV_ID_PCH_LPTLP_I218_LM:
244 : : case E1000_DEV_ID_PCH_LPTLP_I218_V:
245 : : case E1000_DEV_ID_PCH_I218_V2:
246 : : case E1000_DEV_ID_PCH_I218_LM2:
247 : : case E1000_DEV_ID_PCH_I218_V3:
248 : : case E1000_DEV_ID_PCH_I218_LM3:
249 : : case E1000_DEV_ID_PCH_SPT_I219_LM:
250 : : case E1000_DEV_ID_PCH_SPT_I219_V:
251 : : case E1000_DEV_ID_PCH_SPT_I219_LM2:
252 : : case E1000_DEV_ID_PCH_SPT_I219_V2:
253 : : case E1000_DEV_ID_PCH_LBG_I219_LM3:
254 : : case E1000_DEV_ID_PCH_SPT_I219_LM4:
255 : : case E1000_DEV_ID_PCH_SPT_I219_V4:
256 : : case E1000_DEV_ID_PCH_SPT_I219_LM5:
257 : : case E1000_DEV_ID_PCH_SPT_I219_V5:
258 : : case E1000_DEV_ID_PCH_CNP_I219_LM6:
259 : : case E1000_DEV_ID_PCH_CNP_I219_V6:
260 : : case E1000_DEV_ID_PCH_CNP_I219_LM7:
261 : : case E1000_DEV_ID_PCH_CNP_I219_V7:
262 : : case E1000_DEV_ID_PCH_RPL_I219_LM22:
263 : : case E1000_DEV_ID_PCH_RPL_I219_V22:
264 : : case E1000_DEV_ID_PCH_RPL_I219_LM23:
265 : : case E1000_DEV_ID_PCH_RPL_I219_V23:
266 : :
267 : : return 1;
268 : 0 : default:
269 : 0 : return 0;
270 : : }
271 : : }
272 : :
273 : : static int
274 : 0 : eth_em_dev_init(struct rte_eth_dev *eth_dev)
275 : : {
276 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
277 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
278 : 0 : struct e1000_adapter *adapter =
279 : 0 : E1000_DEV_PRIVATE(eth_dev->data->dev_private);
280 : 0 : struct e1000_hw *hw =
281 : : E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
282 : 0 : struct e1000_vfta * shadow_vfta =
283 : : E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
284 : :
285 : 0 : eth_dev->dev_ops = ð_em_ops;
286 : 0 : eth_dev->rx_queue_count = eth_em_rx_queue_count;
287 : 0 : eth_dev->rx_descriptor_status = eth_em_rx_descriptor_status;
288 : 0 : eth_dev->tx_descriptor_status = eth_em_tx_descriptor_status;
289 : 0 : eth_dev->rx_pkt_burst = (eth_rx_burst_t)ð_em_recv_pkts;
290 : 0 : eth_dev->tx_pkt_burst = (eth_tx_burst_t)ð_em_xmit_pkts;
291 : 0 : eth_dev->tx_pkt_prepare = (eth_tx_prep_t)ð_em_prep_pkts;
292 : :
293 : : /* for secondary processes, we don't initialise any further as primary
294 : : * has already done this work. Only check we don't need a different
295 : : * RX function */
296 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY){
297 [ # # ]: 0 : if (eth_dev->data->scattered_rx)
298 : 0 : eth_dev->rx_pkt_burst =
299 : : (eth_rx_burst_t)ð_em_recv_scattered_pkts;
300 : 0 : return 0;
301 : : }
302 : :
303 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
304 : :
305 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
306 : 0 : hw->device_id = pci_dev->id.device_id;
307 : 0 : adapter->stopped = 0;
308 : :
309 : : /* For ICH8 support we'll need to map the flash memory BAR */
310 [ # # ]: 0 : if (eth_em_dev_is_ich8(hw))
311 : 0 : hw->flash_address = (void *)pci_dev->mem_resource[1].addr;
312 : :
313 [ # # # # ]: 0 : if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS ||
314 : 0 : em_hw_init(hw) != 0) {
315 : 0 : PMD_INIT_LOG(ERR, "port_id %d vendorID=0x%x deviceID=0x%x: "
316 : : "failed to init HW",
317 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
318 : : pci_dev->id.device_id);
319 : 0 : return -ENODEV;
320 : : }
321 : :
322 : : /* Allocate memory for storing MAC addresses */
323 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("e1000", RTE_ETHER_ADDR_LEN *
324 : 0 : hw->mac.rar_entry_count, 0);
325 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
326 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
327 : : "store MAC addresses",
328 : : RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count);
329 : 0 : return -ENOMEM;
330 : : }
331 : :
332 : : /* Copy the permanent MAC address */
333 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
334 : : eth_dev->data->mac_addrs);
335 : :
336 : : /* initialize the vfta */
337 : : memset(shadow_vfta, 0, sizeof(*shadow_vfta));
338 : :
339 : 0 : PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
340 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
341 : : pci_dev->id.device_id);
342 : :
343 : 0 : rte_intr_callback_register(intr_handle,
344 : : eth_em_interrupt_handler, eth_dev);
345 : :
346 : 0 : return 0;
347 : : }
348 : :
349 : : static int
350 : 0 : eth_em_dev_uninit(struct rte_eth_dev *eth_dev)
351 : : {
352 : 0 : PMD_INIT_FUNC_TRACE();
353 : :
354 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
355 : : return 0;
356 : :
357 : 0 : eth_em_close(eth_dev);
358 : :
359 : 0 : return 0;
360 : : }
361 : :
362 : 0 : static int eth_em_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
363 : : struct rte_pci_device *pci_dev)
364 : : {
365 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
366 : : sizeof(struct e1000_adapter), eth_em_dev_init);
367 : : }
368 : :
369 : 0 : static int eth_em_pci_remove(struct rte_pci_device *pci_dev)
370 : : {
371 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_em_dev_uninit);
372 : : }
373 : :
374 : : static struct rte_pci_driver rte_em_pmd = {
375 : : .id_table = pci_id_em_map,
376 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
377 : : .probe = eth_em_pci_probe,
378 : : .remove = eth_em_pci_remove,
379 : : };
380 : :
381 : : static int
382 : 0 : em_hw_init(struct e1000_hw *hw)
383 : : {
384 : : int diag;
385 : :
386 : 0 : diag = hw->mac.ops.init_params(hw);
387 [ # # ]: 0 : if (diag != 0) {
388 : 0 : PMD_INIT_LOG(ERR, "MAC Initialization Error");
389 : 0 : return diag;
390 : : }
391 : 0 : diag = hw->nvm.ops.init_params(hw);
392 [ # # ]: 0 : if (diag != 0) {
393 : 0 : PMD_INIT_LOG(ERR, "NVM Initialization Error");
394 : 0 : return diag;
395 : : }
396 : 0 : diag = hw->phy.ops.init_params(hw);
397 [ # # ]: 0 : if (diag != 0) {
398 : 0 : PMD_INIT_LOG(ERR, "PHY Initialization Error");
399 : 0 : return diag;
400 : : }
401 : 0 : (void) e1000_get_bus_info(hw);
402 : :
403 : 0 : hw->mac.autoneg = 1;
404 : 0 : hw->phy.autoneg_wait_to_complete = 0;
405 : 0 : hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
406 : :
407 : 0 : e1000_init_script_state_82541(hw, TRUE);
408 : 0 : e1000_set_tbi_compatibility_82543(hw, TRUE);
409 : :
410 : : /* Copper options */
411 [ # # ]: 0 : if (hw->phy.media_type == e1000_media_type_copper) {
412 : 0 : hw->phy.mdix = 0; /* AUTO_ALL_MODES */
413 : 0 : hw->phy.disable_polarity_correction = 0;
414 : 0 : hw->phy.ms_type = e1000_ms_hw_default;
415 : : }
416 : :
417 : : /*
418 : : * Start from a known state, this is important in reading the nvm
419 : : * and mac from that.
420 : : */
421 : 0 : e1000_reset_hw(hw);
422 : :
423 : : /* Make sure we have a good EEPROM before we read from it */
424 [ # # ]: 0 : if (e1000_validate_nvm_checksum(hw) < 0) {
425 : : /*
426 : : * Some PCI-E parts fail the first check due to
427 : : * the link being in sleep state, call it again,
428 : : * if it fails a second time its a real issue.
429 : : */
430 : 0 : diag = e1000_validate_nvm_checksum(hw);
431 [ # # ]: 0 : if (diag < 0) {
432 : 0 : PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
433 : 0 : goto error;
434 : : }
435 : : }
436 : :
437 : : /* Read the permanent MAC address out of the EEPROM */
438 : 0 : diag = e1000_read_mac_addr(hw);
439 [ # # ]: 0 : if (diag != 0) {
440 : 0 : PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
441 : 0 : goto error;
442 : : }
443 : :
444 : : /* Now initialize the hardware */
445 : 0 : diag = em_hardware_init(hw);
446 [ # # ]: 0 : if (diag != 0) {
447 : 0 : PMD_INIT_LOG(ERR, "Hardware initialization failed");
448 : 0 : goto error;
449 : : }
450 : :
451 : 0 : hw->mac.get_link_status = 1;
452 : :
453 : : /* Indicate SOL/IDER usage */
454 : 0 : diag = e1000_check_reset_block(hw);
455 [ # # ]: 0 : if (diag < 0) {
456 : 0 : PMD_INIT_LOG(ERR, "PHY reset is blocked due to "
457 : : "SOL/IDER session");
458 : : }
459 : : return 0;
460 : :
461 : 0 : error:
462 : : em_hw_control_release(hw);
463 : : return diag;
464 : : }
465 : :
466 : : static int
467 : 0 : eth_em_configure(struct rte_eth_dev *dev)
468 : : {
469 : : struct e1000_interrupt *intr =
470 : 0 : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
471 : :
472 : 0 : PMD_INIT_FUNC_TRACE();
473 : 0 : intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
474 : :
475 : 0 : PMD_INIT_FUNC_TRACE();
476 : :
477 : 0 : return 0;
478 : : }
479 : :
480 : : static void
481 : : em_set_pba(struct e1000_hw *hw)
482 : : {
483 : : uint32_t pba;
484 : :
485 : : /*
486 : : * Packet Buffer Allocation (PBA)
487 : : * Writing PBA sets the receive portion of the buffer
488 : : * the remainder is used for the transmit buffer.
489 : : * Devices before the 82547 had a Packet Buffer of 64K.
490 : : * After the 82547 the buffer was reduced to 40K.
491 : : */
492 [ # # ]: 0 : switch (hw->mac.type) {
493 : : case e1000_82547:
494 : : case e1000_82547_rev_2:
495 : : /* 82547: Total Packet Buffer is 40K */
496 : : pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */
497 : : break;
498 : : case e1000_82571:
499 : : case e1000_82572:
500 : : case e1000_80003es2lan:
501 : : pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
502 : : break;
503 : : case e1000_82573: /* 82573: Total Packet Buffer is 32K */
504 : : pba = E1000_PBA_12K; /* 12K for Rx, 20K for Tx */
505 : : break;
506 : : case e1000_82574:
507 : : case e1000_82583:
508 : : pba = E1000_PBA_20K; /* 20K for Rx, 20K for Tx */
509 : : break;
510 : : case e1000_ich8lan:
511 : : pba = E1000_PBA_8K;
512 : : break;
513 : : case e1000_ich9lan:
514 : : case e1000_ich10lan:
515 : : pba = E1000_PBA_10K;
516 : : break;
517 : : case e1000_pchlan:
518 : : case e1000_pch2lan:
519 : : case e1000_pch_lpt:
520 : : case e1000_pch_spt:
521 : : case e1000_pch_cnp:
522 : : case e1000_pch_adp:
523 : : case e1000_pch_tgp:
524 : : case e1000_pch_mtp:
525 : : case e1000_pch_ptp:
526 : : pba = E1000_PBA_26K;
527 : : break;
528 : : default:
529 : : pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */
530 : : }
531 : :
532 : 0 : E1000_WRITE_REG(hw, E1000_PBA, pba);
533 : : }
534 : :
535 : : static void
536 : 0 : eth_em_rxtx_control(struct rte_eth_dev *dev,
537 : : bool enable)
538 : : {
539 : : struct e1000_hw *hw =
540 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
541 : : uint32_t tctl, rctl;
542 : :
543 : 0 : tctl = E1000_READ_REG(hw, E1000_TCTL);
544 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
545 [ # # ]: 0 : if (enable) {
546 : : /* enable Tx/Rx */
547 : 0 : tctl |= E1000_TCTL_EN;
548 : 0 : rctl |= E1000_RCTL_EN;
549 : : } else {
550 : : /* disable Tx/Rx */
551 : 0 : tctl &= ~E1000_TCTL_EN;
552 : 0 : rctl &= ~E1000_RCTL_EN;
553 : : }
554 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, tctl);
555 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
556 : 0 : E1000_WRITE_FLUSH(hw);
557 : 0 : }
558 : :
559 : : static int
560 : 0 : eth_em_start(struct rte_eth_dev *dev)
561 : : {
562 : 0 : struct e1000_adapter *adapter =
563 : 0 : E1000_DEV_PRIVATE(dev->data->dev_private);
564 : 0 : struct e1000_hw *hw =
565 : : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
566 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
567 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
568 : : int ret, mask;
569 : : uint32_t intr_vector = 0;
570 : : uint32_t *speeds;
571 : : int num_speeds;
572 : : bool autoneg;
573 : :
574 : 0 : PMD_INIT_FUNC_TRACE();
575 : :
576 : : /*
577 : : * This function calls into the base driver, which in turn will use
578 : : * function pointers, which are not guaranteed to be valid in secondary
579 : : * processes, so avoid using this function in secondary processes.
580 : : */
581 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
582 : : return -E_RTE_SECONDARY;
583 : :
584 : 0 : ret = eth_em_stop(dev);
585 [ # # ]: 0 : if (ret != 0)
586 : : return ret;
587 : :
588 : 0 : e1000_power_up_phy(hw);
589 : :
590 : : /* Set default PBA value */
591 : : em_set_pba(hw);
592 : :
593 : : /* Put the address into the Receive Address Array */
594 : 0 : e1000_rar_set(hw, hw->mac.addr, 0);
595 : :
596 : : /*
597 : : * With the 82571 adapter, RAR[0] may be overwritten
598 : : * when the other port is reset, we make a duplicate
599 : : * in RAR[14] for that eventuality, this assures
600 : : * the interface continues to function.
601 : : */
602 [ # # ]: 0 : if (hw->mac.type == e1000_82571) {
603 : 0 : e1000_set_laa_state_82571(hw, TRUE);
604 : 0 : e1000_rar_set(hw, hw->mac.addr, E1000_RAR_ENTRIES - 1);
605 : : }
606 : :
607 : : /* Initialize the hardware */
608 [ # # ]: 0 : if (em_hardware_init(hw)) {
609 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
610 : 0 : return -EIO;
611 : : }
612 : :
613 : 0 : E1000_WRITE_REG(hw, E1000_VET, RTE_ETHER_TYPE_VLAN);
614 : :
615 : : /* Configure for OS presence */
616 : 0 : em_init_manageability(hw);
617 : :
618 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq != 0) {
619 : 0 : intr_vector = dev->data->nb_rx_queues;
620 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector))
621 : : return -1;
622 : : }
623 : :
624 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
625 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
626 : 0 : dev->data->nb_rx_queues)) {
627 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
628 : : " intr_vec", dev->data->nb_rx_queues);
629 : 0 : return -ENOMEM;
630 : : }
631 : :
632 : : /* enable rx interrupt */
633 : : em_rxq_intr_enable(hw);
634 : : }
635 : :
636 : 0 : eth_em_tx_init(dev);
637 : :
638 : 0 : ret = eth_em_rx_init(dev);
639 [ # # ]: 0 : if (ret) {
640 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
641 : 0 : em_dev_clear_queues(dev);
642 : 0 : return ret;
643 : : }
644 : :
645 : 0 : e1000_clear_hw_cntrs_base_generic(hw);
646 : :
647 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
648 : : RTE_ETH_VLAN_EXTEND_MASK;
649 : 0 : ret = eth_em_vlan_offload_set(dev, mask);
650 [ # # ]: 0 : if (ret) {
651 : 0 : PMD_INIT_LOG(ERR, "Unable to update vlan offload");
652 : 0 : em_dev_clear_queues(dev);
653 : 0 : return ret;
654 : : }
655 : :
656 : : /* Set Interrupt Throttling Rate to maximum allowed value. */
657 : 0 : E1000_WRITE_REG(hw, E1000_ITR, UINT16_MAX);
658 : :
659 : : /* Setup link speed and duplex */
660 : 0 : speeds = &dev->data->dev_conf.link_speeds;
661 [ # # ]: 0 : if (*speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
662 : 0 : hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
663 : 0 : hw->mac.autoneg = 1;
664 : : } else {
665 : : num_speeds = 0;
666 : 0 : autoneg = (*speeds & RTE_ETH_LINK_SPEED_FIXED) == 0;
667 : :
668 : : /* Reset */
669 : 0 : hw->phy.autoneg_advertised = 0;
670 : :
671 [ # # ]: 0 : if (*speeds & ~(RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
672 : : RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
673 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_FIXED)) {
674 : : num_speeds = -1;
675 : 0 : goto error_invalid_config;
676 : : }
677 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_10M_HD) {
678 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
679 : : num_speeds++;
680 : : }
681 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_10M) {
682 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
683 : 0 : num_speeds++;
684 : : }
685 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_100M_HD) {
686 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
687 : 0 : num_speeds++;
688 : : }
689 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_100M) {
690 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
691 : 0 : num_speeds++;
692 : : }
693 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_1G) {
694 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
695 : 0 : num_speeds++;
696 : : }
697 [ # # # # ]: 0 : if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
698 : 0 : goto error_invalid_config;
699 : :
700 : : /* Set/reset the mac.autoneg based on the link speed,
701 : : * fixed or not
702 : : */
703 [ # # ]: 0 : if (!autoneg) {
704 : 0 : hw->mac.autoneg = 0;
705 : 0 : hw->mac.forced_speed_duplex =
706 : 0 : hw->phy.autoneg_advertised;
707 : : } else {
708 : 0 : hw->mac.autoneg = 1;
709 : : }
710 : : }
711 : :
712 : 0 : e1000_setup_link(hw);
713 : :
714 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
715 : : /* check if lsc interrupt is enabled */
716 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0) {
717 : : ret = eth_em_interrupt_setup(dev);
718 : : if (ret) {
719 : : PMD_INIT_LOG(ERR, "Unable to setup interrupts");
720 : : em_dev_clear_queues(dev);
721 : : return ret;
722 : : }
723 : : }
724 : : } else {
725 : 0 : rte_intr_callback_unregister(intr_handle,
726 : : eth_em_interrupt_handler,
727 : : (void *)dev);
728 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
729 : 0 : PMD_INIT_LOG(INFO, "lsc won't enable because of"
730 : : " no intr multiplexn");
731 : : }
732 : : /* check if rxq interrupt is enabled */
733 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq != 0)
734 : : eth_em_rxq_interrupt_setup(dev);
735 : :
736 : 0 : rte_intr_enable(intr_handle);
737 : :
738 : 0 : adapter->stopped = 0;
739 : :
740 : 0 : eth_em_rxtx_control(dev, true);
741 : 0 : eth_em_link_update(dev, 0);
742 : :
743 : 0 : PMD_INIT_LOG(DEBUG, "<<");
744 : :
745 : 0 : return 0;
746 : :
747 : 0 : error_invalid_config:
748 : 0 : PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
749 : : dev->data->dev_conf.link_speeds, dev->data->port_id);
750 : 0 : em_dev_clear_queues(dev);
751 : 0 : return -EINVAL;
752 : : }
753 : :
754 : : /*********************************************************************
755 : : *
756 : : * This routine disables all traffic on the adapter by issuing a
757 : : * global reset on the MAC.
758 : : *
759 : : **********************************************************************/
760 : : static int
761 : 0 : eth_em_stop(struct rte_eth_dev *dev)
762 : : {
763 : : struct rte_eth_link link;
764 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
765 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
766 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
767 : :
768 : : /*
769 : : * This function calls into the base driver, which in turn will use
770 : : * function pointers, which are not guaranteed to be valid in secondary
771 : : * processes, so avoid using this function in secondary processes.
772 : : */
773 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
774 : : return -E_RTE_SECONDARY;
775 : :
776 : 0 : dev->data->dev_started = 0;
777 : :
778 : 0 : eth_em_rxtx_control(dev, false);
779 : : em_rxq_intr_disable(hw);
780 : : em_lsc_intr_disable(hw);
781 : :
782 : 0 : e1000_reset_hw(hw);
783 : :
784 : : /* Flush desc rings for i219 */
785 [ # # ]: 0 : if (hw->mac.type == e1000_pch_spt || hw->mac.type == e1000_pch_cnp)
786 : 0 : em_flush_desc_rings(dev);
787 : :
788 [ # # ]: 0 : if (hw->mac.type >= e1000_82544)
789 : 0 : E1000_WRITE_REG(hw, E1000_WUC, 0);
790 : :
791 : : /* Power down the phy. Needed to make the link go down */
792 : 0 : e1000_power_down_phy(hw);
793 : :
794 : 0 : em_dev_clear_queues(dev);
795 : :
796 : : /* clear the recorded link status */
797 : : memset(&link, 0, sizeof(link));
798 : 0 : rte_eth_linkstatus_set(dev, &link);
799 : :
800 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
801 : : /* resume to the default handler */
802 : 0 : rte_intr_callback_register(intr_handle,
803 : : eth_em_interrupt_handler,
804 : : (void *)dev);
805 : :
806 : : /* Clean datapath event and queue/vec mapping */
807 : 0 : rte_intr_efd_disable(intr_handle);
808 : 0 : rte_intr_vec_list_free(intr_handle);
809 : :
810 : 0 : return 0;
811 : : }
812 : :
813 : : static int
814 : 0 : eth_em_close(struct rte_eth_dev *dev)
815 : : {
816 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
817 : : struct e1000_adapter *adapter =
818 : : E1000_DEV_PRIVATE(dev->data->dev_private);
819 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
820 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
821 : : int ret;
822 : :
823 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
824 : : return 0;
825 : :
826 : 0 : ret = eth_em_stop(dev);
827 : 0 : adapter->stopped = 1;
828 : 0 : em_dev_free_queues(dev);
829 : 0 : e1000_phy_hw_reset(hw);
830 : 0 : em_release_manageability(hw);
831 : : em_hw_control_release(hw);
832 : :
833 : : /* disable uio intr before callback unregister */
834 : 0 : rte_intr_disable(intr_handle);
835 : 0 : rte_intr_callback_unregister(intr_handle,
836 : : eth_em_interrupt_handler, dev);
837 : :
838 : 0 : return ret;
839 : : }
840 : :
841 : : static int
842 : : em_get_rx_buffer_size(struct e1000_hw *hw)
843 : : {
844 : : uint32_t rx_buf_size;
845 : :
846 : 0 : rx_buf_size = ((E1000_READ_REG(hw, E1000_PBA) & UINT16_MAX) << 10);
847 : : return rx_buf_size;
848 : : }
849 : :
850 : : /*********************************************************************
851 : : *
852 : : * Initialize the hardware
853 : : *
854 : : **********************************************************************/
855 : : static int
856 : 0 : em_hardware_init(struct e1000_hw *hw)
857 : : {
858 : : uint32_t rx_buf_size;
859 : : int diag;
860 : :
861 : : /* Issue a global reset */
862 : 0 : e1000_reset_hw(hw);
863 : :
864 : : /* Let the firmware know the OS is in control */
865 : : em_hw_control_acquire(hw);
866 : :
867 : : /*
868 : : * These parameters control the automatic generation (Tx) and
869 : : * response (Rx) to Ethernet PAUSE frames.
870 : : * - High water mark should allow for at least two standard size (1518)
871 : : * frames to be received after sending an XOFF.
872 : : * - Low water mark works best when it is very near the high water mark.
873 : : * This allows the receiver to restart by sending XON when it has
874 : : * drained a bit. Here we use an arbitrary value of 1500 which will
875 : : * restart after one full frame is pulled from the buffer. There
876 : : * could be several smaller frames in the buffer and if so they will
877 : : * not trigger the XON until their total number reduces the buffer
878 : : * by 1500.
879 : : * - The pause time is fairly large at 1000 x 512ns = 512 usec.
880 : : */
881 : : rx_buf_size = em_get_rx_buffer_size(hw);
882 : :
883 : 0 : hw->fc.high_water = rx_buf_size -
884 : : PMD_ROUNDUP(RTE_ETHER_MAX_LEN * 2, 1024);
885 : 0 : hw->fc.low_water = hw->fc.high_water - 1500;
886 : :
887 [ # # ]: 0 : if (hw->mac.type == e1000_80003es2lan)
888 : 0 : hw->fc.pause_time = UINT16_MAX;
889 : : else
890 : 0 : hw->fc.pause_time = EM_FC_PAUSE_TIME;
891 : :
892 : 0 : hw->fc.send_xon = 1;
893 : :
894 : : /* Set Flow control, use the tunable location if sane */
895 [ # # ]: 0 : if (em_fc_setting <= e1000_fc_full)
896 : 0 : hw->fc.requested_mode = em_fc_setting;
897 : : else
898 : 0 : hw->fc.requested_mode = e1000_fc_none;
899 : :
900 : : /* Workaround: no TX flow ctrl for PCH */
901 [ # # ]: 0 : if (hw->mac.type == e1000_pchlan)
902 : 0 : hw->fc.requested_mode = e1000_fc_rx_pause;
903 : :
904 : : /* Override - settings for PCH2LAN, ya its magic :) */
905 [ # # ]: 0 : if (hw->mac.type == e1000_pch2lan) {
906 : 0 : hw->fc.high_water = 0x5C20;
907 : 0 : hw->fc.low_water = 0x5048;
908 : 0 : hw->fc.pause_time = 0x0650;
909 : 0 : hw->fc.refresh_time = 0x0400;
910 : 0 : } else if (hw->mac.type == e1000_pch_lpt ||
911 : : hw->mac.type == e1000_pch_spt ||
912 : : hw->mac.type == e1000_pch_cnp ||
913 [ # # ]: 0 : hw->mac.type == e1000_pch_adp ||
914 [ # # ]: 0 : hw->mac.type == e1000_pch_tgp ||
915 [ # # ]: 0 : hw->mac.type == e1000_pch_mtp ||
916 : : hw->mac.type == e1000_pch_ptp) {
917 : 0 : hw->fc.requested_mode = e1000_fc_full;
918 : : }
919 : :
920 : 0 : diag = e1000_init_hw(hw);
921 [ # # ]: 0 : if (diag < 0)
922 : : return diag;
923 : 0 : e1000_check_for_link(hw);
924 : 0 : return 0;
925 : : }
926 : :
927 : : /* This function is based on em_update_stats_counters() in e1000/if_em.c */
928 : : static int
929 : 0 : eth_em_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats,
930 : : struct eth_queue_stats *qstats __rte_unused)
931 : : {
932 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
933 : : struct e1000_hw_stats *stats =
934 : : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
935 : : int pause_frames;
936 : :
937 [ # # ]: 0 : if(hw->phy.media_type == e1000_media_type_copper ||
938 [ # # ]: 0 : (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
939 : 0 : stats->symerrs += E1000_READ_REG(hw,E1000_SYMERRS);
940 : 0 : stats->sec += E1000_READ_REG(hw, E1000_SEC);
941 : : }
942 : :
943 : 0 : stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
944 : 0 : stats->mpc += E1000_READ_REG(hw, E1000_MPC);
945 : 0 : stats->scc += E1000_READ_REG(hw, E1000_SCC);
946 : 0 : stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
947 : :
948 : 0 : stats->mcc += E1000_READ_REG(hw, E1000_MCC);
949 : 0 : stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
950 : 0 : stats->colc += E1000_READ_REG(hw, E1000_COLC);
951 : 0 : stats->dc += E1000_READ_REG(hw, E1000_DC);
952 : 0 : stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
953 : 0 : stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
954 : 0 : stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
955 : :
956 : : /*
957 : : * For watchdog management we need to know if we have been
958 : : * paused during the last interval, so capture that here.
959 : : */
960 : 0 : pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
961 : 0 : stats->xoffrxc += pause_frames;
962 : 0 : stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
963 : 0 : stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
964 : 0 : stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
965 : 0 : stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
966 : 0 : stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
967 : 0 : stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
968 : 0 : stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
969 : 0 : stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
970 : 0 : stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
971 : 0 : stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
972 : 0 : stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
973 : 0 : stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
974 : :
975 : : /*
976 : : * For the 64-bit byte counters the low dword must be read first.
977 : : * Both registers clear on the read of the high dword.
978 : : */
979 : :
980 : 0 : stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
981 : 0 : stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
982 : 0 : stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
983 : 0 : stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
984 : :
985 : 0 : stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
986 : 0 : stats->ruc += E1000_READ_REG(hw, E1000_RUC);
987 : 0 : stats->rfc += E1000_READ_REG(hw, E1000_RFC);
988 : 0 : stats->roc += E1000_READ_REG(hw, E1000_ROC);
989 : 0 : stats->rjc += E1000_READ_REG(hw, E1000_RJC);
990 : :
991 : 0 : stats->tor += E1000_READ_REG(hw, E1000_TORH);
992 : 0 : stats->tot += E1000_READ_REG(hw, E1000_TOTH);
993 : :
994 : 0 : stats->tpr += E1000_READ_REG(hw, E1000_TPR);
995 : 0 : stats->tpt += E1000_READ_REG(hw, E1000_TPT);
996 : 0 : stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
997 : 0 : stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
998 : 0 : stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
999 : 0 : stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1000 : 0 : stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1001 : 0 : stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1002 : 0 : stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1003 : 0 : stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1004 : :
1005 : : /* Interrupt Counts */
1006 : :
1007 [ # # ]: 0 : if (hw->mac.type >= e1000_82571) {
1008 : 0 : stats->iac += E1000_READ_REG(hw, E1000_IAC);
1009 : 0 : stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1010 : 0 : stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1011 : 0 : stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1012 : 0 : stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1013 : 0 : stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1014 : 0 : stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1015 : 0 : stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1016 : 0 : stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1017 : : }
1018 : :
1019 [ # # ]: 0 : if (hw->mac.type >= e1000_82543) {
1020 : 0 : stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1021 : 0 : stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1022 : 0 : stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1023 : 0 : stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1024 : 0 : stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1025 : 0 : stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1026 : : }
1027 : :
1028 [ # # ]: 0 : if (rte_stats == NULL)
1029 : : return -EINVAL;
1030 : :
1031 : : /* Rx Errors */
1032 : 0 : rte_stats->imissed = stats->mpc;
1033 : 0 : rte_stats->ierrors = stats->crcerrs + stats->rlec +
1034 : 0 : stats->rxerrc + stats->algnerrc + stats->cexterr;
1035 : :
1036 : : /* Tx Errors */
1037 : 0 : rte_stats->oerrors = stats->ecol + stats->latecol;
1038 : :
1039 : 0 : rte_stats->ipackets = stats->gprc;
1040 : 0 : rte_stats->opackets = stats->gptc;
1041 : 0 : rte_stats->ibytes = stats->gorc;
1042 : 0 : rte_stats->obytes = stats->gotc;
1043 : 0 : return 0;
1044 : : }
1045 : :
1046 : : static int
1047 : 0 : eth_em_stats_reset(struct rte_eth_dev *dev)
1048 : : {
1049 : 0 : struct e1000_hw_stats *hw_stats =
1050 : 0 : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1051 : :
1052 : : /* HW registers are cleared on read */
1053 : 0 : eth_em_stats_get(dev, NULL, NULL);
1054 : :
1055 : : /* Reset software totals */
1056 : : memset(hw_stats, 0, sizeof(*hw_stats));
1057 : :
1058 : 0 : return 0;
1059 : : }
1060 : :
1061 : : static int
1062 : 0 : eth_em_rx_queue_intr_enable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
1063 : : {
1064 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1065 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1066 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1067 : :
1068 : : /* device interrupts are only subscribed to in primary processes */
1069 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1070 : : return -E_RTE_SECONDARY;
1071 : :
1072 : : em_rxq_intr_enable(hw);
1073 : 0 : rte_intr_ack(intr_handle);
1074 : :
1075 : 0 : return 0;
1076 : : }
1077 : :
1078 : : static int
1079 : 0 : eth_em_rx_queue_intr_disable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
1080 : : {
1081 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1082 : :
1083 : : /* device interrupts are only subscribed to in primary processes */
1084 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1085 : : return -E_RTE_SECONDARY;
1086 : :
1087 : : em_rxq_intr_disable(hw);
1088 : :
1089 : 0 : return 0;
1090 : : }
1091 : :
1092 : : uint32_t
1093 : 0 : em_get_max_pktlen(struct rte_eth_dev *dev)
1094 : : {
1095 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1096 : :
1097 [ # # # # ]: 0 : switch (hw->mac.type) {
1098 : : case e1000_82571:
1099 : : case e1000_82572:
1100 : : case e1000_ich9lan:
1101 : : case e1000_ich10lan:
1102 : : case e1000_pch2lan:
1103 : : case e1000_pch_lpt:
1104 : : case e1000_pch_spt:
1105 : : case e1000_pch_cnp:
1106 : : case e1000_pch_adp:
1107 : : case e1000_pch_tgp:
1108 : : case e1000_pch_mtp:
1109 : : case e1000_pch_ptp:
1110 : : case e1000_82574:
1111 : : case e1000_80003es2lan: /* 9K Jumbo Frame size */
1112 : : case e1000_82583:
1113 : : return 0x2412;
1114 : 0 : case e1000_pchlan:
1115 : 0 : return 0x1000;
1116 : : /* Adapters that do not support jumbo frames */
1117 : 0 : case e1000_ich8lan:
1118 : 0 : return RTE_ETHER_MAX_LEN;
1119 : 0 : default:
1120 : 0 : return MAX_JUMBO_FRAME_SIZE;
1121 : : }
1122 : : }
1123 : :
1124 : : static int
1125 : 0 : eth_em_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1126 : : {
1127 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1128 : :
1129 : 0 : dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1130 : 0 : dev_info->max_rx_pktlen = em_get_max_pktlen(dev);
1131 : 0 : dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1132 : :
1133 : : /*
1134 : : * Starting with 631xESB hw supports 2 TX/RX queues per port.
1135 : : * Unfortunately, all these nics have just one TX context.
1136 : : * So we have few choices for TX:
1137 : : * - Use just one TX queue.
1138 : : * - Allow cksum offload only for one TX queue.
1139 : : * - Don't allow TX cksum offload at all.
1140 : : * For now, option #1 was chosen.
1141 : : * To use second RX queue we have to use extended RX descriptor
1142 : : * (Multiple Receive Queues are mutually exclusive with UDP
1143 : : * fragmentation and are not supported when a legacy receive
1144 : : * descriptor format is used).
1145 : : * Which means separate RX routines - as legacy nics (82540, 82545)
1146 : : * don't support extended RXD.
1147 : : * To avoid it we support just one RX queue for now (no RSS).
1148 : : */
1149 : :
1150 : 0 : dev_info->max_rx_queues = 2;
1151 : 0 : dev_info->max_tx_queues = 2;
1152 : :
1153 : 0 : dev_info->rx_queue_offload_capa = em_get_rx_queue_offloads_capa();
1154 : 0 : dev_info->rx_offload_capa = em_get_rx_port_offloads_capa() |
1155 : 0 : dev_info->rx_queue_offload_capa;
1156 : 0 : dev_info->tx_queue_offload_capa = em_get_tx_queue_offloads_capa(dev);
1157 : 0 : dev_info->tx_offload_capa = em_get_tx_port_offloads_capa(dev) |
1158 : 0 : dev_info->tx_queue_offload_capa;
1159 : :
1160 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1161 : : .nb_max = E1000_MAX_RING_DESC,
1162 : : .nb_min = E1000_MIN_RING_DESC,
1163 : : .nb_align = EM_RXD_ALIGN,
1164 : : };
1165 : :
1166 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1167 : : .nb_max = E1000_MAX_RING_DESC,
1168 : : .nb_min = E1000_MIN_RING_DESC,
1169 : : .nb_align = EM_TXD_ALIGN,
1170 : : .nb_seg_max = EM_TX_MAX_SEG,
1171 : : .nb_mtu_seg_max = EM_TX_MAX_MTU_SEG,
1172 : : };
1173 : :
1174 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
1175 : : RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
1176 : : RTE_ETH_LINK_SPEED_1G;
1177 : :
1178 : 0 : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
1179 : :
1180 : : /* Preferred queue parameters */
1181 : 0 : dev_info->default_rxportconf.nb_queues = 1;
1182 : 0 : dev_info->default_txportconf.nb_queues = 1;
1183 : 0 : dev_info->default_txportconf.ring_size = 256;
1184 : 0 : dev_info->default_rxportconf.ring_size = 256;
1185 : :
1186 : 0 : return 0;
1187 : : }
1188 : :
1189 : : /* return 0 means link status changed, -1 means not changed */
1190 : : static int
1191 : 0 : eth_em_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1192 : : {
1193 : 0 : struct e1000_hw *hw =
1194 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1195 : : struct rte_eth_link link;
1196 : : int link_up, count;
1197 : :
1198 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1199 : : return -1;
1200 : :
1201 : : link_up = 0;
1202 : 0 : hw->mac.get_link_status = 1;
1203 : :
1204 : : /* possible wait-to-complete in up to 9 seconds */
1205 [ # # ]: 0 : for (count = 0; count < EM_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
1206 : : /* Read the real link status */
1207 [ # # # # ]: 0 : switch (hw->phy.media_type) {
1208 : 0 : case e1000_media_type_copper:
1209 : : /* Do the work to read phy */
1210 : 0 : e1000_check_for_link(hw);
1211 : 0 : link_up = !hw->mac.get_link_status;
1212 : 0 : break;
1213 : :
1214 : 0 : case e1000_media_type_fiber:
1215 : 0 : e1000_check_for_link(hw);
1216 : 0 : link_up = (E1000_READ_REG(hw, E1000_STATUS) &
1217 : : E1000_STATUS_LU);
1218 : 0 : break;
1219 : :
1220 : 0 : case e1000_media_type_internal_serdes:
1221 : 0 : e1000_check_for_link(hw);
1222 : 0 : link_up = hw->mac.serdes_has_link;
1223 : 0 : break;
1224 : :
1225 : : default:
1226 : : break;
1227 : : }
1228 [ # # ]: 0 : if (link_up || wait_to_complete == 0)
1229 : : break;
1230 : : rte_delay_ms(EM_LINK_UPDATE_CHECK_INTERVAL);
1231 : : }
1232 : : memset(&link, 0, sizeof(link));
1233 : :
1234 : : /* Now we check if a transition has happened */
1235 [ # # ]: 0 : if (link_up) {
1236 : : uint16_t duplex, speed;
1237 : 0 : hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
1238 : 0 : link.link_duplex = (duplex == FULL_DUPLEX) ?
1239 : 0 : RTE_ETH_LINK_FULL_DUPLEX :
1240 : : RTE_ETH_LINK_HALF_DUPLEX;
1241 : 0 : link.link_speed = speed;
1242 : 0 : link.link_status = RTE_ETH_LINK_UP;
1243 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1244 : : RTE_ETH_LINK_SPEED_FIXED);
1245 : : } else {
1246 : : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1247 : : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1248 : : link.link_status = RTE_ETH_LINK_DOWN;
1249 : : link.link_autoneg = RTE_ETH_LINK_FIXED;
1250 : : }
1251 : :
1252 : : return rte_eth_linkstatus_set(dev, &link);
1253 : : }
1254 : :
1255 : : /*
1256 : : * em_hw_control_acquire sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
1257 : : * For ASF and Pass Through versions of f/w this means
1258 : : * that the driver is loaded. For AMT version type f/w
1259 : : * this means that the network i/f is open.
1260 : : */
1261 : : static void
1262 : : em_hw_control_acquire(struct e1000_hw *hw)
1263 : : {
1264 : : uint32_t ctrl_ext, swsm;
1265 : :
1266 : : /* Let firmware know the driver has taken over */
1267 [ # # ]: 0 : if (hw->mac.type == e1000_82573) {
1268 : 0 : swsm = E1000_READ_REG(hw, E1000_SWSM);
1269 : 0 : E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD);
1270 : :
1271 : : } else {
1272 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1273 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1274 : : ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1275 : : }
1276 : : }
1277 : :
1278 : : /*
1279 : : * em_hw_control_release resets {CTRL_EXTT|FWSM}:DRV_LOAD bit.
1280 : : * For ASF and Pass Through versions of f/w this means that the
1281 : : * driver is no longer loaded. For AMT versions of the
1282 : : * f/w this means that the network i/f is closed.
1283 : : */
1284 : : static void
1285 : : em_hw_control_release(struct e1000_hw *hw)
1286 : : {
1287 : : uint32_t ctrl_ext, swsm;
1288 : :
1289 : : /* Let firmware taken over control of h/w */
1290 [ # # # # ]: 0 : if (hw->mac.type == e1000_82573) {
1291 : 0 : swsm = E1000_READ_REG(hw, E1000_SWSM);
1292 : 0 : E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1293 : : } else {
1294 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1295 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1296 : : ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1297 : : }
1298 : : }
1299 : :
1300 : : /*
1301 : : * Bit of a misnomer, what this really means is
1302 : : * to enable OS management of the system... aka
1303 : : * to disable special hardware management features.
1304 : : */
1305 : : static void
1306 : 0 : em_init_manageability(struct e1000_hw *hw)
1307 : : {
1308 [ # # ]: 0 : if (e1000_enable_mng_pass_thru(hw)) {
1309 : 0 : uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
1310 : 0 : uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1311 : :
1312 : : /* disable hardware interception of ARP */
1313 : 0 : manc &= ~(E1000_MANC_ARP_EN);
1314 : :
1315 : : /* enable receiving management packets to the host */
1316 : 0 : manc |= E1000_MANC_EN_MNG2HOST;
1317 : : manc2h |= 1 << 5; /* Mng Port 623 */
1318 : 0 : manc2h |= 1 << 6; /* Mng Port 664 */
1319 : 0 : E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
1320 : 0 : E1000_WRITE_REG(hw, E1000_MANC, manc);
1321 : : }
1322 : 0 : }
1323 : :
1324 : : /*
1325 : : * Give control back to hardware management
1326 : : * controller if there is one.
1327 : : */
1328 : : static void
1329 : 0 : em_release_manageability(struct e1000_hw *hw)
1330 : : {
1331 : : uint32_t manc;
1332 : :
1333 [ # # ]: 0 : if (e1000_enable_mng_pass_thru(hw)) {
1334 : 0 : manc = E1000_READ_REG(hw, E1000_MANC);
1335 : :
1336 : : /* re-enable hardware interception of ARP */
1337 : : manc |= E1000_MANC_ARP_EN;
1338 : 0 : manc &= ~E1000_MANC_EN_MNG2HOST;
1339 : :
1340 : 0 : E1000_WRITE_REG(hw, E1000_MANC, manc);
1341 : : }
1342 : 0 : }
1343 : :
1344 : : static int
1345 : 0 : eth_em_promiscuous_enable(struct rte_eth_dev *dev)
1346 : : {
1347 : : struct e1000_hw *hw =
1348 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1349 : : uint32_t rctl;
1350 : :
1351 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1352 : 0 : rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1353 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1354 : :
1355 : 0 : return 0;
1356 : : }
1357 : :
1358 : : static int
1359 : 0 : eth_em_promiscuous_disable(struct rte_eth_dev *dev)
1360 : : {
1361 : : struct e1000_hw *hw =
1362 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1363 : : uint32_t rctl;
1364 : :
1365 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1366 : 0 : rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_SBP);
1367 [ # # ]: 0 : if (dev->data->all_multicast == 1)
1368 : 0 : rctl |= E1000_RCTL_MPE;
1369 : : else
1370 : 0 : rctl &= (~E1000_RCTL_MPE);
1371 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1372 : :
1373 : 0 : return 0;
1374 : : }
1375 : :
1376 : : static int
1377 : 0 : eth_em_allmulticast_enable(struct rte_eth_dev *dev)
1378 : : {
1379 : : struct e1000_hw *hw =
1380 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1381 : : uint32_t rctl;
1382 : :
1383 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1384 : 0 : rctl |= E1000_RCTL_MPE;
1385 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1386 : :
1387 : 0 : return 0;
1388 : : }
1389 : :
1390 : : static int
1391 : 0 : eth_em_allmulticast_disable(struct rte_eth_dev *dev)
1392 : : {
1393 : : struct e1000_hw *hw =
1394 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1395 : : uint32_t rctl;
1396 : :
1397 [ # # ]: 0 : if (dev->data->promiscuous == 1)
1398 : : return 0; /* must remain in all_multicast mode */
1399 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1400 : 0 : rctl &= (~E1000_RCTL_MPE);
1401 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1402 : :
1403 : 0 : return 0;
1404 : : }
1405 : :
1406 : : static int
1407 : 0 : eth_em_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1408 : : {
1409 : : struct e1000_hw *hw =
1410 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1411 : : struct e1000_vfta * shadow_vfta =
1412 : : E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1413 : : uint32_t vfta;
1414 : : uint32_t vid_idx;
1415 : : uint32_t vid_bit;
1416 : :
1417 : 0 : vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
1418 : : E1000_VFTA_ENTRY_MASK);
1419 : 0 : vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
1420 : 0 : vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
1421 [ # # ]: 0 : if (on)
1422 : 0 : vfta |= vid_bit;
1423 : : else
1424 : 0 : vfta &= ~vid_bit;
1425 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
1426 : :
1427 : : /* update local VFTA copy */
1428 : 0 : shadow_vfta->vfta[vid_idx] = vfta;
1429 : :
1430 : 0 : return 0;
1431 : : }
1432 : :
1433 : : static void
1434 : : em_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1435 : : {
1436 : : struct e1000_hw *hw =
1437 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1438 : : uint32_t reg;
1439 : :
1440 : : /* Filter Table Disable */
1441 : 0 : reg = E1000_READ_REG(hw, E1000_RCTL);
1442 : : reg &= ~E1000_RCTL_CFIEN;
1443 : 0 : reg &= ~E1000_RCTL_VFE;
1444 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, reg);
1445 : 0 : }
1446 : :
1447 : : static void
1448 : 0 : em_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1449 : : {
1450 : : struct e1000_hw *hw =
1451 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1452 : : struct e1000_vfta * shadow_vfta =
1453 : : E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1454 : : uint32_t reg;
1455 : : int i;
1456 : :
1457 : : /* Filter Table Enable, CFI not used for packet acceptance */
1458 : 0 : reg = E1000_READ_REG(hw, E1000_RCTL);
1459 : 0 : reg &= ~E1000_RCTL_CFIEN;
1460 : 0 : reg |= E1000_RCTL_VFE;
1461 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, reg);
1462 : :
1463 : : /* restore vfta from local copy */
1464 [ # # ]: 0 : for (i = 0; i < IGB_VFTA_SIZE; i++)
1465 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
1466 : 0 : }
1467 : :
1468 : : static void
1469 : : em_vlan_hw_strip_disable(struct rte_eth_dev *dev)
1470 : : {
1471 : : struct e1000_hw *hw =
1472 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1473 : : uint32_t reg;
1474 : :
1475 : : /* VLAN Mode Disable */
1476 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL);
1477 : 0 : reg &= ~E1000_CTRL_VME;
1478 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, reg);
1479 : :
1480 : 0 : }
1481 : :
1482 : : static void
1483 : : em_vlan_hw_strip_enable(struct rte_eth_dev *dev)
1484 : : {
1485 : : struct e1000_hw *hw =
1486 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1487 : : uint32_t reg;
1488 : :
1489 : : /* VLAN Mode Enable */
1490 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL);
1491 : 0 : reg |= E1000_CTRL_VME;
1492 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, reg);
1493 : 0 : }
1494 : :
1495 : : static int
1496 : 0 : eth_em_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1497 : : {
1498 : : struct rte_eth_rxmode *rxmode;
1499 : :
1500 : 0 : rxmode = &dev->data->dev_conf.rxmode;
1501 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1502 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1503 : : em_vlan_hw_strip_enable(dev);
1504 : : else
1505 : : em_vlan_hw_strip_disable(dev);
1506 : : }
1507 : :
1508 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
1509 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
1510 : 0 : em_vlan_hw_filter_enable(dev);
1511 : : else
1512 : : em_vlan_hw_filter_disable(dev);
1513 : : }
1514 : :
1515 : 0 : return 0;
1516 : : }
1517 : :
1518 : : /*
1519 : : * It enables the interrupt mask and then enable the interrupt.
1520 : : *
1521 : : * @param dev
1522 : : * Pointer to struct rte_eth_dev.
1523 : : *
1524 : : * @return
1525 : : * - On success, zero.
1526 : : * - On failure, a negative value.
1527 : : */
1528 : : static int
1529 : : eth_em_interrupt_setup(struct rte_eth_dev *dev)
1530 : : {
1531 : : uint32_t regval;
1532 : : struct e1000_hw *hw =
1533 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1534 : :
1535 : : /* clear interrupt */
1536 : 0 : E1000_READ_REG(hw, E1000_ICR);
1537 : 0 : regval = E1000_READ_REG(hw, E1000_IMS);
1538 : 0 : E1000_WRITE_REG(hw, E1000_IMS,
1539 : : regval | E1000_ICR_LSC | E1000_ICR_OTHER);
1540 : : return 0;
1541 : : }
1542 : :
1543 : : /*
1544 : : * It clears the interrupt causes and enables the interrupt.
1545 : : * It will be called once only during nic initialized.
1546 : : *
1547 : : * @param dev
1548 : : * Pointer to struct rte_eth_dev.
1549 : : *
1550 : : * @return
1551 : : * - On success, zero.
1552 : : * - On failure, a negative value.
1553 : : */
1554 : : static int
1555 : : eth_em_rxq_interrupt_setup(struct rte_eth_dev *dev)
1556 : : {
1557 : : struct e1000_hw *hw =
1558 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1559 : :
1560 : 0 : E1000_READ_REG(hw, E1000_ICR);
1561 : : em_rxq_intr_enable(hw);
1562 : 0 : return 0;
1563 : : }
1564 : :
1565 : : /*
1566 : : * It enable receive packet interrupt.
1567 : : * @param hw
1568 : : * Pointer to struct e1000_hw
1569 : : *
1570 : : * @return
1571 : : */
1572 : : static void
1573 : : em_rxq_intr_enable(struct e1000_hw *hw)
1574 : : {
1575 : 0 : E1000_WRITE_REG(hw, E1000_IMS, E1000_IMS_RXT0);
1576 : 0 : E1000_WRITE_FLUSH(hw);
1577 : 0 : }
1578 : :
1579 : : /*
1580 : : * It disabled lsc interrupt.
1581 : : * @param hw
1582 : : * Pointer to struct e1000_hw
1583 : : *
1584 : : * @return
1585 : : */
1586 : : static void
1587 : : em_lsc_intr_disable(struct e1000_hw *hw)
1588 : : {
1589 : 0 : E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_LSC | E1000_IMS_OTHER);
1590 : 0 : E1000_WRITE_FLUSH(hw);
1591 : : }
1592 : :
1593 : : /*
1594 : : * It disabled receive packet interrupt.
1595 : : * @param hw
1596 : : * Pointer to struct e1000_hw
1597 : : *
1598 : : * @return
1599 : : */
1600 : : static void
1601 : : em_rxq_intr_disable(struct e1000_hw *hw)
1602 : : {
1603 : 0 : E1000_READ_REG(hw, E1000_ICR);
1604 : 0 : E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_RXT0);
1605 : 0 : E1000_WRITE_FLUSH(hw);
1606 : : }
1607 : :
1608 : : /*
1609 : : * It reads ICR and gets interrupt causes, check it and set a bit flag
1610 : : * to update link status.
1611 : : *
1612 : : * @param dev
1613 : : * Pointer to struct rte_eth_dev.
1614 : : *
1615 : : * @return
1616 : : * - On success, zero.
1617 : : * - On failure, a negative value.
1618 : : */
1619 : : static int
1620 : : eth_em_interrupt_get_status(struct rte_eth_dev *dev)
1621 : : {
1622 : : uint32_t icr;
1623 : : struct e1000_hw *hw =
1624 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1625 : : struct e1000_interrupt *intr =
1626 : : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1627 : :
1628 : : /* read-on-clear nic registers here */
1629 : 0 : icr = E1000_READ_REG(hw, E1000_ICR);
1630 [ # # ]: 0 : if (icr & E1000_ICR_LSC) {
1631 : 0 : intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1632 : : }
1633 : :
1634 : : return 0;
1635 : : }
1636 : :
1637 : : /*
1638 : : * It executes link_update after knowing an interrupt is present.
1639 : : *
1640 : : * @param dev
1641 : : * Pointer to struct rte_eth_dev.
1642 : : *
1643 : : * @return
1644 : : * - On success, zero.
1645 : : * - On failure, a negative value.
1646 : : */
1647 : : static int
1648 : 0 : eth_em_interrupt_action(struct rte_eth_dev *dev,
1649 : : struct rte_intr_handle *intr_handle)
1650 : : {
1651 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1652 : : struct e1000_hw *hw =
1653 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1654 : : struct e1000_interrupt *intr =
1655 : : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1656 : : struct rte_eth_link link;
1657 : : int ret;
1658 : :
1659 [ # # ]: 0 : if (!(intr->flags & E1000_FLAG_NEED_LINK_UPDATE))
1660 : : return -1;
1661 : :
1662 : 0 : intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
1663 : 0 : rte_intr_ack(intr_handle);
1664 : :
1665 : : /* set get_link_status to check register later */
1666 : 0 : hw->mac.get_link_status = 1;
1667 : 0 : ret = eth_em_link_update(dev, 0);
1668 : :
1669 : : /* check if link has changed */
1670 [ # # ]: 0 : if (ret < 0)
1671 : : return 0;
1672 : :
1673 : 0 : rte_eth_linkstatus_get(dev, &link);
1674 : :
1675 [ # # ]: 0 : if (link.link_status) {
1676 [ # # ]: 0 : PMD_INIT_LOG(INFO, " Port %d: Link Up - speed %u Mbps - %s",
1677 : : dev->data->port_id, link.link_speed,
1678 : : link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
1679 : : "full-duplex" : "half-duplex");
1680 : : } else {
1681 : 0 : PMD_INIT_LOG(INFO, " Port %d: Link Down", dev->data->port_id);
1682 : : }
1683 : 0 : PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
1684 : : pci_dev->addr.domain, pci_dev->addr.bus,
1685 : : pci_dev->addr.devid, pci_dev->addr.function);
1686 : :
1687 : 0 : return 0;
1688 : : }
1689 : :
1690 : : /**
1691 : : * Interrupt handler which shall be registered at first.
1692 : : *
1693 : : * @param handle
1694 : : * Pointer to interrupt handle.
1695 : : * @param param
1696 : : * The address of parameter (struct rte_eth_dev *) registered before.
1697 : : *
1698 : : * @return
1699 : : * void
1700 : : */
1701 : : static void
1702 : 0 : eth_em_interrupt_handler(void *param)
1703 : : {
1704 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1705 : :
1706 : : eth_em_interrupt_get_status(dev);
1707 : 0 : eth_em_interrupt_action(dev, dev->intr_handle);
1708 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1709 : 0 : }
1710 : :
1711 : : static int
1712 : 0 : eth_em_led_on(struct rte_eth_dev *dev)
1713 : : {
1714 : : struct e1000_hw *hw;
1715 : :
1716 : : /*
1717 : : * This function calls into the base driver, which in turn will use
1718 : : * function pointers, which are not guaranteed to be valid in secondary
1719 : : * processes, so avoid using this function in secondary processes.
1720 : : */
1721 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1722 : : return -E_RTE_SECONDARY;
1723 : :
1724 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1725 [ # # ]: 0 : return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
1726 : : }
1727 : :
1728 : : static int
1729 : 0 : eth_em_led_off(struct rte_eth_dev *dev)
1730 : : {
1731 : : struct e1000_hw *hw;
1732 : :
1733 : : /*
1734 : : * This function calls into the base driver, which in turn will use
1735 : : * function pointers, which are not guaranteed to be valid in secondary
1736 : : * processes, so avoid using this function in secondary processes.
1737 : : */
1738 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1739 : : return -E_RTE_SECONDARY;
1740 : :
1741 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1742 [ # # ]: 0 : return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
1743 : : }
1744 : :
1745 : : static int
1746 : 0 : eth_em_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1747 : : {
1748 : : struct e1000_hw *hw;
1749 : : uint32_t ctrl;
1750 : : int tx_pause;
1751 : : int rx_pause;
1752 : :
1753 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1754 : 0 : fc_conf->pause_time = hw->fc.pause_time;
1755 : 0 : fc_conf->high_water = hw->fc.high_water;
1756 : 0 : fc_conf->low_water = hw->fc.low_water;
1757 : 0 : fc_conf->send_xon = hw->fc.send_xon;
1758 : 0 : fc_conf->autoneg = hw->mac.autoneg;
1759 : :
1760 : : /*
1761 : : * Return rx_pause and tx_pause status according to actual setting of
1762 : : * the TFCE and RFCE bits in the CTRL register.
1763 : : */
1764 : 0 : ctrl = E1000_READ_REG(hw, E1000_CTRL);
1765 [ # # ]: 0 : if (ctrl & E1000_CTRL_TFCE)
1766 : : tx_pause = 1;
1767 : : else
1768 : : tx_pause = 0;
1769 : :
1770 [ # # ]: 0 : if (ctrl & E1000_CTRL_RFCE)
1771 : : rx_pause = 1;
1772 : : else
1773 : : rx_pause = 0;
1774 : :
1775 [ # # ]: 0 : if (rx_pause && tx_pause)
1776 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
1777 [ # # ]: 0 : else if (rx_pause)
1778 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
1779 [ # # ]: 0 : else if (tx_pause)
1780 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
1781 : : else
1782 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
1783 : :
1784 : 0 : return 0;
1785 : : }
1786 : :
1787 : : static int
1788 : 0 : eth_em_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1789 : : {
1790 : : struct e1000_hw *hw;
1791 : : int err;
1792 : 0 : enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
1793 : : e1000_fc_none,
1794 : : e1000_fc_rx_pause,
1795 : : e1000_fc_tx_pause,
1796 : : e1000_fc_full
1797 : : };
1798 : : uint32_t rx_buf_size;
1799 : : uint32_t max_high_water;
1800 : : uint32_t rctl;
1801 : :
1802 : : /*
1803 : : * This function calls into the base driver, which in turn will use
1804 : : * function pointers, which are not guaranteed to be valid in secondary
1805 : : * processes, so avoid using this function in secondary processes.
1806 : : */
1807 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1808 : : return -E_RTE_SECONDARY;
1809 : :
1810 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1811 [ # # ]: 0 : if (fc_conf->autoneg != hw->mac.autoneg)
1812 : : return -ENOTSUP;
1813 : : rx_buf_size = em_get_rx_buffer_size(hw);
1814 : 0 : PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
1815 : :
1816 : : /* At least reserve one Ethernet frame for watermark */
1817 : 0 : max_high_water = rx_buf_size - RTE_ETHER_MAX_LEN;
1818 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
1819 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
1820 : 0 : PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
1821 : 0 : PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
1822 : 0 : return -EINVAL;
1823 : : }
1824 : :
1825 : 0 : hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
1826 : 0 : hw->fc.pause_time = fc_conf->pause_time;
1827 : 0 : hw->fc.high_water = fc_conf->high_water;
1828 : 0 : hw->fc.low_water = fc_conf->low_water;
1829 : 0 : hw->fc.send_xon = fc_conf->send_xon;
1830 : :
1831 : 0 : err = e1000_setup_link_generic(hw);
1832 [ # # ]: 0 : if (err == E1000_SUCCESS) {
1833 : :
1834 : : /* check if we want to forward MAC frames - driver doesn't have native
1835 : : * capability to do that, so we'll write the registers ourselves */
1836 : :
1837 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1838 : :
1839 : : /* set or clear MFLCN.PMCF bit depending on configuration */
1840 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
1841 : 0 : rctl |= E1000_RCTL_PMCF;
1842 : : else
1843 : 0 : rctl &= ~E1000_RCTL_PMCF;
1844 : :
1845 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1846 : 0 : E1000_WRITE_FLUSH(hw);
1847 : :
1848 : 0 : return 0;
1849 : : }
1850 : :
1851 : 0 : PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
1852 : 0 : return -EIO;
1853 : : }
1854 : :
1855 : : static int
1856 : 0 : eth_em_rar_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1857 : : uint32_t index, __rte_unused uint32_t pool)
1858 : : {
1859 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1860 : :
1861 : : /*
1862 : : * This function calls into the base driver, which in turn will use
1863 : : * function pointers, which are not guaranteed to be valid in secondary
1864 : : * processes, so avoid using this function in secondary processes.
1865 : : */
1866 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1867 : : return -E_RTE_SECONDARY;
1868 : :
1869 : 0 : return e1000_rar_set(hw, mac_addr->addr_bytes, index);
1870 : : }
1871 : :
1872 : : static void
1873 : 0 : eth_em_rar_clear(struct rte_eth_dev *dev, uint32_t index)
1874 : : {
1875 : : uint8_t addr[RTE_ETHER_ADDR_LEN];
1876 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1877 : :
1878 : : /*
1879 : : * This function calls into the base driver, which in turn will use
1880 : : * function pointers, which are not guaranteed to be valid in secondary
1881 : : * processes, so avoid using this function in secondary processes.
1882 : : */
1883 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1884 : 0 : return;
1885 : :
1886 : : memset(addr, 0, sizeof(addr));
1887 : :
1888 : 0 : e1000_rar_set(hw, addr, index);
1889 : : }
1890 : :
1891 : : static int
1892 : 0 : eth_em_default_mac_addr_set(struct rte_eth_dev *dev,
1893 : : struct rte_ether_addr *addr)
1894 : : {
1895 : : /*
1896 : : * This function calls into the base driver, which in turn will use
1897 : : * function pointers, which are not guaranteed to be valid in secondary
1898 : : * processes, so avoid using this function in secondary processes.
1899 : : */
1900 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1901 : : return -E_RTE_SECONDARY;
1902 : :
1903 : 0 : eth_em_rar_clear(dev, 0);
1904 : :
1905 : 0 : return eth_em_rar_set(dev, (void *)addr, 0, 0);
1906 : : }
1907 : :
1908 : : static int
1909 : 0 : eth_em_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1910 : : {
1911 : : struct e1000_hw *hw;
1912 : : uint32_t frame_size;
1913 : : uint32_t rctl;
1914 : :
1915 : 0 : frame_size = mtu + E1000_ETH_OVERHEAD;
1916 : :
1917 : : /*
1918 : : * If device is started, refuse mtu that requires the support of
1919 : : * scattered packets when this feature has not been enabled before.
1920 : : */
1921 [ # # ]: 0 : if (dev->data->dev_started && !dev->data->scattered_rx &&
1922 [ # # ]: 0 : frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
1923 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
1924 : 0 : return -EINVAL;
1925 : : }
1926 : :
1927 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1928 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1929 : :
1930 : : /* switch to jumbo mode if needed */
1931 [ # # ]: 0 : if (mtu > RTE_ETHER_MTU)
1932 : 0 : rctl |= E1000_RCTL_LPE;
1933 : : else
1934 : 0 : rctl &= ~E1000_RCTL_LPE;
1935 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1936 : :
1937 : 0 : return 0;
1938 : : }
1939 : :
1940 : : static int
1941 : 0 : eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
1942 : : struct rte_ether_addr *mc_addr_set,
1943 : : uint32_t nb_mc_addr)
1944 : : {
1945 : : struct e1000_hw *hw;
1946 : :
1947 : : /*
1948 : : * This function calls into the base driver, which in turn will use
1949 : : * function pointers, which are not guaranteed to be valid in secondary
1950 : : * processes, so avoid using this function in secondary processes.
1951 : : */
1952 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1953 : : return -E_RTE_SECONDARY;
1954 : :
1955 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1956 : 0 : e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
1957 : 0 : return 0;
1958 : : }
1959 : :
1960 : 253 : RTE_PMD_REGISTER_PCI(net_e1000_em, rte_em_pmd);
1961 : : RTE_PMD_REGISTER_PCI_TABLE(net_e1000_em, pci_id_em_map);
1962 : : RTE_PMD_REGISTER_KMOD_DEP(net_e1000_em, "* igb_uio | uio_pci_generic | vfio-pci");
|