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