blob: ddbc3eec6a1bde454d926b58cb9d6ec3e03e6902 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore434c5e32013-01-08 05:02:28 +00004 Copyright(c) 1999 - 2013 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>
Jiri Pirkoccffad252009-05-22 23:22:17 +000031#include <linux/netdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070032
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000033#include "ixgbe.h"
Auke Kok9a799d72007-09-15 14:07:45 -070034#include "ixgbe_common.h"
35#include "ixgbe_phy.h"
36
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070037static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070038static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
39static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070040static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
41static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
42static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
43 u16 count);
44static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
45static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
46static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
47static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070048
Auke Kok9a799d72007-09-15 14:07:45 -070049static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
Emil Tantiloveb9c3e32011-03-24 00:57:50 +000050static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg);
Emil Tantilov68c70052011-04-20 08:49:06 +000051static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
52 u16 words, u16 *data);
53static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
54 u16 words, u16 *data);
55static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
56 u16 offset);
Emil Tantilovff9d1a52011-08-16 04:35:11 +000057static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw);
Auke Kok9a799d72007-09-15 14:07:45 -070058
59/**
Alexander Duyck67a79df2012-04-19 17:49:56 +000060 * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
61 * control
62 * @hw: pointer to hardware structure
63 *
64 * There are several phys that do not support autoneg flow control. This
65 * function check the device id to see if the associated phy supports
66 * autoneg flow control.
67 **/
Don Skidmore73d80953d2013-07-31 02:19:24 +000068bool ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
Alexander Duyck67a79df2012-04-19 17:49:56 +000069{
Don Skidmore73d80953d2013-07-31 02:19:24 +000070 bool supported = false;
71 ixgbe_link_speed speed;
72 bool link_up;
Alexander Duyck67a79df2012-04-19 17:49:56 +000073
Don Skidmore73d80953d2013-07-31 02:19:24 +000074 switch (hw->phy.media_type) {
75 case ixgbe_media_type_fiber:
76 hw->mac.ops.check_link(hw, &speed, &link_up, false);
77 /* if link is down, assume supported */
78 if (link_up)
79 supported = speed == IXGBE_LINK_SPEED_1GB_FULL ?
80 true : false;
81 else
82 supported = true;
83 break;
84 case ixgbe_media_type_backplane:
85 supported = true;
86 break;
87 case ixgbe_media_type_copper:
88 /* only some copper devices support flow control autoneg */
89 switch (hw->device_id) {
90 case IXGBE_DEV_ID_82599_T3_LOM:
91 case IXGBE_DEV_ID_X540T:
92 case IXGBE_DEV_ID_X540T1:
93 supported = true;
94 break;
95 default:
96 break;
97 }
Alexander Duyck67a79df2012-04-19 17:49:56 +000098 default:
Don Skidmore73d80953d2013-07-31 02:19:24 +000099 break;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000100 }
Don Skidmore73d80953d2013-07-31 02:19:24 +0000101
102 return supported;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000103}
104
105/**
106 * ixgbe_setup_fc - Set up flow control
107 * @hw: pointer to hardware structure
108 *
109 * Called at init time to set up flow control.
110 **/
Alexander Duyck041441d2012-04-19 17:48:48 +0000111static s32 ixgbe_setup_fc(struct ixgbe_hw *hw)
Alexander Duyck67a79df2012-04-19 17:49:56 +0000112{
113 s32 ret_val = 0;
114 u32 reg = 0, reg_bp = 0;
115 u16 reg_cu = 0;
Don Skidmored7bbcd32012-10-24 06:19:01 +0000116 bool got_lock = false;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000117
Alexander Duyck67a79df2012-04-19 17:49:56 +0000118 /*
119 * Validate the requested mode. Strict IEEE mode does not allow
120 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
121 */
122 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
123 hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
124 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
125 goto out;
126 }
127
128 /*
129 * 10gig parts do not have a word in the EEPROM to determine the
130 * default flow control setting, so we explicitly set it to full.
131 */
132 if (hw->fc.requested_mode == ixgbe_fc_default)
133 hw->fc.requested_mode = ixgbe_fc_full;
134
135 /*
136 * Set up the 1G and 10G flow control advertisement registers so the
137 * HW will be able to do fc autoneg once the cable is plugged in. If
138 * we link at 10G, the 1G advertisement is harmless and vice versa.
139 */
Alexander Duyck67a79df2012-04-19 17:49:56 +0000140 switch (hw->phy.media_type) {
141 case ixgbe_media_type_fiber:
142 case ixgbe_media_type_backplane:
143 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
144 reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
145 break;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000146 case ixgbe_media_type_copper:
147 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
148 MDIO_MMD_AN, &reg_cu);
149 break;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000150 default:
Alexander Duyck041441d2012-04-19 17:48:48 +0000151 break;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000152 }
153
154 /*
155 * The possible values of fc.requested_mode are:
156 * 0: Flow control is completely disabled
157 * 1: Rx flow control is enabled (we can receive pause frames,
158 * but not send pause frames).
159 * 2: Tx flow control is enabled (we can send pause frames but
160 * we do not support receiving pause frames).
161 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Alexander Duyck67a79df2012-04-19 17:49:56 +0000162 * other: Invalid.
163 */
164 switch (hw->fc.requested_mode) {
165 case ixgbe_fc_none:
166 /* Flow control completely disabled by software override. */
167 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
168 if (hw->phy.media_type == ixgbe_media_type_backplane)
169 reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
170 IXGBE_AUTOC_ASM_PAUSE);
171 else if (hw->phy.media_type == ixgbe_media_type_copper)
172 reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
173 break;
Alexander Duyck041441d2012-04-19 17:48:48 +0000174 case ixgbe_fc_tx_pause:
175 /*
176 * Tx Flow control is enabled, and Rx Flow control is
177 * disabled by software override.
178 */
179 reg |= IXGBE_PCS1GANA_ASM_PAUSE;
180 reg &= ~IXGBE_PCS1GANA_SYM_PAUSE;
181 if (hw->phy.media_type == ixgbe_media_type_backplane) {
182 reg_bp |= IXGBE_AUTOC_ASM_PAUSE;
183 reg_bp &= ~IXGBE_AUTOC_SYM_PAUSE;
184 } else if (hw->phy.media_type == ixgbe_media_type_copper) {
185 reg_cu |= IXGBE_TAF_ASM_PAUSE;
186 reg_cu &= ~IXGBE_TAF_SYM_PAUSE;
187 }
188 break;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000189 case ixgbe_fc_rx_pause:
190 /*
191 * Rx Flow control is enabled and Tx Flow control is
192 * disabled by software override. Since there really
193 * isn't a way to advertise that we are capable of RX
194 * Pause ONLY, we will advertise that we support both
Alexander Duyck041441d2012-04-19 17:48:48 +0000195 * symmetric and asymmetric Rx PAUSE, as such we fall
196 * through to the fc_full statement. Later, we will
Alexander Duyck67a79df2012-04-19 17:49:56 +0000197 * disable the adapter's ability to send PAUSE frames.
198 */
Alexander Duyck67a79df2012-04-19 17:49:56 +0000199 case ixgbe_fc_full:
200 /* Flow control (both Rx and Tx) is enabled by SW override. */
Alexander Duyck041441d2012-04-19 17:48:48 +0000201 reg |= IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000202 if (hw->phy.media_type == ixgbe_media_type_backplane)
Alexander Duyck041441d2012-04-19 17:48:48 +0000203 reg_bp |= IXGBE_AUTOC_SYM_PAUSE |
204 IXGBE_AUTOC_ASM_PAUSE;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000205 else if (hw->phy.media_type == ixgbe_media_type_copper)
Alexander Duyck041441d2012-04-19 17:48:48 +0000206 reg_cu |= IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000207 break;
Alexander Duyck67a79df2012-04-19 17:49:56 +0000208 default:
209 hw_dbg(hw, "Flow control param set incorrectly\n");
210 ret_val = IXGBE_ERR_CONFIG;
211 goto out;
212 break;
213 }
214
215 if (hw->mac.type != ixgbe_mac_X540) {
216 /*
217 * Enable auto-negotiation between the MAC & PHY;
218 * the MAC will advertise clause 37 flow control.
219 */
220 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
221 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
222
223 /* Disable AN timeout */
224 if (hw->fc.strict_ieee)
225 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
226
227 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
228 hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
229 }
230
231 /*
232 * AUTOC restart handles negotiation of 1G and 10G on backplane
233 * and copper. There is no need to set the PCS1GCTL register.
234 *
235 */
236 if (hw->phy.media_type == ixgbe_media_type_backplane) {
Don Skidmored7bbcd32012-10-24 06:19:01 +0000237 /* Need the SW/FW semaphore around AUTOC writes if 82599 and
238 * LESM is on, likewise reset_pipeline requries the lock as
239 * it also writes AUTOC.
240 */
241 if ((hw->mac.type == ixgbe_mac_82599EB) &&
242 ixgbe_verify_lesm_fw_enabled_82599(hw)) {
243 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
244 IXGBE_GSSR_MAC_CSR_SM);
245 if (ret_val)
246 goto out;
247
248 got_lock = true;
249 }
250
Alexander Duyck67a79df2012-04-19 17:49:56 +0000251 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
Don Skidmored7bbcd32012-10-24 06:19:01 +0000252
253 if (hw->mac.type == ixgbe_mac_82599EB)
254 ixgbe_reset_pipeline_82599(hw);
255
256 if (got_lock)
257 hw->mac.ops.release_swfw_sync(hw,
258 IXGBE_GSSR_MAC_CSR_SM);
259
Alexander Duyck67a79df2012-04-19 17:49:56 +0000260 } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
Don Skidmore73d80953d2013-07-31 02:19:24 +0000261 ixgbe_device_supports_autoneg_fc(hw)) {
Alexander Duyck67a79df2012-04-19 17:49:56 +0000262 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
263 MDIO_MMD_AN, reg_cu);
264 }
265
266 hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
267out:
268 return ret_val;
269}
270
271/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700272 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
Auke Kok9a799d72007-09-15 14:07:45 -0700273 * @hw: pointer to hardware structure
274 *
275 * Starts the hardware by filling the bus info structure and media type, clears
276 * all on chip counters, initializes receive address registers, multicast
277 * table, VLAN filter table, calls routine to set up link and flow control
278 * settings, and leaves transmit and receive units disabled and uninitialized
279 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700280s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700281{
282 u32 ctrl_ext;
283
284 /* Set the media type */
285 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
286
287 /* Identify the PHY */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700288 hw->phy.ops.identify(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700289
Auke Kok9a799d72007-09-15 14:07:45 -0700290 /* Clear the VLAN filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700291 hw->mac.ops.clear_vfta(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700292
Auke Kok9a799d72007-09-15 14:07:45 -0700293 /* Clear statistics registers */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700294 hw->mac.ops.clear_hw_cntrs(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700295
296 /* Set No Snoop Disable */
297 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
298 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
299 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok3957d632007-10-31 15:22:10 -0700300 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700301
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +0000302 /* Setup flow control */
Alexander Duyck041441d2012-04-19 17:48:48 +0000303 ixgbe_setup_fc(hw);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +0000304
Auke Kok9a799d72007-09-15 14:07:45 -0700305 /* Clear adapter stopped flag */
306 hw->adapter_stopped = false;
307
308 return 0;
309}
310
311/**
Emil Tantilov7184b7c2011-03-18 08:18:22 +0000312 * ixgbe_start_hw_gen2 - Init sequence for common device family
313 * @hw: pointer to hw structure
314 *
315 * Performs the init sequence common to the second generation
316 * of 10 GbE devices.
317 * Devices in the second generation:
318 * 82599
319 * X540
320 **/
321s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
322{
323 u32 i;
Emil Tantilov3d5c5202011-03-19 01:32:46 +0000324 u32 regval;
Emil Tantilov7184b7c2011-03-18 08:18:22 +0000325
326 /* Clear the rate limiters */
327 for (i = 0; i < hw->mac.max_tx_queues; i++) {
328 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
329 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
330 }
331 IXGBE_WRITE_FLUSH(hw);
332
Emil Tantilov3d5c5202011-03-19 01:32:46 +0000333 /* Disable relaxed ordering */
334 for (i = 0; i < hw->mac.max_tx_queues; i++) {
335 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000336 regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
Emil Tantilov3d5c5202011-03-19 01:32:46 +0000337 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
338 }
339
340 for (i = 0; i < hw->mac.max_rx_queues; i++) {
341 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000342 regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN |
343 IXGBE_DCA_RXCTRL_HEAD_WRO_EN);
Emil Tantilov3d5c5202011-03-19 01:32:46 +0000344 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
345 }
346
Emil Tantilov7184b7c2011-03-18 08:18:22 +0000347 return 0;
348}
349
350/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700351 * ixgbe_init_hw_generic - Generic hardware initialization
Auke Kok9a799d72007-09-15 14:07:45 -0700352 * @hw: pointer to hardware structure
353 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700354 * Initialize the hardware by resetting the hardware, filling the bus info
Auke Kok9a799d72007-09-15 14:07:45 -0700355 * structure and media type, clears all on chip counters, initializes receive
356 * address registers, multicast table, VLAN filter table, calls routine to set
357 * up link and flow control settings, and leaves transmit and receive units
358 * disabled and uninitialized
359 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700360s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700361{
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000362 s32 status;
363
Auke Kok9a799d72007-09-15 14:07:45 -0700364 /* Reset the hardware */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000365 status = hw->mac.ops.reset_hw(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700366
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000367 if (status == 0) {
368 /* Start the HW */
369 status = hw->mac.ops.start_hw(hw);
370 }
Auke Kok9a799d72007-09-15 14:07:45 -0700371
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +0000372 return status;
Auke Kok9a799d72007-09-15 14:07:45 -0700373}
374
375/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700376 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
Auke Kok9a799d72007-09-15 14:07:45 -0700377 * @hw: pointer to hardware structure
378 *
379 * Clears all hardware statistics counters by reading them from the hardware
380 * Statistics counters are clear on read.
381 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700382s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700383{
384 u16 i = 0;
385
386 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
387 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
388 IXGBE_READ_REG(hw, IXGBE_ERRBC);
389 IXGBE_READ_REG(hw, IXGBE_MSPDC);
390 for (i = 0; i < 8; i++)
391 IXGBE_READ_REG(hw, IXGBE_MPC(i));
392
393 IXGBE_READ_REG(hw, IXGBE_MLFC);
394 IXGBE_READ_REG(hw, IXGBE_MRFC);
395 IXGBE_READ_REG(hw, IXGBE_RLEC);
396 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Auke Kok9a799d72007-09-15 14:07:45 -0700397 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Emil Tantilov667c7562011-02-26 06:40:05 +0000398 if (hw->mac.type >= ixgbe_mac_82599EB) {
399 IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
400 IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
401 } else {
402 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
403 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
404 }
Auke Kok9a799d72007-09-15 14:07:45 -0700405
406 for (i = 0; i < 8; i++) {
407 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700408 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000409 if (hw->mac.type >= ixgbe_mac_82599EB) {
410 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
411 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
412 } else {
413 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
414 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
415 }
Auke Kok9a799d72007-09-15 14:07:45 -0700416 }
Emil Tantilov667c7562011-02-26 06:40:05 +0000417 if (hw->mac.type >= ixgbe_mac_82599EB)
418 for (i = 0; i < 8; i++)
419 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700420 IXGBE_READ_REG(hw, IXGBE_PRC64);
421 IXGBE_READ_REG(hw, IXGBE_PRC127);
422 IXGBE_READ_REG(hw, IXGBE_PRC255);
423 IXGBE_READ_REG(hw, IXGBE_PRC511);
424 IXGBE_READ_REG(hw, IXGBE_PRC1023);
425 IXGBE_READ_REG(hw, IXGBE_PRC1522);
426 IXGBE_READ_REG(hw, IXGBE_GPRC);
427 IXGBE_READ_REG(hw, IXGBE_BPRC);
428 IXGBE_READ_REG(hw, IXGBE_MPRC);
429 IXGBE_READ_REG(hw, IXGBE_GPTC);
430 IXGBE_READ_REG(hw, IXGBE_GORCL);
431 IXGBE_READ_REG(hw, IXGBE_GORCH);
432 IXGBE_READ_REG(hw, IXGBE_GOTCL);
433 IXGBE_READ_REG(hw, IXGBE_GOTCH);
Emil Tantilovf3116f62011-07-29 06:46:15 +0000434 if (hw->mac.type == ixgbe_mac_82598EB)
435 for (i = 0; i < 8; i++)
436 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700437 IXGBE_READ_REG(hw, IXGBE_RUC);
438 IXGBE_READ_REG(hw, IXGBE_RFC);
439 IXGBE_READ_REG(hw, IXGBE_ROC);
440 IXGBE_READ_REG(hw, IXGBE_RJC);
441 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
442 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
443 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
444 IXGBE_READ_REG(hw, IXGBE_TORL);
445 IXGBE_READ_REG(hw, IXGBE_TORH);
446 IXGBE_READ_REG(hw, IXGBE_TPR);
447 IXGBE_READ_REG(hw, IXGBE_TPT);
448 IXGBE_READ_REG(hw, IXGBE_PTC64);
449 IXGBE_READ_REG(hw, IXGBE_PTC127);
450 IXGBE_READ_REG(hw, IXGBE_PTC255);
451 IXGBE_READ_REG(hw, IXGBE_PTC511);
452 IXGBE_READ_REG(hw, IXGBE_PTC1023);
453 IXGBE_READ_REG(hw, IXGBE_PTC1522);
454 IXGBE_READ_REG(hw, IXGBE_MPTC);
455 IXGBE_READ_REG(hw, IXGBE_BPTC);
456 for (i = 0; i < 16; i++) {
457 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700458 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
Emil Tantilov667c7562011-02-26 06:40:05 +0000459 if (hw->mac.type >= ixgbe_mac_82599EB) {
460 IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
461 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
462 IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
463 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
464 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
465 } else {
466 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
467 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
468 }
Auke Kok9a799d72007-09-15 14:07:45 -0700469 }
470
Emil Tantilova3aeea02011-02-26 06:40:11 +0000471 if (hw->mac.type == ixgbe_mac_X540) {
472 if (hw->phy.id == 0)
473 hw->phy.ops.identify(hw);
Emil Tantilovc1085b12011-12-10 08:21:47 +0000474 hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECL, MDIO_MMD_PCS, &i);
475 hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECH, MDIO_MMD_PCS, &i);
476 hw->phy.ops.read_reg(hw, IXGBE_LDPCECL, MDIO_MMD_PCS, &i);
477 hw->phy.ops.read_reg(hw, IXGBE_LDPCECH, MDIO_MMD_PCS, &i);
Emil Tantilova3aeea02011-02-26 06:40:11 +0000478 }
479
Auke Kok9a799d72007-09-15 14:07:45 -0700480 return 0;
481}
482
483/**
Don Skidmore289700db2010-12-03 03:32:58 +0000484 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700485 * @hw: pointer to hardware structure
Don Skidmore289700db2010-12-03 03:32:58 +0000486 * @pba_num: stores the part number string from the EEPROM
487 * @pba_num_size: part number string buffer length
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700488 *
Don Skidmore289700db2010-12-03 03:32:58 +0000489 * Reads the part number string from the EEPROM.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700490 **/
Don Skidmore289700db2010-12-03 03:32:58 +0000491s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
492 u32 pba_num_size)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700493{
494 s32 ret_val;
495 u16 data;
Don Skidmore289700db2010-12-03 03:32:58 +0000496 u16 pba_ptr;
497 u16 offset;
498 u16 length;
499
500 if (pba_num == NULL) {
501 hw_dbg(hw, "PBA string buffer was null\n");
502 return IXGBE_ERR_INVALID_ARGUMENT;
503 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700504
505 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
506 if (ret_val) {
507 hw_dbg(hw, "NVM Read Error\n");
508 return ret_val;
509 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700510
Don Skidmore289700db2010-12-03 03:32:58 +0000511 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700512 if (ret_val) {
513 hw_dbg(hw, "NVM Read Error\n");
514 return ret_val;
515 }
Don Skidmore289700db2010-12-03 03:32:58 +0000516
517 /*
518 * if data is not ptr guard the PBA must be in legacy format which
519 * means pba_ptr is actually our second data word for the PBA number
520 * and we can decode it into an ascii string
521 */
522 if (data != IXGBE_PBANUM_PTR_GUARD) {
523 hw_dbg(hw, "NVM PBA number is not stored as string\n");
524
525 /* we will need 11 characters to store the PBA */
526 if (pba_num_size < 11) {
527 hw_dbg(hw, "PBA string buffer too small\n");
528 return IXGBE_ERR_NO_SPACE;
529 }
530
531 /* extract hex string from data and pba_ptr */
532 pba_num[0] = (data >> 12) & 0xF;
533 pba_num[1] = (data >> 8) & 0xF;
534 pba_num[2] = (data >> 4) & 0xF;
535 pba_num[3] = data & 0xF;
536 pba_num[4] = (pba_ptr >> 12) & 0xF;
537 pba_num[5] = (pba_ptr >> 8) & 0xF;
538 pba_num[6] = '-';
539 pba_num[7] = 0;
540 pba_num[8] = (pba_ptr >> 4) & 0xF;
541 pba_num[9] = pba_ptr & 0xF;
542
543 /* put a null character on the end of our string */
544 pba_num[10] = '\0';
545
546 /* switch all the data but the '-' to hex char */
547 for (offset = 0; offset < 10; offset++) {
548 if (pba_num[offset] < 0xA)
549 pba_num[offset] += '0';
550 else if (pba_num[offset] < 0x10)
551 pba_num[offset] += 'A' - 0xA;
552 }
553
554 return 0;
555 }
556
557 ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
558 if (ret_val) {
559 hw_dbg(hw, "NVM Read Error\n");
560 return ret_val;
561 }
562
563 if (length == 0xFFFF || length == 0) {
564 hw_dbg(hw, "NVM PBA number section invalid length\n");
565 return IXGBE_ERR_PBA_SECTION;
566 }
567
568 /* check if pba_num buffer is big enough */
569 if (pba_num_size < (((u32)length * 2) - 1)) {
570 hw_dbg(hw, "PBA string buffer too small\n");
571 return IXGBE_ERR_NO_SPACE;
572 }
573
574 /* trim pba length from start of string */
575 pba_ptr++;
576 length--;
577
578 for (offset = 0; offset < length; offset++) {
579 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
580 if (ret_val) {
581 hw_dbg(hw, "NVM Read Error\n");
582 return ret_val;
583 }
584 pba_num[offset * 2] = (u8)(data >> 8);
585 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
586 }
587 pba_num[offset * 2] = '\0';
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700588
589 return 0;
590}
591
592/**
593 * ixgbe_get_mac_addr_generic - Generic get MAC address
Auke Kok9a799d72007-09-15 14:07:45 -0700594 * @hw: pointer to hardware structure
595 * @mac_addr: Adapter MAC address
596 *
597 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
598 * A reset of the adapter must be performed prior to calling this function
599 * in order for the MAC address to have been loaded from the EEPROM into RAR0
600 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700601s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
Auke Kok9a799d72007-09-15 14:07:45 -0700602{
603 u32 rar_high;
604 u32 rar_low;
605 u16 i;
606
607 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
608 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
609
610 for (i = 0; i < 4; i++)
611 mac_addr[i] = (u8)(rar_low >> (i*8));
612
613 for (i = 0; i < 2; i++)
614 mac_addr[i+4] = (u8)(rar_high >> (i*8));
615
616 return 0;
617}
618
Jacob Kelleref1889d2013-02-15 09:18:15 +0000619enum ixgbe_bus_width ixgbe_convert_bus_width(u16 link_status)
620{
621 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
622 case IXGBE_PCI_LINK_WIDTH_1:
623 return ixgbe_bus_width_pcie_x1;
624 case IXGBE_PCI_LINK_WIDTH_2:
625 return ixgbe_bus_width_pcie_x2;
626 case IXGBE_PCI_LINK_WIDTH_4:
627 return ixgbe_bus_width_pcie_x4;
628 case IXGBE_PCI_LINK_WIDTH_8:
629 return ixgbe_bus_width_pcie_x8;
630 default:
631 return ixgbe_bus_width_unknown;
632 }
633}
634
635enum ixgbe_bus_speed ixgbe_convert_bus_speed(u16 link_status)
636{
637 switch (link_status & IXGBE_PCI_LINK_SPEED) {
638 case IXGBE_PCI_LINK_SPEED_2500:
639 return ixgbe_bus_speed_2500;
640 case IXGBE_PCI_LINK_SPEED_5000:
641 return ixgbe_bus_speed_5000;
642 case IXGBE_PCI_LINK_SPEED_8000:
643 return ixgbe_bus_speed_8000;
644 default:
645 return ixgbe_bus_speed_unknown;
646 }
647}
648
Auke Kok9a799d72007-09-15 14:07:45 -0700649/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000650 * ixgbe_get_bus_info_generic - Generic set PCI bus info
651 * @hw: pointer to hardware structure
652 *
653 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
654 **/
655s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
656{
657 struct ixgbe_adapter *adapter = hw->back;
658 struct ixgbe_mac_info *mac = &hw->mac;
659 u16 link_status;
660
661 hw->bus.type = ixgbe_bus_type_pci_express;
662
663 /* Get the negotiated link width and speed from PCI config space */
664 pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
665 &link_status);
666
Jacob Kelleref1889d2013-02-15 09:18:15 +0000667 hw->bus.width = ixgbe_convert_bus_width(link_status);
668 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000669
670 mac->ops.set_lan_id(hw);
671
672 return 0;
673}
674
675/**
676 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
677 * @hw: pointer to the HW structure
678 *
679 * Determines the LAN function id by reading memory-mapped registers
680 * and swaps the port value if requested.
681 **/
682void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
683{
684 struct ixgbe_bus_info *bus = &hw->bus;
685 u32 reg;
686
687 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
688 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
689 bus->lan_id = bus->func;
690
691 /* check for a port swap */
692 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
693 if (reg & IXGBE_FACTPS_LFS)
694 bus->func ^= 0x1;
695}
696
697/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700698 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
Auke Kok9a799d72007-09-15 14:07:45 -0700699 * @hw: pointer to hardware structure
700 *
701 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
702 * disables transmit and receive units. The adapter_stopped flag is used by
703 * the shared code and drivers to determine if the adapter is in a stopped
704 * state and should not touch the hardware.
705 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700706s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700707{
Auke Kok9a799d72007-09-15 14:07:45 -0700708 u32 reg_val;
709 u16 i;
710
711 /*
712 * Set the adapter_stopped flag so other driver functions stop touching
713 * the hardware
714 */
715 hw->adapter_stopped = true;
716
717 /* Disable the receive unit */
Emil Tantilovff9d1a52011-08-16 04:35:11 +0000718 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, 0);
Auke Kok9a799d72007-09-15 14:07:45 -0700719
Emil Tantilovff9d1a52011-08-16 04:35:11 +0000720 /* Clear interrupt mask to stop interrupts from being generated */
Auke Kok9a799d72007-09-15 14:07:45 -0700721 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
722
Emil Tantilovff9d1a52011-08-16 04:35:11 +0000723 /* Clear any pending interrupts, flush previous writes */
Auke Kok9a799d72007-09-15 14:07:45 -0700724 IXGBE_READ_REG(hw, IXGBE_EICR);
725
726 /* Disable the transmit unit. Each queue must be disabled. */
Emil Tantilovff9d1a52011-08-16 04:35:11 +0000727 for (i = 0; i < hw->mac.max_tx_queues; i++)
728 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH);
729
730 /* Disable the receive unit by stopping each queue */
731 for (i = 0; i < hw->mac.max_rx_queues; i++) {
732 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
733 reg_val &= ~IXGBE_RXDCTL_ENABLE;
734 reg_val |= IXGBE_RXDCTL_SWFLSH;
735 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
Auke Kok9a799d72007-09-15 14:07:45 -0700736 }
737
Emil Tantilovff9d1a52011-08-16 04:35:11 +0000738 /* flush all queues disables */
739 IXGBE_WRITE_FLUSH(hw);
740 usleep_range(1000, 2000);
741
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700742 /*
743 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
744 * access and verify no pending requests
745 */
Emil Tantilovff9d1a52011-08-16 04:35:11 +0000746 return ixgbe_disable_pcie_master(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700747}
748
749/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700750 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700751 * @hw: pointer to hardware structure
752 * @index: led number to turn on
753 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700754s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700755{
756 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
757
758 /* To turn on the LED, set mode to ON. */
759 led_reg &= ~IXGBE_LED_MODE_MASK(index);
760 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
761 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700762 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700763
764 return 0;
765}
766
767/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700768 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
Auke Kok9a799d72007-09-15 14:07:45 -0700769 * @hw: pointer to hardware structure
770 * @index: led number to turn off
771 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700772s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
Auke Kok9a799d72007-09-15 14:07:45 -0700773{
774 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
775
776 /* To turn off the LED, set mode to OFF. */
777 led_reg &= ~IXGBE_LED_MODE_MASK(index);
778 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
779 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
Auke Kok3957d632007-10-31 15:22:10 -0700780 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -0700781
782 return 0;
783}
784
Auke Kok9a799d72007-09-15 14:07:45 -0700785/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700786 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
Auke Kok9a799d72007-09-15 14:07:45 -0700787 * @hw: pointer to hardware structure
788 *
789 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
790 * ixgbe_hw struct in order to set up EEPROM access.
791 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700792s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -0700793{
794 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
795 u32 eec;
796 u16 eeprom_size;
797
798 if (eeprom->type == ixgbe_eeprom_uninitialized) {
799 eeprom->type = ixgbe_eeprom_none;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700800 /* Set default semaphore delay to 10ms which is a well
801 * tested value */
802 eeprom->semaphore_delay = 10;
Emil Tantilov68c70052011-04-20 08:49:06 +0000803 /* Clear EEPROM page size, it will be initialized as needed */
804 eeprom->word_page_size = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700805
806 /*
807 * Check for EEPROM present first.
808 * If not present leave as none
809 */
810 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
811 if (eec & IXGBE_EEC_PRES) {
812 eeprom->type = ixgbe_eeprom_spi;
813
814 /*
815 * SPI EEPROM is assumed here. This code would need to
816 * change if a future EEPROM is not SPI.
817 */
818 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
819 IXGBE_EEC_SIZE_SHIFT);
820 eeprom->word_size = 1 << (eeprom_size +
821 IXGBE_EEPROM_WORD_SIZE_SHIFT);
822 }
823
824 if (eec & IXGBE_EEC_ADDR_SIZE)
825 eeprom->address_bits = 16;
826 else
827 eeprom->address_bits = 8;
828 hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
829 "%d\n", eeprom->type, eeprom->word_size,
830 eeprom->address_bits);
831 }
832
833 return 0;
834}
835
836/**
Emil Tantilov68c70052011-04-20 08:49:06 +0000837 * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
838 * @hw: pointer to hardware structure
839 * @offset: offset within the EEPROM to write
840 * @words: number of words
841 * @data: 16 bit word(s) to write to EEPROM
842 *
843 * Reads 16 bit word(s) from EEPROM through bit-bang method
844 **/
845s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
846 u16 words, u16 *data)
847{
848 s32 status = 0;
849 u16 i, count;
850
851 hw->eeprom.ops.init_params(hw);
852
853 if (words == 0) {
854 status = IXGBE_ERR_INVALID_ARGUMENT;
855 goto out;
856 }
857
858 if (offset + words > hw->eeprom.word_size) {
859 status = IXGBE_ERR_EEPROM;
860 goto out;
861 }
862
863 /*
864 * The EEPROM page size cannot be queried from the chip. We do lazy
865 * initialization. It is worth to do that when we write large buffer.
866 */
867 if ((hw->eeprom.word_page_size == 0) &&
868 (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
869 ixgbe_detect_eeprom_page_size_generic(hw, offset);
870
871 /*
872 * We cannot hold synchronization semaphores for too long
873 * to avoid other entity starvation. However it is more efficient
874 * to read in bursts than synchronizing access for each word.
875 */
876 for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
877 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
878 IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
879 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
880 count, &data[i]);
881
882 if (status != 0)
883 break;
884 }
885
886out:
887 return status;
888}
889
890/**
891 * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000892 * @hw: pointer to hardware structure
893 * @offset: offset within the EEPROM to be written to
Emil Tantilov68c70052011-04-20 08:49:06 +0000894 * @words: number of word(s)
895 * @data: 16 bit word(s) to be written to the EEPROM
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000896 *
897 * If ixgbe_eeprom_update_checksum is not called after this function, the
898 * EEPROM will most likely contain an invalid checksum.
899 **/
Emil Tantilov68c70052011-04-20 08:49:06 +0000900static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
901 u16 words, u16 *data)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000902{
903 s32 status;
Emil Tantilov68c70052011-04-20 08:49:06 +0000904 u16 word;
905 u16 page_size;
906 u16 i;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000907 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
908
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000909 /* Prepare the EEPROM for writing */
910 status = ixgbe_acquire_eeprom(hw);
911
912 if (status == 0) {
913 if (ixgbe_ready_eeprom(hw) != 0) {
914 ixgbe_release_eeprom(hw);
915 status = IXGBE_ERR_EEPROM;
916 }
917 }
918
919 if (status == 0) {
Emil Tantilov68c70052011-04-20 08:49:06 +0000920 for (i = 0; i < words; i++) {
921 ixgbe_standby_eeprom(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000922
Emil Tantilov68c70052011-04-20 08:49:06 +0000923 /* Send the WRITE ENABLE command (8 bit opcode ) */
924 ixgbe_shift_out_eeprom_bits(hw,
925 IXGBE_EEPROM_WREN_OPCODE_SPI,
926 IXGBE_EEPROM_OPCODE_BITS);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000927
Emil Tantilov68c70052011-04-20 08:49:06 +0000928 ixgbe_standby_eeprom(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000929
Emil Tantilov68c70052011-04-20 08:49:06 +0000930 /*
931 * Some SPI eeproms use the 8th address bit embedded
932 * in the opcode
933 */
934 if ((hw->eeprom.address_bits == 8) &&
935 ((offset + i) >= 128))
936 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000937
Emil Tantilov68c70052011-04-20 08:49:06 +0000938 /* Send the Write command (8-bit opcode + addr) */
939 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
940 IXGBE_EEPROM_OPCODE_BITS);
941 ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
942 hw->eeprom.address_bits);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000943
Emil Tantilov68c70052011-04-20 08:49:06 +0000944 page_size = hw->eeprom.word_page_size;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000945
Emil Tantilov68c70052011-04-20 08:49:06 +0000946 /* Send the data in burst via SPI*/
947 do {
948 word = data[i];
949 word = (word >> 8) | (word << 8);
950 ixgbe_shift_out_eeprom_bits(hw, word, 16);
951
952 if (page_size == 0)
953 break;
954
955 /* do not wrap around page */
956 if (((offset + i) & (page_size - 1)) ==
957 (page_size - 1))
958 break;
959 } while (++i < words);
960
961 ixgbe_standby_eeprom(hw);
962 usleep_range(10000, 20000);
963 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000964 /* Done with writing - release the EEPROM */
965 ixgbe_release_eeprom(hw);
966 }
967
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000968 return status;
969}
970
971/**
Emil Tantilov68c70052011-04-20 08:49:06 +0000972 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700973 * @hw: pointer to hardware structure
Emil Tantilov68c70052011-04-20 08:49:06 +0000974 * @offset: offset within the EEPROM to be written to
975 * @data: 16 bit word to be written to the EEPROM
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700976 *
Emil Tantilov68c70052011-04-20 08:49:06 +0000977 * If ixgbe_eeprom_update_checksum is not called after this function, the
978 * EEPROM will most likely contain an invalid checksum.
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700979 **/
Emil Tantilov68c70052011-04-20 08:49:06 +0000980s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700981{
982 s32 status;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700983
984 hw->eeprom.ops.init_params(hw);
985
986 if (offset >= hw->eeprom.word_size) {
987 status = IXGBE_ERR_EEPROM;
988 goto out;
989 }
990
Emil Tantilov68c70052011-04-20 08:49:06 +0000991 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
992
993out:
994 return status;
995}
996
997/**
998 * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
999 * @hw: pointer to hardware structure
1000 * @offset: offset within the EEPROM to be read
1001 * @words: number of word(s)
1002 * @data: read 16 bit words(s) from EEPROM
1003 *
1004 * Reads 16 bit word(s) from EEPROM through bit-bang method
1005 **/
1006s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1007 u16 words, u16 *data)
1008{
1009 s32 status = 0;
1010 u16 i, count;
1011
1012 hw->eeprom.ops.init_params(hw);
1013
1014 if (words == 0) {
1015 status = IXGBE_ERR_INVALID_ARGUMENT;
1016 goto out;
1017 }
1018
1019 if (offset + words > hw->eeprom.word_size) {
1020 status = IXGBE_ERR_EEPROM;
1021 goto out;
1022 }
1023
1024 /*
1025 * We cannot hold synchronization semaphores for too long
1026 * to avoid other entity starvation. However it is more efficient
1027 * to read in bursts than synchronizing access for each word.
1028 */
1029 for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
1030 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
1031 IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
1032
1033 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
1034 count, &data[i]);
1035
1036 if (status != 0)
1037 break;
1038 }
1039
1040out:
1041 return status;
1042}
1043
1044/**
1045 * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
1046 * @hw: pointer to hardware structure
1047 * @offset: offset within the EEPROM to be read
1048 * @words: number of word(s)
1049 * @data: read 16 bit word(s) from EEPROM
1050 *
1051 * Reads 16 bit word(s) from EEPROM through bit-bang method
1052 **/
1053static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
1054 u16 words, u16 *data)
1055{
1056 s32 status;
1057 u16 word_in;
1058 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
1059 u16 i;
1060
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001061 /* Prepare the EEPROM for reading */
1062 status = ixgbe_acquire_eeprom(hw);
1063
1064 if (status == 0) {
1065 if (ixgbe_ready_eeprom(hw) != 0) {
1066 ixgbe_release_eeprom(hw);
1067 status = IXGBE_ERR_EEPROM;
1068 }
1069 }
1070
1071 if (status == 0) {
Emil Tantilov68c70052011-04-20 08:49:06 +00001072 for (i = 0; i < words; i++) {
1073 ixgbe_standby_eeprom(hw);
1074 /*
1075 * Some SPI eeproms use the 8th address bit embedded
1076 * in the opcode
1077 */
1078 if ((hw->eeprom.address_bits == 8) &&
1079 ((offset + i) >= 128))
1080 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001081
Emil Tantilov68c70052011-04-20 08:49:06 +00001082 /* Send the READ command (opcode + addr) */
1083 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
1084 IXGBE_EEPROM_OPCODE_BITS);
1085 ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
1086 hw->eeprom.address_bits);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001087
Emil Tantilov68c70052011-04-20 08:49:06 +00001088 /* Read the data. */
1089 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
1090 data[i] = (word_in >> 8) | (word_in << 8);
1091 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001092
1093 /* End this read operation */
1094 ixgbe_release_eeprom(hw);
1095 }
1096
Emil Tantilov68c70052011-04-20 08:49:06 +00001097 return status;
1098}
1099
1100/**
1101 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
1102 * @hw: pointer to hardware structure
1103 * @offset: offset within the EEPROM to be read
1104 * @data: read 16 bit value from EEPROM
1105 *
1106 * Reads 16 bit value from EEPROM through bit-bang method
1107 **/
1108s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1109 u16 *data)
1110{
1111 s32 status;
1112
1113 hw->eeprom.ops.init_params(hw);
1114
1115 if (offset >= hw->eeprom.word_size) {
1116 status = IXGBE_ERR_EEPROM;
1117 goto out;
1118 }
1119
1120 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1121
1122out:
1123 return status;
1124}
1125
1126/**
1127 * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
1128 * @hw: pointer to hardware structure
1129 * @offset: offset of word in the EEPROM to read
1130 * @words: number of word(s)
1131 * @data: 16 bit word(s) from the EEPROM
1132 *
1133 * Reads a 16 bit word(s) from the EEPROM using the EERD register.
1134 **/
1135s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1136 u16 words, u16 *data)
1137{
1138 u32 eerd;
1139 s32 status = 0;
1140 u32 i;
1141
1142 hw->eeprom.ops.init_params(hw);
1143
1144 if (words == 0) {
1145 status = IXGBE_ERR_INVALID_ARGUMENT;
1146 goto out;
1147 }
1148
1149 if (offset >= hw->eeprom.word_size) {
1150 status = IXGBE_ERR_EEPROM;
1151 goto out;
1152 }
1153
1154 for (i = 0; i < words; i++) {
Emil Tantilovd0111572013-02-05 09:43:26 +00001155 eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
Emil Tantilov68c70052011-04-20 08:49:06 +00001156 IXGBE_EEPROM_RW_REG_START;
1157
1158 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
1159 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
1160
1161 if (status == 0) {
1162 data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
1163 IXGBE_EEPROM_RW_REG_DATA);
1164 } else {
1165 hw_dbg(hw, "Eeprom read timed out\n");
1166 goto out;
1167 }
1168 }
1169out:
1170 return status;
1171}
1172
1173/**
1174 * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
1175 * @hw: pointer to hardware structure
1176 * @offset: offset within the EEPROM to be used as a scratch pad
1177 *
1178 * Discover EEPROM page size by writing marching data at given offset.
1179 * This function is called only when we are writing a new large buffer
1180 * at given offset so the data would be overwritten anyway.
1181 **/
1182static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
1183 u16 offset)
1184{
1185 u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
1186 s32 status = 0;
1187 u16 i;
1188
1189 for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
1190 data[i] = i;
1191
1192 hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
1193 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
1194 IXGBE_EEPROM_PAGE_SIZE_MAX, data);
1195 hw->eeprom.word_page_size = 0;
1196 if (status != 0)
1197 goto out;
1198
1199 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1200 if (status != 0)
1201 goto out;
1202
1203 /*
1204 * When writing in burst more than the actual page size
1205 * EEPROM address wraps around current page.
1206 */
1207 hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
1208
1209 hw_dbg(hw, "Detected EEPROM page size = %d words.",
1210 hw->eeprom.word_page_size);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001211out:
1212 return status;
1213}
1214
1215/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001216 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
Auke Kok9a799d72007-09-15 14:07:45 -07001217 * @hw: pointer to hardware structure
1218 * @offset: offset of word in the EEPROM to read
1219 * @data: word read from the EEPROM
1220 *
1221 * Reads a 16 bit word from the EEPROM using the EERD register.
1222 **/
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001223s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
Auke Kok9a799d72007-09-15 14:07:45 -07001224{
Emil Tantilov68c70052011-04-20 08:49:06 +00001225 return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
1226}
1227
1228/**
1229 * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
1230 * @hw: pointer to hardware structure
1231 * @offset: offset of word in the EEPROM to write
1232 * @words: number of words
1233 * @data: word(s) write to the EEPROM
1234 *
1235 * Write a 16 bit word(s) to the EEPROM using the EEWR register.
1236 **/
1237s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1238 u16 words, u16 *data)
1239{
1240 u32 eewr;
1241 s32 status = 0;
1242 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07001243
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001244 hw->eeprom.ops.init_params(hw);
1245
Emil Tantilov68c70052011-04-20 08:49:06 +00001246 if (words == 0) {
1247 status = IXGBE_ERR_INVALID_ARGUMENT;
1248 goto out;
1249 }
1250
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001251 if (offset >= hw->eeprom.word_size) {
1252 status = IXGBE_ERR_EEPROM;
1253 goto out;
1254 }
1255
Emil Tantilov68c70052011-04-20 08:49:06 +00001256 for (i = 0; i < words; i++) {
1257 eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1258 (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
1259 IXGBE_EEPROM_RW_REG_START;
Auke Kok9a799d72007-09-15 14:07:45 -07001260
Emil Tantilov68c70052011-04-20 08:49:06 +00001261 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1262 if (status != 0) {
1263 hw_dbg(hw, "Eeprom write EEWR timed out\n");
1264 goto out;
1265 }
Auke Kok9a799d72007-09-15 14:07:45 -07001266
Emil Tantilov68c70052011-04-20 08:49:06 +00001267 IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
1268
1269 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1270 if (status != 0) {
1271 hw_dbg(hw, "Eeprom write EEWR timed out\n");
1272 goto out;
1273 }
1274 }
Auke Kok9a799d72007-09-15 14:07:45 -07001275
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001276out:
Auke Kok9a799d72007-09-15 14:07:45 -07001277 return status;
1278}
1279
1280/**
Emil Tantiloveb9c3e32011-03-24 00:57:50 +00001281 * ixgbe_write_eewr_generic - Write EEPROM word using EEWR
1282 * @hw: pointer to hardware structure
1283 * @offset: offset of word in the EEPROM to write
1284 * @data: word write to the EEPROM
1285 *
1286 * Write a 16 bit word to the EEPROM using the EEWR register.
1287 **/
1288s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1289{
Emil Tantilov68c70052011-04-20 08:49:06 +00001290 return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
Emil Tantiloveb9c3e32011-03-24 00:57:50 +00001291}
1292
1293/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001294 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
Auke Kok9a799d72007-09-15 14:07:45 -07001295 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001296 * @ee_reg: EEPROM flag for polling
Auke Kok9a799d72007-09-15 14:07:45 -07001297 *
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001298 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
1299 * read or write is done respectively.
Auke Kok9a799d72007-09-15 14:07:45 -07001300 **/
Emil Tantiloveb9c3e32011-03-24 00:57:50 +00001301static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
Auke Kok9a799d72007-09-15 14:07:45 -07001302{
1303 u32 i;
1304 u32 reg;
1305 s32 status = IXGBE_ERR_EEPROM;
1306
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00001307 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
1308 if (ee_reg == IXGBE_NVM_POLL_READ)
1309 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
1310 else
1311 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
1312
1313 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
Auke Kok9a799d72007-09-15 14:07:45 -07001314 status = 0;
1315 break;
1316 }
1317 udelay(5);
1318 }
1319 return status;
1320}
1321
1322/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001323 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
1324 * @hw: pointer to hardware structure
1325 *
1326 * Prepares EEPROM for access using bit-bang method. This function should
1327 * be called before issuing a command to the EEPROM.
1328 **/
1329static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
1330{
1331 s32 status = 0;
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001332 u32 eec;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001333 u32 i;
1334
Don Skidmore5e655102011-02-25 01:58:04 +00001335 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001336 status = IXGBE_ERR_SWFW_SYNC;
1337
1338 if (status == 0) {
1339 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1340
1341 /* Request EEPROM Access */
1342 eec |= IXGBE_EEC_REQ;
1343 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1344
1345 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
1346 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1347 if (eec & IXGBE_EEC_GNT)
1348 break;
1349 udelay(5);
1350 }
1351
1352 /* Release if grant not acquired */
1353 if (!(eec & IXGBE_EEC_GNT)) {
1354 eec &= ~IXGBE_EEC_REQ;
1355 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1356 hw_dbg(hw, "Could not acquire EEPROM grant\n");
1357
Don Skidmore5e655102011-02-25 01:58:04 +00001358 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001359 status = IXGBE_ERR_EEPROM;
1360 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001361
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001362 /* Setup EEPROM for Read/Write */
1363 if (status == 0) {
1364 /* Clear CS and SK */
1365 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
1366 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1367 IXGBE_WRITE_FLUSH(hw);
1368 udelay(1);
1369 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001370 }
1371 return status;
1372}
1373
1374/**
Auke Kok9a799d72007-09-15 14:07:45 -07001375 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
1376 * @hw: pointer to hardware structure
1377 *
1378 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
1379 **/
1380static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
1381{
1382 s32 status = IXGBE_ERR_EEPROM;
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001383 u32 timeout = 2000;
Auke Kok9a799d72007-09-15 14:07:45 -07001384 u32 i;
1385 u32 swsm;
1386
Auke Kok9a799d72007-09-15 14:07:45 -07001387 /* Get SMBI software semaphore between device drivers first */
1388 for (i = 0; i < timeout; i++) {
1389 /*
1390 * If the SMBI bit is 0 when we read it, then the bit will be
1391 * set and we have the semaphore
1392 */
1393 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1394 if (!(swsm & IXGBE_SWSM_SMBI)) {
1395 status = 0;
1396 break;
1397 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001398 udelay(50);
Auke Kok9a799d72007-09-15 14:07:45 -07001399 }
1400
Emil Tantilov51275d32011-04-08 01:23:59 +00001401 if (i == timeout) {
1402 hw_dbg(hw, "Driver can't access the Eeprom - SMBI Semaphore "
1403 "not granted.\n");
1404 /*
1405 * this release is particularly important because our attempts
1406 * above to get the semaphore may have succeeded, and if there
1407 * was a timeout, we should unconditionally clear the semaphore
1408 * bits to free the driver to make progress
1409 */
1410 ixgbe_release_eeprom_semaphore(hw);
1411
1412 udelay(50);
1413 /*
1414 * one last try
1415 * If the SMBI bit is 0 when we read it, then the bit will be
1416 * set and we have the semaphore
1417 */
1418 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1419 if (!(swsm & IXGBE_SWSM_SMBI))
1420 status = 0;
1421 }
1422
Auke Kok9a799d72007-09-15 14:07:45 -07001423 /* Now get the semaphore between SW/FW through the SWESMBI bit */
1424 if (status == 0) {
1425 for (i = 0; i < timeout; i++) {
1426 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1427
1428 /* Set the SW EEPROM semaphore bit to request access */
1429 swsm |= IXGBE_SWSM_SWESMBI;
1430 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
1431
1432 /*
1433 * If we set the bit successfully then we got the
1434 * semaphore.
1435 */
1436 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1437 if (swsm & IXGBE_SWSM_SWESMBI)
1438 break;
1439
1440 udelay(50);
1441 }
1442
1443 /*
1444 * Release semaphores and return error if SW EEPROM semaphore
1445 * was not granted because we don't have access to the EEPROM
1446 */
1447 if (i >= timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001448 hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001449 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001450 ixgbe_release_eeprom_semaphore(hw);
1451 status = IXGBE_ERR_EEPROM;
1452 }
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001453 } else {
1454 hw_dbg(hw, "Software semaphore SMBI between device drivers "
1455 "not granted.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001456 }
1457
1458 return status;
1459}
1460
1461/**
1462 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
1463 * @hw: pointer to hardware structure
1464 *
1465 * This function clears hardware semaphore bits.
1466 **/
1467static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
1468{
1469 u32 swsm;
1470
1471 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1472
1473 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
1474 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
1475 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
Auke Kok3957d632007-10-31 15:22:10 -07001476 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001477}
1478
1479/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001480 * ixgbe_ready_eeprom - Polls for EEPROM ready
1481 * @hw: pointer to hardware structure
1482 **/
1483static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
1484{
1485 s32 status = 0;
1486 u16 i;
1487 u8 spi_stat_reg;
1488
1489 /*
1490 * Read "Status Register" repeatedly until the LSB is cleared. The
1491 * EEPROM will signal that the command has been completed by clearing
1492 * bit 0 of the internal status register. If it's not cleared within
1493 * 5 milliseconds, then error out.
1494 */
1495 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
1496 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
1497 IXGBE_EEPROM_OPCODE_BITS);
1498 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
1499 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
1500 break;
1501
1502 udelay(5);
1503 ixgbe_standby_eeprom(hw);
Joe Perches6403eab2011-06-03 11:51:20 +00001504 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001505
1506 /*
1507 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
1508 * devices (and only 0-5mSec on 5V devices)
1509 */
1510 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
1511 hw_dbg(hw, "SPI EEPROM Status error\n");
1512 status = IXGBE_ERR_EEPROM;
1513 }
1514
1515 return status;
1516}
1517
1518/**
1519 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
1520 * @hw: pointer to hardware structure
1521 **/
1522static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
1523{
1524 u32 eec;
1525
1526 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1527
1528 /* Toggle CS to flush commands */
1529 eec |= IXGBE_EEC_CS;
1530 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1531 IXGBE_WRITE_FLUSH(hw);
1532 udelay(1);
1533 eec &= ~IXGBE_EEC_CS;
1534 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1535 IXGBE_WRITE_FLUSH(hw);
1536 udelay(1);
1537}
1538
1539/**
1540 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
1541 * @hw: pointer to hardware structure
1542 * @data: data to send to the EEPROM
1543 * @count: number of bits to shift out
1544 **/
1545static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
1546 u16 count)
1547{
1548 u32 eec;
1549 u32 mask;
1550 u32 i;
1551
1552 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1553
1554 /*
1555 * Mask is used to shift "count" bits of "data" out to the EEPROM
1556 * one bit at a time. Determine the starting bit based on count
1557 */
1558 mask = 0x01 << (count - 1);
1559
1560 for (i = 0; i < count; i++) {
1561 /*
1562 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
1563 * "1", and then raising and then lowering the clock (the SK
1564 * bit controls the clock input to the EEPROM). A "0" is
1565 * shifted out to the EEPROM by setting "DI" to "0" and then
1566 * raising and then lowering the clock.
1567 */
1568 if (data & mask)
1569 eec |= IXGBE_EEC_DI;
1570 else
1571 eec &= ~IXGBE_EEC_DI;
1572
1573 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1574 IXGBE_WRITE_FLUSH(hw);
1575
1576 udelay(1);
1577
1578 ixgbe_raise_eeprom_clk(hw, &eec);
1579 ixgbe_lower_eeprom_clk(hw, &eec);
1580
1581 /*
1582 * Shift mask to signify next bit of data to shift in to the
1583 * EEPROM
1584 */
1585 mask = mask >> 1;
Joe Perches6403eab2011-06-03 11:51:20 +00001586 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001587
1588 /* We leave the "DI" bit set to "0" when we leave this routine. */
1589 eec &= ~IXGBE_EEC_DI;
1590 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1591 IXGBE_WRITE_FLUSH(hw);
1592}
1593
1594/**
1595 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
1596 * @hw: pointer to hardware structure
1597 **/
1598static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
1599{
1600 u32 eec;
1601 u32 i;
1602 u16 data = 0;
1603
1604 /*
1605 * In order to read a register from the EEPROM, we need to shift
1606 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
1607 * the clock input to the EEPROM (setting the SK bit), and then reading
1608 * the value of the "DO" bit. During this "shifting in" process the
1609 * "DI" bit should always be clear.
1610 */
1611 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1612
1613 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1614
1615 for (i = 0; i < count; i++) {
1616 data = data << 1;
1617 ixgbe_raise_eeprom_clk(hw, &eec);
1618
1619 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1620
1621 eec &= ~(IXGBE_EEC_DI);
1622 if (eec & IXGBE_EEC_DO)
1623 data |= 1;
1624
1625 ixgbe_lower_eeprom_clk(hw, &eec);
1626 }
1627
1628 return data;
1629}
1630
1631/**
1632 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1633 * @hw: pointer to hardware structure
1634 * @eec: EEC register's current value
1635 **/
1636static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1637{
1638 /*
1639 * Raise the clock input to the EEPROM
1640 * (setting the SK bit), then delay
1641 */
1642 *eec = *eec | IXGBE_EEC_SK;
1643 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1644 IXGBE_WRITE_FLUSH(hw);
1645 udelay(1);
1646}
1647
1648/**
1649 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1650 * @hw: pointer to hardware structure
1651 * @eecd: EECD's current value
1652 **/
1653static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1654{
1655 /*
1656 * Lower the clock input to the EEPROM (clearing the SK bit), then
1657 * delay
1658 */
1659 *eec = *eec & ~IXGBE_EEC_SK;
1660 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
1661 IXGBE_WRITE_FLUSH(hw);
1662 udelay(1);
1663}
1664
1665/**
1666 * ixgbe_release_eeprom - Release EEPROM, release semaphores
1667 * @hw: pointer to hardware structure
1668 **/
1669static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1670{
1671 u32 eec;
1672
1673 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1674
1675 eec |= IXGBE_EEC_CS; /* Pull CS high */
1676 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1677
1678 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1679 IXGBE_WRITE_FLUSH(hw);
1680
1681 udelay(1);
1682
1683 /* Stop requesting EEPROM access */
1684 eec &= ~IXGBE_EEC_REQ;
1685 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1686
Don Skidmore90827992011-03-05 18:59:20 -08001687 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001688
Don Skidmore032b4322011-03-18 09:32:53 +00001689 /*
1690 * Delay before attempt to obtain semaphore again to allow FW
1691 * access. semaphore_delay is in ms we need us for usleep_range
1692 */
1693 usleep_range(hw->eeprom.semaphore_delay * 1000,
1694 hw->eeprom.semaphore_delay * 2000);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001695}
1696
1697/**
Emil Tantilovdbf893e2011-02-08 09:42:41 +00001698 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001699 * @hw: pointer to hardware structure
1700 **/
Don Skidmorea391f1d2010-11-16 19:27:15 -08001701u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001702{
1703 u16 i;
1704 u16 j;
1705 u16 checksum = 0;
1706 u16 length = 0;
1707 u16 pointer = 0;
1708 u16 word = 0;
1709
1710 /* Include 0x0-0x3F in the checksum */
1711 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001712 if (hw->eeprom.ops.read(hw, i, &word) != 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07001713 hw_dbg(hw, "EEPROM read failed\n");
1714 break;
1715 }
1716 checksum += word;
1717 }
1718
1719 /* Include all data from pointers except for the fw pointer */
1720 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001721 hw->eeprom.ops.read(hw, i, &pointer);
Auke Kok9a799d72007-09-15 14:07:45 -07001722
1723 /* Make sure the pointer seems valid */
1724 if (pointer != 0xFFFF && pointer != 0) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001725 hw->eeprom.ops.read(hw, pointer, &length);
Auke Kok9a799d72007-09-15 14:07:45 -07001726
1727 if (length != 0xFFFF && length != 0) {
1728 for (j = pointer+1; j <= pointer+length; j++) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001729 hw->eeprom.ops.read(hw, j, &word);
Auke Kok9a799d72007-09-15 14:07:45 -07001730 checksum += word;
1731 }
1732 }
1733 }
1734 }
1735
1736 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1737
1738 return checksum;
1739}
1740
1741/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001742 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
Auke Kok9a799d72007-09-15 14:07:45 -07001743 * @hw: pointer to hardware structure
1744 * @checksum_val: calculated checksum
1745 *
1746 * Performs checksum calculation and validates the EEPROM checksum. If the
1747 * caller does not need checksum_val, the value can be NULL.
1748 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001749s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1750 u16 *checksum_val)
Auke Kok9a799d72007-09-15 14:07:45 -07001751{
1752 s32 status;
1753 u16 checksum;
1754 u16 read_checksum = 0;
1755
1756 /*
1757 * Read the first word from the EEPROM. If this times out or fails, do
1758 * not continue or we could be in for a very long wait while every
1759 * EEPROM read fails
1760 */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001761 status = hw->eeprom.ops.read(hw, 0, &checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001762
1763 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001764 checksum = hw->eeprom.ops.calc_checksum(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001765
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001766 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
Auke Kok9a799d72007-09-15 14:07:45 -07001767
1768 /*
1769 * Verify read checksum from EEPROM is the same as
1770 * calculated checksum
1771 */
1772 if (read_checksum != checksum)
1773 status = IXGBE_ERR_EEPROM_CHECKSUM;
1774
1775 /* If the user cares, return the calculated checksum */
1776 if (checksum_val)
1777 *checksum_val = checksum;
1778 } else {
1779 hw_dbg(hw, "EEPROM read failed\n");
1780 }
1781
1782 return status;
1783}
1784
1785/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001786 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1787 * @hw: pointer to hardware structure
1788 **/
1789s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1790{
1791 s32 status;
1792 u16 checksum;
1793
1794 /*
1795 * Read the first word from the EEPROM. If this times out or fails, do
1796 * not continue or we could be in for a very long wait while every
1797 * EEPROM read fails
1798 */
1799 status = hw->eeprom.ops.read(hw, 0, &checksum);
1800
1801 if (status == 0) {
Don Skidmorea391f1d2010-11-16 19:27:15 -08001802 checksum = hw->eeprom.ops.calc_checksum(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001803 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00001804 checksum);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001805 } else {
1806 hw_dbg(hw, "EEPROM read failed\n");
1807 }
1808
1809 return status;
1810}
1811
1812/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001813 * ixgbe_set_rar_generic - Set Rx address register
Auke Kok9a799d72007-09-15 14:07:45 -07001814 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07001815 * @index: Receive address register to write
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001816 * @addr: Address to put into receive address register
1817 * @vmdq: VMDq "set" or "pool" index
Auke Kok9a799d72007-09-15 14:07:45 -07001818 * @enable_addr: set flag that address is active
1819 *
1820 * Puts an ethernet address into a receive address register.
1821 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001822s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1823 u32 enable_addr)
Auke Kok9a799d72007-09-15 14:07:45 -07001824{
1825 u32 rar_low, rar_high;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001826 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001827
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001828 /* Make sure we are using a valid rar index range */
1829 if (index >= rar_entries) {
1830 hw_dbg(hw, "RAR index %d is out of range.\n", index);
1831 return IXGBE_ERR_INVALID_ARGUMENT;
1832 }
1833
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001834 /* setup VMDq pool selection before this RAR gets enabled */
1835 hw->mac.ops.set_vmdq(hw, index, vmdq);
1836
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001837 /*
1838 * HW expects these in little endian so we reverse the byte
1839 * order from network order (big endian) to little endian
1840 */
1841 rar_low = ((u32)addr[0] |
1842 ((u32)addr[1] << 8) |
1843 ((u32)addr[2] << 16) |
1844 ((u32)addr[3] << 24));
1845 /*
1846 * Some parts put the VMDq setting in the extra RAH bits,
1847 * so save everything except the lower 16 bits that hold part
1848 * of the address and the address valid bit.
1849 */
1850 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1851 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1852 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
Auke Kok9a799d72007-09-15 14:07:45 -07001853
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001854 if (enable_addr != 0)
1855 rar_high |= IXGBE_RAH_AV;
Auke Kok9a799d72007-09-15 14:07:45 -07001856
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001857 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1858 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
Auke Kok9a799d72007-09-15 14:07:45 -07001859
1860 return 0;
1861}
1862
1863/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001864 * ixgbe_clear_rar_generic - Remove Rx address register
1865 * @hw: pointer to hardware structure
1866 * @index: Receive address register to write
1867 *
1868 * Clears an ethernet address from a receive address register.
1869 **/
1870s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1871{
1872 u32 rar_high;
1873 u32 rar_entries = hw->mac.num_rar_entries;
1874
1875 /* Make sure we are using a valid rar index range */
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001876 if (index >= rar_entries) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001877 hw_dbg(hw, "RAR index %d is out of range.\n", index);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001878 return IXGBE_ERR_INVALID_ARGUMENT;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001879 }
1880
Emil Tantilovc700f4e2011-02-17 11:34:58 +00001881 /*
1882 * Some parts put the VMDq setting in the extra RAH bits,
1883 * so save everything except the lower 16 bits that hold part
1884 * of the address and the address valid bit.
1885 */
1886 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1887 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1888
1889 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1890 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1891
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001892 /* clear VMDq pool/queue selection for this RAR */
1893 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1894
1895 return 0;
1896}
1897
1898/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001899 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
Auke Kok9a799d72007-09-15 14:07:45 -07001900 * @hw: pointer to hardware structure
1901 *
1902 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001903 * of the receive address registers. Clears the multicast table. Assumes
Auke Kok9a799d72007-09-15 14:07:45 -07001904 * the receiver is in reset when the routine is called.
1905 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001906s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07001907{
1908 u32 i;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001909 u32 rar_entries = hw->mac.num_rar_entries;
Auke Kok9a799d72007-09-15 14:07:45 -07001910
1911 /*
1912 * If the current mac address is valid, assume it is a software override
1913 * to the permanent address.
1914 * Otherwise, use the permanent address from the eeprom.
1915 */
Joe Perchesf8ebc682012-10-24 17:19:02 +00001916 if (!is_valid_ether_addr(hw->mac.addr)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001917 /* Get the MAC address from the RAR0 for later reference */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001918 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001919
hartleysce7194d2010-01-05 06:56:52 +00001920 hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001921 } else {
1922 /* Setup the receive address. */
1923 hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
hartleysce7194d2010-01-05 06:56:52 +00001924 hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
Auke Kok9a799d72007-09-15 14:07:45 -07001925
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001926 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Alexander Duyck96cc6372011-01-19 18:33:05 +00001927
1928 /* clear VMDq pool/queue selection for RAR 0 */
1929 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
Auke Kok9a799d72007-09-15 14:07:45 -07001930 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001931 hw->addr_ctrl.overflow_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001932
1933 hw->addr_ctrl.rar_used_count = 1;
1934
1935 /* Zero out the other receive addresses. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001936 hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07001937 for (i = 1; i < rar_entries; i++) {
1938 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1939 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1940 }
1941
1942 /* Clear the MTA */
Auke Kok9a799d72007-09-15 14:07:45 -07001943 hw->addr_ctrl.mta_in_use = 0;
1944 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1945
1946 hw_dbg(hw, " Clearing MTA\n");
Christopher Leech2c5645c2008-08-26 04:27:02 -07001947 for (i = 0; i < hw->mac.mcft_size; i++)
Auke Kok9a799d72007-09-15 14:07:45 -07001948 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1949
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001950 if (hw->mac.ops.init_uta_tables)
1951 hw->mac.ops.init_uta_tables(hw);
1952
Auke Kok9a799d72007-09-15 14:07:45 -07001953 return 0;
1954}
1955
1956/**
1957 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1958 * @hw: pointer to hardware structure
1959 * @mc_addr: the multicast address
1960 *
1961 * Extracts the 12 bits, from a multicast address, to determine which
1962 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1963 * incoming rx multicast addresses, to determine the bit-vector to check in
1964 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001965 * by the MO field of the MCSTCTRL. The MO field is set during initialization
Auke Kok9a799d72007-09-15 14:07:45 -07001966 * to mc_filter_type.
1967 **/
1968static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1969{
1970 u32 vector = 0;
1971
1972 switch (hw->mac.mc_filter_type) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001973 case 0: /* use bits [47:36] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001974 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
1975 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001976 case 1: /* use bits [46:35] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001977 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
1978 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001979 case 2: /* use bits [45:34] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001980 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
1981 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001982 case 3: /* use bits [43:32] of the address */
Auke Kok9a799d72007-09-15 14:07:45 -07001983 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
1984 break;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001985 default: /* Invalid mc_filter_type */
Auke Kok9a799d72007-09-15 14:07:45 -07001986 hw_dbg(hw, "MC filter type param set incorrectly\n");
1987 break;
1988 }
1989
1990 /* vector can only be 12-bits or boundary will be exceeded */
1991 vector &= 0xFFF;
1992 return vector;
1993}
1994
1995/**
1996 * ixgbe_set_mta - Set bit-vector in multicast table
1997 * @hw: pointer to hardware structure
1998 * @hash_value: Multicast address hash value
1999 *
2000 * Sets the bit-vector in the multicast table.
2001 **/
2002static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
2003{
2004 u32 vector;
2005 u32 vector_bit;
2006 u32 vector_reg;
Auke Kok9a799d72007-09-15 14:07:45 -07002007
2008 hw->addr_ctrl.mta_in_use++;
2009
2010 vector = ixgbe_mta_vector(hw, mc_addr);
2011 hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
2012
2013 /*
2014 * The MTA is a register array of 128 32-bit registers. It is treated
2015 * like an array of 4096 bits. We want to set bit
2016 * BitArray[vector_value]. So we figure out what register the bit is
2017 * in, read it, OR in the new bit, then write back the new value. The
2018 * register is determined by the upper 7 bits of the vector value and
2019 * the bit within that register are determined by the lower 5 bits of
2020 * the value.
2021 */
2022 vector_reg = (vector >> 5) & 0x7F;
2023 vector_bit = vector & 0x1F;
Emil Tantilov80960ab2011-02-18 08:58:27 +00002024 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
Auke Kok9a799d72007-09-15 14:07:45 -07002025}
2026
2027/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002028 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
Auke Kok9a799d72007-09-15 14:07:45 -07002029 * @hw: pointer to hardware structure
Jiri Pirko2853eb82010-03-23 22:58:01 +00002030 * @netdev: pointer to net device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002031 *
2032 * The given list replaces any existing list. Clears the MC addrs from receive
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002033 * address registers and the multicast table. Uses unused receive address
Auke Kok9a799d72007-09-15 14:07:45 -07002034 * registers for the first multicast addresses, and hashes the rest into the
2035 * multicast table.
2036 **/
Jiri Pirko2853eb82010-03-23 22:58:01 +00002037s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
2038 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002039{
Jiri Pirko22bedad32010-04-01 21:22:57 +00002040 struct netdev_hw_addr *ha;
Auke Kok9a799d72007-09-15 14:07:45 -07002041 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002042
2043 /*
2044 * Set the new number of MC addresses that we are being requested to
2045 * use.
2046 */
Jiri Pirko2853eb82010-03-23 22:58:01 +00002047 hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002048 hw->addr_ctrl.mta_in_use = 0;
2049
Emil Tantilov80960ab2011-02-18 08:58:27 +00002050 /* Clear mta_shadow */
Auke Kok9a799d72007-09-15 14:07:45 -07002051 hw_dbg(hw, " Clearing MTA\n");
Emil Tantilov80960ab2011-02-18 08:58:27 +00002052 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
Auke Kok9a799d72007-09-15 14:07:45 -07002053
Emil Tantilov80960ab2011-02-18 08:58:27 +00002054 /* Update mta shadow */
Jiri Pirko22bedad32010-04-01 21:22:57 +00002055 netdev_for_each_mc_addr(ha, netdev) {
Auke Kok9a799d72007-09-15 14:07:45 -07002056 hw_dbg(hw, " Adding the multicast addresses:\n");
Jiri Pirko22bedad32010-04-01 21:22:57 +00002057 ixgbe_set_mta(hw, ha->addr);
Auke Kok9a799d72007-09-15 14:07:45 -07002058 }
2059
2060 /* Enable mta */
Emil Tantilov80960ab2011-02-18 08:58:27 +00002061 for (i = 0; i < hw->mac.mcft_size; i++)
2062 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
2063 hw->mac.mta_shadow[i]);
2064
Auke Kok9a799d72007-09-15 14:07:45 -07002065 if (hw->addr_ctrl.mta_in_use > 0)
2066 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002067 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07002068
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002069 hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002070 return 0;
2071}
2072
2073/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002074 * ixgbe_enable_mc_generic - Enable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07002075 * @hw: pointer to hardware structure
2076 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002077 * Enables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07002078 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002079s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07002080{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002081 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07002082
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002083 if (a->mta_in_use > 0)
2084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
2085 hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07002086
2087 return 0;
2088}
2089
2090/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002091 * ixgbe_disable_mc_generic - Disable multicast address in RAR
Auke Kok9a799d72007-09-15 14:07:45 -07002092 * @hw: pointer to hardware structure
Auke Kok9a799d72007-09-15 14:07:45 -07002093 *
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002094 * Disables multicast address in RAR and the use of the multicast hash table.
Auke Kok9a799d72007-09-15 14:07:45 -07002095 **/
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002096s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07002097{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002098 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07002099
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002100 if (a->mta_in_use > 0)
2101 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
Auke Kok9a799d72007-09-15 14:07:45 -07002102
2103 return 0;
2104}
2105
2106/**
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002107 * ixgbe_fc_enable_generic - Enable flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002108 * @hw: pointer to hardware structure
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002109 *
2110 * Enable flow control according to the current settings.
2111 **/
Alexander Duyck041441d2012-04-19 17:48:48 +00002112s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002113{
2114 s32 ret_val = 0;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002115 u32 mflcn_reg, fccfg_reg;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002116 u32 reg;
John Fastabend16b61be2010-11-16 19:26:44 -08002117 u32 fcrtl, fcrth;
Alexander Duyck041441d2012-04-19 17:48:48 +00002118 int i;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00002119
Alexander Duyck041441d2012-04-19 17:48:48 +00002120 /*
2121 * Validate the water mark configuration for packet buffer 0. Zero
2122 * water marks indicate that the packet buffer was not configured
2123 * and the watermarks for packet buffer 0 should always be configured.
2124 */
2125 if (!hw->fc.low_water ||
2126 !hw->fc.high_water[0] ||
2127 !hw->fc.pause_time) {
2128 hw_dbg(hw, "Invalid water mark configuration\n");
2129 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00002130 goto out;
Alexander Duyck041441d2012-04-19 17:48:48 +00002131 }
Peter P Waskiewicz Jr70b77622009-05-17 12:34:55 +00002132
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002133 /* Negotiate the fc mode to use */
Alexander Duyck786e9a52012-03-28 08:03:48 +00002134 ixgbe_fc_autoneg(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002135
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002136 /* Disable any previous flow control settings */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002137 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
Alexander Duyck041441d2012-04-19 17:48:48 +00002138 mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002139
2140 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2141 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
2142
2143 /*
2144 * The possible values of fc.current_mode are:
2145 * 0: Flow control is completely disabled
2146 * 1: Rx flow control is enabled (we can receive pause frames,
2147 * but not send pause frames).
PJ Waskiewiczbb3daa42009-03-25 22:10:42 +00002148 * 2: Tx flow control is enabled (we can send pause frames but
2149 * we do not support receiving pause frames).
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002150 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2151 * other: Invalid.
2152 */
2153 switch (hw->fc.current_mode) {
2154 case ixgbe_fc_none:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002155 /*
2156 * Flow control is disabled by software override or autoneg.
2157 * The code below will actually disable it in the HW.
2158 */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002159 break;
2160 case ixgbe_fc_rx_pause:
2161 /*
2162 * Rx Flow control is enabled and Tx Flow control is
2163 * disabled by software override. Since there really
2164 * isn't a way to advertise that we are capable of RX
2165 * Pause ONLY, we will advertise that we support both
2166 * symmetric and asymmetric Rx PAUSE. Later, we will
2167 * disable the adapter's ability to send PAUSE frames.
2168 */
2169 mflcn_reg |= IXGBE_MFLCN_RFCE;
2170 break;
2171 case ixgbe_fc_tx_pause:
2172 /*
2173 * Tx Flow control is enabled, and Rx Flow control is
2174 * disabled by software override.
2175 */
2176 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2177 break;
2178 case ixgbe_fc_full:
2179 /* Flow control (both Rx and Tx) is enabled by SW override. */
2180 mflcn_reg |= IXGBE_MFLCN_RFCE;
2181 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2182 break;
2183 default:
2184 hw_dbg(hw, "Flow control param set incorrectly\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002185 ret_val = IXGBE_ERR_CONFIG;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002186 goto out;
2187 break;
2188 }
2189
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002190 /* Set 802.3x based flow control settings. */
PJ Waskiewicz2132d382009-04-09 22:26:21 +00002191 mflcn_reg |= IXGBE_MFLCN_DPF;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002192 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
2193 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
2194
Alexander Duyck041441d2012-04-19 17:48:48 +00002195 fcrtl = (hw->fc.low_water << 10) | IXGBE_FCRTL_XONE;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002196
Alexander Duyck041441d2012-04-19 17:48:48 +00002197 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
2198 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
2199 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2200 hw->fc.high_water[i]) {
2201 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
2202 fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
2203 } else {
2204 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
2205 /*
2206 * In order to prevent Tx hangs when the internal Tx
2207 * switch is enabled we must set the high water mark
2208 * to the maximum FCRTH value. This allows the Tx
2209 * switch to function even under heavy Rx workloads.
2210 */
2211 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
2212 }
2213
2214 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002215 }
2216
2217 /* Configure pause time (2 TCs per register) */
Alexander Duyck041441d2012-04-19 17:48:48 +00002218 reg = hw->fc.pause_time * 0x00010001;
2219 for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
2220 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002221
Alexander Duyck041441d2012-04-19 17:48:48 +00002222 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002223
2224out:
2225 return ret_val;
2226}
2227
2228/**
Alexander Duyck67a79df2012-04-19 17:49:56 +00002229 * ixgbe_negotiate_fc - Negotiate flow control
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002230 * @hw: pointer to hardware structure
Alexander Duyck67a79df2012-04-19 17:49:56 +00002231 * @adv_reg: flow control advertised settings
2232 * @lp_reg: link partner's flow control settings
2233 * @adv_sym: symmetric pause bit in advertisement
2234 * @adv_asm: asymmetric pause bit in advertisement
2235 * @lp_sym: symmetric pause bit in link partner advertisement
2236 * @lp_asm: asymmetric pause bit in link partner advertisement
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002237 *
Alexander Duyck67a79df2012-04-19 17:49:56 +00002238 * Find the intersection between advertised settings and link partner's
2239 * advertised settings
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002240 **/
Alexander Duyck67a79df2012-04-19 17:49:56 +00002241static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
2242 u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002243{
Alexander Duyck67a79df2012-04-19 17:49:56 +00002244 if ((!(adv_reg)) || (!(lp_reg)))
2245 return IXGBE_ERR_FC_NOT_NEGOTIATED;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002246
Alexander Duyck67a79df2012-04-19 17:49:56 +00002247 if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
2248 /*
2249 * Now we need to check if the user selected Rx ONLY
2250 * of pause frames. In this case, we had to advertise
2251 * FULL flow control because we could not advertise RX
2252 * ONLY. Hence, we must now check to see if we need to
2253 * turn OFF the TRANSMISSION of PAUSE frames.
2254 */
2255 if (hw->fc.requested_mode == ixgbe_fc_full) {
2256 hw->fc.current_mode = ixgbe_fc_full;
2257 hw_dbg(hw, "Flow Control = FULL.\n");
2258 } else {
2259 hw->fc.current_mode = ixgbe_fc_rx_pause;
2260 hw_dbg(hw, "Flow Control=RX PAUSE frames only\n");
2261 }
2262 } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2263 (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2264 hw->fc.current_mode = ixgbe_fc_tx_pause;
2265 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
2266 } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2267 !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2268 hw->fc.current_mode = ixgbe_fc_rx_pause;
2269 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002270 } else {
Alexander Duyck67a79df2012-04-19 17:49:56 +00002271 hw->fc.current_mode = ixgbe_fc_none;
2272 hw_dbg(hw, "Flow Control = NONE.\n");
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002273 }
Alexander Duyck67a79df2012-04-19 17:49:56 +00002274 return 0;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002275}
2276
2277/**
2278 * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
2279 * @hw: pointer to hardware structure
2280 *
2281 * Enable flow control according on 1 gig fiber.
2282 **/
2283static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
2284{
2285 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
Alexander Duyck786e9a52012-03-28 08:03:48 +00002286 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002287
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002288 /*
2289 * On multispeed fiber at 1g, bail out if
2290 * - link is up but AN did not complete, or if
2291 * - link is up and AN completed but timed out
2292 */
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002293
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002294 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
Don Skidmore53f096d2011-07-28 01:00:58 +00002295 if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
Alexander Duyck786e9a52012-03-28 08:03:48 +00002296 (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1))
PJ Waskiewicz9bbe3a52009-11-24 18:51:28 +00002297 goto out;
PJ Waskiewicz9bbe3a52009-11-24 18:51:28 +00002298
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002299 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2300 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002301
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002302 ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
2303 pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
2304 IXGBE_PCS1GANA_ASM_PAUSE,
2305 IXGBE_PCS1GANA_SYM_PAUSE,
2306 IXGBE_PCS1GANA_ASM_PAUSE);
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002307
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002308out:
2309 return ret_val;
2310}
2311
2312/**
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002313 * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
2314 * @hw: pointer to hardware structure
2315 *
2316 * Enable flow control according to IEEE clause 37.
2317 **/
2318static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
2319{
2320 u32 links2, anlp1_reg, autoc_reg, links;
Alexander Duyck786e9a52012-03-28 08:03:48 +00002321 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002322
2323 /*
2324 * On backplane, bail out if
2325 * - backplane autoneg was not completed, or if
2326 * - we are 82599 and link partner is not AN enabled
2327 */
2328 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
Alexander Duyck786e9a52012-03-28 08:03:48 +00002329 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0)
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002330 goto out;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002331
2332 if (hw->mac.type == ixgbe_mac_82599EB) {
2333 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
Alexander Duyck786e9a52012-03-28 08:03:48 +00002334 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0)
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002335 goto out;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002336 }
2337 /*
2338 * Read the 10g AN autoc and LP ability registers and resolve
2339 * local flow control settings accordingly
2340 */
2341 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2342 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
2343
2344 ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
2345 anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
2346 IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
2347
2348out:
2349 return ret_val;
2350}
2351
2352/**
2353 * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
2354 * @hw: pointer to hardware structure
2355 *
2356 * Enable flow control according to IEEE clause 37.
2357 **/
2358static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
2359{
2360 u16 technology_ability_reg = 0;
2361 u16 lp_technology_ability_reg = 0;
2362
2363 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
2364 MDIO_MMD_AN,
2365 &technology_ability_reg);
2366 hw->phy.ops.read_reg(hw, MDIO_AN_LPA,
2367 MDIO_MMD_AN,
2368 &lp_technology_ability_reg);
2369
2370 return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
2371 (u32)lp_technology_ability_reg,
2372 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
2373 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
2374}
2375
2376/**
Alexander Duyck67a79df2012-04-19 17:49:56 +00002377 * ixgbe_fc_autoneg - Configure flow control
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002378 * @hw: pointer to hardware structure
2379 *
Alexander Duyck67a79df2012-04-19 17:49:56 +00002380 * Compares our advertised flow control capabilities to those advertised by
2381 * our link partner, and determines the proper flow control mode to use.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002382 **/
Alexander Duyck67a79df2012-04-19 17:49:56 +00002383void ixgbe_fc_autoneg(struct ixgbe_hw *hw)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002384{
Alexander Duyck67a79df2012-04-19 17:49:56 +00002385 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2386 ixgbe_link_speed speed;
2387 bool link_up;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002388
2389 /*
Alexander Duyck67a79df2012-04-19 17:49:56 +00002390 * AN should have completed when the cable was plugged in.
2391 * Look for reasons to bail out. Bail out if:
2392 * - FC autoneg is disabled, or if
2393 * - link is not up.
2394 *
2395 * Since we're being called from an LSC, link is already known to be up.
2396 * So use link_up_wait_to_complete=false.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002397 */
Alexander Duyck67a79df2012-04-19 17:49:56 +00002398 if (hw->fc.disable_fc_autoneg)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002399 goto out;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002400
Alexander Duyck67a79df2012-04-19 17:49:56 +00002401 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2402 if (!link_up)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002403 goto out;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002404
2405 switch (hw->phy.media_type) {
Alexander Duyck67a79df2012-04-19 17:49:56 +00002406 /* Autoneg flow control on fiber adapters */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002407 case ixgbe_media_type_fiber:
Alexander Duyck67a79df2012-04-19 17:49:56 +00002408 if (speed == IXGBE_LINK_SPEED_1GB_FULL)
2409 ret_val = ixgbe_fc_autoneg_fiber(hw);
2410 break;
2411
2412 /* Autoneg flow control on backplane adapters */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002413 case ixgbe_media_type_backplane:
Alexander Duyck67a79df2012-04-19 17:49:56 +00002414 ret_val = ixgbe_fc_autoneg_backplane(hw);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002415 break;
2416
Alexander Duyck67a79df2012-04-19 17:49:56 +00002417 /* Autoneg flow control on copper adapters */
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002418 case ixgbe_media_type_copper:
Don Skidmore73d80953d2013-07-31 02:19:24 +00002419 if (ixgbe_device_supports_autoneg_fc(hw))
Alexander Duyck67a79df2012-04-19 17:49:56 +00002420 ret_val = ixgbe_fc_autoneg_copper(hw);
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00002421 break;
2422
2423 default:
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00002424 break;
2425 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002426
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002427out:
Alexander Duyck67a79df2012-04-19 17:49:56 +00002428 if (ret_val == 0) {
2429 hw->fc.fc_was_autonegged = true;
2430 } else {
2431 hw->fc.fc_was_autonegged = false;
2432 hw->fc.current_mode = hw->fc.requested_mode;
2433 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002434}
2435
2436/**
Auke Kok9a799d72007-09-15 14:07:45 -07002437 * ixgbe_disable_pcie_master - Disable PCI-express master access
2438 * @hw: pointer to hardware structure
2439 *
2440 * Disables PCI-Express master access and verifies there are no pending
2441 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2442 * bit hasn't caused the master requests to be disabled, else 0
2443 * is returned signifying master requests disabled.
2444 **/
Emil Tantilovff9d1a52011-08-16 04:35:11 +00002445static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
Auke Kok9a799d72007-09-15 14:07:45 -07002446{
Emil Tantilova4297dc2011-02-14 08:45:13 +00002447 struct ixgbe_adapter *adapter = hw->back;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002448 s32 status = 0;
Emil Tantilovff9d1a52011-08-16 04:35:11 +00002449 u32 i;
2450 u16 value;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002451
Emil Tantilovff9d1a52011-08-16 04:35:11 +00002452 /* Always set this bit to ensure any future transactions are blocked */
2453 IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS);
2454
2455 /* Exit if master requests are blocked */
Emil Tantilova4297dc2011-02-14 08:45:13 +00002456 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2457 goto out;
Auke Kok9a799d72007-09-15 14:07:45 -07002458
Emil Tantilovff9d1a52011-08-16 04:35:11 +00002459 /* Poll for master request bit to clear */
Auke Kok9a799d72007-09-15 14:07:45 -07002460 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
Emil Tantilovff9d1a52011-08-16 04:35:11 +00002461 udelay(100);
Emil Tantilova4297dc2011-02-14 08:45:13 +00002462 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
Emil Tantilovff9d1a52011-08-16 04:35:11 +00002463 goto out;
Auke Kok9a799d72007-09-15 14:07:45 -07002464 }
2465
Emil Tantilova4297dc2011-02-14 08:45:13 +00002466 /*
2467 * Two consecutive resets are required via CTRL.RST per datasheet
2468 * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
2469 * of this need. The first reset prevents new master requests from
Emil Tantilovff9d1a52011-08-16 04:35:11 +00002470 * being issued by our device. We then must wait 1usec or more for any
Emil Tantilova4297dc2011-02-14 08:45:13 +00002471 * remaining completions from the PCIe bus to trickle in, and then reset
2472 * again to clear out any effects they may have had on our device.
2473 */
Emil Tantilovff9d1a52011-08-16 04:35:11 +00002474 hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
2475 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2476
2477 /*
2478 * Before proceeding, make sure that the PCIe block does not have
2479 * transactions pending.
2480 */
2481 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2482 udelay(100);
2483 pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
2484 &value);
2485 if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2486 goto out;
2487 }
2488
2489 hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
2490 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
Emil Tantilova4297dc2011-02-14 08:45:13 +00002491
2492out:
Auke Kok9a799d72007-09-15 14:07:45 -07002493 return status;
2494}
2495
Auke Kok9a799d72007-09-15 14:07:45 -07002496/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002497 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
Auke Kok9a799d72007-09-15 14:07:45 -07002498 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002499 * @mask: Mask to specify which semaphore to acquire
Auke Kok9a799d72007-09-15 14:07:45 -07002500 *
Emil Tantilovda74cd42011-03-03 09:25:07 +00002501 * Acquires the SWFW semaphore through the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002502 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2503 **/
2504s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2505{
2506 u32 gssr;
2507 u32 swmask = mask;
2508 u32 fwmask = mask << 5;
2509 s32 timeout = 200;
2510
2511 while (timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002512 /*
2513 * SW EEPROM semaphore bit is used for access to all
2514 * SW_FW_SYNC/GSSR bits (not just EEPROM)
2515 */
Auke Kok9a799d72007-09-15 14:07:45 -07002516 if (ixgbe_get_eeprom_semaphore(hw))
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002517 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002518
2519 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2520 if (!(gssr & (fwmask | swmask)))
2521 break;
2522
2523 /*
2524 * Firmware currently using resource (fwmask) or other software
2525 * thread currently using resource (swmask)
2526 */
2527 ixgbe_release_eeprom_semaphore(hw);
Don Skidmore032b4322011-03-18 09:32:53 +00002528 usleep_range(5000, 10000);
Auke Kok9a799d72007-09-15 14:07:45 -07002529 timeout--;
2530 }
2531
2532 if (!timeout) {
Emil Tantilovdbf893e2011-02-08 09:42:41 +00002533 hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
Peter P Waskiewicz Jr539e5f02009-09-30 12:07:38 +00002534 return IXGBE_ERR_SWFW_SYNC;
Auke Kok9a799d72007-09-15 14:07:45 -07002535 }
2536
2537 gssr |= swmask;
2538 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2539
2540 ixgbe_release_eeprom_semaphore(hw);
2541 return 0;
2542}
2543
2544/**
2545 * ixgbe_release_swfw_sync - Release SWFW semaphore
2546 * @hw: pointer to hardware structure
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002547 * @mask: Mask to specify which semaphore to release
Auke Kok9a799d72007-09-15 14:07:45 -07002548 *
Emil Tantilovda74cd42011-03-03 09:25:07 +00002549 * Releases the SWFW semaphore through the GSSR register for the specified
Auke Kok9a799d72007-09-15 14:07:45 -07002550 * function (CSR, PHY0, PHY1, EEPROM, Flash)
2551 **/
2552void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2553{
2554 u32 gssr;
2555 u32 swmask = mask;
2556
2557 ixgbe_get_eeprom_semaphore(hw);
2558
2559 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2560 gssr &= ~swmask;
2561 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2562
2563 ixgbe_release_eeprom_semaphore(hw);
2564}
2565
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002566/**
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00002567 * ixgbe_disable_rx_buff_generic - Stops the receive data path
2568 * @hw: pointer to hardware structure
2569 *
2570 * Stops the receive data path and waits for the HW to internally
2571 * empty the Rx security block.
2572 **/
2573s32 ixgbe_disable_rx_buff_generic(struct ixgbe_hw *hw)
2574{
2575#define IXGBE_MAX_SECRX_POLL 40
2576 int i;
2577 int secrxreg;
2578
2579 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
2580 secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
2581 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
2582 for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
2583 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
2584 if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
2585 break;
2586 else
2587 /* Use interrupt-safe sleep just in case */
Jacob Kellerdb76ad42012-05-03 01:44:12 +00002588 udelay(1000);
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00002589 }
2590
2591 /* For informational purposes only */
2592 if (i >= IXGBE_MAX_SECRX_POLL)
2593 hw_dbg(hw, "Rx unit being enabled before security "
2594 "path fully disabled. Continuing with init.\n");
2595
2596 return 0;
2597
2598}
2599
2600/**
2601 * ixgbe_enable_rx_buff - Enables the receive data path
2602 * @hw: pointer to hardware structure
2603 *
2604 * Enables the receive data path
2605 **/
2606s32 ixgbe_enable_rx_buff_generic(struct ixgbe_hw *hw)
2607{
2608 int secrxreg;
2609
2610 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
2611 secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
2612 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
2613 IXGBE_WRITE_FLUSH(hw);
2614
2615 return 0;
2616}
2617
2618/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002619 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2620 * @hw: pointer to hardware structure
2621 * @regval: register value to write to RXCTRL
2622 *
2623 * Enables the Rx DMA unit
2624 **/
2625s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2626{
2627 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
2628
2629 return 0;
2630}
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002631
2632/**
2633 * ixgbe_blink_led_start_generic - Blink LED based on index.
2634 * @hw: pointer to hardware structure
2635 * @index: led number to blink
2636 **/
2637s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2638{
2639 ixgbe_link_speed speed = 0;
Rusty Russell3db1cd52011-12-19 13:56:45 +00002640 bool link_up = false;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002641 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2642 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
Don Skidmored7bbcd32012-10-24 06:19:01 +00002643 s32 ret_val = 0;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002644
2645 /*
2646 * Link must be up to auto-blink the LEDs;
2647 * Force it if link is down.
2648 */
2649 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2650
2651 if (!link_up) {
Don Skidmored7bbcd32012-10-24 06:19:01 +00002652 /* Need the SW/FW semaphore around AUTOC writes if 82599 and
2653 * LESM is on.
2654 */
2655 bool got_lock = false;
2656
2657 if ((hw->mac.type == ixgbe_mac_82599EB) &&
2658 ixgbe_verify_lesm_fw_enabled_82599(hw)) {
2659 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
2660 IXGBE_GSSR_MAC_CSR_SM);
2661 if (ret_val)
2662 goto out;
2663
2664 got_lock = true;
2665 }
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00002666 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002667 autoc_reg |= IXGBE_AUTOC_FLU;
2668 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002669 IXGBE_WRITE_FLUSH(hw);
Don Skidmored7bbcd32012-10-24 06:19:01 +00002670
2671 if (got_lock)
2672 hw->mac.ops.release_swfw_sync(hw,
2673 IXGBE_GSSR_MAC_CSR_SM);
Don Skidmore032b4322011-03-18 09:32:53 +00002674 usleep_range(10000, 20000);
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002675 }
2676
2677 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2678 led_reg |= IXGBE_LED_BLINK(index);
2679 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2680 IXGBE_WRITE_FLUSH(hw);
2681
Don Skidmored7bbcd32012-10-24 06:19:01 +00002682out:
2683 return ret_val;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002684}
2685
2686/**
2687 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2688 * @hw: pointer to hardware structure
2689 * @index: led number to stop blinking
2690 **/
2691s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2692{
2693 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2694 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
Don Skidmored7bbcd32012-10-24 06:19:01 +00002695 s32 ret_val = 0;
2696 bool got_lock = false;
2697
2698 /* Need the SW/FW semaphore around AUTOC writes if 82599 and
2699 * LESM is on.
2700 */
2701 if ((hw->mac.type == ixgbe_mac_82599EB) &&
2702 ixgbe_verify_lesm_fw_enabled_82599(hw)) {
2703 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
2704 IXGBE_GSSR_MAC_CSR_SM);
2705 if (ret_val)
2706 goto out;
2707
2708 got_lock = true;
2709 }
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002710
2711 autoc_reg &= ~IXGBE_AUTOC_FLU;
2712 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2713 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2714
Don Skidmored7bbcd32012-10-24 06:19:01 +00002715 if (hw->mac.type == ixgbe_mac_82599EB)
2716 ixgbe_reset_pipeline_82599(hw);
2717
2718 if (got_lock)
2719 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
2720
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002721 led_reg &= ~IXGBE_LED_MODE_MASK(index);
2722 led_reg &= ~IXGBE_LED_BLINK(index);
2723 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2724 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2725 IXGBE_WRITE_FLUSH(hw);
2726
Don Skidmored7bbcd32012-10-24 06:19:01 +00002727out:
2728 return ret_val;
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002729}
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002730
2731/**
2732 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2733 * @hw: pointer to hardware structure
2734 * @san_mac_offset: SAN MAC address offset
2735 *
2736 * This function will read the EEPROM location for the SAN MAC address
2737 * pointer, and returns the value at that location. This is used in both
2738 * get and set mac_addr routines.
2739 **/
2740static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2741 u16 *san_mac_offset)
2742{
2743 /*
2744 * First read the EEPROM pointer to see if the MAC addresses are
2745 * available.
2746 */
2747 hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
2748
2749 return 0;
2750}
2751
2752/**
2753 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2754 * @hw: pointer to hardware structure
2755 * @san_mac_addr: SAN MAC address
2756 *
2757 * Reads the SAN MAC address from the EEPROM, if it's available. This is
2758 * per-port, so set_lan_id() must be called before reading the addresses.
2759 * set_lan_id() is called by identify_sfp(), but this cannot be relied
2760 * upon for non-SFP connections, so we must call it here.
2761 **/
2762s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2763{
2764 u16 san_mac_data, san_mac_offset;
2765 u8 i;
2766
2767 /*
2768 * First read the EEPROM pointer to see if the MAC addresses are
2769 * available. If they're not, no point in calling set_lan_id() here.
2770 */
2771 ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
2772
2773 if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
2774 /*
2775 * No addresses available in this EEPROM. It's not an
2776 * error though, so just wipe the local address and return.
2777 */
2778 for (i = 0; i < 6; i++)
2779 san_mac_addr[i] = 0xFF;
2780
2781 goto san_mac_addr_out;
2782 }
2783
2784 /* make sure we know which port we need to program */
2785 hw->mac.ops.set_lan_id(hw);
2786 /* apply the port offset to the address offset */
2787 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2788 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2789 for (i = 0; i < 3; i++) {
2790 hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
2791 san_mac_addr[i * 2] = (u8)(san_mac_data);
2792 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2793 san_mac_offset++;
2794 }
2795
2796san_mac_addr_out:
2797 return 0;
2798}
2799
2800/**
2801 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
2802 * @hw: pointer to hardware structure
2803 *
2804 * Read PCIe configuration space, and get the MSI-X vector count from
2805 * the capabilities table.
2806 **/
Emil Tantilov71161302012-03-22 03:00:29 +00002807u16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002808{
2809 struct ixgbe_adapter *adapter = hw->back;
Emil Tantilov71161302012-03-22 03:00:29 +00002810 u16 msix_count = 1;
2811 u16 max_msix_count;
2812 u16 pcie_offset;
2813
2814 switch (hw->mac.type) {
2815 case ixgbe_mac_82598EB:
2816 pcie_offset = IXGBE_PCIE_MSIX_82598_CAPS;
2817 max_msix_count = IXGBE_MAX_MSIX_VECTORS_82598;
2818 break;
2819 case ixgbe_mac_82599EB:
2820 case ixgbe_mac_X540:
2821 pcie_offset = IXGBE_PCIE_MSIX_82599_CAPS;
2822 max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599;
2823 break;
2824 default:
2825 return msix_count;
2826 }
2827
2828 pci_read_config_word(adapter->pdev, pcie_offset, &msix_count);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002829 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
2830
Emil Tantilov71161302012-03-22 03:00:29 +00002831 /* MSI-X count is zero-based in HW */
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002832 msix_count++;
2833
Emil Tantilov71161302012-03-22 03:00:29 +00002834 if (msix_count > max_msix_count)
2835 msix_count = max_msix_count;
2836
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002837 return msix_count;
2838}
2839
2840/**
2841 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
2842 * @hw: pointer to hardware struct
2843 * @rar: receive address register index to disassociate
2844 * @vmdq: VMDq pool index to remove from the rar
2845 **/
2846s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2847{
2848 u32 mpsar_lo, mpsar_hi;
2849 u32 rar_entries = hw->mac.num_rar_entries;
2850
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002851 /* Make sure we are using a valid rar index range */
2852 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002853 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002854 return IXGBE_ERR_INVALID_ARGUMENT;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002855 }
2856
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002857 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2858 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2859
2860 if (!mpsar_lo && !mpsar_hi)
2861 goto done;
2862
2863 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2864 if (mpsar_lo) {
2865 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2866 mpsar_lo = 0;
2867 }
2868 if (mpsar_hi) {
2869 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2870 mpsar_hi = 0;
2871 }
2872 } else if (vmdq < 32) {
2873 mpsar_lo &= ~(1 << vmdq);
2874 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2875 } else {
2876 mpsar_hi &= ~(1 << (vmdq - 32));
2877 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2878 }
2879
2880 /* was that the last pool using this rar? */
2881 if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
2882 hw->mac.ops.clear_rar(hw, rar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002883done:
2884 return 0;
2885}
2886
2887/**
2888 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
2889 * @hw: pointer to hardware struct
2890 * @rar: receive address register index to associate with a VMDq index
2891 * @vmdq: VMDq pool index
2892 **/
2893s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2894{
2895 u32 mpsar;
2896 u32 rar_entries = hw->mac.num_rar_entries;
2897
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002898 /* Make sure we are using a valid rar index range */
2899 if (rar >= rar_entries) {
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002900 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
Emil Tantilovc700f4e2011-02-17 11:34:58 +00002901 return IXGBE_ERR_INVALID_ARGUMENT;
2902 }
2903
2904 if (vmdq < 32) {
2905 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2906 mpsar |= 1 << vmdq;
2907 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2908 } else {
2909 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2910 mpsar |= 1 << (vmdq - 32);
2911 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002912 }
2913 return 0;
2914}
2915
2916/**
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00002917 * This function should only be involved in the IOV mode.
2918 * In IOV mode, Default pool is next pool after the number of
2919 * VFs advertized and not 0.
2920 * MPSAR table needs to be updated for SAN_MAC RAR [hw->mac.san_mac_rar_index]
2921 *
2922 * ixgbe_set_vmdq_san_mac - Associate default VMDq pool index with a rx address
2923 * @hw: pointer to hardware struct
2924 * @vmdq: VMDq pool index
2925 **/
2926s32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq)
2927{
2928 u32 rar = hw->mac.san_mac_rar_index;
2929
2930 if (vmdq < 32) {
2931 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 1 << vmdq);
2932 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2933 } else {
2934 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2935 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 1 << (vmdq - 32));
2936 }
2937
2938 return 0;
2939}
2940
2941/**
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002942 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
2943 * @hw: pointer to hardware structure
2944 **/
2945s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
2946{
2947 int i;
2948
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002949 for (i = 0; i < 128; i++)
2950 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
2951
2952 return 0;
2953}
2954
2955/**
2956 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
2957 * @hw: pointer to hardware structure
2958 * @vlan: VLAN id to write to VLAN filter
2959 *
2960 * return the VLVF index where this VLAN id should be placed
2961 *
2962 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +00002963static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002964{
2965 u32 bits = 0;
2966 u32 first_empty_slot = 0;
2967 s32 regindex;
2968
2969 /* short cut the special case */
2970 if (vlan == 0)
2971 return 0;
2972
2973 /*
2974 * Search for the vlan id in the VLVF entries. Save off the first empty
2975 * slot found along the way
2976 */
2977 for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
2978 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
2979 if (!bits && !(first_empty_slot))
2980 first_empty_slot = regindex;
2981 else if ((bits & 0x0FFF) == vlan)
2982 break;
2983 }
2984
2985 /*
2986 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
2987 * in the VLVF. Else use the first empty VLVF register for this
2988 * vlan id.
2989 */
2990 if (regindex >= IXGBE_VLVF_ENTRIES) {
2991 if (first_empty_slot)
2992 regindex = first_empty_slot;
2993 else {
2994 hw_dbg(hw, "No space in VLVF.\n");
2995 regindex = IXGBE_ERR_NO_SPACE;
2996 }
2997 }
2998
2999 return regindex;
3000}
3001
3002/**
3003 * ixgbe_set_vfta_generic - Set VLAN filter table
3004 * @hw: pointer to hardware structure
3005 * @vlan: VLAN id to write to VLAN filter
3006 * @vind: VMDq output index that maps queue to VLAN id in VFVFB
3007 * @vlan_on: boolean flag to turn on/off VLAN in VFVF
3008 *
3009 * Turn on/off specified VLAN in the VLAN filter table.
3010 **/
3011s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
3012 bool vlan_on)
3013{
3014 s32 regindex;
3015 u32 bitindex;
3016 u32 vfta;
3017 u32 bits;
3018 u32 vt;
3019 u32 targetbit;
3020 bool vfta_changed = false;
3021
3022 if (vlan > 4095)
3023 return IXGBE_ERR_PARAM;
3024
3025 /*
3026 * this is a 2 part operation - first the VFTA, then the
3027 * VLVF and VLVFB if VT Mode is set
3028 * We don't write the VFTA until we know the VLVF part succeeded.
3029 */
3030
3031 /* Part 1
3032 * The VFTA is a bitstring made up of 128 32-bit registers
3033 * that enable the particular VLAN id, much like the MTA:
3034 * bits[11-5]: which register
3035 * bits[4-0]: which bit in the register
3036 */
3037 regindex = (vlan >> 5) & 0x7F;
3038 bitindex = vlan & 0x1F;
3039 targetbit = (1 << bitindex);
3040 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
3041
3042 if (vlan_on) {
3043 if (!(vfta & targetbit)) {
3044 vfta |= targetbit;
3045 vfta_changed = true;
3046 }
3047 } else {
3048 if ((vfta & targetbit)) {
3049 vfta &= ~targetbit;
3050 vfta_changed = true;
3051 }
3052 }
3053
3054 /* Part 2
3055 * If VT Mode is set
3056 * Either vlan_on
3057 * make sure the vlan is in VLVF
3058 * set the vind bit in the matching VLVFB
3059 * Or !vlan_on
3060 * clear the pool bit and possibly the vind
3061 */
3062 vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3063 if (vt & IXGBE_VT_CTL_VT_ENABLE) {
3064 s32 vlvf_index;
3065
3066 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
3067 if (vlvf_index < 0)
3068 return vlvf_index;
3069
3070 if (vlan_on) {
3071 /* set the pool bit */
3072 if (vind < 32) {
3073 bits = IXGBE_READ_REG(hw,
3074 IXGBE_VLVFB(vlvf_index*2));
3075 bits |= (1 << vind);
3076 IXGBE_WRITE_REG(hw,
3077 IXGBE_VLVFB(vlvf_index*2),
3078 bits);
3079 } else {
3080 bits = IXGBE_READ_REG(hw,
3081 IXGBE_VLVFB((vlvf_index*2)+1));
3082 bits |= (1 << (vind-32));
3083 IXGBE_WRITE_REG(hw,
3084 IXGBE_VLVFB((vlvf_index*2)+1),
3085 bits);
3086 }
3087 } else {
3088 /* clear the pool bit */
3089 if (vind < 32) {
3090 bits = IXGBE_READ_REG(hw,
3091 IXGBE_VLVFB(vlvf_index*2));
3092 bits &= ~(1 << vind);
3093 IXGBE_WRITE_REG(hw,
3094 IXGBE_VLVFB(vlvf_index*2),
3095 bits);
3096 bits |= IXGBE_READ_REG(hw,
3097 IXGBE_VLVFB((vlvf_index*2)+1));
3098 } else {
3099 bits = IXGBE_READ_REG(hw,
3100 IXGBE_VLVFB((vlvf_index*2)+1));
3101 bits &= ~(1 << (vind-32));
3102 IXGBE_WRITE_REG(hw,
3103 IXGBE_VLVFB((vlvf_index*2)+1),
3104 bits);
3105 bits |= IXGBE_READ_REG(hw,
3106 IXGBE_VLVFB(vlvf_index*2));
3107 }
3108 }
3109
3110 /*
3111 * If there are still bits set in the VLVFB registers
3112 * for the VLAN ID indicated we need to see if the
3113 * caller is requesting that we clear the VFTA entry bit.
3114 * If the caller has requested that we clear the VFTA
3115 * entry bit but there are still pools/VFs using this VLAN
3116 * ID entry then ignore the request. We're not worried
3117 * about the case where we're turning the VFTA VLAN ID
3118 * entry bit on, only when requested to turn it off as
3119 * there may be multiple pools and/or VFs using the
3120 * VLAN ID entry. In that case we cannot clear the
3121 * VFTA bit until all pools/VFs using that VLAN ID have also
3122 * been cleared. This will be indicated by "bits" being
3123 * zero.
3124 */
3125 if (bits) {
3126 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
3127 (IXGBE_VLVF_VIEN | vlan));
3128 if (!vlan_on) {
3129 /* someone wants to clear the vfta entry
3130 * but some pools/VFs are still using it.
3131 * Ignore it. */
3132 vfta_changed = false;
3133 }
3134 }
3135 else
3136 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
3137 }
3138
3139 if (vfta_changed)
3140 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
3141
3142 return 0;
3143}
3144
3145/**
3146 * ixgbe_clear_vfta_generic - Clear VLAN filter table
3147 * @hw: pointer to hardware structure
3148 *
3149 * Clears the VLAN filer table, and the VMDq index associated with the filter
3150 **/
3151s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
3152{
3153 u32 offset;
3154
3155 for (offset = 0; offset < hw->mac.vft_size; offset++)
3156 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
3157
3158 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
3159 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
3160 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
3161 IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
3162 }
3163
3164 return 0;
3165}
3166
3167/**
3168 * ixgbe_check_mac_link_generic - Determine link and speed status
3169 * @hw: pointer to hardware structure
3170 * @speed: pointer to link speed
3171 * @link_up: true when link is up
3172 * @link_up_wait_to_complete: bool used to wait for link up or not
3173 *
3174 * Reads the links register to determine if link is up and the current speed
3175 **/
3176s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
Emil Tantilov8c7bea32011-02-19 08:43:44 +00003177 bool *link_up, bool link_up_wait_to_complete)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003178{
Emil Tantilov48de36c2011-02-16 01:38:08 +00003179 u32 links_reg, links_orig;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003180 u32 i;
3181
Emil Tantilov48de36c2011-02-16 01:38:08 +00003182 /* clear the old state */
3183 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
3184
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003185 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
Emil Tantilov48de36c2011-02-16 01:38:08 +00003186
3187 if (links_orig != links_reg) {
3188 hw_dbg(hw, "LINKS changed from %08X to %08X\n",
3189 links_orig, links_reg);
3190 }
3191
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003192 if (link_up_wait_to_complete) {
3193 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
3194 if (links_reg & IXGBE_LINKS_UP) {
3195 *link_up = true;
3196 break;
3197 } else {
3198 *link_up = false;
3199 }
3200 msleep(100);
3201 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
3202 }
3203 } else {
3204 if (links_reg & IXGBE_LINKS_UP)
3205 *link_up = true;
3206 else
3207 *link_up = false;
3208 }
3209
3210 if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
3211 IXGBE_LINKS_SPEED_10G_82599)
3212 *speed = IXGBE_LINK_SPEED_10GB_FULL;
3213 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
Emil Tantilov63d778d2011-02-19 08:43:39 +00003214 IXGBE_LINKS_SPEED_1G_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003215 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00003216 else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
3217 IXGBE_LINKS_SPEED_100_82599)
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003218 *speed = IXGBE_LINK_SPEED_100_FULL;
Emil Tantilov63d778d2011-02-19 08:43:39 +00003219 else
3220 *speed = IXGBE_LINK_SPEED_UNKNOWN;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003221
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00003222 return 0;
3223}
Don Skidmorea391f1d2010-11-16 19:27:15 -08003224
3225/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003226 * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
Don Skidmorea391f1d2010-11-16 19:27:15 -08003227 * the EEPROM
3228 * @hw: pointer to hardware structure
3229 * @wwnn_prefix: the alternative WWNN prefix
3230 * @wwpn_prefix: the alternative WWPN prefix
3231 *
3232 * This function will read the EEPROM from the alternative SAN MAC address
3233 * block to check the support for the alternative WWNN/WWPN prefix support.
3234 **/
3235s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
3236 u16 *wwpn_prefix)
3237{
3238 u16 offset, caps;
3239 u16 alt_san_mac_blk_offset;
3240
3241 /* clear output first */
3242 *wwnn_prefix = 0xFFFF;
3243 *wwpn_prefix = 0xFFFF;
3244
3245 /* check if alternative SAN MAC is supported */
3246 hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
3247 &alt_san_mac_blk_offset);
3248
3249 if ((alt_san_mac_blk_offset == 0) ||
3250 (alt_san_mac_blk_offset == 0xFFFF))
3251 goto wwn_prefix_out;
3252
3253 /* check capability in alternative san mac address block */
3254 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
3255 hw->eeprom.ops.read(hw, offset, &caps);
3256 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
3257 goto wwn_prefix_out;
3258
3259 /* get the corresponding prefix for WWNN/WWPN */
3260 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
3261 hw->eeprom.ops.read(hw, offset, wwnn_prefix);
3262
3263 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
3264 hw->eeprom.ops.read(hw, offset, wwpn_prefix);
3265
3266wwn_prefix_out:
3267 return 0;
3268}
Greg Rosea985b6c32010-11-18 03:02:52 +00003269
3270/**
3271 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
3272 * @hw: pointer to hardware structure
3273 * @enable: enable or disable switch for anti-spoofing
3274 * @pf: Physical Function pool - do not enable anti-spoofing for the PF
3275 *
3276 **/
3277void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
3278{
3279 int j;
3280 int pf_target_reg = pf >> 3;
3281 int pf_target_shift = pf % 8;
3282 u32 pfvfspoof = 0;
3283
3284 if (hw->mac.type == ixgbe_mac_82598EB)
3285 return;
3286
3287 if (enable)
3288 pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
3289
3290 /*
3291 * PFVFSPOOF register array is size 8 with 8 bits assigned to
3292 * MAC anti-spoof enables in each register array element.
3293 */
Alexander Duyckef89e0a2012-05-05 05:32:58 +00003294 for (j = 0; j < pf_target_reg; j++)
Greg Rosea985b6c32010-11-18 03:02:52 +00003295 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
3296
Greg Rosea985b6c32010-11-18 03:02:52 +00003297 /*
3298 * The PF should be allowed to spoof so that it can support
Alexander Duyckef89e0a2012-05-05 05:32:58 +00003299 * emulation mode NICs. Do not set the bits assigned to the PF
Greg Rosea985b6c32010-11-18 03:02:52 +00003300 */
Alexander Duyckef89e0a2012-05-05 05:32:58 +00003301 pfvfspoof &= (1 << pf_target_shift) - 1;
3302 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
3303
3304 /*
3305 * Remaining pools belong to the PF so they do not need to have
3306 * anti-spoofing enabled.
3307 */
3308 for (j++; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
3309 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), 0);
Greg Rosea985b6c32010-11-18 03:02:52 +00003310}
3311
3312/**
3313 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
3314 * @hw: pointer to hardware structure
3315 * @enable: enable or disable switch for VLAN anti-spoofing
3316 * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
3317 *
3318 **/
3319void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
3320{
3321 int vf_target_reg = vf >> 3;
3322 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
3323 u32 pfvfspoof;
3324
3325 if (hw->mac.type == ixgbe_mac_82598EB)
3326 return;
3327
3328 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
3329 if (enable)
3330 pfvfspoof |= (1 << vf_target_shift);
3331 else
3332 pfvfspoof &= ~(1 << vf_target_shift);
3333 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
3334}
Emil Tantilovb776d102011-03-31 09:36:18 +00003335
3336/**
3337 * ixgbe_get_device_caps_generic - Get additional device capabilities
3338 * @hw: pointer to hardware structure
3339 * @device_caps: the EEPROM word with the extra device capabilities
3340 *
3341 * This function will read the EEPROM location for the device capabilities,
3342 * and return the word through device_caps.
3343 **/
3344s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
3345{
3346 hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
3347
3348 return 0;
3349}
John Fastabend80605c652011-05-02 12:34:10 +00003350
3351/**
3352 * ixgbe_set_rxpba_generic - Initialize RX packet buffer
3353 * @hw: pointer to hardware structure
3354 * @num_pb: number of packet buffers to allocate
3355 * @headroom: reserve n KB of headroom
3356 * @strategy: packet buffer allocation strategy
3357 **/
3358void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw,
3359 int num_pb,
3360 u32 headroom,
3361 int strategy)
3362{
3363 u32 pbsize = hw->mac.rx_pb_size;
3364 int i = 0;
3365 u32 rxpktsize, txpktsize, txpbthresh;
3366
3367 /* Reserve headroom */
3368 pbsize -= headroom;
3369
3370 if (!num_pb)
3371 num_pb = 1;
3372
3373 /* Divide remaining packet buffer space amongst the number
3374 * of packet buffers requested using supplied strategy.
3375 */
3376 switch (strategy) {
3377 case (PBA_STRATEGY_WEIGHTED):
3378 /* pba_80_48 strategy weight first half of packet buffer with
3379 * 5/8 of the packet buffer space.
3380 */
3381 rxpktsize = ((pbsize * 5 * 2) / (num_pb * 8));
3382 pbsize -= rxpktsize * (num_pb / 2);
3383 rxpktsize <<= IXGBE_RXPBSIZE_SHIFT;
3384 for (; i < (num_pb / 2); i++)
3385 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
3386 /* Fall through to configure remaining packet buffers */
3387 case (PBA_STRATEGY_EQUAL):
3388 /* Divide the remaining Rx packet buffer evenly among the TCs */
3389 rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
3390 for (; i < num_pb; i++)
3391 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
3392 break;
3393 default:
3394 break;
3395 }
3396
3397 /*
3398 * Setup Tx packet buffer and threshold equally for all TCs
3399 * TXPBTHRESH register is set in K so divide by 1024 and subtract
3400 * 10 since the largest packet we support is just over 9K.
3401 */
3402 txpktsize = IXGBE_TXPBSIZE_MAX / num_pb;
3403 txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
3404 for (i = 0; i < num_pb; i++) {
3405 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
3406 IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
3407 }
3408
3409 /* Clear unused TCs, if any, to zero buffer size*/
3410 for (; i < IXGBE_MAX_PB; i++) {
3411 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
3412 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
3413 IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
3414 }
3415}
Emil Tantilov9612de92011-05-07 07:40:20 +00003416
3417/**
3418 * ixgbe_calculate_checksum - Calculate checksum for buffer
3419 * @buffer: pointer to EEPROM
3420 * @length: size of EEPROM to calculate a checksum for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003421 *
Emil Tantilov9612de92011-05-07 07:40:20 +00003422 * Calculates the checksum for some buffer on a specified length. The
3423 * checksum calculated is returned.
3424 **/
3425static u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
3426{
3427 u32 i;
3428 u8 sum = 0;
3429
3430 if (!buffer)
3431 return 0;
3432
3433 for (i = 0; i < length; i++)
3434 sum += buffer[i];
3435
3436 return (u8) (0 - sum);
3437}
3438
3439/**
3440 * ixgbe_host_interface_command - Issue command to manageability block
3441 * @hw: pointer to the HW structure
3442 * @buffer: contains the command to write and where the return status will
3443 * be placed
Don Skidmorec466d7a2012-02-28 06:35:54 +00003444 * @length: length of buffer, must be multiple of 4 bytes
Emil Tantilov9612de92011-05-07 07:40:20 +00003445 *
3446 * Communicates with the manageability block. On success return 0
3447 * else return IXGBE_ERR_HOST_INTERFACE_COMMAND.
3448 **/
Emil Tantilov79488c52011-10-11 08:24:57 +00003449static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
Emil Tantilov9612de92011-05-07 07:40:20 +00003450 u32 length)
3451{
Emil Tantilov331bcf42011-10-22 05:21:32 +00003452 u32 hicr, i, bi;
Emil Tantilov9612de92011-05-07 07:40:20 +00003453 u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
3454 u8 buf_len, dword_len;
3455
3456 s32 ret_val = 0;
3457
3458 if (length == 0 || length & 0x3 ||
3459 length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
3460 hw_dbg(hw, "Buffer length failure.\n");
3461 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3462 goto out;
3463 }
3464
3465 /* Check that the host interface is enabled. */
3466 hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
3467 if ((hicr & IXGBE_HICR_EN) == 0) {
3468 hw_dbg(hw, "IXGBE_HOST_EN bit disabled.\n");
3469 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3470 goto out;
3471 }
3472
3473 /* Calculate length in DWORDs */
3474 dword_len = length >> 2;
3475
3476 /*
3477 * The device driver writes the relevant command block
3478 * into the ram area.
3479 */
3480 for (i = 0; i < dword_len; i++)
3481 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG,
Emil Tantilov79488c52011-10-11 08:24:57 +00003482 i, cpu_to_le32(buffer[i]));
Emil Tantilov9612de92011-05-07 07:40:20 +00003483
3484 /* Setting this bit tells the ARC that a new command is pending. */
3485 IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C);
3486
3487 for (i = 0; i < IXGBE_HI_COMMAND_TIMEOUT; i++) {
3488 hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
3489 if (!(hicr & IXGBE_HICR_C))
3490 break;
3491 usleep_range(1000, 2000);
3492 }
3493
3494 /* Check command successful completion. */
3495 if (i == IXGBE_HI_COMMAND_TIMEOUT ||
3496 (!(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV))) {
3497 hw_dbg(hw, "Command has failed with no status valid.\n");
3498 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3499 goto out;
3500 }
3501
3502 /* Calculate length in DWORDs */
3503 dword_len = hdr_size >> 2;
3504
3505 /* first pull in the header so we know the buffer length */
Emil Tantilov331bcf42011-10-22 05:21:32 +00003506 for (bi = 0; bi < dword_len; bi++) {
3507 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
3508 le32_to_cpus(&buffer[bi]);
Emil Tantilov79488c52011-10-11 08:24:57 +00003509 }
Emil Tantilov9612de92011-05-07 07:40:20 +00003510
3511 /* If there is any thing in data position pull it in */
3512 buf_len = ((struct ixgbe_hic_hdr *)buffer)->buf_len;
3513 if (buf_len == 0)
3514 goto out;
3515
3516 if (length < (buf_len + hdr_size)) {
3517 hw_dbg(hw, "Buffer not large enough for reply message.\n");
3518 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3519 goto out;
3520 }
3521
Emil Tantilov331bcf42011-10-22 05:21:32 +00003522 /* Calculate length in DWORDs, add 3 for odd lengths */
3523 dword_len = (buf_len + 3) >> 2;
Emil Tantilov9612de92011-05-07 07:40:20 +00003524
Emil Tantilov331bcf42011-10-22 05:21:32 +00003525 /* Pull in the rest of the buffer (bi is where we left off)*/
3526 for (; bi <= dword_len; bi++) {
3527 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
3528 le32_to_cpus(&buffer[bi]);
3529 }
Emil Tantilov9612de92011-05-07 07:40:20 +00003530
3531out:
3532 return ret_val;
3533}
3534
3535/**
3536 * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware
3537 * @hw: pointer to the HW structure
3538 * @maj: driver version major number
3539 * @min: driver version minor number
3540 * @build: driver version build number
3541 * @sub: driver version sub build number
3542 *
3543 * Sends driver version number to firmware through the manageability
3544 * block. On success return 0
3545 * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
3546 * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
3547 **/
3548s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
3549 u8 build, u8 sub)
3550{
3551 struct ixgbe_hic_drv_info fw_cmd;
3552 int i;
3553 s32 ret_val = 0;
3554
3555 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM) != 0) {
3556 ret_val = IXGBE_ERR_SWFW_SYNC;
3557 goto out;
3558 }
3559
3560 fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
3561 fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
3562 fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
3563 fw_cmd.port_num = (u8)hw->bus.func;
3564 fw_cmd.ver_maj = maj;
3565 fw_cmd.ver_min = min;
3566 fw_cmd.ver_build = build;
3567 fw_cmd.ver_sub = sub;
3568 fw_cmd.hdr.checksum = 0;
3569 fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
3570 (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
3571 fw_cmd.pad = 0;
3572 fw_cmd.pad2 = 0;
3573
3574 for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
Emil Tantilov79488c52011-10-11 08:24:57 +00003575 ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
Emil Tantilov9612de92011-05-07 07:40:20 +00003576 sizeof(fw_cmd));
3577 if (ret_val != 0)
3578 continue;
3579
3580 if (fw_cmd.hdr.cmd_or_resp.ret_status ==
3581 FW_CEM_RESP_STATUS_SUCCESS)
3582 ret_val = 0;
3583 else
3584 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3585
3586 break;
3587 }
3588
3589 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
3590out:
3591 return ret_val;
3592}
Emil Tantilovff9d1a52011-08-16 04:35:11 +00003593
3594/**
3595 * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
3596 * @hw: pointer to the hardware structure
3597 *
3598 * The 82599 and x540 MACs can experience issues if TX work is still pending
3599 * when a reset occurs. This function prevents this by flushing the PCIe
3600 * buffers on the system.
3601 **/
3602void ixgbe_clear_tx_pending(struct ixgbe_hw *hw)
3603{
3604 u32 gcr_ext, hlreg0;
3605
3606 /*
3607 * If double reset is not requested then all transactions should
3608 * already be clear and as such there is no work to do
3609 */
3610 if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
3611 return;
3612
3613 /*
3614 * Set loopback enable to prevent any transmits from being sent
3615 * should the link come up. This assumes that the RXCTRL.RXEN bit
3616 * has already been cleared.
3617 */
3618 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3619 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK);
3620
3621 /* initiate cleaning flow for buffers in the PCIe transaction layer */
3622 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3623 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT,
3624 gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR);
3625
3626 /* Flush all writes and allow 20usec for all transactions to clear */
3627 IXGBE_WRITE_FLUSH(hw);
3628 udelay(20);
3629
3630 /* restore previous register values */
3631 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3632 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3633}
Don Skidmoree1ea9152012-02-17 02:38:58 +00003634
3635static const u8 ixgbe_emc_temp_data[4] = {
3636 IXGBE_EMC_INTERNAL_DATA,
3637 IXGBE_EMC_DIODE1_DATA,
3638 IXGBE_EMC_DIODE2_DATA,
3639 IXGBE_EMC_DIODE3_DATA
3640};
3641static const u8 ixgbe_emc_therm_limit[4] = {
3642 IXGBE_EMC_INTERNAL_THERM_LIMIT,
3643 IXGBE_EMC_DIODE1_THERM_LIMIT,
3644 IXGBE_EMC_DIODE2_THERM_LIMIT,
3645 IXGBE_EMC_DIODE3_THERM_LIMIT
3646};
3647
3648/**
3649 * ixgbe_get_ets_data - Extracts the ETS bit data
3650 * @hw: pointer to hardware structure
3651 * @ets_cfg: extected ETS data
3652 * @ets_offset: offset of ETS data
3653 *
3654 * Returns error code.
3655 **/
3656static s32 ixgbe_get_ets_data(struct ixgbe_hw *hw, u16 *ets_cfg,
3657 u16 *ets_offset)
3658{
3659 s32 status = 0;
3660
3661 status = hw->eeprom.ops.read(hw, IXGBE_ETS_CFG, ets_offset);
3662 if (status)
3663 goto out;
3664
3665 if ((*ets_offset == 0x0000) || (*ets_offset == 0xFFFF)) {
3666 status = IXGBE_NOT_IMPLEMENTED;
3667 goto out;
3668 }
3669
3670 status = hw->eeprom.ops.read(hw, *ets_offset, ets_cfg);
3671 if (status)
3672 goto out;
3673
3674 if ((*ets_cfg & IXGBE_ETS_TYPE_MASK) != IXGBE_ETS_TYPE_EMC_SHIFTED) {
3675 status = IXGBE_NOT_IMPLEMENTED;
3676 goto out;
3677 }
3678
3679out:
3680 return status;
3681}
3682
3683/**
3684 * ixgbe_get_thermal_sensor_data - Gathers thermal sensor data
3685 * @hw: pointer to hardware structure
3686 *
3687 * Returns the thermal sensor data structure
3688 **/
3689s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw)
3690{
3691 s32 status = 0;
3692 u16 ets_offset;
3693 u16 ets_cfg;
3694 u16 ets_sensor;
3695 u8 num_sensors;
3696 u8 i;
3697 struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
3698
Don Skidmore3ca8bc62012-04-12 00:33:31 +00003699 /* Only support thermal sensors attached to physical port 0 */
3700 if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) {
Don Skidmoree1ea9152012-02-17 02:38:58 +00003701 status = IXGBE_NOT_IMPLEMENTED;
3702 goto out;
3703 }
3704
3705 status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset);
3706 if (status)
3707 goto out;
3708
3709 num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
3710 if (num_sensors > IXGBE_MAX_SENSORS)
3711 num_sensors = IXGBE_MAX_SENSORS;
3712
3713 for (i = 0; i < num_sensors; i++) {
3714 u8 sensor_index;
3715 u8 sensor_location;
3716
3717 status = hw->eeprom.ops.read(hw, (ets_offset + 1 + i),
3718 &ets_sensor);
3719 if (status)
3720 goto out;
3721
3722 sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
3723 IXGBE_ETS_DATA_INDEX_SHIFT);
3724 sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
3725 IXGBE_ETS_DATA_LOC_SHIFT);
3726
3727 if (sensor_location != 0) {
3728 status = hw->phy.ops.read_i2c_byte(hw,
3729 ixgbe_emc_temp_data[sensor_index],
3730 IXGBE_I2C_THERMAL_SENSOR_ADDR,
3731 &data->sensor[i].temp);
3732 if (status)
3733 goto out;
3734 }
3735 }
3736out:
3737 return status;
3738}
3739
3740/**
3741 * ixgbe_init_thermal_sensor_thresh_generic - Inits thermal sensor thresholds
3742 * @hw: pointer to hardware structure
3743 *
3744 * Inits the thermal sensor thresholds according to the NVM map
3745 * and save off the threshold and location values into mac.thermal_sensor_data
3746 **/
3747s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw)
3748{
3749 s32 status = 0;
3750 u16 ets_offset;
3751 u16 ets_cfg;
3752 u16 ets_sensor;
3753 u8 low_thresh_delta;
3754 u8 num_sensors;
3755 u8 therm_limit;
3756 u8 i;
3757 struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
3758
3759 memset(data, 0, sizeof(struct ixgbe_thermal_sensor_data));
3760
Don Skidmore3ca8bc62012-04-12 00:33:31 +00003761 /* Only support thermal sensors attached to physical port 0 */
3762 if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) {
Don Skidmoree1ea9152012-02-17 02:38:58 +00003763 status = IXGBE_NOT_IMPLEMENTED;
3764 goto out;
3765 }
3766
3767 status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset);
3768 if (status)
3769 goto out;
3770
3771 low_thresh_delta = ((ets_cfg & IXGBE_ETS_LTHRES_DELTA_MASK) >>
3772 IXGBE_ETS_LTHRES_DELTA_SHIFT);
3773 num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
3774 if (num_sensors > IXGBE_MAX_SENSORS)
3775 num_sensors = IXGBE_MAX_SENSORS;
3776
3777 for (i = 0; i < num_sensors; i++) {
3778 u8 sensor_index;
3779 u8 sensor_location;
3780
3781 hw->eeprom.ops.read(hw, (ets_offset + 1 + i), &ets_sensor);
3782 sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
3783 IXGBE_ETS_DATA_INDEX_SHIFT);
3784 sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
3785 IXGBE_ETS_DATA_LOC_SHIFT);
3786 therm_limit = ets_sensor & IXGBE_ETS_DATA_HTHRESH_MASK;
3787
3788 hw->phy.ops.write_i2c_byte(hw,
3789 ixgbe_emc_therm_limit[sensor_index],
3790 IXGBE_I2C_THERMAL_SENSOR_ADDR, therm_limit);
3791
3792 if (sensor_location == 0)
3793 continue;
3794
3795 data->sensor[i].location = sensor_location;
3796 data->sensor[i].caution_thresh = therm_limit;
3797 data->sensor[i].max_op_thresh = therm_limit - low_thresh_delta;
3798 }
3799out:
3800 return status;
3801}
3802