Commit | Line | Data |
---|---|---|
bc7f75fa AK |
1 | /******************************************************************************* |
2 | ||
3 | Intel PRO/1000 Linux driver | |
c7e54b1b | 4 | Copyright(c) 1999 - 2009 Intel Corporation. |
bc7f75fa AK |
5 | |
6 | This program is free software; you can redistribute it and/or modify it | |
7 | under the terms and conditions of the GNU General Public License, | |
8 | version 2, as published by the Free Software Foundation. | |
9 | ||
10 | This program is distributed in the hope it will be useful, but WITHOUT | |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License along with | |
16 | this program; if not, write to the Free Software Foundation, Inc., | |
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | ||
19 | The full GNU General Public License is included in this distribution in | |
20 | the file called "COPYING". | |
21 | ||
22 | Contact Information: | |
23 | Linux NICS <linux.nics@intel.com> | |
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | |
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
26 | ||
27 | *******************************************************************************/ | |
28 | ||
bc7f75fa AK |
29 | #include "e1000.h" |
30 | ||
31 | enum e1000_mng_mode { | |
32 | e1000_mng_mode_none = 0, | |
33 | e1000_mng_mode_asf, | |
34 | e1000_mng_mode_pt, | |
35 | e1000_mng_mode_ipmi, | |
36 | e1000_mng_mode_host_if_only | |
37 | }; | |
38 | ||
39 | #define E1000_FACTPS_MNGCG 0x20000000 | |
40 | ||
ad68076e BA |
41 | /* Intel(R) Active Management Technology signature */ |
42 | #define E1000_IAMT_SIGNATURE 0x544D4149 | |
bc7f75fa AK |
43 | |
44 | /** | |
45 | * e1000e_get_bus_info_pcie - Get PCIe bus information | |
46 | * @hw: pointer to the HW structure | |
47 | * | |
48 | * Determines and stores the system bus information for a particular | |
49 | * network interface. The following bus information is determined and stored: | |
50 | * bus speed, bus width, type (PCIe), and PCIe function. | |
51 | **/ | |
52 | s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw) | |
53 | { | |
54 | struct e1000_bus_info *bus = &hw->bus; | |
55 | struct e1000_adapter *adapter = hw->adapter; | |
56 | u32 status; | |
57 | u16 pcie_link_status, pci_header_type, cap_offset; | |
58 | ||
59 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); | |
60 | if (!cap_offset) { | |
61 | bus->width = e1000_bus_width_unknown; | |
62 | } else { | |
63 | pci_read_config_word(adapter->pdev, | |
64 | cap_offset + PCIE_LINK_STATUS, | |
65 | &pcie_link_status); | |
66 | bus->width = (enum e1000_bus_width)((pcie_link_status & | |
67 | PCIE_LINK_WIDTH_MASK) >> | |
68 | PCIE_LINK_WIDTH_SHIFT); | |
69 | } | |
70 | ||
71 | pci_read_config_word(adapter->pdev, PCI_HEADER_TYPE_REGISTER, | |
72 | &pci_header_type); | |
73 | if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC) { | |
74 | status = er32(STATUS); | |
75 | bus->func = (status & E1000_STATUS_FUNC_MASK) | |
76 | >> E1000_STATUS_FUNC_SHIFT; | |
77 | } else { | |
78 | bus->func = 0; | |
79 | } | |
80 | ||
81 | return 0; | |
82 | } | |
83 | ||
84 | /** | |
85 | * e1000e_write_vfta - Write value to VLAN filter table | |
86 | * @hw: pointer to the HW structure | |
87 | * @offset: register offset in VLAN filter table | |
88 | * @value: register value written to VLAN filter table | |
89 | * | |
90 | * Writes value at the given offset in the register array which stores | |
91 | * the VLAN filter table. | |
92 | **/ | |
93 | void e1000e_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) | |
94 | { | |
95 | E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value); | |
96 | e1e_flush(); | |
97 | } | |
98 | ||
99 | /** | |
100 | * e1000e_init_rx_addrs - Initialize receive address's | |
101 | * @hw: pointer to the HW structure | |
102 | * @rar_count: receive address registers | |
103 | * | |
104 | * Setups the receive address registers by setting the base receive address | |
105 | * register to the devices MAC address and clearing all the other receive | |
106 | * address registers to 0. | |
107 | **/ | |
108 | void e1000e_init_rx_addrs(struct e1000_hw *hw, u16 rar_count) | |
109 | { | |
110 | u32 i; | |
111 | ||
112 | /* Setup the receive address */ | |
3bb99fe2 | 113 | e_dbg("Programming MAC Address into RAR[0]\n"); |
bc7f75fa AK |
114 | |
115 | e1000e_rar_set(hw, hw->mac.addr, 0); | |
116 | ||
117 | /* Zero out the other (rar_entry_count - 1) receive addresses */ | |
3bb99fe2 | 118 | e_dbg("Clearing RAR[1-%u]\n", rar_count-1); |
bc7f75fa AK |
119 | for (i = 1; i < rar_count; i++) { |
120 | E1000_WRITE_REG_ARRAY(hw, E1000_RA, (i << 1), 0); | |
121 | e1e_flush(); | |
122 | E1000_WRITE_REG_ARRAY(hw, E1000_RA, ((i << 1) + 1), 0); | |
123 | e1e_flush(); | |
124 | } | |
125 | } | |
126 | ||
127 | /** | |
128 | * e1000e_rar_set - Set receive address register | |
129 | * @hw: pointer to the HW structure | |
130 | * @addr: pointer to the receive address | |
131 | * @index: receive address array register | |
132 | * | |
133 | * Sets the receive address array register at index to the address passed | |
134 | * in by addr. | |
135 | **/ | |
136 | void e1000e_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) | |
137 | { | |
138 | u32 rar_low, rar_high; | |
139 | ||
ad68076e BA |
140 | /* |
141 | * HW expects these in little endian so we reverse the byte order | |
bc7f75fa AK |
142 | * from network order (big endian) to little endian |
143 | */ | |
144 | rar_low = ((u32) addr[0] | | |
145 | ((u32) addr[1] << 8) | | |
146 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); | |
147 | ||
148 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); | |
149 | ||
150 | rar_high |= E1000_RAH_AV; | |
151 | ||
152 | E1000_WRITE_REG_ARRAY(hw, E1000_RA, (index << 1), rar_low); | |
153 | E1000_WRITE_REG_ARRAY(hw, E1000_RA, ((index << 1) + 1), rar_high); | |
154 | } | |
155 | ||
bc7f75fa AK |
156 | /** |
157 | * e1000_hash_mc_addr - Generate a multicast hash value | |
158 | * @hw: pointer to the HW structure | |
159 | * @mc_addr: pointer to a multicast address | |
160 | * | |
161 | * Generates a multicast address hash value which is used to determine | |
162 | * the multicast filter table array address and new table value. See | |
163 | * e1000_mta_set_generic() | |
164 | **/ | |
165 | static u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) | |
166 | { | |
167 | u32 hash_value, hash_mask; | |
168 | u8 bit_shift = 0; | |
169 | ||
170 | /* Register count multiplied by bits per register */ | |
171 | hash_mask = (hw->mac.mta_reg_count * 32) - 1; | |
172 | ||
ad68076e BA |
173 | /* |
174 | * For a mc_filter_type of 0, bit_shift is the number of left-shifts | |
175 | * where 0xFF would still fall within the hash mask. | |
176 | */ | |
bc7f75fa AK |
177 | while (hash_mask >> bit_shift != 0xFF) |
178 | bit_shift++; | |
179 | ||
ad68076e BA |
180 | /* |
181 | * The portion of the address that is used for the hash table | |
bc7f75fa AK |
182 | * is determined by the mc_filter_type setting. |
183 | * The algorithm is such that there is a total of 8 bits of shifting. | |
184 | * The bit_shift for a mc_filter_type of 0 represents the number of | |
185 | * left-shifts where the MSB of mc_addr[5] would still fall within | |
186 | * the hash_mask. Case 0 does this exactly. Since there are a total | |
187 | * of 8 bits of shifting, then mc_addr[4] will shift right the | |
188 | * remaining number of bits. Thus 8 - bit_shift. The rest of the | |
189 | * cases are a variation of this algorithm...essentially raising the | |
190 | * number of bits to shift mc_addr[5] left, while still keeping the | |
191 | * 8-bit shifting total. | |
ad68076e BA |
192 | * |
193 | * For example, given the following Destination MAC Address and an | |
bc7f75fa AK |
194 | * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask), |
195 | * we can see that the bit_shift for case 0 is 4. These are the hash | |
196 | * values resulting from each mc_filter_type... | |
197 | * [0] [1] [2] [3] [4] [5] | |
198 | * 01 AA 00 12 34 56 | |
199 | * LSB MSB | |
200 | * | |
201 | * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563 | |
202 | * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6 | |
203 | * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163 | |
204 | * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634 | |
205 | */ | |
206 | switch (hw->mac.mc_filter_type) { | |
207 | default: | |
208 | case 0: | |
209 | break; | |
210 | case 1: | |
211 | bit_shift += 1; | |
212 | break; | |
213 | case 2: | |
214 | bit_shift += 2; | |
215 | break; | |
216 | case 3: | |
217 | bit_shift += 4; | |
218 | break; | |
219 | } | |
220 | ||
221 | hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) | | |
222 | (((u16) mc_addr[5]) << bit_shift))); | |
223 | ||
224 | return hash_value; | |
225 | } | |
226 | ||
227 | /** | |
e2de3eb6 | 228 | * e1000e_update_mc_addr_list_generic - Update Multicast addresses |
bc7f75fa AK |
229 | * @hw: pointer to the HW structure |
230 | * @mc_addr_list: array of multicast addresses to program | |
231 | * @mc_addr_count: number of multicast addresses to program | |
232 | * @rar_used_count: the first RAR register free to program | |
233 | * @rar_count: total number of supported Receive Address Registers | |
234 | * | |
235 | * Updates the Receive Address Registers and Multicast Table Array. | |
236 | * The caller must have a packed mc_addr_list of multicast addresses. | |
237 | * The parameter rar_count will usually be hw->mac.rar_entry_count | |
238 | * unless there are workarounds that change this. | |
239 | **/ | |
e2de3eb6 JK |
240 | void e1000e_update_mc_addr_list_generic(struct e1000_hw *hw, |
241 | u8 *mc_addr_list, u32 mc_addr_count, | |
242 | u32 rar_used_count, u32 rar_count) | |
bc7f75fa | 243 | { |
bc7f75fa | 244 | u32 i; |
a72d2b2c JB |
245 | u32 *mcarray = kzalloc(hw->mac.mta_reg_count * sizeof(u32), GFP_ATOMIC); |
246 | ||
247 | if (!mcarray) { | |
248 | printk(KERN_ERR "multicast array memory allocation failed\n"); | |
249 | return; | |
250 | } | |
bc7f75fa | 251 | |
ad68076e BA |
252 | /* |
253 | * Load the first set of multicast addresses into the exact | |
bc7f75fa AK |
254 | * filters (RAR). If there are not enough to fill the RAR |
255 | * array, clear the filters. | |
256 | */ | |
257 | for (i = rar_used_count; i < rar_count; i++) { | |
258 | if (mc_addr_count) { | |
259 | e1000e_rar_set(hw, mc_addr_list, i); | |
260 | mc_addr_count--; | |
261 | mc_addr_list += ETH_ALEN; | |
262 | } else { | |
263 | E1000_WRITE_REG_ARRAY(hw, E1000_RA, i << 1, 0); | |
264 | e1e_flush(); | |
265 | E1000_WRITE_REG_ARRAY(hw, E1000_RA, (i << 1) + 1, 0); | |
266 | e1e_flush(); | |
267 | } | |
268 | } | |
269 | ||
bc7f75fa AK |
270 | /* Load any remaining multicast addresses into the hash table. */ |
271 | for (; mc_addr_count > 0; mc_addr_count--) { | |
a72d2b2c | 272 | u32 hash_value, hash_reg, hash_bit, mta; |
bc7f75fa | 273 | hash_value = e1000_hash_mc_addr(hw, mc_addr_list); |
3bb99fe2 | 274 | e_dbg("Hash value = 0x%03X\n", hash_value); |
a72d2b2c JB |
275 | hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); |
276 | hash_bit = hash_value & 0x1F; | |
277 | mta = (1 << hash_bit); | |
278 | mcarray[hash_reg] |= mta; | |
bc7f75fa AK |
279 | mc_addr_list += ETH_ALEN; |
280 | } | |
a72d2b2c JB |
281 | |
282 | /* write the hash table completely */ | |
283 | for (i = 0; i < hw->mac.mta_reg_count; i++) | |
284 | E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, mcarray[i]); | |
285 | ||
286 | e1e_flush(); | |
287 | kfree(mcarray); | |
bc7f75fa AK |
288 | } |
289 | ||
290 | /** | |
291 | * e1000e_clear_hw_cntrs_base - Clear base hardware counters | |
292 | * @hw: pointer to the HW structure | |
293 | * | |
294 | * Clears the base hardware counters by reading the counter registers. | |
295 | **/ | |
296 | void e1000e_clear_hw_cntrs_base(struct e1000_hw *hw) | |
297 | { | |
99673d9b BA |
298 | er32(CRCERRS); |
299 | er32(SYMERRS); | |
300 | er32(MPC); | |
301 | er32(SCC); | |
302 | er32(ECOL); | |
303 | er32(MCC); | |
304 | er32(LATECOL); | |
305 | er32(COLC); | |
306 | er32(DC); | |
307 | er32(SEC); | |
308 | er32(RLEC); | |
309 | er32(XONRXC); | |
310 | er32(XONTXC); | |
311 | er32(XOFFRXC); | |
312 | er32(XOFFTXC); | |
313 | er32(FCRUC); | |
314 | er32(GPRC); | |
315 | er32(BPRC); | |
316 | er32(MPRC); | |
317 | er32(GPTC); | |
318 | er32(GORCL); | |
319 | er32(GORCH); | |
320 | er32(GOTCL); | |
321 | er32(GOTCH); | |
322 | er32(RNBC); | |
323 | er32(RUC); | |
324 | er32(RFC); | |
325 | er32(ROC); | |
326 | er32(RJC); | |
327 | er32(TORL); | |
328 | er32(TORH); | |
329 | er32(TOTL); | |
330 | er32(TOTH); | |
331 | er32(TPR); | |
332 | er32(TPT); | |
333 | er32(MPTC); | |
334 | er32(BPTC); | |
bc7f75fa AK |
335 | } |
336 | ||
337 | /** | |
338 | * e1000e_check_for_copper_link - Check for link (Copper) | |
339 | * @hw: pointer to the HW structure | |
340 | * | |
341 | * Checks to see of the link status of the hardware has changed. If a | |
342 | * change in link status has been detected, then we read the PHY registers | |
343 | * to get the current speed/duplex if link exists. | |
344 | **/ | |
345 | s32 e1000e_check_for_copper_link(struct e1000_hw *hw) | |
346 | { | |
347 | struct e1000_mac_info *mac = &hw->mac; | |
348 | s32 ret_val; | |
349 | bool link; | |
350 | ||
ad68076e BA |
351 | /* |
352 | * We only want to go out to the PHY registers to see if Auto-Neg | |
bc7f75fa AK |
353 | * has completed and/or if our link status has changed. The |
354 | * get_link_status flag is set upon receiving a Link Status | |
355 | * Change or Rx Sequence Error interrupt. | |
356 | */ | |
357 | if (!mac->get_link_status) | |
358 | return 0; | |
359 | ||
ad68076e BA |
360 | /* |
361 | * First we want to see if the MII Status Register reports | |
bc7f75fa AK |
362 | * link. If so, then we want to get the current speed/duplex |
363 | * of the PHY. | |
364 | */ | |
365 | ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link); | |
366 | if (ret_val) | |
367 | return ret_val; | |
368 | ||
369 | if (!link) | |
370 | return ret_val; /* No link detected */ | |
371 | ||
564ea9bb | 372 | mac->get_link_status = false; |
bc7f75fa | 373 | |
ad68076e BA |
374 | /* |
375 | * Check if there was DownShift, must be checked | |
376 | * immediately after link-up | |
377 | */ | |
bc7f75fa AK |
378 | e1000e_check_downshift(hw); |
379 | ||
ad68076e BA |
380 | /* |
381 | * If we are forcing speed/duplex, then we simply return since | |
bc7f75fa AK |
382 | * we have already determined whether we have link or not. |
383 | */ | |
384 | if (!mac->autoneg) { | |
385 | ret_val = -E1000_ERR_CONFIG; | |
386 | return ret_val; | |
387 | } | |
388 | ||
ad68076e BA |
389 | /* |
390 | * Auto-Neg is enabled. Auto Speed Detection takes care | |
bc7f75fa AK |
391 | * of MAC speed/duplex configuration. So we only need to |
392 | * configure Collision Distance in the MAC. | |
393 | */ | |
394 | e1000e_config_collision_dist(hw); | |
395 | ||
ad68076e BA |
396 | /* |
397 | * Configure Flow Control now that Auto-Neg has completed. | |
bc7f75fa AK |
398 | * First, we need to restore the desired flow control |
399 | * settings because we may have had to re-autoneg with a | |
400 | * different link partner. | |
401 | */ | |
402 | ret_val = e1000e_config_fc_after_link_up(hw); | |
403 | if (ret_val) { | |
3bb99fe2 | 404 | e_dbg("Error configuring flow control\n"); |
bc7f75fa AK |
405 | } |
406 | ||
407 | return ret_val; | |
408 | } | |
409 | ||
410 | /** | |
411 | * e1000e_check_for_fiber_link - Check for link (Fiber) | |
412 | * @hw: pointer to the HW structure | |
413 | * | |
414 | * Checks for link up on the hardware. If link is not up and we have | |
415 | * a signal, then we need to force link up. | |
416 | **/ | |
417 | s32 e1000e_check_for_fiber_link(struct e1000_hw *hw) | |
418 | { | |
419 | struct e1000_mac_info *mac = &hw->mac; | |
420 | u32 rxcw; | |
421 | u32 ctrl; | |
422 | u32 status; | |
423 | s32 ret_val; | |
424 | ||
425 | ctrl = er32(CTRL); | |
426 | status = er32(STATUS); | |
427 | rxcw = er32(RXCW); | |
428 | ||
ad68076e BA |
429 | /* |
430 | * If we don't have link (auto-negotiation failed or link partner | |
bc7f75fa AK |
431 | * cannot auto-negotiate), the cable is plugged in (we have signal), |
432 | * and our link partner is not trying to auto-negotiate with us (we | |
433 | * are receiving idles or data), we need to force link up. We also | |
434 | * need to give auto-negotiation time to complete, in case the cable | |
435 | * was just plugged in. The autoneg_failed flag does this. | |
436 | */ | |
437 | /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ | |
438 | if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) && | |
439 | (!(rxcw & E1000_RXCW_C))) { | |
440 | if (mac->autoneg_failed == 0) { | |
441 | mac->autoneg_failed = 1; | |
442 | return 0; | |
443 | } | |
3bb99fe2 | 444 | e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n"); |
bc7f75fa AK |
445 | |
446 | /* Disable auto-negotiation in the TXCW register */ | |
447 | ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE)); | |
448 | ||
449 | /* Force link-up and also force full-duplex. */ | |
450 | ctrl = er32(CTRL); | |
451 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); | |
452 | ew32(CTRL, ctrl); | |
453 | ||
454 | /* Configure Flow Control after forcing link up. */ | |
455 | ret_val = e1000e_config_fc_after_link_up(hw); | |
456 | if (ret_val) { | |
3bb99fe2 | 457 | e_dbg("Error configuring flow control\n"); |
bc7f75fa AK |
458 | return ret_val; |
459 | } | |
460 | } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { | |
ad68076e BA |
461 | /* |
462 | * If we are forcing link and we are receiving /C/ ordered | |
bc7f75fa AK |
463 | * sets, re-enable auto-negotiation in the TXCW register |
464 | * and disable forced link in the Device Control register | |
465 | * in an attempt to auto-negotiate with our link partner. | |
466 | */ | |
3bb99fe2 | 467 | e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n"); |
bc7f75fa AK |
468 | ew32(TXCW, mac->txcw); |
469 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); | |
470 | ||
612e244c | 471 | mac->serdes_has_link = true; |
bc7f75fa AK |
472 | } |
473 | ||
474 | return 0; | |
475 | } | |
476 | ||
477 | /** | |
478 | * e1000e_check_for_serdes_link - Check for link (Serdes) | |
479 | * @hw: pointer to the HW structure | |
480 | * | |
481 | * Checks for link up on the hardware. If link is not up and we have | |
482 | * a signal, then we need to force link up. | |
483 | **/ | |
484 | s32 e1000e_check_for_serdes_link(struct e1000_hw *hw) | |
485 | { | |
486 | struct e1000_mac_info *mac = &hw->mac; | |
487 | u32 rxcw; | |
488 | u32 ctrl; | |
489 | u32 status; | |
490 | s32 ret_val; | |
491 | ||
492 | ctrl = er32(CTRL); | |
493 | status = er32(STATUS); | |
494 | rxcw = er32(RXCW); | |
495 | ||
ad68076e BA |
496 | /* |
497 | * If we don't have link (auto-negotiation failed or link partner | |
bc7f75fa AK |
498 | * cannot auto-negotiate), and our link partner is not trying to |
499 | * auto-negotiate with us (we are receiving idles or data), | |
500 | * we need to force link up. We also need to give auto-negotiation | |
501 | * time to complete. | |
502 | */ | |
503 | /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ | |
504 | if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { | |
505 | if (mac->autoneg_failed == 0) { | |
506 | mac->autoneg_failed = 1; | |
507 | return 0; | |
508 | } | |
3bb99fe2 | 509 | e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n"); |
bc7f75fa AK |
510 | |
511 | /* Disable auto-negotiation in the TXCW register */ | |
512 | ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE)); | |
513 | ||
514 | /* Force link-up and also force full-duplex. */ | |
515 | ctrl = er32(CTRL); | |
516 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); | |
517 | ew32(CTRL, ctrl); | |
518 | ||
519 | /* Configure Flow Control after forcing link up. */ | |
520 | ret_val = e1000e_config_fc_after_link_up(hw); | |
521 | if (ret_val) { | |
3bb99fe2 | 522 | e_dbg("Error configuring flow control\n"); |
bc7f75fa AK |
523 | return ret_val; |
524 | } | |
525 | } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { | |
ad68076e BA |
526 | /* |
527 | * If we are forcing link and we are receiving /C/ ordered | |
bc7f75fa AK |
528 | * sets, re-enable auto-negotiation in the TXCW register |
529 | * and disable forced link in the Device Control register | |
530 | * in an attempt to auto-negotiate with our link partner. | |
531 | */ | |
3bb99fe2 | 532 | e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n"); |
bc7f75fa AK |
533 | ew32(TXCW, mac->txcw); |
534 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); | |
535 | ||
612e244c | 536 | mac->serdes_has_link = true; |
bc7f75fa | 537 | } else if (!(E1000_TXCW_ANE & er32(TXCW))) { |
ad68076e BA |
538 | /* |
539 | * If we force link for non-auto-negotiation switch, check | |
bc7f75fa AK |
540 | * link status based on MAC synchronization for internal |
541 | * serdes media type. | |
542 | */ | |
543 | /* SYNCH bit and IV bit are sticky. */ | |
544 | udelay(10); | |
63dcf3d3 BA |
545 | rxcw = er32(RXCW); |
546 | if (rxcw & E1000_RXCW_SYNCH) { | |
bc7f75fa | 547 | if (!(rxcw & E1000_RXCW_IV)) { |
63dcf3d3 | 548 | mac->serdes_has_link = true; |
3bb99fe2 | 549 | e_dbg("SERDES: Link up - forced.\n"); |
bc7f75fa AK |
550 | } |
551 | } else { | |
63dcf3d3 | 552 | mac->serdes_has_link = false; |
3bb99fe2 | 553 | e_dbg("SERDES: Link down - force failed.\n"); |
bc7f75fa AK |
554 | } |
555 | } | |
556 | ||
557 | if (E1000_TXCW_ANE & er32(TXCW)) { | |
558 | status = er32(STATUS); | |
63dcf3d3 BA |
559 | if (status & E1000_STATUS_LU) { |
560 | /* SYNCH bit and IV bit are sticky, so reread rxcw. */ | |
561 | udelay(10); | |
562 | rxcw = er32(RXCW); | |
563 | if (rxcw & E1000_RXCW_SYNCH) { | |
564 | if (!(rxcw & E1000_RXCW_IV)) { | |
565 | mac->serdes_has_link = true; | |
3bb99fe2 | 566 | e_dbg("SERDES: Link up - autoneg " |
63dcf3d3 BA |
567 | "completed sucessfully.\n"); |
568 | } else { | |
569 | mac->serdes_has_link = false; | |
3bb99fe2 | 570 | e_dbg("SERDES: Link down - invalid" |
63dcf3d3 BA |
571 | "codewords detected in autoneg.\n"); |
572 | } | |
573 | } else { | |
574 | mac->serdes_has_link = false; | |
3bb99fe2 | 575 | e_dbg("SERDES: Link down - no sync.\n"); |
63dcf3d3 BA |
576 | } |
577 | } else { | |
578 | mac->serdes_has_link = false; | |
3bb99fe2 | 579 | e_dbg("SERDES: Link down - autoneg failed\n"); |
63dcf3d3 | 580 | } |
bc7f75fa AK |
581 | } |
582 | ||
583 | return 0; | |
584 | } | |
585 | ||
586 | /** | |
587 | * e1000_set_default_fc_generic - Set flow control default values | |
588 | * @hw: pointer to the HW structure | |
589 | * | |
590 | * Read the EEPROM for the default values for flow control and store the | |
591 | * values. | |
592 | **/ | |
593 | static s32 e1000_set_default_fc_generic(struct e1000_hw *hw) | |
594 | { | |
bc7f75fa AK |
595 | s32 ret_val; |
596 | u16 nvm_data; | |
597 | ||
ad68076e BA |
598 | /* |
599 | * Read and store word 0x0F of the EEPROM. This word contains bits | |
bc7f75fa AK |
600 | * that determine the hardware's default PAUSE (flow control) mode, |
601 | * a bit that determines whether the HW defaults to enabling or | |
602 | * disabling auto-negotiation, and the direction of the | |
603 | * SW defined pins. If there is no SW over-ride of the flow | |
604 | * control setting, then the variable hw->fc will | |
605 | * be initialized based on a value in the EEPROM. | |
606 | */ | |
607 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data); | |
608 | ||
609 | if (ret_val) { | |
3bb99fe2 | 610 | e_dbg("NVM Read Error\n"); |
bc7f75fa AK |
611 | return ret_val; |
612 | } | |
613 | ||
614 | if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0) | |
5c48ef3e | 615 | hw->fc.requested_mode = e1000_fc_none; |
bc7f75fa AK |
616 | else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == |
617 | NVM_WORD0F_ASM_DIR) | |
5c48ef3e | 618 | hw->fc.requested_mode = e1000_fc_tx_pause; |
bc7f75fa | 619 | else |
5c48ef3e | 620 | hw->fc.requested_mode = e1000_fc_full; |
bc7f75fa AK |
621 | |
622 | return 0; | |
623 | } | |
624 | ||
625 | /** | |
626 | * e1000e_setup_link - Setup flow control and link settings | |
627 | * @hw: pointer to the HW structure | |
628 | * | |
629 | * Determines which flow control settings to use, then configures flow | |
630 | * control. Calls the appropriate media-specific link configuration | |
631 | * function. Assuming the adapter has a valid link partner, a valid link | |
632 | * should be established. Assumes the hardware has previously been reset | |
633 | * and the transmitter and receiver are not enabled. | |
634 | **/ | |
635 | s32 e1000e_setup_link(struct e1000_hw *hw) | |
636 | { | |
637 | struct e1000_mac_info *mac = &hw->mac; | |
638 | s32 ret_val; | |
639 | ||
ad68076e BA |
640 | /* |
641 | * In the case of the phy reset being blocked, we already have a link. | |
bc7f75fa AK |
642 | * We do not need to set it up again. |
643 | */ | |
644 | if (e1000_check_reset_block(hw)) | |
645 | return 0; | |
646 | ||
309af40b | 647 | /* |
5c48ef3e BA |
648 | * If requested flow control is set to default, set flow control |
649 | * based on the EEPROM flow control settings. | |
309af40b | 650 | */ |
5c48ef3e | 651 | if (hw->fc.requested_mode == e1000_fc_default) { |
309af40b AK |
652 | ret_val = e1000_set_default_fc_generic(hw); |
653 | if (ret_val) | |
654 | return ret_val; | |
655 | } | |
bc7f75fa | 656 | |
ad68076e | 657 | /* |
5c48ef3e BA |
658 | * Save off the requested flow control mode for use later. Depending |
659 | * on the link partner's capabilities, we may or may not use this mode. | |
bc7f75fa | 660 | */ |
5c48ef3e | 661 | hw->fc.current_mode = hw->fc.requested_mode; |
bc7f75fa | 662 | |
3bb99fe2 | 663 | e_dbg("After fix-ups FlowControl is now = %x\n", |
5c48ef3e | 664 | hw->fc.current_mode); |
bc7f75fa AK |
665 | |
666 | /* Call the necessary media_type subroutine to configure the link. */ | |
667 | ret_val = mac->ops.setup_physical_interface(hw); | |
668 | if (ret_val) | |
669 | return ret_val; | |
670 | ||
ad68076e BA |
671 | /* |
672 | * Initialize the flow control address, type, and PAUSE timer | |
bc7f75fa AK |
673 | * registers to their default values. This is done even if flow |
674 | * control is disabled, because it does not hurt anything to | |
675 | * initialize these registers. | |
676 | */ | |
3bb99fe2 | 677 | e_dbg("Initializing the Flow Control address, type and timer regs\n"); |
bc7f75fa AK |
678 | ew32(FCT, FLOW_CONTROL_TYPE); |
679 | ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); | |
680 | ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); | |
681 | ||
318a94d6 | 682 | ew32(FCTTV, hw->fc.pause_time); |
bc7f75fa AK |
683 | |
684 | return e1000e_set_fc_watermarks(hw); | |
685 | } | |
686 | ||
687 | /** | |
688 | * e1000_commit_fc_settings_generic - Configure flow control | |
689 | * @hw: pointer to the HW structure | |
690 | * | |
691 | * Write the flow control settings to the Transmit Config Word Register (TXCW) | |
692 | * base on the flow control settings in e1000_mac_info. | |
693 | **/ | |
694 | static s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw) | |
695 | { | |
696 | struct e1000_mac_info *mac = &hw->mac; | |
697 | u32 txcw; | |
698 | ||
ad68076e BA |
699 | /* |
700 | * Check for a software override of the flow control settings, and | |
bc7f75fa AK |
701 | * setup the device accordingly. If auto-negotiation is enabled, then |
702 | * software will have to set the "PAUSE" bits to the correct value in | |
703 | * the Transmit Config Word Register (TXCW) and re-start auto- | |
704 | * negotiation. However, if auto-negotiation is disabled, then | |
705 | * software will have to manually configure the two flow control enable | |
706 | * bits in the CTRL register. | |
707 | * | |
708 | * The possible values of the "fc" parameter are: | |
709 | * 0: Flow control is completely disabled | |
710 | * 1: Rx flow control is enabled (we can receive pause frames, | |
711 | * but not send pause frames). | |
712 | * 2: Tx flow control is enabled (we can send pause frames but we | |
713 | * do not support receiving pause frames). | |
ad68076e | 714 | * 3: Both Rx and Tx flow control (symmetric) are enabled. |
bc7f75fa | 715 | */ |
5c48ef3e | 716 | switch (hw->fc.current_mode) { |
bc7f75fa AK |
717 | case e1000_fc_none: |
718 | /* Flow control completely disabled by a software over-ride. */ | |
719 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); | |
720 | break; | |
721 | case e1000_fc_rx_pause: | |
ad68076e BA |
722 | /* |
723 | * Rx Flow control is enabled and Tx Flow control is disabled | |
bc7f75fa | 724 | * by a software over-ride. Since there really isn't a way to |
ad68076e BA |
725 | * advertise that we are capable of Rx Pause ONLY, we will |
726 | * advertise that we support both symmetric and asymmetric Rx | |
bc7f75fa AK |
727 | * PAUSE. Later, we will disable the adapter's ability to send |
728 | * PAUSE frames. | |
729 | */ | |
730 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); | |
731 | break; | |
732 | case e1000_fc_tx_pause: | |
ad68076e BA |
733 | /* |
734 | * Tx Flow control is enabled, and Rx Flow control is disabled, | |
bc7f75fa AK |
735 | * by a software over-ride. |
736 | */ | |
737 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); | |
738 | break; | |
739 | case e1000_fc_full: | |
ad68076e BA |
740 | /* |
741 | * Flow control (both Rx and Tx) is enabled by a software | |
bc7f75fa AK |
742 | * over-ride. |
743 | */ | |
744 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); | |
745 | break; | |
746 | default: | |
3bb99fe2 | 747 | e_dbg("Flow control param set incorrectly\n"); |
bc7f75fa AK |
748 | return -E1000_ERR_CONFIG; |
749 | break; | |
750 | } | |
751 | ||
752 | ew32(TXCW, txcw); | |
753 | mac->txcw = txcw; | |
754 | ||
755 | return 0; | |
756 | } | |
757 | ||
758 | /** | |
759 | * e1000_poll_fiber_serdes_link_generic - Poll for link up | |
760 | * @hw: pointer to the HW structure | |
761 | * | |
762 | * Polls for link up by reading the status register, if link fails to come | |
763 | * up with auto-negotiation, then the link is forced if a signal is detected. | |
764 | **/ | |
765 | static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw) | |
766 | { | |
767 | struct e1000_mac_info *mac = &hw->mac; | |
768 | u32 i, status; | |
769 | s32 ret_val; | |
770 | ||
ad68076e BA |
771 | /* |
772 | * If we have a signal (the cable is plugged in, or assumed true for | |
bc7f75fa AK |
773 | * serdes media) then poll for a "Link-Up" indication in the Device |
774 | * Status Register. Time-out if a link isn't seen in 500 milliseconds | |
775 | * seconds (Auto-negotiation should complete in less than 500 | |
776 | * milliseconds even if the other end is doing it in SW). | |
777 | */ | |
778 | for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) { | |
779 | msleep(10); | |
780 | status = er32(STATUS); | |
781 | if (status & E1000_STATUS_LU) | |
782 | break; | |
783 | } | |
784 | if (i == FIBER_LINK_UP_LIMIT) { | |
3bb99fe2 | 785 | e_dbg("Never got a valid link from auto-neg!!!\n"); |
bc7f75fa | 786 | mac->autoneg_failed = 1; |
ad68076e BA |
787 | /* |
788 | * AutoNeg failed to achieve a link, so we'll call | |
bc7f75fa AK |
789 | * mac->check_for_link. This routine will force the |
790 | * link up if we detect a signal. This will allow us to | |
791 | * communicate with non-autonegotiating link partners. | |
792 | */ | |
793 | ret_val = mac->ops.check_for_link(hw); | |
794 | if (ret_val) { | |
3bb99fe2 | 795 | e_dbg("Error while checking for link\n"); |
bc7f75fa AK |
796 | return ret_val; |
797 | } | |
798 | mac->autoneg_failed = 0; | |
799 | } else { | |
800 | mac->autoneg_failed = 0; | |
3bb99fe2 | 801 | e_dbg("Valid Link Found\n"); |
bc7f75fa AK |
802 | } |
803 | ||
804 | return 0; | |
805 | } | |
806 | ||
807 | /** | |
808 | * e1000e_setup_fiber_serdes_link - Setup link for fiber/serdes | |
809 | * @hw: pointer to the HW structure | |
810 | * | |
811 | * Configures collision distance and flow control for fiber and serdes | |
812 | * links. Upon successful setup, poll for link. | |
813 | **/ | |
814 | s32 e1000e_setup_fiber_serdes_link(struct e1000_hw *hw) | |
815 | { | |
816 | u32 ctrl; | |
817 | s32 ret_val; | |
818 | ||
819 | ctrl = er32(CTRL); | |
820 | ||
821 | /* Take the link out of reset */ | |
822 | ctrl &= ~E1000_CTRL_LRST; | |
823 | ||
824 | e1000e_config_collision_dist(hw); | |
825 | ||
826 | ret_val = e1000_commit_fc_settings_generic(hw); | |
827 | if (ret_val) | |
828 | return ret_val; | |
829 | ||
ad68076e BA |
830 | /* |
831 | * Since auto-negotiation is enabled, take the link out of reset (the | |
bc7f75fa AK |
832 | * link will be in reset, because we previously reset the chip). This |
833 | * will restart auto-negotiation. If auto-negotiation is successful | |
834 | * then the link-up status bit will be set and the flow control enable | |
835 | * bits (RFCE and TFCE) will be set according to their negotiated value. | |
836 | */ | |
3bb99fe2 | 837 | e_dbg("Auto-negotiation enabled\n"); |
bc7f75fa AK |
838 | |
839 | ew32(CTRL, ctrl); | |
840 | e1e_flush(); | |
841 | msleep(1); | |
842 | ||
ad68076e BA |
843 | /* |
844 | * For these adapters, the SW definable pin 1 is set when the optics | |
bc7f75fa AK |
845 | * detect a signal. If we have a signal, then poll for a "Link-Up" |
846 | * indication. | |
847 | */ | |
318a94d6 | 848 | if (hw->phy.media_type == e1000_media_type_internal_serdes || |
bc7f75fa AK |
849 | (er32(CTRL) & E1000_CTRL_SWDPIN1)) { |
850 | ret_val = e1000_poll_fiber_serdes_link_generic(hw); | |
851 | } else { | |
3bb99fe2 | 852 | e_dbg("No signal detected\n"); |
bc7f75fa AK |
853 | } |
854 | ||
855 | return 0; | |
856 | } | |
857 | ||
858 | /** | |
859 | * e1000e_config_collision_dist - Configure collision distance | |
860 | * @hw: pointer to the HW structure | |
861 | * | |
862 | * Configures the collision distance to the default value and is used | |
863 | * during link setup. Currently no func pointer exists and all | |
864 | * implementations are handled in the generic version of this function. | |
865 | **/ | |
866 | void e1000e_config_collision_dist(struct e1000_hw *hw) | |
867 | { | |
868 | u32 tctl; | |
869 | ||
870 | tctl = er32(TCTL); | |
871 | ||
872 | tctl &= ~E1000_TCTL_COLD; | |
873 | tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT; | |
874 | ||
875 | ew32(TCTL, tctl); | |
876 | e1e_flush(); | |
877 | } | |
878 | ||
879 | /** | |
880 | * e1000e_set_fc_watermarks - Set flow control high/low watermarks | |
881 | * @hw: pointer to the HW structure | |
882 | * | |
883 | * Sets the flow control high/low threshold (watermark) registers. If | |
884 | * flow control XON frame transmission is enabled, then set XON frame | |
ad68076e | 885 | * transmission as well. |
bc7f75fa AK |
886 | **/ |
887 | s32 e1000e_set_fc_watermarks(struct e1000_hw *hw) | |
888 | { | |
bc7f75fa AK |
889 | u32 fcrtl = 0, fcrth = 0; |
890 | ||
ad68076e BA |
891 | /* |
892 | * Set the flow control receive threshold registers. Normally, | |
bc7f75fa AK |
893 | * these registers will be set to a default threshold that may be |
894 | * adjusted later by the driver's runtime code. However, if the | |
895 | * ability to transmit pause frames is not enabled, then these | |
896 | * registers will be set to 0. | |
897 | */ | |
5c48ef3e | 898 | if (hw->fc.current_mode & e1000_fc_tx_pause) { |
ad68076e BA |
899 | /* |
900 | * We need to set up the Receive Threshold high and low water | |
bc7f75fa AK |
901 | * marks as well as (optionally) enabling the transmission of |
902 | * XON frames. | |
903 | */ | |
318a94d6 | 904 | fcrtl = hw->fc.low_water; |
bc7f75fa | 905 | fcrtl |= E1000_FCRTL_XONE; |
318a94d6 | 906 | fcrth = hw->fc.high_water; |
bc7f75fa AK |
907 | } |
908 | ew32(FCRTL, fcrtl); | |
909 | ew32(FCRTH, fcrth); | |
910 | ||
911 | return 0; | |
912 | } | |
913 | ||
914 | /** | |
915 | * e1000e_force_mac_fc - Force the MAC's flow control settings | |
916 | * @hw: pointer to the HW structure | |
917 | * | |
918 | * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the | |
919 | * device control register to reflect the adapter settings. TFCE and RFCE | |
920 | * need to be explicitly set by software when a copper PHY is used because | |
921 | * autonegotiation is managed by the PHY rather than the MAC. Software must | |
922 | * also configure these bits when link is forced on a fiber connection. | |
923 | **/ | |
924 | s32 e1000e_force_mac_fc(struct e1000_hw *hw) | |
925 | { | |
bc7f75fa AK |
926 | u32 ctrl; |
927 | ||
928 | ctrl = er32(CTRL); | |
929 | ||
ad68076e BA |
930 | /* |
931 | * Because we didn't get link via the internal auto-negotiation | |
bc7f75fa AK |
932 | * mechanism (we either forced link or we got link via PHY |
933 | * auto-neg), we have to manually enable/disable transmit an | |
934 | * receive flow control. | |
935 | * | |
936 | * The "Case" statement below enables/disable flow control | |
5c48ef3e | 937 | * according to the "hw->fc.current_mode" parameter. |
bc7f75fa AK |
938 | * |
939 | * The possible values of the "fc" parameter are: | |
940 | * 0: Flow control is completely disabled | |
941 | * 1: Rx flow control is enabled (we can receive pause | |
942 | * frames but not send pause frames). | |
943 | * 2: Tx flow control is enabled (we can send pause frames | |
944 | * frames but we do not receive pause frames). | |
ad68076e | 945 | * 3: Both Rx and Tx flow control (symmetric) is enabled. |
bc7f75fa AK |
946 | * other: No other values should be possible at this point. |
947 | */ | |
3bb99fe2 | 948 | e_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode); |
bc7f75fa | 949 | |
5c48ef3e | 950 | switch (hw->fc.current_mode) { |
bc7f75fa AK |
951 | case e1000_fc_none: |
952 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); | |
953 | break; | |
954 | case e1000_fc_rx_pause: | |
955 | ctrl &= (~E1000_CTRL_TFCE); | |
956 | ctrl |= E1000_CTRL_RFCE; | |
957 | break; | |
958 | case e1000_fc_tx_pause: | |
959 | ctrl &= (~E1000_CTRL_RFCE); | |
960 | ctrl |= E1000_CTRL_TFCE; | |
961 | break; | |
962 | case e1000_fc_full: | |
963 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); | |
964 | break; | |
965 | default: | |
3bb99fe2 | 966 | e_dbg("Flow control param set incorrectly\n"); |
bc7f75fa AK |
967 | return -E1000_ERR_CONFIG; |
968 | } | |
969 | ||
970 | ew32(CTRL, ctrl); | |
971 | ||
972 | return 0; | |
973 | } | |
974 | ||
975 | /** | |
976 | * e1000e_config_fc_after_link_up - Configures flow control after link | |
977 | * @hw: pointer to the HW structure | |
978 | * | |
979 | * Checks the status of auto-negotiation after link up to ensure that the | |
980 | * speed and duplex were not forced. If the link needed to be forced, then | |
981 | * flow control needs to be forced also. If auto-negotiation is enabled | |
982 | * and did not fail, then we configure flow control based on our link | |
983 | * partner. | |
984 | **/ | |
985 | s32 e1000e_config_fc_after_link_up(struct e1000_hw *hw) | |
986 | { | |
987 | struct e1000_mac_info *mac = &hw->mac; | |
988 | s32 ret_val = 0; | |
989 | u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg; | |
990 | u16 speed, duplex; | |
991 | ||
ad68076e BA |
992 | /* |
993 | * Check for the case where we have fiber media and auto-neg failed | |
bc7f75fa AK |
994 | * so we had to force link. In this case, we need to force the |
995 | * configuration of the MAC to match the "fc" parameter. | |
996 | */ | |
997 | if (mac->autoneg_failed) { | |
318a94d6 JK |
998 | if (hw->phy.media_type == e1000_media_type_fiber || |
999 | hw->phy.media_type == e1000_media_type_internal_serdes) | |
bc7f75fa AK |
1000 | ret_val = e1000e_force_mac_fc(hw); |
1001 | } else { | |
318a94d6 | 1002 | if (hw->phy.media_type == e1000_media_type_copper) |
bc7f75fa AK |
1003 | ret_val = e1000e_force_mac_fc(hw); |
1004 | } | |
1005 | ||
1006 | if (ret_val) { | |
3bb99fe2 | 1007 | e_dbg("Error forcing flow control settings\n"); |
bc7f75fa AK |
1008 | return ret_val; |
1009 | } | |
1010 | ||
ad68076e BA |
1011 | /* |
1012 | * Check for the case where we have copper media and auto-neg is | |
bc7f75fa AK |
1013 | * enabled. In this case, we need to check and see if Auto-Neg |
1014 | * has completed, and if so, how the PHY and link partner has | |
1015 | * flow control configured. | |
1016 | */ | |
318a94d6 | 1017 | if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) { |
ad68076e BA |
1018 | /* |
1019 | * Read the MII Status Register and check to see if AutoNeg | |
bc7f75fa AK |
1020 | * has completed. We read this twice because this reg has |
1021 | * some "sticky" (latched) bits. | |
1022 | */ | |
1023 | ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg); | |
1024 | if (ret_val) | |
1025 | return ret_val; | |
1026 | ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg); | |
1027 | if (ret_val) | |
1028 | return ret_val; | |
1029 | ||
1030 | if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) { | |
3bb99fe2 | 1031 | e_dbg("Copper PHY and Auto Neg " |
bc7f75fa AK |
1032 | "has not completed.\n"); |
1033 | return ret_val; | |
1034 | } | |
1035 | ||
ad68076e BA |
1036 | /* |
1037 | * The AutoNeg process has completed, so we now need to | |
bc7f75fa AK |
1038 | * read both the Auto Negotiation Advertisement |
1039 | * Register (Address 4) and the Auto_Negotiation Base | |
1040 | * Page Ability Register (Address 5) to determine how | |
1041 | * flow control was negotiated. | |
1042 | */ | |
1043 | ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg); | |
1044 | if (ret_val) | |
1045 | return ret_val; | |
1046 | ret_val = e1e_rphy(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg); | |
1047 | if (ret_val) | |
1048 | return ret_val; | |
1049 | ||
ad68076e BA |
1050 | /* |
1051 | * Two bits in the Auto Negotiation Advertisement Register | |
bc7f75fa AK |
1052 | * (Address 4) and two bits in the Auto Negotiation Base |
1053 | * Page Ability Register (Address 5) determine flow control | |
1054 | * for both the PHY and the link partner. The following | |
1055 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, | |
1056 | * 1999, describes these PAUSE resolution bits and how flow | |
1057 | * control is determined based upon these settings. | |
1058 | * NOTE: DC = Don't Care | |
1059 | * | |
1060 | * LOCAL DEVICE | LINK PARTNER | |
1061 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution | |
1062 | *-------|---------|-------|---------|-------------------- | |
1063 | * 0 | 0 | DC | DC | e1000_fc_none | |
1064 | * 0 | 1 | 0 | DC | e1000_fc_none | |
1065 | * 0 | 1 | 1 | 0 | e1000_fc_none | |
1066 | * 0 | 1 | 1 | 1 | e1000_fc_tx_pause | |
1067 | * 1 | 0 | 0 | DC | e1000_fc_none | |
1068 | * 1 | DC | 1 | DC | e1000_fc_full | |
1069 | * 1 | 1 | 0 | 0 | e1000_fc_none | |
1070 | * 1 | 1 | 0 | 1 | e1000_fc_rx_pause | |
1071 | * | |
ad68076e BA |
1072 | * |
1073 | * Are both PAUSE bits set to 1? If so, this implies | |
bc7f75fa AK |
1074 | * Symmetric Flow Control is enabled at both ends. The |
1075 | * ASM_DIR bits are irrelevant per the spec. | |
1076 | * | |
1077 | * For Symmetric Flow Control: | |
1078 | * | |
1079 | * LOCAL DEVICE | LINK PARTNER | |
1080 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | |
1081 | *-------|---------|-------|---------|-------------------- | |
1082 | * 1 | DC | 1 | DC | E1000_fc_full | |
1083 | * | |
1084 | */ | |
1085 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && | |
1086 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { | |
ad68076e BA |
1087 | /* |
1088 | * Now we need to check if the user selected Rx ONLY | |
bc7f75fa | 1089 | * of pause frames. In this case, we had to advertise |
ad68076e | 1090 | * FULL flow control because we could not advertise Rx |
bc7f75fa AK |
1091 | * ONLY. Hence, we must now check to see if we need to |
1092 | * turn OFF the TRANSMISSION of PAUSE frames. | |
1093 | */ | |
5c48ef3e BA |
1094 | if (hw->fc.requested_mode == e1000_fc_full) { |
1095 | hw->fc.current_mode = e1000_fc_full; | |
3bb99fe2 | 1096 | e_dbg("Flow Control = FULL.\r\n"); |
bc7f75fa | 1097 | } else { |
5c48ef3e | 1098 | hw->fc.current_mode = e1000_fc_rx_pause; |
3bb99fe2 | 1099 | e_dbg("Flow Control = " |
bc7f75fa AK |
1100 | "RX PAUSE frames only.\r\n"); |
1101 | } | |
1102 | } | |
ad68076e BA |
1103 | /* |
1104 | * For receiving PAUSE frames ONLY. | |
bc7f75fa AK |
1105 | * |
1106 | * LOCAL DEVICE | LINK PARTNER | |
1107 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | |
1108 | *-------|---------|-------|---------|-------------------- | |
1109 | * 0 | 1 | 1 | 1 | e1000_fc_tx_pause | |
1110 | * | |
1111 | */ | |
1112 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && | |
1113 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && | |
1114 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && | |
1115 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { | |
5c48ef3e | 1116 | hw->fc.current_mode = e1000_fc_tx_pause; |
3bb99fe2 | 1117 | e_dbg("Flow Control = Tx PAUSE frames only.\r\n"); |
bc7f75fa | 1118 | } |
ad68076e BA |
1119 | /* |
1120 | * For transmitting PAUSE frames ONLY. | |
bc7f75fa AK |
1121 | * |
1122 | * LOCAL DEVICE | LINK PARTNER | |
1123 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | |
1124 | *-------|---------|-------|---------|-------------------- | |
1125 | * 1 | 1 | 0 | 1 | e1000_fc_rx_pause | |
1126 | * | |
1127 | */ | |
1128 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && | |
1129 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && | |
1130 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && | |
1131 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { | |
5c48ef3e | 1132 | hw->fc.current_mode = e1000_fc_rx_pause; |
3bb99fe2 | 1133 | e_dbg("Flow Control = Rx PAUSE frames only.\r\n"); |
de92d84e JB |
1134 | } else { |
1135 | /* | |
1136 | * Per the IEEE spec, at this point flow control | |
1137 | * should be disabled. | |
1138 | */ | |
5c48ef3e | 1139 | hw->fc.current_mode = e1000_fc_none; |
3bb99fe2 | 1140 | e_dbg("Flow Control = NONE.\r\n"); |
bc7f75fa AK |
1141 | } |
1142 | ||
ad68076e BA |
1143 | /* |
1144 | * Now we need to do one last check... If we auto- | |
bc7f75fa AK |
1145 | * negotiated to HALF DUPLEX, flow control should not be |
1146 | * enabled per IEEE 802.3 spec. | |
1147 | */ | |
1148 | ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex); | |
1149 | if (ret_val) { | |
3bb99fe2 | 1150 | e_dbg("Error getting link speed and duplex\n"); |
bc7f75fa AK |
1151 | return ret_val; |
1152 | } | |
1153 | ||
1154 | if (duplex == HALF_DUPLEX) | |
5c48ef3e | 1155 | hw->fc.current_mode = e1000_fc_none; |
bc7f75fa | 1156 | |
ad68076e BA |
1157 | /* |
1158 | * Now we call a subroutine to actually force the MAC | |
bc7f75fa AK |
1159 | * controller to use the correct flow control settings. |
1160 | */ | |
1161 | ret_val = e1000e_force_mac_fc(hw); | |
1162 | if (ret_val) { | |
3bb99fe2 | 1163 | e_dbg("Error forcing flow control settings\n"); |
bc7f75fa AK |
1164 | return ret_val; |
1165 | } | |
1166 | } | |
1167 | ||
1168 | return 0; | |
1169 | } | |
1170 | ||
1171 | /** | |
489815ce | 1172 | * e1000e_get_speed_and_duplex_copper - Retrieve current speed/duplex |
bc7f75fa AK |
1173 | * @hw: pointer to the HW structure |
1174 | * @speed: stores the current speed | |
1175 | * @duplex: stores the current duplex | |
1176 | * | |
1177 | * Read the status register for the current speed/duplex and store the current | |
1178 | * speed and duplex for copper connections. | |
1179 | **/ | |
1180 | s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, u16 *duplex) | |
1181 | { | |
1182 | u32 status; | |
1183 | ||
1184 | status = er32(STATUS); | |
1185 | if (status & E1000_STATUS_SPEED_1000) { | |
1186 | *speed = SPEED_1000; | |
3bb99fe2 | 1187 | e_dbg("1000 Mbs, "); |
bc7f75fa AK |
1188 | } else if (status & E1000_STATUS_SPEED_100) { |
1189 | *speed = SPEED_100; | |
3bb99fe2 | 1190 | e_dbg("100 Mbs, "); |
bc7f75fa AK |
1191 | } else { |
1192 | *speed = SPEED_10; | |
3bb99fe2 | 1193 | e_dbg("10 Mbs, "); |
bc7f75fa AK |
1194 | } |
1195 | ||
1196 | if (status & E1000_STATUS_FD) { | |
1197 | *duplex = FULL_DUPLEX; | |
3bb99fe2 | 1198 | e_dbg("Full Duplex\n"); |
bc7f75fa AK |
1199 | } else { |
1200 | *duplex = HALF_DUPLEX; | |
3bb99fe2 | 1201 | e_dbg("Half Duplex\n"); |
bc7f75fa AK |
1202 | } |
1203 | ||
1204 | return 0; | |
1205 | } | |
1206 | ||
1207 | /** | |
489815ce | 1208 | * e1000e_get_speed_and_duplex_fiber_serdes - Retrieve current speed/duplex |
bc7f75fa AK |
1209 | * @hw: pointer to the HW structure |
1210 | * @speed: stores the current speed | |
1211 | * @duplex: stores the current duplex | |
1212 | * | |
1213 | * Sets the speed and duplex to gigabit full duplex (the only possible option) | |
1214 | * for fiber/serdes links. | |
1215 | **/ | |
1216 | s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw, u16 *speed, u16 *duplex) | |
1217 | { | |
1218 | *speed = SPEED_1000; | |
1219 | *duplex = FULL_DUPLEX; | |
1220 | ||
1221 | return 0; | |
1222 | } | |
1223 | ||
1224 | /** | |
1225 | * e1000e_get_hw_semaphore - Acquire hardware semaphore | |
1226 | * @hw: pointer to the HW structure | |
1227 | * | |
1228 | * Acquire the HW semaphore to access the PHY or NVM | |
1229 | **/ | |
1230 | s32 e1000e_get_hw_semaphore(struct e1000_hw *hw) | |
1231 | { | |
1232 | u32 swsm; | |
1233 | s32 timeout = hw->nvm.word_size + 1; | |
1234 | s32 i = 0; | |
1235 | ||
1236 | /* Get the SW semaphore */ | |
1237 | while (i < timeout) { | |
1238 | swsm = er32(SWSM); | |
1239 | if (!(swsm & E1000_SWSM_SMBI)) | |
1240 | break; | |
1241 | ||
1242 | udelay(50); | |
1243 | i++; | |
1244 | } | |
1245 | ||
1246 | if (i == timeout) { | |
3bb99fe2 | 1247 | e_dbg("Driver can't access device - SMBI bit is set.\n"); |
bc7f75fa AK |
1248 | return -E1000_ERR_NVM; |
1249 | } | |
1250 | ||
1251 | /* Get the FW semaphore. */ | |
1252 | for (i = 0; i < timeout; i++) { | |
1253 | swsm = er32(SWSM); | |
1254 | ew32(SWSM, swsm | E1000_SWSM_SWESMBI); | |
1255 | ||
1256 | /* Semaphore acquired if bit latched */ | |
1257 | if (er32(SWSM) & E1000_SWSM_SWESMBI) | |
1258 | break; | |
1259 | ||
1260 | udelay(50); | |
1261 | } | |
1262 | ||
1263 | if (i == timeout) { | |
1264 | /* Release semaphores */ | |
1265 | e1000e_put_hw_semaphore(hw); | |
3bb99fe2 | 1266 | e_dbg("Driver can't access the NVM\n"); |
bc7f75fa AK |
1267 | return -E1000_ERR_NVM; |
1268 | } | |
1269 | ||
1270 | return 0; | |
1271 | } | |
1272 | ||
1273 | /** | |
1274 | * e1000e_put_hw_semaphore - Release hardware semaphore | |
1275 | * @hw: pointer to the HW structure | |
1276 | * | |
1277 | * Release hardware semaphore used to access the PHY or NVM | |
1278 | **/ | |
1279 | void e1000e_put_hw_semaphore(struct e1000_hw *hw) | |
1280 | { | |
1281 | u32 swsm; | |
1282 | ||
1283 | swsm = er32(SWSM); | |
1284 | swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); | |
1285 | ew32(SWSM, swsm); | |
1286 | } | |
1287 | ||
1288 | /** | |
1289 | * e1000e_get_auto_rd_done - Check for auto read completion | |
1290 | * @hw: pointer to the HW structure | |
1291 | * | |
1292 | * Check EEPROM for Auto Read done bit. | |
1293 | **/ | |
1294 | s32 e1000e_get_auto_rd_done(struct e1000_hw *hw) | |
1295 | { | |
1296 | s32 i = 0; | |
1297 | ||
1298 | while (i < AUTO_READ_DONE_TIMEOUT) { | |
1299 | if (er32(EECD) & E1000_EECD_AUTO_RD) | |
1300 | break; | |
1301 | msleep(1); | |
1302 | i++; | |
1303 | } | |
1304 | ||
1305 | if (i == AUTO_READ_DONE_TIMEOUT) { | |
3bb99fe2 | 1306 | e_dbg("Auto read by HW from NVM has not completed.\n"); |
bc7f75fa AK |
1307 | return -E1000_ERR_RESET; |
1308 | } | |
1309 | ||
1310 | return 0; | |
1311 | } | |
1312 | ||
1313 | /** | |
1314 | * e1000e_valid_led_default - Verify a valid default LED config | |
1315 | * @hw: pointer to the HW structure | |
1316 | * @data: pointer to the NVM (EEPROM) | |
1317 | * | |
1318 | * Read the EEPROM for the current default LED configuration. If the | |
1319 | * LED configuration is not valid, set to a valid LED configuration. | |
1320 | **/ | |
1321 | s32 e1000e_valid_led_default(struct e1000_hw *hw, u16 *data) | |
1322 | { | |
1323 | s32 ret_val; | |
1324 | ||
1325 | ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data); | |
1326 | if (ret_val) { | |
3bb99fe2 | 1327 | e_dbg("NVM Read Error\n"); |
bc7f75fa AK |
1328 | return ret_val; |
1329 | } | |
1330 | ||
1331 | if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) | |
1332 | *data = ID_LED_DEFAULT; | |
1333 | ||
1334 | return 0; | |
1335 | } | |
1336 | ||
1337 | /** | |
1338 | * e1000e_id_led_init - | |
1339 | * @hw: pointer to the HW structure | |
1340 | * | |
1341 | **/ | |
1342 | s32 e1000e_id_led_init(struct e1000_hw *hw) | |
1343 | { | |
1344 | struct e1000_mac_info *mac = &hw->mac; | |
1345 | s32 ret_val; | |
1346 | const u32 ledctl_mask = 0x000000FF; | |
1347 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; | |
1348 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; | |
1349 | u16 data, i, temp; | |
1350 | const u16 led_mask = 0x0F; | |
1351 | ||
1352 | ret_val = hw->nvm.ops.valid_led_default(hw, &data); | |
1353 | if (ret_val) | |
1354 | return ret_val; | |
1355 | ||
1356 | mac->ledctl_default = er32(LEDCTL); | |
1357 | mac->ledctl_mode1 = mac->ledctl_default; | |
1358 | mac->ledctl_mode2 = mac->ledctl_default; | |
1359 | ||
1360 | for (i = 0; i < 4; i++) { | |
1361 | temp = (data >> (i << 2)) & led_mask; | |
1362 | switch (temp) { | |
1363 | case ID_LED_ON1_DEF2: | |
1364 | case ID_LED_ON1_ON2: | |
1365 | case ID_LED_ON1_OFF2: | |
1366 | mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); | |
1367 | mac->ledctl_mode1 |= ledctl_on << (i << 3); | |
1368 | break; | |
1369 | case ID_LED_OFF1_DEF2: | |
1370 | case ID_LED_OFF1_ON2: | |
1371 | case ID_LED_OFF1_OFF2: | |
1372 | mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); | |
1373 | mac->ledctl_mode1 |= ledctl_off << (i << 3); | |
1374 | break; | |
1375 | default: | |
1376 | /* Do nothing */ | |
1377 | break; | |
1378 | } | |
1379 | switch (temp) { | |
1380 | case ID_LED_DEF1_ON2: | |
1381 | case ID_LED_ON1_ON2: | |
1382 | case ID_LED_OFF1_ON2: | |
1383 | mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); | |
1384 | mac->ledctl_mode2 |= ledctl_on << (i << 3); | |
1385 | break; | |
1386 | case ID_LED_DEF1_OFF2: | |
1387 | case ID_LED_ON1_OFF2: | |
1388 | case ID_LED_OFF1_OFF2: | |
1389 | mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); | |
1390 | mac->ledctl_mode2 |= ledctl_off << (i << 3); | |
1391 | break; | |
1392 | default: | |
1393 | /* Do nothing */ | |
1394 | break; | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | return 0; | |
1399 | } | |
1400 | ||
a4f58f54 BA |
1401 | /** |
1402 | * e1000e_setup_led_generic - Configures SW controllable LED | |
1403 | * @hw: pointer to the HW structure | |
1404 | * | |
1405 | * This prepares the SW controllable LED for use and saves the current state | |
1406 | * of the LED so it can be later restored. | |
1407 | **/ | |
1408 | s32 e1000e_setup_led_generic(struct e1000_hw *hw) | |
1409 | { | |
1410 | u32 ledctl; | |
1411 | ||
1412 | if (hw->mac.ops.setup_led != e1000e_setup_led_generic) { | |
1413 | return -E1000_ERR_CONFIG; | |
1414 | } | |
1415 | ||
1416 | if (hw->phy.media_type == e1000_media_type_fiber) { | |
1417 | ledctl = er32(LEDCTL); | |
1418 | hw->mac.ledctl_default = ledctl; | |
1419 | /* Turn off LED0 */ | |
1420 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | | |
1421 | E1000_LEDCTL_LED0_BLINK | | |
1422 | E1000_LEDCTL_LED0_MODE_MASK); | |
1423 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << | |
1424 | E1000_LEDCTL_LED0_MODE_SHIFT); | |
1425 | ew32(LEDCTL, ledctl); | |
1426 | } else if (hw->phy.media_type == e1000_media_type_copper) { | |
1427 | ew32(LEDCTL, hw->mac.ledctl_mode1); | |
1428 | } | |
1429 | ||
1430 | return 0; | |
1431 | } | |
1432 | ||
bc7f75fa AK |
1433 | /** |
1434 | * e1000e_cleanup_led_generic - Set LED config to default operation | |
1435 | * @hw: pointer to the HW structure | |
1436 | * | |
1437 | * Remove the current LED configuration and set the LED configuration | |
1438 | * to the default value, saved from the EEPROM. | |
1439 | **/ | |
1440 | s32 e1000e_cleanup_led_generic(struct e1000_hw *hw) | |
1441 | { | |
1442 | ew32(LEDCTL, hw->mac.ledctl_default); | |
1443 | return 0; | |
1444 | } | |
1445 | ||
1446 | /** | |
1447 | * e1000e_blink_led - Blink LED | |
1448 | * @hw: pointer to the HW structure | |
1449 | * | |
489815ce | 1450 | * Blink the LEDs which are set to be on. |
bc7f75fa AK |
1451 | **/ |
1452 | s32 e1000e_blink_led(struct e1000_hw *hw) | |
1453 | { | |
1454 | u32 ledctl_blink = 0; | |
1455 | u32 i; | |
1456 | ||
318a94d6 | 1457 | if (hw->phy.media_type == e1000_media_type_fiber) { |
bc7f75fa AK |
1458 | /* always blink LED0 for PCI-E fiber */ |
1459 | ledctl_blink = E1000_LEDCTL_LED0_BLINK | | |
1460 | (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT); | |
1461 | } else { | |
ad68076e BA |
1462 | /* |
1463 | * set the blink bit for each LED that's "on" (0x0E) | |
1464 | * in ledctl_mode2 | |
1465 | */ | |
bc7f75fa AK |
1466 | ledctl_blink = hw->mac.ledctl_mode2; |
1467 | for (i = 0; i < 4; i++) | |
1468 | if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) == | |
1469 | E1000_LEDCTL_MODE_LED_ON) | |
1470 | ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << | |
1471 | (i * 8)); | |
1472 | } | |
1473 | ||
1474 | ew32(LEDCTL, ledctl_blink); | |
1475 | ||
1476 | return 0; | |
1477 | } | |
1478 | ||
1479 | /** | |
1480 | * e1000e_led_on_generic - Turn LED on | |
1481 | * @hw: pointer to the HW structure | |
1482 | * | |
1483 | * Turn LED on. | |
1484 | **/ | |
1485 | s32 e1000e_led_on_generic(struct e1000_hw *hw) | |
1486 | { | |
1487 | u32 ctrl; | |
1488 | ||
318a94d6 | 1489 | switch (hw->phy.media_type) { |
bc7f75fa AK |
1490 | case e1000_media_type_fiber: |
1491 | ctrl = er32(CTRL); | |
1492 | ctrl &= ~E1000_CTRL_SWDPIN0; | |
1493 | ctrl |= E1000_CTRL_SWDPIO0; | |
1494 | ew32(CTRL, ctrl); | |
1495 | break; | |
1496 | case e1000_media_type_copper: | |
1497 | ew32(LEDCTL, hw->mac.ledctl_mode2); | |
1498 | break; | |
1499 | default: | |
1500 | break; | |
1501 | } | |
1502 | ||
1503 | return 0; | |
1504 | } | |
1505 | ||
1506 | /** | |
1507 | * e1000e_led_off_generic - Turn LED off | |
1508 | * @hw: pointer to the HW structure | |
1509 | * | |
1510 | * Turn LED off. | |
1511 | **/ | |
1512 | s32 e1000e_led_off_generic(struct e1000_hw *hw) | |
1513 | { | |
1514 | u32 ctrl; | |
1515 | ||
318a94d6 | 1516 | switch (hw->phy.media_type) { |
bc7f75fa AK |
1517 | case e1000_media_type_fiber: |
1518 | ctrl = er32(CTRL); | |
1519 | ctrl |= E1000_CTRL_SWDPIN0; | |
1520 | ctrl |= E1000_CTRL_SWDPIO0; | |
1521 | ew32(CTRL, ctrl); | |
1522 | break; | |
1523 | case e1000_media_type_copper: | |
1524 | ew32(LEDCTL, hw->mac.ledctl_mode1); | |
1525 | break; | |
1526 | default: | |
1527 | break; | |
1528 | } | |
1529 | ||
1530 | return 0; | |
1531 | } | |
1532 | ||
1533 | /** | |
1534 | * e1000e_set_pcie_no_snoop - Set PCI-express capabilities | |
1535 | * @hw: pointer to the HW structure | |
1536 | * @no_snoop: bitmap of snoop events | |
1537 | * | |
1538 | * Set the PCI-express register to snoop for events enabled in 'no_snoop'. | |
1539 | **/ | |
1540 | void e1000e_set_pcie_no_snoop(struct e1000_hw *hw, u32 no_snoop) | |
1541 | { | |
1542 | u32 gcr; | |
1543 | ||
1544 | if (no_snoop) { | |
1545 | gcr = er32(GCR); | |
1546 | gcr &= ~(PCIE_NO_SNOOP_ALL); | |
1547 | gcr |= no_snoop; | |
1548 | ew32(GCR, gcr); | |
1549 | } | |
1550 | } | |
1551 | ||
1552 | /** | |
1553 | * e1000e_disable_pcie_master - Disables PCI-express master access | |
1554 | * @hw: pointer to the HW structure | |
1555 | * | |
1556 | * Returns 0 if successful, else returns -10 | |
489815ce | 1557 | * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused |
bc7f75fa AK |
1558 | * the master requests to be disabled. |
1559 | * | |
1560 | * Disables PCI-Express master access and verifies there are no pending | |
1561 | * requests. | |
1562 | **/ | |
1563 | s32 e1000e_disable_pcie_master(struct e1000_hw *hw) | |
1564 | { | |
1565 | u32 ctrl; | |
1566 | s32 timeout = MASTER_DISABLE_TIMEOUT; | |
1567 | ||
1568 | ctrl = er32(CTRL); | |
1569 | ctrl |= E1000_CTRL_GIO_MASTER_DISABLE; | |
1570 | ew32(CTRL, ctrl); | |
1571 | ||
1572 | while (timeout) { | |
1573 | if (!(er32(STATUS) & | |
1574 | E1000_STATUS_GIO_MASTER_ENABLE)) | |
1575 | break; | |
1576 | udelay(100); | |
1577 | timeout--; | |
1578 | } | |
1579 | ||
1580 | if (!timeout) { | |
3bb99fe2 | 1581 | e_dbg("Master requests are pending.\n"); |
bc7f75fa AK |
1582 | return -E1000_ERR_MASTER_REQUESTS_PENDING; |
1583 | } | |
1584 | ||
1585 | return 0; | |
1586 | } | |
1587 | ||
1588 | /** | |
1589 | * e1000e_reset_adaptive - Reset Adaptive Interframe Spacing | |
1590 | * @hw: pointer to the HW structure | |
1591 | * | |
1592 | * Reset the Adaptive Interframe Spacing throttle to default values. | |
1593 | **/ | |
1594 | void e1000e_reset_adaptive(struct e1000_hw *hw) | |
1595 | { | |
1596 | struct e1000_mac_info *mac = &hw->mac; | |
1597 | ||
1598 | mac->current_ifs_val = 0; | |
1599 | mac->ifs_min_val = IFS_MIN; | |
1600 | mac->ifs_max_val = IFS_MAX; | |
1601 | mac->ifs_step_size = IFS_STEP; | |
1602 | mac->ifs_ratio = IFS_RATIO; | |
1603 | ||
564ea9bb | 1604 | mac->in_ifs_mode = false; |
bc7f75fa AK |
1605 | ew32(AIT, 0); |
1606 | } | |
1607 | ||
1608 | /** | |
1609 | * e1000e_update_adaptive - Update Adaptive Interframe Spacing | |
1610 | * @hw: pointer to the HW structure | |
1611 | * | |
1612 | * Update the Adaptive Interframe Spacing Throttle value based on the | |
1613 | * time between transmitted packets and time between collisions. | |
1614 | **/ | |
1615 | void e1000e_update_adaptive(struct e1000_hw *hw) | |
1616 | { | |
1617 | struct e1000_mac_info *mac = &hw->mac; | |
1618 | ||
1619 | if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) { | |
1620 | if (mac->tx_packet_delta > MIN_NUM_XMITS) { | |
564ea9bb | 1621 | mac->in_ifs_mode = true; |
bc7f75fa AK |
1622 | if (mac->current_ifs_val < mac->ifs_max_val) { |
1623 | if (!mac->current_ifs_val) | |
1624 | mac->current_ifs_val = mac->ifs_min_val; | |
1625 | else | |
1626 | mac->current_ifs_val += | |
1627 | mac->ifs_step_size; | |
ad68076e | 1628 | ew32(AIT, mac->current_ifs_val); |
bc7f75fa AK |
1629 | } |
1630 | } | |
1631 | } else { | |
1632 | if (mac->in_ifs_mode && | |
1633 | (mac->tx_packet_delta <= MIN_NUM_XMITS)) { | |
1634 | mac->current_ifs_val = 0; | |
564ea9bb | 1635 | mac->in_ifs_mode = false; |
bc7f75fa AK |
1636 | ew32(AIT, 0); |
1637 | } | |
1638 | } | |
1639 | } | |
1640 | ||
1641 | /** | |
1642 | * e1000_raise_eec_clk - Raise EEPROM clock | |
1643 | * @hw: pointer to the HW structure | |
1644 | * @eecd: pointer to the EEPROM | |
1645 | * | |
1646 | * Enable/Raise the EEPROM clock bit. | |
1647 | **/ | |
1648 | static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd) | |
1649 | { | |
1650 | *eecd = *eecd | E1000_EECD_SK; | |
1651 | ew32(EECD, *eecd); | |
1652 | e1e_flush(); | |
1653 | udelay(hw->nvm.delay_usec); | |
1654 | } | |
1655 | ||
1656 | /** | |
1657 | * e1000_lower_eec_clk - Lower EEPROM clock | |
1658 | * @hw: pointer to the HW structure | |
1659 | * @eecd: pointer to the EEPROM | |
1660 | * | |
1661 | * Clear/Lower the EEPROM clock bit. | |
1662 | **/ | |
1663 | static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd) | |
1664 | { | |
1665 | *eecd = *eecd & ~E1000_EECD_SK; | |
1666 | ew32(EECD, *eecd); | |
1667 | e1e_flush(); | |
1668 | udelay(hw->nvm.delay_usec); | |
1669 | } | |
1670 | ||
1671 | /** | |
1672 | * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM | |
1673 | * @hw: pointer to the HW structure | |
1674 | * @data: data to send to the EEPROM | |
1675 | * @count: number of bits to shift out | |
1676 | * | |
1677 | * We need to shift 'count' bits out to the EEPROM. So, the value in the | |
1678 | * "data" parameter will be shifted out to the EEPROM one bit at a time. | |
1679 | * In order to do this, "data" must be broken down into bits. | |
1680 | **/ | |
1681 | static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count) | |
1682 | { | |
1683 | struct e1000_nvm_info *nvm = &hw->nvm; | |
1684 | u32 eecd = er32(EECD); | |
1685 | u32 mask; | |
1686 | ||
1687 | mask = 0x01 << (count - 1); | |
1688 | if (nvm->type == e1000_nvm_eeprom_spi) | |
1689 | eecd |= E1000_EECD_DO; | |
1690 | ||
1691 | do { | |
1692 | eecd &= ~E1000_EECD_DI; | |
1693 | ||
1694 | if (data & mask) | |
1695 | eecd |= E1000_EECD_DI; | |
1696 | ||
1697 | ew32(EECD, eecd); | |
1698 | e1e_flush(); | |
1699 | ||
1700 | udelay(nvm->delay_usec); | |
1701 | ||
1702 | e1000_raise_eec_clk(hw, &eecd); | |
1703 | e1000_lower_eec_clk(hw, &eecd); | |
1704 | ||
1705 | mask >>= 1; | |
1706 | } while (mask); | |
1707 | ||
1708 | eecd &= ~E1000_EECD_DI; | |
1709 | ew32(EECD, eecd); | |
1710 | } | |
1711 | ||
1712 | /** | |
1713 | * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM | |
1714 | * @hw: pointer to the HW structure | |
1715 | * @count: number of bits to shift in | |
1716 | * | |
1717 | * In order to read a register from the EEPROM, we need to shift 'count' bits | |
1718 | * in from the EEPROM. Bits are "shifted in" by raising the clock input to | |
1719 | * the EEPROM (setting the SK bit), and then reading the value of the data out | |
1720 | * "DO" bit. During this "shifting in" process the data in "DI" bit should | |
1721 | * always be clear. | |
1722 | **/ | |
1723 | static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count) | |
1724 | { | |
1725 | u32 eecd; | |
1726 | u32 i; | |
1727 | u16 data; | |
1728 | ||
1729 | eecd = er32(EECD); | |
1730 | ||
1731 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); | |
1732 | data = 0; | |
1733 | ||
1734 | for (i = 0; i < count; i++) { | |
1735 | data <<= 1; | |
1736 | e1000_raise_eec_clk(hw, &eecd); | |
1737 | ||
1738 | eecd = er32(EECD); | |
1739 | ||
1740 | eecd &= ~E1000_EECD_DI; | |
1741 | if (eecd & E1000_EECD_DO) | |
1742 | data |= 1; | |
1743 | ||
1744 | e1000_lower_eec_clk(hw, &eecd); | |
1745 | } | |
1746 | ||
1747 | return data; | |
1748 | } | |
1749 | ||
1750 | /** | |
1751 | * e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion | |
1752 | * @hw: pointer to the HW structure | |
1753 | * @ee_reg: EEPROM flag for polling | |
1754 | * | |
1755 | * Polls the EEPROM status bit for either read or write completion based | |
1756 | * upon the value of 'ee_reg'. | |
1757 | **/ | |
1758 | s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg) | |
1759 | { | |
1760 | u32 attempts = 100000; | |
1761 | u32 i, reg = 0; | |
1762 | ||
1763 | for (i = 0; i < attempts; i++) { | |
1764 | if (ee_reg == E1000_NVM_POLL_READ) | |
1765 | reg = er32(EERD); | |
1766 | else | |
1767 | reg = er32(EEWR); | |
1768 | ||
1769 | if (reg & E1000_NVM_RW_REG_DONE) | |
1770 | return 0; | |
1771 | ||
1772 | udelay(5); | |
1773 | } | |
1774 | ||
1775 | return -E1000_ERR_NVM; | |
1776 | } | |
1777 | ||
1778 | /** | |
1779 | * e1000e_acquire_nvm - Generic request for access to EEPROM | |
1780 | * @hw: pointer to the HW structure | |
1781 | * | |
1782 | * Set the EEPROM access request bit and wait for EEPROM access grant bit. | |
1783 | * Return successful if access grant bit set, else clear the request for | |
1784 | * EEPROM access and return -E1000_ERR_NVM (-1). | |
1785 | **/ | |
1786 | s32 e1000e_acquire_nvm(struct e1000_hw *hw) | |
1787 | { | |
1788 | u32 eecd = er32(EECD); | |
1789 | s32 timeout = E1000_NVM_GRANT_ATTEMPTS; | |
1790 | ||
1791 | ew32(EECD, eecd | E1000_EECD_REQ); | |
1792 | eecd = er32(EECD); | |
1793 | ||
1794 | while (timeout) { | |
1795 | if (eecd & E1000_EECD_GNT) | |
1796 | break; | |
1797 | udelay(5); | |
1798 | eecd = er32(EECD); | |
1799 | timeout--; | |
1800 | } | |
1801 | ||
1802 | if (!timeout) { | |
1803 | eecd &= ~E1000_EECD_REQ; | |
1804 | ew32(EECD, eecd); | |
3bb99fe2 | 1805 | e_dbg("Could not acquire NVM grant\n"); |
bc7f75fa AK |
1806 | return -E1000_ERR_NVM; |
1807 | } | |
1808 | ||
1809 | return 0; | |
1810 | } | |
1811 | ||
1812 | /** | |
1813 | * e1000_standby_nvm - Return EEPROM to standby state | |
1814 | * @hw: pointer to the HW structure | |
1815 | * | |
1816 | * Return the EEPROM to a standby state. | |
1817 | **/ | |
1818 | static void e1000_standby_nvm(struct e1000_hw *hw) | |
1819 | { | |
1820 | struct e1000_nvm_info *nvm = &hw->nvm; | |
1821 | u32 eecd = er32(EECD); | |
1822 | ||
1823 | if (nvm->type == e1000_nvm_eeprom_spi) { | |
1824 | /* Toggle CS to flush commands */ | |
1825 | eecd |= E1000_EECD_CS; | |
1826 | ew32(EECD, eecd); | |
1827 | e1e_flush(); | |
1828 | udelay(nvm->delay_usec); | |
1829 | eecd &= ~E1000_EECD_CS; | |
1830 | ew32(EECD, eecd); | |
1831 | e1e_flush(); | |
1832 | udelay(nvm->delay_usec); | |
1833 | } | |
1834 | } | |
1835 | ||
1836 | /** | |
1837 | * e1000_stop_nvm - Terminate EEPROM command | |
1838 | * @hw: pointer to the HW structure | |
1839 | * | |
1840 | * Terminates the current command by inverting the EEPROM's chip select pin. | |
1841 | **/ | |
1842 | static void e1000_stop_nvm(struct e1000_hw *hw) | |
1843 | { | |
1844 | u32 eecd; | |
1845 | ||
1846 | eecd = er32(EECD); | |
1847 | if (hw->nvm.type == e1000_nvm_eeprom_spi) { | |
1848 | /* Pull CS high */ | |
1849 | eecd |= E1000_EECD_CS; | |
1850 | e1000_lower_eec_clk(hw, &eecd); | |
1851 | } | |
1852 | } | |
1853 | ||
1854 | /** | |
1855 | * e1000e_release_nvm - Release exclusive access to EEPROM | |
1856 | * @hw: pointer to the HW structure | |
1857 | * | |
1858 | * Stop any current commands to the EEPROM and clear the EEPROM request bit. | |
1859 | **/ | |
1860 | void e1000e_release_nvm(struct e1000_hw *hw) | |
1861 | { | |
1862 | u32 eecd; | |
1863 | ||
1864 | e1000_stop_nvm(hw); | |
1865 | ||
1866 | eecd = er32(EECD); | |
1867 | eecd &= ~E1000_EECD_REQ; | |
1868 | ew32(EECD, eecd); | |
1869 | } | |
1870 | ||
1871 | /** | |
1872 | * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write | |
1873 | * @hw: pointer to the HW structure | |
1874 | * | |
1875 | * Setups the EEPROM for reading and writing. | |
1876 | **/ | |
1877 | static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw) | |
1878 | { | |
1879 | struct e1000_nvm_info *nvm = &hw->nvm; | |
1880 | u32 eecd = er32(EECD); | |
1881 | u16 timeout = 0; | |
1882 | u8 spi_stat_reg; | |
1883 | ||
1884 | if (nvm->type == e1000_nvm_eeprom_spi) { | |
1885 | /* Clear SK and CS */ | |
1886 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); | |
1887 | ew32(EECD, eecd); | |
1888 | udelay(1); | |
1889 | timeout = NVM_MAX_RETRY_SPI; | |
1890 | ||
ad68076e BA |
1891 | /* |
1892 | * Read "Status Register" repeatedly until the LSB is cleared. | |
bc7f75fa AK |
1893 | * The EEPROM will signal that the command has been completed |
1894 | * by clearing bit 0 of the internal status register. If it's | |
ad68076e BA |
1895 | * not cleared within 'timeout', then error out. |
1896 | */ | |
bc7f75fa AK |
1897 | while (timeout) { |
1898 | e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI, | |
1899 | hw->nvm.opcode_bits); | |
1900 | spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8); | |
1901 | if (!(spi_stat_reg & NVM_STATUS_RDY_SPI)) | |
1902 | break; | |
1903 | ||
1904 | udelay(5); | |
1905 | e1000_standby_nvm(hw); | |
1906 | timeout--; | |
1907 | } | |
1908 | ||
1909 | if (!timeout) { | |
3bb99fe2 | 1910 | e_dbg("SPI NVM Status error\n"); |
bc7f75fa AK |
1911 | return -E1000_ERR_NVM; |
1912 | } | |
1913 | } | |
1914 | ||
1915 | return 0; | |
1916 | } | |
1917 | ||
bc7f75fa AK |
1918 | /** |
1919 | * e1000e_read_nvm_eerd - Reads EEPROM using EERD register | |
1920 | * @hw: pointer to the HW structure | |
1921 | * @offset: offset of word in the EEPROM to read | |
1922 | * @words: number of words to read | |
1923 | * @data: word read from the EEPROM | |
1924 | * | |
1925 | * Reads a 16 bit word from the EEPROM using the EERD register. | |
1926 | **/ | |
1927 | s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) | |
1928 | { | |
1929 | struct e1000_nvm_info *nvm = &hw->nvm; | |
1930 | u32 i, eerd = 0; | |
1931 | s32 ret_val = 0; | |
1932 | ||
ad68076e BA |
1933 | /* |
1934 | * A check for invalid values: offset too large, too many words, | |
1935 | * too many words for the offset, and not enough words. | |
1936 | */ | |
bc7f75fa AK |
1937 | if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || |
1938 | (words == 0)) { | |
3bb99fe2 | 1939 | e_dbg("nvm parameter(s) out of bounds\n"); |
bc7f75fa AK |
1940 | return -E1000_ERR_NVM; |
1941 | } | |
1942 | ||
1943 | for (i = 0; i < words; i++) { | |
1944 | eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) + | |
1945 | E1000_NVM_RW_REG_START; | |
1946 | ||
1947 | ew32(EERD, eerd); | |
1948 | ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ); | |
1949 | if (ret_val) | |
1950 | break; | |
1951 | ||
ad68076e | 1952 | data[i] = (er32(EERD) >> E1000_NVM_RW_REG_DATA); |
bc7f75fa AK |
1953 | } |
1954 | ||
1955 | return ret_val; | |
1956 | } | |
1957 | ||
1958 | /** | |
1959 | * e1000e_write_nvm_spi - Write to EEPROM using SPI | |
1960 | * @hw: pointer to the HW structure | |
1961 | * @offset: offset within the EEPROM to be written to | |
1962 | * @words: number of words to write | |
1963 | * @data: 16 bit word(s) to be written to the EEPROM | |
1964 | * | |
1965 | * Writes data to EEPROM at offset using SPI interface. | |
1966 | * | |
1967 | * If e1000e_update_nvm_checksum is not called after this function , the | |
489815ce | 1968 | * EEPROM will most likely contain an invalid checksum. |
bc7f75fa AK |
1969 | **/ |
1970 | s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) | |
1971 | { | |
1972 | struct e1000_nvm_info *nvm = &hw->nvm; | |
1973 | s32 ret_val; | |
1974 | u16 widx = 0; | |
1975 | ||
ad68076e BA |
1976 | /* |
1977 | * A check for invalid values: offset too large, too many words, | |
1978 | * and not enough words. | |
1979 | */ | |
bc7f75fa AK |
1980 | if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || |
1981 | (words == 0)) { | |
3bb99fe2 | 1982 | e_dbg("nvm parameter(s) out of bounds\n"); |
bc7f75fa AK |
1983 | return -E1000_ERR_NVM; |
1984 | } | |
1985 | ||
94d8186a | 1986 | ret_val = nvm->ops.acquire(hw); |
bc7f75fa AK |
1987 | if (ret_val) |
1988 | return ret_val; | |
1989 | ||
1990 | msleep(10); | |
1991 | ||
1992 | while (widx < words) { | |
1993 | u8 write_opcode = NVM_WRITE_OPCODE_SPI; | |
1994 | ||
1995 | ret_val = e1000_ready_nvm_eeprom(hw); | |
1996 | if (ret_val) { | |
94d8186a | 1997 | nvm->ops.release(hw); |
bc7f75fa AK |
1998 | return ret_val; |
1999 | } | |
2000 | ||
2001 | e1000_standby_nvm(hw); | |
2002 | ||
2003 | /* Send the WRITE ENABLE command (8 bit opcode) */ | |
2004 | e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI, | |
2005 | nvm->opcode_bits); | |
2006 | ||
2007 | e1000_standby_nvm(hw); | |
2008 | ||
ad68076e BA |
2009 | /* |
2010 | * Some SPI eeproms use the 8th address bit embedded in the | |
2011 | * opcode | |
2012 | */ | |
bc7f75fa AK |
2013 | if ((nvm->address_bits == 8) && (offset >= 128)) |
2014 | write_opcode |= NVM_A8_OPCODE_SPI; | |
2015 | ||
2016 | /* Send the Write command (8-bit opcode + addr) */ | |
2017 | e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits); | |
2018 | e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2), | |
2019 | nvm->address_bits); | |
2020 | ||
2021 | /* Loop to allow for up to whole page write of eeprom */ | |
2022 | while (widx < words) { | |
2023 | u16 word_out = data[widx]; | |
2024 | word_out = (word_out >> 8) | (word_out << 8); | |
2025 | e1000_shift_out_eec_bits(hw, word_out, 16); | |
2026 | widx++; | |
2027 | ||
2028 | if ((((offset + widx) * 2) % nvm->page_size) == 0) { | |
2029 | e1000_standby_nvm(hw); | |
2030 | break; | |
2031 | } | |
2032 | } | |
2033 | } | |
2034 | ||
2035 | msleep(10); | |
94d8186a | 2036 | nvm->ops.release(hw); |
bc7f75fa AK |
2037 | return 0; |
2038 | } | |
2039 | ||
2040 | /** | |
2041 | * e1000e_read_mac_addr - Read device MAC address | |
2042 | * @hw: pointer to the HW structure | |
2043 | * | |
2044 | * Reads the device MAC address from the EEPROM and stores the value. | |
2045 | * Since devices with two ports use the same EEPROM, we increment the | |
2046 | * last bit in the MAC address for the second port. | |
2047 | **/ | |
2048 | s32 e1000e_read_mac_addr(struct e1000_hw *hw) | |
2049 | { | |
2050 | s32 ret_val; | |
2051 | u16 offset, nvm_data, i; | |
93ca1610 BH |
2052 | u16 mac_addr_offset = 0; |
2053 | ||
2054 | if (hw->mac.type == e1000_82571) { | |
2055 | /* Check for an alternate MAC address. An alternate MAC | |
2056 | * address can be setup by pre-boot software and must be | |
2057 | * treated like a permanent address and must override the | |
ad68076e | 2058 | * actual permanent MAC address.*/ |
93ca1610 | 2059 | ret_val = e1000_read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1, |
ad68076e | 2060 | &mac_addr_offset); |
93ca1610 | 2061 | if (ret_val) { |
3bb99fe2 | 2062 | e_dbg("NVM Read Error\n"); |
93ca1610 BH |
2063 | return ret_val; |
2064 | } | |
2065 | if (mac_addr_offset == 0xFFFF) | |
2066 | mac_addr_offset = 0; | |
2067 | ||
2068 | if (mac_addr_offset) { | |
2069 | if (hw->bus.func == E1000_FUNC_1) | |
2070 | mac_addr_offset += ETH_ALEN/sizeof(u16); | |
2071 | ||
2072 | /* make sure we have a valid mac address here | |
ad68076e | 2073 | * before using it */ |
93ca1610 BH |
2074 | ret_val = e1000_read_nvm(hw, mac_addr_offset, 1, |
2075 | &nvm_data); | |
2076 | if (ret_val) { | |
3bb99fe2 | 2077 | e_dbg("NVM Read Error\n"); |
93ca1610 BH |
2078 | return ret_val; |
2079 | } | |
2080 | if (nvm_data & 0x0001) | |
2081 | mac_addr_offset = 0; | |
2082 | } | |
2083 | ||
2084 | if (mac_addr_offset) | |
ad68076e | 2085 | hw->dev_spec.e82571.alt_mac_addr_is_present = 1; |
93ca1610 | 2086 | } |
bc7f75fa AK |
2087 | |
2088 | for (i = 0; i < ETH_ALEN; i += 2) { | |
93ca1610 | 2089 | offset = mac_addr_offset + (i >> 1); |
bc7f75fa AK |
2090 | ret_val = e1000_read_nvm(hw, offset, 1, &nvm_data); |
2091 | if (ret_val) { | |
3bb99fe2 | 2092 | e_dbg("NVM Read Error\n"); |
bc7f75fa AK |
2093 | return ret_val; |
2094 | } | |
2095 | hw->mac.perm_addr[i] = (u8)(nvm_data & 0xFF); | |
2096 | hw->mac.perm_addr[i+1] = (u8)(nvm_data >> 8); | |
2097 | } | |
2098 | ||
2099 | /* Flip last bit of mac address if we're on second port */ | |
93ca1610 | 2100 | if (!mac_addr_offset && hw->bus.func == E1000_FUNC_1) |
bc7f75fa AK |
2101 | hw->mac.perm_addr[5] ^= 1; |
2102 | ||
2103 | for (i = 0; i < ETH_ALEN; i++) | |
2104 | hw->mac.addr[i] = hw->mac.perm_addr[i]; | |
2105 | ||
2106 | return 0; | |
2107 | } | |
2108 | ||
2109 | /** | |
2110 | * e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum | |
2111 | * @hw: pointer to the HW structure | |
2112 | * | |
2113 | * Calculates the EEPROM checksum by reading/adding each word of the EEPROM | |
2114 | * and then verifies that the sum of the EEPROM is equal to 0xBABA. | |
2115 | **/ | |
2116 | s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw) | |
2117 | { | |
2118 | s32 ret_val; | |
2119 | u16 checksum = 0; | |
2120 | u16 i, nvm_data; | |
2121 | ||
2122 | for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { | |
2123 | ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); | |
2124 | if (ret_val) { | |
3bb99fe2 | 2125 | e_dbg("NVM Read Error\n"); |
bc7f75fa AK |
2126 | return ret_val; |
2127 | } | |
2128 | checksum += nvm_data; | |
2129 | } | |
2130 | ||
2131 | if (checksum != (u16) NVM_SUM) { | |
3bb99fe2 | 2132 | e_dbg("NVM Checksum Invalid\n"); |
bc7f75fa AK |
2133 | return -E1000_ERR_NVM; |
2134 | } | |
2135 | ||
2136 | return 0; | |
2137 | } | |
2138 | ||
2139 | /** | |
2140 | * e1000e_update_nvm_checksum_generic - Update EEPROM checksum | |
2141 | * @hw: pointer to the HW structure | |
2142 | * | |
2143 | * Updates the EEPROM checksum by reading/adding each word of the EEPROM | |
2144 | * up to the checksum. Then calculates the EEPROM checksum and writes the | |
2145 | * value to the EEPROM. | |
2146 | **/ | |
2147 | s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw) | |
2148 | { | |
2149 | s32 ret_val; | |
2150 | u16 checksum = 0; | |
2151 | u16 i, nvm_data; | |
2152 | ||
2153 | for (i = 0; i < NVM_CHECKSUM_REG; i++) { | |
2154 | ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); | |
2155 | if (ret_val) { | |
3bb99fe2 | 2156 | e_dbg("NVM Read Error while updating checksum.\n"); |
bc7f75fa AK |
2157 | return ret_val; |
2158 | } | |
2159 | checksum += nvm_data; | |
2160 | } | |
2161 | checksum = (u16) NVM_SUM - checksum; | |
2162 | ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum); | |
2163 | if (ret_val) | |
3bb99fe2 | 2164 | e_dbg("NVM Write Error while updating checksum.\n"); |
bc7f75fa AK |
2165 | |
2166 | return ret_val; | |
2167 | } | |
2168 | ||
2169 | /** | |
2170 | * e1000e_reload_nvm - Reloads EEPROM | |
2171 | * @hw: pointer to the HW structure | |
2172 | * | |
2173 | * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the | |
2174 | * extended control register. | |
2175 | **/ | |
2176 | void e1000e_reload_nvm(struct e1000_hw *hw) | |
2177 | { | |
2178 | u32 ctrl_ext; | |
2179 | ||
2180 | udelay(10); | |
2181 | ctrl_ext = er32(CTRL_EXT); | |
2182 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; | |
2183 | ew32(CTRL_EXT, ctrl_ext); | |
2184 | e1e_flush(); | |
2185 | } | |
2186 | ||
2187 | /** | |
2188 | * e1000_calculate_checksum - Calculate checksum for buffer | |
2189 | * @buffer: pointer to EEPROM | |
2190 | * @length: size of EEPROM to calculate a checksum for | |
2191 | * | |
2192 | * Calculates the checksum for some buffer on a specified length. The | |
2193 | * checksum calculated is returned. | |
2194 | **/ | |
2195 | static u8 e1000_calculate_checksum(u8 *buffer, u32 length) | |
2196 | { | |
2197 | u32 i; | |
2198 | u8 sum = 0; | |
2199 | ||
2200 | if (!buffer) | |
2201 | return 0; | |
2202 | ||
2203 | for (i = 0; i < length; i++) | |
2204 | sum += buffer[i]; | |
2205 | ||
2206 | return (u8) (0 - sum); | |
2207 | } | |
2208 | ||
2209 | /** | |
2210 | * e1000_mng_enable_host_if - Checks host interface is enabled | |
2211 | * @hw: pointer to the HW structure | |
2212 | * | |
2213 | * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND | |
2214 | * | |
489815ce | 2215 | * This function checks whether the HOST IF is enabled for command operation |
bc7f75fa AK |
2216 | * and also checks whether the previous command is completed. It busy waits |
2217 | * in case of previous command is not completed. | |
2218 | **/ | |
2219 | static s32 e1000_mng_enable_host_if(struct e1000_hw *hw) | |
2220 | { | |
2221 | u32 hicr; | |
2222 | u8 i; | |
2223 | ||
2224 | /* Check that the host interface is enabled. */ | |
2225 | hicr = er32(HICR); | |
2226 | if ((hicr & E1000_HICR_EN) == 0) { | |
3bb99fe2 | 2227 | e_dbg("E1000_HOST_EN bit disabled.\n"); |
bc7f75fa AK |
2228 | return -E1000_ERR_HOST_INTERFACE_COMMAND; |
2229 | } | |
2230 | /* check the previous command is completed */ | |
2231 | for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) { | |
2232 | hicr = er32(HICR); | |
2233 | if (!(hicr & E1000_HICR_C)) | |
2234 | break; | |
2235 | mdelay(1); | |
2236 | } | |
2237 | ||
2238 | if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) { | |
3bb99fe2 | 2239 | e_dbg("Previous command timeout failed .\n"); |
bc7f75fa AK |
2240 | return -E1000_ERR_HOST_INTERFACE_COMMAND; |
2241 | } | |
2242 | ||
2243 | return 0; | |
2244 | } | |
2245 | ||
2246 | /** | |
4662e82b | 2247 | * e1000e_check_mng_mode_generic - check management mode |
bc7f75fa AK |
2248 | * @hw: pointer to the HW structure |
2249 | * | |
2250 | * Reads the firmware semaphore register and returns true (>0) if | |
2251 | * manageability is enabled, else false (0). | |
2252 | **/ | |
4662e82b | 2253 | bool e1000e_check_mng_mode_generic(struct e1000_hw *hw) |
bc7f75fa AK |
2254 | { |
2255 | u32 fwsm = er32(FWSM); | |
2256 | ||
4662e82b BA |
2257 | return (fwsm & E1000_FWSM_MODE_MASK) == |
2258 | (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT); | |
bc7f75fa AK |
2259 | } |
2260 | ||
2261 | /** | |
ad68076e | 2262 | * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx |
bc7f75fa AK |
2263 | * @hw: pointer to the HW structure |
2264 | * | |
2265 | * Enables packet filtering on transmit packets if manageability is enabled | |
2266 | * and host interface is enabled. | |
2267 | **/ | |
2268 | bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw) | |
2269 | { | |
2270 | struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie; | |
2271 | u32 *buffer = (u32 *)&hw->mng_cookie; | |
2272 | u32 offset; | |
2273 | s32 ret_val, hdr_csum, csum; | |
2274 | u8 i, len; | |
2275 | ||
2276 | /* No manageability, no filtering */ | |
2277 | if (!e1000e_check_mng_mode(hw)) { | |
564ea9bb | 2278 | hw->mac.tx_pkt_filtering = false; |
bc7f75fa AK |
2279 | return 0; |
2280 | } | |
2281 | ||
ad68076e BA |
2282 | /* |
2283 | * If we can't read from the host interface for whatever | |
bc7f75fa AK |
2284 | * reason, disable filtering. |
2285 | */ | |
2286 | ret_val = e1000_mng_enable_host_if(hw); | |
2287 | if (ret_val != 0) { | |
564ea9bb | 2288 | hw->mac.tx_pkt_filtering = false; |
bc7f75fa AK |
2289 | return ret_val; |
2290 | } | |
2291 | ||
2292 | /* Read in the header. Length and offset are in dwords. */ | |
2293 | len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2; | |
2294 | offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2; | |
2295 | for (i = 0; i < len; i++) | |
2296 | *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset + i); | |
2297 | hdr_csum = hdr->checksum; | |
2298 | hdr->checksum = 0; | |
2299 | csum = e1000_calculate_checksum((u8 *)hdr, | |
2300 | E1000_MNG_DHCP_COOKIE_LENGTH); | |
ad68076e BA |
2301 | /* |
2302 | * If either the checksums or signature don't match, then | |
bc7f75fa AK |
2303 | * the cookie area isn't considered valid, in which case we |
2304 | * take the safe route of assuming Tx filtering is enabled. | |
2305 | */ | |
2306 | if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) { | |
564ea9bb | 2307 | hw->mac.tx_pkt_filtering = true; |
bc7f75fa AK |
2308 | return 1; |
2309 | } | |
2310 | ||
2311 | /* Cookie area is valid, make the final check for filtering. */ | |
2312 | if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) { | |
564ea9bb | 2313 | hw->mac.tx_pkt_filtering = false; |
bc7f75fa AK |
2314 | return 0; |
2315 | } | |
2316 | ||
564ea9bb | 2317 | hw->mac.tx_pkt_filtering = true; |
bc7f75fa AK |
2318 | return 1; |
2319 | } | |
2320 | ||
2321 | /** | |
2322 | * e1000_mng_write_cmd_header - Writes manageability command header | |
2323 | * @hw: pointer to the HW structure | |
2324 | * @hdr: pointer to the host interface command header | |
2325 | * | |
2326 | * Writes the command header after does the checksum calculation. | |
2327 | **/ | |
2328 | static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw, | |
2329 | struct e1000_host_mng_command_header *hdr) | |
2330 | { | |
2331 | u16 i, length = sizeof(struct e1000_host_mng_command_header); | |
2332 | ||
2333 | /* Write the whole command header structure with new checksum. */ | |
2334 | ||
2335 | hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length); | |
2336 | ||
2337 | length >>= 2; | |
2338 | /* Write the relevant command block into the ram area. */ | |
2339 | for (i = 0; i < length; i++) { | |
2340 | E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i, | |
2341 | *((u32 *) hdr + i)); | |
2342 | e1e_flush(); | |
2343 | } | |
2344 | ||
2345 | return 0; | |
2346 | } | |
2347 | ||
2348 | /** | |
2349 | * e1000_mng_host_if_write - Writes to the manageability host interface | |
2350 | * @hw: pointer to the HW structure | |
2351 | * @buffer: pointer to the host interface buffer | |
2352 | * @length: size of the buffer | |
2353 | * @offset: location in the buffer to write to | |
2354 | * @sum: sum of the data (not checksum) | |
2355 | * | |
2356 | * This function writes the buffer content at the offset given on the host if. | |
2357 | * It also does alignment considerations to do the writes in most efficient | |
2358 | * way. Also fills up the sum of the buffer in *buffer parameter. | |
2359 | **/ | |
2360 | static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, | |
2361 | u16 length, u16 offset, u8 *sum) | |
2362 | { | |
2363 | u8 *tmp; | |
2364 | u8 *bufptr = buffer; | |
2365 | u32 data = 0; | |
2366 | u16 remaining, i, j, prev_bytes; | |
2367 | ||
2368 | /* sum = only sum of the data and it is not checksum */ | |
2369 | ||
2370 | if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) | |
2371 | return -E1000_ERR_PARAM; | |
2372 | ||
2373 | tmp = (u8 *)&data; | |
2374 | prev_bytes = offset & 0x3; | |
2375 | offset >>= 2; | |
2376 | ||
2377 | if (prev_bytes) { | |
2378 | data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset); | |
2379 | for (j = prev_bytes; j < sizeof(u32); j++) { | |
2380 | *(tmp + j) = *bufptr++; | |
2381 | *sum += *(tmp + j); | |
2382 | } | |
2383 | E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data); | |
2384 | length -= j - prev_bytes; | |
2385 | offset++; | |
2386 | } | |
2387 | ||
2388 | remaining = length & 0x3; | |
2389 | length -= remaining; | |
2390 | ||
2391 | /* Calculate length in DWORDs */ | |
2392 | length >>= 2; | |
2393 | ||
ad68076e BA |
2394 | /* |
2395 | * The device driver writes the relevant command block into the | |
2396 | * ram area. | |
2397 | */ | |
bc7f75fa AK |
2398 | for (i = 0; i < length; i++) { |
2399 | for (j = 0; j < sizeof(u32); j++) { | |
2400 | *(tmp + j) = *bufptr++; | |
2401 | *sum += *(tmp + j); | |
2402 | } | |
2403 | ||
2404 | E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); | |
2405 | } | |
2406 | if (remaining) { | |
2407 | for (j = 0; j < sizeof(u32); j++) { | |
2408 | if (j < remaining) | |
2409 | *(tmp + j) = *bufptr++; | |
2410 | else | |
2411 | *(tmp + j) = 0; | |
2412 | ||
2413 | *sum += *(tmp + j); | |
2414 | } | |
2415 | E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); | |
2416 | } | |
2417 | ||
2418 | return 0; | |
2419 | } | |
2420 | ||
2421 | /** | |
2422 | * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface | |
2423 | * @hw: pointer to the HW structure | |
2424 | * @buffer: pointer to the host interface | |
2425 | * @length: size of the buffer | |
2426 | * | |
2427 | * Writes the DHCP information to the host interface. | |
2428 | **/ | |
2429 | s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length) | |
2430 | { | |
2431 | struct e1000_host_mng_command_header hdr; | |
2432 | s32 ret_val; | |
2433 | u32 hicr; | |
2434 | ||
2435 | hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD; | |
2436 | hdr.command_length = length; | |
2437 | hdr.reserved1 = 0; | |
2438 | hdr.reserved2 = 0; | |
2439 | hdr.checksum = 0; | |
2440 | ||
2441 | /* Enable the host interface */ | |
2442 | ret_val = e1000_mng_enable_host_if(hw); | |
2443 | if (ret_val) | |
2444 | return ret_val; | |
2445 | ||
2446 | /* Populate the host interface with the contents of "buffer". */ | |
2447 | ret_val = e1000_mng_host_if_write(hw, buffer, length, | |
2448 | sizeof(hdr), &(hdr.checksum)); | |
2449 | if (ret_val) | |
2450 | return ret_val; | |
2451 | ||
2452 | /* Write the manageability command header */ | |
2453 | ret_val = e1000_mng_write_cmd_header(hw, &hdr); | |
2454 | if (ret_val) | |
2455 | return ret_val; | |
2456 | ||
2457 | /* Tell the ARC a new command is pending. */ | |
2458 | hicr = er32(HICR); | |
2459 | ew32(HICR, hicr | E1000_HICR_C); | |
2460 | ||
2461 | return 0; | |
2462 | } | |
2463 | ||
2464 | /** | |
2465 | * e1000e_enable_mng_pass_thru - Enable processing of ARP's | |
2466 | * @hw: pointer to the HW structure | |
2467 | * | |
2468 | * Verifies the hardware needs to allow ARPs to be processed by the host. | |
2469 | **/ | |
2470 | bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw) | |
2471 | { | |
2472 | u32 manc; | |
2473 | u32 fwsm, factps; | |
564ea9bb | 2474 | bool ret_val = false; |
bc7f75fa AK |
2475 | |
2476 | manc = er32(MANC); | |
2477 | ||
2478 | if (!(manc & E1000_MANC_RCV_TCO_EN) || | |
2479 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) | |
2480 | return ret_val; | |
2481 | ||
2482 | if (hw->mac.arc_subsystem_valid) { | |
2483 | fwsm = er32(FWSM); | |
2484 | factps = er32(FACTPS); | |
2485 | ||
2486 | if (!(factps & E1000_FACTPS_MNGCG) && | |
2487 | ((fwsm & E1000_FWSM_MODE_MASK) == | |
2488 | (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) { | |
564ea9bb | 2489 | ret_val = true; |
bc7f75fa AK |
2490 | return ret_val; |
2491 | } | |
2492 | } else { | |
2493 | if ((manc & E1000_MANC_SMBUS_EN) && | |
2494 | !(manc & E1000_MANC_ASF_EN)) { | |
564ea9bb | 2495 | ret_val = true; |
bc7f75fa AK |
2496 | return ret_val; |
2497 | } | |
2498 | } | |
2499 | ||
2500 | return ret_val; | |
2501 | } | |
2502 | ||
69e3fd8c | 2503 | s32 e1000e_read_pba_num(struct e1000_hw *hw, u32 *pba_num) |
bc7f75fa AK |
2504 | { |
2505 | s32 ret_val; | |
2506 | u16 nvm_data; | |
2507 | ||
2508 | ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data); | |
2509 | if (ret_val) { | |
3bb99fe2 | 2510 | e_dbg("NVM Read Error\n"); |
bc7f75fa AK |
2511 | return ret_val; |
2512 | } | |
69e3fd8c | 2513 | *pba_num = (u32)(nvm_data << 16); |
bc7f75fa AK |
2514 | |
2515 | ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &nvm_data); | |
2516 | if (ret_val) { | |
3bb99fe2 | 2517 | e_dbg("NVM Read Error\n"); |
bc7f75fa AK |
2518 | return ret_val; |
2519 | } | |
69e3fd8c | 2520 | *pba_num |= nvm_data; |
bc7f75fa AK |
2521 | |
2522 | return 0; | |
2523 | } |