blob: 7cddcfba809e73bbd86a6ae108951de1f21376d3 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
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:
Auke Kok9a799d72007-09-15 14:07:45 -070023 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
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070032#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070033#include "ixgbe_phy.h"
34
35#define IXGBE_82598_MAX_TX_QUEUES 32
36#define IXGBE_82598_MAX_RX_QUEUES 64
37#define IXGBE_82598_RAR_ENTRIES 16
Christopher Leech2c5645c2008-08-26 04:27:02 -070038#define IXGBE_82598_MC_TBL_SIZE 128
39#define IXGBE_82598_VFT_TBL_SIZE 128
Auke Kok9a799d72007-09-15 14:07:45 -070040
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070041static s32 ixgbe_get_copper_link_capabilities_82598(struct ixgbe_hw *hw,
42 ixgbe_link_speed *speed,
43 bool *autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -070044static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070045static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw,
46 ixgbe_link_speed speed,
47 bool autoneg,
48 bool autoneg_wait_to_complete);
Auke Kok9a799d72007-09-15 14:07:45 -070049
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070050/**
51 */
Auke Kok9a799d72007-09-15 14:07:45 -070052static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw)
53{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070054 struct ixgbe_mac_info *mac = &hw->mac;
55 struct ixgbe_phy_info *phy = &hw->phy;
Auke Kok9a799d72007-09-15 14:07:45 -070056
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070057 /* Call PHY identify routine to get the phy type */
58 ixgbe_identify_phy_generic(hw);
Auke Kok3957d632007-10-31 15:22:10 -070059
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070060 /* PHY Init */
61 switch (phy->type) {
62 default:
63 break;
Auke Kok3957d632007-10-31 15:22:10 -070064 }
65
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070066 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
67 mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
68 mac->ops.setup_link_speed =
69 &ixgbe_setup_copper_link_speed_82598;
70 mac->ops.get_link_capabilities =
71 &ixgbe_get_copper_link_capabilities_82598;
72 }
73
74 mac->mcft_size = IXGBE_82598_MC_TBL_SIZE;
75 mac->vft_size = IXGBE_82598_VFT_TBL_SIZE;
76 mac->num_rar_entries = IXGBE_82598_RAR_ENTRIES;
77 mac->max_rx_queues = IXGBE_82598_MAX_RX_QUEUES;
78 mac->max_tx_queues = IXGBE_82598_MAX_TX_QUEUES;
79
Auke Kok9a799d72007-09-15 14:07:45 -070080 return 0;
81}
82
83/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070084 * ixgbe_get_link_capabilities_82598 - Determines link capabilities
Auke Kok9a799d72007-09-15 14:07:45 -070085 * @hw: pointer to hardware structure
86 * @speed: pointer to link speed
87 * @autoneg: boolean auto-negotiation value
88 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070089 * Determines the link capabilities by reading the AUTOC register.
Auke Kok9a799d72007-09-15 14:07:45 -070090 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070091static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070092 ixgbe_link_speed *speed,
93 bool *autoneg)
Auke Kok9a799d72007-09-15 14:07:45 -070094{
95 s32 status = 0;
96 s32 autoc_reg;
97
98 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
99
100 if (hw->mac.link_settings_loaded) {
101 autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
102 autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
103 autoc_reg |= hw->mac.link_attach_type;
104 autoc_reg |= hw->mac.link_mode_select;
105 }
106
107 switch (autoc_reg & IXGBE_AUTOC_LMS_MASK) {
108 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
109 *speed = IXGBE_LINK_SPEED_1GB_FULL;
110 *autoneg = false;
111 break;
112
113 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
114 *speed = IXGBE_LINK_SPEED_10GB_FULL;
115 *autoneg = false;
116 break;
117
118 case IXGBE_AUTOC_LMS_1G_AN:
119 *speed = IXGBE_LINK_SPEED_1GB_FULL;
120 *autoneg = true;
121 break;
122
123 case IXGBE_AUTOC_LMS_KX4_AN:
124 case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
125 *speed = IXGBE_LINK_SPEED_UNKNOWN;
126 if (autoc_reg & IXGBE_AUTOC_KX4_SUPP)
127 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
128 if (autoc_reg & IXGBE_AUTOC_KX_SUPP)
129 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
130 *autoneg = true;
131 break;
132
133 default:
134 status = IXGBE_ERR_LINK_SETUP;
135 break;
136 }
137
138 return status;
139}
140
141/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700142 * ixgbe_get_copper_link_capabilities_82598 - Determines link capabilities
Auke Kok9a799d72007-09-15 14:07:45 -0700143 * @hw: pointer to hardware structure
144 * @speed: pointer to link speed
145 * @autoneg: boolean auto-negotiation value
146 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700147 * Determines the link capabilities by reading the AUTOC register.
Auke Kok9a799d72007-09-15 14:07:45 -0700148 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700149s32 ixgbe_get_copper_link_capabilities_82598(struct ixgbe_hw *hw,
150 ixgbe_link_speed *speed,
151 bool *autoneg)
Auke Kok9a799d72007-09-15 14:07:45 -0700152{
153 s32 status = IXGBE_ERR_LINK_SETUP;
154 u16 speed_ability;
155
156 *speed = 0;
157 *autoneg = true;
158
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700159 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700160 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
161 &speed_ability);
Auke Kok9a799d72007-09-15 14:07:45 -0700162
163 if (status == 0) {
164 if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
165 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
166 if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
167 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
168 }
169
170 return status;
171}
172
173/**
174 * ixgbe_get_media_type_82598 - Determines media type
175 * @hw: pointer to hardware structure
176 *
177 * Returns the media type (fiber, copper, backplane)
178 **/
179static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw)
180{
181 enum ixgbe_media_type media_type;
182
183 /* Media type for I82598 is based on device ID */
184 switch (hw->device_id) {
185 case IXGBE_DEV_ID_82598AF_DUAL_PORT:
186 case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
187 case IXGBE_DEV_ID_82598EB_CX4:
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -0700188 case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -0700189 case IXGBE_DEV_ID_82598EB_XF_LR:
Auke Kok9a799d72007-09-15 14:07:45 -0700190 media_type = ixgbe_media_type_fiber;
191 break;
Auke Kok9a799d72007-09-15 14:07:45 -0700192 default:
193 media_type = ixgbe_media_type_unknown;
194 break;
195 }
196
197 return media_type;
198}
199
200/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700201 * ixgbe_setup_fc_82598 - Configure flow control settings
202 * @hw: pointer to hardware structure
203 * @packetbuf_num: packet buffer number (0-7)
204 *
205 * Configures the flow control settings based on SW configuration. This
206 * function is used for 802.3x flow control configuration only.
207 **/
208s32 ixgbe_setup_fc_82598(struct ixgbe_hw *hw, s32 packetbuf_num)
209{
210 u32 frctl_reg;
211 u32 rmcs_reg;
212
213 if (packetbuf_num < 0 || packetbuf_num > 7) {
214 hw_dbg(hw, "Invalid packet buffer number [%d], expected range is"
215 " 0-7\n", packetbuf_num);
216 }
217
218 frctl_reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
219 frctl_reg &= ~(IXGBE_FCTRL_RFCE | IXGBE_FCTRL_RPFCE);
220
221 rmcs_reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
222 rmcs_reg &= ~(IXGBE_RMCS_TFCE_PRIORITY | IXGBE_RMCS_TFCE_802_3X);
223
224 /*
225 * 10 gig parts do not have a word in the EEPROM to determine the
226 * default flow control setting, so we explicitly set it to full.
227 */
228 if (hw->fc.type == ixgbe_fc_default)
229 hw->fc.type = ixgbe_fc_full;
230
231 /*
232 * We want to save off the original Flow Control configuration just in
233 * case we get disconnected and then reconnected into a different hub
234 * or switch with different Flow Control capabilities.
235 */
236 hw->fc.original_type = hw->fc.type;
237
238 /*
239 * The possible values of the "flow_control" parameter are:
240 * 0: Flow control is completely disabled
241 * 1: Rx flow control is enabled (we can receive pause frames but not
242 * send pause frames).
243 * 2: Tx flow control is enabled (we can send pause frames but we do not
244 * support receiving pause frames)
245 * 3: Both Rx and Tx flow control (symmetric) are enabled.
246 * other: Invalid.
247 */
248 switch (hw->fc.type) {
249 case ixgbe_fc_none:
250 break;
251 case ixgbe_fc_rx_pause:
252 /*
253 * Rx Flow control is enabled,
254 * and Tx Flow control is disabled.
255 */
256 frctl_reg |= IXGBE_FCTRL_RFCE;
257 break;
258 case ixgbe_fc_tx_pause:
259 /*
260 * Tx Flow control is enabled, and Rx Flow control is disabled,
261 * by a software over-ride.
262 */
263 rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
264 break;
265 case ixgbe_fc_full:
266 /*
267 * Flow control (both Rx and Tx) is enabled by a software
268 * over-ride.
269 */
270 frctl_reg |= IXGBE_FCTRL_RFCE;
271 rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
272 break;
273 default:
274 /* We should never get here. The value should be 0-3. */
275 hw_dbg(hw, "Flow control param set incorrectly\n");
276 break;
277 }
278
279 /* Enable 802.3x based flow control settings. */
280 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, frctl_reg);
281 IXGBE_WRITE_REG(hw, IXGBE_RMCS, rmcs_reg);
282
283 /*
284 * Check for invalid software configuration, zeros are completely
285 * invalid for all parameters used past this point, and if we enable
286 * flow control with zero water marks, we blast flow control packets.
287 */
288 if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
289 hw_dbg(hw, "Flow control structure initialized incorrectly\n");
290 return IXGBE_ERR_INVALID_LINK_SETTINGS;
291 }
292
293 /*
294 * We need to set up the Receive Threshold high and low water
295 * marks as well as (optionally) enabling the transmission of
296 * XON frames.
297 */
298 if (hw->fc.type & ixgbe_fc_tx_pause) {
299 if (hw->fc.send_xon) {
300 IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num),
301 (hw->fc.low_water | IXGBE_FCRTL_XONE));
302 } else {
303 IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num),
304 hw->fc.low_water);
305 }
306 IXGBE_WRITE_REG(hw, IXGBE_FCRTH(packetbuf_num),
307 (hw->fc.high_water)|IXGBE_FCRTH_FCEN);
308 }
309
310 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(0), hw->fc.pause_time);
311 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
312
313 return 0;
314}
315
316/**
Auke Kok9a799d72007-09-15 14:07:45 -0700317 * ixgbe_setup_mac_link_82598 - Configures MAC link settings
318 * @hw: pointer to hardware structure
319 *
320 * Configures link settings based on values in the ixgbe_hw struct.
321 * Restarts the link. Performs autonegotiation if needed.
322 **/
323static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw)
324{
325 u32 autoc_reg;
326 u32 links_reg;
327 u32 i;
328 s32 status = 0;
329
330 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
331
332 if (hw->mac.link_settings_loaded) {
333 autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
334 autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
335 autoc_reg |= hw->mac.link_attach_type;
336 autoc_reg |= hw->mac.link_mode_select;
337
338 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700339 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700340 msleep(50);
341 }
342
343 /* Restart link */
344 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
345 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
346
347 /* Only poll for autoneg to complete if specified to do so */
348 if (hw->phy.autoneg_wait_to_complete) {
349 if (hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN ||
350 hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
351 links_reg = 0; /* Just in case Autoneg time = 0 */
352 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
353 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
354 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
355 break;
356 msleep(100);
357 }
358 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
359 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700360 hw_dbg(hw, "Autonegotiation did not complete.\n");
Auke Kok9a799d72007-09-15 14:07:45 -0700361 }
362 }
363 }
364
365 /*
366 * We want to save off the original Flow Control configuration just in
367 * case we get disconnected and then reconnected into a different hub
368 * or switch with different Flow Control capabilities.
369 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700370 hw->fc.original_type = hw->fc.type;
371 ixgbe_setup_fc_82598(hw, 0);
Auke Kok9a799d72007-09-15 14:07:45 -0700372
373 /* Add delay to filter out noises during initial link setup */
374 msleep(50);
375
376 return status;
377}
378
379/**
380 * ixgbe_check_mac_link_82598 - Get link/speed status
381 * @hw: pointer to hardware structure
382 * @speed: pointer to link speed
383 * @link_up: true is link is up, false otherwise
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700384 * @link_up_wait_to_complete: bool used to wait for link up or not
Auke Kok9a799d72007-09-15 14:07:45 -0700385 *
386 * Reads the links register to determine if link is up and the current speed
387 **/
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700388static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw,
389 ixgbe_link_speed *speed, bool *link_up,
390 bool link_up_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700391{
392 u32 links_reg;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700393 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -0700394
395 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700396 if (link_up_wait_to_complete) {
397 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
398 if (links_reg & IXGBE_LINKS_UP) {
399 *link_up = true;
400 break;
401 } else {
402 *link_up = false;
403 }
404 msleep(100);
405 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
406 }
407 } else {
408 if (links_reg & IXGBE_LINKS_UP)
409 *link_up = true;
410 else
411 *link_up = false;
412 }
Auke Kok9a799d72007-09-15 14:07:45 -0700413
414 if (links_reg & IXGBE_LINKS_SPEED)
415 *speed = IXGBE_LINK_SPEED_10GB_FULL;
416 else
417 *speed = IXGBE_LINK_SPEED_1GB_FULL;
418
419 return 0;
420}
421
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700422
Auke Kok9a799d72007-09-15 14:07:45 -0700423/**
424 * ixgbe_setup_mac_link_speed_82598 - Set MAC link speed
425 * @hw: pointer to hardware structure
426 * @speed: new link speed
427 * @autoneg: true if auto-negotiation enabled
428 * @autoneg_wait_to_complete: true if waiting is needed to complete
429 *
430 * Set the link speed in the AUTOC register and restarts link.
431 **/
432static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700433 ixgbe_link_speed speed, bool autoneg,
434 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700435{
436 s32 status = 0;
437
438 /* If speed is 10G, then check for CX4 or XAUI. */
439 if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700440 (!(hw->mac.link_attach_type & IXGBE_AUTOC_10G_KX4))) {
Auke Kok9a799d72007-09-15 14:07:45 -0700441 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700442 } else if ((speed == IXGBE_LINK_SPEED_1GB_FULL) && (!autoneg)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700443 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700444 } else if (autoneg) {
Auke Kok9a799d72007-09-15 14:07:45 -0700445 /* BX mode - Autonegotiate 1G */
446 if (!(hw->mac.link_attach_type & IXGBE_AUTOC_1G_PMA_PMD))
447 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_AN;
448 else /* KX/KX4 mode */
449 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN_1G_AN;
450 } else {
451 status = IXGBE_ERR_LINK_SETUP;
452 }
453
454 if (status == 0) {
455 hw->phy.autoneg_wait_to_complete = autoneg_wait_to_complete;
456
457 hw->mac.link_settings_loaded = true;
458 /*
459 * Setup and restart the link based on the new values in
460 * ixgbe_hw This will write the AUTOC register based on the new
461 * stored values
462 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700463 ixgbe_setup_mac_link_82598(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700464 }
465
466 return status;
467}
468
469
470/**
471 * ixgbe_setup_copper_link_82598 - Setup copper link settings
472 * @hw: pointer to hardware structure
473 *
474 * Configures link settings based on values in the ixgbe_hw struct.
475 * Restarts the link. Performs autonegotiation if needed. Restart
476 * phy and wait for autonegotiate to finish. Then synchronize the
477 * MAC and PHY.
478 **/
479static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw)
480{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700481 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700482
483 /* Restart autonegotiation on PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700484 status = hw->phy.ops.setup_link(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700485
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700486 /* Set MAC to KX/KX4 autoneg, which defaults to Parallel detection */
Auke Kok3957d632007-10-31 15:22:10 -0700487 hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
488 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
Auke Kok9a799d72007-09-15 14:07:45 -0700489
Auke Kok3957d632007-10-31 15:22:10 -0700490 /* Set up MAC */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700491 ixgbe_setup_mac_link_82598(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700492
493 return status;
494}
495
496/**
497 * ixgbe_setup_copper_link_speed_82598 - Set the PHY autoneg advertised field
498 * @hw: pointer to hardware structure
499 * @speed: new link speed
500 * @autoneg: true if autonegotiation enabled
501 * @autoneg_wait_to_complete: true if waiting is needed to complete
502 *
503 * Sets the link speed in the AUTOC register in the MAC and restarts link.
504 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700505static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700506 ixgbe_link_speed speed,
507 bool autoneg,
508 bool autoneg_wait_to_complete)
Auke Kok9a799d72007-09-15 14:07:45 -0700509{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700510 s32 status;
Auke Kok9a799d72007-09-15 14:07:45 -0700511
512 /* Setup the PHY according to input speed */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700513 status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
514 autoneg_wait_to_complete);
Auke Kok9a799d72007-09-15 14:07:45 -0700515
Auke Kok3957d632007-10-31 15:22:10 -0700516 /* Set MAC to KX/KX4 autoneg, which defaults to Parallel detection */
517 hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
518 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
519
520 /* Set up MAC */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700521 ixgbe_setup_mac_link_82598(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700522
523 return status;
524}
525
526/**
527 * ixgbe_reset_hw_82598 - Performs hardware reset
528 * @hw: pointer to hardware structure
529 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700530 * Resets the hardware by resetting the transmit and receive units, masks and
Auke Kok9a799d72007-09-15 14:07:45 -0700531 * clears all interrupts, performing a PHY reset, and performing a link (MAC)
532 * reset.
533 **/
534static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
535{
536 s32 status = 0;
537 u32 ctrl;
538 u32 gheccr;
539 u32 i;
540 u32 autoc;
541 u8 analog_val;
542
543 /* Call adapter stop to disable tx/rx and clear interrupts */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700544 hw->mac.ops.stop_adapter(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700545
546 /*
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700547 * Power up the Atlas Tx lanes if they are currently powered down.
548 * Atlas Tx lanes are powered down for MAC loopback tests, but
Auke Kok9a799d72007-09-15 14:07:45 -0700549 * they are not automatically restored on reset.
550 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700551 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700552 if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700553 /* Enable Tx Atlas so packets can be transmitted again */
554 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
555 &analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700556 analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700557 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
558 analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700559
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700560 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
561 &analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700562 analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700563 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
564 analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700565
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700566 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
567 &analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700568 analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700569 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
570 analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700571
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700572 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
573 &analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700574 analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700575 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
576 analog_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700577 }
578
579 /* Reset PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700580 if (hw->phy.reset_disable == false)
581 hw->phy.ops.reset(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700582
583 /*
584 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
585 * access and verify no pending requests before reset
586 */
587 if (ixgbe_disable_pcie_master(hw) != 0) {
588 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
589 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
590 }
591
592 /*
593 * Issue global reset to the MAC. This needs to be a SW reset.
594 * If link reset is used, it might reset the MAC when mng is using it
595 */
596 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
597 IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
598 IXGBE_WRITE_FLUSH(hw);
599
600 /* Poll for reset bit to self-clear indicating reset is complete */
601 for (i = 0; i < 10; i++) {
602 udelay(1);
603 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
604 if (!(ctrl & IXGBE_CTRL_RST))
605 break;
606 }
607 if (ctrl & IXGBE_CTRL_RST) {
608 status = IXGBE_ERR_RESET_FAILED;
609 hw_dbg(hw, "Reset polling failed to complete.\n");
610 }
611
612 msleep(50);
613
614 gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
615 gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
616 IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
617
618 /*
619 * AUTOC register which stores link settings gets cleared
620 * and reloaded from EEPROM after reset. We need to restore
621 * our stored value from init in case SW changed the attach
622 * type or speed. If this is the first time and link settings
623 * have not been stored, store default settings from AUTOC.
624 */
625 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
626 if (hw->mac.link_settings_loaded) {
627 autoc &= ~(IXGBE_AUTOC_LMS_ATTACH_TYPE);
628 autoc &= ~(IXGBE_AUTOC_LMS_MASK);
629 autoc |= hw->mac.link_attach_type;
630 autoc |= hw->mac.link_mode_select;
631 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
632 } else {
633 hw->mac.link_attach_type =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700634 (autoc & IXGBE_AUTOC_LMS_ATTACH_TYPE);
Auke Kok9a799d72007-09-15 14:07:45 -0700635 hw->mac.link_mode_select = (autoc & IXGBE_AUTOC_LMS_MASK);
636 hw->mac.link_settings_loaded = true;
637 }
638
639 /* Store the permanent mac address */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700640 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
Auke Kok9a799d72007-09-15 14:07:45 -0700641
642 return status;
643}
644
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700645/**
646 * ixgbe_set_vmdq_82598 - Associate a VMDq set index with a rx address
647 * @hw: pointer to hardware struct
648 * @rar: receive address register index to associate with a VMDq index
649 * @vmdq: VMDq set index
650 **/
651s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
652{
653 u32 rar_high;
654
655 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
656 rar_high &= ~IXGBE_RAH_VIND_MASK;
657 rar_high |= ((vmdq << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK);
658 IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
659 return 0;
660}
661
662/**
663 * ixgbe_clear_vmdq_82598 - Disassociate a VMDq set index from an rx address
664 * @hw: pointer to hardware struct
665 * @rar: receive address register index to associate with a VMDq index
666 * @vmdq: VMDq clear index (not used in 82598, but elsewhere)
667 **/
668static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
669{
670 u32 rar_high;
671 u32 rar_entries = hw->mac.num_rar_entries;
672
673 if (rar < rar_entries) {
674 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
675 if (rar_high & IXGBE_RAH_VIND_MASK) {
676 rar_high &= ~IXGBE_RAH_VIND_MASK;
677 IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
678 }
679 } else {
680 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
681 }
682
683 return 0;
684}
685
686/**
687 * ixgbe_set_vfta_82598 - Set VLAN filter table
688 * @hw: pointer to hardware structure
689 * @vlan: VLAN id to write to VLAN filter
690 * @vind: VMDq output index that maps queue to VLAN id in VFTA
691 * @vlan_on: boolean flag to turn on/off VLAN in VFTA
692 *
693 * Turn on/off specified VLAN in the VLAN filter table.
694 **/
695s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan, u32 vind,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700696 bool vlan_on)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700697{
698 u32 regindex;
699 u32 bitindex;
700 u32 bits;
701 u32 vftabyte;
702
703 if (vlan > 4095)
704 return IXGBE_ERR_PARAM;
705
706 /* Determine 32-bit word position in array */
707 regindex = (vlan >> 5) & 0x7F; /* upper seven bits */
708
709 /* Determine the location of the (VMD) queue index */
710 vftabyte = ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */
711 bitindex = (vlan & 0x7) << 2; /* lower 3 bits indicate nibble */
712
713 /* Set the nibble for VMD queue index */
714 bits = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex));
715 bits &= (~(0x0F << bitindex));
716 bits |= (vind << bitindex);
717 IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex), bits);
718
719 /* Determine the location of the bit for this VLAN id */
720 bitindex = vlan & 0x1F; /* lower five bits */
721
722 bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
723 if (vlan_on)
724 /* Turn on this VLAN id */
725 bits |= (1 << bitindex);
726 else
727 /* Turn off this VLAN id */
728 bits &= ~(1 << bitindex);
729 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
730
731 return 0;
732}
733
734/**
735 * ixgbe_clear_vfta_82598 - Clear VLAN filter table
736 * @hw: pointer to hardware structure
737 *
738 * Clears the VLAN filer table, and the VMDq index associated with the filter
739 **/
740static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw)
741{
742 u32 offset;
743 u32 vlanbyte;
744
745 for (offset = 0; offset < hw->mac.vft_size; offset++)
746 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
747
748 for (vlanbyte = 0; vlanbyte < 4; vlanbyte++)
749 for (offset = 0; offset < hw->mac.vft_size; offset++)
750 IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset),
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700751 0);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700752
753 return 0;
754}
755
756/**
757 * ixgbe_blink_led_start_82598 - Blink LED based on index.
758 * @hw: pointer to hardware structure
759 * @index: led number to blink
760 **/
761static s32 ixgbe_blink_led_start_82598(struct ixgbe_hw *hw, u32 index)
762{
763 ixgbe_link_speed speed = 0;
764 bool link_up = 0;
765 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
766 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
767
768 /*
769 * Link must be up to auto-blink the LEDs on the 82598EB MAC;
770 * force it if link is down.
771 */
772 hw->mac.ops.check_link(hw, &speed, &link_up, false);
773
774 if (!link_up) {
775 autoc_reg |= IXGBE_AUTOC_FLU;
776 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
777 msleep(10);
778 }
779
780 led_reg &= ~IXGBE_LED_MODE_MASK(index);
781 led_reg |= IXGBE_LED_BLINK(index);
782 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
783 IXGBE_WRITE_FLUSH(hw);
784
785 return 0;
786}
787
788/**
789 * ixgbe_blink_led_stop_82598 - Stop blinking LED based on index.
790 * @hw: pointer to hardware structure
791 * @index: led number to stop blinking
792 **/
793static s32 ixgbe_blink_led_stop_82598(struct ixgbe_hw *hw, u32 index)
794{
795 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
796 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
797
798 autoc_reg &= ~IXGBE_AUTOC_FLU;
799 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
800 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
801
802 led_reg &= ~IXGBE_LED_MODE_MASK(index);
803 led_reg &= ~IXGBE_LED_BLINK(index);
804 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
805 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
806 IXGBE_WRITE_FLUSH(hw);
807
808 return 0;
809}
810
811/**
812 * ixgbe_read_analog_reg8_82598 - Reads 8 bit Atlas analog register
813 * @hw: pointer to hardware structure
814 * @reg: analog register to read
815 * @val: read value
816 *
817 * Performs read operation to Atlas analog register specified.
818 **/
819s32 ixgbe_read_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 *val)
820{
821 u32 atlas_ctl;
822
823 IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL,
824 IXGBE_ATLASCTL_WRITE_CMD | (reg << 8));
825 IXGBE_WRITE_FLUSH(hw);
826 udelay(10);
827 atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
828 *val = (u8)atlas_ctl;
829
830 return 0;
831}
832
833/**
834 * ixgbe_write_analog_reg8_82598 - Writes 8 bit Atlas analog register
835 * @hw: pointer to hardware structure
836 * @reg: atlas register to write
837 * @val: value to write
838 *
839 * Performs write operation to Atlas analog register specified.
840 **/
841s32 ixgbe_write_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 val)
842{
843 u32 atlas_ctl;
844
845 atlas_ctl = (reg << 8) | val;
846 IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl);
847 IXGBE_WRITE_FLUSH(hw);
848 udelay(10);
849
850 return 0;
851}
852
853/**
854 * ixgbe_get_supported_physical_layer_82598 - Returns physical layer type
855 * @hw: pointer to hardware structure
856 *
857 * Determines physical layer capabilities of the current configuration.
858 **/
859s32 ixgbe_get_supported_physical_layer_82598(struct ixgbe_hw *hw)
860{
861 s32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
862
863 switch (hw->device_id) {
864 case IXGBE_DEV_ID_82598EB_CX4:
865 case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
866 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
867 break;
868 case IXGBE_DEV_ID_82598AF_DUAL_PORT:
869 case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
870 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
871 break;
872 case IXGBE_DEV_ID_82598EB_XF_LR:
873 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
874 break;
875
876 default:
877 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
878 break;
879 }
880
881 return physical_layer;
882}
883
Auke Kok9a799d72007-09-15 14:07:45 -0700884static struct ixgbe_mac_operations mac_ops_82598 = {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700885 .init_hw = &ixgbe_init_hw_generic,
886 .reset_hw = &ixgbe_reset_hw_82598,
887 .start_hw = &ixgbe_start_hw_generic,
888 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
Auke Kok9a799d72007-09-15 14:07:45 -0700889 .get_media_type = &ixgbe_get_media_type_82598,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700890 .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82598,
891 .get_mac_addr = &ixgbe_get_mac_addr_generic,
892 .stop_adapter = &ixgbe_stop_adapter_generic,
893 .read_analog_reg8 = &ixgbe_read_analog_reg8_82598,
894 .write_analog_reg8 = &ixgbe_write_analog_reg8_82598,
Auke Kok3957d632007-10-31 15:22:10 -0700895 .setup_link = &ixgbe_setup_mac_link_82598,
Auke Kok3957d632007-10-31 15:22:10 -0700896 .setup_link_speed = &ixgbe_setup_mac_link_speed_82598,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700897 .check_link = &ixgbe_check_mac_link_82598,
898 .get_link_capabilities = &ixgbe_get_link_capabilities_82598,
899 .led_on = &ixgbe_led_on_generic,
900 .led_off = &ixgbe_led_off_generic,
901 .blink_led_start = &ixgbe_blink_led_start_82598,
902 .blink_led_stop = &ixgbe_blink_led_stop_82598,
903 .set_rar = &ixgbe_set_rar_generic,
904 .clear_rar = &ixgbe_clear_rar_generic,
905 .set_vmdq = &ixgbe_set_vmdq_82598,
906 .clear_vmdq = &ixgbe_clear_vmdq_82598,
907 .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
908 .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
909 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
910 .enable_mc = &ixgbe_enable_mc_generic,
911 .disable_mc = &ixgbe_disable_mc_generic,
912 .clear_vfta = &ixgbe_clear_vfta_82598,
913 .set_vfta = &ixgbe_set_vfta_82598,
914 .setup_fc = &ixgbe_setup_fc_82598,
915};
916
917static struct ixgbe_eeprom_operations eeprom_ops_82598 = {
918 .init_params = &ixgbe_init_eeprom_params_generic,
919 .read = &ixgbe_read_eeprom_generic,
920 .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
921 .update_checksum = &ixgbe_update_eeprom_checksum_generic,
922};
923
924static struct ixgbe_phy_operations phy_ops_82598 = {
925 .identify = &ixgbe_identify_phy_generic,
926 /* .identify_sfp = &ixgbe_identify_sfp_module_generic, */
927 .reset = &ixgbe_reset_phy_generic,
928 .read_reg = &ixgbe_read_phy_reg_generic,
929 .write_reg = &ixgbe_write_phy_reg_generic,
930 .setup_link = &ixgbe_setup_phy_link_generic,
931 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
Auke Kok9a799d72007-09-15 14:07:45 -0700932};
933
Auke Kok3957d632007-10-31 15:22:10 -0700934struct ixgbe_info ixgbe_82598_info = {
Auke Kok9a799d72007-09-15 14:07:45 -0700935 .mac = ixgbe_mac_82598EB,
936 .get_invariants = &ixgbe_get_invariants_82598,
937 .mac_ops = &mac_ops_82598,
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700938 .eeprom_ops = &eeprom_ops_82598,
939 .phy_ops = &phy_ops_82598,
Auke Kok9a799d72007-09-15 14:07:45 -0700940};
941