2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2016 Nicole Graziano <nicole@nextbsd.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <machine/_inttypes.h>
34 #define em_mac_min e1000_82571
35 #define igb_mac_min e1000_82575
37 /*********************************************************************
39 *********************************************************************/
40 char em_driver_version[] = "7.6.1-k";
42 /*********************************************************************
45 * Used by probe to select devices to load on
46 * Last field stores an index into e1000_strings
47 * Last entry must be all 0s
49 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
50 *********************************************************************/
52 static pci_vendor_info_t em_vendor_info_array[] =
54 /* Intel(R) - lem-class legacy devices */
55 PVID(0x8086, E1000_DEV_ID_82540EM, "Intel(R) Legacy PRO/1000 MT 82540EM"),
56 PVID(0x8086, E1000_DEV_ID_82540EM_LOM, "Intel(R) Legacy PRO/1000 MT 82540EM (LOM)"),
57 PVID(0x8086, E1000_DEV_ID_82540EP, "Intel(R) Legacy PRO/1000 MT 82540EP"),
58 PVID(0x8086, E1000_DEV_ID_82540EP_LOM, "Intel(R) Legacy PRO/1000 MT 82540EP (LOM)"),
59 PVID(0x8086, E1000_DEV_ID_82540EP_LP, "Intel(R) Legacy PRO/1000 MT 82540EP (Mobile)"),
61 PVID(0x8086, E1000_DEV_ID_82541EI, "Intel(R) Legacy PRO/1000 MT 82541EI (Copper)"),
62 PVID(0x8086, E1000_DEV_ID_82541ER, "Intel(R) Legacy PRO/1000 82541ER"),
63 PVID(0x8086, E1000_DEV_ID_82541ER_LOM, "Intel(R) Legacy PRO/1000 MT 82541ER"),
64 PVID(0x8086, E1000_DEV_ID_82541EI_MOBILE, "Intel(R) Legacy PRO/1000 MT 82541EI (Mobile)"),
65 PVID(0x8086, E1000_DEV_ID_82541GI, "Intel(R) Legacy PRO/1000 MT 82541GI"),
66 PVID(0x8086, E1000_DEV_ID_82541GI_LF, "Intel(R) Legacy PRO/1000 GT 82541PI"),
67 PVID(0x8086, E1000_DEV_ID_82541GI_MOBILE, "Intel(R) Legacy PRO/1000 MT 82541GI (Mobile)"),
69 PVID(0x8086, E1000_DEV_ID_82542, "Intel(R) Legacy PRO/1000 82542 (Fiber)"),
71 PVID(0x8086, E1000_DEV_ID_82543GC_FIBER, "Intel(R) Legacy PRO/1000 F 82543GC (Fiber)"),
72 PVID(0x8086, E1000_DEV_ID_82543GC_COPPER, "Intel(R) Legacy PRO/1000 T 82543GC (Copper)"),
74 PVID(0x8086, E1000_DEV_ID_82544EI_COPPER, "Intel(R) Legacy PRO/1000 XT 82544EI (Copper)"),
75 PVID(0x8086, E1000_DEV_ID_82544EI_FIBER, "Intel(R) Legacy PRO/1000 XF 82544EI (Fiber)"),
76 PVID(0x8086, E1000_DEV_ID_82544GC_COPPER, "Intel(R) Legacy PRO/1000 T 82544GC (Copper)"),
77 PVID(0x8086, E1000_DEV_ID_82544GC_LOM, "Intel(R) Legacy PRO/1000 XT 82544GC (LOM)"),
79 PVID(0x8086, E1000_DEV_ID_82545EM_COPPER, "Intel(R) Legacy PRO/1000 MT 82545EM (Copper)"),
80 PVID(0x8086, E1000_DEV_ID_82545EM_FIBER, "Intel(R) Legacy PRO/1000 MF 82545EM (Fiber)"),
81 PVID(0x8086, E1000_DEV_ID_82545GM_COPPER, "Intel(R) Legacy PRO/1000 MT 82545GM (Copper)"),
82 PVID(0x8086, E1000_DEV_ID_82545GM_FIBER, "Intel(R) Legacy PRO/1000 MF 82545GM (Fiber)"),
83 PVID(0x8086, E1000_DEV_ID_82545GM_SERDES, "Intel(R) Legacy PRO/1000 MB 82545GM (SERDES)"),
85 PVID(0x8086, E1000_DEV_ID_82546EB_COPPER, "Intel(R) Legacy PRO/1000 MT 82546EB (Copper)"),
86 PVID(0x8086, E1000_DEV_ID_82546EB_FIBER, "Intel(R) Legacy PRO/1000 MF 82546EB (Fiber)"),
87 PVID(0x8086, E1000_DEV_ID_82546EB_QUAD_COPPER, "Intel(R) Legacy PRO/1000 MT 82546EB (Quad Copper"),
88 PVID(0x8086, E1000_DEV_ID_82546GB_COPPER, "Intel(R) Legacy PRO/1000 MT 82546GB (Copper)"),
89 PVID(0x8086, E1000_DEV_ID_82546GB_FIBER, "Intel(R) Legacy PRO/1000 MF 82546GB (Fiber)"),
90 PVID(0x8086, E1000_DEV_ID_82546GB_SERDES, "Intel(R) Legacy PRO/1000 MB 82546GB (SERDES)"),
91 PVID(0x8086, E1000_DEV_ID_82546GB_PCIE, "Intel(R) Legacy PRO/1000 P 82546GB (PCIe)"),
92 PVID(0x8086, E1000_DEV_ID_82546GB_QUAD_COPPER, "Intel(R) Legacy PRO/1000 GT 82546GB (Quad Copper)"),
93 PVID(0x8086, E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3, "Intel(R) Legacy PRO/1000 GT 82546GB (Quad Copper)"),
95 PVID(0x8086, E1000_DEV_ID_82547EI, "Intel(R) Legacy PRO/1000 CT 82547EI"),
96 PVID(0x8086, E1000_DEV_ID_82547EI_MOBILE, "Intel(R) Legacy PRO/1000 CT 82547EI (Mobile)"),
97 PVID(0x8086, E1000_DEV_ID_82547GI, "Intel(R) Legacy PRO/1000 CT 82547GI"),
99 /* Intel(R) - em-class devices */
100 PVID(0x8086, E1000_DEV_ID_82571EB_COPPER, "Intel(R) PRO/1000 PT 82571EB/82571GB (Copper)"),
101 PVID(0x8086, E1000_DEV_ID_82571EB_FIBER, "Intel(R) PRO/1000 PF 82571EB/82571GB (Fiber)"),
102 PVID(0x8086, E1000_DEV_ID_82571EB_SERDES, "Intel(R) PRO/1000 PB 82571EB (SERDES)"),
103 PVID(0x8086, E1000_DEV_ID_82571EB_SERDES_DUAL, "Intel(R) PRO/1000 82571EB (Dual Mezzanine)"),
104 PVID(0x8086, E1000_DEV_ID_82571EB_SERDES_QUAD, "Intel(R) PRO/1000 82571EB (Quad Mezzanine)"),
105 PVID(0x8086, E1000_DEV_ID_82571EB_QUAD_COPPER, "Intel(R) PRO/1000 PT 82571EB/82571GB (Quad Copper)"),
106 PVID(0x8086, E1000_DEV_ID_82571EB_QUAD_COPPER_LP, "Intel(R) PRO/1000 PT 82571EB/82571GB (Quad Copper)"),
107 PVID(0x8086, E1000_DEV_ID_82571EB_QUAD_FIBER, "Intel(R) PRO/1000 PF 82571EB (Quad Fiber)"),
108 PVID(0x8086, E1000_DEV_ID_82571PT_QUAD_COPPER, "Intel(R) PRO/1000 PT 82571PT (Quad Copper)"),
109 PVID(0x8086, E1000_DEV_ID_82572EI, "Intel(R) PRO/1000 PT 82572EI (Copper)"),
110 PVID(0x8086, E1000_DEV_ID_82572EI_COPPER, "Intel(R) PRO/1000 PT 82572EI (Copper)"),
111 PVID(0x8086, E1000_DEV_ID_82572EI_FIBER, "Intel(R) PRO/1000 PF 82572EI (Fiber)"),
112 PVID(0x8086, E1000_DEV_ID_82572EI_SERDES, "Intel(R) PRO/1000 82572EI (SERDES)"),
113 PVID(0x8086, E1000_DEV_ID_82573E, "Intel(R) PRO/1000 82573E (Copper)"),
114 PVID(0x8086, E1000_DEV_ID_82573E_IAMT, "Intel(R) PRO/1000 82573E AMT (Copper)"),
115 PVID(0x8086, E1000_DEV_ID_82573L, "Intel(R) PRO/1000 82573L"),
116 PVID(0x8086, E1000_DEV_ID_82583V, "Intel(R) 82583V"),
117 PVID(0x8086, E1000_DEV_ID_80003ES2LAN_COPPER_SPT, "Intel(R) 80003ES2LAN (Copper)"),
118 PVID(0x8086, E1000_DEV_ID_80003ES2LAN_SERDES_SPT, "Intel(R) 80003ES2LAN (SERDES)"),
119 PVID(0x8086, E1000_DEV_ID_80003ES2LAN_COPPER_DPT, "Intel(R) 80003ES2LAN (Dual Copper)"),
120 PVID(0x8086, E1000_DEV_ID_80003ES2LAN_SERDES_DPT, "Intel(R) 80003ES2LAN (Dual SERDES)"),
121 PVID(0x8086, E1000_DEV_ID_ICH8_IGP_M_AMT, "Intel(R) 82566MM ICH8 AMT (Mobile)"),
122 PVID(0x8086, E1000_DEV_ID_ICH8_IGP_AMT, "Intel(R) 82566DM ICH8 AMT"),
123 PVID(0x8086, E1000_DEV_ID_ICH8_IGP_C, "Intel(R) 82566DC ICH8"),
124 PVID(0x8086, E1000_DEV_ID_ICH8_IFE, "Intel(R) 82562V ICH8"),
125 PVID(0x8086, E1000_DEV_ID_ICH8_IFE_GT, "Intel(R) 82562GT ICH8"),
126 PVID(0x8086, E1000_DEV_ID_ICH8_IFE_G, "Intel(R) 82562G ICH8"),
127 PVID(0x8086, E1000_DEV_ID_ICH8_IGP_M, "Intel(R) 82566MC ICH8"),
128 PVID(0x8086, E1000_DEV_ID_ICH8_82567V_3, "Intel(R) 82567V-3 ICH8"),
129 PVID(0x8086, E1000_DEV_ID_ICH9_IGP_M_AMT, "Intel(R) 82567LM ICH9 AMT"),
130 PVID(0x8086, E1000_DEV_ID_ICH9_IGP_AMT, "Intel(R) 82566DM-2 ICH9 AMT"),
131 PVID(0x8086, E1000_DEV_ID_ICH9_IGP_C, "Intel(R) 82566DC-2 ICH9"),
132 PVID(0x8086, E1000_DEV_ID_ICH9_IGP_M, "Intel(R) 82567LF ICH9"),
133 PVID(0x8086, E1000_DEV_ID_ICH9_IGP_M_V, "Intel(R) 82567V ICH9"),
134 PVID(0x8086, E1000_DEV_ID_ICH9_IFE, "Intel(R) 82562V-2 ICH9"),
135 PVID(0x8086, E1000_DEV_ID_ICH9_IFE_GT, "Intel(R) 82562GT-2 ICH9"),
136 PVID(0x8086, E1000_DEV_ID_ICH9_IFE_G, "Intel(R) 82562G-2 ICH9"),
137 PVID(0x8086, E1000_DEV_ID_ICH9_BM, "Intel(R) 82567LM-4 ICH9"),
138 PVID(0x8086, E1000_DEV_ID_82574L, "Intel(R) Gigabit CT 82574L"),
139 PVID(0x8086, E1000_DEV_ID_82574LA, "Intel(R) 82574L-Apple"),
140 PVID(0x8086, E1000_DEV_ID_ICH10_R_BM_LM, "Intel(R) 82567LM-2 ICH10"),
141 PVID(0x8086, E1000_DEV_ID_ICH10_R_BM_LF, "Intel(R) 82567LF-2 ICH10"),
142 PVID(0x8086, E1000_DEV_ID_ICH10_R_BM_V, "Intel(R) 82567V-2 ICH10"),
143 PVID(0x8086, E1000_DEV_ID_ICH10_D_BM_LM, "Intel(R) 82567LM-3 ICH10"),
144 PVID(0x8086, E1000_DEV_ID_ICH10_D_BM_LF, "Intel(R) 82567LF-3 ICH10"),
145 PVID(0x8086, E1000_DEV_ID_ICH10_D_BM_V, "Intel(R) 82567V-4 ICH10"),
146 PVID(0x8086, E1000_DEV_ID_PCH_M_HV_LM, "Intel(R) 82577LM"),
147 PVID(0x8086, E1000_DEV_ID_PCH_M_HV_LC, "Intel(R) 82577LC"),
148 PVID(0x8086, E1000_DEV_ID_PCH_D_HV_DM, "Intel(R) 82578DM"),
149 PVID(0x8086, E1000_DEV_ID_PCH_D_HV_DC, "Intel(R) 82578DC"),
150 PVID(0x8086, E1000_DEV_ID_PCH2_LV_LM, "Intel(R) 82579LM"),
151 PVID(0x8086, E1000_DEV_ID_PCH2_LV_V, "Intel(R) 82579V"),
152 PVID(0x8086, E1000_DEV_ID_PCH_LPT_I217_LM, "Intel(R) I217-LM LPT"),
153 PVID(0x8086, E1000_DEV_ID_PCH_LPT_I217_V, "Intel(R) I217-V LPT"),
154 PVID(0x8086, E1000_DEV_ID_PCH_LPTLP_I218_LM, "Intel(R) I218-LM LPTLP"),
155 PVID(0x8086, E1000_DEV_ID_PCH_LPTLP_I218_V, "Intel(R) I218-V LPTLP"),
156 PVID(0x8086, E1000_DEV_ID_PCH_I218_LM2, "Intel(R) I218-LM (2)"),
157 PVID(0x8086, E1000_DEV_ID_PCH_I218_V2, "Intel(R) I218-V (2)"),
158 PVID(0x8086, E1000_DEV_ID_PCH_I218_LM3, "Intel(R) I218-LM (3)"),
159 PVID(0x8086, E1000_DEV_ID_PCH_I218_V3, "Intel(R) I218-V (3)"),
160 PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_LM, "Intel(R) I219-LM SPT"),
161 PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_V, "Intel(R) I219-V SPT"),
162 PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_LM2, "Intel(R) I219-LM SPT-H(2)"),
163 PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_V2, "Intel(R) I219-V SPT-H(2)"),
164 PVID(0x8086, E1000_DEV_ID_PCH_LBG_I219_LM3, "Intel(R) I219-LM LBG(3)"),
165 PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_LM4, "Intel(R) I219-LM SPT(4)"),
166 PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_V4, "Intel(R) I219-V SPT(4)"),
167 PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_LM5, "Intel(R) I219-LM SPT(5)"),
168 PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_V5, "Intel(R) I219-V SPT(5)"),
169 PVID(0x8086, E1000_DEV_ID_PCH_CNP_I219_LM6, "Intel(R) I219-LM CNP(6)"),
170 PVID(0x8086, E1000_DEV_ID_PCH_CNP_I219_V6, "Intel(R) I219-V CNP(6)"),
171 PVID(0x8086, E1000_DEV_ID_PCH_CNP_I219_LM7, "Intel(R) I219-LM CNP(7)"),
172 PVID(0x8086, E1000_DEV_ID_PCH_CNP_I219_V7, "Intel(R) I219-V CNP(7)"),
173 PVID(0x8086, E1000_DEV_ID_PCH_ICP_I219_LM8, "Intel(R) I219-LM ICP(8)"),
174 PVID(0x8086, E1000_DEV_ID_PCH_ICP_I219_V8, "Intel(R) I219-V ICP(8)"),
175 PVID(0x8086, E1000_DEV_ID_PCH_ICP_I219_LM9, "Intel(R) I219-LM ICP(9)"),
176 PVID(0x8086, E1000_DEV_ID_PCH_ICP_I219_V9, "Intel(R) I219-V ICP(9)"),
177 PVID(0x8086, E1000_DEV_ID_PCH_CMP_I219_LM10, "Intel(R) I219-LM CMP(10)"),
178 PVID(0x8086, E1000_DEV_ID_PCH_CMP_I219_V10, "Intel(R) I219-V CMP(10)"),
179 PVID(0x8086, E1000_DEV_ID_PCH_CMP_I219_LM11, "Intel(R) I219-LM CMP(11)"),
180 PVID(0x8086, E1000_DEV_ID_PCH_CMP_I219_V11, "Intel(R) I219-V CMP(11)"),
181 PVID(0x8086, E1000_DEV_ID_PCH_CMP_I219_LM12, "Intel(R) I219-LM CMP(12)"),
182 PVID(0x8086, E1000_DEV_ID_PCH_CMP_I219_V12, "Intel(R) I219-V CMP(12)"),
183 PVID(0x8086, E1000_DEV_ID_PCH_TGP_I219_LM13, "Intel(R) I219-LM TGP(13)"),
184 PVID(0x8086, E1000_DEV_ID_PCH_TGP_I219_V13, "Intel(R) I219-V TGP(13)"),
185 PVID(0x8086, E1000_DEV_ID_PCH_TGP_I219_LM14, "Intel(R) I219-LM TGP(14)"),
186 PVID(0x8086, E1000_DEV_ID_PCH_TGP_I219_V14, "Intel(R) I219-V GTP(14)"),
187 PVID(0x8086, E1000_DEV_ID_PCH_TGP_I219_LM15, "Intel(R) I219-LM TGP(15)"),
188 PVID(0x8086, E1000_DEV_ID_PCH_TGP_I219_V15, "Intel(R) I219-V TGP(15)"),
189 PVID(0x8086, E1000_DEV_ID_PCH_ADL_I219_LM16, "Intel(R) I219-LM ADL(16)"),
190 PVID(0x8086, E1000_DEV_ID_PCH_ADL_I219_V16, "Intel(R) I219-V ADL(16)"),
191 PVID(0x8086, E1000_DEV_ID_PCH_ADL_I219_LM17, "Intel(R) I219-LM ADL(17)"),
192 PVID(0x8086, E1000_DEV_ID_PCH_ADL_I219_V17, "Intel(R) I219-V ADL(17)"),
193 PVID(0x8086, E1000_DEV_ID_PCH_MTP_I219_LM18, "Intel(R) I219-LM MTP(18)"),
194 PVID(0x8086, E1000_DEV_ID_PCH_MTP_I219_V18, "Intel(R) I219-V MTP(18)"),
195 PVID(0x8086, E1000_DEV_ID_PCH_MTP_I219_LM19, "Intel(R) I219-LM MTP(19)"),
196 PVID(0x8086, E1000_DEV_ID_PCH_MTP_I219_V19, "Intel(R) I219-V MTP(19)"),
197 /* required last entry */
201 static pci_vendor_info_t igb_vendor_info_array[] =
203 /* Intel(R) - igb-class devices */
204 PVID(0x8086, E1000_DEV_ID_82575EB_COPPER, "Intel(R) PRO/1000 82575EB (Copper)"),
205 PVID(0x8086, E1000_DEV_ID_82575EB_FIBER_SERDES, "Intel(R) PRO/1000 82575EB (SERDES)"),
206 PVID(0x8086, E1000_DEV_ID_82575GB_QUAD_COPPER, "Intel(R) PRO/1000 VT 82575GB (Quad Copper)"),
207 PVID(0x8086, E1000_DEV_ID_82576, "Intel(R) PRO/1000 82576"),
208 PVID(0x8086, E1000_DEV_ID_82576_NS, "Intel(R) PRO/1000 82576NS"),
209 PVID(0x8086, E1000_DEV_ID_82576_NS_SERDES, "Intel(R) PRO/1000 82576NS (SERDES)"),
210 PVID(0x8086, E1000_DEV_ID_82576_FIBER, "Intel(R) PRO/1000 EF 82576 (Dual Fiber)"),
211 PVID(0x8086, E1000_DEV_ID_82576_SERDES, "Intel(R) PRO/1000 82576 (Dual SERDES)"),
212 PVID(0x8086, E1000_DEV_ID_82576_SERDES_QUAD, "Intel(R) PRO/1000 ET 82576 (Quad SERDES)"),
213 PVID(0x8086, E1000_DEV_ID_82576_QUAD_COPPER, "Intel(R) PRO/1000 ET 82576 (Quad Copper)"),
214 PVID(0x8086, E1000_DEV_ID_82576_QUAD_COPPER_ET2, "Intel(R) PRO/1000 ET(2) 82576 (Quad Copper)"),
215 PVID(0x8086, E1000_DEV_ID_82576_VF, "Intel(R) PRO/1000 82576 Virtual Function"),
216 PVID(0x8086, E1000_DEV_ID_82580_COPPER, "Intel(R) I340 82580 (Copper)"),
217 PVID(0x8086, E1000_DEV_ID_82580_FIBER, "Intel(R) I340 82580 (Fiber)"),
218 PVID(0x8086, E1000_DEV_ID_82580_SERDES, "Intel(R) I340 82580 (SERDES)"),
219 PVID(0x8086, E1000_DEV_ID_82580_SGMII, "Intel(R) I340 82580 (SGMII)"),
220 PVID(0x8086, E1000_DEV_ID_82580_COPPER_DUAL, "Intel(R) I340-T2 82580 (Dual Copper)"),
221 PVID(0x8086, E1000_DEV_ID_82580_QUAD_FIBER, "Intel(R) I340-F4 82580 (Quad Fiber)"),
222 PVID(0x8086, E1000_DEV_ID_DH89XXCC_SERDES, "Intel(R) DH89XXCC (SERDES)"),
223 PVID(0x8086, E1000_DEV_ID_DH89XXCC_SGMII, "Intel(R) I347-AT4 DH89XXCC"),
224 PVID(0x8086, E1000_DEV_ID_DH89XXCC_SFP, "Intel(R) DH89XXCC (SFP)"),
225 PVID(0x8086, E1000_DEV_ID_DH89XXCC_BACKPLANE, "Intel(R) DH89XXCC (Backplane)"),
226 PVID(0x8086, E1000_DEV_ID_I350_COPPER, "Intel(R) I350 (Copper)"),
227 PVID(0x8086, E1000_DEV_ID_I350_FIBER, "Intel(R) I350 (Fiber)"),
228 PVID(0x8086, E1000_DEV_ID_I350_SERDES, "Intel(R) I350 (SERDES)"),
229 PVID(0x8086, E1000_DEV_ID_I350_SGMII, "Intel(R) I350 (SGMII)"),
230 PVID(0x8086, E1000_DEV_ID_I350_VF, "Intel(R) I350 Virtual Function"),
231 PVID(0x8086, E1000_DEV_ID_I210_COPPER, "Intel(R) I210 (Copper)"),
232 PVID(0x8086, E1000_DEV_ID_I210_COPPER_IT, "Intel(R) I210 IT (Copper)"),
233 PVID(0x8086, E1000_DEV_ID_I210_COPPER_OEM1, "Intel(R) I210 (OEM)"),
234 PVID(0x8086, E1000_DEV_ID_I210_COPPER_FLASHLESS, "Intel(R) I210 Flashless (Copper)"),
235 PVID(0x8086, E1000_DEV_ID_I210_SERDES_FLASHLESS, "Intel(R) I210 Flashless (SERDES)"),
236 PVID(0x8086, E1000_DEV_ID_I210_SGMII_FLASHLESS, "Intel(R) I210 Flashless (SGMII)"),
237 PVID(0x8086, E1000_DEV_ID_I210_FIBER, "Intel(R) I210 (Fiber)"),
238 PVID(0x8086, E1000_DEV_ID_I210_SERDES, "Intel(R) I210 (SERDES)"),
239 PVID(0x8086, E1000_DEV_ID_I210_SGMII, "Intel(R) I210 (SGMII)"),
240 PVID(0x8086, E1000_DEV_ID_I211_COPPER, "Intel(R) I211 (Copper)"),
241 PVID(0x8086, E1000_DEV_ID_I354_BACKPLANE_1GBPS, "Intel(R) I354 (1.0 GbE Backplane)"),
242 PVID(0x8086, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS, "Intel(R) I354 (2.5 GbE Backplane)"),
243 PVID(0x8086, E1000_DEV_ID_I354_SGMII, "Intel(R) I354 (SGMII)"),
244 /* required last entry */
248 /*********************************************************************
249 * Function prototypes
250 *********************************************************************/
251 static void *em_register(device_t dev);
252 static void *igb_register(device_t dev);
253 static int em_if_attach_pre(if_ctx_t ctx);
254 static int em_if_attach_post(if_ctx_t ctx);
255 static int em_if_detach(if_ctx_t ctx);
256 static int em_if_shutdown(if_ctx_t ctx);
257 static int em_if_suspend(if_ctx_t ctx);
258 static int em_if_resume(if_ctx_t ctx);
260 static int em_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets);
261 static int em_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nrxqs, int nrxqsets);
262 static void em_if_queues_free(if_ctx_t ctx);
264 static uint64_t em_if_get_counter(if_ctx_t, ift_counter);
265 static void em_if_init(if_ctx_t ctx);
266 static void em_if_stop(if_ctx_t ctx);
267 static void em_if_media_status(if_ctx_t, struct ifmediareq *);
268 static int em_if_media_change(if_ctx_t ctx);
269 static int em_if_mtu_set(if_ctx_t ctx, uint32_t mtu);
270 static void em_if_timer(if_ctx_t ctx, uint16_t qid);
271 static void em_if_vlan_register(if_ctx_t ctx, u16 vtag);
272 static void em_if_vlan_unregister(if_ctx_t ctx, u16 vtag);
273 static void em_if_watchdog_reset(if_ctx_t ctx);
274 static bool em_if_needs_restart(if_ctx_t ctx, enum iflib_restart_event event);
276 static void em_identify_hardware(if_ctx_t ctx);
277 static int em_allocate_pci_resources(if_ctx_t ctx);
278 static void em_free_pci_resources(if_ctx_t ctx);
279 static void em_reset(if_ctx_t ctx);
280 static int em_setup_interface(if_ctx_t ctx);
281 static int em_setup_msix(if_ctx_t ctx);
283 static void em_initialize_transmit_unit(if_ctx_t ctx);
284 static void em_initialize_receive_unit(if_ctx_t ctx);
286 static void em_if_intr_enable(if_ctx_t ctx);
287 static void em_if_intr_disable(if_ctx_t ctx);
288 static void igb_if_intr_enable(if_ctx_t ctx);
289 static void igb_if_intr_disable(if_ctx_t ctx);
290 static int em_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid);
291 static int em_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid);
292 static int igb_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid);
293 static int igb_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid);
294 static void em_if_multi_set(if_ctx_t ctx);
295 static void em_if_update_admin_status(if_ctx_t ctx);
296 static void em_if_debug(if_ctx_t ctx);
297 static void em_update_stats_counters(struct e1000_softc *);
298 static void em_add_hw_stats(struct e1000_softc *);
299 static int em_if_set_promisc(if_ctx_t ctx, int flags);
300 static bool em_if_vlan_filter_capable(struct e1000_softc *);
301 static bool em_if_vlan_filter_used(struct e1000_softc *);
302 static void em_if_vlan_filter_enable(struct e1000_softc *);
303 static void em_if_vlan_filter_disable(struct e1000_softc *);
304 static void em_if_vlan_filter_write(struct e1000_softc *);
305 static void em_setup_vlan_hw_support(struct e1000_softc *);
306 static int em_sysctl_nvm_info(SYSCTL_HANDLER_ARGS);
307 static void em_print_nvm_info(struct e1000_softc *);
308 static int em_sysctl_debug_info(SYSCTL_HANDLER_ARGS);
309 static int em_get_rs(SYSCTL_HANDLER_ARGS);
310 static void em_print_debug_info(struct e1000_softc *);
311 static int em_is_valid_ether_addr(u8 *);
312 static int em_sysctl_int_delay(SYSCTL_HANDLER_ARGS);
313 static void em_add_int_delay_sysctl(struct e1000_softc *, const char *,
314 const char *, struct em_int_delay_info *, int, int);
315 /* Management and WOL Support */
316 static void em_init_manageability(struct e1000_softc *);
317 static void em_release_manageability(struct e1000_softc *);
318 static void em_get_hw_control(struct e1000_softc *);
319 static void em_release_hw_control(struct e1000_softc *);
320 static void em_get_wakeup(if_ctx_t ctx);
321 static void em_enable_wakeup(if_ctx_t ctx);
322 static int em_enable_phy_wakeup(struct e1000_softc *);
323 static void em_disable_aspm(struct e1000_softc *);
325 int em_intr(void *arg);
328 static int em_if_msix_intr_assign(if_ctx_t, int);
329 static int em_msix_link(void *);
330 static void em_handle_link(void *context);
332 static void em_enable_vectors_82574(if_ctx_t);
334 static int em_set_flowcntl(SYSCTL_HANDLER_ARGS);
335 static int em_sysctl_eee(SYSCTL_HANDLER_ARGS);
336 static void em_if_led_func(if_ctx_t ctx, int onoff);
338 static int em_get_regs(SYSCTL_HANDLER_ARGS);
340 static void lem_smartspeed(struct e1000_softc *);
341 static void igb_configure_queues(struct e1000_softc *);
344 /*********************************************************************
345 * FreeBSD Device Interface Entry Points
346 *********************************************************************/
347 static device_method_t em_methods[] = {
348 /* Device interface */
349 DEVMETHOD(device_register, em_register),
350 DEVMETHOD(device_probe, iflib_device_probe),
351 DEVMETHOD(device_attach, iflib_device_attach),
352 DEVMETHOD(device_detach, iflib_device_detach),
353 DEVMETHOD(device_shutdown, iflib_device_shutdown),
354 DEVMETHOD(device_suspend, iflib_device_suspend),
355 DEVMETHOD(device_resume, iflib_device_resume),
359 static device_method_t igb_methods[] = {
360 /* Device interface */
361 DEVMETHOD(device_register, igb_register),
362 DEVMETHOD(device_probe, iflib_device_probe),
363 DEVMETHOD(device_attach, iflib_device_attach),
364 DEVMETHOD(device_detach, iflib_device_detach),
365 DEVMETHOD(device_shutdown, iflib_device_shutdown),
366 DEVMETHOD(device_suspend, iflib_device_suspend),
367 DEVMETHOD(device_resume, iflib_device_resume),
372 static driver_t em_driver = {
373 "em", em_methods, sizeof(struct e1000_softc),
376 static devclass_t em_devclass;
377 DRIVER_MODULE(em, pci, em_driver, em_devclass, 0, 0);
379 MODULE_DEPEND(em, pci, 1, 1, 1);
380 MODULE_DEPEND(em, ether, 1, 1, 1);
381 MODULE_DEPEND(em, iflib, 1, 1, 1);
383 IFLIB_PNP_INFO(pci, em, em_vendor_info_array);
385 static driver_t igb_driver = {
386 "igb", igb_methods, sizeof(struct e1000_softc),
389 static devclass_t igb_devclass;
390 DRIVER_MODULE(igb, pci, igb_driver, igb_devclass, 0, 0);
392 MODULE_DEPEND(igb, pci, 1, 1, 1);
393 MODULE_DEPEND(igb, ether, 1, 1, 1);
394 MODULE_DEPEND(igb, iflib, 1, 1, 1);
396 IFLIB_PNP_INFO(pci, igb, igb_vendor_info_array);
398 static device_method_t em_if_methods[] = {
399 DEVMETHOD(ifdi_attach_pre, em_if_attach_pre),
400 DEVMETHOD(ifdi_attach_post, em_if_attach_post),
401 DEVMETHOD(ifdi_detach, em_if_detach),
402 DEVMETHOD(ifdi_shutdown, em_if_shutdown),
403 DEVMETHOD(ifdi_suspend, em_if_suspend),
404 DEVMETHOD(ifdi_resume, em_if_resume),
405 DEVMETHOD(ifdi_init, em_if_init),
406 DEVMETHOD(ifdi_stop, em_if_stop),
407 DEVMETHOD(ifdi_msix_intr_assign, em_if_msix_intr_assign),
408 DEVMETHOD(ifdi_intr_enable, em_if_intr_enable),
409 DEVMETHOD(ifdi_intr_disable, em_if_intr_disable),
410 DEVMETHOD(ifdi_tx_queues_alloc, em_if_tx_queues_alloc),
411 DEVMETHOD(ifdi_rx_queues_alloc, em_if_rx_queues_alloc),
412 DEVMETHOD(ifdi_queues_free, em_if_queues_free),
413 DEVMETHOD(ifdi_update_admin_status, em_if_update_admin_status),
414 DEVMETHOD(ifdi_multi_set, em_if_multi_set),
415 DEVMETHOD(ifdi_media_status, em_if_media_status),
416 DEVMETHOD(ifdi_media_change, em_if_media_change),
417 DEVMETHOD(ifdi_mtu_set, em_if_mtu_set),
418 DEVMETHOD(ifdi_promisc_set, em_if_set_promisc),
419 DEVMETHOD(ifdi_timer, em_if_timer),
420 DEVMETHOD(ifdi_watchdog_reset, em_if_watchdog_reset),
421 DEVMETHOD(ifdi_vlan_register, em_if_vlan_register),
422 DEVMETHOD(ifdi_vlan_unregister, em_if_vlan_unregister),
423 DEVMETHOD(ifdi_get_counter, em_if_get_counter),
424 DEVMETHOD(ifdi_led_func, em_if_led_func),
425 DEVMETHOD(ifdi_rx_queue_intr_enable, em_if_rx_queue_intr_enable),
426 DEVMETHOD(ifdi_tx_queue_intr_enable, em_if_tx_queue_intr_enable),
427 DEVMETHOD(ifdi_debug, em_if_debug),
428 DEVMETHOD(ifdi_needs_restart, em_if_needs_restart),
432 static driver_t em_if_driver = {
433 "em_if", em_if_methods, sizeof(struct e1000_softc)
436 static device_method_t igb_if_methods[] = {
437 DEVMETHOD(ifdi_attach_pre, em_if_attach_pre),
438 DEVMETHOD(ifdi_attach_post, em_if_attach_post),
439 DEVMETHOD(ifdi_detach, em_if_detach),
440 DEVMETHOD(ifdi_shutdown, em_if_shutdown),
441 DEVMETHOD(ifdi_suspend, em_if_suspend),
442 DEVMETHOD(ifdi_resume, em_if_resume),
443 DEVMETHOD(ifdi_init, em_if_init),
444 DEVMETHOD(ifdi_stop, em_if_stop),
445 DEVMETHOD(ifdi_msix_intr_assign, em_if_msix_intr_assign),
446 DEVMETHOD(ifdi_intr_enable, igb_if_intr_enable),
447 DEVMETHOD(ifdi_intr_disable, igb_if_intr_disable),
448 DEVMETHOD(ifdi_tx_queues_alloc, em_if_tx_queues_alloc),
449 DEVMETHOD(ifdi_rx_queues_alloc, em_if_rx_queues_alloc),
450 DEVMETHOD(ifdi_queues_free, em_if_queues_free),
451 DEVMETHOD(ifdi_update_admin_status, em_if_update_admin_status),
452 DEVMETHOD(ifdi_multi_set, em_if_multi_set),
453 DEVMETHOD(ifdi_media_status, em_if_media_status),
454 DEVMETHOD(ifdi_media_change, em_if_media_change),
455 DEVMETHOD(ifdi_mtu_set, em_if_mtu_set),
456 DEVMETHOD(ifdi_promisc_set, em_if_set_promisc),
457 DEVMETHOD(ifdi_timer, em_if_timer),
458 DEVMETHOD(ifdi_watchdog_reset, em_if_watchdog_reset),
459 DEVMETHOD(ifdi_vlan_register, em_if_vlan_register),
460 DEVMETHOD(ifdi_vlan_unregister, em_if_vlan_unregister),
461 DEVMETHOD(ifdi_get_counter, em_if_get_counter),
462 DEVMETHOD(ifdi_led_func, em_if_led_func),
463 DEVMETHOD(ifdi_rx_queue_intr_enable, igb_if_rx_queue_intr_enable),
464 DEVMETHOD(ifdi_tx_queue_intr_enable, igb_if_tx_queue_intr_enable),
465 DEVMETHOD(ifdi_debug, em_if_debug),
466 DEVMETHOD(ifdi_needs_restart, em_if_needs_restart),
470 static driver_t igb_if_driver = {
471 "igb_if", igb_if_methods, sizeof(struct e1000_softc)
474 /*********************************************************************
475 * Tunable default values.
476 *********************************************************************/
478 #define EM_TICKS_TO_USECS(ticks) ((1024 * (ticks) + 500) / 1000)
479 #define EM_USECS_TO_TICKS(usecs) ((1000 * (usecs) + 512) / 1024)
481 #define MAX_INTS_PER_SEC 8000
482 #define DEFAULT_ITR (1000000000/(MAX_INTS_PER_SEC * 256))
484 /* Allow common code without TSO */
489 static SYSCTL_NODE(_hw, OID_AUTO, em, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
490 "EM driver parameters");
492 static int em_disable_crc_stripping = 0;
493 SYSCTL_INT(_hw_em, OID_AUTO, disable_crc_stripping, CTLFLAG_RDTUN,
494 &em_disable_crc_stripping, 0, "Disable CRC Stripping");
496 static int em_tx_int_delay_dflt = EM_TICKS_TO_USECS(EM_TIDV);
497 static int em_rx_int_delay_dflt = EM_TICKS_TO_USECS(EM_RDTR);
498 SYSCTL_INT(_hw_em, OID_AUTO, tx_int_delay, CTLFLAG_RDTUN, &em_tx_int_delay_dflt,
499 0, "Default transmit interrupt delay in usecs");
500 SYSCTL_INT(_hw_em, OID_AUTO, rx_int_delay, CTLFLAG_RDTUN, &em_rx_int_delay_dflt,
501 0, "Default receive interrupt delay in usecs");
503 static int em_tx_abs_int_delay_dflt = EM_TICKS_TO_USECS(EM_TADV);
504 static int em_rx_abs_int_delay_dflt = EM_TICKS_TO_USECS(EM_RADV);
505 SYSCTL_INT(_hw_em, OID_AUTO, tx_abs_int_delay, CTLFLAG_RDTUN,
506 &em_tx_abs_int_delay_dflt, 0,
507 "Default transmit interrupt delay limit in usecs");
508 SYSCTL_INT(_hw_em, OID_AUTO, rx_abs_int_delay, CTLFLAG_RDTUN,
509 &em_rx_abs_int_delay_dflt, 0,
510 "Default receive interrupt delay limit in usecs");
512 static int em_smart_pwr_down = false;
513 SYSCTL_INT(_hw_em, OID_AUTO, smart_pwr_down, CTLFLAG_RDTUN, &em_smart_pwr_down,
514 0, "Set to true to leave smart power down enabled on newer adapters");
516 /* Controls whether promiscuous also shows bad packets */
517 static int em_debug_sbp = false;
518 SYSCTL_INT(_hw_em, OID_AUTO, sbp, CTLFLAG_RDTUN, &em_debug_sbp, 0,
519 "Show bad packets in promiscuous mode");
521 /* How many packets rxeof tries to clean at a time */
522 static int em_rx_process_limit = 100;
523 SYSCTL_INT(_hw_em, OID_AUTO, rx_process_limit, CTLFLAG_RDTUN,
524 &em_rx_process_limit, 0,
525 "Maximum number of received packets to process "
526 "at a time, -1 means unlimited");
528 /* Energy efficient ethernet - default to OFF */
529 static int eee_setting = 1;
530 SYSCTL_INT(_hw_em, OID_AUTO, eee_setting, CTLFLAG_RDTUN, &eee_setting, 0,
531 "Enable Energy Efficient Ethernet");
534 ** Tuneable Interrupt rate
536 static int em_max_interrupt_rate = 8000;
537 SYSCTL_INT(_hw_em, OID_AUTO, max_interrupt_rate, CTLFLAG_RDTUN,
538 &em_max_interrupt_rate, 0, "Maximum interrupts per second");
542 /* Global used in WOL setup with multiport cards */
543 static int global_quad_port_a = 0;
545 extern struct if_txrx igb_txrx;
546 extern struct if_txrx em_txrx;
547 extern struct if_txrx lem_txrx;
549 static struct if_shared_ctx em_sctx_init = {
550 .isc_magic = IFLIB_MAGIC,
551 .isc_q_align = PAGE_SIZE,
552 .isc_tx_maxsize = EM_TSO_SIZE + sizeof(struct ether_vlan_header),
553 .isc_tx_maxsegsize = PAGE_SIZE,
554 .isc_tso_maxsize = EM_TSO_SIZE + sizeof(struct ether_vlan_header),
555 .isc_tso_maxsegsize = EM_TSO_SEG_SIZE,
556 .isc_rx_maxsize = MJUM9BYTES,
557 .isc_rx_nsegments = 1,
558 .isc_rx_maxsegsize = MJUM9BYTES,
562 .isc_admin_intrcnt = 1,
563 .isc_vendor_info = em_vendor_info_array,
564 .isc_driver_version = em_driver_version,
565 .isc_driver = &em_if_driver,
566 .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_TSO_INIT_IP | IFLIB_NEED_ZERO_CSUM,
568 .isc_nrxd_min = {EM_MIN_RXD},
569 .isc_ntxd_min = {EM_MIN_TXD},
570 .isc_nrxd_max = {EM_MAX_RXD},
571 .isc_ntxd_max = {EM_MAX_TXD},
572 .isc_nrxd_default = {EM_DEFAULT_RXD},
573 .isc_ntxd_default = {EM_DEFAULT_TXD},
576 static struct if_shared_ctx igb_sctx_init = {
577 .isc_magic = IFLIB_MAGIC,
578 .isc_q_align = PAGE_SIZE,
579 .isc_tx_maxsize = EM_TSO_SIZE + sizeof(struct ether_vlan_header),
580 .isc_tx_maxsegsize = PAGE_SIZE,
581 .isc_tso_maxsize = EM_TSO_SIZE + sizeof(struct ether_vlan_header),
582 .isc_tso_maxsegsize = EM_TSO_SEG_SIZE,
583 .isc_rx_maxsize = MJUM9BYTES,
584 .isc_rx_nsegments = 1,
585 .isc_rx_maxsegsize = MJUM9BYTES,
589 .isc_admin_intrcnt = 1,
590 .isc_vendor_info = igb_vendor_info_array,
591 .isc_driver_version = em_driver_version,
592 .isc_driver = &igb_if_driver,
593 .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_TSO_INIT_IP | IFLIB_NEED_ZERO_CSUM,
595 .isc_nrxd_min = {EM_MIN_RXD},
596 .isc_ntxd_min = {EM_MIN_TXD},
597 .isc_nrxd_max = {IGB_MAX_RXD},
598 .isc_ntxd_max = {IGB_MAX_TXD},
599 .isc_nrxd_default = {EM_DEFAULT_RXD},
600 .isc_ntxd_default = {EM_DEFAULT_TXD},
603 /*****************************************************************
607 ****************************************************************/
608 #define IGB_REGS_LEN 739
610 static int em_get_regs(SYSCTL_HANDLER_ARGS)
612 struct e1000_softc *sc = (struct e1000_softc *)arg1;
613 struct e1000_hw *hw = &sc->hw;
618 regs_buff = malloc(sizeof(u32) * IGB_REGS_LEN, M_DEVBUF, M_WAITOK);
619 memset(regs_buff, 0, IGB_REGS_LEN * sizeof(u32));
621 rc = sysctl_wire_old_buffer(req, 0);
624 free(regs_buff, M_DEVBUF);
628 sb = sbuf_new_for_sysctl(NULL, NULL, 32*400, req);
631 free(regs_buff, M_DEVBUF);
635 /* General Registers */
636 regs_buff[0] = E1000_READ_REG(hw, E1000_CTRL);
637 regs_buff[1] = E1000_READ_REG(hw, E1000_STATUS);
638 regs_buff[2] = E1000_READ_REG(hw, E1000_CTRL_EXT);
639 regs_buff[3] = E1000_READ_REG(hw, E1000_ICR);
640 regs_buff[4] = E1000_READ_REG(hw, E1000_RCTL);
641 regs_buff[5] = E1000_READ_REG(hw, E1000_RDLEN(0));
642 regs_buff[6] = E1000_READ_REG(hw, E1000_RDH(0));
643 regs_buff[7] = E1000_READ_REG(hw, E1000_RDT(0));
644 regs_buff[8] = E1000_READ_REG(hw, E1000_RXDCTL(0));
645 regs_buff[9] = E1000_READ_REG(hw, E1000_RDBAL(0));
646 regs_buff[10] = E1000_READ_REG(hw, E1000_RDBAH(0));
647 regs_buff[11] = E1000_READ_REG(hw, E1000_TCTL);
648 regs_buff[12] = E1000_READ_REG(hw, E1000_TDBAL(0));
649 regs_buff[13] = E1000_READ_REG(hw, E1000_TDBAH(0));
650 regs_buff[14] = E1000_READ_REG(hw, E1000_TDLEN(0));
651 regs_buff[15] = E1000_READ_REG(hw, E1000_TDH(0));
652 regs_buff[16] = E1000_READ_REG(hw, E1000_TDT(0));
653 regs_buff[17] = E1000_READ_REG(hw, E1000_TXDCTL(0));
654 regs_buff[18] = E1000_READ_REG(hw, E1000_TDFH);
655 regs_buff[19] = E1000_READ_REG(hw, E1000_TDFT);
656 regs_buff[20] = E1000_READ_REG(hw, E1000_TDFHS);
657 regs_buff[21] = E1000_READ_REG(hw, E1000_TDFPC);
659 sbuf_printf(sb, "General Registers\n");
660 sbuf_printf(sb, "\tCTRL\t %08x\n", regs_buff[0]);
661 sbuf_printf(sb, "\tSTATUS\t %08x\n", regs_buff[1]);
662 sbuf_printf(sb, "\tCTRL_EXT\t %08x\n\n", regs_buff[2]);
664 sbuf_printf(sb, "Interrupt Registers\n");
665 sbuf_printf(sb, "\tICR\t %08x\n\n", regs_buff[3]);
667 sbuf_printf(sb, "RX Registers\n");
668 sbuf_printf(sb, "\tRCTL\t %08x\n", regs_buff[4]);
669 sbuf_printf(sb, "\tRDLEN\t %08x\n", regs_buff[5]);
670 sbuf_printf(sb, "\tRDH\t %08x\n", regs_buff[6]);
671 sbuf_printf(sb, "\tRDT\t %08x\n", regs_buff[7]);
672 sbuf_printf(sb, "\tRXDCTL\t %08x\n", regs_buff[8]);
673 sbuf_printf(sb, "\tRDBAL\t %08x\n", regs_buff[9]);
674 sbuf_printf(sb, "\tRDBAH\t %08x\n\n", regs_buff[10]);
676 sbuf_printf(sb, "TX Registers\n");
677 sbuf_printf(sb, "\tTCTL\t %08x\n", regs_buff[11]);
678 sbuf_printf(sb, "\tTDBAL\t %08x\n", regs_buff[12]);
679 sbuf_printf(sb, "\tTDBAH\t %08x\n", regs_buff[13]);
680 sbuf_printf(sb, "\tTDLEN\t %08x\n", regs_buff[14]);
681 sbuf_printf(sb, "\tTDH\t %08x\n", regs_buff[15]);
682 sbuf_printf(sb, "\tTDT\t %08x\n", regs_buff[16]);
683 sbuf_printf(sb, "\tTXDCTL\t %08x\n", regs_buff[17]);
684 sbuf_printf(sb, "\tTDFH\t %08x\n", regs_buff[18]);
685 sbuf_printf(sb, "\tTDFT\t %08x\n", regs_buff[19]);
686 sbuf_printf(sb, "\tTDFHS\t %08x\n", regs_buff[20]);
687 sbuf_printf(sb, "\tTDFPC\t %08x\n\n", regs_buff[21]);
689 free(regs_buff, M_DEVBUF);
693 if_softc_ctx_t scctx = sc->shared;
694 struct rx_ring *rxr = &rx_que->rxr;
695 struct tx_ring *txr = &tx_que->txr;
696 int ntxd = scctx->isc_ntxd[0];
697 int nrxd = scctx->isc_nrxd[0];
700 for (j = 0; j < nrxd; j++) {
701 u32 staterr = le32toh(rxr->rx_base[j].wb.upper.status_error);
702 u32 length = le32toh(rxr->rx_base[j].wb.upper.length);
703 sbuf_printf(sb, "\tReceive Descriptor Address %d: %08" PRIx64 " Error:%d Length:%d\n", j, rxr->rx_base[j].read.buffer_addr, staterr, length);
706 for (j = 0; j < min(ntxd, 256); j++) {
707 unsigned int *ptr = (unsigned int *)&txr->tx_base[j];
709 sbuf_printf(sb, "\tTXD[%03d] [0]: %08x [1]: %08x [2]: %08x [3]: %08x eop: %d DD=%d\n",
710 j, ptr[0], ptr[1], ptr[2], ptr[3], buf->eop,
711 buf->eop != -1 ? txr->tx_base[buf->eop].upper.fields.status & E1000_TXD_STAT_DD : 0);
717 rc = sbuf_finish(sb);
723 em_register(device_t dev)
725 return (&em_sctx_init);
729 igb_register(device_t dev)
731 return (&igb_sctx_init);
735 em_set_num_queues(if_ctx_t ctx)
737 struct e1000_softc *sc = iflib_get_softc(ctx);
740 /* Sanity check based on HW */
741 switch (sc->hw.mac.type) {
765 IFCAP_HWCSUM | IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING | \
766 IFCAP_VLAN_HWCSUM | IFCAP_WOL | IFCAP_VLAN_HWFILTER
769 IFCAP_HWCSUM | IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING | \
770 IFCAP_VLAN_HWCSUM | IFCAP_WOL | IFCAP_VLAN_HWFILTER | IFCAP_TSO4 | \
771 IFCAP_LRO | IFCAP_VLAN_HWTSO
774 IFCAP_HWCSUM | IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING | \
775 IFCAP_VLAN_HWCSUM | IFCAP_WOL | IFCAP_VLAN_HWFILTER | IFCAP_TSO4 | \
776 IFCAP_LRO | IFCAP_VLAN_HWTSO | IFCAP_JUMBO_MTU | IFCAP_HWCSUM_IPV6 |\
779 /*********************************************************************
780 * Device initialization routine
782 * The attach entry point is called when the driver is being loaded.
783 * This routine identifies the type of hardware, allocates all resources
784 * and initializes the hardware.
786 * return 0 on success, positive on failure
787 *********************************************************************/
789 em_if_attach_pre(if_ctx_t ctx)
791 struct e1000_softc *sc;
792 if_softc_ctx_t scctx;
797 INIT_DEBUGOUT("em_if_attach_pre: begin");
798 dev = iflib_get_dev(ctx);
799 sc = iflib_get_softc(ctx);
801 sc->ctx = sc->osdep.ctx = ctx;
802 sc->dev = sc->osdep.dev = dev;
803 scctx = sc->shared = iflib_get_softc_ctx(ctx);
804 sc->media = iflib_get_media(ctx);
807 sc->tx_process_limit = scctx->isc_ntxd[0];
810 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
811 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
812 OID_AUTO, "nvm", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
813 sc, 0, em_sysctl_nvm_info, "I", "NVM Information");
815 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
816 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
817 OID_AUTO, "debug", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
818 sc, 0, em_sysctl_debug_info, "I", "Debug Information");
820 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
821 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
822 OID_AUTO, "fc", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
823 sc, 0, em_set_flowcntl, "I", "Flow Control");
825 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
826 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
827 OID_AUTO, "reg_dump",
828 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NEEDGIANT, sc, 0,
829 em_get_regs, "A", "Dump Registers");
831 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
832 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
834 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, sc, 0,
835 em_get_rs, "I", "Dump RS indexes");
837 /* Determine hardware and mac info */
838 em_identify_hardware(ctx);
840 scctx->isc_tx_nsegments = EM_MAX_SCATTER;
841 scctx->isc_nrxqsets_max = scctx->isc_ntxqsets_max = em_set_num_queues(ctx);
843 device_printf(dev, "attach_pre capping queues at %d\n",
844 scctx->isc_ntxqsets_max);
846 if (hw->mac.type >= igb_mac_min) {
847 scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0] * sizeof(union e1000_adv_tx_desc), EM_DBA_ALIGN);
848 scctx->isc_rxqsizes[0] = roundup2(scctx->isc_nrxd[0] * sizeof(union e1000_adv_rx_desc), EM_DBA_ALIGN);
849 scctx->isc_txd_size[0] = sizeof(union e1000_adv_tx_desc);
850 scctx->isc_rxd_size[0] = sizeof(union e1000_adv_rx_desc);
851 scctx->isc_txrx = &igb_txrx;
852 scctx->isc_tx_tso_segments_max = EM_MAX_SCATTER;
853 scctx->isc_tx_tso_size_max = EM_TSO_SIZE;
854 scctx->isc_tx_tso_segsize_max = EM_TSO_SEG_SIZE;
855 scctx->isc_capabilities = scctx->isc_capenable = IGB_CAPS;
856 scctx->isc_tx_csum_flags = CSUM_TCP | CSUM_UDP | CSUM_TSO |
857 CSUM_IP6_TCP | CSUM_IP6_UDP;
858 if (hw->mac.type != e1000_82575)
859 scctx->isc_tx_csum_flags |= CSUM_SCTP | CSUM_IP6_SCTP;
861 ** Some new devices, as with ixgbe, now may
862 ** use a different BAR, so we need to keep
863 ** track of which is used.
865 scctx->isc_msix_bar = pci_msix_table_bar(dev);
866 } else if (hw->mac.type >= em_mac_min) {
867 scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0]* sizeof(struct e1000_tx_desc), EM_DBA_ALIGN);
868 scctx->isc_rxqsizes[0] = roundup2(scctx->isc_nrxd[0] * sizeof(union e1000_rx_desc_extended), EM_DBA_ALIGN);
869 scctx->isc_txd_size[0] = sizeof(struct e1000_tx_desc);
870 scctx->isc_rxd_size[0] = sizeof(union e1000_rx_desc_extended);
871 scctx->isc_txrx = &em_txrx;
872 scctx->isc_tx_tso_segments_max = EM_MAX_SCATTER;
873 scctx->isc_tx_tso_size_max = EM_TSO_SIZE;
874 scctx->isc_tx_tso_segsize_max = EM_TSO_SEG_SIZE;
875 scctx->isc_capabilities = scctx->isc_capenable = EM_CAPS;
877 * For EM-class devices, don't enable IFCAP_{TSO4,VLAN_HWTSO}
878 * by default as we don't have workarounds for all associated
879 * silicon errata. E. g., with several MACs such as 82573E,
880 * TSO only works at Gigabit speed and otherwise can cause the
881 * hardware to hang (which also would be next to impossible to
882 * work around given that already queued TSO-using descriptors
883 * would need to be flushed and vlan(4) reconfigured at runtime
884 * in case of a link speed change). Moreover, MACs like 82579
885 * still can hang at Gigabit even with all publicly documented
886 * TSO workarounds implemented. Generally, the penality of
887 * these workarounds is rather high and may involve copying
888 * mbuf data around so advantages of TSO lapse. Still, TSO may
889 * work for a few MACs of this class - at least when sticking
890 * with Gigabit - in which case users may enable TSO manually.
892 scctx->isc_capenable &= ~(IFCAP_TSO4 | IFCAP_VLAN_HWTSO);
893 scctx->isc_tx_csum_flags = CSUM_TCP | CSUM_UDP | CSUM_IP_TSO;
895 * We support MSI-X with 82574 only, but indicate to iflib(4)
896 * that it shall give MSI at least a try with other devices.
898 if (hw->mac.type == e1000_82574) {
899 scctx->isc_msix_bar = pci_msix_table_bar(dev);;
901 scctx->isc_msix_bar = -1;
902 scctx->isc_disable_msix = 1;
905 scctx->isc_txqsizes[0] = roundup2((scctx->isc_ntxd[0] + 1) * sizeof(struct e1000_tx_desc), EM_DBA_ALIGN);
906 scctx->isc_rxqsizes[0] = roundup2((scctx->isc_nrxd[0] + 1) * sizeof(struct e1000_rx_desc), EM_DBA_ALIGN);
907 scctx->isc_txd_size[0] = sizeof(struct e1000_tx_desc);
908 scctx->isc_rxd_size[0] = sizeof(struct e1000_rx_desc);
909 scctx->isc_tx_csum_flags = CSUM_TCP | CSUM_UDP;
910 scctx->isc_txrx = &lem_txrx;
911 scctx->isc_capabilities = scctx->isc_capenable = LEM_CAPS;
912 if (hw->mac.type < e1000_82543)
913 scctx->isc_capenable &= ~(IFCAP_HWCSUM|IFCAP_VLAN_HWCSUM);
914 /* 82541ER doesn't do HW tagging */
915 if (hw->device_id == E1000_DEV_ID_82541ER || hw->device_id == E1000_DEV_ID_82541ER_LOM)
916 scctx->isc_capenable &= ~IFCAP_VLAN_HWTAGGING;
918 scctx->isc_msix_bar = 0;
921 /* Setup PCI resources */
922 if (em_allocate_pci_resources(ctx)) {
923 device_printf(dev, "Allocation of PCI resources failed\n");
929 ** For ICH8 and family we need to
930 ** map the flash memory, and this
931 ** must happen after the MAC is
934 if ((hw->mac.type == e1000_ich8lan) ||
935 (hw->mac.type == e1000_ich9lan) ||
936 (hw->mac.type == e1000_ich10lan) ||
937 (hw->mac.type == e1000_pchlan) ||
938 (hw->mac.type == e1000_pch2lan) ||
939 (hw->mac.type == e1000_pch_lpt)) {
940 int rid = EM_BAR_TYPE_FLASH;
941 sc->flash = bus_alloc_resource_any(dev,
942 SYS_RES_MEMORY, &rid, RF_ACTIVE);
943 if (sc->flash == NULL) {
944 device_printf(dev, "Mapping of Flash failed\n");
948 /* This is used in the shared code */
949 hw->flash_address = (u8 *)sc->flash;
950 sc->osdep.flash_bus_space_tag =
951 rman_get_bustag(sc->flash);
952 sc->osdep.flash_bus_space_handle =
953 rman_get_bushandle(sc->flash);
956 ** In the new SPT device flash is not a
957 ** separate BAR, rather it is also in BAR0,
958 ** so use the same tag and an offset handle for the
959 ** FLASH read/write macros in the shared code.
961 else if (hw->mac.type >= e1000_pch_spt) {
962 sc->osdep.flash_bus_space_tag =
963 sc->osdep.mem_bus_space_tag;
964 sc->osdep.flash_bus_space_handle =
965 sc->osdep.mem_bus_space_handle
966 + E1000_FLASH_BASE_ADDR;
969 /* Do Shared Code initialization */
970 error = e1000_setup_init_funcs(hw, true);
972 device_printf(dev, "Setup of Shared code failed, error %d\n",
979 e1000_get_bus_info(hw);
981 /* Set up some sysctls for the tunable interrupt delays */
982 em_add_int_delay_sysctl(sc, "rx_int_delay",
983 "receive interrupt delay in usecs", &sc->rx_int_delay,
984 E1000_REGISTER(hw, E1000_RDTR), em_rx_int_delay_dflt);
985 em_add_int_delay_sysctl(sc, "tx_int_delay",
986 "transmit interrupt delay in usecs", &sc->tx_int_delay,
987 E1000_REGISTER(hw, E1000_TIDV), em_tx_int_delay_dflt);
988 em_add_int_delay_sysctl(sc, "rx_abs_int_delay",
989 "receive interrupt delay limit in usecs",
990 &sc->rx_abs_int_delay,
991 E1000_REGISTER(hw, E1000_RADV),
992 em_rx_abs_int_delay_dflt);
993 em_add_int_delay_sysctl(sc, "tx_abs_int_delay",
994 "transmit interrupt delay limit in usecs",
995 &sc->tx_abs_int_delay,
996 E1000_REGISTER(hw, E1000_TADV),
997 em_tx_abs_int_delay_dflt);
998 em_add_int_delay_sysctl(sc, "itr",
999 "interrupt delay limit in usecs/4",
1001 E1000_REGISTER(hw, E1000_ITR),
1004 hw->mac.autoneg = DO_AUTO_NEG;
1005 hw->phy.autoneg_wait_to_complete = false;
1006 hw->phy.autoneg_advertised = AUTONEG_ADV_DEFAULT;
1008 if (hw->mac.type < em_mac_min) {
1009 e1000_init_script_state_82541(hw, true);
1010 e1000_set_tbi_compatibility_82543(hw, true);
1012 /* Copper options */
1013 if (hw->phy.media_type == e1000_media_type_copper) {
1014 hw->phy.mdix = AUTO_ALL_MODES;
1015 hw->phy.disable_polarity_correction = false;
1016 hw->phy.ms_type = EM_MASTER_SLAVE;
1020 * Set the frame limits assuming
1021 * standard ethernet sized frames.
1023 scctx->isc_max_frame_size = hw->mac.max_frame_size =
1024 ETHERMTU + ETHER_HDR_LEN + ETHERNET_FCS_SIZE;
1027 * This controls when hardware reports transmit completion
1030 hw->mac.report_tx_early = 1;
1032 /* Allocate multicast array memory. */
1033 sc->mta = malloc(sizeof(u8) * ETHER_ADDR_LEN *
1034 MAX_NUM_MULTICAST_ADDRESSES, M_DEVBUF, M_NOWAIT);
1035 if (sc->mta == NULL) {
1036 device_printf(dev, "Can not allocate multicast setup array\n");
1041 /* Check SOL/IDER usage */
1042 if (e1000_check_reset_block(hw))
1043 device_printf(dev, "PHY reset is blocked"
1044 " due to SOL/IDER session.\n");
1046 /* Sysctl for setting Energy Efficient Ethernet */
1047 hw->dev_spec.ich8lan.eee_disable = eee_setting;
1048 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1049 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
1050 OID_AUTO, "eee_control",
1051 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
1052 sc, 0, em_sysctl_eee, "I",
1053 "Disable Energy Efficient Ethernet");
1056 ** Start from a known state, this is
1057 ** important in reading the nvm and
1062 /* Make sure we have a good EEPROM before we read from it */
1063 if (e1000_validate_nvm_checksum(hw) < 0) {
1065 ** Some PCI-E parts fail the first check due to
1066 ** the link being in sleep state, call it again,
1067 ** if it fails a second time its a real issue.
1069 if (e1000_validate_nvm_checksum(hw) < 0) {
1071 "The EEPROM Checksum Is Not Valid\n");
1077 /* Copy the permanent MAC address out of the EEPROM */
1078 if (e1000_read_mac_addr(hw) < 0) {
1079 device_printf(dev, "EEPROM read error while reading MAC"
1085 if (!em_is_valid_ether_addr(hw->mac.addr)) {
1087 ether_gen_addr(iflib_get_ifp(ctx),
1088 (struct ether_addr *)hw->mac.addr);
1090 device_printf(dev, "Invalid MAC address\n");
1096 /* Disable ULP support */
1097 e1000_disable_ulp_lpt_lp(hw, true);
1100 * Get Wake-on-Lan and Management info for later use
1104 /* Enable only WOL MAGIC by default */
1105 scctx->isc_capenable &= ~IFCAP_WOL;
1107 scctx->isc_capenable |= IFCAP_WOL_MAGIC;
1109 iflib_set_mac(ctx, hw->mac.addr);
1114 em_release_hw_control(sc);
1116 em_free_pci_resources(ctx);
1117 free(sc->mta, M_DEVBUF);
1123 em_if_attach_post(if_ctx_t ctx)
1125 struct e1000_softc *sc = iflib_get_softc(ctx);
1126 struct e1000_hw *hw = &sc->hw;
1129 /* Setup OS specific network interface */
1130 error = em_setup_interface(ctx);
1132 device_printf(sc->dev, "Interface setup failed: %d\n", error);
1138 /* Initialize statistics */
1139 em_update_stats_counters(sc);
1140 hw->mac.get_link_status = 1;
1141 em_if_update_admin_status(ctx);
1142 em_add_hw_stats(sc);
1144 /* Non-AMT based hardware can now take control from firmware */
1145 if (sc->has_manage && !sc->has_amt)
1146 em_get_hw_control(sc);
1148 INIT_DEBUGOUT("em_if_attach_post: end");
1153 /* upon attach_post() error, iflib calls _if_detach() to free resources. */
1157 /*********************************************************************
1158 * Device removal routine
1160 * The detach entry point is called when the driver is being removed.
1161 * This routine stops the adapter and deallocates all the resources
1162 * that were allocated for driver operation.
1164 * return 0 on success, positive on failure
1165 *********************************************************************/
1167 em_if_detach(if_ctx_t ctx)
1169 struct e1000_softc *sc = iflib_get_softc(ctx);
1171 INIT_DEBUGOUT("em_if_detach: begin");
1173 e1000_phy_hw_reset(&sc->hw);
1175 em_release_manageability(sc);
1176 em_release_hw_control(sc);
1177 em_free_pci_resources(ctx);
1178 free(sc->mta, M_DEVBUF);
1184 /*********************************************************************
1186 * Shutdown entry point
1188 **********************************************************************/
1191 em_if_shutdown(if_ctx_t ctx)
1193 return em_if_suspend(ctx);
1197 * Suspend/resume device methods.
1200 em_if_suspend(if_ctx_t ctx)
1202 struct e1000_softc *sc = iflib_get_softc(ctx);
1204 em_release_manageability(sc);
1205 em_release_hw_control(sc);
1206 em_enable_wakeup(ctx);
1211 em_if_resume(if_ctx_t ctx)
1213 struct e1000_softc *sc = iflib_get_softc(ctx);
1215 if (sc->hw.mac.type == e1000_pch2lan)
1216 e1000_resume_workarounds_pchlan(&sc->hw);
1218 em_init_manageability(sc);
1224 em_if_mtu_set(if_ctx_t ctx, uint32_t mtu)
1227 struct e1000_softc *sc = iflib_get_softc(ctx);
1228 if_softc_ctx_t scctx = iflib_get_softc_ctx(ctx);
1230 IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)");
1232 switch (sc->hw.mac.type) {
1236 case e1000_ich10lan:
1246 case e1000_80003es2lan:
1247 /* 9K Jumbo Frame size */
1248 max_frame_size = 9234;
1251 max_frame_size = 4096;
1255 /* Adapters that do not support jumbo frames */
1256 max_frame_size = ETHER_MAX_LEN;
1259 if (sc->hw.mac.type >= igb_mac_min)
1260 max_frame_size = 9234;
1262 max_frame_size = MAX_JUMBO_FRAME_SIZE;
1264 if (mtu > max_frame_size - ETHER_HDR_LEN - ETHER_CRC_LEN) {
1268 scctx->isc_max_frame_size = sc->hw.mac.max_frame_size =
1269 mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1273 /*********************************************************************
1276 * This routine is used in two ways. It is used by the stack as
1277 * init entry point in network interface structure. It is also used
1278 * by the driver as a hw/sw initialization routine to get to a
1281 **********************************************************************/
1283 em_if_init(if_ctx_t ctx)
1285 struct e1000_softc *sc = iflib_get_softc(ctx);
1286 if_softc_ctx_t scctx = sc->shared;
1287 struct ifnet *ifp = iflib_get_ifp(ctx);
1288 struct em_tx_queue *tx_que;
1291 INIT_DEBUGOUT("em_if_init: begin");
1293 /* Get the latest mac address, User can use a LAA */
1294 bcopy(if_getlladdr(ifp), sc->hw.mac.addr,
1297 /* Put the address into the Receive Address Array */
1298 e1000_rar_set(&sc->hw, sc->hw.mac.addr, 0);
1301 * With the 82571 adapter, RAR[0] may be overwritten
1302 * when the other port is reset, we make a duplicate
1303 * in RAR[14] for that eventuality, this assures
1304 * the interface continues to function.
1306 if (sc->hw.mac.type == e1000_82571) {
1307 e1000_set_laa_state_82571(&sc->hw, true);
1308 e1000_rar_set(&sc->hw, sc->hw.mac.addr,
1309 E1000_RAR_ENTRIES - 1);
1313 /* Initialize the hardware */
1315 em_if_update_admin_status(ctx);
1317 for (i = 0, tx_que = sc->tx_queues; i < sc->tx_num_queues; i++, tx_que++) {
1318 struct tx_ring *txr = &tx_que->txr;
1320 txr->tx_rs_cidx = txr->tx_rs_pidx;
1322 /* Initialize the last processed descriptor to be the end of
1323 * the ring, rather than the start, so that we avoid an
1324 * off-by-one error when calculating how many descriptors are
1325 * done in the credits_update function.
1327 txr->tx_cidx_processed = scctx->isc_ntxd[0] - 1;
1330 /* Setup VLAN support, basic and offload if available */
1331 E1000_WRITE_REG(&sc->hw, E1000_VET, ETHERTYPE_VLAN);
1333 /* Clear bad data from Rx FIFOs */
1334 if (sc->hw.mac.type >= igb_mac_min)
1335 e1000_rx_fifo_flush_base(&sc->hw);
1337 /* Configure for OS presence */
1338 em_init_manageability(sc);
1340 /* Prepare transmit descriptors and buffers */
1341 em_initialize_transmit_unit(ctx);
1343 /* Setup Multicast table */
1344 em_if_multi_set(ctx);
1346 sc->rx_mbuf_sz = iflib_get_rx_mbuf_sz(ctx);
1347 em_initialize_receive_unit(ctx);
1349 /* Set up VLAN support and filter */
1350 em_setup_vlan_hw_support(sc);
1352 /* Don't lose promiscuous settings */
1353 em_if_set_promisc(ctx, if_getflags(ifp));
1354 e1000_clear_hw_cntrs_base_generic(&sc->hw);
1356 /* MSI-X configuration for 82574 */
1357 if (sc->hw.mac.type == e1000_82574) {
1358 int tmp = E1000_READ_REG(&sc->hw, E1000_CTRL_EXT);
1360 tmp |= E1000_CTRL_EXT_PBA_CLR;
1361 E1000_WRITE_REG(&sc->hw, E1000_CTRL_EXT, tmp);
1362 /* Set the IVAR - interrupt vector routing. */
1363 E1000_WRITE_REG(&sc->hw, E1000_IVAR, sc->ivars);
1364 } else if (sc->intr_type == IFLIB_INTR_MSIX) /* Set up queue routing */
1365 igb_configure_queues(sc);
1367 /* this clears any pending interrupts */
1368 E1000_READ_REG(&sc->hw, E1000_ICR);
1369 E1000_WRITE_REG(&sc->hw, E1000_ICS, E1000_ICS_LSC);
1371 /* AMT based hardware can now take control from firmware */
1372 if (sc->has_manage && sc->has_amt)
1373 em_get_hw_control(sc);
1375 /* Set Energy Efficient Ethernet */
1376 if (sc->hw.mac.type >= igb_mac_min &&
1377 sc->hw.phy.media_type == e1000_media_type_copper) {
1378 if (sc->hw.mac.type == e1000_i354)
1379 e1000_set_eee_i354(&sc->hw, true, true);
1381 e1000_set_eee_i350(&sc->hw, true, true);
1385 /*********************************************************************
1387 * Fast Legacy/MSI Combined Interrupt Service routine
1389 *********************************************************************/
1393 struct e1000_softc *sc = arg;
1394 if_ctx_t ctx = sc->ctx;
1397 reg_icr = E1000_READ_REG(&sc->hw, E1000_ICR);
1400 if (reg_icr == 0xffffffff)
1401 return FILTER_STRAY;
1403 /* Definitely not our interrupt. */
1405 return FILTER_STRAY;
1408 * Starting with the 82571 chip, bit 31 should be used to
1409 * determine whether the interrupt belongs to us.
1411 if (sc->hw.mac.type >= e1000_82571 &&
1412 (reg_icr & E1000_ICR_INT_ASSERTED) == 0)
1413 return FILTER_STRAY;
1416 * Only MSI-X interrupts have one-shot behavior by taking advantage
1417 * of the EIAC register. Thus, explicitly disable interrupts. This
1418 * also works around the MSI message reordering errata on certain
1421 IFDI_INTR_DISABLE(ctx);
1423 /* Link status change */
1424 if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))
1425 em_handle_link(ctx);
1427 if (reg_icr & E1000_ICR_RXO)
1430 return (FILTER_SCHEDULE_THREAD);
1434 em_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid)
1436 struct e1000_softc *sc = iflib_get_softc(ctx);
1437 struct em_rx_queue *rxq = &sc->rx_queues[rxqid];
1439 E1000_WRITE_REG(&sc->hw, E1000_IMS, rxq->eims);
1444 em_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid)
1446 struct e1000_softc *sc = iflib_get_softc(ctx);
1447 struct em_tx_queue *txq = &sc->tx_queues[txqid];
1449 E1000_WRITE_REG(&sc->hw, E1000_IMS, txq->eims);
1454 igb_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid)
1456 struct e1000_softc *sc = iflib_get_softc(ctx);
1457 struct em_rx_queue *rxq = &sc->rx_queues[rxqid];
1459 E1000_WRITE_REG(&sc->hw, E1000_EIMS, rxq->eims);
1464 igb_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid)
1466 struct e1000_softc *sc = iflib_get_softc(ctx);
1467 struct em_tx_queue *txq = &sc->tx_queues[txqid];
1469 E1000_WRITE_REG(&sc->hw, E1000_EIMS, txq->eims);
1473 /*********************************************************************
1475 * MSI-X RX Interrupt Service routine
1477 **********************************************************************/
1479 em_msix_que(void *arg)
1481 struct em_rx_queue *que = arg;
1485 return (FILTER_SCHEDULE_THREAD);
1488 /*********************************************************************
1490 * MSI-X Link Fast Interrupt Service routine
1492 **********************************************************************/
1494 em_msix_link(void *arg)
1496 struct e1000_softc *sc = arg;
1500 MPASS(sc->hw.back != NULL);
1501 reg_icr = E1000_READ_REG(&sc->hw, E1000_ICR);
1503 if (reg_icr & E1000_ICR_RXO)
1506 if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))
1507 em_handle_link(sc->ctx);
1509 /* Re-arm unconditionally */
1510 if (sc->hw.mac.type >= igb_mac_min) {
1511 E1000_WRITE_REG(&sc->hw, E1000_IMS, E1000_IMS_LSC);
1512 E1000_WRITE_REG(&sc->hw, E1000_EIMS, sc->link_mask);
1513 } else if (sc->hw.mac.type == e1000_82574) {
1514 E1000_WRITE_REG(&sc->hw, E1000_IMS, E1000_IMS_LSC |
1517 * Because we must read the ICR for this interrupt it may
1518 * clear other causes using autoclear, for this reason we
1519 * simply create a soft interrupt for all these vectors.
1522 E1000_WRITE_REG(&sc->hw, E1000_ICS, sc->ims);
1524 E1000_WRITE_REG(&sc->hw, E1000_IMS, E1000_IMS_LSC);
1526 return (FILTER_HANDLED);
1530 em_handle_link(void *context)
1532 if_ctx_t ctx = context;
1533 struct e1000_softc *sc = iflib_get_softc(ctx);
1535 sc->hw.mac.get_link_status = 1;
1536 iflib_admin_intr_deferred(ctx);
1539 /*********************************************************************
1541 * Media Ioctl callback
1543 * This routine is called whenever the user queries the status of
1544 * the interface using ifconfig.
1546 **********************************************************************/
1548 em_if_media_status(if_ctx_t ctx, struct ifmediareq *ifmr)
1550 struct e1000_softc *sc = iflib_get_softc(ctx);
1551 u_char fiber_type = IFM_1000_SX;
1553 INIT_DEBUGOUT("em_if_media_status: begin");
1555 iflib_admin_intr_deferred(ctx);
1557 ifmr->ifm_status = IFM_AVALID;
1558 ifmr->ifm_active = IFM_ETHER;
1560 if (!sc->link_active) {
1564 ifmr->ifm_status |= IFM_ACTIVE;
1566 if ((sc->hw.phy.media_type == e1000_media_type_fiber) ||
1567 (sc->hw.phy.media_type == e1000_media_type_internal_serdes)) {
1568 if (sc->hw.mac.type == e1000_82545)
1569 fiber_type = IFM_1000_LX;
1570 ifmr->ifm_active |= fiber_type | IFM_FDX;
1572 switch (sc->link_speed) {
1574 ifmr->ifm_active |= IFM_10_T;
1577 ifmr->ifm_active |= IFM_100_TX;
1580 ifmr->ifm_active |= IFM_1000_T;
1583 if (sc->link_duplex == FULL_DUPLEX)
1584 ifmr->ifm_active |= IFM_FDX;
1586 ifmr->ifm_active |= IFM_HDX;
1590 /*********************************************************************
1592 * Media Ioctl callback
1594 * This routine is called when the user changes speed/duplex using
1595 * media/mediopt option with ifconfig.
1597 **********************************************************************/
1599 em_if_media_change(if_ctx_t ctx)
1601 struct e1000_softc *sc = iflib_get_softc(ctx);
1602 struct ifmedia *ifm = iflib_get_media(ctx);
1604 INIT_DEBUGOUT("em_if_media_change: begin");
1606 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1609 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1611 sc->hw.mac.autoneg = DO_AUTO_NEG;
1612 sc->hw.phy.autoneg_advertised = AUTONEG_ADV_DEFAULT;
1617 sc->hw.mac.autoneg = DO_AUTO_NEG;
1618 sc->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
1621 sc->hw.mac.autoneg = false;
1622 sc->hw.phy.autoneg_advertised = 0;
1623 if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
1624 sc->hw.mac.forced_speed_duplex = ADVERTISE_100_FULL;
1626 sc->hw.mac.forced_speed_duplex = ADVERTISE_100_HALF;
1629 sc->hw.mac.autoneg = false;
1630 sc->hw.phy.autoneg_advertised = 0;
1631 if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
1632 sc->hw.mac.forced_speed_duplex = ADVERTISE_10_FULL;
1634 sc->hw.mac.forced_speed_duplex = ADVERTISE_10_HALF;
1637 device_printf(sc->dev, "Unsupported media type\n");
1646 em_if_set_promisc(if_ctx_t ctx, int flags)
1648 struct e1000_softc *sc = iflib_get_softc(ctx);
1649 struct ifnet *ifp = iflib_get_ifp(ctx);
1653 reg_rctl = E1000_READ_REG(&sc->hw, E1000_RCTL);
1654 reg_rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_UPE);
1655 if (flags & IFF_ALLMULTI)
1656 mcnt = MAX_NUM_MULTICAST_ADDRESSES;
1658 mcnt = min(if_llmaddr_count(ifp), MAX_NUM_MULTICAST_ADDRESSES);
1660 if (mcnt < MAX_NUM_MULTICAST_ADDRESSES)
1661 reg_rctl &= (~E1000_RCTL_MPE);
1662 E1000_WRITE_REG(&sc->hw, E1000_RCTL, reg_rctl);
1664 if (flags & IFF_PROMISC) {
1665 reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1666 em_if_vlan_filter_disable(sc);
1667 /* Turn this on if you want to see bad packets */
1669 reg_rctl |= E1000_RCTL_SBP;
1670 E1000_WRITE_REG(&sc->hw, E1000_RCTL, reg_rctl);
1672 if (flags & IFF_ALLMULTI) {
1673 reg_rctl |= E1000_RCTL_MPE;
1674 reg_rctl &= ~E1000_RCTL_UPE;
1675 E1000_WRITE_REG(&sc->hw, E1000_RCTL, reg_rctl);
1677 if (em_if_vlan_filter_used(sc))
1678 em_if_vlan_filter_enable(sc);
1684 em_copy_maddr(void *arg, struct sockaddr_dl *sdl, u_int idx)
1688 if (idx == MAX_NUM_MULTICAST_ADDRESSES)
1691 bcopy(LLADDR(sdl), &mta[idx * ETHER_ADDR_LEN], ETHER_ADDR_LEN);
1696 /*********************************************************************
1699 * This routine is called whenever multicast address list is updated.
1701 **********************************************************************/
1703 em_if_multi_set(if_ctx_t ctx)
1705 struct e1000_softc *sc = iflib_get_softc(ctx);
1706 struct ifnet *ifp = iflib_get_ifp(ctx);
1707 u8 *mta; /* Multicast array memory */
1711 IOCTL_DEBUGOUT("em_set_multi: begin");
1714 bzero(mta, sizeof(u8) * ETHER_ADDR_LEN * MAX_NUM_MULTICAST_ADDRESSES);
1716 if (sc->hw.mac.type == e1000_82542 &&
1717 sc->hw.revision_id == E1000_REVISION_2) {
1718 reg_rctl = E1000_READ_REG(&sc->hw, E1000_RCTL);
1719 if (sc->hw.bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
1720 e1000_pci_clear_mwi(&sc->hw);
1721 reg_rctl |= E1000_RCTL_RST;
1722 E1000_WRITE_REG(&sc->hw, E1000_RCTL, reg_rctl);
1726 mcnt = if_foreach_llmaddr(ifp, em_copy_maddr, mta);
1728 reg_rctl = E1000_READ_REG(&sc->hw, E1000_RCTL);
1730 if (if_getflags(ifp) & IFF_PROMISC)
1731 reg_rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1732 else if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES ||
1733 if_getflags(ifp) & IFF_ALLMULTI) {
1734 reg_rctl |= E1000_RCTL_MPE;
1735 reg_rctl &= ~E1000_RCTL_UPE;
1737 reg_rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
1739 E1000_WRITE_REG(&sc->hw, E1000_RCTL, reg_rctl);
1741 if (mcnt < MAX_NUM_MULTICAST_ADDRESSES)
1742 e1000_update_mc_addr_list(&sc->hw, mta, mcnt);
1744 if (sc->hw.mac.type == e1000_82542 &&
1745 sc->hw.revision_id == E1000_REVISION_2) {
1746 reg_rctl = E1000_READ_REG(&sc->hw, E1000_RCTL);
1747 reg_rctl &= ~E1000_RCTL_RST;
1748 E1000_WRITE_REG(&sc->hw, E1000_RCTL, reg_rctl);
1750 if (sc->hw.bus.pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
1751 e1000_pci_set_mwi(&sc->hw);
1755 /*********************************************************************
1758 * This routine schedules em_if_update_admin_status() to check for
1759 * link status and to gather statistics as well as to perform some
1760 * controller-specific hardware patting.
1762 **********************************************************************/
1764 em_if_timer(if_ctx_t ctx, uint16_t qid)
1770 iflib_admin_intr_deferred(ctx);
1774 em_if_update_admin_status(if_ctx_t ctx)
1776 struct e1000_softc *sc = iflib_get_softc(ctx);
1777 struct e1000_hw *hw = &sc->hw;
1778 device_t dev = iflib_get_dev(ctx);
1779 u32 link_check, thstat, ctrl;
1781 link_check = thstat = ctrl = 0;
1782 /* Get the cached link value or read phy for real */
1783 switch (hw->phy.media_type) {
1784 case e1000_media_type_copper:
1785 if (hw->mac.get_link_status) {
1786 if (hw->mac.type == e1000_pch_spt)
1788 /* Do the work to read phy */
1789 e1000_check_for_link(hw);
1790 link_check = !hw->mac.get_link_status;
1791 if (link_check) /* ESB2 fix */
1792 e1000_cfg_on_link_up(hw);
1797 case e1000_media_type_fiber:
1798 e1000_check_for_link(hw);
1799 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
1802 case e1000_media_type_internal_serdes:
1803 e1000_check_for_link(hw);
1804 link_check = hw->mac.serdes_has_link;
1806 /* VF device is type_unknown */
1807 case e1000_media_type_unknown:
1808 e1000_check_for_link(hw);
1809 link_check = !hw->mac.get_link_status;
1815 /* Check for thermal downshift or shutdown */
1816 if (hw->mac.type == e1000_i350) {
1817 thstat = E1000_READ_REG(hw, E1000_THSTAT);
1818 ctrl = E1000_READ_REG(hw, E1000_CTRL_EXT);
1821 /* Now check for a transition */
1822 if (link_check && (sc->link_active == 0)) {
1823 e1000_get_speed_and_duplex(hw, &sc->link_speed,
1825 /* Check if we must disable SPEED_MODE bit on PCI-E */
1826 if ((sc->link_speed != SPEED_1000) &&
1827 ((hw->mac.type == e1000_82571) ||
1828 (hw->mac.type == e1000_82572))) {
1830 tarc0 = E1000_READ_REG(hw, E1000_TARC(0));
1831 tarc0 &= ~TARC_SPEED_MODE_BIT;
1832 E1000_WRITE_REG(hw, E1000_TARC(0), tarc0);
1835 device_printf(dev, "Link is up %d Mbps %s\n",
1837 ((sc->link_duplex == FULL_DUPLEX) ?
1838 "Full Duplex" : "Half Duplex"));
1839 sc->link_active = 1;
1841 if ((ctrl & E1000_CTRL_EXT_LINK_MODE_MASK) ==
1842 E1000_CTRL_EXT_LINK_MODE_GMII &&
1843 (thstat & E1000_THSTAT_LINK_THROTTLE))
1844 device_printf(dev, "Link: thermal downshift\n");
1845 /* Delay Link Up for Phy update */
1846 if (((hw->mac.type == e1000_i210) ||
1847 (hw->mac.type == e1000_i211)) &&
1848 (hw->phy.id == I210_I_PHY_ID))
1849 msec_delay(I210_LINK_DELAY);
1850 /* Reset if the media type changed. */
1851 if (hw->dev_spec._82575.media_changed &&
1852 hw->mac.type >= igb_mac_min) {
1853 hw->dev_spec._82575.media_changed = false;
1854 sc->flags |= IGB_MEDIA_RESET;
1857 iflib_link_state_change(ctx, LINK_STATE_UP,
1858 IF_Mbps(sc->link_speed));
1859 } else if (!link_check && (sc->link_active == 1)) {
1861 sc->link_duplex = 0;
1862 sc->link_active = 0;
1863 iflib_link_state_change(ctx, LINK_STATE_DOWN, 0);
1865 em_update_stats_counters(sc);
1867 /* Reset LAA into RAR[0] on 82571 */
1868 if (hw->mac.type == e1000_82571 && e1000_get_laa_state_82571(hw))
1869 e1000_rar_set(hw, hw->mac.addr, 0);
1871 if (hw->mac.type < em_mac_min)
1876 em_if_watchdog_reset(if_ctx_t ctx)
1878 struct e1000_softc *sc = iflib_get_softc(ctx);
1881 * Just count the event; iflib(4) will already trigger a
1882 * sufficient reset of the controller.
1884 sc->watchdog_events++;
1887 /*********************************************************************
1889 * This routine disables all traffic on the adapter by issuing a
1890 * global reset on the MAC.
1892 **********************************************************************/
1894 em_if_stop(if_ctx_t ctx)
1896 struct e1000_softc *sc = iflib_get_softc(ctx);
1898 INIT_DEBUGOUT("em_if_stop: begin");
1900 e1000_reset_hw(&sc->hw);
1901 if (sc->hw.mac.type >= e1000_82544)
1902 E1000_WRITE_REG(&sc->hw, E1000_WUFC, 0);
1904 e1000_led_off(&sc->hw);
1905 e1000_cleanup_led(&sc->hw);
1908 /*********************************************************************
1910 * Determine hardware revision.
1912 **********************************************************************/
1914 em_identify_hardware(if_ctx_t ctx)
1916 device_t dev = iflib_get_dev(ctx);
1917 struct e1000_softc *sc = iflib_get_softc(ctx);
1919 /* Make sure our PCI config space has the necessary stuff set */
1920 sc->hw.bus.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2);
1922 /* Save off the information about this board */
1923 sc->hw.vendor_id = pci_get_vendor(dev);
1924 sc->hw.device_id = pci_get_device(dev);
1925 sc->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1);
1926 sc->hw.subsystem_vendor_id =
1927 pci_read_config(dev, PCIR_SUBVEND_0, 2);
1928 sc->hw.subsystem_device_id =
1929 pci_read_config(dev, PCIR_SUBDEV_0, 2);
1931 /* Do Shared Code Init and Setup */
1932 if (e1000_set_mac_type(&sc->hw)) {
1933 device_printf(dev, "Setup init failure\n");
1937 /* Are we a VF device? */
1938 if ((sc->hw.mac.type == e1000_vfadapt) ||
1939 (sc->hw.mac.type == e1000_vfadapt_i350))
1946 em_allocate_pci_resources(if_ctx_t ctx)
1948 struct e1000_softc *sc = iflib_get_softc(ctx);
1949 device_t dev = iflib_get_dev(ctx);
1953 sc->memory = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1955 if (sc->memory == NULL) {
1956 device_printf(dev, "Unable to allocate bus resource: memory\n");
1959 sc->osdep.mem_bus_space_tag = rman_get_bustag(sc->memory);
1960 sc->osdep.mem_bus_space_handle =
1961 rman_get_bushandle(sc->memory);
1962 sc->hw.hw_addr = (u8 *)&sc->osdep.mem_bus_space_handle;
1964 /* Only older adapters use IO mapping */
1965 if (sc->hw.mac.type < em_mac_min &&
1966 sc->hw.mac.type > e1000_82543) {
1967 /* Figure our where our IO BAR is ? */
1968 for (rid = PCIR_BAR(0); rid < PCIR_CIS;) {
1969 val = pci_read_config(dev, rid, 4);
1970 if (EM_BAR_TYPE(val) == EM_BAR_TYPE_IO) {
1974 /* check for 64bit BAR */
1975 if (EM_BAR_MEM_TYPE(val) == EM_BAR_MEM_TYPE_64BIT)
1978 if (rid >= PCIR_CIS) {
1979 device_printf(dev, "Unable to locate IO BAR\n");
1982 sc->ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
1984 if (sc->ioport == NULL) {
1985 device_printf(dev, "Unable to allocate bus resource: "
1990 sc->osdep.io_bus_space_tag =
1991 rman_get_bustag(sc->ioport);
1992 sc->osdep.io_bus_space_handle =
1993 rman_get_bushandle(sc->ioport);
1996 sc->hw.back = &sc->osdep;
2001 /*********************************************************************
2003 * Set up the MSI-X Interrupt handlers
2005 **********************************************************************/
2007 em_if_msix_intr_assign(if_ctx_t ctx, int msix)
2009 struct e1000_softc *sc = iflib_get_softc(ctx);
2010 struct em_rx_queue *rx_que = sc->rx_queues;
2011 struct em_tx_queue *tx_que = sc->tx_queues;
2012 int error, rid, i, vector = 0, rx_vectors;
2015 /* First set up ring resources */
2016 for (i = 0; i < sc->rx_num_queues; i++, rx_que++, vector++) {
2018 snprintf(buf, sizeof(buf), "rxq%d", i);
2019 error = iflib_irq_alloc_generic(ctx, &rx_que->que_irq, rid, IFLIB_INTR_RXTX, em_msix_que, rx_que, rx_que->me, buf);
2021 device_printf(iflib_get_dev(ctx), "Failed to allocate que int %d err: %d", i, error);
2022 sc->rx_num_queues = i + 1;
2026 rx_que->msix = vector;
2029 * Set the bit to enable interrupt
2030 * in E1000_IMS -- bits 20 and 21
2031 * are for RX0 and RX1, note this has
2032 * NOTHING to do with the MSI-X vector
2034 if (sc->hw.mac.type == e1000_82574) {
2035 rx_que->eims = 1 << (20 + i);
2036 sc->ims |= rx_que->eims;
2037 sc->ivars |= (8 | rx_que->msix) << (i * 4);
2038 } else if (sc->hw.mac.type == e1000_82575)
2039 rx_que->eims = E1000_EICR_TX_QUEUE0 << vector;
2041 rx_que->eims = 1 << vector;
2043 rx_vectors = vector;
2046 for (i = 0; i < sc->tx_num_queues; i++, tx_que++, vector++) {
2047 snprintf(buf, sizeof(buf), "txq%d", i);
2048 tx_que = &sc->tx_queues[i];
2049 iflib_softirq_alloc_generic(ctx,
2050 &sc->rx_queues[i % sc->rx_num_queues].que_irq,
2051 IFLIB_INTR_TX, tx_que, tx_que->me, buf);
2053 tx_que->msix = (vector % sc->rx_num_queues);
2056 * Set the bit to enable interrupt
2057 * in E1000_IMS -- bits 22 and 23
2058 * are for TX0 and TX1, note this has
2059 * NOTHING to do with the MSI-X vector
2061 if (sc->hw.mac.type == e1000_82574) {
2062 tx_que->eims = 1 << (22 + i);
2063 sc->ims |= tx_que->eims;
2064 sc->ivars |= (8 | tx_que->msix) << (8 + (i * 4));
2065 } else if (sc->hw.mac.type == e1000_82575) {
2066 tx_que->eims = E1000_EICR_TX_QUEUE0 << i;
2068 tx_que->eims = 1 << i;
2072 /* Link interrupt */
2073 rid = rx_vectors + 1;
2074 error = iflib_irq_alloc_generic(ctx, &sc->irq, rid, IFLIB_INTR_ADMIN, em_msix_link, sc, 0, "aq");
2077 device_printf(iflib_get_dev(ctx), "Failed to register admin handler");
2080 sc->linkvec = rx_vectors;
2081 if (sc->hw.mac.type < igb_mac_min) {
2082 sc->ivars |= (8 | rx_vectors) << 16;
2083 sc->ivars |= 0x80000000;
2084 /* Enable the "Other" interrupt type for link status change */
2085 sc->ims |= E1000_IMS_OTHER;
2090 iflib_irq_free(ctx, &sc->irq);
2091 rx_que = sc->rx_queues;
2092 for (int i = 0; i < sc->rx_num_queues; i++, rx_que++)
2093 iflib_irq_free(ctx, &rx_que->que_irq);
2098 igb_configure_queues(struct e1000_softc *sc)
2100 struct e1000_hw *hw = &sc->hw;
2101 struct em_rx_queue *rx_que;
2102 struct em_tx_queue *tx_que;
2103 u32 tmp, ivar = 0, newitr = 0;
2105 /* First turn on RSS capability */
2106 if (hw->mac.type != e1000_82575)
2107 E1000_WRITE_REG(hw, E1000_GPIE,
2108 E1000_GPIE_MSIX_MODE | E1000_GPIE_EIAME |
2109 E1000_GPIE_PBA | E1000_GPIE_NSICR);
2112 switch (hw->mac.type) {
2119 case e1000_vfadapt_i350:
2121 for (int i = 0; i < sc->rx_num_queues; i++) {
2123 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
2124 rx_que = &sc->rx_queues[i];
2127 ivar |= (rx_que->msix | E1000_IVAR_VALID) << 16;
2130 ivar |= rx_que->msix | E1000_IVAR_VALID;
2132 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
2135 for (int i = 0; i < sc->tx_num_queues; i++) {
2137 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
2138 tx_que = &sc->tx_queues[i];
2141 ivar |= (tx_que->msix | E1000_IVAR_VALID) << 24;
2144 ivar |= (tx_que->msix | E1000_IVAR_VALID) << 8;
2146 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
2147 sc->que_mask |= tx_que->eims;
2150 /* And for the link interrupt */
2151 ivar = (sc->linkvec | E1000_IVAR_VALID) << 8;
2152 sc->link_mask = 1 << sc->linkvec;
2153 E1000_WRITE_REG(hw, E1000_IVAR_MISC, ivar);
2157 for (int i = 0; i < sc->rx_num_queues; i++) {
2158 u32 index = i & 0x7; /* Each IVAR has two entries */
2159 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
2160 rx_que = &sc->rx_queues[i];
2163 ivar |= rx_que->msix | E1000_IVAR_VALID;
2166 ivar |= (rx_que->msix | E1000_IVAR_VALID) << 16;
2168 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
2169 sc->que_mask |= rx_que->eims;
2172 for (int i = 0; i < sc->tx_num_queues; i++) {
2173 u32 index = i & 0x7; /* Each IVAR has two entries */
2174 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
2175 tx_que = &sc->tx_queues[i];
2178 ivar |= (tx_que->msix | E1000_IVAR_VALID) << 8;
2181 ivar |= (tx_que->msix | E1000_IVAR_VALID) << 24;
2183 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
2184 sc->que_mask |= tx_que->eims;
2187 /* And for the link interrupt */
2188 ivar = (sc->linkvec | E1000_IVAR_VALID) << 8;
2189 sc->link_mask = 1 << sc->linkvec;
2190 E1000_WRITE_REG(hw, E1000_IVAR_MISC, ivar);
2194 /* enable MSI-X support*/
2195 tmp = E1000_READ_REG(hw, E1000_CTRL_EXT);
2196 tmp |= E1000_CTRL_EXT_PBA_CLR;
2197 /* Auto-Mask interrupts upon ICR read. */
2198 tmp |= E1000_CTRL_EXT_EIAME;
2199 tmp |= E1000_CTRL_EXT_IRCA;
2200 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmp);
2203 for (int i = 0; i < sc->rx_num_queues; i++) {
2204 rx_que = &sc->rx_queues[i];
2205 tmp = E1000_EICR_RX_QUEUE0 << i;
2206 tmp |= E1000_EICR_TX_QUEUE0 << i;
2208 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0),
2210 sc->que_mask |= rx_que->eims;
2214 E1000_WRITE_REG(hw, E1000_MSIXBM(sc->linkvec),
2216 sc->link_mask |= E1000_EIMS_OTHER;
2221 /* Set the starting interrupt rate */
2222 if (em_max_interrupt_rate > 0)
2223 newitr = (4000000 / em_max_interrupt_rate) & 0x7FFC;
2225 if (hw->mac.type == e1000_82575)
2226 newitr |= newitr << 16;
2228 newitr |= E1000_EITR_CNT_IGNR;
2230 for (int i = 0; i < sc->rx_num_queues; i++) {
2231 rx_que = &sc->rx_queues[i];
2232 E1000_WRITE_REG(hw, E1000_EITR(rx_que->msix), newitr);
2239 em_free_pci_resources(if_ctx_t ctx)
2241 struct e1000_softc *sc = iflib_get_softc(ctx);
2242 struct em_rx_queue *que = sc->rx_queues;
2243 device_t dev = iflib_get_dev(ctx);
2245 /* Release all MSI-X queue resources */
2246 if (sc->intr_type == IFLIB_INTR_MSIX)
2247 iflib_irq_free(ctx, &sc->irq);
2250 for (int i = 0; i < sc->rx_num_queues; i++, que++) {
2251 iflib_irq_free(ctx, &que->que_irq);
2255 if (sc->memory != NULL) {
2256 bus_release_resource(dev, SYS_RES_MEMORY,
2257 rman_get_rid(sc->memory), sc->memory);
2261 if (sc->flash != NULL) {
2262 bus_release_resource(dev, SYS_RES_MEMORY,
2263 rman_get_rid(sc->flash), sc->flash);
2267 if (sc->ioport != NULL) {
2268 bus_release_resource(dev, SYS_RES_IOPORT,
2269 rman_get_rid(sc->ioport), sc->ioport);
2274 /* Set up MSI or MSI-X */
2276 em_setup_msix(if_ctx_t ctx)
2278 struct e1000_softc *sc = iflib_get_softc(ctx);
2280 if (sc->hw.mac.type == e1000_82574) {
2281 em_enable_vectors_82574(ctx);
2286 /*********************************************************************
2288 * Workaround for SmartSpeed on 82541 and 82547 controllers
2290 **********************************************************************/
2292 lem_smartspeed(struct e1000_softc *sc)
2296 if (sc->link_active || (sc->hw.phy.type != e1000_phy_igp) ||
2297 sc->hw.mac.autoneg == 0 ||
2298 (sc->hw.phy.autoneg_advertised & ADVERTISE_1000_FULL) == 0)
2301 if (sc->smartspeed == 0) {
2302 /* If Master/Slave config fault is asserted twice,
2303 * we assume back-to-back */
2304 e1000_read_phy_reg(&sc->hw, PHY_1000T_STATUS, &phy_tmp);
2305 if (!(phy_tmp & SR_1000T_MS_CONFIG_FAULT))
2307 e1000_read_phy_reg(&sc->hw, PHY_1000T_STATUS, &phy_tmp);
2308 if (phy_tmp & SR_1000T_MS_CONFIG_FAULT) {
2309 e1000_read_phy_reg(&sc->hw,
2310 PHY_1000T_CTRL, &phy_tmp);
2311 if(phy_tmp & CR_1000T_MS_ENABLE) {
2312 phy_tmp &= ~CR_1000T_MS_ENABLE;
2313 e1000_write_phy_reg(&sc->hw,
2314 PHY_1000T_CTRL, phy_tmp);
2316 if(sc->hw.mac.autoneg &&
2317 !e1000_copper_link_autoneg(&sc->hw) &&
2318 !e1000_read_phy_reg(&sc->hw,
2319 PHY_CONTROL, &phy_tmp)) {
2320 phy_tmp |= (MII_CR_AUTO_NEG_EN |
2321 MII_CR_RESTART_AUTO_NEG);
2322 e1000_write_phy_reg(&sc->hw,
2323 PHY_CONTROL, phy_tmp);
2328 } else if(sc->smartspeed == EM_SMARTSPEED_DOWNSHIFT) {
2329 /* If still no link, perhaps using 2/3 pair cable */
2330 e1000_read_phy_reg(&sc->hw, PHY_1000T_CTRL, &phy_tmp);
2331 phy_tmp |= CR_1000T_MS_ENABLE;
2332 e1000_write_phy_reg(&sc->hw, PHY_1000T_CTRL, phy_tmp);
2333 if(sc->hw.mac.autoneg &&
2334 !e1000_copper_link_autoneg(&sc->hw) &&
2335 !e1000_read_phy_reg(&sc->hw, PHY_CONTROL, &phy_tmp)) {
2336 phy_tmp |= (MII_CR_AUTO_NEG_EN |
2337 MII_CR_RESTART_AUTO_NEG);
2338 e1000_write_phy_reg(&sc->hw, PHY_CONTROL, phy_tmp);
2341 /* Restart process after EM_SMARTSPEED_MAX iterations */
2342 if(sc->smartspeed++ == EM_SMARTSPEED_MAX)
2346 /*********************************************************************
2348 * Initialize the DMA Coalescing feature
2350 **********************************************************************/
2352 igb_init_dmac(struct e1000_softc *sc, u32 pba)
2354 device_t dev = sc->dev;
2355 struct e1000_hw *hw = &sc->hw;
2356 u32 dmac, reg = ~E1000_DMACR_DMAC_EN;
2360 if (hw->mac.type == e1000_i211)
2363 max_frame_size = sc->shared->isc_max_frame_size;
2364 if (hw->mac.type > e1000_82580) {
2366 if (sc->dmac == 0) { /* Disabling it */
2367 E1000_WRITE_REG(hw, E1000_DMACR, reg);
2370 device_printf(dev, "DMA Coalescing enabled\n");
2372 /* Set starting threshold */
2373 E1000_WRITE_REG(hw, E1000_DMCTXTH, 0);
2375 hwm = 64 * pba - max_frame_size / 16;
2376 if (hwm < 64 * (pba - 6))
2377 hwm = 64 * (pba - 6);
2378 reg = E1000_READ_REG(hw, E1000_FCRTC);
2379 reg &= ~E1000_FCRTC_RTH_COAL_MASK;
2380 reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
2381 & E1000_FCRTC_RTH_COAL_MASK);
2382 E1000_WRITE_REG(hw, E1000_FCRTC, reg);
2385 dmac = pba - max_frame_size / 512;
2386 if (dmac < pba - 10)
2388 reg = E1000_READ_REG(hw, E1000_DMACR);
2389 reg &= ~E1000_DMACR_DMACTHR_MASK;
2390 reg |= ((dmac << E1000_DMACR_DMACTHR_SHIFT)
2391 & E1000_DMACR_DMACTHR_MASK);
2393 /* transition to L0x or L1 if available..*/
2394 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
2396 /* Check if status is 2.5Gb backplane connection
2397 * before configuration of watchdog timer, which is
2398 * in msec values in 12.8usec intervals
2399 * watchdog timer= msec values in 32usec intervals
2400 * for non 2.5Gb connection
2402 if (hw->mac.type == e1000_i354) {
2403 int status = E1000_READ_REG(hw, E1000_STATUS);
2404 if ((status & E1000_STATUS_2P5_SKU) &&
2405 (!(status & E1000_STATUS_2P5_SKU_OVER)))
2406 reg |= ((sc->dmac * 5) >> 6);
2408 reg |= (sc->dmac >> 5);
2410 reg |= (sc->dmac >> 5);
2413 E1000_WRITE_REG(hw, E1000_DMACR, reg);
2415 E1000_WRITE_REG(hw, E1000_DMCRTRH, 0);
2417 /* Set the interval before transition */
2418 reg = E1000_READ_REG(hw, E1000_DMCTLX);
2419 if (hw->mac.type == e1000_i350)
2420 reg |= IGB_DMCTLX_DCFLUSH_DIS;
2422 ** in 2.5Gb connection, TTLX unit is 0.4 usec
2423 ** which is 0x4*2 = 0xA. But delay is still 4 usec
2425 if (hw->mac.type == e1000_i354) {
2426 int status = E1000_READ_REG(hw, E1000_STATUS);
2427 if ((status & E1000_STATUS_2P5_SKU) &&
2428 (!(status & E1000_STATUS_2P5_SKU_OVER)))
2436 E1000_WRITE_REG(hw, E1000_DMCTLX, reg);
2438 /* free space in tx packet buffer to wake from DMA coal */
2439 E1000_WRITE_REG(hw, E1000_DMCTXTH, (IGB_TXPBSIZE -
2440 (2 * max_frame_size)) >> 6);
2442 /* make low power state decision controlled by DMA coal */
2443 reg = E1000_READ_REG(hw, E1000_PCIEMISC);
2444 reg &= ~E1000_PCIEMISC_LX_DECISION;
2445 E1000_WRITE_REG(hw, E1000_PCIEMISC, reg);
2447 } else if (hw->mac.type == e1000_82580) {
2448 u32 reg = E1000_READ_REG(hw, E1000_PCIEMISC);
2449 E1000_WRITE_REG(hw, E1000_PCIEMISC,
2450 reg & ~E1000_PCIEMISC_LX_DECISION);
2451 E1000_WRITE_REG(hw, E1000_DMACR, 0);
2455 /*********************************************************************
2457 * Initialize the hardware to a configuration as specified by the
2460 **********************************************************************/
2462 em_reset(if_ctx_t ctx)
2464 device_t dev = iflib_get_dev(ctx);
2465 struct e1000_softc *sc = iflib_get_softc(ctx);
2466 struct ifnet *ifp = iflib_get_ifp(ctx);
2467 struct e1000_hw *hw = &sc->hw;
2471 INIT_DEBUGOUT("em_reset: begin");
2472 /* Let the firmware know the OS is in control */
2473 em_get_hw_control(sc);
2475 /* Set up smart power down as default off on newer adapters. */
2476 if (!em_smart_pwr_down && (hw->mac.type == e1000_82571 ||
2477 hw->mac.type == e1000_82572)) {
2480 /* Speed up time to link by disabling smart power down. */
2481 e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_tmp);
2482 phy_tmp &= ~IGP02E1000_PM_SPD;
2483 e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_tmp);
2487 * Packet Buffer Allocation (PBA)
2488 * Writing PBA sets the receive portion of the buffer
2489 * the remainder is used for the transmit buffer.
2491 switch (hw->mac.type) {
2492 /* 82547: Total Packet Buffer is 40K */
2494 case e1000_82547_rev_2:
2495 if (hw->mac.max_frame_size > 8192)
2496 pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */
2498 pba = E1000_PBA_30K; /* 30K for Rx, 10K for Tx */
2500 /* 82571/82572/80003es2lan: Total Packet Buffer is 48K */
2503 case e1000_80003es2lan:
2504 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
2506 /* 82573: Total Packet Buffer is 32K */
2508 pba = E1000_PBA_12K; /* 12K for Rx, 20K for Tx */
2512 pba = E1000_PBA_20K; /* 20K for Rx, 20K for Tx */
2518 case e1000_ich10lan:
2519 /* Boost Receive side for jumbo frames */
2520 if (hw->mac.max_frame_size > 4096)
2521 pba = E1000_PBA_14K;
2523 pba = E1000_PBA_10K;
2533 pba = E1000_PBA_26K;
2536 pba = E1000_PBA_32K;
2540 pba = E1000_READ_REG(hw, E1000_RXPBS);
2541 pba &= E1000_RXPBS_SIZE_MASK_82576;
2546 case e1000_vfadapt_i350:
2547 pba = E1000_READ_REG(hw, E1000_RXPBS);
2548 pba = e1000_rxpbs_adjust_82580(pba);
2552 pba = E1000_PBA_34K;
2555 /* Remaining devices assumed to have a Packet Buffer of 64K. */
2556 if (hw->mac.max_frame_size > 8192)
2557 pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */
2559 pba = E1000_PBA_48K; /* 48K for Rx, 16K for Tx */
2562 /* Special needs in case of Jumbo frames */
2563 if ((hw->mac.type == e1000_82575) && (ifp->if_mtu > ETHERMTU)) {
2564 u32 tx_space, min_tx, min_rx;
2565 pba = E1000_READ_REG(hw, E1000_PBA);
2566 tx_space = pba >> 16;
2568 min_tx = (hw->mac.max_frame_size +
2569 sizeof(struct e1000_tx_desc) - ETHERNET_FCS_SIZE) * 2;
2570 min_tx = roundup2(min_tx, 1024);
2572 min_rx = hw->mac.max_frame_size;
2573 min_rx = roundup2(min_rx, 1024);
2575 if (tx_space < min_tx &&
2576 ((min_tx - tx_space) < pba)) {
2577 pba = pba - (min_tx - tx_space);
2579 * if short on rx space, rx wins
2580 * and must trump tx adjustment
2585 E1000_WRITE_REG(hw, E1000_PBA, pba);
2588 if (hw->mac.type < igb_mac_min)
2589 E1000_WRITE_REG(hw, E1000_PBA, pba);
2591 INIT_DEBUGOUT1("em_reset: pba=%dK",pba);
2594 * These parameters control the automatic generation (Tx) and
2595 * response (Rx) to Ethernet PAUSE frames.
2596 * - High water mark should allow for at least two frames to be
2597 * received after sending an XOFF.
2598 * - Low water mark works best when it is very near the high water mark.
2599 * This allows the receiver to restart by sending XON when it has
2600 * drained a bit. Here we use an arbitrary value of 1500 which will
2601 * restart after one full frame is pulled from the buffer. There
2602 * could be several smaller frames in the buffer and if so they will
2603 * not trigger the XON until their total number reduces the buffer
2605 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
2607 rx_buffer_size = (pba & 0xffff) << 10;
2608 hw->fc.high_water = rx_buffer_size -
2609 roundup2(hw->mac.max_frame_size, 1024);
2610 hw->fc.low_water = hw->fc.high_water - 1500;
2612 if (sc->fc) /* locally set flow control value? */
2613 hw->fc.requested_mode = sc->fc;
2615 hw->fc.requested_mode = e1000_fc_full;
2617 if (hw->mac.type == e1000_80003es2lan)
2618 hw->fc.pause_time = 0xFFFF;
2620 hw->fc.pause_time = EM_FC_PAUSE_TIME;
2622 hw->fc.send_xon = true;
2624 /* Device specific overrides/settings */
2625 switch (hw->mac.type) {
2627 /* Workaround: no TX flow ctrl for PCH */
2628 hw->fc.requested_mode = e1000_fc_rx_pause;
2629 hw->fc.pause_time = 0xFFFF; /* override */
2630 if (if_getmtu(ifp) > ETHERMTU) {
2631 hw->fc.high_water = 0x3500;
2632 hw->fc.low_water = 0x1500;
2634 hw->fc.high_water = 0x5000;
2635 hw->fc.low_water = 0x3000;
2637 hw->fc.refresh_time = 0x1000;
2646 hw->fc.high_water = 0x5C20;
2647 hw->fc.low_water = 0x5048;
2648 hw->fc.pause_time = 0x0650;
2649 hw->fc.refresh_time = 0x0400;
2650 /* Jumbos need adjusted PBA */
2651 if (if_getmtu(ifp) > ETHERMTU)
2652 E1000_WRITE_REG(hw, E1000_PBA, 12);
2654 E1000_WRITE_REG(hw, E1000_PBA, 26);
2658 /* 8-byte granularity */
2659 hw->fc.low_water = hw->fc.high_water - 8;
2667 case e1000_vfadapt_i350:
2668 /* 16-byte granularity */
2669 hw->fc.low_water = hw->fc.high_water - 16;
2672 case e1000_ich10lan:
2673 if (if_getmtu(ifp) > ETHERMTU) {
2674 hw->fc.high_water = 0x2800;
2675 hw->fc.low_water = hw->fc.high_water - 8;
2680 if (hw->mac.type == e1000_80003es2lan)
2681 hw->fc.pause_time = 0xFFFF;
2685 /* Issue a global reset */
2687 if (hw->mac.type >= igb_mac_min) {
2688 E1000_WRITE_REG(hw, E1000_WUC, 0);
2690 E1000_WRITE_REG(hw, E1000_WUFC, 0);
2691 em_disable_aspm(sc);
2693 if (sc->flags & IGB_MEDIA_RESET) {
2694 e1000_setup_init_funcs(hw, true);
2695 e1000_get_bus_info(hw);
2696 sc->flags &= ~IGB_MEDIA_RESET;
2699 if (e1000_init_hw(hw) < 0) {
2700 device_printf(dev, "Hardware Initialization Failed\n");
2703 if (hw->mac.type >= igb_mac_min)
2704 igb_init_dmac(sc, pba);
2706 E1000_WRITE_REG(hw, E1000_VET, ETHERTYPE_VLAN);
2707 e1000_get_phy_info(hw);
2708 e1000_check_for_link(hw);
2712 * Initialise the RSS mapping for NICs that support multiple transmit/
2716 #define RSSKEYLEN 10
2718 em_initialize_rss_mapping(struct e1000_softc *sc)
2720 uint8_t rss_key[4 * RSSKEYLEN];
2722 struct e1000_hw *hw = &sc->hw;
2728 arc4rand(rss_key, sizeof(rss_key), 0);
2729 for (i = 0; i < RSSKEYLEN; ++i) {
2732 rssrk = EM_RSSRK_VAL(rss_key, i);
2733 E1000_WRITE_REG(hw,E1000_RSSRK(i), rssrk);
2737 * Configure RSS redirect table in following fashion:
2738 * (hash & ring_cnt_mask) == rdr_table[(hash & rdr_table_mask)]
2740 for (i = 0; i < sizeof(reta); ++i) {
2743 q = (i % sc->rx_num_queues) << 7;
2744 reta |= q << (8 * i);
2747 for (i = 0; i < 32; ++i)
2748 E1000_WRITE_REG(hw, E1000_RETA(i), reta);
2750 E1000_WRITE_REG(hw, E1000_MRQC, E1000_MRQC_RSS_ENABLE_2Q |
2751 E1000_MRQC_RSS_FIELD_IPV4_TCP |
2752 E1000_MRQC_RSS_FIELD_IPV4 |
2753 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX |
2754 E1000_MRQC_RSS_FIELD_IPV6_EX |
2755 E1000_MRQC_RSS_FIELD_IPV6);
2759 igb_initialize_rss_mapping(struct e1000_softc *sc)
2761 struct e1000_hw *hw = &sc->hw;
2765 u32 rss_key[10], mrqc, shift = 0;
2768 if (hw->mac.type == e1000_82575)
2772 * The redirection table controls which destination
2773 * queue each bucket redirects traffic to.
2774 * Each DWORD represents four queues, with the LSB
2775 * being the first queue in the DWORD.
2777 * This just allocates buckets to queues using round-robin
2780 * NOTE: It Just Happens to line up with the default
2781 * RSS allocation method.
2784 /* Warning FM follows */
2786 for (i = 0; i < 128; i++) {
2788 queue_id = rss_get_indirection_to_bucket(i);
2790 * If we have more queues than buckets, we'll
2791 * end up mapping buckets to a subset of the
2794 * If we have more buckets than queues, we'll
2795 * end up instead assigning multiple buckets
2798 * Both are suboptimal, but we need to handle
2799 * the case so we don't go out of bounds
2800 * indexing arrays and such.
2802 queue_id = queue_id % sc->rx_num_queues;
2804 queue_id = (i % sc->rx_num_queues);
2806 /* Adjust if required */
2807 queue_id = queue_id << shift;
2810 * The low 8 bits are for hash value (n+0);
2811 * The next 8 bits are for hash value (n+1), etc.
2814 reta = reta | ( ((uint32_t) queue_id) << 24);
2816 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
2821 /* Now fill in hash table */
2824 * MRQC: Multiple Receive Queues Command
2825 * Set queuing to RSS control, number depends on the device.
2827 mrqc = E1000_MRQC_ENABLE_RSS_MQ;
2830 /* XXX ew typecasting */
2831 rss_getkey((uint8_t *) &rss_key);
2833 arc4rand(&rss_key, sizeof(rss_key), 0);
2835 for (i = 0; i < 10; i++)
2836 E1000_WRITE_REG_ARRAY(hw, E1000_RSSRK(0), i, rss_key[i]);
2839 * Configure the RSS fields to hash upon.
2841 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
2842 E1000_MRQC_RSS_FIELD_IPV4_TCP);
2843 mrqc |= (E1000_MRQC_RSS_FIELD_IPV6 |
2844 E1000_MRQC_RSS_FIELD_IPV6_TCP);
2845 mrqc |=( E1000_MRQC_RSS_FIELD_IPV4_UDP |
2846 E1000_MRQC_RSS_FIELD_IPV6_UDP);
2847 mrqc |=( E1000_MRQC_RSS_FIELD_IPV6_UDP_EX |
2848 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
2850 E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
2853 /*********************************************************************
2855 * Setup networking device structure and register interface media.
2857 **********************************************************************/
2859 em_setup_interface(if_ctx_t ctx)
2861 struct ifnet *ifp = iflib_get_ifp(ctx);
2862 struct e1000_softc *sc = iflib_get_softc(ctx);
2863 if_softc_ctx_t scctx = sc->shared;
2865 INIT_DEBUGOUT("em_setup_interface: begin");
2868 if (sc->tx_num_queues == 1) {
2869 if_setsendqlen(ifp, scctx->isc_ntxd[0] - 1);
2870 if_setsendqready(ifp);
2874 * Specify the media types supported by this adapter and register
2875 * callbacks to update media and link information
2877 if (sc->hw.phy.media_type == e1000_media_type_fiber ||
2878 sc->hw.phy.media_type == e1000_media_type_internal_serdes) {
2879 u_char fiber_type = IFM_1000_SX; /* default type */
2881 if (sc->hw.mac.type == e1000_82545)
2882 fiber_type = IFM_1000_LX;
2883 ifmedia_add(sc->media, IFM_ETHER | fiber_type | IFM_FDX, 0, NULL);
2884 ifmedia_add(sc->media, IFM_ETHER | fiber_type, 0, NULL);
2886 ifmedia_add(sc->media, IFM_ETHER | IFM_10_T, 0, NULL);
2887 ifmedia_add(sc->media, IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL);
2888 ifmedia_add(sc->media, IFM_ETHER | IFM_100_TX, 0, NULL);
2889 ifmedia_add(sc->media, IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL);
2890 if (sc->hw.phy.type != e1000_phy_ife) {
2891 ifmedia_add(sc->media, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
2892 ifmedia_add(sc->media, IFM_ETHER | IFM_1000_T, 0, NULL);
2895 ifmedia_add(sc->media, IFM_ETHER | IFM_AUTO, 0, NULL);
2896 ifmedia_set(sc->media, IFM_ETHER | IFM_AUTO);
2901 em_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets)
2903 struct e1000_softc *sc = iflib_get_softc(ctx);
2904 if_softc_ctx_t scctx = sc->shared;
2905 int error = E1000_SUCCESS;
2906 struct em_tx_queue *que;
2909 MPASS(sc->tx_num_queues > 0);
2910 MPASS(sc->tx_num_queues == ntxqsets);
2912 /* First allocate the top level queue structs */
2913 if (!(sc->tx_queues =
2914 (struct em_tx_queue *) malloc(sizeof(struct em_tx_queue) *
2915 sc->tx_num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2916 device_printf(iflib_get_dev(ctx), "Unable to allocate queue memory\n");
2920 for (i = 0, que = sc->tx_queues; i < sc->tx_num_queues; i++, que++) {
2921 /* Set up some basics */
2923 struct tx_ring *txr = &que->txr;
2924 txr->sc = que->sc = sc;
2925 que->me = txr->me = i;
2927 /* Allocate report status array */
2928 if (!(txr->tx_rsq = (qidx_t *) malloc(sizeof(qidx_t) * scctx->isc_ntxd[0], M_DEVBUF, M_NOWAIT | M_ZERO))) {
2929 device_printf(iflib_get_dev(ctx), "failed to allocate rs_idxs memory\n");
2933 for (j = 0; j < scctx->isc_ntxd[0]; j++)
2934 txr->tx_rsq[j] = QIDX_INVALID;
2935 /* get the virtual and physical address of the hardware queues */
2936 txr->tx_base = (struct e1000_tx_desc *)vaddrs[i*ntxqs];
2937 txr->tx_paddr = paddrs[i*ntxqs];
2941 device_printf(iflib_get_dev(ctx),
2942 "allocated for %d tx_queues\n", sc->tx_num_queues);
2945 em_if_queues_free(ctx);
2950 em_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nrxqs, int nrxqsets)
2952 struct e1000_softc *sc = iflib_get_softc(ctx);
2953 int error = E1000_SUCCESS;
2954 struct em_rx_queue *que;
2957 MPASS(sc->rx_num_queues > 0);
2958 MPASS(sc->rx_num_queues == nrxqsets);
2960 /* First allocate the top level queue structs */
2961 if (!(sc->rx_queues =
2962 (struct em_rx_queue *) malloc(sizeof(struct em_rx_queue) *
2963 sc->rx_num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2964 device_printf(iflib_get_dev(ctx), "Unable to allocate queue memory\n");
2969 for (i = 0, que = sc->rx_queues; i < nrxqsets; i++, que++) {
2970 /* Set up some basics */
2971 struct rx_ring *rxr = &que->rxr;
2972 rxr->sc = que->sc = sc;
2974 que->me = rxr->me = i;
2976 /* get the virtual and physical address of the hardware queues */
2977 rxr->rx_base = (union e1000_rx_desc_extended *)vaddrs[i*nrxqs];
2978 rxr->rx_paddr = paddrs[i*nrxqs];
2982 device_printf(iflib_get_dev(ctx),
2983 "allocated for %d rx_queues\n", sc->rx_num_queues);
2987 em_if_queues_free(ctx);
2992 em_if_queues_free(if_ctx_t ctx)
2994 struct e1000_softc *sc = iflib_get_softc(ctx);
2995 struct em_tx_queue *tx_que = sc->tx_queues;
2996 struct em_rx_queue *rx_que = sc->rx_queues;
2998 if (tx_que != NULL) {
2999 for (int i = 0; i < sc->tx_num_queues; i++, tx_que++) {
3000 struct tx_ring *txr = &tx_que->txr;
3001 if (txr->tx_rsq == NULL)
3004 free(txr->tx_rsq, M_DEVBUF);
3007 free(sc->tx_queues, M_DEVBUF);
3008 sc->tx_queues = NULL;
3011 if (rx_que != NULL) {
3012 free(sc->rx_queues, M_DEVBUF);
3013 sc->rx_queues = NULL;
3017 /*********************************************************************
3019 * Enable transmit unit.
3021 **********************************************************************/
3023 em_initialize_transmit_unit(if_ctx_t ctx)
3025 struct e1000_softc *sc = iflib_get_softc(ctx);
3026 if_softc_ctx_t scctx = sc->shared;
3027 struct em_tx_queue *que;
3028 struct tx_ring *txr;
3029 struct e1000_hw *hw = &sc->hw;
3030 u32 tctl, txdctl = 0, tarc, tipg = 0;
3032 INIT_DEBUGOUT("em_initialize_transmit_unit: begin");
3034 for (int i = 0; i < sc->tx_num_queues; i++, txr++) {
3038 que = &sc->tx_queues[i];
3040 bus_addr = txr->tx_paddr;
3042 /* Clear checksum offload context. */
3043 offp = (caddr_t)&txr->csum_flags;
3044 endp = (caddr_t)(txr + 1);
3045 bzero(offp, endp - offp);
3047 /* Base and Len of TX Ring */
3048 E1000_WRITE_REG(hw, E1000_TDLEN(i),
3049 scctx->isc_ntxd[0] * sizeof(struct e1000_tx_desc));
3050 E1000_WRITE_REG(hw, E1000_TDBAH(i),
3051 (u32)(bus_addr >> 32));
3052 E1000_WRITE_REG(hw, E1000_TDBAL(i),
3054 /* Init the HEAD/TAIL indices */
3055 E1000_WRITE_REG(hw, E1000_TDT(i), 0);
3056 E1000_WRITE_REG(hw, E1000_TDH(i), 0);
3058 HW_DEBUGOUT2("Base = %x, Length = %x\n",
3059 E1000_READ_REG(hw, E1000_TDBAL(i)),
3060 E1000_READ_REG(hw, E1000_TDLEN(i)));
3062 txdctl = 0; /* clear txdctl */
3063 txdctl |= 0x1f; /* PTHRESH */
3064 txdctl |= 1 << 8; /* HTHRESH */
3065 txdctl |= 1 << 16;/* WTHRESH */
3066 txdctl |= 1 << 22; /* Reserved bit 22 must always be 1 */
3067 txdctl |= E1000_TXDCTL_GRAN;
3068 txdctl |= 1 << 25; /* LWTHRESH */
3070 E1000_WRITE_REG(hw, E1000_TXDCTL(i), txdctl);
3073 /* Set the default values for the Tx Inter Packet Gap timer */
3074 switch (hw->mac.type) {
3075 case e1000_80003es2lan:
3076 tipg = DEFAULT_82543_TIPG_IPGR1;
3077 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGR2 <<
3078 E1000_TIPG_IPGR2_SHIFT;
3081 tipg = DEFAULT_82542_TIPG_IPGT;
3082 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
3083 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
3086 if (hw->phy.media_type == e1000_media_type_fiber ||
3087 hw->phy.media_type == e1000_media_type_internal_serdes)
3088 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
3090 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
3091 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
3092 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
3095 E1000_WRITE_REG(hw, E1000_TIPG, tipg);
3096 E1000_WRITE_REG(hw, E1000_TIDV, sc->tx_int_delay.value);
3098 if(hw->mac.type >= e1000_82540)
3099 E1000_WRITE_REG(hw, E1000_TADV,
3100 sc->tx_abs_int_delay.value);
3102 if (hw->mac.type == e1000_82571 || hw->mac.type == e1000_82572) {
3103 tarc = E1000_READ_REG(hw, E1000_TARC(0));
3104 tarc |= TARC_SPEED_MODE_BIT;
3105 E1000_WRITE_REG(hw, E1000_TARC(0), tarc);
3106 } else if (hw->mac.type == e1000_80003es2lan) {
3107 /* errata: program both queues to unweighted RR */
3108 tarc = E1000_READ_REG(hw, E1000_TARC(0));
3110 E1000_WRITE_REG(hw, E1000_TARC(0), tarc);
3111 tarc = E1000_READ_REG(hw, E1000_TARC(1));
3113 E1000_WRITE_REG(hw, E1000_TARC(1), tarc);
3114 } else if (hw->mac.type == e1000_82574) {
3115 tarc = E1000_READ_REG(hw, E1000_TARC(0));
3116 tarc |= TARC_ERRATA_BIT;
3117 if ( sc->tx_num_queues > 1) {
3118 tarc |= (TARC_COMPENSATION_MODE | TARC_MQ_FIX);
3119 E1000_WRITE_REG(hw, E1000_TARC(0), tarc);
3120 E1000_WRITE_REG(hw, E1000_TARC(1), tarc);
3122 E1000_WRITE_REG(hw, E1000_TARC(0), tarc);
3125 if (sc->tx_int_delay.value > 0)
3126 sc->txd_cmd |= E1000_TXD_CMD_IDE;
3128 /* Program the Transmit Control Register */
3129 tctl = E1000_READ_REG(hw, E1000_TCTL);
3130 tctl &= ~E1000_TCTL_CT;
3131 tctl |= (E1000_TCTL_PSP | E1000_TCTL_RTLC | E1000_TCTL_EN |
3132 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT));
3134 if (hw->mac.type >= e1000_82571)
3135 tctl |= E1000_TCTL_MULR;
3137 /* This write will effectively turn on the transmit unit. */
3138 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
3140 /* SPT and KBL errata workarounds */
3141 if (hw->mac.type == e1000_pch_spt) {
3143 reg = E1000_READ_REG(hw, E1000_IOSFPC);
3144 reg |= E1000_RCTL_RDMTS_HEX;
3145 E1000_WRITE_REG(hw, E1000_IOSFPC, reg);
3146 /* i218-i219 Specification Update 1.5.4.5 */
3147 reg = E1000_READ_REG(hw, E1000_TARC(0));
3148 reg &= ~E1000_TARC0_CB_MULTIQ_3_REQ;
3149 reg |= E1000_TARC0_CB_MULTIQ_2_REQ;
3150 E1000_WRITE_REG(hw, E1000_TARC(0), reg);
3154 /*********************************************************************
3156 * Enable receive unit.
3158 **********************************************************************/
3159 #define BSIZEPKT_ROUNDUP ((1<<E1000_SRRCTL_BSIZEPKT_SHIFT)-1)
3162 em_initialize_receive_unit(if_ctx_t ctx)
3164 struct e1000_softc *sc = iflib_get_softc(ctx);
3165 if_softc_ctx_t scctx = sc->shared;
3166 struct ifnet *ifp = iflib_get_ifp(ctx);
3167 struct e1000_hw *hw = &sc->hw;
3168 struct em_rx_queue *que;
3170 uint32_t rctl, rxcsum;
3172 INIT_DEBUGOUT("em_initialize_receive_units: begin");
3175 * Make sure receives are disabled while setting
3176 * up the descriptor ring
3178 rctl = E1000_READ_REG(hw, E1000_RCTL);
3179 /* Do not disable if ever enabled on this hardware */
3180 if ((hw->mac.type != e1000_82574) && (hw->mac.type != e1000_82583))
3181 E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
3183 /* Setup the Receive Control Register */
3184 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3185 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
3186 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
3187 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3189 /* Do not store bad packets */
3190 rctl &= ~E1000_RCTL_SBP;
3192 /* Enable Long Packet receive */
3193 if (if_getmtu(ifp) > ETHERMTU)
3194 rctl |= E1000_RCTL_LPE;
3196 rctl &= ~E1000_RCTL_LPE;
3199 if (!em_disable_crc_stripping)
3200 rctl |= E1000_RCTL_SECRC;
3202 if (hw->mac.type >= e1000_82540) {
3203 E1000_WRITE_REG(hw, E1000_RADV,
3204 sc->rx_abs_int_delay.value);
3207 * Set the interrupt throttling rate. Value is calculated
3208 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns)
3210 E1000_WRITE_REG(hw, E1000_ITR, DEFAULT_ITR);
3212 E1000_WRITE_REG(hw, E1000_RDTR, sc->rx_int_delay.value);
3214 if (hw->mac.type >= em_mac_min) {
3216 /* Use extended rx descriptor formats */
3217 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3218 rfctl |= E1000_RFCTL_EXTEN;
3221 * When using MSI-X interrupts we need to throttle
3222 * using the EITR register (82574 only)
3224 if (hw->mac.type == e1000_82574) {
3225 for (int i = 0; i < 4; i++)
3226 E1000_WRITE_REG(hw, E1000_EITR_82574(i),
3228 /* Disable accelerated acknowledge */
3229 rfctl |= E1000_RFCTL_ACK_DIS;
3231 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3234 /* Set up L3 and L4 csum Rx descriptor offloads */
3235 rxcsum = E1000_READ_REG(hw, E1000_RXCSUM);
3236 if (scctx->isc_capenable & IFCAP_RXCSUM) {
3237 rxcsum |= E1000_RXCSUM_TUOFL | E1000_RXCSUM_IPOFL;
3238 if (hw->mac.type > e1000_82575)
3239 rxcsum |= E1000_RXCSUM_CRCOFL;
3240 else if (hw->mac.type < em_mac_min &&
3241 scctx->isc_capenable & IFCAP_HWCSUM_IPV6)
3242 rxcsum |= E1000_RXCSUM_IPV6OFL;
3244 rxcsum &= ~(E1000_RXCSUM_IPOFL | E1000_RXCSUM_TUOFL);
3245 if (hw->mac.type > e1000_82575)
3246 rxcsum &= ~E1000_RXCSUM_CRCOFL;
3247 else if (hw->mac.type < em_mac_min)
3248 rxcsum &= ~E1000_RXCSUM_IPV6OFL;
3251 if (sc->rx_num_queues > 1) {
3252 /* RSS hash needed in the Rx descriptor */
3253 rxcsum |= E1000_RXCSUM_PCSD;
3255 if (hw->mac.type >= igb_mac_min)
3256 igb_initialize_rss_mapping(sc);
3258 em_initialize_rss_mapping(sc);
3260 E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum);
3263 * XXX TEMPORARY WORKAROUND: on some systems with 82573
3264 * long latencies are observed, like Lenovo X60. This
3265 * change eliminates the problem, but since having positive
3266 * values in RDTR is a known source of problems on other
3267 * platforms another solution is being sought.
3269 if (hw->mac.type == e1000_82573)
3270 E1000_WRITE_REG(hw, E1000_RDTR, 0x20);
3272 for (i = 0, que = sc->rx_queues; i < sc->rx_num_queues; i++, que++) {
3273 struct rx_ring *rxr = &que->rxr;
3274 /* Setup the Base and Length of the Rx Descriptor Ring */
3275 u64 bus_addr = rxr->rx_paddr;
3277 u32 rdt = sc->rx_num_queues -1; /* default */
3280 E1000_WRITE_REG(hw, E1000_RDLEN(i),
3281 scctx->isc_nrxd[0] * sizeof(union e1000_rx_desc_extended));
3282 E1000_WRITE_REG(hw, E1000_RDBAH(i), (u32)(bus_addr >> 32));
3283 E1000_WRITE_REG(hw, E1000_RDBAL(i), (u32)bus_addr);
3284 /* Setup the Head and Tail Descriptor Pointers */
3285 E1000_WRITE_REG(hw, E1000_RDH(i), 0);
3286 E1000_WRITE_REG(hw, E1000_RDT(i), 0);
3290 * Set PTHRESH for improved jumbo performance
3291 * According to 10.2.5.11 of Intel 82574 Datasheet,
3292 * RXDCTL(1) is written whenever RXDCTL(0) is written.
3293 * Only write to RXDCTL(1) if there is a need for different
3296 if ((hw->mac.type == e1000_ich9lan || hw->mac.type == e1000_pch2lan ||
3297 hw->mac.type == e1000_ich10lan) && if_getmtu(ifp) > ETHERMTU) {
3298 u32 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(0));
3299 E1000_WRITE_REG(hw, E1000_RXDCTL(0), rxdctl | 3);
3300 } else if (hw->mac.type == e1000_82574) {
3301 for (int i = 0; i < sc->rx_num_queues; i++) {
3302 u32 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i));
3303 rxdctl |= 0x20; /* PTHRESH */
3304 rxdctl |= 4 << 8; /* HTHRESH */
3305 rxdctl |= 4 << 16;/* WTHRESH */
3306 rxdctl |= 1 << 24; /* Switch to granularity */
3307 E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl);
3309 } else if (hw->mac.type >= igb_mac_min) {
3310 u32 psize, srrctl = 0;
3312 if (if_getmtu(ifp) > ETHERMTU) {
3313 psize = scctx->isc_max_frame_size;
3314 /* are we on a vlan? */
3315 if (ifp->if_vlantrunk != NULL)
3316 psize += VLAN_TAG_SIZE;
3319 e1000_rlpml_set_vf(hw, psize);
3321 E1000_WRITE_REG(hw, E1000_RLPML, psize);
3324 /* Set maximum packet buffer len */
3325 srrctl |= (sc->rx_mbuf_sz + BSIZEPKT_ROUNDUP) >>
3326 E1000_SRRCTL_BSIZEPKT_SHIFT;
3329 * If TX flow control is disabled and there's >1 queue defined,
3332 * This drops frames rather than hanging the RX MAC for all queues.
3334 if ((sc->rx_num_queues > 1) &&
3335 (sc->fc == e1000_fc_none ||
3336 sc->fc == e1000_fc_rx_pause)) {
3337 srrctl |= E1000_SRRCTL_DROP_EN;
3339 /* Setup the Base and Length of the Rx Descriptor Rings */
3340 for (i = 0, que = sc->rx_queues; i < sc->rx_num_queues; i++, que++) {
3341 struct rx_ring *rxr = &que->rxr;
3342 u64 bus_addr = rxr->rx_paddr;
3346 /* Configure for header split? -- ignore for now */
3347 rxr->hdr_split = igb_header_split;
3349 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
3352 E1000_WRITE_REG(hw, E1000_RDLEN(i),
3353 scctx->isc_nrxd[0] * sizeof(struct e1000_rx_desc));
3354 E1000_WRITE_REG(hw, E1000_RDBAH(i),
3355 (uint32_t)(bus_addr >> 32));
3356 E1000_WRITE_REG(hw, E1000_RDBAL(i),
3357 (uint32_t)bus_addr);
3358 E1000_WRITE_REG(hw, E1000_SRRCTL(i), srrctl);
3359 /* Enable this Queue */
3360 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i));
3361 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
3362 rxdctl &= 0xFFF00000;
3363 rxdctl |= IGB_RX_PTHRESH;
3364 rxdctl |= IGB_RX_HTHRESH << 8;
3365 rxdctl |= IGB_RX_WTHRESH << 16;
3366 E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl);
3368 } else if (hw->mac.type >= e1000_pch2lan) {
3369 if (if_getmtu(ifp) > ETHERMTU)
3370 e1000_lv_jumbo_workaround_ich8lan(hw, true);
3372 e1000_lv_jumbo_workaround_ich8lan(hw, false);
3375 /* Make sure VLAN Filters are off */
3376 rctl &= ~E1000_RCTL_VFE;
3378 /* Set up packet buffer size, overridden by per queue srrctl on igb */
3379 if (hw->mac.type < igb_mac_min) {
3380 if (sc->rx_mbuf_sz > 2048 && sc->rx_mbuf_sz <= 4096)
3381 rctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX;
3382 else if (sc->rx_mbuf_sz > 4096 && sc->rx_mbuf_sz <= 8192)
3383 rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX;
3384 else if (sc->rx_mbuf_sz > 8192)
3385 rctl |= E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX;
3387 rctl |= E1000_RCTL_SZ_2048;
3388 rctl &= ~E1000_RCTL_BSEX;
3391 rctl |= E1000_RCTL_SZ_2048;
3394 * rctl bits 11:10 are as follows
3398 * and should be 00 on all of the above
3400 rctl &= ~0x00000C00;
3402 /* Write out the settings */
3403 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3409 em_if_vlan_register(if_ctx_t ctx, u16 vtag)
3411 struct e1000_softc *sc = iflib_get_softc(ctx);
3414 index = (vtag >> 5) & 0x7F;
3416 sc->shadow_vfta[index] |= (1 << bit);
3418 em_if_vlan_filter_write(sc);
3422 em_if_vlan_unregister(if_ctx_t ctx, u16 vtag)
3424 struct e1000_softc *sc = iflib_get_softc(ctx);
3427 index = (vtag >> 5) & 0x7F;
3429 sc->shadow_vfta[index] &= ~(1 << bit);
3431 em_if_vlan_filter_write(sc);
3435 em_if_vlan_filter_capable(struct e1000_softc *sc)
3437 if_softc_ctx_t scctx = sc->shared;
3439 if ((scctx->isc_capenable & IFCAP_VLAN_HWFILTER) &&
3440 !em_disable_crc_stripping)
3447 em_if_vlan_filter_used(struct e1000_softc *sc)
3449 if (!em_if_vlan_filter_capable(sc))
3452 for (int i = 0; i < EM_VFTA_SIZE; i++)
3453 if (sc->shadow_vfta[i] != 0)
3460 em_if_vlan_filter_enable(struct e1000_softc *sc)
3462 struct e1000_hw *hw = &sc->hw;
3465 reg = E1000_READ_REG(hw, E1000_RCTL);
3466 reg &= ~E1000_RCTL_CFIEN;
3467 reg |= E1000_RCTL_VFE;
3468 E1000_WRITE_REG(hw, E1000_RCTL, reg);
3472 em_if_vlan_filter_disable(struct e1000_softc *sc)
3474 struct e1000_hw *hw = &sc->hw;
3477 reg = E1000_READ_REG(hw, E1000_RCTL);
3478 reg &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
3479 E1000_WRITE_REG(hw, E1000_RCTL, reg);
3483 em_if_vlan_filter_write(struct e1000_softc *sc)
3485 struct e1000_hw *hw = &sc->hw;
3490 /* Disable interrupts for lem-class devices during the filter change */
3491 if (hw->mac.type < em_mac_min)
3492 em_if_intr_disable(sc->ctx);
3494 for (int i = 0; i < EM_VFTA_SIZE; i++)
3495 if (sc->shadow_vfta[i] != 0) {
3496 /* XXXKB: incomplete VF support, we return early above */
3498 e1000_vfta_set_vf(hw, sc->shadow_vfta[i], true);
3500 e1000_write_vfta(hw, i, sc->shadow_vfta[i]);
3503 /* Re-enable interrupts for lem-class devices */
3504 if (hw->mac.type < em_mac_min)
3505 em_if_intr_enable(sc->ctx);
3509 em_setup_vlan_hw_support(struct e1000_softc *sc)
3511 if_softc_ctx_t scctx = sc->shared;
3512 struct e1000_hw *hw = &sc->hw;
3515 /* XXXKB: Return early if we are a VF until VF decap and filter management
3516 * is ready and tested.
3521 if (scctx->isc_capenable & IFCAP_VLAN_HWTAGGING &&
3522 !em_disable_crc_stripping) {
3523 reg = E1000_READ_REG(hw, E1000_CTRL);
3524 reg |= E1000_CTRL_VME;
3525 E1000_WRITE_REG(hw, E1000_CTRL, reg);
3527 reg = E1000_READ_REG(hw, E1000_CTRL);
3528 reg &= ~E1000_CTRL_VME;
3529 E1000_WRITE_REG(hw, E1000_CTRL, reg);
3532 /* If we aren't doing HW filtering, we're done */
3533 if (!em_if_vlan_filter_capable(sc)) {
3534 em_if_vlan_filter_disable(sc);
3539 * A soft reset zero's out the VFTA, so
3540 * we need to repopulate it now.
3542 em_if_vlan_filter_write(sc);
3544 /* Enable the Filter Table */
3545 em_if_vlan_filter_enable(sc);
3549 em_if_intr_enable(if_ctx_t ctx)
3551 struct e1000_softc *sc = iflib_get_softc(ctx);
3552 struct e1000_hw *hw = &sc->hw;
3553 u32 ims_mask = IMS_ENABLE_MASK;
3555 if (sc->intr_type == IFLIB_INTR_MSIX) {
3556 E1000_WRITE_REG(hw, EM_EIAC, sc->ims);
3557 ims_mask |= sc->ims;
3559 E1000_WRITE_REG(hw, E1000_IMS, ims_mask);
3560 E1000_WRITE_FLUSH(hw);
3564 em_if_intr_disable(if_ctx_t ctx)
3566 struct e1000_softc *sc = iflib_get_softc(ctx);
3567 struct e1000_hw *hw = &sc->hw;
3569 if (sc->intr_type == IFLIB_INTR_MSIX)
3570 E1000_WRITE_REG(hw, EM_EIAC, 0);
3571 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
3572 E1000_WRITE_FLUSH(hw);
3576 igb_if_intr_enable(if_ctx_t ctx)
3578 struct e1000_softc *sc = iflib_get_softc(ctx);
3579 struct e1000_hw *hw = &sc->hw;
3582 if (__predict_true(sc->intr_type == IFLIB_INTR_MSIX)) {
3583 mask = (sc->que_mask | sc->link_mask);
3584 E1000_WRITE_REG(hw, E1000_EIAC, mask);
3585 E1000_WRITE_REG(hw, E1000_EIAM, mask);
3586 E1000_WRITE_REG(hw, E1000_EIMS, mask);
3587 E1000_WRITE_REG(hw, E1000_IMS, E1000_IMS_LSC);
3589 E1000_WRITE_REG(hw, E1000_IMS, IMS_ENABLE_MASK);
3590 E1000_WRITE_FLUSH(hw);
3594 igb_if_intr_disable(if_ctx_t ctx)
3596 struct e1000_softc *sc = iflib_get_softc(ctx);
3597 struct e1000_hw *hw = &sc->hw;
3599 if (__predict_true(sc->intr_type == IFLIB_INTR_MSIX)) {
3600 E1000_WRITE_REG(hw, E1000_EIMC, 0xffffffff);
3601 E1000_WRITE_REG(hw, E1000_EIAC, 0);
3603 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
3604 E1000_WRITE_FLUSH(hw);
3608 * Bit of a misnomer, what this really means is
3609 * to enable OS management of the system... aka
3610 * to disable special hardware management features
3613 em_init_manageability(struct e1000_softc *sc)
3615 /* A shared code workaround */
3616 #define E1000_82542_MANC2H E1000_MANC2H
3617 if (sc->has_manage) {
3618 int manc2h = E1000_READ_REG(&sc->hw, E1000_MANC2H);
3619 int manc = E1000_READ_REG(&sc->hw, E1000_MANC);
3621 /* disable hardware interception of ARP */
3622 manc &= ~(E1000_MANC_ARP_EN);
3624 /* enable receiving management packets to the host */
3625 manc |= E1000_MANC_EN_MNG2HOST;
3626 #define E1000_MNG2HOST_PORT_623 (1 << 5)
3627 #define E1000_MNG2HOST_PORT_664 (1 << 6)
3628 manc2h |= E1000_MNG2HOST_PORT_623;
3629 manc2h |= E1000_MNG2HOST_PORT_664;
3630 E1000_WRITE_REG(&sc->hw, E1000_MANC2H, manc2h);
3631 E1000_WRITE_REG(&sc->hw, E1000_MANC, manc);
3636 * Give control back to hardware management
3637 * controller if there is one.
3640 em_release_manageability(struct e1000_softc *sc)
3642 if (sc->has_manage) {
3643 int manc = E1000_READ_REG(&sc->hw, E1000_MANC);
3645 /* re-enable hardware interception of ARP */
3646 manc |= E1000_MANC_ARP_EN;
3647 manc &= ~E1000_MANC_EN_MNG2HOST;
3649 E1000_WRITE_REG(&sc->hw, E1000_MANC, manc);
3654 * em_get_hw_control sets the {CTRL_EXT|FWSM}:DRV_LOAD bit.
3655 * For ASF and Pass Through versions of f/w this means
3656 * that the driver is loaded. For AMT version type f/w
3657 * this means that the network i/f is open.
3660 em_get_hw_control(struct e1000_softc *sc)
3667 if (sc->hw.mac.type == e1000_82573) {
3668 swsm = E1000_READ_REG(&sc->hw, E1000_SWSM);
3669 E1000_WRITE_REG(&sc->hw, E1000_SWSM,
3670 swsm | E1000_SWSM_DRV_LOAD);
3674 ctrl_ext = E1000_READ_REG(&sc->hw, E1000_CTRL_EXT);
3675 E1000_WRITE_REG(&sc->hw, E1000_CTRL_EXT,
3676 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
3680 * em_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
3681 * For ASF and Pass Through versions of f/w this means that
3682 * the driver is no longer loaded. For AMT versions of the
3683 * f/w this means that the network i/f is closed.
3686 em_release_hw_control(struct e1000_softc *sc)
3690 if (!sc->has_manage)
3693 if (sc->hw.mac.type == e1000_82573) {
3694 swsm = E1000_READ_REG(&sc->hw, E1000_SWSM);
3695 E1000_WRITE_REG(&sc->hw, E1000_SWSM,
3696 swsm & ~E1000_SWSM_DRV_LOAD);
3700 ctrl_ext = E1000_READ_REG(&sc->hw, E1000_CTRL_EXT);
3701 E1000_WRITE_REG(&sc->hw, E1000_CTRL_EXT,
3702 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
3707 em_is_valid_ether_addr(u8 *addr)
3709 char zero_addr[6] = { 0, 0, 0, 0, 0, 0 };
3711 if ((addr[0] & 1) || (!bcmp(addr, zero_addr, ETHER_ADDR_LEN))) {
3719 ** Parse the interface capabilities with regard
3720 ** to both system management and wake-on-lan for
3724 em_get_wakeup(if_ctx_t ctx)
3726 struct e1000_softc *sc = iflib_get_softc(ctx);
3727 device_t dev = iflib_get_dev(ctx);
3728 u16 eeprom_data = 0, device_id, apme_mask;
3730 sc->has_manage = e1000_enable_mng_pass_thru(&sc->hw);
3731 apme_mask = EM_EEPROM_APME;
3733 switch (sc->hw.mac.type) {
3738 e1000_read_nvm(&sc->hw,
3739 NVM_INIT_CONTROL2_REG, 1, &eeprom_data);
3740 apme_mask = EM_82544_APME;
3743 case e1000_82546_rev_3:
3744 if (sc->hw.bus.func == 1) {
3745 e1000_read_nvm(&sc->hw,
3746 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
3749 e1000_read_nvm(&sc->hw,
3750 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
3758 case e1000_80003es2lan:
3759 if (sc->hw.bus.func == 1) {
3760 e1000_read_nvm(&sc->hw,
3761 NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
3764 e1000_read_nvm(&sc->hw,
3765 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
3769 case e1000_ich10lan:
3774 case e1000_82575: /* listing all igb devices */
3782 case e1000_vfadapt_i350:
3783 apme_mask = E1000_WUC_APME;
3785 eeprom_data = E1000_READ_REG(&sc->hw, E1000_WUC);
3788 e1000_read_nvm(&sc->hw,
3789 NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
3792 if (eeprom_data & apme_mask)
3793 sc->wol = (E1000_WUFC_MAG | E1000_WUFC_MC);
3795 * We have the eeprom settings, now apply the special cases
3796 * where the eeprom may be wrong or the board won't support
3797 * wake on lan on a particular port
3799 device_id = pci_get_device(dev);
3800 switch (device_id) {
3801 case E1000_DEV_ID_82546GB_PCIE:
3804 case E1000_DEV_ID_82546EB_FIBER:
3805 case E1000_DEV_ID_82546GB_FIBER:
3806 /* Wake events only supported on port A for dual fiber
3807 * regardless of eeprom setting */
3808 if (E1000_READ_REG(&sc->hw, E1000_STATUS) &
3809 E1000_STATUS_FUNC_1)
3812 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
3813 /* if quad port adapter, disable WoL on all but port A */
3814 if (global_quad_port_a != 0)
3816 /* Reset for multiple quad port adapters */
3817 if (++global_quad_port_a == 4)
3818 global_quad_port_a = 0;
3820 case E1000_DEV_ID_82571EB_FIBER:
3821 /* Wake events only supported on port A for dual fiber
3822 * regardless of eeprom setting */
3823 if (E1000_READ_REG(&sc->hw, E1000_STATUS) &
3824 E1000_STATUS_FUNC_1)
3827 case E1000_DEV_ID_82571EB_QUAD_COPPER:
3828 case E1000_DEV_ID_82571EB_QUAD_FIBER:
3829 case E1000_DEV_ID_82571EB_QUAD_COPPER_LP:
3830 /* if quad port adapter, disable WoL on all but port A */
3831 if (global_quad_port_a != 0)
3833 /* Reset for multiple quad port adapters */
3834 if (++global_quad_port_a == 4)
3835 global_quad_port_a = 0;
3843 * Enable PCI Wake On Lan capability
3846 em_enable_wakeup(if_ctx_t ctx)
3848 struct e1000_softc *sc = iflib_get_softc(ctx);
3849 device_t dev = iflib_get_dev(ctx);
3850 if_t ifp = iflib_get_ifp(ctx);
3852 u32 pmc, ctrl, ctrl_ext, rctl;
3855 if (pci_find_cap(dev, PCIY_PMG, &pmc) != 0)
3859 * Determine type of Wakeup: note that wol
3860 * is set with all bits on by default.
3862 if ((if_getcapenable(ifp) & IFCAP_WOL_MAGIC) == 0)
3863 sc->wol &= ~E1000_WUFC_MAG;
3865 if ((if_getcapenable(ifp) & IFCAP_WOL_UCAST) == 0)
3866 sc->wol &= ~E1000_WUFC_EX;
3868 if ((if_getcapenable(ifp) & IFCAP_WOL_MCAST) == 0)
3869 sc->wol &= ~E1000_WUFC_MC;
3871 rctl = E1000_READ_REG(&sc->hw, E1000_RCTL);
3872 rctl |= E1000_RCTL_MPE;
3873 E1000_WRITE_REG(&sc->hw, E1000_RCTL, rctl);
3876 if (!(sc->wol & (E1000_WUFC_EX | E1000_WUFC_MAG | E1000_WUFC_MC)))
3879 /* Advertise the wakeup capability */
3880 ctrl = E1000_READ_REG(&sc->hw, E1000_CTRL);
3881 ctrl |= (E1000_CTRL_SWDPIN2 | E1000_CTRL_SWDPIN3);
3882 E1000_WRITE_REG(&sc->hw, E1000_CTRL, ctrl);
3884 /* Keep the laser running on Fiber adapters */
3885 if (sc->hw.phy.media_type == e1000_media_type_fiber ||
3886 sc->hw.phy.media_type == e1000_media_type_internal_serdes) {
3887 ctrl_ext = E1000_READ_REG(&sc->hw, E1000_CTRL_EXT);
3888 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
3889 E1000_WRITE_REG(&sc->hw, E1000_CTRL_EXT, ctrl_ext);
3892 if ((sc->hw.mac.type == e1000_ich8lan) ||
3893 (sc->hw.mac.type == e1000_pchlan) ||
3894 (sc->hw.mac.type == e1000_ich9lan) ||
3895 (sc->hw.mac.type == e1000_ich10lan))
3896 e1000_suspend_workarounds_ich8lan(&sc->hw);
3898 if ( sc->hw.mac.type >= e1000_pchlan) {
3899 error = em_enable_phy_wakeup(sc);
3903 /* Enable wakeup by the MAC */
3904 E1000_WRITE_REG(&sc->hw, E1000_WUC, E1000_WUC_PME_EN);
3905 E1000_WRITE_REG(&sc->hw, E1000_WUFC, sc->wol);
3908 if (sc->hw.phy.type == e1000_phy_igp_3)
3909 e1000_igp3_phy_powerdown_workaround_ich8lan(&sc->hw);
3912 status = pci_read_config(dev, pmc + PCIR_POWER_STATUS, 2);
3913 status &= ~(PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE);
3914 if (!error && (if_getcapenable(ifp) & IFCAP_WOL))
3915 status |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE;
3916 pci_write_config(dev, pmc + PCIR_POWER_STATUS, status, 2);
3922 * WOL in the newer chipset interfaces (pchlan)
3923 * require thing to be copied into the phy
3926 em_enable_phy_wakeup(struct e1000_softc *sc)
3928 struct e1000_hw *hw = &sc->hw;
3932 /* copy MAC RARs to PHY RARs */
3933 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
3935 /* copy MAC MTA to PHY MTA */
3936 for (int i = 0; i < hw->mac.mta_reg_count; i++) {
3937 mreg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
3938 e1000_write_phy_reg(hw, BM_MTA(i), (u16)(mreg & 0xFFFF));
3939 e1000_write_phy_reg(hw, BM_MTA(i) + 1,
3940 (u16)((mreg >> 16) & 0xFFFF));
3943 /* configure PHY Rx Control register */
3944 e1000_read_phy_reg(hw, BM_RCTL, &preg);
3945 mreg = E1000_READ_REG(hw, E1000_RCTL);
3946 if (mreg & E1000_RCTL_UPE)
3947 preg |= BM_RCTL_UPE;
3948 if (mreg & E1000_RCTL_MPE)
3949 preg |= BM_RCTL_MPE;
3950 preg &= ~(BM_RCTL_MO_MASK);
3951 if (mreg & E1000_RCTL_MO_3)
3952 preg |= (((mreg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
3953 << BM_RCTL_MO_SHIFT);
3954 if (mreg & E1000_RCTL_BAM)
3955 preg |= BM_RCTL_BAM;
3956 if (mreg & E1000_RCTL_PMCF)
3957 preg |= BM_RCTL_PMCF;
3958 mreg = E1000_READ_REG(hw, E1000_CTRL);
3959 if (mreg & E1000_CTRL_RFCE)
3960 preg |= BM_RCTL_RFCE;
3961 e1000_write_phy_reg(hw, BM_RCTL, preg);
3963 /* enable PHY wakeup in MAC register */
3964 E1000_WRITE_REG(hw, E1000_WUC,
3965 E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN | E1000_WUC_APME);
3966 E1000_WRITE_REG(hw, E1000_WUFC, sc->wol);
3968 /* configure and enable PHY wakeup in PHY registers */
3969 e1000_write_phy_reg(hw, BM_WUFC, sc->wol);
3970 e1000_write_phy_reg(hw, BM_WUC, E1000_WUC_PME_EN);
3972 /* activate PHY wakeup */
3973 ret = hw->phy.ops.acquire(hw);
3975 printf("Could not acquire PHY\n");
3978 e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3979 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
3980 ret = e1000_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &preg);
3982 printf("Could not read PHY page 769\n");
3985 preg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
3986 ret = e1000_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, preg);
3988 printf("Could not set PHY Host Wakeup bit\n");
3990 hw->phy.ops.release(hw);
3996 em_if_led_func(if_ctx_t ctx, int onoff)
3998 struct e1000_softc *sc = iflib_get_softc(ctx);
4001 e1000_setup_led(&sc->hw);
4002 e1000_led_on(&sc->hw);
4004 e1000_led_off(&sc->hw);
4005 e1000_cleanup_led(&sc->hw);
4010 * Disable the L0S and L1 LINK states
4013 em_disable_aspm(struct e1000_softc *sc)
4016 u16 link_cap,link_ctrl;
4017 device_t dev = sc->dev;
4019 switch (sc->hw.mac.type) {
4027 if (pci_find_cap(dev, PCIY_EXPRESS, &base) != 0)
4029 reg = base + PCIER_LINK_CAP;
4030 link_cap = pci_read_config(dev, reg, 2);
4031 if ((link_cap & PCIEM_LINK_CAP_ASPM) == 0)
4033 reg = base + PCIER_LINK_CTL;
4034 link_ctrl = pci_read_config(dev, reg, 2);
4035 link_ctrl &= ~PCIEM_LINK_CTL_ASPMC;
4036 pci_write_config(dev, reg, link_ctrl, 2);
4040 /**********************************************************************
4042 * Update the board statistics counters.
4044 **********************************************************************/
4046 em_update_stats_counters(struct e1000_softc *sc)
4048 u64 prev_xoffrxc = sc->stats.xoffrxc;
4050 if(sc->hw.phy.media_type == e1000_media_type_copper ||
4051 (E1000_READ_REG(&sc->hw, E1000_STATUS) & E1000_STATUS_LU)) {
4052 sc->stats.symerrs += E1000_READ_REG(&sc->hw, E1000_SYMERRS);
4053 sc->stats.sec += E1000_READ_REG(&sc->hw, E1000_SEC);
4055 sc->stats.crcerrs += E1000_READ_REG(&sc->hw, E1000_CRCERRS);
4056 sc->stats.mpc += E1000_READ_REG(&sc->hw, E1000_MPC);
4057 sc->stats.scc += E1000_READ_REG(&sc->hw, E1000_SCC);
4058 sc->stats.ecol += E1000_READ_REG(&sc->hw, E1000_ECOL);
4060 sc->stats.mcc += E1000_READ_REG(&sc->hw, E1000_MCC);
4061 sc->stats.latecol += E1000_READ_REG(&sc->hw, E1000_LATECOL);
4062 sc->stats.colc += E1000_READ_REG(&sc->hw, E1000_COLC);
4063 sc->stats.dc += E1000_READ_REG(&sc->hw, E1000_DC);
4064 sc->stats.rlec += E1000_READ_REG(&sc->hw, E1000_RLEC);
4065 sc->stats.xonrxc += E1000_READ_REG(&sc->hw, E1000_XONRXC);
4066 sc->stats.xontxc += E1000_READ_REG(&sc->hw, E1000_XONTXC);
4067 sc->stats.xoffrxc += E1000_READ_REG(&sc->hw, E1000_XOFFRXC);
4069 ** For watchdog management we need to know if we have been
4070 ** paused during the last interval, so capture that here.
4072 if (sc->stats.xoffrxc != prev_xoffrxc)
4073 sc->shared->isc_pause_frames = 1;
4074 sc->stats.xofftxc += E1000_READ_REG(&sc->hw, E1000_XOFFTXC);
4075 sc->stats.fcruc += E1000_READ_REG(&sc->hw, E1000_FCRUC);
4076 sc->stats.prc64 += E1000_READ_REG(&sc->hw, E1000_PRC64);
4077 sc->stats.prc127 += E1000_READ_REG(&sc->hw, E1000_PRC127);
4078 sc->stats.prc255 += E1000_READ_REG(&sc->hw, E1000_PRC255);
4079 sc->stats.prc511 += E1000_READ_REG(&sc->hw, E1000_PRC511);
4080 sc->stats.prc1023 += E1000_READ_REG(&sc->hw, E1000_PRC1023);
4081 sc->stats.prc1522 += E1000_READ_REG(&sc->hw, E1000_PRC1522);
4082 sc->stats.gprc += E1000_READ_REG(&sc->hw, E1000_GPRC);
4083 sc->stats.bprc += E1000_READ_REG(&sc->hw, E1000_BPRC);
4084 sc->stats.mprc += E1000_READ_REG(&sc->hw, E1000_MPRC);
4085 sc->stats.gptc += E1000_READ_REG(&sc->hw, E1000_GPTC);
4087 /* For the 64-bit byte counters the low dword must be read first. */
4088 /* Both registers clear on the read of the high dword */
4090 sc->stats.gorc += E1000_READ_REG(&sc->hw, E1000_GORCL) +
4091 ((u64)E1000_READ_REG(&sc->hw, E1000_GORCH) << 32);
4092 sc->stats.gotc += E1000_READ_REG(&sc->hw, E1000_GOTCL) +
4093 ((u64)E1000_READ_REG(&sc->hw, E1000_GOTCH) << 32);
4095 sc->stats.rnbc += E1000_READ_REG(&sc->hw, E1000_RNBC);
4096 sc->stats.ruc += E1000_READ_REG(&sc->hw, E1000_RUC);
4097 sc->stats.rfc += E1000_READ_REG(&sc->hw, E1000_RFC);
4098 sc->stats.roc += E1000_READ_REG(&sc->hw, E1000_ROC);
4099 sc->stats.rjc += E1000_READ_REG(&sc->hw, E1000_RJC);
4101 sc->stats.tor += E1000_READ_REG(&sc->hw, E1000_TORH);
4102 sc->stats.tot += E1000_READ_REG(&sc->hw, E1000_TOTH);
4104 sc->stats.tpr += E1000_READ_REG(&sc->hw, E1000_TPR);
4105 sc->stats.tpt += E1000_READ_REG(&sc->hw, E1000_TPT);
4106 sc->stats.ptc64 += E1000_READ_REG(&sc->hw, E1000_PTC64);
4107 sc->stats.ptc127 += E1000_READ_REG(&sc->hw, E1000_PTC127);
4108 sc->stats.ptc255 += E1000_READ_REG(&sc->hw, E1000_PTC255);
4109 sc->stats.ptc511 += E1000_READ_REG(&sc->hw, E1000_PTC511);
4110 sc->stats.ptc1023 += E1000_READ_REG(&sc->hw, E1000_PTC1023);
4111 sc->stats.ptc1522 += E1000_READ_REG(&sc->hw, E1000_PTC1522);
4112 sc->stats.mptc += E1000_READ_REG(&sc->hw, E1000_MPTC);
4113 sc->stats.bptc += E1000_READ_REG(&sc->hw, E1000_BPTC);
4115 /* Interrupt Counts */
4117 sc->stats.iac += E1000_READ_REG(&sc->hw, E1000_IAC);
4118 sc->stats.icrxptc += E1000_READ_REG(&sc->hw, E1000_ICRXPTC);
4119 sc->stats.icrxatc += E1000_READ_REG(&sc->hw, E1000_ICRXATC);
4120 sc->stats.ictxptc += E1000_READ_REG(&sc->hw, E1000_ICTXPTC);
4121 sc->stats.ictxatc += E1000_READ_REG(&sc->hw, E1000_ICTXATC);
4122 sc->stats.ictxqec += E1000_READ_REG(&sc->hw, E1000_ICTXQEC);
4123 sc->stats.ictxqmtc += E1000_READ_REG(&sc->hw, E1000_ICTXQMTC);
4124 sc->stats.icrxdmtc += E1000_READ_REG(&sc->hw, E1000_ICRXDMTC);
4125 sc->stats.icrxoc += E1000_READ_REG(&sc->hw, E1000_ICRXOC);
4127 if (sc->hw.mac.type >= e1000_82543) {
4128 sc->stats.algnerrc +=
4129 E1000_READ_REG(&sc->hw, E1000_ALGNERRC);
4131 E1000_READ_REG(&sc->hw, E1000_RXERRC);
4133 E1000_READ_REG(&sc->hw, E1000_TNCRS);
4134 sc->stats.cexterr +=
4135 E1000_READ_REG(&sc->hw, E1000_CEXTERR);
4137 E1000_READ_REG(&sc->hw, E1000_TSCTC);
4139 E1000_READ_REG(&sc->hw, E1000_TSCTFC);
4144 em_if_get_counter(if_ctx_t ctx, ift_counter cnt)
4146 struct e1000_softc *sc = iflib_get_softc(ctx);
4147 struct ifnet *ifp = iflib_get_ifp(ctx);
4150 case IFCOUNTER_COLLISIONS:
4151 return (sc->stats.colc);
4152 case IFCOUNTER_IERRORS:
4153 return (sc->dropped_pkts + sc->stats.rxerrc +
4154 sc->stats.crcerrs + sc->stats.algnerrc +
4155 sc->stats.ruc + sc->stats.roc +
4156 sc->stats.mpc + sc->stats.cexterr);
4157 case IFCOUNTER_OERRORS:
4158 return (sc->stats.ecol + sc->stats.latecol +
4159 sc->watchdog_events);
4161 return (if_get_counter_default(ifp, cnt));
4165 /* em_if_needs_restart - Tell iflib when the driver needs to be reinitialized
4166 * @ctx: iflib context
4167 * @event: event code to check
4169 * Defaults to returning true for unknown events.
4171 * @returns true if iflib needs to reinit the interface
4174 em_if_needs_restart(if_ctx_t ctx __unused, enum iflib_restart_event event)
4177 case IFLIB_RESTART_VLAN_CONFIG:
4184 /* Export a single 32-bit register via a read-only sysctl. */
4186 em_sysctl_reg_handler(SYSCTL_HANDLER_ARGS)
4188 struct e1000_softc *sc;
4191 sc = oidp->oid_arg1;
4192 val = E1000_READ_REG(&sc->hw, oidp->oid_arg2);
4193 return (sysctl_handle_int(oidp, &val, 0, req));
4197 * Add sysctl variables, one per statistic, to the system.
4200 em_add_hw_stats(struct e1000_softc *sc)
4202 device_t dev = iflib_get_dev(sc->ctx);
4203 struct em_tx_queue *tx_que = sc->tx_queues;
4204 struct em_rx_queue *rx_que = sc->rx_queues;
4206 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev);
4207 struct sysctl_oid *tree = device_get_sysctl_tree(dev);
4208 struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
4209 struct e1000_hw_stats *stats = &sc->stats;
4211 struct sysctl_oid *stat_node, *queue_node, *int_node;
4212 struct sysctl_oid_list *stat_list, *queue_list, *int_list;
4214 #define QUEUE_NAME_LEN 32
4215 char namebuf[QUEUE_NAME_LEN];
4217 /* Driver Statistics */
4218 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "dropped",
4219 CTLFLAG_RD, &sc->dropped_pkts,
4220 "Driver dropped packets");
4221 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "link_irq",
4222 CTLFLAG_RD, &sc->link_irq,
4223 "Link MSI-X IRQ Handled");
4224 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "rx_overruns",
4225 CTLFLAG_RD, &sc->rx_overruns,
4227 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_timeouts",
4228 CTLFLAG_RD, &sc->watchdog_events,
4229 "Watchdog timeouts");
4230 SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "device_control",
4231 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
4232 sc, E1000_CTRL, em_sysctl_reg_handler, "IU",
4233 "Device Control Register");
4234 SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rx_control",
4235 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
4236 sc, E1000_RCTL, em_sysctl_reg_handler, "IU",
4237 "Receiver Control Register");
4238 SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "fc_high_water",
4239 CTLFLAG_RD, &sc->hw.fc.high_water, 0,
4240 "Flow Control High Watermark");
4241 SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "fc_low_water",
4242 CTLFLAG_RD, &sc->hw.fc.low_water, 0,
4243 "Flow Control Low Watermark");
4245 for (int i = 0; i < sc->tx_num_queues; i++, tx_que++) {
4246 struct tx_ring *txr = &tx_que->txr;
4247 snprintf(namebuf, QUEUE_NAME_LEN, "queue_tx_%d", i);
4248 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
4249 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "TX Queue Name");
4250 queue_list = SYSCTL_CHILDREN(queue_node);
4252 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_head",
4253 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, sc,
4254 E1000_TDH(txr->me), em_sysctl_reg_handler, "IU",
4255 "Transmit Descriptor Head");
4256 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_tail",
4257 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, sc,
4258 E1000_TDT(txr->me), em_sysctl_reg_handler, "IU",
4259 "Transmit Descriptor Tail");
4260 SYSCTL_ADD_ULONG(ctx, queue_list, OID_AUTO, "tx_irq",
4261 CTLFLAG_RD, &txr->tx_irq,
4262 "Queue MSI-X Transmit Interrupts");
4265 for (int j = 0; j < sc->rx_num_queues; j++, rx_que++) {
4266 struct rx_ring *rxr = &rx_que->rxr;
4267 snprintf(namebuf, QUEUE_NAME_LEN, "queue_rx_%d", j);
4268 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
4269 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "RX Queue Name");
4270 queue_list = SYSCTL_CHILDREN(queue_node);
4272 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_head",
4273 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, sc,
4274 E1000_RDH(rxr->me), em_sysctl_reg_handler, "IU",
4275 "Receive Descriptor Head");
4276 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_tail",
4277 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, sc,
4278 E1000_RDT(rxr->me), em_sysctl_reg_handler, "IU",
4279 "Receive Descriptor Tail");
4280 SYSCTL_ADD_ULONG(ctx, queue_list, OID_AUTO, "rx_irq",
4281 CTLFLAG_RD, &rxr->rx_irq,
4282 "Queue MSI-X Receive Interrupts");
4285 /* MAC stats get their own sub node */
4287 stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac_stats",
4288 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Statistics");
4289 stat_list = SYSCTL_CHILDREN(stat_node);
4291 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "excess_coll",
4292 CTLFLAG_RD, &stats->ecol,
4293 "Excessive collisions");
4294 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "single_coll",
4295 CTLFLAG_RD, &stats->scc,
4296 "Single collisions");
4297 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "multiple_coll",
4298 CTLFLAG_RD, &stats->mcc,
4299 "Multiple collisions");
4300 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "late_coll",
4301 CTLFLAG_RD, &stats->latecol,
4303 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "collision_count",
4304 CTLFLAG_RD, &stats->colc,
4306 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "symbol_errors",
4307 CTLFLAG_RD, &sc->stats.symerrs,
4309 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "sequence_errors",
4310 CTLFLAG_RD, &sc->stats.sec,
4312 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "defer_count",
4313 CTLFLAG_RD, &sc->stats.dc,
4315 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "missed_packets",
4316 CTLFLAG_RD, &sc->stats.mpc,
4318 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_no_buff",
4319 CTLFLAG_RD, &sc->stats.rnbc,
4320 "Receive No Buffers");
4321 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_undersize",
4322 CTLFLAG_RD, &sc->stats.ruc,
4323 "Receive Undersize");
4324 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_fragmented",
4325 CTLFLAG_RD, &sc->stats.rfc,
4326 "Fragmented Packets Received ");
4327 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_oversize",
4328 CTLFLAG_RD, &sc->stats.roc,
4329 "Oversized Packets Received");
4330 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_jabber",
4331 CTLFLAG_RD, &sc->stats.rjc,
4333 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_errs",
4334 CTLFLAG_RD, &sc->stats.rxerrc,
4336 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "crc_errs",
4337 CTLFLAG_RD, &sc->stats.crcerrs,
4339 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "alignment_errs",
4340 CTLFLAG_RD, &sc->stats.algnerrc,
4341 "Alignment Errors");
4342 /* On 82575 these are collision counts */
4343 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "coll_ext_errs",
4344 CTLFLAG_RD, &sc->stats.cexterr,
4345 "Collision/Carrier extension errors");
4346 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xon_recvd",
4347 CTLFLAG_RD, &sc->stats.xonrxc,
4349 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xon_txd",
4350 CTLFLAG_RD, &sc->stats.xontxc,
4352 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xoff_recvd",
4353 CTLFLAG_RD, &sc->stats.xoffrxc,
4355 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xoff_txd",
4356 CTLFLAG_RD, &sc->stats.xofftxc,
4357 "XOFF Transmitted");
4359 /* Packet Reception Stats */
4360 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_recvd",
4361 CTLFLAG_RD, &sc->stats.tpr,
4362 "Total Packets Received ");
4363 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_recvd",
4364 CTLFLAG_RD, &sc->stats.gprc,
4365 "Good Packets Received");
4366 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_recvd",
4367 CTLFLAG_RD, &sc->stats.bprc,
4368 "Broadcast Packets Received");
4369 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_recvd",
4370 CTLFLAG_RD, &sc->stats.mprc,
4371 "Multicast Packets Received");
4372 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_64",
4373 CTLFLAG_RD, &sc->stats.prc64,
4374 "64 byte frames received ");
4375 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_65_127",
4376 CTLFLAG_RD, &sc->stats.prc127,
4377 "65-127 byte frames received");
4378 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_128_255",
4379 CTLFLAG_RD, &sc->stats.prc255,
4380 "128-255 byte frames received");
4381 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_256_511",
4382 CTLFLAG_RD, &sc->stats.prc511,
4383 "256-511 byte frames received");
4384 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_512_1023",
4385 CTLFLAG_RD, &sc->stats.prc1023,
4386 "512-1023 byte frames received");
4387 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_1024_1522",
4388 CTLFLAG_RD, &sc->stats.prc1522,
4389 "1023-1522 byte frames received");
4390 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_recvd",
4391 CTLFLAG_RD, &sc->stats.gorc,
4392 "Good Octets Received");
4394 /* Packet Transmission Stats */
4395 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_txd",
4396 CTLFLAG_RD, &sc->stats.gotc,
4397 "Good Octets Transmitted");
4398 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_txd",
4399 CTLFLAG_RD, &sc->stats.tpt,
4400 "Total Packets Transmitted");
4401 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_txd",
4402 CTLFLAG_RD, &sc->stats.gptc,
4403 "Good Packets Transmitted");
4404 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_txd",
4405 CTLFLAG_RD, &sc->stats.bptc,
4406 "Broadcast Packets Transmitted");
4407 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_txd",
4408 CTLFLAG_RD, &sc->stats.mptc,
4409 "Multicast Packets Transmitted");
4410 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_64",
4411 CTLFLAG_RD, &sc->stats.ptc64,
4412 "64 byte frames transmitted ");
4413 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_65_127",
4414 CTLFLAG_RD, &sc->stats.ptc127,
4415 "65-127 byte frames transmitted");
4416 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_128_255",
4417 CTLFLAG_RD, &sc->stats.ptc255,
4418 "128-255 byte frames transmitted");
4419 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_256_511",
4420 CTLFLAG_RD, &sc->stats.ptc511,
4421 "256-511 byte frames transmitted");
4422 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_512_1023",
4423 CTLFLAG_RD, &sc->stats.ptc1023,
4424 "512-1023 byte frames transmitted");
4425 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_1024_1522",
4426 CTLFLAG_RD, &sc->stats.ptc1522,
4427 "1024-1522 byte frames transmitted");
4428 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tso_txd",
4429 CTLFLAG_RD, &sc->stats.tsctc,
4430 "TSO Contexts Transmitted");
4431 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tso_ctx_fail",
4432 CTLFLAG_RD, &sc->stats.tsctfc,
4433 "TSO Contexts Failed");
4436 /* Interrupt Stats */
4438 int_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "interrupts",
4439 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Interrupt Statistics");
4440 int_list = SYSCTL_CHILDREN(int_node);
4442 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "asserts",
4443 CTLFLAG_RD, &sc->stats.iac,
4444 "Interrupt Assertion Count");
4446 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "rx_pkt_timer",
4447 CTLFLAG_RD, &sc->stats.icrxptc,
4448 "Interrupt Cause Rx Pkt Timer Expire Count");
4450 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "rx_abs_timer",
4451 CTLFLAG_RD, &sc->stats.icrxatc,
4452 "Interrupt Cause Rx Abs Timer Expire Count");
4454 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "tx_pkt_timer",
4455 CTLFLAG_RD, &sc->stats.ictxptc,
4456 "Interrupt Cause Tx Pkt Timer Expire Count");
4458 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "tx_abs_timer",
4459 CTLFLAG_RD, &sc->stats.ictxatc,
4460 "Interrupt Cause Tx Abs Timer Expire Count");
4462 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "tx_queue_empty",
4463 CTLFLAG_RD, &sc->stats.ictxqec,
4464 "Interrupt Cause Tx Queue Empty Count");
4466 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "tx_queue_min_thresh",
4467 CTLFLAG_RD, &sc->stats.ictxqmtc,
4468 "Interrupt Cause Tx Queue Min Thresh Count");
4470 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "rx_desc_min_thresh",
4471 CTLFLAG_RD, &sc->stats.icrxdmtc,
4472 "Interrupt Cause Rx Desc Min Thresh Count");
4474 SYSCTL_ADD_UQUAD(ctx, int_list, OID_AUTO, "rx_overrun",
4475 CTLFLAG_RD, &sc->stats.icrxoc,
4476 "Interrupt Cause Receiver Overrun Count");
4479 /**********************************************************************
4481 * This routine provides a way to dump out the adapter eeprom,
4482 * often a useful debug/service tool. This only dumps the first
4483 * 32 words, stuff that matters is in that extent.
4485 **********************************************************************/
4487 em_sysctl_nvm_info(SYSCTL_HANDLER_ARGS)
4489 struct e1000_softc *sc = (struct e1000_softc *)arg1;
4494 error = sysctl_handle_int(oidp, &result, 0, req);
4496 if (error || !req->newptr)
4500 * This value will cause a hex dump of the
4501 * first 32 16-bit words of the EEPROM to
4505 em_print_nvm_info(sc);
4511 em_print_nvm_info(struct e1000_softc *sc)
4516 /* Its a bit crude, but it gets the job done */
4517 printf("\nInterface EEPROM Dump:\n");
4518 printf("Offset\n0x0000 ");
4519 for (i = 0, j = 0; i < 32; i++, j++) {
4520 if (j == 8) { /* Make the offset block */
4522 printf("\n0x00%x0 ",row);
4524 e1000_read_nvm(&sc->hw, i, 1, &eeprom_data);
4525 printf("%04x ", eeprom_data);
4531 em_sysctl_int_delay(SYSCTL_HANDLER_ARGS)
4533 struct em_int_delay_info *info;
4534 struct e1000_softc *sc;
4536 int error, usecs, ticks;
4538 info = (struct em_int_delay_info *) arg1;
4539 usecs = info->value;
4540 error = sysctl_handle_int(oidp, &usecs, 0, req);
4541 if (error != 0 || req->newptr == NULL)
4543 if (usecs < 0 || usecs > EM_TICKS_TO_USECS(65535))
4545 info->value = usecs;
4546 ticks = EM_USECS_TO_TICKS(usecs);
4547 if (info->offset == E1000_ITR) /* units are 256ns here */
4552 regval = E1000_READ_OFFSET(&sc->hw, info->offset);
4553 regval = (regval & ~0xffff) | (ticks & 0xffff);
4554 /* Handle a few special cases. */
4555 switch (info->offset) {
4560 sc->txd_cmd &= ~E1000_TXD_CMD_IDE;
4561 /* Don't write 0 into the TIDV register. */
4564 sc->txd_cmd |= E1000_TXD_CMD_IDE;
4567 E1000_WRITE_OFFSET(&sc->hw, info->offset, regval);
4572 em_add_int_delay_sysctl(struct e1000_softc *sc, const char *name,
4573 const char *description, struct em_int_delay_info *info,
4574 int offset, int value)
4577 info->offset = offset;
4578 info->value = value;
4579 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
4580 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)),
4581 OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
4582 info, 0, em_sysctl_int_delay, "I", description);
4586 * Set flow control using sysctl:
4587 * Flow control values:
4594 em_set_flowcntl(SYSCTL_HANDLER_ARGS)
4597 static int input = 3; /* default is full */
4598 struct e1000_softc *sc = (struct e1000_softc *) arg1;
4600 error = sysctl_handle_int(oidp, &input, 0, req);
4602 if ((error) || (req->newptr == NULL))
4605 if (input == sc->fc) /* no change? */
4609 case e1000_fc_rx_pause:
4610 case e1000_fc_tx_pause:
4613 sc->hw.fc.requested_mode = input;
4621 sc->hw.fc.current_mode = sc->hw.fc.requested_mode;
4622 e1000_force_mac_fc(&sc->hw);
4627 * Manage Energy Efficient Ethernet:
4629 * 0/1 - enabled/disabled
4632 em_sysctl_eee(SYSCTL_HANDLER_ARGS)
4634 struct e1000_softc *sc = (struct e1000_softc *) arg1;
4637 value = sc->hw.dev_spec.ich8lan.eee_disable;
4638 error = sysctl_handle_int(oidp, &value, 0, req);
4639 if (error || req->newptr == NULL)
4641 sc->hw.dev_spec.ich8lan.eee_disable = (value != 0);
4642 em_if_init(sc->ctx);
4648 em_sysctl_debug_info(SYSCTL_HANDLER_ARGS)
4650 struct e1000_softc *sc;
4655 error = sysctl_handle_int(oidp, &result, 0, req);
4657 if (error || !req->newptr)
4661 sc = (struct e1000_softc *) arg1;
4662 em_print_debug_info(sc);
4669 em_get_rs(SYSCTL_HANDLER_ARGS)
4671 struct e1000_softc *sc = (struct e1000_softc *) arg1;
4676 error = sysctl_handle_int(oidp, &result, 0, req);
4678 if (error || !req->newptr || result != 1)
4686 em_if_debug(if_ctx_t ctx)
4688 em_dump_rs(iflib_get_softc(ctx));
4692 * This routine is meant to be fluid, add whatever is
4693 * needed for debugging a problem. -jfv
4696 em_print_debug_info(struct e1000_softc *sc)
4698 device_t dev = iflib_get_dev(sc->ctx);
4699 struct ifnet *ifp = iflib_get_ifp(sc->ctx);
4700 struct tx_ring *txr = &sc->tx_queues->txr;
4701 struct rx_ring *rxr = &sc->rx_queues->rxr;
4703 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING)
4704 printf("Interface is RUNNING ");
4706 printf("Interface is NOT RUNNING\n");
4708 if (if_getdrvflags(ifp) & IFF_DRV_OACTIVE)
4709 printf("and INACTIVE\n");
4711 printf("and ACTIVE\n");
4713 for (int i = 0; i < sc->tx_num_queues; i++, txr++) {
4714 device_printf(dev, "TX Queue %d ------\n", i);
4715 device_printf(dev, "hw tdh = %d, hw tdt = %d\n",
4716 E1000_READ_REG(&sc->hw, E1000_TDH(i)),
4717 E1000_READ_REG(&sc->hw, E1000_TDT(i)));
4720 for (int j=0; j < sc->rx_num_queues; j++, rxr++) {
4721 device_printf(dev, "RX Queue %d ------\n", j);
4722 device_printf(dev, "hw rdh = %d, hw rdt = %d\n",
4723 E1000_READ_REG(&sc->hw, E1000_RDH(j)),
4724 E1000_READ_REG(&sc->hw, E1000_RDT(j)));
4730 * Write a new value to the EEPROM increasing the number of MSI-X
4731 * vectors from 3 to 5, for proper multiqueue support.
4734 em_enable_vectors_82574(if_ctx_t ctx)
4736 struct e1000_softc *sc = iflib_get_softc(ctx);
4737 struct e1000_hw *hw = &sc->hw;
4738 device_t dev = iflib_get_dev(ctx);
4741 e1000_read_nvm(hw, EM_NVM_PCIE_CTRL, 1, &edata);
4743 device_printf(dev, "EM_NVM_PCIE_CTRL = %#06x\n", edata);
4744 if (((edata & EM_NVM_MSIX_N_MASK) >> EM_NVM_MSIX_N_SHIFT) != 4) {
4745 device_printf(dev, "Writing to eeprom: increasing "
4746 "reported MSI-X vectors from 3 to 5...\n");
4747 edata &= ~(EM_NVM_MSIX_N_MASK);
4748 edata |= 4 << EM_NVM_MSIX_N_SHIFT;
4749 e1000_write_nvm(hw, EM_NVM_PCIE_CTRL, 1, &edata);
4750 e1000_update_nvm_checksum(hw);
4751 device_printf(dev, "Writing to eeprom: done\n");