blob: eca216b9b859b623d4db03e6ea8987f3e5c8bada [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/10GbE Linux driver
Jesse Brandeburgf731a9e2008-07-08 15:53:09 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kok0abb6eb2006-09-27 12:53:14 -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
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok0abb6eb2006-09-27 12:53:14 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Joe Perchesd328bc82010-04-27 00:50:58 +000029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "ixgb_hw.h"
32#include "ixgb_ee.h"
33/* Local prototypes */
Joe Perches222441a2008-04-03 10:06:25 -070034static u16 ixgb_shift_in_bits(struct ixgb_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static void ixgb_shift_out_bits(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -070037 u16 data,
38 u16 count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static void ixgb_standby_eeprom(struct ixgb_hw *hw);
40
Joe Perches446490c2008-03-21 11:06:37 -070041static bool ixgb_wait_eeprom_command(struct ixgb_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43static void ixgb_cleanup_eeprom(struct ixgb_hw *hw);
44
45/******************************************************************************
46 * Raises the EEPROM's clock input.
47 *
48 * hw - Struct containing variables accessed by shared code
49 * eecd_reg - EECD's current value
50 *****************************************************************************/
51static void
52ixgb_raise_clock(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -070053 u32 *eecd_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
56 * wait 50 microseconds.
57 */
58 *eecd_reg = *eecd_reg | IXGB_EECD_SK;
59 IXGB_WRITE_REG(hw, EECD, *eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +000060 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 udelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
64/******************************************************************************
65 * Lowers the EEPROM's clock input.
66 *
67 * hw - Struct containing variables accessed by shared code
68 * eecd_reg - EECD's current value
69 *****************************************************************************/
70static void
71ixgb_lower_clock(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -070072 u32 *eecd_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
75 * wait 50 microseconds.
76 */
77 *eecd_reg = *eecd_reg & ~IXGB_EECD_SK;
78 IXGB_WRITE_REG(hw, EECD, *eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +000079 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 udelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
83/******************************************************************************
84 * Shift data bits out to the EEPROM.
85 *
86 * hw - Struct containing variables accessed by shared code
87 * data - data to send to the EEPROM
88 * count - number of bits to shift out
89 *****************************************************************************/
90static void
91ixgb_shift_out_bits(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -070092 u16 data,
93 u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Joe Perches222441a2008-04-03 10:06:25 -070095 u32 eecd_reg;
96 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 /* We need to shift "count" bits out to the EEPROM. So, value in the
99 * "data" parameter will be shifted out to the EEPROM one bit at a time.
100 * In order to do this, "data" must be broken down into bits.
101 */
102 mask = 0x01 << (count - 1);
103 eecd_reg = IXGB_READ_REG(hw, EECD);
104 eecd_reg &= ~(IXGB_EECD_DO | IXGB_EECD_DI);
105 do {
106 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
107 * and then raising and then lowering the clock (the SK bit controls
108 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
109 * by setting "DI" to "0" and then raising and then lowering the clock.
110 */
111 eecd_reg &= ~IXGB_EECD_DI;
112
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700113 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 eecd_reg |= IXGB_EECD_DI;
115
116 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000117 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 udelay(50);
120
121 ixgb_raise_clock(hw, &eecd_reg);
122 ixgb_lower_clock(hw, &eecd_reg);
123
124 mask = mask >> 1;
125
Jesse Brandeburg9a432992008-07-08 15:52:18 -0700126 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /* We leave the "DI" bit set to "0" when we leave this routine. */
129 eecd_reg &= ~IXGB_EECD_DI;
130 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133/******************************************************************************
134 * Shift data bits in from the EEPROM
135 *
136 * hw - Struct containing variables accessed by shared code
137 *****************************************************************************/
Joe Perches222441a2008-04-03 10:06:25 -0700138static u16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139ixgb_shift_in_bits(struct ixgb_hw *hw)
140{
Joe Perches222441a2008-04-03 10:06:25 -0700141 u32 eecd_reg;
142 u32 i;
143 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* In order to read a register from the EEPROM, we need to shift 16 bits
146 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
147 * the EEPROM (setting the SK bit), and then reading the value of the "DO"
148 * bit. During this "shifting in" process the "DI" bit should always be
149 * clear..
150 */
151
152 eecd_reg = IXGB_READ_REG(hw, EECD);
153
154 eecd_reg &= ~(IXGB_EECD_DO | IXGB_EECD_DI);
155 data = 0;
156
Jesse Brandeburg14593362008-07-08 15:52:33 -0700157 for (i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 data = data << 1;
159 ixgb_raise_clock(hw, &eecd_reg);
160
161 eecd_reg = IXGB_READ_REG(hw, EECD);
162
163 eecd_reg &= ~(IXGB_EECD_DI);
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700164 if (eecd_reg & IXGB_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 data |= 1;
166
167 ixgb_lower_clock(hw, &eecd_reg);
168 }
169
170 return data;
171}
172
173/******************************************************************************
174 * Prepares EEPROM for access
175 *
176 * hw - Struct containing variables accessed by shared code
177 *
178 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
179 * function should be called before issuing a command to the EEPROM.
180 *****************************************************************************/
181static void
182ixgb_setup_eeprom(struct ixgb_hw *hw)
183{
Joe Perches222441a2008-04-03 10:06:25 -0700184 u32 eecd_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 eecd_reg = IXGB_READ_REG(hw, EECD);
187
188 /* Clear SK and DI */
189 eecd_reg &= ~(IXGB_EECD_SK | IXGB_EECD_DI);
190 IXGB_WRITE_REG(hw, EECD, eecd_reg);
191
192 /* Set CS */
193 eecd_reg |= IXGB_EECD_CS;
194 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
197/******************************************************************************
198 * Returns EEPROM to a "standby" state
199 *
200 * hw - Struct containing variables accessed by shared code
201 *****************************************************************************/
202static void
203ixgb_standby_eeprom(struct ixgb_hw *hw)
204{
Joe Perches222441a2008-04-03 10:06:25 -0700205 u32 eecd_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 eecd_reg = IXGB_READ_REG(hw, EECD);
208
Jesse Brandeburg52035bd2008-07-08 15:52:28 -0700209 /* Deselect EEPROM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 eecd_reg &= ~(IXGB_EECD_CS | IXGB_EECD_SK);
211 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000212 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 udelay(50);
214
215 /* Clock high */
216 eecd_reg |= IXGB_EECD_SK;
217 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000218 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 udelay(50);
220
221 /* Select EEPROM */
222 eecd_reg |= IXGB_EECD_CS;
223 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000224 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 udelay(50);
226
227 /* Clock low */
228 eecd_reg &= ~IXGB_EECD_SK;
229 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000230 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 udelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
234/******************************************************************************
235 * Raises then lowers the EEPROM's clock pin
236 *
237 * hw - Struct containing variables accessed by shared code
238 *****************************************************************************/
239static void
240ixgb_clock_eeprom(struct ixgb_hw *hw)
241{
Joe Perches222441a2008-04-03 10:06:25 -0700242 u32 eecd_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 eecd_reg = IXGB_READ_REG(hw, EECD);
245
246 /* Rising edge of clock */
247 eecd_reg |= IXGB_EECD_SK;
248 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000249 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 udelay(50);
251
252 /* Falling edge of clock */
253 eecd_reg &= ~IXGB_EECD_SK;
254 IXGB_WRITE_REG(hw, EECD, eecd_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000255 IXGB_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 udelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
259/******************************************************************************
260 * Terminates a command by lowering the EEPROM's chip select pin
261 *
262 * hw - Struct containing variables accessed by shared code
263 *****************************************************************************/
264static void
265ixgb_cleanup_eeprom(struct ixgb_hw *hw)
266{
Joe Perches222441a2008-04-03 10:06:25 -0700267 u32 eecd_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 eecd_reg = IXGB_READ_REG(hw, EECD);
270
271 eecd_reg &= ~(IXGB_EECD_CS | IXGB_EECD_DI);
272
273 IXGB_WRITE_REG(hw, EECD, eecd_reg);
274
275 ixgb_clock_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
278/******************************************************************************
279 * Waits for the EEPROM to finish the current command.
280 *
281 * hw - Struct containing variables accessed by shared code
282 *
283 * The command is done when the EEPROM's data out pin goes high.
284 *
285 * Returns:
Joe Perches446490c2008-03-21 11:06:37 -0700286 * true: EEPROM data pin is high before timeout.
287 * false: Time expired.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700289static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290ixgb_wait_eeprom_command(struct ixgb_hw *hw)
291{
Joe Perches222441a2008-04-03 10:06:25 -0700292 u32 eecd_reg;
293 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 /* Toggle the CS line. This in effect tells to EEPROM to actually execute
296 * the command in question.
297 */
298 ixgb_standby_eeprom(hw);
299
Jesse Brandeburg52035bd2008-07-08 15:52:28 -0700300 /* Now read DO repeatedly until is high (equal to '1'). The EEPROM will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 * signal that the command has been completed by raising the DO signal.
302 * If DO does not go high in 10 milliseconds, then error out.
303 */
Jesse Brandeburg14593362008-07-08 15:52:33 -0700304 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 eecd_reg = IXGB_READ_REG(hw, EECD);
306
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700307 if (eecd_reg & IXGB_EECD_DO)
Eric Dumazet807540b2010-09-23 05:40:09 +0000308 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 udelay(50);
311 }
312 ASSERT(0);
Eric Dumazet807540b2010-09-23 05:40:09 +0000313 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
316/******************************************************************************
317 * Verifies that the EEPROM has a valid checksum
318 *
319 * hw - Struct containing variables accessed by shared code
320 *
321 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
Michael Opdenacker59c51592007-05-09 08:57:56 +0200322 * If the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 * valid.
324 *
325 * Returns:
Joe Perches446490c2008-03-21 11:06:37 -0700326 * true: Checksum is valid
327 * false: Checksum is not valid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700329bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330ixgb_validate_eeprom_checksum(struct ixgb_hw *hw)
331{
Joe Perches222441a2008-04-03 10:06:25 -0700332 u16 checksum = 0;
333 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Jesse Brandeburg14593362008-07-08 15:52:33 -0700335 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 checksum += ixgb_read_eeprom(hw, i);
337
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700338 if (checksum == (u16) EEPROM_SUM)
Eric Dumazet807540b2010-09-23 05:40:09 +0000339 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 else
Eric Dumazet807540b2010-09-23 05:40:09 +0000341 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
344/******************************************************************************
345 * Calculates the EEPROM checksum and writes it to the EEPROM
346 *
347 * hw - Struct containing variables accessed by shared code
348 *
349 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
350 * Writes the difference to word offset 63 of the EEPROM.
351 *****************************************************************************/
352void
353ixgb_update_eeprom_checksum(struct ixgb_hw *hw)
354{
Joe Perches222441a2008-04-03 10:06:25 -0700355 u16 checksum = 0;
356 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Jesse Brandeburg14593362008-07-08 15:52:33 -0700358 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 checksum += ixgb_read_eeprom(hw, i);
360
Joe Perches222441a2008-04-03 10:06:25 -0700361 checksum = (u16) EEPROM_SUM - checksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 ixgb_write_eeprom(hw, EEPROM_CHECKSUM_REG, checksum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
366/******************************************************************************
367 * Writes a 16 bit word to a given offset in the EEPROM.
368 *
369 * hw - Struct containing variables accessed by shared code
370 * reg - offset within the EEPROM to be written to
Jesse Brandeburg52035bd2008-07-08 15:52:28 -0700371 * data - 16 bit word to be written to the EEPROM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 *
373 * If ixgb_update_eeprom_checksum is not called after this function, the
374 * EEPROM will most likely contain an invalid checksum.
375 *
376 *****************************************************************************/
377void
Joe Perches222441a2008-04-03 10:06:25 -0700378ixgb_write_eeprom(struct ixgb_hw *hw, u16 offset, u16 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
380 struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
381
382 /* Prepare the EEPROM for writing */
383 ixgb_setup_eeprom(hw);
384
385 /* Send the 9-bit EWEN (write enable) command to the EEPROM (5-bit opcode
386 * plus 4-bit dummy). This puts the EEPROM into write/erase mode.
387 */
388 ixgb_shift_out_bits(hw, EEPROM_EWEN_OPCODE, 5);
389 ixgb_shift_out_bits(hw, 0, 4);
390
391 /* Prepare the EEPROM */
392 ixgb_standby_eeprom(hw);
393
394 /* Send the Write command (3-bit opcode + 6-bit addr) */
395 ixgb_shift_out_bits(hw, EEPROM_WRITE_OPCODE, 3);
396 ixgb_shift_out_bits(hw, offset, 6);
397
398 /* Send the data */
399 ixgb_shift_out_bits(hw, data, 16);
400
401 ixgb_wait_eeprom_command(hw);
402
403 /* Recover from write */
404 ixgb_standby_eeprom(hw);
405
406 /* Send the 9-bit EWDS (write disable) command to the EEPROM (5-bit
407 * opcode plus 4-bit dummy). This takes the EEPROM out of write/erase
408 * mode.
409 */
410 ixgb_shift_out_bits(hw, EEPROM_EWDS_OPCODE, 5);
411 ixgb_shift_out_bits(hw, 0, 4);
412
413 /* Done with writing */
414 ixgb_cleanup_eeprom(hw);
415
416 /* clear the init_ctrl_reg_1 to signify that the cache is invalidated */
Al Viroc6765042007-08-23 00:47:03 -0400417 ee_map->init_ctrl_reg_1 = cpu_to_le16(EEPROM_ICW1_SIGNATURE_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
420/******************************************************************************
421 * Reads a 16 bit word from the EEPROM.
422 *
423 * hw - Struct containing variables accessed by shared code
424 * offset - offset of 16 bit word in the EEPROM to read
425 *
426 * Returns:
427 * The 16-bit value read from the eeprom
428 *****************************************************************************/
Joe Perches222441a2008-04-03 10:06:25 -0700429u16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430ixgb_read_eeprom(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700431 u16 offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Joe Perches222441a2008-04-03 10:06:25 -0700433 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 /* Prepare the EEPROM for reading */
436 ixgb_setup_eeprom(hw);
437
438 /* Send the READ command (opcode + addr) */
439 ixgb_shift_out_bits(hw, EEPROM_READ_OPCODE, 3);
440 /*
441 * We have a 64 word EEPROM, there are 6 address bits
442 */
443 ixgb_shift_out_bits(hw, offset, 6);
444
445 /* Read the data */
446 data = ixgb_shift_in_bits(hw);
447
448 /* End this read operation */
449 ixgb_standby_eeprom(hw);
450
Eric Dumazet807540b2010-09-23 05:40:09 +0000451 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
454/******************************************************************************
455 * Reads eeprom and stores data in shared structure.
456 * Validates eeprom checksum and eeprom signature.
457 *
458 * hw - Struct containing variables accessed by shared code
459 *
460 * Returns:
Joe Perches446490c2008-03-21 11:06:37 -0700461 * true: if eeprom read is successful
462 * false: otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 *****************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700464bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465ixgb_get_eeprom_data(struct ixgb_hw *hw)
466{
Joe Perches222441a2008-04-03 10:06:25 -0700467 u16 i;
468 u16 checksum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 struct ixgb_ee_map_type *ee_map;
470
Joe Perchesd328bc82010-04-27 00:50:58 +0000471 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473 ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
474
Joe Perchesd328bc82010-04-27 00:50:58 +0000475 pr_debug("Reading eeprom data\n");
Jesse Brandeburg14593362008-07-08 15:52:33 -0700476 for (i = 0; i < IXGB_EEPROM_SIZE ; i++) {
Joe Perches222441a2008-04-03 10:06:25 -0700477 u16 ee_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 ee_data = ixgb_read_eeprom(hw, i);
479 checksum += ee_data;
Al Viroc6765042007-08-23 00:47:03 -0400480 hw->eeprom[i] = cpu_to_le16(ee_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482
Joe Perches222441a2008-04-03 10:06:25 -0700483 if (checksum != (u16) EEPROM_SUM) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000484 pr_debug("Checksum invalid\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /* clear the init_ctrl_reg_1 to signify that the cache is
486 * invalidated */
Al Viroc6765042007-08-23 00:47:03 -0400487 ee_map->init_ctrl_reg_1 = cpu_to_le16(EEPROM_ICW1_SIGNATURE_CLEAR);
Eric Dumazet807540b2010-09-23 05:40:09 +0000488 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 }
490
Al Viroc6765042007-08-23 00:47:03 -0400491 if ((ee_map->init_ctrl_reg_1 & cpu_to_le16(EEPROM_ICW1_SIGNATURE_MASK))
492 != cpu_to_le16(EEPROM_ICW1_SIGNATURE_VALID)) {
Joe Perchesd328bc82010-04-27 00:50:58 +0000493 pr_debug("Signature invalid\n");
Eric Dumazet807540b2010-09-23 05:40:09 +0000494 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496
Eric Dumazet807540b2010-09-23 05:40:09 +0000497 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498}
499
500/******************************************************************************
501 * Local function to check if the eeprom signature is good
502 * If the eeprom signature is good, calls ixgb)get_eeprom_data.
503 *
504 * hw - Struct containing variables accessed by shared code
505 *
506 * Returns:
Joe Perches446490c2008-03-21 11:06:37 -0700507 * true: eeprom signature was good and the eeprom read was successful
508 * false: otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 ******************************************************************************/
Joe Perches446490c2008-03-21 11:06:37 -0700510static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511ixgb_check_and_get_eeprom_data (struct ixgb_hw* hw)
512{
513 struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
514
Al Viroc6765042007-08-23 00:47:03 -0400515 if ((ee_map->init_ctrl_reg_1 & cpu_to_le16(EEPROM_ICW1_SIGNATURE_MASK))
516 == cpu_to_le16(EEPROM_ICW1_SIGNATURE_VALID)) {
Eric Dumazet807540b2010-09-23 05:40:09 +0000517 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 } else {
519 return ixgb_get_eeprom_data(hw);
520 }
521}
522
523/******************************************************************************
524 * return a word from the eeprom
525 *
526 * hw - Struct containing variables accessed by shared code
527 * index - Offset of eeprom word
528 *
529 * Returns:
530 * Word at indexed offset in eeprom, if valid, 0 otherwise.
531 ******************************************************************************/
Al Viroc6765042007-08-23 00:47:03 -0400532__le16
Joe Perches222441a2008-04-03 10:06:25 -0700533ixgb_get_eeprom_word(struct ixgb_hw *hw, u16 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
535
Joe Perches23677ce2012-02-09 11:17:23 +0000536 if (index < IXGB_EEPROM_SIZE && ixgb_check_and_get_eeprom_data(hw))
537 return hw->eeprom[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Eric Dumazet807540b2010-09-23 05:40:09 +0000539 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
541
542/******************************************************************************
543 * return the mac address from EEPROM
544 *
545 * hw - Struct containing variables accessed by shared code
546 * mac_addr - Ethernet Address if EEPROM contents are valid, 0 otherwise
547 *
548 * Returns: None.
549 ******************************************************************************/
550void
551ixgb_get_ee_mac_addr(struct ixgb_hw *hw,
Joe Perches222441a2008-04-03 10:06:25 -0700552 u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
554 int i;
555 struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
556
Joe Perchesd328bc82010-04-27 00:50:58 +0000557 ENTER();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Joe Perches23677ce2012-02-09 11:17:23 +0000559 if (ixgb_check_and_get_eeprom_data(hw)) {
Jesse Brandeburgac5ac782011-09-23 02:11:29 +0000560 for (i = 0; i < ETH_ALEN; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 mac_addr[i] = ee_map->mac_addr[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
Joe Perchesd328bc82010-04-27 00:50:58 +0000563 pr_debug("eeprom mac address = %pM\n", mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565}
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568/******************************************************************************
569 * return the Printed Board Assembly number from EEPROM
570 *
571 * hw - Struct containing variables accessed by shared code
572 *
573 * Returns:
574 * PBA number if EEPROM contents are valid, 0 otherwise
575 ******************************************************************************/
Joe Perches222441a2008-04-03 10:06:25 -0700576u32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577ixgb_get_ee_pba_number(struct ixgb_hw *hw)
578{
Joe Perches23677ce2012-02-09 11:17:23 +0000579 if (ixgb_check_and_get_eeprom_data(hw))
Eric Dumazet807540b2010-09-23 05:40:09 +0000580 return le16_to_cpu(hw->eeprom[EEPROM_PBA_1_2_REG])
581 | (le16_to_cpu(hw->eeprom[EEPROM_PBA_3_4_REG])<<16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Eric Dumazet807540b2010-09-23 05:40:09 +0000583 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587/******************************************************************************
588 * return the Device Id from EEPROM
589 *
590 * hw - Struct containing variables accessed by shared code
591 *
592 * Returns:
593 * Device Id if EEPROM contents are valid, 0 otherwise
594 ******************************************************************************/
Joe Perches222441a2008-04-03 10:06:25 -0700595u16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596ixgb_get_ee_device_id(struct ixgb_hw *hw)
597{
598 struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
599
Joe Perches23677ce2012-02-09 11:17:23 +0000600 if (ixgb_check_and_get_eeprom_data(hw))
Eric Dumazet807540b2010-09-23 05:40:09 +0000601 return le16_to_cpu(ee_map->device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Eric Dumazet807540b2010-09-23 05:40:09 +0000603 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605