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