1 /* 2 * CDDL HEADER START 3 * 4 * Copyright(c) 2007-2009 Intel Corporation. All rights reserved. 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at: 10 * http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When using or redistributing this file, you may do so under the 15 * License only. No other modification of this header is permitted. 16 * 17 * If applicable, add the following below this CDDL HEADER, with the 18 * fields enclosed by brackets "[]" replaced with your own identifying 19 * information: Portions Copyright [yyyy] [name of copyright owner] 20 * 21 * CDDL HEADER END 22 */ 23 24 /* 25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms of the CDDL. 27 */ 28 29 /* IntelVersion: 1.49 v2-9-8_2009-6-12 */ 30 31 #include "igb_api.h" 32 33 static void e1000_stop_nvm(struct e1000_hw *hw); 34 static void e1000_reload_nvm_generic(struct e1000_hw *hw); 35 36 /* 37 * e1000_init_nvm_ops_generic - Initialize NVM function pointers 38 * @hw: pointer to the HW structure 39 * 40 * Setups up the function pointers to no-op functions 41 */ 42 void 43 e1000_init_nvm_ops_generic(struct e1000_hw *hw) 44 { 45 struct e1000_nvm_info *nvm = &hw->nvm; 46 DEBUGFUNC("e1000_init_nvm_ops_generic"); 47 48 /* Initialize function pointers */ 49 nvm->ops.init_params = e1000_null_ops_generic; 50 nvm->ops.acquire = e1000_null_ops_generic; 51 nvm->ops.read = e1000_null_read_nvm; 52 nvm->ops.release = e1000_null_nvm_generic; 53 nvm->ops.reload = e1000_reload_nvm_generic; 54 nvm->ops.update = e1000_null_ops_generic; 55 nvm->ops.valid_led_default = e1000_null_led_default; 56 nvm->ops.validate = e1000_null_ops_generic; 57 nvm->ops.write = e1000_null_write_nvm; 58 } 59 60 /* 61 * e1000_null_nvm_read - No-op function, return 0 62 * @hw: pointer to the HW structure 63 */ 64 s32 65 e1000_null_read_nvm(struct e1000_hw *hw, u16 a, u16 b, u16 *c) 66 { 67 DEBUGFUNC("e1000_null_read_nvm"); 68 UNREFERENCED_4PARAMETER(hw, a, b, c); 69 return (E1000_SUCCESS); 70 } 71 72 /* 73 * e1000_null_nvm_generic - No-op function, return void 74 * @hw: pointer to the HW structure 75 */ 76 void 77 e1000_null_nvm_generic(struct e1000_hw *hw) 78 { 79 DEBUGFUNC("e1000_null_nvm_generic"); 80 UNREFERENCED_1PARAMETER(hw); 81 } 82 83 /* 84 * e1000_null_led_default - No-op function, return 0 85 * @hw: pointer to the HW structure 86 */ 87 s32 88 e1000_null_led_default(struct e1000_hw *hw, u16 *data) 89 { 90 DEBUGFUNC("e1000_null_led_default"); 91 UNREFERENCED_2PARAMETER(hw, data); 92 return (E1000_SUCCESS); 93 } 94 95 /* 96 * e1000_null_write_nvm - No-op function, return 0 97 * @hw: pointer to the HW structure 98 */ 99 s32 100 e1000_null_write_nvm(struct e1000_hw *hw, u16 a, u16 b, u16 *c) 101 { 102 DEBUGFUNC("e1000_null_write_nvm"); 103 UNREFERENCED_4PARAMETER(hw, a, b, c); 104 return (E1000_SUCCESS); 105 } 106 107 /* 108 * e1000_raise_eec_clk - Raise EEPROM clock 109 * @hw: pointer to the HW structure 110 * @eecd: pointer to the EEPROM 111 * 112 * Enable/Raise the EEPROM clock bit. 113 */ 114 static void 115 e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd) 116 { 117 *eecd = *eecd | E1000_EECD_SK; 118 E1000_WRITE_REG(hw, E1000_EECD, *eecd); 119 E1000_WRITE_FLUSH(hw); 120 usec_delay(hw->nvm.delay_usec); 121 } 122 123 /* 124 * e1000_lower_eec_clk - Lower EEPROM clock 125 * @hw: pointer to the HW structure 126 * @eecd: pointer to the EEPROM 127 * 128 * Clear/Lower the EEPROM clock bit. 129 */ 130 static void 131 e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd) 132 { 133 *eecd = *eecd & ~E1000_EECD_SK; 134 E1000_WRITE_REG(hw, E1000_EECD, *eecd); 135 E1000_WRITE_FLUSH(hw); 136 usec_delay(hw->nvm.delay_usec); 137 } 138 139 /* 140 * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM 141 * @hw: pointer to the HW structure 142 * @data: data to send to the EEPROM 143 * @count: number of bits to shift out 144 * 145 * We need to shift 'count' bits out to the EEPROM. So, the value in the 146 * "data" parameter will be shifted out to the EEPROM one bit at a time. 147 * In order to do this, "data" must be broken down into bits. 148 */ 149 static void 150 e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count) 151 { 152 struct e1000_nvm_info *nvm = &hw->nvm; 153 u32 eecd = E1000_READ_REG(hw, E1000_EECD); 154 u32 mask; 155 156 DEBUGFUNC("e1000_shift_out_eec_bits"); 157 158 mask = 0x01 << (count - 1); 159 if (nvm->type == e1000_nvm_eeprom_microwire) 160 eecd &= ~E1000_EECD_DO; 161 else if (nvm->type == e1000_nvm_eeprom_spi) 162 eecd |= E1000_EECD_DO; 163 164 do { 165 eecd &= ~E1000_EECD_DI; 166 167 if (data & mask) 168 eecd |= E1000_EECD_DI; 169 170 E1000_WRITE_REG(hw, E1000_EECD, eecd); 171 E1000_WRITE_FLUSH(hw); 172 173 usec_delay(nvm->delay_usec); 174 175 e1000_raise_eec_clk(hw, &eecd); 176 e1000_lower_eec_clk(hw, &eecd); 177 178 mask >>= 1; 179 } while (mask); 180 181 eecd &= ~E1000_EECD_DI; 182 E1000_WRITE_REG(hw, E1000_EECD, eecd); 183 } 184 185 /* 186 * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM 187 * @hw: pointer to the HW structure 188 * @count: number of bits to shift in 189 * 190 * In order to read a register from the EEPROM, we need to shift 'count' bits 191 * in from the EEPROM. Bits are "shifted in" by raising the clock input to 192 * the EEPROM (setting the SK bit), and then reading the value of the data out 193 * "DO" bit. During this "shifting in" process the data in "DI" bit should 194 * always be clear. 195 */ 196 static u16 197 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count) 198 { 199 u32 eecd; 200 u32 i; 201 u16 data; 202 203 DEBUGFUNC("e1000_shift_in_eec_bits"); 204 205 eecd = E1000_READ_REG(hw, E1000_EECD); 206 207 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); 208 data = 0; 209 210 for (i = 0; i < count; i++) { 211 data <<= 1; 212 e1000_raise_eec_clk(hw, &eecd); 213 214 eecd = E1000_READ_REG(hw, E1000_EECD); 215 216 eecd &= ~E1000_EECD_DI; 217 if (eecd & E1000_EECD_DO) 218 data |= 1; 219 220 e1000_lower_eec_clk(hw, &eecd); 221 } 222 223 return (data); 224 } 225 226 /* 227 * e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion 228 * @hw: pointer to the HW structure 229 * @ee_reg: EEPROM flag for polling 230 * 231 * Polls the EEPROM status bit for either read or write completion based 232 * upon the value of 'ee_reg'. 233 */ 234 s32 235 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg) 236 { 237 u32 attempts = 100000; 238 u32 i, reg = 0; 239 s32 ret_val = -E1000_ERR_NVM; 240 241 DEBUGFUNC("e1000_poll_eerd_eewr_done"); 242 243 for (i = 0; i < attempts; i++) { 244 if (ee_reg == E1000_NVM_POLL_READ) 245 reg = E1000_READ_REG(hw, E1000_EERD); 246 else 247 reg = E1000_READ_REG(hw, E1000_EEWR); 248 249 if (reg & E1000_NVM_RW_REG_DONE) { 250 ret_val = E1000_SUCCESS; 251 break; 252 } 253 254 usec_delay(5); 255 } 256 257 return (ret_val); 258 } 259 260 /* 261 * e1000_acquire_nvm_generic - Generic request for access to EEPROM 262 * @hw: pointer to the HW structure 263 * 264 * Set the EEPROM access request bit and wait for EEPROM access grant bit. 265 * Return successful if access grant bit set, else clear the request for 266 * EEPROM access and return -E1000_ERR_NVM (-1). 267 */ 268 s32 269 e1000_acquire_nvm_generic(struct e1000_hw *hw) 270 { 271 u32 eecd = E1000_READ_REG(hw, E1000_EECD); 272 s32 timeout = E1000_NVM_GRANT_ATTEMPTS; 273 s32 ret_val = E1000_SUCCESS; 274 275 DEBUGFUNC("e1000_acquire_nvm_generic"); 276 277 E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ); 278 eecd = E1000_READ_REG(hw, E1000_EECD); 279 280 while (timeout) { 281 if (eecd & E1000_EECD_GNT) 282 break; 283 usec_delay(5); 284 eecd = E1000_READ_REG(hw, E1000_EECD); 285 timeout--; 286 } 287 288 if (!timeout) { 289 eecd &= ~E1000_EECD_REQ; 290 E1000_WRITE_REG(hw, E1000_EECD, eecd); 291 DEBUGOUT("Could not acquire NVM grant\n"); 292 ret_val = -E1000_ERR_NVM; 293 } 294 295 return (ret_val); 296 } 297 298 /* 299 * e1000_standby_nvm - Return EEPROM to standby state 300 * @hw: pointer to the HW structure 301 * 302 * Return the EEPROM to a standby state. 303 */ 304 static void 305 e1000_standby_nvm(struct e1000_hw *hw) 306 { 307 struct e1000_nvm_info *nvm = &hw->nvm; 308 u32 eecd = E1000_READ_REG(hw, E1000_EECD); 309 310 DEBUGFUNC("e1000_standby_nvm"); 311 312 if (nvm->type == e1000_nvm_eeprom_microwire) { 313 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); 314 E1000_WRITE_REG(hw, E1000_EECD, eecd); 315 E1000_WRITE_FLUSH(hw); 316 usec_delay(nvm->delay_usec); 317 318 e1000_raise_eec_clk(hw, &eecd); 319 320 /* Select EEPROM */ 321 eecd |= E1000_EECD_CS; 322 E1000_WRITE_REG(hw, E1000_EECD, eecd); 323 E1000_WRITE_FLUSH(hw); 324 usec_delay(nvm->delay_usec); 325 326 e1000_lower_eec_clk(hw, &eecd); 327 } else if (nvm->type == e1000_nvm_eeprom_spi) { 328 /* Toggle CS to flush commands */ 329 eecd |= E1000_EECD_CS; 330 E1000_WRITE_REG(hw, E1000_EECD, eecd); 331 E1000_WRITE_FLUSH(hw); 332 usec_delay(nvm->delay_usec); 333 eecd &= ~E1000_EECD_CS; 334 E1000_WRITE_REG(hw, E1000_EECD, eecd); 335 E1000_WRITE_FLUSH(hw); 336 usec_delay(nvm->delay_usec); 337 } 338 } 339 340 /* 341 * e1000_stop_nvm - Terminate EEPROM command 342 * @hw: pointer to the HW structure 343 * 344 * Terminates the current command by inverting the EEPROM's chip select pin. 345 */ 346 void 347 e1000_stop_nvm(struct e1000_hw *hw) 348 { 349 u32 eecd; 350 351 DEBUGFUNC("e1000_stop_nvm"); 352 353 eecd = E1000_READ_REG(hw, E1000_EECD); 354 if (hw->nvm.type == e1000_nvm_eeprom_spi) { 355 /* Pull CS high */ 356 eecd |= E1000_EECD_CS; 357 e1000_lower_eec_clk(hw, &eecd); 358 } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) { 359 /* CS on Microwire is active-high */ 360 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); 361 E1000_WRITE_REG(hw, E1000_EECD, eecd); 362 e1000_raise_eec_clk(hw, &eecd); 363 e1000_lower_eec_clk(hw, &eecd); 364 } 365 } 366 367 /* 368 * e1000_release_nvm_generic - Release exclusive access to EEPROM 369 * @hw: pointer to the HW structure 370 * 371 * Stop any current commands to the EEPROM and clear the EEPROM request bit. 372 */ 373 void 374 e1000_release_nvm_generic(struct e1000_hw *hw) 375 { 376 u32 eecd; 377 378 DEBUGFUNC("e1000_release_nvm_generic"); 379 380 e1000_stop_nvm(hw); 381 382 eecd = E1000_READ_REG(hw, E1000_EECD); 383 eecd &= ~E1000_EECD_REQ; 384 E1000_WRITE_REG(hw, E1000_EECD, eecd); 385 } 386 387 /* 388 * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write 389 * @hw: pointer to the HW structure 390 * 391 * Setups the EEPROM for reading and writing. 392 */ 393 static s32 394 e1000_ready_nvm_eeprom(struct e1000_hw *hw) 395 { 396 struct e1000_nvm_info *nvm = &hw->nvm; 397 u32 eecd = E1000_READ_REG(hw, E1000_EECD); 398 s32 ret_val = E1000_SUCCESS; 399 u16 timeout = 0; 400 u8 spi_stat_reg; 401 402 DEBUGFUNC("e1000_ready_nvm_eeprom"); 403 404 if (nvm->type == e1000_nvm_eeprom_microwire) { 405 /* Clear SK and DI */ 406 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); 407 E1000_WRITE_REG(hw, E1000_EECD, eecd); 408 /* Set CS */ 409 eecd |= E1000_EECD_CS; 410 E1000_WRITE_REG(hw, E1000_EECD, eecd); 411 } else if (nvm->type == e1000_nvm_eeprom_spi) { 412 /* Clear SK and CS */ 413 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); 414 E1000_WRITE_REG(hw, E1000_EECD, eecd); 415 usec_delay(1); 416 timeout = NVM_MAX_RETRY_SPI; 417 418 /* 419 * Read "Status Register" repeatedly until the LSB is cleared. 420 * The EEPROM will signal that the command has been completed 421 * by clearing bit 0 of the internal status register. If it's 422 * not cleared within 'timeout', then error out. 423 */ 424 while (timeout) { 425 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI, 426 hw->nvm.opcode_bits); 427 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8); 428 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI)) 429 break; 430 431 usec_delay(5); 432 e1000_standby_nvm(hw); 433 timeout--; 434 } 435 436 if (!timeout) { 437 DEBUGOUT("SPI NVM Status error\n"); 438 ret_val = -E1000_ERR_NVM; 439 goto out; 440 } 441 } 442 443 out: 444 return (ret_val); 445 } 446 447 /* 448 * e1000_read_nvm_microwire - Reads EEPROM's using microwire 449 * @hw: pointer to the HW structure 450 * @offset: offset of word in the EEPROM to read 451 * @words: number of words to read 452 * @data: word read from the EEPROM 453 * 454 * Reads a 16 bit word from the EEPROM. 455 */ 456 s32 457 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words, 458 u16 *data) 459 { 460 struct e1000_nvm_info *nvm = &hw->nvm; 461 u32 i = 0; 462 s32 ret_val; 463 u8 read_opcode = NVM_READ_OPCODE_MICROWIRE; 464 465 DEBUGFUNC("e1000_read_nvm_microwire"); 466 467 /* 468 * A check for invalid values: offset too large, too many words, 469 * and not enough words. 470 */ 471 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 472 (words == 0)) { 473 DEBUGOUT("nvm parameter(s) out of bounds\n"); 474 ret_val = -E1000_ERR_NVM; 475 goto out; 476 } 477 478 ret_val = nvm->ops.acquire(hw); 479 if (ret_val) 480 goto out; 481 482 ret_val = e1000_ready_nvm_eeprom(hw); 483 if (ret_val) 484 goto release; 485 486 for (i = 0; i < words; i++) { 487 /* Send the READ command (opcode + addr) */ 488 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits); 489 e1000_shift_out_eec_bits(hw, (u16)(offset + i), 490 nvm->address_bits); 491 492 /* 493 * Read the data. For microwire, each word requires the 494 * overhead of setup and tear-down. 495 */ 496 data[i] = e1000_shift_in_eec_bits(hw, 16); 497 e1000_standby_nvm(hw); 498 } 499 500 release: 501 nvm->ops.release(hw); 502 503 out: 504 return (ret_val); 505 } 506 507 /* 508 * e1000_read_nvm_eerd - Reads EEPROM using EERD register 509 * @hw: pointer to the HW structure 510 * @offset: offset of word in the EEPROM to read 511 * @words: number of words to read 512 * @data: word read from the EEPROM 513 * 514 * Reads a 16 bit word from the EEPROM using the EERD register. 515 */ 516 s32 517 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 518 { 519 struct e1000_nvm_info *nvm = &hw->nvm; 520 u32 i, eerd = 0; 521 s32 ret_val = E1000_SUCCESS; 522 523 DEBUGFUNC("e1000_read_nvm_eerd"); 524 525 /* 526 * A check for invalid values: offset too large, too many words, 527 * too many words for the offset, and not enough words. 528 */ 529 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 530 (words == 0)) { 531 DEBUGOUT("nvm parameter(s) out of bounds\n"); 532 ret_val = -E1000_ERR_NVM; 533 goto out; 534 } 535 536 for (i = 0; i < words; i++) { 537 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) + 538 E1000_NVM_RW_REG_START; 539 540 E1000_WRITE_REG(hw, E1000_EERD, eerd); 541 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ); 542 if (ret_val) 543 break; 544 545 data[i] = (E1000_READ_REG(hw, E1000_EERD) >> 546 E1000_NVM_RW_REG_DATA); 547 } 548 549 out: 550 return (ret_val); 551 } 552 553 /* 554 * e1000_write_nvm_spi - Write to EEPROM using SPI 555 * @hw: pointer to the HW structure 556 * @offset: offset within the EEPROM to be written to 557 * @words: number of words to write 558 * @data: 16 bit word(s) to be written to the EEPROM 559 * 560 * Writes data to EEPROM at offset using SPI interface. 561 * 562 * If e1000_update_nvm_checksum is not called after this function , the 563 * EEPROM will most likely contain an invalid checksum. 564 */ 565 s32 566 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 567 { 568 struct e1000_nvm_info *nvm = &hw->nvm; 569 s32 ret_val; 570 u16 widx = 0; 571 572 DEBUGFUNC("e1000_write_nvm_spi"); 573 574 /* 575 * A check for invalid values: offset too large, too many words, 576 * and not enough words. 577 */ 578 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 579 (words == 0)) { 580 DEBUGOUT("nvm parameter(s) out of bounds\n"); 581 ret_val = -E1000_ERR_NVM; 582 goto out; 583 } 584 585 ret_val = nvm->ops.acquire(hw); 586 if (ret_val) 587 goto out; 588 589 while (widx < words) { 590 u8 write_opcode = NVM_WRITE_OPCODE_SPI; 591 592 ret_val = e1000_ready_nvm_eeprom(hw); 593 if (ret_val) 594 goto release; 595 596 e1000_standby_nvm(hw); 597 598 /* Send the WRITE ENABLE command (8 bit opcode) */ 599 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI, 600 nvm->opcode_bits); 601 602 e1000_standby_nvm(hw); 603 604 /* 605 * Some SPI eeproms use the 8th address bit embedded in the 606 * opcode 607 */ 608 if ((nvm->address_bits == 8) && (offset >= 128)) 609 write_opcode |= NVM_A8_OPCODE_SPI; 610 611 /* Send the Write command (8-bit opcode + addr) */ 612 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits); 613 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2), 614 nvm->address_bits); 615 616 /* Loop to allow for up to whole page write of eeprom */ 617 while (widx < words) { 618 u16 word_out = data[widx]; 619 word_out = (word_out >> 8) | (word_out << 8); 620 e1000_shift_out_eec_bits(hw, word_out, 16); 621 widx++; 622 623 if ((((offset + widx) * 2) % nvm->page_size) == 0) { 624 e1000_standby_nvm(hw); 625 break; 626 } 627 } 628 } 629 630 msec_delay(10); 631 release: 632 nvm->ops.release(hw); 633 634 out: 635 return (ret_val); 636 } 637 638 /* 639 * e1000_write_nvm_microwire - Writes EEPROM using microwire 640 * @hw: pointer to the HW structure 641 * @offset: offset within the EEPROM to be written to 642 * @words: number of words to write 643 * @data: 16 bit word(s) to be written to the EEPROM 644 * 645 * Writes data to EEPROM at offset using microwire interface. 646 * 647 * If e1000_update_nvm_checksum is not called after this function , the 648 * EEPROM will most likely contain an invalid checksum. 649 */ 650 s32 651 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words, 652 u16 *data) 653 { 654 struct e1000_nvm_info *nvm = &hw->nvm; 655 s32 ret_val; 656 u32 eecd; 657 u16 words_written = 0; 658 u16 widx = 0; 659 660 DEBUGFUNC("e1000_write_nvm_microwire"); 661 662 /* 663 * A check for invalid values: offset too large, too many words, 664 * and not enough words. 665 */ 666 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 667 (words == 0)) { 668 DEBUGOUT("nvm parameter(s) out of bounds\n"); 669 ret_val = -E1000_ERR_NVM; 670 goto out; 671 } 672 673 ret_val = nvm->ops.acquire(hw); 674 if (ret_val) 675 goto out; 676 677 ret_val = e1000_ready_nvm_eeprom(hw); 678 if (ret_val) 679 goto release; 680 681 e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE, 682 (u16)(nvm->opcode_bits + 2)); 683 684 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2)); 685 686 e1000_standby_nvm(hw); 687 688 while (words_written < words) { 689 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE, 690 nvm->opcode_bits); 691 692 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written), 693 nvm->address_bits); 694 695 e1000_shift_out_eec_bits(hw, data[words_written], 16); 696 697 e1000_standby_nvm(hw); 698 699 for (widx = 0; widx < 200; widx++) { 700 eecd = E1000_READ_REG(hw, E1000_EECD); 701 if (eecd & E1000_EECD_DO) 702 break; 703 usec_delay(50); 704 } 705 706 if (widx == 200) { 707 DEBUGOUT("NVM Write did not complete\n"); 708 ret_val = -E1000_ERR_NVM; 709 goto release; 710 } 711 712 e1000_standby_nvm(hw); 713 714 words_written++; 715 } 716 717 e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE, 718 (u16)(nvm->opcode_bits + 2)); 719 720 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2)); 721 722 release: 723 nvm->ops.release(hw); 724 725 out: 726 return (ret_val); 727 } 728 729 /* 730 * e1000_read_pba_num_generic - Read device part number 731 * @hw: pointer to the HW structure 732 * @pba_num: pointer to device part number 733 * 734 * Reads the product board assembly (PBA) number from the EEPROM and stores 735 * the value in pba_num. 736 */ 737 s32 738 e1000_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num) 739 { 740 s32 ret_val; 741 u16 nvm_data; 742 743 DEBUGFUNC("e1000_read_pba_num_generic"); 744 745 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data); 746 if (ret_val) { 747 DEBUGOUT("NVM Read Error\n"); 748 goto out; 749 } 750 *pba_num = (u32)(nvm_data << 16); 751 752 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data); 753 if (ret_val) { 754 DEBUGOUT("NVM Read Error\n"); 755 goto out; 756 } 757 *pba_num |= nvm_data; 758 759 out: 760 return (ret_val); 761 } 762 763 /* 764 * e1000_read_mac_addr_generic - Read device MAC address 765 * @hw: pointer to the HW structure 766 * 767 * Reads the device MAC address from the EEPROM and stores the value. 768 * Since devices with two ports use the same EEPROM, we increment the 769 * last bit in the MAC address for the second port. 770 */ 771 s32 772 e1000_read_mac_addr_generic(struct e1000_hw *hw) 773 { 774 u32 rar_high; 775 u32 rar_low; 776 u16 i; 777 778 rar_high = E1000_READ_REG(hw, E1000_RAH(0)); 779 rar_low = E1000_READ_REG(hw, E1000_RAL(0)); 780 781 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++) 782 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8)); 783 784 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++) 785 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8)); 786 787 for (i = 0; i < ETH_ADDR_LEN; i++) 788 hw->mac.addr[i] = hw->mac.perm_addr[i]; 789 790 return (E1000_SUCCESS); 791 } 792 793 /* 794 * e1000_validate_nvm_checksum_generic - Validate EEPROM checksum 795 * @hw: pointer to the HW structure 796 * 797 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM 798 * and then verifies that the sum of the EEPROM is equal to 0xBABA. 799 */ 800 s32 801 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw) 802 { 803 s32 ret_val = E1000_SUCCESS; 804 u16 checksum = 0; 805 u16 i, nvm_data; 806 807 DEBUGFUNC("e1000_validate_nvm_checksum_generic"); 808 809 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { 810 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data); 811 if (ret_val) { 812 DEBUGOUT("NVM Read Error\n"); 813 goto out; 814 } 815 checksum += nvm_data; 816 } 817 818 if (checksum != (u16) NVM_SUM) { 819 DEBUGOUT("NVM Checksum Invalid\n"); 820 ret_val = -E1000_ERR_NVM; 821 goto out; 822 } 823 824 out: 825 return (ret_val); 826 } 827 828 /* 829 * e1000_update_nvm_checksum_generic - Update EEPROM checksum 830 * @hw: pointer to the HW structure 831 * 832 * Updates the EEPROM checksum by reading/adding each word of the EEPROM 833 * up to the checksum. Then calculates the EEPROM checksum and writes the 834 * value to the EEPROM. 835 */ 836 s32 837 e1000_update_nvm_checksum_generic(struct e1000_hw *hw) 838 { 839 s32 ret_val; 840 u16 checksum = 0; 841 u16 i, nvm_data; 842 843 DEBUGFUNC("e1000_update_nvm_checksum"); 844 845 for (i = 0; i < NVM_CHECKSUM_REG; i++) { 846 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data); 847 if (ret_val) { 848 DEBUGOUT("NVM Read Error while updating checksum.\n"); 849 goto out; 850 } 851 checksum += nvm_data; 852 } 853 checksum = (u16) NVM_SUM - checksum; 854 ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum); 855 if (ret_val) 856 DEBUGOUT("NVM Write Error while updating checksum.\n"); 857 858 out: 859 return (ret_val); 860 } 861 862 /* 863 * e1000_reload_nvm_generic - Reloads EEPROM 864 * @hw: pointer to the HW structure 865 * 866 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the 867 * extended control register. 868 */ 869 void 870 e1000_reload_nvm_generic(struct e1000_hw *hw) 871 { 872 u32 ctrl_ext; 873 874 DEBUGFUNC("e1000_reload_nvm_generic"); 875 876 usec_delay(10); 877 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT); 878 ctrl_ext |= E1000_CTRL_EXT_EE_RST; 879 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext); 880 E1000_WRITE_FLUSH(hw); 881 } 882