3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
5 * Copyright © 2005 Agere Systems Inc.
9 *------------------------------------------------------------------------------
11 * et1310_eeprom.c - Code used to access the device's EEPROM
13 *------------------------------------------------------------------------------
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.
22 * Copyright © 2005 Agere Systems Inc.
23 * All rights reserved.
25 * Redistribution and use in source or binary forms, with or without
26 * modifications, are permitted provided that the following conditions are met:
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
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.
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.
43 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44 * 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
58 #include "et131x_version.h"
59 #include "et131x_debug.h"
60 #include "et131x_defs.h"
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>
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>
76 #include <linux/delay.h>
77 #include <linux/bitops.h>
79 #include <asm/system.h>
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>
87 #include "et1310_phy.h"
88 #include "et1310_pm.h"
89 #include "et1310_jagcore.h"
90 #include "et1310_eeprom.h"
92 #include "et131x_adapter.h"
93 #include "et131x_initpci.h"
94 #include "et131x_isr.h"
96 #include "et1310_tx.h"
103 /* LBCIF Register Groups (addressed via 32-bit offsets) */
104 #define LBCIF_DWORD0_GROUP_OFFSET 0xAC
105 #define LBCIF_DWORD1_GROUP_OFFSET 0xB0
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
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
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
132 /* Miscellaneous Constraints */
133 #define MAX_NUM_REGISTER_POLLS 1000
134 #define MAX_NUM_WRITE_RETRIES 2
137 * Define macros that allow individual register values to be extracted from a
138 * DWORD1 register grouping
140 #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)
145 * EepromWriteByte - Write a byte to the ET1310's EEPROM
146 * @etdev: pointer to our private adapter structure
147 * @addr: the address to write
148 * @data: the value to write
150 * Returns SUCCESS or FAILURE
152 int EepromWriteByte(struct et131x_adapter *etdev, u32 addr, u8 data)
154 struct pci_dev *pdev = etdev->pdev;
166 * The following excerpt is from "Serial EEPROM HW Design
167 * Specification" Version 0.92 (9/20/2004):
171 * For an EEPROM, an I2C single byte write is defined as a START
172 * condition followed by the device address, EEPROM address, one byte
173 * of data and a STOP condition. The STOP condition will trigger the
174 * EEPROM's internally timed write cycle to the nonvolatile memory.
175 * All inputs are disabled during this write cycle and the EEPROM will
176 * not respond to any access until the internal write is complete.
177 * The steps to execute a single byte write are as follows:
179 * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and
180 * bits 7,1:0 both equal to 1, at least once after reset.
181 * Subsequent operations need only to check that bits 1:0 are
182 * equal to 1 prior to starting a single byte write.
184 * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0,
185 * and bits 1:0 both =0. Bit 5 should be set according to the
186 * type of EEPROM being accessed (1=two byte addressing, 0=one
189 * 3. Write the address to the LBCIF Address Register.
191 * 4. Write the data to the LBCIF Data Register (the I2C write will
194 * 5. Monitor bit 1:0 of the LBCIF Status Register. When bits 1:0 are
195 * both equal to 1, the I2C write has completed and the internal
196 * write cycle of the EEPROM is about to start. (bits 1:0 = 01 is
197 * a legal state while waiting from both equal to 1, but bits
198 * 1:0 = 10 is invalid and implies that something is broken).
200 * 6. Check bit 3 of the LBCIF Status Register. If equal to 1, an
201 * error has occurred.
203 * 7. Check bit 2 of the LBCIF Status Register. If equal to 1 an ACK
204 * error has occurred on the address phase of the write. This
205 * could be due to an actual hardware failure or the EEPROM may
206 * still be in its internal write cycle from a previous write.
207 * This write operation was ignored and must be repeated later.
209 * 8. Set bit 6 of the LBCIF Control Register = 0. If another write is
210 * required, go to step 1.
214 for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) {
215 /* Read registers grouped in DWORD1 */
216 if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET,
222 status = EXTRACT_STATUS_REGISTER(dword1);
224 if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL &&
225 status & LBCIF_STATUS_I2C_IDLE)
226 /* bits 1:0 are equal to 1 */
230 if (err || (index >= MAX_NUM_REGISTER_POLLS))
235 control |= LBCIF_CONTROL_LBCIF_ENABLE | LBCIF_CONTROL_I2C_WRITE;
237 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET,
244 /* Prepare EEPROM address for Step 3 */
246 for (retries = 0; retries < MAX_NUM_WRITE_RETRIES; retries++) {
248 if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER_OFFSET,
254 if (pci_write_config_byte(pdev, LBCIF_DATA_REGISTER_OFFSET,
260 for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) {
261 /* Read registers grouped in DWORD1 */
262 if (pci_read_config_dword(pdev,
263 LBCIF_DWORD1_GROUP_OFFSET,
269 status = EXTRACT_STATUS_REGISTER(dword1);
271 if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL &&
272 status & LBCIF_STATUS_I2C_IDLE) {
273 /* I2C write complete */
278 if (err || (index >= MAX_NUM_REGISTER_POLLS))
282 * Step 6: Don't break here if we are revision 1, this is
283 * so we do a blind write for load bug.
285 if (status & LBCIF_STATUS_GENERAL_ERROR
286 && etdev->pdev->revision == 0) {
291 if (status & LBCIF_STATUS_ACK_ERROR) {
293 * This could be due to an actual hardware failure
294 * or the EEPROM may still be in its internal write
295 * cycle from a previous write. This write operation
296 * was ignored and must be repeated later.
310 control &= ~LBCIF_CONTROL_I2C_WRITE;
312 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET,
317 /* Do read until internal ACK_ERROR goes away meaning write
321 pci_write_config_dword(pdev,
322 LBCIF_ADDRESS_REGISTER_OFFSET,
325 pci_read_config_dword(pdev,
326 LBCIF_DATA_REGISTER_OFFSET, &val);
327 } while ((val & 0x00010000) == 0);
328 } while (val & 0x00040000);
330 control = EXTRACT_CONTROL_REG(val);
332 if (control != 0xC0 || index == 10000)
338 return writeok ? SUCCESS : FAILURE;
342 * EepromReadByte - Read a byte from the ET1310's EEPROM
343 * @etdev: pointer to our private adapter structure
344 * @addr: the address from which to read
345 * @pdata: a pointer to a byte in which to store the value of the read
346 * @eeprom_id: the ID of the EEPROM
347 * @addrmode: how the EEPROM is to be accessed
349 * Returns SUCCESS or FAILURE
351 int EepromReadByte(struct et131x_adapter *etdev, u32 addr, u8 *pdata)
353 struct pci_dev *pdev = etdev->pdev;
361 * The following excerpt is from "Serial EEPROM HW Design
362 * Specification" Version 0.92 (9/20/2004):
366 * A single byte read is similar to the single byte write, with the
367 * exception of the data flow:
369 * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and
370 * bits 7,1:0 both equal to 1, at least once after reset.
371 * Subsequent operations need only to check that bits 1:0 are equal
372 * to 1 prior to starting a single byte read.
374 * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0,
375 * and bits 1:0 both =0. Bit 5 should be set according to the type
376 * of EEPROM being accessed (1=two byte addressing, 0=one byte
379 * 3. Write the address to the LBCIF Address Register (I2C read will
382 * 4. Monitor bit 0 of the LBCIF Status Register. When =1, I2C read
383 * is complete. (if bit 1 =1 and bit 0 stays =0, a hardware failure
386 * 5. Check bit 2 of the LBCIF Status Register. If =1, then an error
387 * has occurred. The data that has been returned from the PHY may
390 * 6. Regardless of error status, read data byte from LBCIF Data
391 * Register. If another byte is required, go to step 1.
395 for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) {
396 /* Read registers grouped in DWORD1 */
397 if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET,
403 status = EXTRACT_STATUS_REGISTER(dword1);
405 if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL &&
406 status & LBCIF_STATUS_I2C_IDLE) {
407 /* bits 1:0 are equal to 1 */
412 if (err || (index >= MAX_NUM_REGISTER_POLLS))
417 control |= LBCIF_CONTROL_LBCIF_ENABLE;
419 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER_OFFSET,
426 if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER_OFFSET,
432 for (index = 0; index < MAX_NUM_REGISTER_POLLS; index++) {
433 /* Read registers grouped in DWORD1 */
434 if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP_OFFSET,
440 status = EXTRACT_STATUS_REGISTER(dword1);
442 if (status & LBCIF_STATUS_PHY_QUEUE_AVAIL
443 && status & LBCIF_STATUS_I2C_IDLE) {
444 /* I2C read complete */
449 if (err || (index >= MAX_NUM_REGISTER_POLLS))
453 *pdata = EXTRACT_DATA_REGISTER(dword1);
455 return (status & LBCIF_STATUS_ACK_ERROR) ? FAILURE : SUCCESS;