blob: a6f06d59a64a2dbec689ba4a5587c7b7205d3bf9 [file] [log] [blame]
Don Skidmorefe15e8e2010-11-16 19:27:16 -08001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2010 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 "COPYING".
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 <linux/pci.h>
29#include <linux/delay.h>
30#include <linux/sched.h>
31
32#include "ixgbe.h"
33#include "ixgbe_phy.h"
34//#include "ixgbe_mbx.h"
35
36#define IXGBE_X540_MAX_TX_QUEUES 128
37#define IXGBE_X540_MAX_RX_QUEUES 128
38#define IXGBE_X540_RAR_ENTRIES 128
39#define IXGBE_X540_MC_TBL_SIZE 128
40#define IXGBE_X540_VFT_TBL_SIZE 128
41
42static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw);
43static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw);
44static s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask);
45static void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask);
46static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw);
47static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw);
48
Don Skidmoreb93a2222010-11-16 19:27:17 -080049static enum ixgbe_media_type ixgbe_get_media_type_X540(struct ixgbe_hw *hw)
Don Skidmorefe15e8e2010-11-16 19:27:16 -080050{
51 return ixgbe_media_type_copper;
52}
53
54static s32 ixgbe_get_invariants_X540(struct ixgbe_hw *hw)
55{
56 struct ixgbe_mac_info *mac = &hw->mac;
57
58 /* Call PHY identify routine to get the phy type */
59 ixgbe_identify_phy_generic(hw);
60
61 mac->mcft_size = IXGBE_X540_MC_TBL_SIZE;
62 mac->vft_size = IXGBE_X540_VFT_TBL_SIZE;
63 mac->num_rar_entries = IXGBE_X540_RAR_ENTRIES;
64 mac->max_rx_queues = IXGBE_X540_MAX_RX_QUEUES;
65 mac->max_tx_queues = IXGBE_X540_MAX_TX_QUEUES;
66 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
67
68 return 0;
69}
70
71/**
72 * ixgbe_setup_mac_link_X540 - Set the auto advertised capabilitires
73 * @hw: pointer to hardware structure
74 * @speed: new link speed
75 * @autoneg: true if autonegotiation enabled
76 * @autoneg_wait_to_complete: true when waiting for completion is needed
77 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -080078static s32 ixgbe_setup_mac_link_X540(struct ixgbe_hw *hw,
79 ixgbe_link_speed speed, bool autoneg,
80 bool autoneg_wait_to_complete)
Don Skidmorefe15e8e2010-11-16 19:27:16 -080081{
82 return hw->phy.ops.setup_link_speed(hw, speed, autoneg,
83 autoneg_wait_to_complete);
84}
85
86/**
87 * ixgbe_reset_hw_X540 - Perform hardware reset
88 * @hw: pointer to hardware structure
89 *
90 * Resets the hardware by resetting the transmit and receive units, masks
91 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
92 * reset.
93 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -080094static s32 ixgbe_reset_hw_X540(struct ixgbe_hw *hw)
Don Skidmorefe15e8e2010-11-16 19:27:16 -080095{
96 ixgbe_link_speed link_speed;
97 s32 status = 0;
98 u32 ctrl;
99 u32 ctrl_ext;
100 u32 reset_bit;
101 u32 i;
102 u32 autoc;
103 u32 autoc2;
104 bool link_up = false;
105
106 /* Call adapter stop to disable tx/rx and clear interrupts */
107 hw->mac.ops.stop_adapter(hw);
108
109 /*
110 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
111 * access and verify no pending requests before reset
112 */
Emil Tantilova4297dc2011-02-14 08:45:13 +0000113 ixgbe_disable_pcie_master(hw);
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800114
Emil Tantilova4297dc2011-02-14 08:45:13 +0000115mac_reset_top:
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800116 /*
117 * Issue global reset to the MAC. Needs to be SW reset if link is up.
118 * If link reset is used when link is up, it might reset the PHY when
119 * mng is using it. If link is down or the flag to force full link
120 * reset is set, then perform link reset.
121 */
122 if (hw->force_full_reset) {
123 reset_bit = IXGBE_CTRL_LNK_RST;
124 } else {
125 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
126 if (!link_up)
127 reset_bit = IXGBE_CTRL_LNK_RST;
128 else
129 reset_bit = IXGBE_CTRL_RST;
130 }
131
132 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
Emil Tantilov2c4db942011-01-05 07:09:41 +0000133 IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | reset_bit));
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800134 IXGBE_WRITE_FLUSH(hw);
135
136 /* Poll for reset bit to self-clear indicating reset is complete */
137 for (i = 0; i < 10; i++) {
138 udelay(1);
139 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
Emil Tantilov2c4db942011-01-05 07:09:41 +0000140 if (!(ctrl & reset_bit))
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800141 break;
142 }
Emil Tantilov2c4db942011-01-05 07:09:41 +0000143 if (ctrl & reset_bit) {
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800144 status = IXGBE_ERR_RESET_FAILED;
145 hw_dbg(hw, "Reset polling failed to complete.\n");
146 }
147
Emil Tantilova4297dc2011-02-14 08:45:13 +0000148 /*
149 * Double resets are required for recovery from certain error
150 * conditions. Between resets, it is necessary to stall to allow time
151 * for any pending HW events to complete. We use 1usec since that is
152 * what is needed for ixgbe_disable_pcie_master(). The second reset
153 * then clears out any effects of those events.
154 */
155 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
156 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
157 udelay(1);
158 goto mac_reset_top;
159 }
160
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800161 /* Clear PF Reset Done bit so PF/VF Mail Ops can work */
162 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
163 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
164 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
165
166 msleep(50);
167
168 /* Set the Rx packet buffer size. */
169 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), 384 << IXGBE_RXPBSIZE_SHIFT);
170
171 /* Store the permanent mac address */
172 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
173
174 /*
175 * Store the original AUTOC/AUTOC2 values if they have not been
176 * stored off yet. Otherwise restore the stored original
177 * values since the reset operation sets back to defaults.
178 */
179 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
180 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
181 if (hw->mac.orig_link_settings_stored == false) {
182 hw->mac.orig_autoc = autoc;
183 hw->mac.orig_autoc2 = autoc2;
184 hw->mac.orig_link_settings_stored = true;
185 } else {
186 if (autoc != hw->mac.orig_autoc)
187 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc |
188 IXGBE_AUTOC_AN_RESTART));
189
190 if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
191 (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
192 autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
193 autoc2 |= (hw->mac.orig_autoc2 &
194 IXGBE_AUTOC2_UPPER_MASK);
195 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
196 }
197 }
198
199 /*
200 * Store MAC address from RAR0, clear receive address registers, and
201 * clear the multicast table. Also reset num_rar_entries to 128,
202 * since we modify this value when programming the SAN MAC address.
203 */
204 hw->mac.num_rar_entries = 128;
205 hw->mac.ops.init_rx_addrs(hw);
206
207 /* Store the permanent mac address */
208 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
209
210 /* Store the permanent SAN mac address */
211 hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
212
213 /* Add the SAN MAC address to the RAR only if it's a valid address */
214 if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
215 hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
216 hw->mac.san_addr, 0, IXGBE_RAH_AV);
217
218 /* Reserve the last RAR for the SAN MAC address */
219 hw->mac.num_rar_entries--;
220 }
221
222 /* Store the alternative WWNN/WWPN prefix */
223 hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
224 &hw->mac.wwpn_prefix);
225
226 return status;
227}
228
229/**
230 * ixgbe_get_supported_physical_layer_X540 - Returns physical layer type
231 * @hw: pointer to hardware structure
232 *
233 * Determines physical layer capabilities of the current configuration.
234 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -0800235static u32 ixgbe_get_supported_physical_layer_X540(struct ixgbe_hw *hw)
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800236{
237 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
238 u16 ext_ability = 0;
239
240 hw->phy.ops.identify(hw);
241
242 hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD,
243 &ext_ability);
244 if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
245 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
246 if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
247 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
248 if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
249 physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
250
251 return physical_layer;
252}
253
254/**
255 * ixgbe_init_eeprom_params_X540 - Initialize EEPROM params
256 * @hw: pointer to hardware structure
257 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -0800258static s32 ixgbe_init_eeprom_params_X540(struct ixgbe_hw *hw)
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800259{
260 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
261 u32 eec;
262 u16 eeprom_size;
263
264 if (eeprom->type == ixgbe_eeprom_uninitialized) {
265 eeprom->semaphore_delay = 10;
266 eeprom->type = ixgbe_flash;
267
268 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
269 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
270 IXGBE_EEC_SIZE_SHIFT);
271 eeprom->word_size = 1 << (eeprom_size +
272 IXGBE_EEPROM_WORD_SIZE_SHIFT);
273
274 hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
275 eeprom->type, eeprom->word_size);
276 }
277
278 return 0;
279}
280
281/**
282 * ixgbe_read_eerd_X540 - Read EEPROM word using EERD
283 * @hw: pointer to hardware structure
284 * @offset: offset of word in the EEPROM to read
285 * @data: word read from the EERPOM
286 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -0800287static s32 ixgbe_read_eerd_X540(struct ixgbe_hw *hw, u16 offset, u16 *data)
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800288{
289 s32 status;
290
Don Skidmored9946532010-12-09 06:55:19 +0000291 if (ixgbe_acquire_swfw_sync_X540(hw, IXGBE_GSSR_EEP_SM) == 0)
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800292 status = ixgbe_read_eerd_generic(hw, offset, data);
293 else
294 status = IXGBE_ERR_SWFW_SYNC;
295
296 ixgbe_release_swfw_sync_X540(hw, IXGBE_GSSR_EEP_SM);
297 return status;
298}
299
300/**
301 * ixgbe_write_eewr_X540 - Write EEPROM word using EEWR
302 * @hw: pointer to hardware structure
303 * @offset: offset of word in the EEPROM to write
304 * @data: word write to the EEPROM
305 *
306 * Write a 16 bit word to the EEPROM using the EEWR register.
307 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -0800308static s32 ixgbe_write_eewr_X540(struct ixgbe_hw *hw, u16 offset, u16 data)
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800309{
310 u32 eewr;
311 s32 status;
312
313 hw->eeprom.ops.init_params(hw);
314
315 if (offset >= hw->eeprom.word_size) {
316 status = IXGBE_ERR_EEPROM;
317 goto out;
318 }
319
320 eewr = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) |
321 (data << IXGBE_EEPROM_RW_REG_DATA) |
322 IXGBE_EEPROM_RW_REG_START;
323
Don Skidmored9946532010-12-09 06:55:19 +0000324 if (ixgbe_acquire_swfw_sync_X540(hw, IXGBE_GSSR_EEP_SM) == 0) {
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800325 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
326 if (status != 0) {
327 hw_dbg(hw, "Eeprom write EEWR timed out\n");
328 goto out;
329 }
330
331 IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
332
333 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
334 if (status != 0) {
335 hw_dbg(hw, "Eeprom write EEWR timed out\n");
336 goto out;
337 }
338 } else {
339 status = IXGBE_ERR_SWFW_SYNC;
340 }
341
342out:
343 ixgbe_release_swfw_sync_X540(hw, IXGBE_GSSR_EEP_SM);
344 return status;
345}
346
347/**
348 * ixgbe_calc_eeprom_checksum_X540 - Calculates and returns the checksum
349 * @hw: pointer to hardware structure
350 **/
351static u16 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
352{
353 u16 i;
354 u16 j;
355 u16 checksum = 0;
356 u16 length = 0;
357 u16 pointer = 0;
358 u16 word = 0;
359
360 /* Include 0x0-0x3F in the checksum */
361 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
362 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
363 hw_dbg(hw, "EEPROM read failed\n");
364 break;
365 }
366 checksum += word;
367 }
368
369 /*
370 * Include all data from pointers 0x3, 0x6-0xE. This excludes the
371 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
372 */
373 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
374 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
375 continue;
376
377 if (hw->eeprom.ops.read(hw, i, &pointer) != 0) {
378 hw_dbg(hw, "EEPROM read failed\n");
379 break;
380 }
381
382 /* Skip pointer section if the pointer is invalid. */
383 if (pointer == 0xFFFF || pointer == 0 ||
384 pointer >= hw->eeprom.word_size)
385 continue;
386
387 if (hw->eeprom.ops.read(hw, pointer, &length) != 0) {
388 hw_dbg(hw, "EEPROM read failed\n");
389 break;
390 }
391
392 /* Skip pointer section if length is invalid. */
393 if (length == 0xFFFF || length == 0 ||
394 (pointer + length) >= hw->eeprom.word_size)
395 continue;
396
397 for (j = pointer+1; j <= pointer+length; j++) {
398 if (hw->eeprom.ops.read(hw, j, &word) != 0) {
399 hw_dbg(hw, "EEPROM read failed\n");
400 break;
401 }
402 checksum += word;
403 }
404 }
405
406 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
407
408 return checksum;
409}
410
411/**
412 * ixgbe_update_eeprom_checksum_X540 - Updates the EEPROM checksum and flash
413 * @hw: pointer to hardware structure
414 *
415 * After writing EEPROM to shadow RAM using EEWR register, software calculates
416 * checksum and updates the EEPROM and instructs the hardware to update
417 * the flash.
418 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -0800419static s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw)
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800420{
421 s32 status;
422
423 status = ixgbe_update_eeprom_checksum_generic(hw);
424
425 if (status)
426 status = ixgbe_update_flash_X540(hw);
427
428 return status;
429}
430
431/**
432 * ixgbe_update_flash_X540 - Instruct HW to copy EEPROM to Flash device
433 * @hw: pointer to hardware structure
434 *
435 * Set FLUP (bit 23) of the EEC register to instruct Hardware to copy
436 * EEPROM from shadow RAM to the flash device.
437 **/
438static s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw)
439{
440 u32 flup;
441 s32 status = IXGBE_ERR_EEPROM;
442
443 status = ixgbe_poll_flash_update_done_X540(hw);
444 if (status == IXGBE_ERR_EEPROM) {
445 hw_dbg(hw, "Flash update time out\n");
446 goto out;
447 }
448
449 flup = IXGBE_READ_REG(hw, IXGBE_EEC) | IXGBE_EEC_FLUP;
450 IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
451
452 status = ixgbe_poll_flash_update_done_X540(hw);
453 if (status)
454 hw_dbg(hw, "Flash update complete\n");
455 else
456 hw_dbg(hw, "Flash update time out\n");
457
458 if (hw->revision_id == 0) {
459 flup = IXGBE_READ_REG(hw, IXGBE_EEC);
460
461 if (flup & IXGBE_EEC_SEC1VAL) {
462 flup |= IXGBE_EEC_FLUP;
463 IXGBE_WRITE_REG(hw, IXGBE_EEC, flup);
464 }
465
466 status = ixgbe_poll_flash_update_done_X540(hw);
467 if (status)
468 hw_dbg(hw, "Flash update complete\n");
469 else
470 hw_dbg(hw, "Flash update time out\n");
471
472 }
473out:
474 return status;
475}
476
477/**
478 * ixgbe_poll_flash_update_done_X540 - Poll flash update status
479 * @hw: pointer to hardware structure
480 *
481 * Polls the FLUDONE (bit 26) of the EEC Register to determine when the
482 * flash update is done.
483 **/
484static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
485{
486 u32 i;
487 u32 reg;
488 s32 status = IXGBE_ERR_EEPROM;
489
490 for (i = 0; i < IXGBE_FLUDONE_ATTEMPTS; i++) {
491 reg = IXGBE_READ_REG(hw, IXGBE_EEC);
492 if (reg & IXGBE_EEC_FLUDONE) {
493 status = 0;
494 break;
495 }
496 udelay(5);
497 }
498 return status;
499}
500
501/**
502 * ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore
503 * @hw: pointer to hardware structure
504 * @mask: Mask to specify which semaphore to acquire
505 *
506 * Acquires the SWFW semaphore thought the SW_FW_SYNC register for
507 * the specified function (CSR, PHY0, PHY1, NVM, Flash)
508 **/
509static s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
510{
511 u32 swfw_sync;
512 u32 swmask = mask;
513 u32 fwmask = mask << 5;
514 u32 hwmask = 0;
515 u32 timeout = 200;
516 u32 i;
517
518 if (swmask == IXGBE_GSSR_EEP_SM)
519 hwmask = IXGBE_GSSR_FLASH_SM;
520
521 for (i = 0; i < timeout; i++) {
522 /*
523 * SW NVM semaphore bit is used for access to all
524 * SW_FW_SYNC bits (not just NVM)
525 */
526 if (ixgbe_get_swfw_sync_semaphore(hw))
527 return IXGBE_ERR_SWFW_SYNC;
528
529 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
530 if (!(swfw_sync & (fwmask | swmask | hwmask))) {
531 swfw_sync |= swmask;
532 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
533 ixgbe_release_swfw_sync_semaphore(hw);
534 break;
535 } else {
536 /*
537 * Firmware currently using resource (fwmask),
538 * hardware currently using resource (hwmask),
539 * or other software thread currently using
540 * resource (swmask)
541 */
542 ixgbe_release_swfw_sync_semaphore(hw);
543 msleep(5);
544 }
545 }
546
547 /*
548 * If the resource is not released by the FW/HW the SW can assume that
549 * the FW/HW malfunctions. In that case the SW should sets the
550 * SW bit(s) of the requested resource(s) while ignoring the
551 * corresponding FW/HW bits in the SW_FW_SYNC register.
552 */
553 if (i >= timeout) {
554 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
555 if (swfw_sync & (fwmask | hwmask)) {
556 if (ixgbe_get_swfw_sync_semaphore(hw))
557 return IXGBE_ERR_SWFW_SYNC;
558
559 swfw_sync |= swmask;
560 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
561 ixgbe_release_swfw_sync_semaphore(hw);
562 }
563 }
564
565 msleep(5);
566 return 0;
567}
568
569/**
570 * ixgbe_release_swfw_sync_X540 - Release SWFW semaphore
571 * @hw: pointer to hardware structure
572 * @mask: Mask to specify which semaphore to release
573 *
574 * Releases the SWFW semaphore throught the SW_FW_SYNC register
575 * for the specified function (CSR, PHY0, PHY1, EVM, Flash)
576 **/
577static void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
578{
579 u32 swfw_sync;
580 u32 swmask = mask;
581
582 ixgbe_get_swfw_sync_semaphore(hw);
583
584 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
585 swfw_sync &= ~swmask;
586 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
587
588 ixgbe_release_swfw_sync_semaphore(hw);
589 msleep(5);
590}
591
592/**
593 * ixgbe_get_nvm_semaphore - Get hardware semaphore
594 * @hw: pointer to hardware structure
595 *
596 * Sets the hardware semaphores so SW/FW can gain control of shared resources
597 **/
598static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw)
599{
600 s32 status = IXGBE_ERR_EEPROM;
601 u32 timeout = 2000;
602 u32 i;
603 u32 swsm;
604
605 /* Get SMBI software semaphore between device drivers first */
606 for (i = 0; i < timeout; i++) {
607 /*
608 * If the SMBI bit is 0 when we read it, then the bit will be
609 * set and we have the semaphore
610 */
611 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
612 if (!(swsm & IXGBE_SWSM_SMBI)) {
613 status = 0;
614 break;
615 }
616 udelay(50);
617 }
618
619 /* Now get the semaphore between SW/FW through the REGSMP bit */
620 if (status) {
621 for (i = 0; i < timeout; i++) {
622 swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
623 if (!(swsm & IXGBE_SWFW_REGSMP))
624 break;
625
626 udelay(50);
627 }
628 } else {
629 hw_dbg(hw, "Software semaphore SMBI between device drivers "
630 "not granted.\n");
631 }
632
633 return status;
634}
635
636/**
637 * ixgbe_release_nvm_semaphore - Release hardware semaphore
638 * @hw: pointer to hardware structure
639 *
640 * This function clears hardware semaphore bits.
641 **/
642static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw)
643{
644 u32 swsm;
645
646 /* Release both semaphores by writing 0 to the bits REGSMP and SMBI */
647
648 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
649 swsm &= ~IXGBE_SWSM_SMBI;
650 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
651
652 swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
653 swsm &= ~IXGBE_SWFW_REGSMP;
654 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swsm);
655
656 IXGBE_WRITE_FLUSH(hw);
657}
658
659static struct ixgbe_mac_operations mac_ops_X540 = {
660 .init_hw = &ixgbe_init_hw_generic,
661 .reset_hw = &ixgbe_reset_hw_X540,
662 .start_hw = &ixgbe_start_hw_generic,
663 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
664 .get_media_type = &ixgbe_get_media_type_X540,
665 .get_supported_physical_layer =
666 &ixgbe_get_supported_physical_layer_X540,
667 .enable_rx_dma = &ixgbe_enable_rx_dma_generic,
668 .get_mac_addr = &ixgbe_get_mac_addr_generic,
669 .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
670 .get_device_caps = NULL,
671 .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
672 .stop_adapter = &ixgbe_stop_adapter_generic,
673 .get_bus_info = &ixgbe_get_bus_info_generic,
674 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
675 .read_analog_reg8 = NULL,
676 .write_analog_reg8 = NULL,
677 .setup_link = &ixgbe_setup_mac_link_X540,
678 .check_link = &ixgbe_check_mac_link_generic,
679 .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
680 .led_on = &ixgbe_led_on_generic,
681 .led_off = &ixgbe_led_off_generic,
682 .blink_led_start = &ixgbe_blink_led_start_generic,
683 .blink_led_stop = &ixgbe_blink_led_stop_generic,
684 .set_rar = &ixgbe_set_rar_generic,
685 .clear_rar = &ixgbe_clear_rar_generic,
686 .set_vmdq = &ixgbe_set_vmdq_generic,
687 .clear_vmdq = &ixgbe_clear_vmdq_generic,
688 .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
689 .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
690 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
691 .enable_mc = &ixgbe_enable_mc_generic,
692 .disable_mc = &ixgbe_disable_mc_generic,
693 .clear_vfta = &ixgbe_clear_vfta_generic,
694 .set_vfta = &ixgbe_set_vfta_generic,
695 .fc_enable = &ixgbe_fc_enable_generic,
696 .init_uta_tables = &ixgbe_init_uta_tables_generic,
697 .setup_sfp = NULL,
Greg Rose3377eba792010-12-07 08:16:45 +0000698 .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing,
699 .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing,
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800700};
701
702static struct ixgbe_eeprom_operations eeprom_ops_X540 = {
703 .init_params = &ixgbe_init_eeprom_params_X540,
704 .read = &ixgbe_read_eerd_X540,
705 .write = &ixgbe_write_eewr_X540,
706 .calc_checksum = &ixgbe_calc_eeprom_checksum_X540,
707 .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
708 .update_checksum = &ixgbe_update_eeprom_checksum_X540,
709};
710
711static struct ixgbe_phy_operations phy_ops_X540 = {
712 .identify = &ixgbe_identify_phy_generic,
713 .identify_sfp = &ixgbe_identify_sfp_module_generic,
714 .init = NULL,
715 .reset = &ixgbe_reset_phy_generic,
716 .read_reg = &ixgbe_read_phy_reg_generic,
717 .write_reg = &ixgbe_write_phy_reg_generic,
718 .setup_link = &ixgbe_setup_phy_link_generic,
719 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
720 .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
721 .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
722 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
723 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
724 .check_overtemp = &ixgbe_tn_check_overtemp,
725};
726
727struct ixgbe_info ixgbe_X540_info = {
728 .mac = ixgbe_mac_X540,
729 .get_invariants = &ixgbe_get_invariants_X540,
730 .mac_ops = &mac_ops_X540,
731 .eeprom_ops = &eeprom_ops_X540,
732 .phy_ops = &phy_ops_X540,
733 .mbx_ops = &mbx_ops_generic,
734};