00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 FILE_LICENCE ( GPL2_ONLY );
00029
00030 #include "igb.h"
00031
00032 static void igb_stop_nvm(struct e1000_hw *hw);
00033 static void igb_reload_nvm_generic(struct e1000_hw *hw);
00034
00035
00036
00037
00038
00039
00040
00041 void igb_init_nvm_ops_generic(struct e1000_hw *hw)
00042 {
00043 struct e1000_nvm_info *nvm = &hw->nvm;
00044 DEBUGFUNC("igb_init_nvm_ops_generic");
00045
00046
00047 nvm->ops.reload = igb_reload_nvm_generic;
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057 static void igb_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
00058 {
00059 *eecd = *eecd | E1000_EECD_SK;
00060 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
00061 E1000_WRITE_FLUSH(hw);
00062 usec_delay(hw->nvm.delay_usec);
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072 static void igb_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
00073 {
00074 *eecd = *eecd & ~E1000_EECD_SK;
00075 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
00076 E1000_WRITE_FLUSH(hw);
00077 usec_delay(hw->nvm.delay_usec);
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 static void igb_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
00091 {
00092 struct e1000_nvm_info *nvm = &hw->nvm;
00093 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
00094 u32 mask;
00095
00096 DEBUGFUNC("igb_shift_out_eec_bits");
00097
00098 mask = 0x01 << (count - 1);
00099 if (nvm->type == e1000_nvm_eeprom_spi)
00100 eecd |= E1000_EECD_DO;
00101
00102 do {
00103 eecd &= ~E1000_EECD_DI;
00104
00105 if (data & mask)
00106 eecd |= E1000_EECD_DI;
00107
00108 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00109 E1000_WRITE_FLUSH(hw);
00110
00111 usec_delay(nvm->delay_usec);
00112
00113 igb_raise_eec_clk(hw, &eecd);
00114 igb_lower_eec_clk(hw, &eecd);
00115
00116 mask >>= 1;
00117 } while (mask);
00118
00119 eecd &= ~E1000_EECD_DI;
00120 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 static u16 igb_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
00135 {
00136 u32 eecd;
00137 u32 i;
00138 u16 data;
00139
00140 DEBUGFUNC("igb_shift_in_eec_bits");
00141
00142 eecd = E1000_READ_REG(hw, E1000_EECD);
00143
00144 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
00145 data = 0;
00146
00147 for (i = 0; i < count; i++) {
00148 data <<= 1;
00149 igb_raise_eec_clk(hw, &eecd);
00150
00151 eecd = E1000_READ_REG(hw, E1000_EECD);
00152
00153 eecd &= ~E1000_EECD_DI;
00154 if (eecd & E1000_EECD_DO)
00155 data |= 1;
00156
00157 igb_lower_eec_clk(hw, &eecd);
00158 }
00159
00160 return data;
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 s32 igb_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
00172 {
00173 u32 attempts = 100000;
00174 u32 i, reg = 0;
00175 s32 ret_val = -E1000_ERR_NVM;
00176
00177 DEBUGFUNC("igb_poll_eerd_eewr_done");
00178
00179 for (i = 0; i < attempts; i++) {
00180 if (ee_reg == E1000_NVM_POLL_READ)
00181 reg = E1000_READ_REG(hw, E1000_EERD);
00182 else
00183 reg = E1000_READ_REG(hw, E1000_EEWR);
00184
00185 if (reg & E1000_NVM_RW_REG_DONE) {
00186 ret_val = E1000_SUCCESS;
00187 break;
00188 }
00189
00190 usec_delay(5);
00191 }
00192
00193 return ret_val;
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 s32 igb_acquire_nvm_generic(struct e1000_hw *hw)
00205 {
00206 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
00207 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
00208 s32 ret_val = E1000_SUCCESS;
00209
00210 DEBUGFUNC("igb_acquire_nvm_generic");
00211
00212 E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
00213 eecd = E1000_READ_REG(hw, E1000_EECD);
00214
00215 while (timeout) {
00216 if (eecd & E1000_EECD_GNT)
00217 break;
00218 usec_delay(5);
00219 eecd = E1000_READ_REG(hw, E1000_EECD);
00220 timeout--;
00221 }
00222
00223 if (!timeout) {
00224 eecd &= ~E1000_EECD_REQ;
00225 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00226 DEBUGOUT("Could not acquire NVM grant\n");
00227 ret_val = -E1000_ERR_NVM;
00228 }
00229
00230 return ret_val;
00231 }
00232
00233
00234
00235
00236
00237
00238
00239 static void igb_standby_nvm(struct e1000_hw *hw)
00240 {
00241 struct e1000_nvm_info *nvm = &hw->nvm;
00242 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
00243
00244 DEBUGFUNC("igb_standby_nvm");
00245
00246 if (nvm->type == e1000_nvm_eeprom_spi) {
00247
00248 eecd |= E1000_EECD_CS;
00249 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00250 E1000_WRITE_FLUSH(hw);
00251 usec_delay(nvm->delay_usec);
00252 eecd &= ~E1000_EECD_CS;
00253 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00254 E1000_WRITE_FLUSH(hw);
00255 usec_delay(nvm->delay_usec);
00256 }
00257 }
00258
00259
00260
00261
00262
00263
00264
00265 static void igb_stop_nvm(struct e1000_hw *hw)
00266 {
00267 u32 eecd;
00268
00269 DEBUGFUNC("igb_stop_nvm");
00270
00271 eecd = E1000_READ_REG(hw, E1000_EECD);
00272 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
00273
00274 eecd |= E1000_EECD_CS;
00275 igb_lower_eec_clk(hw, &eecd);
00276 }
00277 }
00278
00279
00280
00281
00282
00283
00284
00285 void igb_release_nvm_generic(struct e1000_hw *hw)
00286 {
00287 u32 eecd;
00288
00289 DEBUGFUNC("igb_release_nvm_generic");
00290
00291 igb_stop_nvm(hw);
00292
00293 eecd = E1000_READ_REG(hw, E1000_EECD);
00294 eecd &= ~E1000_EECD_REQ;
00295 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00296 }
00297
00298
00299
00300
00301
00302
00303
00304 static s32 igb_ready_nvm_eeprom(struct e1000_hw *hw)
00305 {
00306 struct e1000_nvm_info *nvm = &hw->nvm;
00307 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
00308 s32 ret_val = E1000_SUCCESS;
00309 u16 timeout = 0;
00310 u8 spi_stat_reg;
00311
00312 DEBUGFUNC("igb_ready_nvm_eeprom");
00313
00314 if (nvm->type == e1000_nvm_eeprom_spi) {
00315
00316 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
00317 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00318 usec_delay(1);
00319 timeout = NVM_MAX_RETRY_SPI;
00320
00321
00322
00323
00324
00325
00326
00327 while (timeout) {
00328 igb_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
00329 hw->nvm.opcode_bits);
00330 spi_stat_reg = (u8)igb_shift_in_eec_bits(hw, 8);
00331 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
00332 break;
00333
00334 usec_delay(5);
00335 igb_standby_nvm(hw);
00336 timeout--;
00337 }
00338
00339 if (!timeout) {
00340 DEBUGOUT("SPI NVM Status error\n");
00341 ret_val = -E1000_ERR_NVM;
00342 goto out;
00343 }
00344 }
00345
00346 out:
00347 return ret_val;
00348 }
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 s32 igb_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
00360 {
00361 struct e1000_nvm_info *nvm = &hw->nvm;
00362 u32 i, eerd = 0;
00363 s32 ret_val = E1000_SUCCESS;
00364
00365 DEBUGFUNC("igb_read_nvm_eerd");
00366
00367
00368
00369
00370
00371 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
00372 (words == 0)) {
00373 DEBUGOUT("nvm parameter(s) out of bounds\n");
00374 ret_val = -E1000_ERR_NVM;
00375 goto out;
00376 }
00377
00378 for (i = 0; i < words; i++) {
00379 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
00380 E1000_NVM_RW_REG_START;
00381
00382 E1000_WRITE_REG(hw, E1000_EERD, eerd);
00383 ret_val = igb_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
00384 if (ret_val)
00385 break;
00386
00387 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
00388 E1000_NVM_RW_REG_DATA);
00389 }
00390
00391 out:
00392 return ret_val;
00393 }
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 s32 igb_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
00408 {
00409 struct e1000_nvm_info *nvm = &hw->nvm;
00410 s32 ret_val;
00411 u16 widx = 0;
00412
00413 DEBUGFUNC("igb_write_nvm_spi");
00414
00415
00416
00417
00418
00419 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
00420 (words == 0)) {
00421 DEBUGOUT("nvm parameter(s) out of bounds\n");
00422 ret_val = -E1000_ERR_NVM;
00423 goto out;
00424 }
00425
00426 ret_val = nvm->ops.acquire(hw);
00427 if (ret_val)
00428 goto out;
00429
00430 while (widx < words) {
00431 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
00432
00433 ret_val = igb_ready_nvm_eeprom(hw);
00434 if (ret_val)
00435 goto release;
00436
00437 igb_standby_nvm(hw);
00438
00439
00440 igb_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
00441 nvm->opcode_bits);
00442
00443 igb_standby_nvm(hw);
00444
00445
00446
00447
00448
00449 if ((nvm->address_bits == 8) && (offset >= 128))
00450 write_opcode |= NVM_A8_OPCODE_SPI;
00451
00452
00453 igb_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
00454 igb_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
00455 nvm->address_bits);
00456
00457
00458 while (widx < words) {
00459 u16 word_out = data[widx];
00460 word_out = (word_out >> 8) | (word_out << 8);
00461 igb_shift_out_eec_bits(hw, word_out, 16);
00462 widx++;
00463
00464 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
00465 igb_standby_nvm(hw);
00466 break;
00467 }
00468 }
00469 }
00470
00471 msec_delay(10);
00472 release:
00473 nvm->ops.release(hw);
00474
00475 out:
00476 return ret_val;
00477 }
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487 s32 igb_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num)
00488 {
00489 s32 ret_val;
00490 u16 nvm_data;
00491
00492 DEBUGFUNC("igb_read_pba_num_generic");
00493
00494 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
00495 if (ret_val) {
00496 DEBUGOUT("NVM Read Error\n");
00497 goto out;
00498 }
00499 *pba_num = (u32)(nvm_data << 16);
00500
00501 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
00502 if (ret_val) {
00503 DEBUGOUT("NVM Read Error\n");
00504 goto out;
00505 }
00506 *pba_num |= nvm_data;
00507
00508 out:
00509 return ret_val;
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520 s32 igb_read_mac_addr_generic(struct e1000_hw *hw)
00521 {
00522 u32 rar_high;
00523 u32 rar_low;
00524 u16 i;
00525
00526 rar_high = E1000_READ_REG(hw, E1000_RAH(0));
00527 rar_low = E1000_READ_REG(hw, E1000_RAL(0));
00528
00529 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
00530 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
00531
00532 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
00533 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
00534
00535 for (i = 0; i < ETH_ADDR_LEN; i++)
00536 hw->mac.addr[i] = hw->mac.perm_addr[i];
00537
00538 return E1000_SUCCESS;
00539 }
00540
00541
00542
00543
00544
00545
00546
00547
00548 s32 igb_validate_nvm_checksum_generic(struct e1000_hw *hw)
00549 {
00550 s32 ret_val = E1000_SUCCESS;
00551 u16 checksum = 0;
00552 u16 i, nvm_data;
00553
00554 DEBUGFUNC("igb_validate_nvm_checksum_generic");
00555
00556 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
00557 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
00558 if (ret_val) {
00559 DEBUGOUT("NVM Read Error\n");
00560 goto out;
00561 }
00562 checksum += nvm_data;
00563 }
00564
00565 if (checksum != (u16) NVM_SUM) {
00566 DEBUGOUT("NVM Checksum Invalid\n");
00567 ret_val = -E1000_ERR_NVM;
00568 goto out;
00569 }
00570
00571 out:
00572 return ret_val;
00573 }
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583 s32 igb_update_nvm_checksum_generic(struct e1000_hw *hw)
00584 {
00585 s32 ret_val;
00586 u16 checksum = 0;
00587 u16 i, nvm_data;
00588
00589 DEBUGFUNC("igb_update_nvm_checksum");
00590
00591 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
00592 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
00593 if (ret_val) {
00594 DEBUGOUT("NVM Read Error while updating checksum.\n");
00595 goto out;
00596 }
00597 checksum += nvm_data;
00598 }
00599 checksum = (u16) NVM_SUM - checksum;
00600 ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
00601 if (ret_val) {
00602 DEBUGOUT("NVM Write Error while updating checksum.\n");
00603 }
00604 out:
00605 return ret_val;
00606 }
00607
00608
00609
00610
00611
00612
00613
00614
00615 static void igb_reload_nvm_generic(struct e1000_hw *hw)
00616 {
00617 u32 ctrl_ext;
00618
00619 DEBUGFUNC("igb_reload_nvm_generic");
00620
00621 usec_delay(10);
00622 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
00623 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
00624 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
00625 E1000_WRITE_FLUSH(hw);
00626 }
00627