]> git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/lib/librte_eal/linuxapp/kni/ethtool/ixgbe/ixgbe_x540.c
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / dpdk / lib / librte_eal / linuxapp / kni / ethtool / ixgbe / ixgbe_x540.c
1 /*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
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 "LICENSE.GPL".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26 *******************************************************************************/
27
28 #include "ixgbe_x540.h"
29 #include "ixgbe_type.h"
30 #include "ixgbe_api.h"
31 #include "ixgbe_common.h"
32 #include "ixgbe_phy.h"
33
34 static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw);
35 static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw);
36 static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw);
37 static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw);
38
39 /**
40 * ixgbe_init_ops_X540 - Inits func ptrs and MAC type
41 * @hw: pointer to hardware structure
42 *
43 * Initialize the function pointers and assign the MAC type for X540.
44 * Does not touch the hardware.
45 **/
46 s32 ixgbe_init_ops_X540(struct ixgbe_hw *hw)
47 {
48 struct ixgbe_mac_info *mac = &hw->mac;
49 struct ixgbe_phy_info *phy = &hw->phy;
50 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
51 s32 ret_val;
52
53 ret_val = ixgbe_init_phy_ops_generic(hw);
54 ret_val = ixgbe_init_ops_generic(hw);
55
56
57 /* EEPROM */
58 eeprom->ops.init_params = &ixgbe_init_eeprom_params_X540;
59 eeprom->ops.read = &ixgbe_read_eerd_X540;
60 eeprom->ops.read_buffer = &ixgbe_read_eerd_buffer_X540;
61 eeprom->ops.write = &ixgbe_write_eewr_X540;
62 eeprom->ops.write_buffer = &ixgbe_write_eewr_buffer_X540;
63 eeprom->ops.update_checksum = &ixgbe_update_eeprom_checksum_X540;
64 eeprom->ops.validate_checksum = &ixgbe_validate_eeprom_checksum_X540;
65 eeprom->ops.calc_checksum = &ixgbe_calc_eeprom_checksum_X540;
66
67 /* PHY */
68 phy->ops.init = &ixgbe_init_phy_ops_generic;
69 phy->ops.reset = NULL;
70
71 /* MAC */
72 mac->ops.reset_hw = &ixgbe_reset_hw_X540;
73 mac->ops.get_media_type = &ixgbe_get_media_type_X540;
74 mac->ops.get_supported_physical_layer =
75 &ixgbe_get_supported_physical_layer_X540;
76 mac->ops.read_analog_reg8 = NULL;
77 mac->ops.write_analog_reg8 = NULL;
78 mac->ops.start_hw = &ixgbe_start_hw_X540;
79 mac->ops.get_san_mac_addr = &ixgbe_get_san_mac_addr_generic;
80 mac->ops.set_san_mac_addr = &ixgbe_set_san_mac_addr_generic;
81 mac->ops.get_device_caps = &ixgbe_get_device_caps_generic;
82 mac->ops.get_wwn_prefix = &ixgbe_get_wwn_prefix_generic;
83 mac->ops.get_fcoe_boot_status = &ixgbe_get_fcoe_boot_status_generic;
84 mac->ops.acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540;
85 mac->ops.release_swfw_sync = &ixgbe_release_swfw_sync_X540;
86 mac->ops.disable_sec_rx_path = &ixgbe_disable_sec_rx_path_generic;
87 mac->ops.enable_sec_rx_path = &ixgbe_enable_sec_rx_path_generic;
88
89 /* RAR, Multicast, VLAN */
90 mac->ops.set_vmdq = &ixgbe_set_vmdq_generic;
91 mac->ops.set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic;
92 mac->ops.clear_vmdq = &ixgbe_clear_vmdq_generic;
93 mac->ops.insert_mac_addr = &ixgbe_insert_mac_addr_generic;
94 mac->rar_highwater = 1;
95 mac->ops.set_vfta = &ixgbe_set_vfta_generic;
96 mac->ops.set_vlvf = &ixgbe_set_vlvf_generic;
97 mac->ops.clear_vfta = &ixgbe_clear_vfta_generic;
98 mac->ops.init_uta_tables = &ixgbe_init_uta_tables_generic;
99 mac->ops.set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing;
100 mac->ops.set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing;
101
102 /* Link */
103 mac->ops.get_link_capabilities =
104 &ixgbe_get_copper_link_capabilities_generic;
105 mac->ops.setup_link = &ixgbe_setup_mac_link_X540;
106 mac->ops.setup_rxpba = &ixgbe_set_rxpba_generic;
107 mac->ops.check_link = &ixgbe_check_mac_link_generic;
108
109 mac->mcft_size = 128;
110 mac->vft_size = 128;
111 mac->num_rar_entries = 128;
112 mac->rx_pb_size = 384;
113 mac->max_tx_queues = 128;
114 mac->max_rx_queues = 128;
115 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
116
117 /*
118 * FWSM register
119 * ARC supported; valid only if manageability features are
120 * enabled.
121 */
122 mac->arc_subsystem_valid = (IXGBE_READ_REG(hw, IXGBE_FWSM) &
123 IXGBE_FWSM_MODE_MASK) ? true : false;
124
125 //hw->mbx.ops.init_params = ixgbe_init_mbx_params_pf;
126
127 /* LEDs */
128 mac->ops.blink_led_start = ixgbe_blink_led_start_X540;
129 mac->ops.blink_led_stop = ixgbe_blink_led_stop_X540;
130
131 /* Manageability interface */
132 mac->ops.set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic;
133
134 return ret_val;
135 }
136
137 /**
138 * ixgbe_get_link_capabilities_X540 - Determines link capabilities
139 * @hw: pointer to hardware structure
140 * @speed: pointer to link speed
141 * @autoneg: true when autoneg or autotry is enabled
142 *
143 * Determines the link capabilities by reading the AUTOC register.
144 **/
145 s32 ixgbe_get_link_capabilities_X540(struct ixgbe_hw *hw,
146 ixgbe_link_speed *speed,
147 bool *autoneg)
148 {
149 ixgbe_get_copper_link_capabilities_generic(hw, speed, autoneg);
150
151 return 0;
152 }
153
154 /**
155 * ixgbe_get_media_type_X540 - Get media type
156 * @hw: pointer to hardware structure
157 *
158 * Returns the media type (fiber, copper, backplane)
159 **/
160 enum ixgbe_media_type ixgbe_get_media_type_X540(struct ixgbe_hw *hw)
161 {
162 return ixgbe_media_type_copper;
163 }
164
165 /**
166 * ixgbe_setup_mac_link_X540 - Sets the auto advertised capabilities
167 * @hw: pointer to hardware structure
168 * @speed: new link speed
169 * @autoneg: true if autonegotiation enabled
170 * @autoneg_wait_to_complete: true when waiting for completion is needed
171 **/
172 s32 ixgbe_setup_mac_link_X540(struct ixgbe_hw *hw,
173 ixgbe_link_speed speed, bool autoneg,
174 bool autoneg_wait_to_complete)
175 {
176 return hw->phy.ops.setup_link_speed(hw, speed, autoneg,
177 autoneg_wait_to_complete);
178 }
179
180 /**
181 * ixgbe_reset_hw_X540 - Perform hardware reset
182 * @hw: pointer to hardware structure
183 *
184 * Resets the hardware by resetting the transmit and receive units, masks
185 * and clears all interrupts, and perform a reset.
186 **/
187 s32 ixgbe_reset_hw_X540(struct ixgbe_hw *hw)
188 {
189 s32 status = 0;
190
191 /*
192 * Userland DPDK takes the ownershiop of device
193 * Kernel driver here used as the simple path for ethtool only
194 * Won't real reset device anyway
195 */
196 #if 0
197 u32 ctrl, i;
198
199 /* Call adapter stop to disable tx/rx and clear interrupts */
200 status = hw->mac.ops.stop_adapter(hw);
201 if (status != 0)
202 goto reset_hw_out;
203
204 /* flush pending Tx transactions */
205 ixgbe_clear_tx_pending(hw);
206
207 mac_reset_top:
208 ctrl = IXGBE_CTRL_RST;
209 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
210 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
211 IXGBE_WRITE_FLUSH(hw);
212
213 /* Poll for reset bit to self-clear indicating reset is complete */
214 for (i = 0; i < 10; i++) {
215 udelay(1);
216 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
217 if (!(ctrl & IXGBE_CTRL_RST_MASK))
218 break;
219 }
220
221 if (ctrl & IXGBE_CTRL_RST_MASK) {
222 status = IXGBE_ERR_RESET_FAILED;
223 hw_dbg(hw, "Reset polling failed to complete.\n");
224 }
225 msleep(100);
226
227 /*
228 * Double resets are required for recovery from certain error
229 * conditions. Between resets, it is necessary to stall to allow time
230 * for any pending HW events to complete.
231 */
232 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
233 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
234 goto mac_reset_top;
235 }
236
237 /* Set the Rx packet buffer size. */
238 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), 384 << IXGBE_RXPBSIZE_SHIFT);
239
240 #endif
241
242 /* Store the permanent mac address */
243 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
244
245 /*
246 * Store MAC address from RAR0, clear receive address registers, and
247 * clear the multicast table. Also reset num_rar_entries to 128,
248 * since we modify this value when programming the SAN MAC address.
249 */
250 hw->mac.num_rar_entries = 128;
251 hw->mac.ops.init_rx_addrs(hw);
252
253 /* Store the permanent SAN mac address */
254 hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
255
256 /* Add the SAN MAC address to the RAR only if it's a valid address */
257 if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
258 hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
259 hw->mac.san_addr, 0, IXGBE_RAH_AV);
260
261 /* Save the SAN MAC RAR index */
262 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
263
264 /* Reserve the last RAR for the SAN MAC address */
265 hw->mac.num_rar_entries--;
266 }
267
268 /* Store the alternative WWNN/WWPN prefix */
269 hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
270 &hw->mac.wwpn_prefix);
271
272 //reset_hw_out:
273 return status;
274 }
275
276 /**
277 * ixgbe_start_hw_X540 - Prepare hardware for Tx/Rx
278 * @hw: pointer to hardware structure
279 *
280 * Starts the hardware using the generic start_hw function
281 * and the generation start_hw function.
282 * Then performs revision-specific operations, if any.
283 **/
284 s32 ixgbe_start_hw_X540(struct ixgbe_hw *hw)
285 {
286 s32 ret_val = 0;
287
288 ret_val = ixgbe_start_hw_generic(hw);
289 if (ret_val != 0)
290 goto out;
291
292 ret_val = ixgbe_start_hw_gen2(hw);
293
294 out:
295 return ret_val;
296 }
297
298 /**
299 * ixgbe_get_supported_physical_layer_X540 - Returns physical layer type
300 * @hw: pointer to hardware structure
301 *
302 * Determines physical layer capabilities of the current configuration.
303 **/
304 u32 ixgbe_get_supported_physical_layer_X540(struct ixgbe_hw *hw)
305 {
306 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
307 u16 ext_ability = 0;
308
309 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
310 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
311 if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
312 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
313 if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
314 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
315 if (ext_ability & IXGBE_MDIO_PHY_100BASETX_ABILITY)
316 physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
317
318 return physical_layer;
319 }
320
321 /**
322 * ixgbe_init_eeprom_params_X540 - Initialize EEPROM params
323 * @hw: pointer to hardware structure
324 *
325 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
326 * ixgbe_hw struct in order to set up EEPROM access.
327 **/
328 s32 ixgbe_init_eeprom_params_X540(struct ixgbe_hw *hw)
329 {
330 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
331 u32 eec;
332 u16 eeprom_size;
333
334 if (eeprom->type == ixgbe_eeprom_uninitialized) {
335 eeprom->semaphore_delay = 10;
336 eeprom->type = ixgbe_flash;
337
338 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
339 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
340 IXGBE_EEC_SIZE_SHIFT);
341 eeprom->word_size = 1 << (eeprom_size +
342 IXGBE_EEPROM_WORD_SIZE_SHIFT);
343
344 hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
345 eeprom->type, eeprom->word_size);
346 }
347
348 return 0;
349 }
350
351 /**
352 * ixgbe_read_eerd_X540- Read EEPROM word using EERD
353 * @hw: pointer to hardware structure
354 * @offset: offset of word in the EEPROM to read
355 * @data: word read from the EEPROM
356 *
357 * Reads a 16 bit word from the EEPROM using the EERD register.
358 **/
359 s32 ixgbe_read_eerd_X540(struct ixgbe_hw *hw, u16 offset, u16 *data)
360 {
361 s32 status = 0;
362
363 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
364 0)
365 status = ixgbe_read_eerd_generic(hw, offset, data);
366 else
367 status = IXGBE_ERR_SWFW_SYNC;
368
369 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
370 return status;
371 }
372
373 /**
374 * ixgbe_read_eerd_buffer_X540- Read EEPROM word(s) using EERD
375 * @hw: pointer to hardware structure
376 * @offset: offset of word in the EEPROM to read
377 * @words: number of words
378 * @data: word(s) read from the EEPROM
379 *
380 * Reads a 16 bit word(s) from the EEPROM using the EERD register.
381 **/
382 s32 ixgbe_read_eerd_buffer_X540(struct ixgbe_hw *hw,
383 u16 offset, u16 words, u16 *data)
384 {
385 s32 status = 0;
386
387 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
388 0)
389 status = ixgbe_read_eerd_buffer_generic(hw, offset,
390 words, data);
391 else
392 status = IXGBE_ERR_SWFW_SYNC;
393
394 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
395 return status;
396 }
397
398 /**
399 * ixgbe_write_eewr_X540 - Write EEPROM word using EEWR
400 * @hw: pointer to hardware structure
401 * @offset: offset of word in the EEPROM to write
402 * @data: word write to the EEPROM
403 *
404 * Write a 16 bit word to the EEPROM using the EEWR register.
405 **/
406 s32 ixgbe_write_eewr_X540(struct ixgbe_hw *hw, u16 offset, u16 data)
407 {
408 s32 status = 0;
409
410 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
411 0)
412 status = ixgbe_write_eewr_generic(hw, offset, data);
413 else
414 status = IXGBE_ERR_SWFW_SYNC;
415
416 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
417 return status;
418 }
419
420 /**
421 * ixgbe_write_eewr_buffer_X540 - Write EEPROM word(s) using EEWR
422 * @hw: pointer to hardware structure
423 * @offset: offset of word in the EEPROM to write
424 * @words: number of words
425 * @data: word(s) write to the EEPROM
426 *
427 * Write a 16 bit word(s) to the EEPROM using the EEWR register.
428 **/
429 s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw,
430 u16 offset, u16 words, u16 *data)
431 {
432 s32 status = 0;
433
434 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
435 0)
436 status = ixgbe_write_eewr_buffer_generic(hw, offset,
437 words, data);
438 else
439 status = IXGBE_ERR_SWFW_SYNC;
440
441 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
442 return status;
443 }
444
445 /**
446 * ixgbe_calc_eeprom_checksum_X540 - Calculates and returns the checksum
447 *
448 * This function does not use synchronization for EERD and EEWR. It can
449 * be used internally by function which utilize ixgbe_acquire_swfw_sync_X540.
450 *
451 * @hw: pointer to hardware structure
452 **/
453 u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
454 {
455 u16 i;
456 u16 j;
457 u16 checksum = 0;
458 u16 length = 0;
459 u16 pointer = 0;
460 u16 word = 0;
461
462 /*
463 * Do not use hw->eeprom.ops.read because we do not want to take
464 * the synchronization semaphores here. Instead use
465 * ixgbe_read_eerd_generic
466 */
467
468 /* Include 0x0-0x3F in the checksum */
469 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
470 if (ixgbe_read_eerd_generic(hw, i, &word) != 0) {
471 hw_dbg(hw, "EEPROM read failed\n");
472 break;
473 }
474 checksum += word;
475 }
476
477 /*
478 * Include all data from pointers 0x3, 0x6-0xE. This excludes the
479 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
480 */
481 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
482 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
483 continue;
484
485 if (ixgbe_read_eerd_generic(hw, i, &pointer) != 0) {
486 hw_dbg(hw, "EEPROM read failed\n");
487 break;
488 }
489
490 /* Skip pointer section if the pointer is invalid. */
491 if (pointer == 0xFFFF || pointer == 0 ||
492 pointer >= hw->eeprom.word_size)
493 continue;
494
495 if (ixgbe_read_eerd_generic(hw, pointer, &length) !=
496 0) {
497 hw_dbg(hw, "EEPROM read failed\n");
498 break;
499 }
500
501 /* Skip pointer section if length is invalid. */
502 if (length == 0xFFFF || length == 0 ||
503 (pointer + length) >= hw->eeprom.word_size)
504 continue;
505
506 for (j = pointer+1; j <= pointer+length; j++) {
507 if (ixgbe_read_eerd_generic(hw, j, &word) !=
508 0) {
509 hw_dbg(hw, "EEPROM read failed\n");
510 break;
511 }
512 checksum += word;
513 }
514 }
515
516 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
517
518 return checksum;
519 }
520
521 /**
522 * ixgbe_validate_eeprom_checksum_X540 - Validate EEPROM checksum
523 * @hw: pointer to hardware structure
524 * @checksum_val: calculated checksum
525 *
526 * Performs checksum calculation and validates the EEPROM checksum. If the
527 * caller does not need checksum_val, the value can be NULL.
528 **/
529 s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw *hw,
530 u16 *checksum_val)
531 {
532 s32 status;
533 u16 checksum;
534 u16 read_checksum = 0;
535
536 /*
537 * Read the first word from the EEPROM. If this times out or fails, do
538 * not continue or we could be in for a very long wait while every
539 * EEPROM read fails
540 */
541 status = hw->eeprom.ops.read(hw, 0, &checksum);
542
543 if (status != 0) {
544 hw_dbg(hw, "EEPROM read failed\n");
545 goto out;
546 }
547
548 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
549 0) {
550 checksum = hw->eeprom.ops.calc_checksum(hw);
551
552 /*
553 * Do not use hw->eeprom.ops.read because we do not want to take
554 * the synchronization semaphores twice here.
555 */
556 ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM,
557 &read_checksum);
558
559 /*
560 * Verify read checksum from EEPROM is the same as
561 * calculated checksum
562 */
563 if (read_checksum != checksum)
564 status = IXGBE_ERR_EEPROM_CHECKSUM;
565
566 /* If the user cares, return the calculated checksum */
567 if (checksum_val)
568 *checksum_val = checksum;
569 } else {
570 status = IXGBE_ERR_SWFW_SYNC;
571 }
572
573 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
574 out:
575 return status;
576 }
577
578 /**
579 * ixgbe_update_eeprom_checksum_X540 - Updates the EEPROM checksum and flash
580 * @hw: pointer to hardware structure
581 *
582 * After writing EEPROM to shadow RAM using EEWR register, software calculates
583 * checksum and updates the EEPROM and instructs the hardware to update
584 * the flash.
585 **/
586 s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw)
587 {
588 s32 status;
589 u16 checksum;
590
591 /*
592 * Read the first word from the EEPROM. If this times out or fails, do
593 * not continue or we could be in for a very long wait while every
594 * EEPROM read fails
595 */
596 status = hw->eeprom.ops.read(hw, 0, &checksum);
597
598 if (status != 0)
599 hw_dbg(hw, "EEPROM read failed\n");
600
601 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
602 0) {
603 checksum = hw->eeprom.ops.calc_checksum(hw);
604
605 /*
606 * Do not use hw->eeprom.ops.write because we do not want to
607 * take the synchronization semaphores twice here.
608 */
609 status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM,
610 checksum);
611
612 if (status == 0)
613 status = ixgbe_update_flash_X540(hw);
614 else
615 status = IXGBE_ERR_SWFW_SYNC;
616 }
617
618 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
619
620 return status;
621 }
622
623 /**
624 * ixgbe_update_flash_X540 - Instruct HW to copy EEPROM to Flash device
625 * @hw: pointer to hardware structure
626 *
627 * Set FLUP (bit 23) of the EEC register to instruct Hardware to copy
628 * EEPROM from shadow RAM to the flash device.
629 **/
630 static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw)
631 {
632 u32 flup;
633 s32 status = IXGBE_ERR_EEPROM;
634
635 status = ixgbe_poll_flash_update_done_X540(hw);
636 if (status == IXGBE_ERR_EEPROM) {
637 hw_dbg(hw, "Flash update time out\n");
638 goto out;
639 }
640
641 flup = IXGBE_READ_REG(hw, IXGBE_EEC) | IXGBE_EEC_FLUP;
642 IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
643
644 status = ixgbe_poll_flash_update_done_X540(hw);
645 if (status == 0)
646 hw_dbg(hw, "Flash update complete\n");
647 else
648 hw_dbg(hw, "Flash update time out\n");
649
650 if (hw->revision_id == 0) {
651 flup = IXGBE_READ_REG(hw, IXGBE_EEC);
652
653 if (flup & IXGBE_EEC_SEC1VAL) {
654 flup |= IXGBE_EEC_FLUP;
655 IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
656 }
657
658 status = ixgbe_poll_flash_update_done_X540(hw);
659 if (status == 0)
660 hw_dbg(hw, "Flash update complete\n");
661 else
662 hw_dbg(hw, "Flash update time out\n");
663 }
664 out:
665 return status;
666 }
667
668 /**
669 * ixgbe_poll_flash_update_done_X540 - Poll flash update status
670 * @hw: pointer to hardware structure
671 *
672 * Polls the FLUDONE (bit 26) of the EEC Register to determine when the
673 * flash update is done.
674 **/
675 static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
676 {
677 u32 i;
678 u32 reg;
679 s32 status = IXGBE_ERR_EEPROM;
680
681 for (i = 0; i < IXGBE_FLUDONE_ATTEMPTS; i++) {
682 reg = IXGBE_READ_REG(hw, IXGBE_EEC);
683 if (reg & IXGBE_EEC_FLUDONE) {
684 status = 0;
685 break;
686 }
687 udelay(5);
688 }
689 return status;
690 }
691
692 /**
693 * ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore
694 * @hw: pointer to hardware structure
695 * @mask: Mask to specify which semaphore to acquire
696 *
697 * Acquires the SWFW semaphore thought the SW_FW_SYNC register for
698 * the specified function (CSR, PHY0, PHY1, NVM, Flash)
699 **/
700 s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
701 {
702 u32 swfw_sync;
703 u32 swmask = mask;
704 u32 fwmask = mask << 5;
705 u32 hwmask = 0;
706 u32 timeout = 200;
707 u32 i;
708 s32 ret_val = 0;
709
710 if (swmask == IXGBE_GSSR_EEP_SM)
711 hwmask = IXGBE_GSSR_FLASH_SM;
712
713 /* SW only mask doesn't have FW bit pair */
714 if (swmask == IXGBE_GSSR_SW_MNG_SM)
715 fwmask = 0;
716
717 for (i = 0; i < timeout; i++) {
718 /*
719 * SW NVM semaphore bit is used for access to all
720 * SW_FW_SYNC bits (not just NVM)
721 */
722 if (ixgbe_get_swfw_sync_semaphore(hw)) {
723 ret_val = IXGBE_ERR_SWFW_SYNC;
724 goto out;
725 }
726
727 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
728 if (!(swfw_sync & (fwmask | swmask | hwmask))) {
729 swfw_sync |= swmask;
730 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
731 ixgbe_release_swfw_sync_semaphore(hw);
732 msleep(5);
733 goto out;
734 } else {
735 /*
736 * Firmware currently using resource (fwmask), hardware
737 * currently using resource (hwmask), or other software
738 * thread currently using resource (swmask)
739 */
740 ixgbe_release_swfw_sync_semaphore(hw);
741 msleep(5);
742 }
743 }
744
745 /* Failed to get SW only semaphore */
746 if (swmask == IXGBE_GSSR_SW_MNG_SM) {
747 ret_val = IXGBE_ERR_SWFW_SYNC;
748 goto out;
749 }
750
751 /* If the resource is not released by the FW/HW the SW can assume that
752 * the FW/HW malfunctions. In that case the SW should sets the SW bit(s)
753 * of the requested resource(s) while ignoring the corresponding FW/HW
754 * bits in the SW_FW_SYNC register.
755 */
756 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
757 if (swfw_sync & (fwmask | hwmask)) {
758 if (ixgbe_get_swfw_sync_semaphore(hw)) {
759 ret_val = IXGBE_ERR_SWFW_SYNC;
760 goto out;
761 }
762
763 swfw_sync |= swmask;
764 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
765 ixgbe_release_swfw_sync_semaphore(hw);
766 msleep(5);
767 }
768
769 out:
770 return ret_val;
771 }
772
773 /**
774 * ixgbe_release_swfw_sync_X540 - Release SWFW semaphore
775 * @hw: pointer to hardware structure
776 * @mask: Mask to specify which semaphore to release
777 *
778 * Releases the SWFW semaphore through the SW_FW_SYNC register
779 * for the specified function (CSR, PHY0, PHY1, EVM, Flash)
780 **/
781 void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
782 {
783 u32 swfw_sync;
784 u32 swmask = mask;
785
786 ixgbe_get_swfw_sync_semaphore(hw);
787
788 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
789 swfw_sync &= ~swmask;
790 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
791
792 ixgbe_release_swfw_sync_semaphore(hw);
793 msleep(5);
794 }
795
796 /**
797 * ixgbe_get_nvm_semaphore - Get hardware semaphore
798 * @hw: pointer to hardware structure
799 *
800 * Sets the hardware semaphores so SW/FW can gain control of shared resources
801 **/
802 static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw)
803 {
804 s32 status = IXGBE_ERR_EEPROM;
805 u32 timeout = 2000;
806 u32 i;
807 u32 swsm;
808
809 /* Get SMBI software semaphore between device drivers first */
810 for (i = 0; i < timeout; i++) {
811 /*
812 * If the SMBI bit is 0 when we read it, then the bit will be
813 * set and we have the semaphore
814 */
815 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
816 if (!(swsm & IXGBE_SWSM_SMBI)) {
817 status = 0;
818 break;
819 }
820 udelay(50);
821 }
822
823 /* Now get the semaphore between SW/FW through the REGSMP bit */
824 if (status == 0) {
825 for (i = 0; i < timeout; i++) {
826 swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
827 if (!(swsm & IXGBE_SWFW_REGSMP))
828 break;
829
830 udelay(50);
831 }
832
833 /*
834 * Release semaphores and return error if SW NVM semaphore
835 * was not granted because we don't have access to the EEPROM
836 */
837 if (i >= timeout) {
838 hw_dbg(hw, "REGSMP Software NVM semaphore not "
839 "granted.\n");
840 ixgbe_release_swfw_sync_semaphore(hw);
841 status = IXGBE_ERR_EEPROM;
842 }
843 } else {
844 hw_dbg(hw, "Software semaphore SMBI between device drivers "
845 "not granted.\n");
846 }
847
848 return status;
849 }
850
851 /**
852 * ixgbe_release_nvm_semaphore - Release hardware semaphore
853 * @hw: pointer to hardware structure
854 *
855 * This function clears hardware semaphore bits.
856 **/
857 static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw)
858 {
859 u32 swsm;
860
861 /* Release both semaphores by writing 0 to the bits REGSMP and SMBI */
862
863 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
864 swsm &= ~IXGBE_SWSM_SMBI;
865 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
866
867 swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
868 swsm &= ~IXGBE_SWFW_REGSMP;
869 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swsm);
870
871 IXGBE_WRITE_FLUSH(hw);
872 }
873
874 /**
875 * ixgbe_blink_led_start_X540 - Blink LED based on index.
876 * @hw: pointer to hardware structure
877 * @index: led number to blink
878 *
879 * Devices that implement the version 2 interface:
880 * X540
881 **/
882 s32 ixgbe_blink_led_start_X540(struct ixgbe_hw *hw, u32 index)
883 {
884 u32 macc_reg;
885 u32 ledctl_reg;
886 ixgbe_link_speed speed;
887 bool link_up;
888
889 /*
890 * Link should be up in order for the blink bit in the LED control
891 * register to work. Force link and speed in the MAC if link is down.
892 * This will be reversed when we stop the blinking.
893 */
894 hw->mac.ops.check_link(hw, &speed, &link_up, false);
895 if (link_up == false) {
896 macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
897 macc_reg |= IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS;
898 IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
899 }
900 /* Set the LED to LINK_UP + BLINK. */
901 ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
902 ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
903 ledctl_reg |= IXGBE_LED_BLINK(index);
904 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
905 IXGBE_WRITE_FLUSH(hw);
906
907 return 0;
908 }
909
910 /**
911 * ixgbe_blink_led_stop_X540 - Stop blinking LED based on index.
912 * @hw: pointer to hardware structure
913 * @index: led number to stop blinking
914 *
915 * Devices that implement the version 2 interface:
916 * X540
917 **/
918 s32 ixgbe_blink_led_stop_X540(struct ixgbe_hw *hw, u32 index)
919 {
920 u32 macc_reg;
921 u32 ledctl_reg;
922
923 /* Restore the LED to its default value. */
924 ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
925 ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
926 ledctl_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
927 ledctl_reg &= ~IXGBE_LED_BLINK(index);
928 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
929
930 /* Unforce link and speed in the MAC. */
931 macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
932 macc_reg &= ~(IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS);
933 IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
934 IXGBE_WRITE_FLUSH(hw);
935
936 return 0;
937 }