blob: 94538624c103d586d38e8dab8c0ad677d3f8a441 [file] [log] [blame]
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001/*
2 * Agere Systems Inc.
3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4 *
Alan Cox64f93032009-06-10 17:30:41 +01005 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07006 * All rights reserved.
7 * http://www.agere.com
8 *
9 *------------------------------------------------------------------------------
10 *
11 * et1310_eeprom.c - Code used to access the device's EEPROM
12 *
13 *------------------------------------------------------------------------------
14 *
15 * SOFTWARE LICENSE
16 *
17 * This software is provided subject to the following terms and conditions,
18 * which you should read carefully before using the software. Using this
19 * software indicates your acceptance of these terms and conditions. If you do
20 * not agree with these terms and conditions, do not use the software.
21 *
Alan Cox64f93032009-06-10 17:30:41 +010022 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070023 * All rights reserved.
24 *
25 * Redistribution and use in source or binary forms, with or without
26 * modifications, are permitted provided that the following conditions are met:
27 *
28 * . Redistributions of source code must retain the above copyright notice, this
29 * list of conditions and the following Disclaimer as comments in the code as
30 * well as in the documentation and/or other materials provided with the
31 * distribution.
32 *
33 * . Redistributions in binary form must reproduce the above copyright notice,
34 * this list of conditions and the following Disclaimer in the documentation
35 * and/or other materials provided with the distribution.
36 *
37 * . Neither the name of Agere Systems Inc. nor the names of the contributors
38 * may be used to endorse or promote products derived from this software
39 * without specific prior written permission.
40 *
41 * Disclaimer
42 *
Alan Cox64f93032009-06-10 17:30:41 +010043 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070044 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
45 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
46 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
47 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
48 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
54 * DAMAGE.
55 *
56 */
57
58#include "et131x_version.h"
59#include "et131x_debug.h"
60#include "et131x_defs.h"
61
62#include <linux/pci.h>
63#include <linux/init.h>
64#include <linux/module.h>
65#include <linux/types.h>
66#include <linux/kernel.h>
67
68#include <linux/sched.h>
69#include <linux/ptrace.h>
70#include <linux/slab.h>
71#include <linux/ctype.h>
72#include <linux/string.h>
73#include <linux/timer.h>
74#include <linux/interrupt.h>
75#include <linux/in.h>
76#include <linux/delay.h>
Alan Cox64f93032009-06-10 17:30:41 +010077#include <linux/bitops.h>
78#include <linux/io.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070079#include <asm/system.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070080
81#include <linux/netdevice.h>
82#include <linux/etherdevice.h>
83#include <linux/skbuff.h>
84#include <linux/if_arp.h>
85#include <linux/ioport.h>
86
87#include "et1310_phy.h"
88#include "et1310_pm.h"
89#include "et1310_jagcore.h"
90#include "et1310_eeprom.h"
91
92#include "et131x_adapter.h"
93#include "et131x_initpci.h"
94#include "et131x_isr.h"
95
96#include "et1310_tx.h"
97
98
99/*
100 * EEPROM Defines
101 */
102
103/* LBCIF Register Groups (addressed via 32-bit offsets) */
104#define LBCIF_DWORD0_GROUP_OFFSET 0xAC
105#define LBCIF_DWORD1_GROUP_OFFSET 0xB0
106
107/* LBCIF Registers (addressed via 8-bit offsets) */
108#define LBCIF_ADDRESS_REGISTER_OFFSET 0xAC
109#define LBCIF_DATA_REGISTER_OFFSET 0xB0
110#define LBCIF_CONTROL_REGISTER_OFFSET 0xB1
111#define LBCIF_STATUS_REGISTER_OFFSET 0xB2
112
113/* LBCIF Control Register Bits */
114#define LBCIF_CONTROL_SEQUENTIAL_READ 0x01
115#define LBCIF_CONTROL_PAGE_WRITE 0x02
116#define LBCIF_CONTROL_UNUSED1 0x04
117#define LBCIF_CONTROL_EEPROM_RELOAD 0x08
118#define LBCIF_CONTROL_UNUSED2 0x10
119#define LBCIF_CONTROL_TWO_BYTE_ADDR 0x20
120#define LBCIF_CONTROL_I2C_WRITE 0x40
121#define LBCIF_CONTROL_LBCIF_ENABLE 0x80
122
123/* LBCIF Status Register Bits */
124#define LBCIF_STATUS_PHY_QUEUE_AVAIL 0x01
125#define LBCIF_STATUS_I2C_IDLE 0x02
126#define LBCIF_STATUS_ACK_ERROR 0x04
127#define LBCIF_STATUS_GENERAL_ERROR 0x08
128#define LBCIF_STATUS_UNUSED 0x30
129#define LBCIF_STATUS_CHECKSUM_ERROR 0x40
130#define LBCIF_STATUS_EEPROM_PRESENT 0x80
131
132/* Miscellaneous Constraints */
133#define MAX_NUM_REGISTER_POLLS 1000
134#define MAX_NUM_WRITE_RETRIES 2
135
136/*
137 * Define macros that allow individual register values to be extracted from a
138 * DWORD1 register grouping
139 */
Alan Cox9fa81092009-08-27 11:00:36 +0100140#define EXTRACT_DATA_REGISTER(x) (u8)(x & 0xFF)
141#define EXTRACT_STATUS_REGISTER(x) (u8)((x >> 16) & 0xFF)
142#define EXTRACT_CONTROL_REG(x) (u8)((x >> 8) & 0xFF)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700143
144/**
145 * EepromWriteByte - Write a byte to the ET1310's EEPROM
Alan Cox25ad00b2009-08-19 18:21:44 +0100146 * @etdev: pointer to our private adapter structure
Alan Cox9fa81092009-08-27 11:00:36 +0100147 * @addr: the address to write
148 * @data: the value to write
149 * @eeprom_id: the ID of the EEPROM
150 * @addrmode: how the EEPROM is to be accessed
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700151 *
152 * Returns SUCCESS or FAILURE
153 */
Alan Cox9fa81092009-08-27 11:00:36 +0100154int EepromWriteByte(struct et131x_adapter *etdev, u32 addr,
155 u8 data, u32 eeprom_id,
156 u32 addrmode)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700157{
Alan Cox25ad00b2009-08-19 18:21:44 +0100158 struct pci_dev *pdev = etdev->pdev;
Alan Cox9fa81092009-08-27 11:00:36 +0100159 int index;
160 int retries;
161 int err = 0;
162 int i2c_wack = 0;
163 int writeok = 0;
164 u8 control;
165 u8 status = 0;
166 u32 dword1 = 0;
167 u32 val = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700168
169 /*
170 * The following excerpt is from "Serial EEPROM HW Design
171 * Specification" Version 0.92 (9/20/2004):
172 *
173 * Single Byte Writes
174 *
175 * For an EEPROM, an I2C single byte write is defined as a START
176 * condition followed by the device address, EEPROM address, one byte
177 * of data and a STOP condition. The STOP condition will trigger the
178 * EEPROM's internally timed write cycle to the nonvolatile memory.
179 * All inputs are disabled during this write cycle and the EEPROM will
180 * not respond to any access until the internal write is complete.
181 * The steps to execute a single byte write are as follows:
182 *
183 * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and
184 * bits 7,1:0 both equal to 1, at least once after reset.
185 * Subsequent operations need only to check that bits 1:0 are
186 * equal to 1 prior to starting a single byte write.
187 *
188 * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0,
189 * and bits 1:0 both =0. Bit 5 should be set according to the
190 * type of EEPROM being accessed (1=two byte addressing, 0=one
191 * byte addressing).
192 *
193 * 3. Write the address to the LBCIF Address Register.
194 *
195 * 4. Write the data to the LBCIF Data Register (the I2C write will
196 * begin).
197 *
198 * 5. Monitor bit 1:0 of the LBCIF Status Register. When bits 1:0 are
199 * both equal to 1, the I2C write has completed and the internal
200 * write cycle of the EEPROM is about to start. (bits 1:0 = 01 is
201 * a legal state while waiting from both equal to 1, but bits
202 * 1:0 = 10 is invalid and implies that something is broken).
203 *
204 * 6. Check bit 3 of the LBCIF Status Register. If equal to 1, an
205 * error has occurred.
206 *
207 * 7. Check bit 2 of the LBCIF Status Register. If equal to 1 an ACK
208 * error has occurred on the address phase of the write. This
209 * could be due to an actual hardware failure or the EEPROM may
210 * still be in its internal write cycle from a previous write.
211 * This write operation was ignored and must be repeated later.
212 *
213 * 8. Set bit 6 of the LBCIF Control Register = 0. If another write is
214 * required, go to step 1.
215 */
216
217 /* Step 1: */
Alan Cox9fa81092009-08-27 11:00:36 +0100218 for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700219 /* Read registers grouped in DWORD1 */
220 if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100221 &dword1)) {
222 err = 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700223 break;
224 }
225
Alan Cox9fa81092009-08-27 11:00:36 +0100226 status = EXTRACT_STATUS_REGISTER(dword1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700227
Alan Cox9fa81092009-08-27 11:00:36 +0100228 if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL &&
229 status & LBCIF_STATUS_I2C_IDLE)
Alan Cox64f93032009-06-10 17:30:41 +0100230 /* bits 1:0 are equal to 1 */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700231 break;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700232 }
233
Alan Cox9fa81092009-08-27 11:00:36 +0100234 if (err || (index >= MAX_NUM_REGISTER_POLLS))
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700235 return FAILURE;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700236
237 /* Step 2: */
Alan Cox9fa81092009-08-27 11:00:36 +0100238 control = 0;
239 control |= LBCIF_CONTROL_LBCIF_ENABLE | LBCIF_CONTROL_I2C_WRITE;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700240
Alan Cox9fa81092009-08-27 11:00:36 +0100241 if (addrmode == DUAL_BYTE)
242 control |= LBCIF_CONTROL_TWO_BYTE_ADDR;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700243
244 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100245 control)) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700246 return FAILURE;
247 }
248
Alan Cox9fa81092009-08-27 11:00:36 +0100249 i2c_wack = 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700250
251 /* Prepare EEPROM address for Step 3 */
Alan Cox9fa81092009-08-27 11:00:36 +0100252 addr |= (addrmode == DUAL_BYTE) ?
253 (eeprom_id << 16) : (eeprom_id << 8);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700254
Alan Cox9fa81092009-08-27 11:00:36 +0100255 for (retries = 0; retries < MAX_NUM_WRITE_RETRIES; retries++) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700256 /* Step 3:*/
257 if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100258 addr)) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700259 break;
260 }
261
262 /* Step 4: */
263 if (pci_write_config_byte(pdev, LBCIF_DATA_REGISTER_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100264 data)) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700265 break;
266 }
267
268 /* Step 5: */
Alan Cox9fa81092009-08-27 11:00:36 +0100269 for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700270 /* Read registers grouped in DWORD1 */
271 if (pci_read_config_dword(pdev,
272 LBCIF_DWORD1_GROUP_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100273 &dword1)) {
274 err = 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700275 break;
276 }
277
Alan Cox9fa81092009-08-27 11:00:36 +0100278 status = EXTRACT_STATUS_REGISTER(dword1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700279
Alan Cox9fa81092009-08-27 11:00:36 +0100280 if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL &&
281 status & LBCIF_STATUS_I2C_IDLE) {
Alan Cox64f93032009-06-10 17:30:41 +0100282 /* I2C write complete */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700283 break;
284 }
285 }
286
Alan Cox9fa81092009-08-27 11:00:36 +0100287 if (err || (index >= MAX_NUM_REGISTER_POLLS))
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700288 break;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700289
290 /*
291 * Step 6: Don't break here if we are revision 1, this is
292 * so we do a blind write for load bug.
Alan Cox64f93032009-06-10 17:30:41 +0100293 */
Alan Cox9fa81092009-08-27 11:00:36 +0100294 if (status & LBCIF_STATUS_GENERAL_ERROR
Alan Cox5ec34872009-08-27 10:59:13 +0100295 && etdev->pdev->revision == 0) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700296 break;
297 }
298
299 /* Step 7 */
Alan Cox9fa81092009-08-27 11:00:36 +0100300 if (status & LBCIF_STATUS_ACK_ERROR) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700301 /*
302 * This could be due to an actual hardware failure
303 * or the EEPROM may still be in its internal write
304 * cycle from a previous write. This write operation
305 * was ignored and must be repeated later.
306 */
307 udelay(10);
308 continue;
309 }
310
Alan Cox9fa81092009-08-27 11:00:36 +0100311 writeok = 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700312 break;
313 }
314
315 /* Step 8: */
316 udelay(10);
Alan Cox9fa81092009-08-27 11:00:36 +0100317 index = 0;
318 while (i2c_wack) {
319 control &= ~LBCIF_CONTROL_I2C_WRITE;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700320
321 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100322 control)) {
323 writeok = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700324 }
325
326 /* Do read until internal ACK_ERROR goes away meaning write
327 * completed
328 */
329 do {
330 pci_write_config_dword(pdev,
331 LBCIF_ADDRESS_REGISTER_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100332 addr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700333 do {
334 pci_read_config_dword(pdev,
Alan Cox9fa81092009-08-27 11:00:36 +0100335 LBCIF_DATA_REGISTER_OFFSET, &val);
336 } while ((val & 0x00010000) == 0);
337 } while (val & 0x00040000);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700338
Alan Cox9fa81092009-08-27 11:00:36 +0100339 control = EXTRACT_CONTROL_REG(val);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700340
Alan Cox9fa81092009-08-27 11:00:36 +0100341 if (control != 0xC0 || index == 10000)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700342 break;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700343
Alan Cox9fa81092009-08-27 11:00:36 +0100344 index++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700345 }
346
Alan Cox9fa81092009-08-27 11:00:36 +0100347 return writeok ? SUCCESS : FAILURE;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700348}
349
350/**
351 * EepromReadByte - Read a byte from the ET1310's EEPROM
Alan Cox25ad00b2009-08-19 18:21:44 +0100352 * @etdev: pointer to our private adapter structure
Alan Cox9fa81092009-08-27 11:00:36 +0100353 * @addr: the address from which to read
354 * @pdata: a pointer to a byte in which to store the value of the read
355 * @eeprom_id: the ID of the EEPROM
356 * @addrmode: how the EEPROM is to be accessed
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700357 *
358 * Returns SUCCESS or FAILURE
359 */
Alan Cox9fa81092009-08-27 11:00:36 +0100360int EepromReadByte(struct et131x_adapter *etdev, u32 addr,
361 u8 *pdata, u32 eeprom_id,
362 u32 addrmode)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700363{
Alan Cox25ad00b2009-08-19 18:21:44 +0100364 struct pci_dev *pdev = etdev->pdev;
Alan Cox9fa81092009-08-27 11:00:36 +0100365 int index;
366 int err = 0;
367 u8 control;
368 u8 status = 0;
369 u32 dword1 = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700370
371 /*
372 * The following excerpt is from "Serial EEPROM HW Design
373 * Specification" Version 0.92 (9/20/2004):
374 *
375 * Single Byte Reads
376 *
377 * A single byte read is similar to the single byte write, with the
378 * exception of the data flow:
379 *
380 * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and
381 * bits 7,1:0 both equal to 1, at least once after reset.
382 * Subsequent operations need only to check that bits 1:0 are equal
383 * to 1 prior to starting a single byte read.
384 *
385 * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0,
386 * and bits 1:0 both =0. Bit 5 should be set according to the type
387 * of EEPROM being accessed (1=two byte addressing, 0=one byte
388 * addressing).
389 *
390 * 3. Write the address to the LBCIF Address Register (I2C read will
391 * begin).
392 *
393 * 4. Monitor bit 0 of the LBCIF Status Register. When =1, I2C read
394 * is complete. (if bit 1 =1 and bit 0 stays =0, a hardware failure
395 * has occurred).
396 *
397 * 5. Check bit 2 of the LBCIF Status Register. If =1, then an error
398 * has occurred. The data that has been returned from the PHY may
399 * be invalid.
400 *
401 * 6. Regardless of error status, read data byte from LBCIF Data
402 * Register. If another byte is required, go to step 1.
403 */
404
405 /* Step 1: */
Alan Cox9fa81092009-08-27 11:00:36 +0100406 for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700407 /* Read registers grouped in DWORD1 */
408 if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100409 &dword1)) {
410 err = 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700411 break;
412 }
413
Alan Cox9fa81092009-08-27 11:00:36 +0100414 status = EXTRACT_STATUS_REGISTER(dword1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700415
Alan Cox9fa81092009-08-27 11:00:36 +0100416 if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL &&
417 status & LBCIF_STATUS_I2C_IDLE) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700418 /* bits 1:0 are equal to 1 */
419 break;
420 }
421 }
422
Alan Cox9fa81092009-08-27 11:00:36 +0100423 if (err || (index >= MAX_NUM_REGISTER_POLLS))
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700424 return FAILURE;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700425
426 /* Step 2: */
Alan Cox9fa81092009-08-27 11:00:36 +0100427 control = 0;
428 control |= LBCIF_CONTROL_LBCIF_ENABLE;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700429
Alan Cox9fa81092009-08-27 11:00:36 +0100430 if (addrmode == DUAL_BYTE)
431 control |= LBCIF_CONTROL_TWO_BYTE_ADDR;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700432
433 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100434 control)) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700435 return FAILURE;
436 }
437
438 /* Step 3: */
Alan Cox9fa81092009-08-27 11:00:36 +0100439 addr |= (addrmode == DUAL_BYTE) ?
440 (eeprom_id << 16) : (eeprom_id << 8);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700441
442 if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100443 addr)) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700444 return FAILURE;
445 }
446
447 /* Step 4: */
Alan Cox9fa81092009-08-27 11:00:36 +0100448 for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700449 /* Read registers grouped in DWORD1 */
450 if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET,
Alan Cox9fa81092009-08-27 11:00:36 +0100451 &dword1)) {
452 err = 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700453 break;
454 }
455
Alan Cox9fa81092009-08-27 11:00:36 +0100456 status = EXTRACT_STATUS_REGISTER(dword1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700457
Alan Cox9fa81092009-08-27 11:00:36 +0100458 if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL
459 && status & LBCIF_STATUS_I2C_IDLE) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700460 /* I2C read complete */
461 break;
462 }
463 }
464
Alan Cox9fa81092009-08-27 11:00:36 +0100465 if (err || (index >= MAX_NUM_REGISTER_POLLS))
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700466 return FAILURE;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700467
468 /* Step 6: */
Alan Cox9fa81092009-08-27 11:00:36 +0100469 *pdata = EXTRACT_DATA_REGISTER(dword1);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700470
Alan Cox9fa81092009-08-27 11:00:36 +0100471 return (status & LBCIF_STATUS_ACK_ERROR) ? FAILURE : SUCCESS;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700472}