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);
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 : 0 : ret = eth_em_stop(dev);
577 [ # # ]: 0 : if (ret != 0)
578 : : return ret;
579 : :
580 : 0 : e1000_power_up_phy(hw);
581 : :
582 : : /* Set default PBA value */
583 : : em_set_pba(hw);
584 : :
585 : : /* Put the address into the Receive Address Array */
586 : 0 : e1000_rar_set(hw, hw->mac.addr, 0);
587 : :
588 : : /*
589 : : * With the 82571 adapter, RAR[0] may be overwritten
590 : : * when the other port is reset, we make a duplicate
591 : : * in RAR[14] for that eventuality, this assures
592 : : * the interface continues to function.
593 : : */
594 [ # # ]: 0 : if (hw->mac.type == e1000_82571) {
595 : 0 : e1000_set_laa_state_82571(hw, TRUE);
596 : 0 : e1000_rar_set(hw, hw->mac.addr, E1000_RAR_ENTRIES - 1);
597 : : }
598 : :
599 : : /* Initialize the hardware */
600 [ # # ]: 0 : if (em_hardware_init(hw)) {
601 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
602 : 0 : return -EIO;
603 : : }
604 : :
605 : 0 : E1000_WRITE_REG(hw, E1000_VET, RTE_ETHER_TYPE_VLAN);
606 : :
607 : : /* Configure for OS presence */
608 : 0 : em_init_manageability(hw);
609 : :
610 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq != 0) {
611 : 0 : intr_vector = dev->data->nb_rx_queues;
612 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector))
613 : : return -1;
614 : : }
615 : :
616 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
617 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
618 : 0 : dev->data->nb_rx_queues)) {
619 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
620 : : " intr_vec", dev->data->nb_rx_queues);
621 : 0 : return -ENOMEM;
622 : : }
623 : :
624 : : /* enable rx interrupt */
625 : : em_rxq_intr_enable(hw);
626 : : }
627 : :
628 : 0 : eth_em_tx_init(dev);
629 : :
630 : 0 : ret = eth_em_rx_init(dev);
631 [ # # ]: 0 : if (ret) {
632 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
633 : 0 : em_dev_clear_queues(dev);
634 : 0 : return ret;
635 : : }
636 : :
637 : 0 : e1000_clear_hw_cntrs_base_generic(hw);
638 : :
639 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
640 : : RTE_ETH_VLAN_EXTEND_MASK;
641 : 0 : ret = eth_em_vlan_offload_set(dev, mask);
642 [ # # ]: 0 : if (ret) {
643 : 0 : PMD_INIT_LOG(ERR, "Unable to update vlan offload");
644 : 0 : em_dev_clear_queues(dev);
645 : 0 : return ret;
646 : : }
647 : :
648 : : /* Set Interrupt Throttling Rate to maximum allowed value. */
649 : 0 : E1000_WRITE_REG(hw, E1000_ITR, UINT16_MAX);
650 : :
651 : : /* Setup link speed and duplex */
652 : 0 : speeds = &dev->data->dev_conf.link_speeds;
653 [ # # ]: 0 : if (*speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
654 : 0 : hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
655 : 0 : hw->mac.autoneg = 1;
656 : : } else {
657 : : num_speeds = 0;
658 : 0 : autoneg = (*speeds & RTE_ETH_LINK_SPEED_FIXED) == 0;
659 : :
660 : : /* Reset */
661 : 0 : hw->phy.autoneg_advertised = 0;
662 : :
663 [ # # ]: 0 : if (*speeds & ~(RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
664 : : RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
665 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_FIXED)) {
666 : : num_speeds = -1;
667 : 0 : goto error_invalid_config;
668 : : }
669 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_10M_HD) {
670 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
671 : : num_speeds++;
672 : : }
673 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_10M) {
674 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
675 : 0 : num_speeds++;
676 : : }
677 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_100M_HD) {
678 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
679 : 0 : num_speeds++;
680 : : }
681 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_100M) {
682 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
683 : 0 : num_speeds++;
684 : : }
685 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_1G) {
686 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
687 : 0 : num_speeds++;
688 : : }
689 [ # # # # ]: 0 : if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
690 : 0 : goto error_invalid_config;
691 : :
692 : : /* Set/reset the mac.autoneg based on the link speed,
693 : : * fixed or not
694 : : */
695 [ # # ]: 0 : if (!autoneg) {
696 : 0 : hw->mac.autoneg = 0;
697 : 0 : hw->mac.forced_speed_duplex =
698 : 0 : hw->phy.autoneg_advertised;
699 : : } else {
700 : 0 : hw->mac.autoneg = 1;
701 : : }
702 : : }
703 : :
704 : 0 : e1000_setup_link(hw);
705 : :
706 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
707 : : /* check if lsc interrupt is enabled */
708 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0) {
709 : : ret = eth_em_interrupt_setup(dev);
710 : : if (ret) {
711 : : PMD_INIT_LOG(ERR, "Unable to setup interrupts");
712 : : em_dev_clear_queues(dev);
713 : : return ret;
714 : : }
715 : : }
716 : : } else {
717 : 0 : rte_intr_callback_unregister(intr_handle,
718 : : eth_em_interrupt_handler,
719 : : (void *)dev);
720 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
721 : 0 : PMD_INIT_LOG(INFO, "lsc won't enable because of"
722 : : " no intr multiplexn");
723 : : }
724 : : /* check if rxq interrupt is enabled */
725 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq != 0)
726 : : eth_em_rxq_interrupt_setup(dev);
727 : :
728 : 0 : rte_intr_enable(intr_handle);
729 : :
730 : 0 : adapter->stopped = 0;
731 : :
732 : 0 : eth_em_rxtx_control(dev, true);
733 : 0 : eth_em_link_update(dev, 0);
734 : :
735 : 0 : PMD_INIT_LOG(DEBUG, "<<");
736 : :
737 : 0 : return 0;
738 : :
739 : 0 : error_invalid_config:
740 : 0 : PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
741 : : dev->data->dev_conf.link_speeds, dev->data->port_id);
742 : 0 : em_dev_clear_queues(dev);
743 : 0 : return -EINVAL;
744 : : }
745 : :
746 : : /*********************************************************************
747 : : *
748 : : * This routine disables all traffic on the adapter by issuing a
749 : : * global reset on the MAC.
750 : : *
751 : : **********************************************************************/
752 : : static int
753 : 0 : eth_em_stop(struct rte_eth_dev *dev)
754 : : {
755 : : struct rte_eth_link link;
756 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
757 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
758 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
759 : :
760 : 0 : dev->data->dev_started = 0;
761 : :
762 : 0 : eth_em_rxtx_control(dev, false);
763 : : em_rxq_intr_disable(hw);
764 : : em_lsc_intr_disable(hw);
765 : :
766 : 0 : e1000_reset_hw(hw);
767 : :
768 : : /* Flush desc rings for i219 */
769 [ # # ]: 0 : if (hw->mac.type == e1000_pch_spt || hw->mac.type == e1000_pch_cnp)
770 : 0 : em_flush_desc_rings(dev);
771 : :
772 [ # # ]: 0 : if (hw->mac.type >= e1000_82544)
773 : 0 : E1000_WRITE_REG(hw, E1000_WUC, 0);
774 : :
775 : : /* Power down the phy. Needed to make the link go down */
776 : 0 : e1000_power_down_phy(hw);
777 : :
778 : 0 : em_dev_clear_queues(dev);
779 : :
780 : : /* clear the recorded link status */
781 : : memset(&link, 0, sizeof(link));
782 : 0 : rte_eth_linkstatus_set(dev, &link);
783 : :
784 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
785 : : /* resume to the default handler */
786 : 0 : rte_intr_callback_register(intr_handle,
787 : : eth_em_interrupt_handler,
788 : : (void *)dev);
789 : :
790 : : /* Clean datapath event and queue/vec mapping */
791 : 0 : rte_intr_efd_disable(intr_handle);
792 : 0 : rte_intr_vec_list_free(intr_handle);
793 : :
794 : 0 : return 0;
795 : : }
796 : :
797 : : static int
798 : 0 : eth_em_close(struct rte_eth_dev *dev)
799 : : {
800 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
801 : : struct e1000_adapter *adapter =
802 : : E1000_DEV_PRIVATE(dev->data->dev_private);
803 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
804 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
805 : : int ret;
806 : :
807 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
808 : : return 0;
809 : :
810 : 0 : ret = eth_em_stop(dev);
811 : 0 : adapter->stopped = 1;
812 : 0 : em_dev_free_queues(dev);
813 : 0 : e1000_phy_hw_reset(hw);
814 : 0 : em_release_manageability(hw);
815 : : em_hw_control_release(hw);
816 : :
817 : : /* disable uio intr before callback unregister */
818 : 0 : rte_intr_disable(intr_handle);
819 : 0 : rte_intr_callback_unregister(intr_handle,
820 : : eth_em_interrupt_handler, dev);
821 : :
822 : 0 : return ret;
823 : : }
824 : :
825 : : static int
826 : : em_get_rx_buffer_size(struct e1000_hw *hw)
827 : : {
828 : : uint32_t rx_buf_size;
829 : :
830 : 0 : rx_buf_size = ((E1000_READ_REG(hw, E1000_PBA) & UINT16_MAX) << 10);
831 : : return rx_buf_size;
832 : : }
833 : :
834 : : /*********************************************************************
835 : : *
836 : : * Initialize the hardware
837 : : *
838 : : **********************************************************************/
839 : : static int
840 : 0 : em_hardware_init(struct e1000_hw *hw)
841 : : {
842 : : uint32_t rx_buf_size;
843 : : int diag;
844 : :
845 : : /* Issue a global reset */
846 : 0 : e1000_reset_hw(hw);
847 : :
848 : : /* Let the firmware know the OS is in control */
849 : : em_hw_control_acquire(hw);
850 : :
851 : : /*
852 : : * These parameters control the automatic generation (Tx) and
853 : : * response (Rx) to Ethernet PAUSE frames.
854 : : * - High water mark should allow for at least two standard size (1518)
855 : : * frames to be received after sending an XOFF.
856 : : * - Low water mark works best when it is very near the high water mark.
857 : : * This allows the receiver to restart by sending XON when it has
858 : : * drained a bit. Here we use an arbitrary value of 1500 which will
859 : : * restart after one full frame is pulled from the buffer. There
860 : : * could be several smaller frames in the buffer and if so they will
861 : : * not trigger the XON until their total number reduces the buffer
862 : : * by 1500.
863 : : * - The pause time is fairly large at 1000 x 512ns = 512 usec.
864 : : */
865 : : rx_buf_size = em_get_rx_buffer_size(hw);
866 : :
867 : 0 : hw->fc.high_water = rx_buf_size -
868 : : PMD_ROUNDUP(RTE_ETHER_MAX_LEN * 2, 1024);
869 : 0 : hw->fc.low_water = hw->fc.high_water - 1500;
870 : :
871 [ # # ]: 0 : if (hw->mac.type == e1000_80003es2lan)
872 : 0 : hw->fc.pause_time = UINT16_MAX;
873 : : else
874 : 0 : hw->fc.pause_time = EM_FC_PAUSE_TIME;
875 : :
876 : 0 : hw->fc.send_xon = 1;
877 : :
878 : : /* Set Flow control, use the tunable location if sane */
879 [ # # ]: 0 : if (em_fc_setting <= e1000_fc_full)
880 : 0 : hw->fc.requested_mode = em_fc_setting;
881 : : else
882 : 0 : hw->fc.requested_mode = e1000_fc_none;
883 : :
884 : : /* Workaround: no TX flow ctrl for PCH */
885 [ # # ]: 0 : if (hw->mac.type == e1000_pchlan)
886 : 0 : hw->fc.requested_mode = e1000_fc_rx_pause;
887 : :
888 : : /* Override - settings for PCH2LAN, ya its magic :) */
889 [ # # ]: 0 : if (hw->mac.type == e1000_pch2lan) {
890 : 0 : hw->fc.high_water = 0x5C20;
891 : 0 : hw->fc.low_water = 0x5048;
892 : 0 : hw->fc.pause_time = 0x0650;
893 : 0 : hw->fc.refresh_time = 0x0400;
894 : 0 : } else if (hw->mac.type == e1000_pch_lpt ||
895 : : hw->mac.type == e1000_pch_spt ||
896 : : hw->mac.type == e1000_pch_cnp ||
897 [ # # ]: 0 : hw->mac.type == e1000_pch_adp ||
898 [ # # ]: 0 : hw->mac.type == e1000_pch_tgp ||
899 [ # # ]: 0 : hw->mac.type == e1000_pch_mtp ||
900 : : hw->mac.type == e1000_pch_ptp) {
901 : 0 : hw->fc.requested_mode = e1000_fc_full;
902 : : }
903 : :
904 : 0 : diag = e1000_init_hw(hw);
905 [ # # ]: 0 : if (diag < 0)
906 : : return diag;
907 : 0 : e1000_check_for_link(hw);
908 : 0 : return 0;
909 : : }
910 : :
911 : : /* This function is based on em_update_stats_counters() in e1000/if_em.c */
912 : : static int
913 : 0 : eth_em_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
914 : : {
915 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
916 : : struct e1000_hw_stats *stats =
917 : : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
918 : : int pause_frames;
919 : :
920 [ # # ]: 0 : if(hw->phy.media_type == e1000_media_type_copper ||
921 [ # # ]: 0 : (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
922 : 0 : stats->symerrs += E1000_READ_REG(hw,E1000_SYMERRS);
923 : 0 : stats->sec += E1000_READ_REG(hw, E1000_SEC);
924 : : }
925 : :
926 : 0 : stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
927 : 0 : stats->mpc += E1000_READ_REG(hw, E1000_MPC);
928 : 0 : stats->scc += E1000_READ_REG(hw, E1000_SCC);
929 : 0 : stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
930 : :
931 : 0 : stats->mcc += E1000_READ_REG(hw, E1000_MCC);
932 : 0 : stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
933 : 0 : stats->colc += E1000_READ_REG(hw, E1000_COLC);
934 : 0 : stats->dc += E1000_READ_REG(hw, E1000_DC);
935 : 0 : stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
936 : 0 : stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
937 : 0 : stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
938 : :
939 : : /*
940 : : * For watchdog management we need to know if we have been
941 : : * paused during the last interval, so capture that here.
942 : : */
943 : 0 : pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
944 : 0 : stats->xoffrxc += pause_frames;
945 : 0 : stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
946 : 0 : stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
947 : 0 : stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
948 : 0 : stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
949 : 0 : stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
950 : 0 : stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
951 : 0 : stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
952 : 0 : stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
953 : 0 : stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
954 : 0 : stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
955 : 0 : stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
956 : 0 : stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
957 : :
958 : : /*
959 : : * For the 64-bit byte counters the low dword must be read first.
960 : : * Both registers clear on the read of the high dword.
961 : : */
962 : :
963 : 0 : stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
964 : 0 : stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
965 : 0 : stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
966 : 0 : stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
967 : :
968 : 0 : stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
969 : 0 : stats->ruc += E1000_READ_REG(hw, E1000_RUC);
970 : 0 : stats->rfc += E1000_READ_REG(hw, E1000_RFC);
971 : 0 : stats->roc += E1000_READ_REG(hw, E1000_ROC);
972 : 0 : stats->rjc += E1000_READ_REG(hw, E1000_RJC);
973 : :
974 : 0 : stats->tor += E1000_READ_REG(hw, E1000_TORH);
975 : 0 : stats->tot += E1000_READ_REG(hw, E1000_TOTH);
976 : :
977 : 0 : stats->tpr += E1000_READ_REG(hw, E1000_TPR);
978 : 0 : stats->tpt += E1000_READ_REG(hw, E1000_TPT);
979 : 0 : stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
980 : 0 : stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
981 : 0 : stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
982 : 0 : stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
983 : 0 : stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
984 : 0 : stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
985 : 0 : stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
986 : 0 : stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
987 : :
988 : : /* Interrupt Counts */
989 : :
990 [ # # ]: 0 : if (hw->mac.type >= e1000_82571) {
991 : 0 : stats->iac += E1000_READ_REG(hw, E1000_IAC);
992 : 0 : stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
993 : 0 : stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
994 : 0 : stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
995 : 0 : stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
996 : 0 : stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
997 : 0 : stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
998 : 0 : stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
999 : 0 : stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1000 : : }
1001 : :
1002 [ # # ]: 0 : if (hw->mac.type >= e1000_82543) {
1003 : 0 : stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1004 : 0 : stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1005 : 0 : stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1006 : 0 : stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1007 : 0 : stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1008 : 0 : stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1009 : : }
1010 : :
1011 [ # # ]: 0 : if (rte_stats == NULL)
1012 : : return -EINVAL;
1013 : :
1014 : : /* Rx Errors */
1015 : 0 : rte_stats->imissed = stats->mpc;
1016 : 0 : rte_stats->ierrors = stats->crcerrs + stats->rlec +
1017 : 0 : stats->rxerrc + stats->algnerrc + stats->cexterr;
1018 : :
1019 : : /* Tx Errors */
1020 : 0 : rte_stats->oerrors = stats->ecol + stats->latecol;
1021 : :
1022 : 0 : rte_stats->ipackets = stats->gprc;
1023 : 0 : rte_stats->opackets = stats->gptc;
1024 : 0 : rte_stats->ibytes = stats->gorc;
1025 : 0 : rte_stats->obytes = stats->gotc;
1026 : 0 : return 0;
1027 : : }
1028 : :
1029 : : static int
1030 : 0 : eth_em_stats_reset(struct rte_eth_dev *dev)
1031 : : {
1032 : 0 : struct e1000_hw_stats *hw_stats =
1033 : 0 : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1034 : :
1035 : : /* HW registers are cleared on read */
1036 : 0 : eth_em_stats_get(dev, NULL);
1037 : :
1038 : : /* Reset software totals */
1039 : : memset(hw_stats, 0, sizeof(*hw_stats));
1040 : :
1041 : 0 : return 0;
1042 : : }
1043 : :
1044 : : static int
1045 : 0 : eth_em_rx_queue_intr_enable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
1046 : : {
1047 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1048 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1049 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1050 : :
1051 : : em_rxq_intr_enable(hw);
1052 : 0 : rte_intr_ack(intr_handle);
1053 : :
1054 : 0 : return 0;
1055 : : }
1056 : :
1057 : : static int
1058 : 0 : eth_em_rx_queue_intr_disable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
1059 : : {
1060 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1061 : :
1062 : : em_rxq_intr_disable(hw);
1063 : :
1064 : 0 : return 0;
1065 : : }
1066 : :
1067 : : uint32_t
1068 : 0 : em_get_max_pktlen(struct rte_eth_dev *dev)
1069 : : {
1070 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1071 : :
1072 [ # # # # ]: 0 : switch (hw->mac.type) {
1073 : : case e1000_82571:
1074 : : case e1000_82572:
1075 : : case e1000_ich9lan:
1076 : : case e1000_ich10lan:
1077 : : case e1000_pch2lan:
1078 : : case e1000_pch_lpt:
1079 : : case e1000_pch_spt:
1080 : : case e1000_pch_cnp:
1081 : : case e1000_pch_adp:
1082 : : case e1000_pch_tgp:
1083 : : case e1000_pch_mtp:
1084 : : case e1000_pch_ptp:
1085 : : case e1000_82574:
1086 : : case e1000_80003es2lan: /* 9K Jumbo Frame size */
1087 : : case e1000_82583:
1088 : : return 0x2412;
1089 : 0 : case e1000_pchlan:
1090 : 0 : return 0x1000;
1091 : : /* Adapters that do not support jumbo frames */
1092 : 0 : case e1000_ich8lan:
1093 : 0 : return RTE_ETHER_MAX_LEN;
1094 : 0 : default:
1095 : 0 : return MAX_JUMBO_FRAME_SIZE;
1096 : : }
1097 : : }
1098 : :
1099 : : static int
1100 : 0 : eth_em_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1101 : : {
1102 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1103 : :
1104 : 0 : dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1105 : 0 : dev_info->max_rx_pktlen = em_get_max_pktlen(dev);
1106 : 0 : dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1107 : :
1108 : : /*
1109 : : * Starting with 631xESB hw supports 2 TX/RX queues per port.
1110 : : * Unfortunately, all these nics have just one TX context.
1111 : : * So we have few choices for TX:
1112 : : * - Use just one TX queue.
1113 : : * - Allow cksum offload only for one TX queue.
1114 : : * - Don't allow TX cksum offload at all.
1115 : : * For now, option #1 was chosen.
1116 : : * To use second RX queue we have to use extended RX descriptor
1117 : : * (Multiple Receive Queues are mutually exclusive with UDP
1118 : : * fragmentation and are not supported when a legacy receive
1119 : : * descriptor format is used).
1120 : : * Which means separate RX routines - as legacy nics (82540, 82545)
1121 : : * don't support extended RXD.
1122 : : * To avoid it we support just one RX queue for now (no RSS).
1123 : : */
1124 : :
1125 : 0 : dev_info->max_rx_queues = 2;
1126 : 0 : dev_info->max_tx_queues = 2;
1127 : :
1128 : 0 : dev_info->rx_queue_offload_capa = em_get_rx_queue_offloads_capa();
1129 : 0 : dev_info->rx_offload_capa = em_get_rx_port_offloads_capa() |
1130 : 0 : dev_info->rx_queue_offload_capa;
1131 : 0 : dev_info->tx_queue_offload_capa = em_get_tx_queue_offloads_capa(dev);
1132 : 0 : dev_info->tx_offload_capa = em_get_tx_port_offloads_capa(dev) |
1133 : 0 : dev_info->tx_queue_offload_capa;
1134 : :
1135 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1136 : : .nb_max = E1000_MAX_RING_DESC,
1137 : : .nb_min = E1000_MIN_RING_DESC,
1138 : : .nb_align = EM_RXD_ALIGN,
1139 : : };
1140 : :
1141 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1142 : : .nb_max = E1000_MAX_RING_DESC,
1143 : : .nb_min = E1000_MIN_RING_DESC,
1144 : : .nb_align = EM_TXD_ALIGN,
1145 : : .nb_seg_max = EM_TX_MAX_SEG,
1146 : : .nb_mtu_seg_max = EM_TX_MAX_MTU_SEG,
1147 : : };
1148 : :
1149 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
1150 : : RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
1151 : : RTE_ETH_LINK_SPEED_1G;
1152 : :
1153 : 0 : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
1154 : :
1155 : : /* Preferred queue parameters */
1156 : 0 : dev_info->default_rxportconf.nb_queues = 1;
1157 : 0 : dev_info->default_txportconf.nb_queues = 1;
1158 : 0 : dev_info->default_txportconf.ring_size = 256;
1159 : 0 : dev_info->default_rxportconf.ring_size = 256;
1160 : :
1161 : 0 : return 0;
1162 : : }
1163 : :
1164 : : /* return 0 means link status changed, -1 means not changed */
1165 : : static int
1166 : 0 : eth_em_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1167 : : {
1168 : 0 : struct e1000_hw *hw =
1169 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1170 : : struct rte_eth_link link;
1171 : : int link_up, count;
1172 : :
1173 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1174 : : return -1;
1175 : :
1176 : : link_up = 0;
1177 : 0 : hw->mac.get_link_status = 1;
1178 : :
1179 : : /* possible wait-to-complete in up to 9 seconds */
1180 [ # # ]: 0 : for (count = 0; count < EM_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
1181 : : /* Read the real link status */
1182 [ # # # # ]: 0 : switch (hw->phy.media_type) {
1183 : 0 : case e1000_media_type_copper:
1184 : : /* Do the work to read phy */
1185 : 0 : e1000_check_for_link(hw);
1186 : 0 : link_up = !hw->mac.get_link_status;
1187 : 0 : break;
1188 : :
1189 : 0 : case e1000_media_type_fiber:
1190 : 0 : e1000_check_for_link(hw);
1191 : 0 : link_up = (E1000_READ_REG(hw, E1000_STATUS) &
1192 : : E1000_STATUS_LU);
1193 : 0 : break;
1194 : :
1195 : 0 : case e1000_media_type_internal_serdes:
1196 : 0 : e1000_check_for_link(hw);
1197 : 0 : link_up = hw->mac.serdes_has_link;
1198 : 0 : break;
1199 : :
1200 : : default:
1201 : : break;
1202 : : }
1203 [ # # ]: 0 : if (link_up || wait_to_complete == 0)
1204 : : break;
1205 : : rte_delay_ms(EM_LINK_UPDATE_CHECK_INTERVAL);
1206 : : }
1207 : : memset(&link, 0, sizeof(link));
1208 : :
1209 : : /* Now we check if a transition has happened */
1210 [ # # ]: 0 : if (link_up) {
1211 : : uint16_t duplex, speed;
1212 : 0 : hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
1213 : 0 : link.link_duplex = (duplex == FULL_DUPLEX) ?
1214 : 0 : RTE_ETH_LINK_FULL_DUPLEX :
1215 : : RTE_ETH_LINK_HALF_DUPLEX;
1216 : 0 : link.link_speed = speed;
1217 : 0 : link.link_status = RTE_ETH_LINK_UP;
1218 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1219 : : RTE_ETH_LINK_SPEED_FIXED);
1220 : : } else {
1221 : : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1222 : : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1223 : : link.link_status = RTE_ETH_LINK_DOWN;
1224 : : link.link_autoneg = RTE_ETH_LINK_FIXED;
1225 : : }
1226 : :
1227 : : return rte_eth_linkstatus_set(dev, &link);
1228 : : }
1229 : :
1230 : : /*
1231 : : * em_hw_control_acquire sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
1232 : : * For ASF and Pass Through versions of f/w this means
1233 : : * that the driver is loaded. For AMT version type f/w
1234 : : * this means that the network i/f is open.
1235 : : */
1236 : : static void
1237 : : em_hw_control_acquire(struct e1000_hw *hw)
1238 : : {
1239 : : uint32_t ctrl_ext, swsm;
1240 : :
1241 : : /* Let firmware know the driver has taken over */
1242 [ # # ]: 0 : if (hw->mac.type == e1000_82573) {
1243 : 0 : swsm = E1000_READ_REG(hw, E1000_SWSM);
1244 : 0 : E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD);
1245 : :
1246 : : } else {
1247 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1248 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1249 : : ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1250 : : }
1251 : : }
1252 : :
1253 : : /*
1254 : : * em_hw_control_release resets {CTRL_EXTT|FWSM}:DRV_LOAD bit.
1255 : : * For ASF and Pass Through versions of f/w this means that the
1256 : : * driver is no longer loaded. For AMT versions of the
1257 : : * f/w this means that the network i/f is closed.
1258 : : */
1259 : : static void
1260 : : em_hw_control_release(struct e1000_hw *hw)
1261 : : {
1262 : : uint32_t ctrl_ext, swsm;
1263 : :
1264 : : /* Let firmware taken over control of h/w */
1265 [ # # # # ]: 0 : if (hw->mac.type == e1000_82573) {
1266 : 0 : swsm = E1000_READ_REG(hw, E1000_SWSM);
1267 : 0 : E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
1268 : : } else {
1269 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1270 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1271 : : ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1272 : : }
1273 : : }
1274 : :
1275 : : /*
1276 : : * Bit of a misnomer, what this really means is
1277 : : * to enable OS management of the system... aka
1278 : : * to disable special hardware management features.
1279 : : */
1280 : : static void
1281 : 0 : em_init_manageability(struct e1000_hw *hw)
1282 : : {
1283 [ # # ]: 0 : if (e1000_enable_mng_pass_thru(hw)) {
1284 : 0 : uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
1285 : 0 : uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1286 : :
1287 : : /* disable hardware interception of ARP */
1288 : 0 : manc &= ~(E1000_MANC_ARP_EN);
1289 : :
1290 : : /* enable receiving management packets to the host */
1291 : 0 : manc |= E1000_MANC_EN_MNG2HOST;
1292 : : manc2h |= 1 << 5; /* Mng Port 623 */
1293 : 0 : manc2h |= 1 << 6; /* Mng Port 664 */
1294 : 0 : E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
1295 : 0 : E1000_WRITE_REG(hw, E1000_MANC, manc);
1296 : : }
1297 : 0 : }
1298 : :
1299 : : /*
1300 : : * Give control back to hardware management
1301 : : * controller if there is one.
1302 : : */
1303 : : static void
1304 : 0 : em_release_manageability(struct e1000_hw *hw)
1305 : : {
1306 : : uint32_t manc;
1307 : :
1308 [ # # ]: 0 : if (e1000_enable_mng_pass_thru(hw)) {
1309 : 0 : manc = E1000_READ_REG(hw, E1000_MANC);
1310 : :
1311 : : /* re-enable hardware interception of ARP */
1312 : : manc |= E1000_MANC_ARP_EN;
1313 : 0 : manc &= ~E1000_MANC_EN_MNG2HOST;
1314 : :
1315 : 0 : E1000_WRITE_REG(hw, E1000_MANC, manc);
1316 : : }
1317 : 0 : }
1318 : :
1319 : : static int
1320 : 0 : eth_em_promiscuous_enable(struct rte_eth_dev *dev)
1321 : : {
1322 : : struct e1000_hw *hw =
1323 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1324 : : uint32_t rctl;
1325 : :
1326 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1327 : 0 : rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1328 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1329 : :
1330 : 0 : return 0;
1331 : : }
1332 : :
1333 : : static int
1334 : 0 : eth_em_promiscuous_disable(struct rte_eth_dev *dev)
1335 : : {
1336 : : struct e1000_hw *hw =
1337 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1338 : : uint32_t rctl;
1339 : :
1340 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1341 : 0 : rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_SBP);
1342 [ # # ]: 0 : if (dev->data->all_multicast == 1)
1343 : 0 : rctl |= E1000_RCTL_MPE;
1344 : : else
1345 : 0 : rctl &= (~E1000_RCTL_MPE);
1346 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1347 : :
1348 : 0 : return 0;
1349 : : }
1350 : :
1351 : : static int
1352 : 0 : eth_em_allmulticast_enable(struct rte_eth_dev *dev)
1353 : : {
1354 : : struct e1000_hw *hw =
1355 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1356 : : uint32_t rctl;
1357 : :
1358 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1359 : 0 : rctl |= E1000_RCTL_MPE;
1360 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1361 : :
1362 : 0 : return 0;
1363 : : }
1364 : :
1365 : : static int
1366 : 0 : eth_em_allmulticast_disable(struct rte_eth_dev *dev)
1367 : : {
1368 : : struct e1000_hw *hw =
1369 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1370 : : uint32_t rctl;
1371 : :
1372 [ # # ]: 0 : if (dev->data->promiscuous == 1)
1373 : : return 0; /* must remain in all_multicast mode */
1374 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1375 : 0 : rctl &= (~E1000_RCTL_MPE);
1376 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1377 : :
1378 : 0 : return 0;
1379 : : }
1380 : :
1381 : : static int
1382 : 0 : eth_em_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1383 : : {
1384 : : struct e1000_hw *hw =
1385 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1386 : : struct e1000_vfta * shadow_vfta =
1387 : : E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1388 : : uint32_t vfta;
1389 : : uint32_t vid_idx;
1390 : : uint32_t vid_bit;
1391 : :
1392 : 0 : vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
1393 : : E1000_VFTA_ENTRY_MASK);
1394 : 0 : vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
1395 : 0 : vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
1396 [ # # ]: 0 : if (on)
1397 : 0 : vfta |= vid_bit;
1398 : : else
1399 : 0 : vfta &= ~vid_bit;
1400 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
1401 : :
1402 : : /* update local VFTA copy */
1403 : 0 : shadow_vfta->vfta[vid_idx] = vfta;
1404 : :
1405 : 0 : return 0;
1406 : : }
1407 : :
1408 : : static void
1409 : : em_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1410 : : {
1411 : : struct e1000_hw *hw =
1412 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1413 : : uint32_t reg;
1414 : :
1415 : : /* Filter Table Disable */
1416 : 0 : reg = E1000_READ_REG(hw, E1000_RCTL);
1417 : : reg &= ~E1000_RCTL_CFIEN;
1418 : 0 : reg &= ~E1000_RCTL_VFE;
1419 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, reg);
1420 : 0 : }
1421 : :
1422 : : static void
1423 : 0 : em_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1424 : : {
1425 : : struct e1000_hw *hw =
1426 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1427 : : struct e1000_vfta * shadow_vfta =
1428 : : E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1429 : : uint32_t reg;
1430 : : int i;
1431 : :
1432 : : /* Filter Table Enable, CFI not used for packet acceptance */
1433 : 0 : reg = E1000_READ_REG(hw, E1000_RCTL);
1434 : 0 : reg &= ~E1000_RCTL_CFIEN;
1435 : 0 : reg |= E1000_RCTL_VFE;
1436 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, reg);
1437 : :
1438 : : /* restore vfta from local copy */
1439 [ # # ]: 0 : for (i = 0; i < IGB_VFTA_SIZE; i++)
1440 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
1441 : 0 : }
1442 : :
1443 : : static void
1444 : : em_vlan_hw_strip_disable(struct rte_eth_dev *dev)
1445 : : {
1446 : : struct e1000_hw *hw =
1447 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1448 : : uint32_t reg;
1449 : :
1450 : : /* VLAN Mode Disable */
1451 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL);
1452 : 0 : reg &= ~E1000_CTRL_VME;
1453 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, reg);
1454 : :
1455 : 0 : }
1456 : :
1457 : : static void
1458 : : em_vlan_hw_strip_enable(struct rte_eth_dev *dev)
1459 : : {
1460 : : struct e1000_hw *hw =
1461 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1462 : : uint32_t reg;
1463 : :
1464 : : /* VLAN Mode Enable */
1465 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL);
1466 : 0 : reg |= E1000_CTRL_VME;
1467 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, reg);
1468 : 0 : }
1469 : :
1470 : : static int
1471 : 0 : eth_em_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1472 : : {
1473 : : struct rte_eth_rxmode *rxmode;
1474 : :
1475 : 0 : rxmode = &dev->data->dev_conf.rxmode;
1476 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1477 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1478 : : em_vlan_hw_strip_enable(dev);
1479 : : else
1480 : : em_vlan_hw_strip_disable(dev);
1481 : : }
1482 : :
1483 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
1484 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
1485 : 0 : em_vlan_hw_filter_enable(dev);
1486 : : else
1487 : : em_vlan_hw_filter_disable(dev);
1488 : : }
1489 : :
1490 : 0 : return 0;
1491 : : }
1492 : :
1493 : : /*
1494 : : * It enables the interrupt mask and then enable the interrupt.
1495 : : *
1496 : : * @param dev
1497 : : * Pointer to struct rte_eth_dev.
1498 : : *
1499 : : * @return
1500 : : * - On success, zero.
1501 : : * - On failure, a negative value.
1502 : : */
1503 : : static int
1504 : : eth_em_interrupt_setup(struct rte_eth_dev *dev)
1505 : : {
1506 : : uint32_t regval;
1507 : : struct e1000_hw *hw =
1508 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1509 : :
1510 : : /* clear interrupt */
1511 : 0 : E1000_READ_REG(hw, E1000_ICR);
1512 : 0 : regval = E1000_READ_REG(hw, E1000_IMS);
1513 : 0 : E1000_WRITE_REG(hw, E1000_IMS,
1514 : : regval | E1000_ICR_LSC | E1000_ICR_OTHER);
1515 : : return 0;
1516 : : }
1517 : :
1518 : : /*
1519 : : * It clears the interrupt causes and enables the interrupt.
1520 : : * It will be called once only during nic initialized.
1521 : : *
1522 : : * @param dev
1523 : : * Pointer to struct rte_eth_dev.
1524 : : *
1525 : : * @return
1526 : : * - On success, zero.
1527 : : * - On failure, a negative value.
1528 : : */
1529 : : static int
1530 : : eth_em_rxq_interrupt_setup(struct rte_eth_dev *dev)
1531 : : {
1532 : : struct e1000_hw *hw =
1533 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1534 : :
1535 : 0 : E1000_READ_REG(hw, E1000_ICR);
1536 : : em_rxq_intr_enable(hw);
1537 : 0 : return 0;
1538 : : }
1539 : :
1540 : : /*
1541 : : * It enable receive packet interrupt.
1542 : : * @param hw
1543 : : * Pointer to struct e1000_hw
1544 : : *
1545 : : * @return
1546 : : */
1547 : : static void
1548 : : em_rxq_intr_enable(struct e1000_hw *hw)
1549 : : {
1550 : 0 : E1000_WRITE_REG(hw, E1000_IMS, E1000_IMS_RXT0);
1551 : 0 : E1000_WRITE_FLUSH(hw);
1552 : 0 : }
1553 : :
1554 : : /*
1555 : : * It disabled lsc interrupt.
1556 : : * @param hw
1557 : : * Pointer to struct e1000_hw
1558 : : *
1559 : : * @return
1560 : : */
1561 : : static void
1562 : : em_lsc_intr_disable(struct e1000_hw *hw)
1563 : : {
1564 : 0 : E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_LSC | E1000_IMS_OTHER);
1565 : 0 : E1000_WRITE_FLUSH(hw);
1566 : : }
1567 : :
1568 : : /*
1569 : : * It disabled receive packet interrupt.
1570 : : * @param hw
1571 : : * Pointer to struct e1000_hw
1572 : : *
1573 : : * @return
1574 : : */
1575 : : static void
1576 : : em_rxq_intr_disable(struct e1000_hw *hw)
1577 : : {
1578 : 0 : E1000_READ_REG(hw, E1000_ICR);
1579 : 0 : E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_RXT0);
1580 : 0 : E1000_WRITE_FLUSH(hw);
1581 : : }
1582 : :
1583 : : /*
1584 : : * It reads ICR and gets interrupt causes, check it and set a bit flag
1585 : : * to update link status.
1586 : : *
1587 : : * @param dev
1588 : : * Pointer to struct rte_eth_dev.
1589 : : *
1590 : : * @return
1591 : : * - On success, zero.
1592 : : * - On failure, a negative value.
1593 : : */
1594 : : static int
1595 : : eth_em_interrupt_get_status(struct rte_eth_dev *dev)
1596 : : {
1597 : : uint32_t icr;
1598 : : struct e1000_hw *hw =
1599 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1600 : : struct e1000_interrupt *intr =
1601 : : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1602 : :
1603 : : /* read-on-clear nic registers here */
1604 : 0 : icr = E1000_READ_REG(hw, E1000_ICR);
1605 [ # # ]: 0 : if (icr & E1000_ICR_LSC) {
1606 : 0 : intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1607 : : }
1608 : :
1609 : : return 0;
1610 : : }
1611 : :
1612 : : /*
1613 : : * It executes link_update after knowing an interrupt is present.
1614 : : *
1615 : : * @param dev
1616 : : * Pointer to struct rte_eth_dev.
1617 : : *
1618 : : * @return
1619 : : * - On success, zero.
1620 : : * - On failure, a negative value.
1621 : : */
1622 : : static int
1623 : 0 : eth_em_interrupt_action(struct rte_eth_dev *dev,
1624 : : struct rte_intr_handle *intr_handle)
1625 : : {
1626 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1627 : : struct e1000_hw *hw =
1628 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1629 : : struct e1000_interrupt *intr =
1630 : : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1631 : : struct rte_eth_link link;
1632 : : int ret;
1633 : :
1634 [ # # ]: 0 : if (!(intr->flags & E1000_FLAG_NEED_LINK_UPDATE))
1635 : : return -1;
1636 : :
1637 : 0 : intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
1638 : 0 : rte_intr_ack(intr_handle);
1639 : :
1640 : : /* set get_link_status to check register later */
1641 : 0 : hw->mac.get_link_status = 1;
1642 : 0 : ret = eth_em_link_update(dev, 0);
1643 : :
1644 : : /* check if link has changed */
1645 [ # # ]: 0 : if (ret < 0)
1646 : : return 0;
1647 : :
1648 : 0 : rte_eth_linkstatus_get(dev, &link);
1649 : :
1650 [ # # ]: 0 : if (link.link_status) {
1651 [ # # ]: 0 : PMD_INIT_LOG(INFO, " Port %d: Link Up - speed %u Mbps - %s",
1652 : : dev->data->port_id, link.link_speed,
1653 : : link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
1654 : : "full-duplex" : "half-duplex");
1655 : : } else {
1656 : 0 : PMD_INIT_LOG(INFO, " Port %d: Link Down", dev->data->port_id);
1657 : : }
1658 : 0 : PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
1659 : : pci_dev->addr.domain, pci_dev->addr.bus,
1660 : : pci_dev->addr.devid, pci_dev->addr.function);
1661 : :
1662 : 0 : return 0;
1663 : : }
1664 : :
1665 : : /**
1666 : : * Interrupt handler which shall be registered at first.
1667 : : *
1668 : : * @param handle
1669 : : * Pointer to interrupt handle.
1670 : : * @param param
1671 : : * The address of parameter (struct rte_eth_dev *) registered before.
1672 : : *
1673 : : * @return
1674 : : * void
1675 : : */
1676 : : static void
1677 : 0 : eth_em_interrupt_handler(void *param)
1678 : : {
1679 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1680 : :
1681 : : eth_em_interrupt_get_status(dev);
1682 : 0 : eth_em_interrupt_action(dev, dev->intr_handle);
1683 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1684 : 0 : }
1685 : :
1686 : : static int
1687 : 0 : eth_em_led_on(struct rte_eth_dev *dev)
1688 : : {
1689 : : struct e1000_hw *hw;
1690 : :
1691 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1692 [ # # ]: 0 : return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
1693 : : }
1694 : :
1695 : : static int
1696 : 0 : eth_em_led_off(struct rte_eth_dev *dev)
1697 : : {
1698 : : struct e1000_hw *hw;
1699 : :
1700 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1701 [ # # ]: 0 : return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
1702 : : }
1703 : :
1704 : : static int
1705 : 0 : eth_em_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1706 : : {
1707 : : struct e1000_hw *hw;
1708 : : uint32_t ctrl;
1709 : : int tx_pause;
1710 : : int rx_pause;
1711 : :
1712 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1713 : 0 : fc_conf->pause_time = hw->fc.pause_time;
1714 : 0 : fc_conf->high_water = hw->fc.high_water;
1715 : 0 : fc_conf->low_water = hw->fc.low_water;
1716 : 0 : fc_conf->send_xon = hw->fc.send_xon;
1717 : 0 : fc_conf->autoneg = hw->mac.autoneg;
1718 : :
1719 : : /*
1720 : : * Return rx_pause and tx_pause status according to actual setting of
1721 : : * the TFCE and RFCE bits in the CTRL register.
1722 : : */
1723 : 0 : ctrl = E1000_READ_REG(hw, E1000_CTRL);
1724 [ # # ]: 0 : if (ctrl & E1000_CTRL_TFCE)
1725 : : tx_pause = 1;
1726 : : else
1727 : : tx_pause = 0;
1728 : :
1729 [ # # ]: 0 : if (ctrl & E1000_CTRL_RFCE)
1730 : : rx_pause = 1;
1731 : : else
1732 : : rx_pause = 0;
1733 : :
1734 [ # # ]: 0 : if (rx_pause && tx_pause)
1735 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
1736 [ # # ]: 0 : else if (rx_pause)
1737 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
1738 [ # # ]: 0 : else if (tx_pause)
1739 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
1740 : : else
1741 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
1742 : :
1743 : 0 : return 0;
1744 : : }
1745 : :
1746 : : static int
1747 : 0 : eth_em_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1748 : : {
1749 : : struct e1000_hw *hw;
1750 : : int err;
1751 : 0 : enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
1752 : : e1000_fc_none,
1753 : : e1000_fc_rx_pause,
1754 : : e1000_fc_tx_pause,
1755 : : e1000_fc_full
1756 : : };
1757 : : uint32_t rx_buf_size;
1758 : : uint32_t max_high_water;
1759 : : uint32_t rctl;
1760 : :
1761 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1762 [ # # ]: 0 : if (fc_conf->autoneg != hw->mac.autoneg)
1763 : : return -ENOTSUP;
1764 : : rx_buf_size = em_get_rx_buffer_size(hw);
1765 : 0 : PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
1766 : :
1767 : : /* At least reserve one Ethernet frame for watermark */
1768 : 0 : max_high_water = rx_buf_size - RTE_ETHER_MAX_LEN;
1769 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
1770 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
1771 : 0 : PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
1772 : 0 : PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
1773 : 0 : return -EINVAL;
1774 : : }
1775 : :
1776 : 0 : hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
1777 : 0 : hw->fc.pause_time = fc_conf->pause_time;
1778 : 0 : hw->fc.high_water = fc_conf->high_water;
1779 : 0 : hw->fc.low_water = fc_conf->low_water;
1780 : 0 : hw->fc.send_xon = fc_conf->send_xon;
1781 : :
1782 : 0 : err = e1000_setup_link_generic(hw);
1783 [ # # ]: 0 : if (err == E1000_SUCCESS) {
1784 : :
1785 : : /* check if we want to forward MAC frames - driver doesn't have native
1786 : : * capability to do that, so we'll write the registers ourselves */
1787 : :
1788 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1789 : :
1790 : : /* set or clear MFLCN.PMCF bit depending on configuration */
1791 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
1792 : 0 : rctl |= E1000_RCTL_PMCF;
1793 : : else
1794 : 0 : rctl &= ~E1000_RCTL_PMCF;
1795 : :
1796 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1797 : 0 : E1000_WRITE_FLUSH(hw);
1798 : :
1799 : 0 : return 0;
1800 : : }
1801 : :
1802 : 0 : PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
1803 : 0 : return -EIO;
1804 : : }
1805 : :
1806 : : static int
1807 : 0 : eth_em_rar_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1808 : : uint32_t index, __rte_unused uint32_t pool)
1809 : : {
1810 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1811 : :
1812 : 0 : return e1000_rar_set(hw, mac_addr->addr_bytes, index);
1813 : : }
1814 : :
1815 : : static void
1816 : 0 : eth_em_rar_clear(struct rte_eth_dev *dev, uint32_t index)
1817 : : {
1818 : : uint8_t addr[RTE_ETHER_ADDR_LEN];
1819 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1820 : :
1821 : : memset(addr, 0, sizeof(addr));
1822 : :
1823 : 0 : e1000_rar_set(hw, addr, index);
1824 : 0 : }
1825 : :
1826 : : static int
1827 : 0 : eth_em_default_mac_addr_set(struct rte_eth_dev *dev,
1828 : : struct rte_ether_addr *addr)
1829 : : {
1830 : 0 : eth_em_rar_clear(dev, 0);
1831 : :
1832 : 0 : return eth_em_rar_set(dev, (void *)addr, 0, 0);
1833 : : }
1834 : :
1835 : : static int
1836 : 0 : eth_em_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1837 : : {
1838 : : struct e1000_hw *hw;
1839 : : uint32_t frame_size;
1840 : : uint32_t rctl;
1841 : :
1842 : 0 : frame_size = mtu + E1000_ETH_OVERHEAD;
1843 : :
1844 : : /*
1845 : : * If device is started, refuse mtu that requires the support of
1846 : : * scattered packets when this feature has not been enabled before.
1847 : : */
1848 [ # # ]: 0 : if (dev->data->dev_started && !dev->data->scattered_rx &&
1849 [ # # ]: 0 : frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
1850 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
1851 : 0 : return -EINVAL;
1852 : : }
1853 : :
1854 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1855 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1856 : :
1857 : : /* switch to jumbo mode if needed */
1858 [ # # ]: 0 : if (mtu > RTE_ETHER_MTU)
1859 : 0 : rctl |= E1000_RCTL_LPE;
1860 : : else
1861 : 0 : rctl &= ~E1000_RCTL_LPE;
1862 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1863 : :
1864 : 0 : return 0;
1865 : : }
1866 : :
1867 : : static int
1868 : 0 : eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
1869 : : struct rte_ether_addr *mc_addr_set,
1870 : : uint32_t nb_mc_addr)
1871 : : {
1872 : : struct e1000_hw *hw;
1873 : :
1874 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1875 : 0 : e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
1876 : 0 : return 0;
1877 : : }
1878 : :
1879 : 252 : RTE_PMD_REGISTER_PCI(net_e1000_em, rte_em_pmd);
1880 : : RTE_PMD_REGISTER_PCI_TABLE(net_e1000_em, pci_id_em_map);
1881 : : RTE_PMD_REGISTER_KMOD_DEP(net_e1000_em, "* igb_uio | uio_pci_generic | vfio-pci");
|