Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 3 | Intel PRO/10GbE Linux driver |
Jesse Brandeburg | f731a9e | 2008-07-08 15:53:09 -0700 | [diff] [blame] | 4 | Copyright(c) 1999 - 2008 Intel Corporation. |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 5 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | more details. |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License along with |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
Joe Perches | d328bc8 | 2010-04-27 00:50:58 +0000 | [diff] [blame^] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "ixgb_hw.h" |
| 32 | #include "ixgb_ee.h" |
| 33 | /* Local prototypes */ |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 34 | static u16 ixgb_shift_in_bits(struct ixgb_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | static void ixgb_shift_out_bits(struct ixgb_hw *hw, |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 37 | u16 data, |
| 38 | u16 count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static void ixgb_standby_eeprom(struct ixgb_hw *hw); |
| 40 | |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 41 | static bool ixgb_wait_eeprom_command(struct ixgb_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | static 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 | *****************************************************************************/ |
| 51 | static void |
| 52 | ixgb_raise_clock(struct ixgb_hw *hw, |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 53 | u32 *eecd_reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 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); |
| 60 | udelay(50); |
| 61 | return; |
| 62 | } |
| 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 | *****************************************************************************/ |
| 70 | static void |
| 71 | ixgb_lower_clock(struct ixgb_hw *hw, |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 72 | u32 *eecd_reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 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); |
| 79 | udelay(50); |
| 80 | return; |
| 81 | } |
| 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 | *****************************************************************************/ |
| 90 | static void |
| 91 | ixgb_shift_out_bits(struct ixgb_hw *hw, |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 92 | u16 data, |
| 93 | u16 count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 95 | u32 eecd_reg; |
| 96 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 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 Brandeburg | 03f8304 | 2008-07-08 15:52:13 -0700 | [diff] [blame] | 113 | if (data & mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | eecd_reg |= IXGB_EECD_DI; |
| 115 | |
| 116 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 117 | |
| 118 | udelay(50); |
| 119 | |
| 120 | ixgb_raise_clock(hw, &eecd_reg); |
| 121 | ixgb_lower_clock(hw, &eecd_reg); |
| 122 | |
| 123 | mask = mask >> 1; |
| 124 | |
Jesse Brandeburg | 9a43299 | 2008-07-08 15:52:18 -0700 | [diff] [blame] | 125 | } while (mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 128 | eecd_reg &= ~IXGB_EECD_DI; |
| 129 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | /****************************************************************************** |
| 134 | * Shift data bits in from the EEPROM |
| 135 | * |
| 136 | * hw - Struct containing variables accessed by shared code |
| 137 | *****************************************************************************/ |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 138 | static u16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | ixgb_shift_in_bits(struct ixgb_hw *hw) |
| 140 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 141 | u32 eecd_reg; |
| 142 | u32 i; |
| 143 | u16 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 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 Brandeburg | 1459336 | 2008-07-08 15:52:33 -0700 | [diff] [blame] | 157 | for (i = 0; i < 16; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | 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 Brandeburg | 03f8304 | 2008-07-08 15:52:13 -0700 | [diff] [blame] | 164 | if (eecd_reg & IXGB_EECD_DO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | 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 | *****************************************************************************/ |
| 181 | static void |
| 182 | ixgb_setup_eeprom(struct ixgb_hw *hw) |
| 183 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 184 | u32 eecd_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 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); |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | /****************************************************************************** |
| 199 | * Returns EEPROM to a "standby" state |
| 200 | * |
| 201 | * hw - Struct containing variables accessed by shared code |
| 202 | *****************************************************************************/ |
| 203 | static void |
| 204 | ixgb_standby_eeprom(struct ixgb_hw *hw) |
| 205 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 206 | u32 eecd_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | eecd_reg = IXGB_READ_REG(hw, EECD); |
| 209 | |
Jesse Brandeburg | 52035bd | 2008-07-08 15:52:28 -0700 | [diff] [blame] | 210 | /* Deselect EEPROM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | eecd_reg &= ~(IXGB_EECD_CS | IXGB_EECD_SK); |
| 212 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 213 | udelay(50); |
| 214 | |
| 215 | /* Clock high */ |
| 216 | eecd_reg |= IXGB_EECD_SK; |
| 217 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 218 | udelay(50); |
| 219 | |
| 220 | /* Select EEPROM */ |
| 221 | eecd_reg |= IXGB_EECD_CS; |
| 222 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 223 | udelay(50); |
| 224 | |
| 225 | /* Clock low */ |
| 226 | eecd_reg &= ~IXGB_EECD_SK; |
| 227 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 228 | udelay(50); |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | /****************************************************************************** |
| 233 | * Raises then lowers the EEPROM's clock pin |
| 234 | * |
| 235 | * hw - Struct containing variables accessed by shared code |
| 236 | *****************************************************************************/ |
| 237 | static void |
| 238 | ixgb_clock_eeprom(struct ixgb_hw *hw) |
| 239 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 240 | u32 eecd_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | eecd_reg = IXGB_READ_REG(hw, EECD); |
| 243 | |
| 244 | /* Rising edge of clock */ |
| 245 | eecd_reg |= IXGB_EECD_SK; |
| 246 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 247 | udelay(50); |
| 248 | |
| 249 | /* Falling edge of clock */ |
| 250 | eecd_reg &= ~IXGB_EECD_SK; |
| 251 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 252 | udelay(50); |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | /****************************************************************************** |
| 257 | * Terminates a command by lowering the EEPROM's chip select pin |
| 258 | * |
| 259 | * hw - Struct containing variables accessed by shared code |
| 260 | *****************************************************************************/ |
| 261 | static void |
| 262 | ixgb_cleanup_eeprom(struct ixgb_hw *hw) |
| 263 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 264 | u32 eecd_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | eecd_reg = IXGB_READ_REG(hw, EECD); |
| 267 | |
| 268 | eecd_reg &= ~(IXGB_EECD_CS | IXGB_EECD_DI); |
| 269 | |
| 270 | IXGB_WRITE_REG(hw, EECD, eecd_reg); |
| 271 | |
| 272 | ixgb_clock_eeprom(hw); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | /****************************************************************************** |
| 277 | * Waits for the EEPROM to finish the current command. |
| 278 | * |
| 279 | * hw - Struct containing variables accessed by shared code |
| 280 | * |
| 281 | * The command is done when the EEPROM's data out pin goes high. |
| 282 | * |
| 283 | * Returns: |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 284 | * true: EEPROM data pin is high before timeout. |
| 285 | * false: Time expired. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | *****************************************************************************/ |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 287 | static bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | ixgb_wait_eeprom_command(struct ixgb_hw *hw) |
| 289 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 290 | u32 eecd_reg; |
| 291 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | /* Toggle the CS line. This in effect tells to EEPROM to actually execute |
| 294 | * the command in question. |
| 295 | */ |
| 296 | ixgb_standby_eeprom(hw); |
| 297 | |
Jesse Brandeburg | 52035bd | 2008-07-08 15:52:28 -0700 | [diff] [blame] | 298 | /* Now read DO repeatedly until is high (equal to '1'). The EEPROM will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | * signal that the command has been completed by raising the DO signal. |
| 300 | * If DO does not go high in 10 milliseconds, then error out. |
| 301 | */ |
Jesse Brandeburg | 1459336 | 2008-07-08 15:52:33 -0700 | [diff] [blame] | 302 | for (i = 0; i < 200; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | eecd_reg = IXGB_READ_REG(hw, EECD); |
| 304 | |
Jesse Brandeburg | 03f8304 | 2008-07-08 15:52:13 -0700 | [diff] [blame] | 305 | if (eecd_reg & IXGB_EECD_DO) |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 306 | return (true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | udelay(50); |
| 309 | } |
| 310 | ASSERT(0); |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 311 | return (false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /****************************************************************************** |
| 315 | * Verifies that the EEPROM has a valid checksum |
| 316 | * |
| 317 | * hw - Struct containing variables accessed by shared code |
| 318 | * |
| 319 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 320 | * If the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | * valid. |
| 322 | * |
| 323 | * Returns: |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 324 | * true: Checksum is valid |
| 325 | * false: Checksum is not valid. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | *****************************************************************************/ |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 327 | bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | ixgb_validate_eeprom_checksum(struct ixgb_hw *hw) |
| 329 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 330 | u16 checksum = 0; |
| 331 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Jesse Brandeburg | 1459336 | 2008-07-08 15:52:33 -0700 | [diff] [blame] | 333 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | checksum += ixgb_read_eeprom(hw, i); |
| 335 | |
Jesse Brandeburg | 03f8304 | 2008-07-08 15:52:13 -0700 | [diff] [blame] | 336 | if (checksum == (u16) EEPROM_SUM) |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 337 | return (true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | else |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 339 | return (false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /****************************************************************************** |
| 343 | * Calculates the EEPROM checksum and writes it to the EEPROM |
| 344 | * |
| 345 | * hw - Struct containing variables accessed by shared code |
| 346 | * |
| 347 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. |
| 348 | * Writes the difference to word offset 63 of the EEPROM. |
| 349 | *****************************************************************************/ |
| 350 | void |
| 351 | ixgb_update_eeprom_checksum(struct ixgb_hw *hw) |
| 352 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 353 | u16 checksum = 0; |
| 354 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Jesse Brandeburg | 1459336 | 2008-07-08 15:52:33 -0700 | [diff] [blame] | 356 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | checksum += ixgb_read_eeprom(hw, i); |
| 358 | |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 359 | checksum = (u16) EEPROM_SUM - checksum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | ixgb_write_eeprom(hw, EEPROM_CHECKSUM_REG, checksum); |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | /****************************************************************************** |
| 366 | * Writes a 16 bit word to a given offset in the EEPROM. |
| 367 | * |
| 368 | * hw - Struct containing variables accessed by shared code |
| 369 | * reg - offset within the EEPROM to be written to |
Jesse Brandeburg | 52035bd | 2008-07-08 15:52:28 -0700 | [diff] [blame] | 370 | * data - 16 bit word to be written to the EEPROM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | * |
| 372 | * If ixgb_update_eeprom_checksum is not called after this function, the |
| 373 | * EEPROM will most likely contain an invalid checksum. |
| 374 | * |
| 375 | *****************************************************************************/ |
| 376 | void |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 377 | ixgb_write_eeprom(struct ixgb_hw *hw, u16 offset, u16 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
| 379 | struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom; |
| 380 | |
| 381 | /* Prepare the EEPROM for writing */ |
| 382 | ixgb_setup_eeprom(hw); |
| 383 | |
| 384 | /* Send the 9-bit EWEN (write enable) command to the EEPROM (5-bit opcode |
| 385 | * plus 4-bit dummy). This puts the EEPROM into write/erase mode. |
| 386 | */ |
| 387 | ixgb_shift_out_bits(hw, EEPROM_EWEN_OPCODE, 5); |
| 388 | ixgb_shift_out_bits(hw, 0, 4); |
| 389 | |
| 390 | /* Prepare the EEPROM */ |
| 391 | ixgb_standby_eeprom(hw); |
| 392 | |
| 393 | /* Send the Write command (3-bit opcode + 6-bit addr) */ |
| 394 | ixgb_shift_out_bits(hw, EEPROM_WRITE_OPCODE, 3); |
| 395 | ixgb_shift_out_bits(hw, offset, 6); |
| 396 | |
| 397 | /* Send the data */ |
| 398 | ixgb_shift_out_bits(hw, data, 16); |
| 399 | |
| 400 | ixgb_wait_eeprom_command(hw); |
| 401 | |
| 402 | /* Recover from write */ |
| 403 | ixgb_standby_eeprom(hw); |
| 404 | |
| 405 | /* Send the 9-bit EWDS (write disable) command to the EEPROM (5-bit |
| 406 | * opcode plus 4-bit dummy). This takes the EEPROM out of write/erase |
| 407 | * mode. |
| 408 | */ |
| 409 | ixgb_shift_out_bits(hw, EEPROM_EWDS_OPCODE, 5); |
| 410 | ixgb_shift_out_bits(hw, 0, 4); |
| 411 | |
| 412 | /* Done with writing */ |
| 413 | ixgb_cleanup_eeprom(hw); |
| 414 | |
| 415 | /* clear the init_ctrl_reg_1 to signify that the cache is invalidated */ |
Al Viro | c676504 | 2007-08-23 00:47:03 -0400 | [diff] [blame] | 416 | ee_map->init_ctrl_reg_1 = cpu_to_le16(EEPROM_ICW1_SIGNATURE_CLEAR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | /****************************************************************************** |
| 422 | * Reads a 16 bit word from the EEPROM. |
| 423 | * |
| 424 | * hw - Struct containing variables accessed by shared code |
| 425 | * offset - offset of 16 bit word in the EEPROM to read |
| 426 | * |
| 427 | * Returns: |
| 428 | * The 16-bit value read from the eeprom |
| 429 | *****************************************************************************/ |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 430 | u16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | ixgb_read_eeprom(struct ixgb_hw *hw, |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 432 | u16 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 434 | u16 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | /* Prepare the EEPROM for reading */ |
| 437 | ixgb_setup_eeprom(hw); |
| 438 | |
| 439 | /* Send the READ command (opcode + addr) */ |
| 440 | ixgb_shift_out_bits(hw, EEPROM_READ_OPCODE, 3); |
| 441 | /* |
| 442 | * We have a 64 word EEPROM, there are 6 address bits |
| 443 | */ |
| 444 | ixgb_shift_out_bits(hw, offset, 6); |
| 445 | |
| 446 | /* Read the data */ |
| 447 | data = ixgb_shift_in_bits(hw); |
| 448 | |
| 449 | /* End this read operation */ |
| 450 | ixgb_standby_eeprom(hw); |
| 451 | |
| 452 | return (data); |
| 453 | } |
| 454 | |
| 455 | /****************************************************************************** |
| 456 | * Reads eeprom and stores data in shared structure. |
| 457 | * Validates eeprom checksum and eeprom signature. |
| 458 | * |
| 459 | * hw - Struct containing variables accessed by shared code |
| 460 | * |
| 461 | * Returns: |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 462 | * true: if eeprom read is successful |
| 463 | * false: otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | *****************************************************************************/ |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 465 | bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | ixgb_get_eeprom_data(struct ixgb_hw *hw) |
| 467 | { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 468 | u16 i; |
| 469 | u16 checksum = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | struct ixgb_ee_map_type *ee_map; |
| 471 | |
Joe Perches | d328bc8 | 2010-04-27 00:50:58 +0000 | [diff] [blame^] | 472 | ENTER(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | ee_map = (struct ixgb_ee_map_type *)hw->eeprom; |
| 475 | |
Joe Perches | d328bc8 | 2010-04-27 00:50:58 +0000 | [diff] [blame^] | 476 | pr_debug("Reading eeprom data\n"); |
Jesse Brandeburg | 1459336 | 2008-07-08 15:52:33 -0700 | [diff] [blame] | 477 | for (i = 0; i < IXGB_EEPROM_SIZE ; i++) { |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 478 | u16 ee_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | ee_data = ixgb_read_eeprom(hw, i); |
| 480 | checksum += ee_data; |
Al Viro | c676504 | 2007-08-23 00:47:03 -0400 | [diff] [blame] | 481 | hw->eeprom[i] = cpu_to_le16(ee_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 484 | if (checksum != (u16) EEPROM_SUM) { |
Joe Perches | d328bc8 | 2010-04-27 00:50:58 +0000 | [diff] [blame^] | 485 | pr_debug("Checksum invalid\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | /* clear the init_ctrl_reg_1 to signify that the cache is |
| 487 | * invalidated */ |
Al Viro | c676504 | 2007-08-23 00:47:03 -0400 | [diff] [blame] | 488 | ee_map->init_ctrl_reg_1 = cpu_to_le16(EEPROM_ICW1_SIGNATURE_CLEAR); |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 489 | return (false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Al Viro | c676504 | 2007-08-23 00:47:03 -0400 | [diff] [blame] | 492 | if ((ee_map->init_ctrl_reg_1 & cpu_to_le16(EEPROM_ICW1_SIGNATURE_MASK)) |
| 493 | != cpu_to_le16(EEPROM_ICW1_SIGNATURE_VALID)) { |
Joe Perches | d328bc8 | 2010-04-27 00:50:58 +0000 | [diff] [blame^] | 494 | pr_debug("Signature invalid\n"); |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 495 | return(false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 498 | return(true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /****************************************************************************** |
| 502 | * Local function to check if the eeprom signature is good |
| 503 | * If the eeprom signature is good, calls ixgb)get_eeprom_data. |
| 504 | * |
| 505 | * hw - Struct containing variables accessed by shared code |
| 506 | * |
| 507 | * Returns: |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 508 | * true: eeprom signature was good and the eeprom read was successful |
| 509 | * false: otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | ******************************************************************************/ |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 511 | static bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | ixgb_check_and_get_eeprom_data (struct ixgb_hw* hw) |
| 513 | { |
| 514 | struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom; |
| 515 | |
Al Viro | c676504 | 2007-08-23 00:47:03 -0400 | [diff] [blame] | 516 | if ((ee_map->init_ctrl_reg_1 & cpu_to_le16(EEPROM_ICW1_SIGNATURE_MASK)) |
| 517 | == cpu_to_le16(EEPROM_ICW1_SIGNATURE_VALID)) { |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 518 | return (true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } else { |
| 520 | return ixgb_get_eeprom_data(hw); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | /****************************************************************************** |
| 525 | * return a word from the eeprom |
| 526 | * |
| 527 | * hw - Struct containing variables accessed by shared code |
| 528 | * index - Offset of eeprom word |
| 529 | * |
| 530 | * Returns: |
| 531 | * Word at indexed offset in eeprom, if valid, 0 otherwise. |
| 532 | ******************************************************************************/ |
Al Viro | c676504 | 2007-08-23 00:47:03 -0400 | [diff] [blame] | 533 | __le16 |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 534 | ixgb_get_eeprom_word(struct ixgb_hw *hw, u16 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | { |
| 536 | |
| 537 | if ((index < IXGB_EEPROM_SIZE) && |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 538 | (ixgb_check_and_get_eeprom_data(hw) == true)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return(hw->eeprom[index]); |
| 540 | } |
| 541 | |
| 542 | return(0); |
| 543 | } |
| 544 | |
| 545 | /****************************************************************************** |
| 546 | * return the mac address from EEPROM |
| 547 | * |
| 548 | * hw - Struct containing variables accessed by shared code |
| 549 | * mac_addr - Ethernet Address if EEPROM contents are valid, 0 otherwise |
| 550 | * |
| 551 | * Returns: None. |
| 552 | ******************************************************************************/ |
| 553 | void |
| 554 | ixgb_get_ee_mac_addr(struct ixgb_hw *hw, |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 555 | u8 *mac_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | { |
| 557 | int i; |
| 558 | struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom; |
| 559 | |
Joe Perches | d328bc8 | 2010-04-27 00:50:58 +0000 | [diff] [blame^] | 560 | ENTER(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 562 | if (ixgb_check_and_get_eeprom_data(hw) == true) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | for (i = 0; i < IXGB_ETH_LENGTH_OF_ADDRESS; i++) { |
| 564 | mac_addr[i] = ee_map->mac_addr[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
Joe Perches | d328bc8 | 2010-04-27 00:50:58 +0000 | [diff] [blame^] | 566 | pr_debug("eeprom mac address = %pM\n", mac_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | /****************************************************************************** |
| 572 | * return the Printed Board Assembly number from EEPROM |
| 573 | * |
| 574 | * hw - Struct containing variables accessed by shared code |
| 575 | * |
| 576 | * Returns: |
| 577 | * PBA number if EEPROM contents are valid, 0 otherwise |
| 578 | ******************************************************************************/ |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 579 | u32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | ixgb_get_ee_pba_number(struct ixgb_hw *hw) |
| 581 | { |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 582 | if (ixgb_check_and_get_eeprom_data(hw) == true) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | return (le16_to_cpu(hw->eeprom[EEPROM_PBA_1_2_REG]) |
| 584 | | (le16_to_cpu(hw->eeprom[EEPROM_PBA_3_4_REG])<<16)); |
| 585 | |
| 586 | return(0); |
| 587 | } |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
| 590 | /****************************************************************************** |
| 591 | * return the Device Id from EEPROM |
| 592 | * |
| 593 | * hw - Struct containing variables accessed by shared code |
| 594 | * |
| 595 | * Returns: |
| 596 | * Device Id if EEPROM contents are valid, 0 otherwise |
| 597 | ******************************************************************************/ |
Joe Perches | 222441a | 2008-04-03 10:06:25 -0700 | [diff] [blame] | 598 | u16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | ixgb_get_ee_device_id(struct ixgb_hw *hw) |
| 600 | { |
| 601 | struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom; |
| 602 | |
Joe Perches | 446490c | 2008-03-21 11:06:37 -0700 | [diff] [blame] | 603 | if (ixgb_check_and_get_eeprom_data(hw) == true) |
Malli Chilakala | abf481d | 2005-04-28 19:03:32 -0700 | [diff] [blame] | 604 | return (le16_to_cpu(ee_map->device_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
Malli Chilakala | fcb0175 | 2005-08-11 13:59:31 -0700 | [diff] [blame] | 606 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |