Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2020 Intel Corporation
3 : : */
4 : :
5 : : #include "e1000_api.h"
6 : :
7 : : STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw);
8 : :
9 : : /**
10 : : * e1000_init_nvm_ops_generic - Initialize NVM function pointers
11 : : * @hw: pointer to the HW structure
12 : : *
13 : : * Setups up the function pointers to no-op functions
14 : : **/
15 : 0 : void e1000_init_nvm_ops_generic(struct e1000_hw *hw)
16 : : {
17 : : struct e1000_nvm_info *nvm = &hw->nvm;
18 : 0 : DEBUGFUNC("e1000_init_nvm_ops_generic");
19 : :
20 : : /* Initialize function pointers */
21 : 0 : nvm->ops.init_params = e1000_null_ops_generic;
22 : 0 : nvm->ops.acquire = e1000_null_ops_generic;
23 : 0 : nvm->ops.read = e1000_null_read_nvm;
24 : 0 : nvm->ops.release = e1000_null_nvm_generic;
25 : 0 : nvm->ops.reload = e1000_reload_nvm_generic;
26 : 0 : nvm->ops.update = e1000_null_ops_generic;
27 : 0 : nvm->ops.valid_led_default = e1000_null_led_default;
28 : 0 : nvm->ops.validate = e1000_null_ops_generic;
29 : 0 : nvm->ops.write = e1000_null_write_nvm;
30 : 0 : }
31 : :
32 : : /**
33 : : * e1000_null_nvm_read - No-op function, return 0
34 : : * @hw: pointer to the HW structure
35 : : * @a: dummy variable
36 : : * @b: dummy variable
37 : : * @c: dummy variable
38 : : **/
39 : 0 : s32 e1000_null_read_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
40 : : u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
41 : : u16 E1000_UNUSEDARG *c)
42 : : {
43 : 0 : DEBUGFUNC("e1000_null_read_nvm");
44 : : UNREFERENCED_4PARAMETER(hw, a, b, c);
45 : 0 : return E1000_SUCCESS;
46 : : }
47 : :
48 : : /**
49 : : * e1000_null_nvm_generic - No-op function, return void
50 : : * @hw: pointer to the HW structure
51 : : **/
52 : 0 : void e1000_null_nvm_generic(struct e1000_hw E1000_UNUSEDARG *hw)
53 : : {
54 : 0 : DEBUGFUNC("e1000_null_nvm_generic");
55 : : UNREFERENCED_1PARAMETER(hw);
56 : 0 : return;
57 : : }
58 : :
59 : : /**
60 : : * e1000_null_led_default - No-op function, return 0
61 : : * @hw: pointer to the HW structure
62 : : * @data: dummy variable
63 : : **/
64 : 0 : s32 e1000_null_led_default(struct e1000_hw E1000_UNUSEDARG *hw,
65 : : u16 E1000_UNUSEDARG *data)
66 : : {
67 : 0 : DEBUGFUNC("e1000_null_led_default");
68 : : UNREFERENCED_2PARAMETER(hw, data);
69 : 0 : return E1000_SUCCESS;
70 : : }
71 : :
72 : : /**
73 : : * e1000_null_write_nvm - No-op function, return 0
74 : : * @hw: pointer to the HW structure
75 : : * @a: dummy variable
76 : : * @b: dummy variable
77 : : * @c: dummy variable
78 : : **/
79 : 0 : s32 e1000_null_write_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
80 : : u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
81 : : u16 E1000_UNUSEDARG *c)
82 : : {
83 : 0 : DEBUGFUNC("e1000_null_write_nvm");
84 : : UNREFERENCED_4PARAMETER(hw, a, b, c);
85 : 0 : return E1000_SUCCESS;
86 : : }
87 : :
88 : : /**
89 : : * e1000_raise_eec_clk - Raise EEPROM clock
90 : : * @hw: pointer to the HW structure
91 : : * @eecd: pointer to the EEPROM
92 : : *
93 : : * Enable/Raise the EEPROM clock bit.
94 : : **/
95 : : STATIC void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
96 : : {
97 : 0 : *eecd = *eecd | E1000_EECD_SK;
98 : 0 : E1000_WRITE_REG(hw, E1000_EECD, *eecd);
99 : 0 : E1000_WRITE_FLUSH(hw);
100 : 0 : usec_delay(hw->nvm.delay_usec);
101 : : }
102 : :
103 : : /**
104 : : * e1000_lower_eec_clk - Lower EEPROM clock
105 : : * @hw: pointer to the HW structure
106 : : * @eecd: pointer to the EEPROM
107 : : *
108 : : * Clear/Lower the EEPROM clock bit.
109 : : **/
110 : : STATIC void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
111 : : {
112 : 0 : *eecd = *eecd & ~E1000_EECD_SK;
113 : 0 : E1000_WRITE_REG(hw, E1000_EECD, *eecd);
114 : 0 : E1000_WRITE_FLUSH(hw);
115 : 0 : usec_delay(hw->nvm.delay_usec);
116 : 0 : }
117 : :
118 : : /**
119 : : * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
120 : : * @hw: pointer to the HW structure
121 : : * @data: data to send to the EEPROM
122 : : * @count: number of bits to shift out
123 : : *
124 : : * We need to shift 'count' bits out to the EEPROM. So, the value in the
125 : : * "data" parameter will be shifted out to the EEPROM one bit at a time.
126 : : * In order to do this, "data" must be broken down into bits.
127 : : **/
128 : 0 : STATIC void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
129 : : {
130 : : struct e1000_nvm_info *nvm = &hw->nvm;
131 : 0 : u32 eecd = E1000_READ_REG(hw, E1000_EECD);
132 : : u32 mask;
133 : :
134 : 0 : DEBUGFUNC("e1000_shift_out_eec_bits");
135 : :
136 : 0 : mask = 0x01 << (count - 1);
137 [ # # ]: 0 : if (nvm->type == e1000_nvm_eeprom_microwire)
138 : 0 : eecd &= ~E1000_EECD_DO;
139 : : else
140 [ # # ]: 0 : if (nvm->type == e1000_nvm_eeprom_spi)
141 : 0 : eecd |= E1000_EECD_DO;
142 : :
143 : : do {
144 : 0 : eecd &= ~E1000_EECD_DI;
145 : :
146 [ # # ]: 0 : if (data & mask)
147 : 0 : eecd |= E1000_EECD_DI;
148 : :
149 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
150 : 0 : E1000_WRITE_FLUSH(hw);
151 : :
152 : 0 : usec_delay(nvm->delay_usec);
153 : :
154 : : e1000_raise_eec_clk(hw, &eecd);
155 : : e1000_lower_eec_clk(hw, &eecd);
156 : :
157 : 0 : mask >>= 1;
158 [ # # ]: 0 : } while (mask);
159 : :
160 : 0 : eecd &= ~E1000_EECD_DI;
161 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
162 : 0 : }
163 : :
164 : : /**
165 : : * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
166 : : * @hw: pointer to the HW structure
167 : : * @count: number of bits to shift in
168 : : *
169 : : * In order to read a register from the EEPROM, we need to shift 'count' bits
170 : : * in from the EEPROM. Bits are "shifted in" by raising the clock input to
171 : : * the EEPROM (setting the SK bit), and then reading the value of the data out
172 : : * "DO" bit. During this "shifting in" process the data in "DI" bit should
173 : : * always be clear.
174 : : **/
175 : 0 : STATIC u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
176 : : {
177 : : u32 eecd;
178 : : u32 i;
179 : : u16 data;
180 : :
181 : 0 : DEBUGFUNC("e1000_shift_in_eec_bits");
182 : :
183 : 0 : eecd = E1000_READ_REG(hw, E1000_EECD);
184 : :
185 : 0 : eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
186 : : data = 0;
187 : :
188 [ # # ]: 0 : for (i = 0; i < count; i++) {
189 : 0 : data <<= 1;
190 : : e1000_raise_eec_clk(hw, &eecd);
191 : :
192 : 0 : eecd = E1000_READ_REG(hw, E1000_EECD);
193 : :
194 : : eecd &= ~E1000_EECD_DI;
195 [ # # ]: 0 : if (eecd & E1000_EECD_DO)
196 : 0 : data |= 1;
197 : :
198 : : e1000_lower_eec_clk(hw, &eecd);
199 : : }
200 : :
201 : 0 : return data;
202 : : }
203 : :
204 : : /**
205 : : * e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion
206 : : * @hw: pointer to the HW structure
207 : : * @ee_reg: EEPROM flag for polling
208 : : *
209 : : * Polls the EEPROM status bit for either read or write completion based
210 : : * upon the value of 'ee_reg'.
211 : : **/
212 : 0 : s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
213 : : {
214 : : u32 attempts = 100000;
215 : : u32 i, reg = 0;
216 : :
217 : 0 : DEBUGFUNC("e1000_poll_eerd_eewr_done");
218 : :
219 [ # # ]: 0 : for (i = 0; i < attempts; i++) {
220 [ # # ]: 0 : if (ee_reg == E1000_NVM_POLL_READ)
221 : 0 : reg = E1000_READ_REG(hw, E1000_EERD);
222 : : else
223 : 0 : reg = E1000_READ_REG(hw, E1000_EEWR);
224 : :
225 [ # # ]: 0 : if (reg & E1000_NVM_RW_REG_DONE)
226 : : return E1000_SUCCESS;
227 : :
228 : 0 : usec_delay(5);
229 : : }
230 : :
231 : : return -E1000_ERR_NVM;
232 : : }
233 : :
234 : : /**
235 : : * e1000_acquire_nvm_generic - Generic request for access to EEPROM
236 : : * @hw: pointer to the HW structure
237 : : *
238 : : * Set the EEPROM access request bit and wait for EEPROM access grant bit.
239 : : * Return successful if access grant bit set, else clear the request for
240 : : * EEPROM access and return -E1000_ERR_NVM (-1).
241 : : **/
242 : 0 : s32 e1000_acquire_nvm_generic(struct e1000_hw *hw)
243 : : {
244 : 0 : u32 eecd = E1000_READ_REG(hw, E1000_EECD);
245 : : s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
246 : :
247 : 0 : DEBUGFUNC("e1000_acquire_nvm_generic");
248 : :
249 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
250 : 0 : eecd = E1000_READ_REG(hw, E1000_EECD);
251 : :
252 [ # # ]: 0 : while (timeout) {
253 [ # # ]: 0 : if (eecd & E1000_EECD_GNT)
254 : : break;
255 : 0 : usec_delay(5);
256 : 0 : eecd = E1000_READ_REG(hw, E1000_EECD);
257 : 0 : timeout--;
258 : : }
259 : :
260 [ # # ]: 0 : if (!timeout) {
261 : 0 : eecd &= ~E1000_EECD_REQ;
262 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
263 : 0 : DEBUGOUT("Could not acquire NVM grant\n");
264 : 0 : return -E1000_ERR_NVM;
265 : : }
266 : :
267 : : return E1000_SUCCESS;
268 : : }
269 : :
270 : : /**
271 : : * e1000_standby_nvm - Return EEPROM to standby state
272 : : * @hw: pointer to the HW structure
273 : : *
274 : : * Return the EEPROM to a standby state.
275 : : **/
276 : 0 : STATIC void e1000_standby_nvm(struct e1000_hw *hw)
277 : : {
278 : : struct e1000_nvm_info *nvm = &hw->nvm;
279 : 0 : u32 eecd = E1000_READ_REG(hw, E1000_EECD);
280 : :
281 : 0 : DEBUGFUNC("e1000_standby_nvm");
282 : :
283 [ # # ]: 0 : if (nvm->type == e1000_nvm_eeprom_microwire) {
284 : 0 : eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
285 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
286 : 0 : E1000_WRITE_FLUSH(hw);
287 : 0 : usec_delay(nvm->delay_usec);
288 : :
289 : : e1000_raise_eec_clk(hw, &eecd);
290 : :
291 : : /* Select EEPROM */
292 : 0 : eecd |= E1000_EECD_CS;
293 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
294 : 0 : E1000_WRITE_FLUSH(hw);
295 : 0 : usec_delay(nvm->delay_usec);
296 : :
297 : : e1000_lower_eec_clk(hw, &eecd);
298 [ # # ]: 0 : } else if (nvm->type == e1000_nvm_eeprom_spi) {
299 : : /* Toggle CS to flush commands */
300 : 0 : eecd |= E1000_EECD_CS;
301 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
302 : 0 : E1000_WRITE_FLUSH(hw);
303 : 0 : usec_delay(nvm->delay_usec);
304 : : eecd &= ~E1000_EECD_CS;
305 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
306 : 0 : E1000_WRITE_FLUSH(hw);
307 : 0 : usec_delay(nvm->delay_usec);
308 : : }
309 : 0 : }
310 : :
311 : : /**
312 : : * e1000_stop_nvm - Terminate EEPROM command
313 : : * @hw: pointer to the HW structure
314 : : *
315 : : * Terminates the current command by inverting the EEPROM's chip select pin.
316 : : **/
317 : 0 : void e1000_stop_nvm(struct e1000_hw *hw)
318 : : {
319 : : u32 eecd;
320 : :
321 : 0 : DEBUGFUNC("e1000_stop_nvm");
322 : :
323 : 0 : eecd = E1000_READ_REG(hw, E1000_EECD);
324 [ # # ]: 0 : if (hw->nvm.type == e1000_nvm_eeprom_spi) {
325 : : /* Pull CS high */
326 : : eecd |= E1000_EECD_CS;
327 : : e1000_lower_eec_clk(hw, &eecd);
328 [ # # ]: 0 : } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
329 : : /* CS on Microwire is active-high */
330 : 0 : eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
331 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
332 : : e1000_raise_eec_clk(hw, &eecd);
333 : : e1000_lower_eec_clk(hw, &eecd);
334 : : }
335 : 0 : }
336 : :
337 : : /**
338 : : * e1000_release_nvm_generic - Release exclusive access to EEPROM
339 : : * @hw: pointer to the HW structure
340 : : *
341 : : * Stop any current commands to the EEPROM and clear the EEPROM request bit.
342 : : **/
343 : 0 : void e1000_release_nvm_generic(struct e1000_hw *hw)
344 : : {
345 : : u32 eecd;
346 : :
347 : 0 : DEBUGFUNC("e1000_release_nvm_generic");
348 : :
349 : 0 : e1000_stop_nvm(hw);
350 : :
351 : 0 : eecd = E1000_READ_REG(hw, E1000_EECD);
352 : 0 : eecd &= ~E1000_EECD_REQ;
353 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
354 : 0 : }
355 : :
356 : : /**
357 : : * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
358 : : * @hw: pointer to the HW structure
359 : : *
360 : : * Setups the EEPROM for reading and writing.
361 : : **/
362 : 0 : STATIC s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
363 : : {
364 : : struct e1000_nvm_info *nvm = &hw->nvm;
365 : 0 : u32 eecd = E1000_READ_REG(hw, E1000_EECD);
366 : : u8 spi_stat_reg;
367 : :
368 : 0 : DEBUGFUNC("e1000_ready_nvm_eeprom");
369 : :
370 [ # # ]: 0 : if (nvm->type == e1000_nvm_eeprom_microwire) {
371 : : /* Clear SK and DI */
372 : 0 : eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
373 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
374 : : /* Set CS */
375 : 0 : eecd |= E1000_EECD_CS;
376 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
377 [ # # ]: 0 : } else if (nvm->type == e1000_nvm_eeprom_spi) {
378 : : u16 timeout = NVM_MAX_RETRY_SPI;
379 : :
380 : : /* Clear SK and CS */
381 : 0 : eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
382 : 0 : E1000_WRITE_REG(hw, E1000_EECD, eecd);
383 : 0 : E1000_WRITE_FLUSH(hw);
384 : 0 : usec_delay(1);
385 : :
386 : : /* Read "Status Register" repeatedly until the LSB is cleared.
387 : : * The EEPROM will signal that the command has been completed
388 : : * by clearing bit 0 of the internal status register. If it's
389 : : * not cleared within 'timeout', then error out.
390 : : */
391 [ # # ]: 0 : while (timeout) {
392 : 0 : e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
393 : 0 : hw->nvm.opcode_bits);
394 : 0 : spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
395 [ # # ]: 0 : if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
396 : : break;
397 : :
398 : 0 : usec_delay(5);
399 : 0 : e1000_standby_nvm(hw);
400 : 0 : timeout--;
401 : : }
402 : :
403 [ # # ]: 0 : if (!timeout) {
404 : 0 : DEBUGOUT("SPI NVM Status error\n");
405 : 0 : return -E1000_ERR_NVM;
406 : : }
407 : : }
408 : :
409 : : return E1000_SUCCESS;
410 : : }
411 : :
412 : : /**
413 : : * e1000_read_nvm_spi - Read EEPROM's using SPI
414 : : * @hw: pointer to the HW structure
415 : : * @offset: offset of word in the EEPROM to read
416 : : * @words: number of words to read
417 : : * @data: word read from the EEPROM
418 : : *
419 : : * Reads a 16 bit word from the EEPROM.
420 : : **/
421 : 0 : s32 e1000_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
422 : : {
423 : : struct e1000_nvm_info *nvm = &hw->nvm;
424 : : u32 i = 0;
425 : : s32 ret_val;
426 : : u16 word_in;
427 : : u8 read_opcode = NVM_READ_OPCODE_SPI;
428 : :
429 : 0 : DEBUGFUNC("e1000_read_nvm_spi");
430 : :
431 : : /* A check for invalid values: offset too large, too many words,
432 : : * and not enough words.
433 : : */
434 [ # # # # : 0 : if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
# # ]
435 : : (words == 0)) {
436 : 0 : DEBUGOUT("nvm parameter(s) out of bounds\n");
437 : 0 : return -E1000_ERR_NVM;
438 : : }
439 : :
440 : 0 : ret_val = nvm->ops.acquire(hw);
441 [ # # ]: 0 : if (ret_val)
442 : : return ret_val;
443 : :
444 : 0 : ret_val = e1000_ready_nvm_eeprom(hw);
445 [ # # ]: 0 : if (ret_val)
446 : 0 : goto release;
447 : :
448 : 0 : e1000_standby_nvm(hw);
449 : :
450 [ # # # # ]: 0 : if ((nvm->address_bits == 8) && (offset >= 128))
451 : : read_opcode |= NVM_A8_OPCODE_SPI;
452 : :
453 : : /* Send the READ command (opcode + addr) */
454 : 0 : e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
455 : 0 : e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
456 : :
457 : : /* Read the data. SPI NVMs increment the address with each byte
458 : : * read and will roll over if reading beyond the end. This allows
459 : : * us to read the whole NVM from any offset
460 : : */
461 [ # # ]: 0 : for (i = 0; i < words; i++) {
462 : 0 : word_in = e1000_shift_in_eec_bits(hw, 16);
463 : 0 : data[i] = (word_in >> 8) | (word_in << 8);
464 : : }
465 : :
466 : 0 : release:
467 : 0 : nvm->ops.release(hw);
468 : :
469 : 0 : return ret_val;
470 : : }
471 : :
472 : : /**
473 : : * e1000_read_nvm_microwire - Reads EEPROM's using microwire
474 : : * @hw: pointer to the HW structure
475 : : * @offset: offset of word in the EEPROM to read
476 : : * @words: number of words to read
477 : : * @data: word read from the EEPROM
478 : : *
479 : : * Reads a 16 bit word from the EEPROM.
480 : : **/
481 : 0 : s32 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
482 : : u16 *data)
483 : : {
484 : : struct e1000_nvm_info *nvm = &hw->nvm;
485 : : u32 i = 0;
486 : : s32 ret_val;
487 : : u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
488 : :
489 : 0 : DEBUGFUNC("e1000_read_nvm_microwire");
490 : :
491 : : /* A check for invalid values: offset too large, too many words,
492 : : * and not enough words.
493 : : */
494 [ # # # # : 0 : if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
# # ]
495 : : (words == 0)) {
496 : 0 : DEBUGOUT("nvm parameter(s) out of bounds\n");
497 : 0 : return -E1000_ERR_NVM;
498 : : }
499 : :
500 : 0 : ret_val = nvm->ops.acquire(hw);
501 [ # # ]: 0 : if (ret_val)
502 : : return ret_val;
503 : :
504 : 0 : ret_val = e1000_ready_nvm_eeprom(hw);
505 [ # # ]: 0 : if (ret_val)
506 : 0 : goto release;
507 : :
508 [ # # ]: 0 : for (i = 0; i < words; i++) {
509 : : /* Send the READ command (opcode + addr) */
510 : 0 : e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
511 : 0 : e1000_shift_out_eec_bits(hw, (u16)(offset + i),
512 : 0 : nvm->address_bits);
513 : :
514 : : /* Read the data. For microwire, each word requires the
515 : : * overhead of setup and tear-down.
516 : : */
517 : 0 : data[i] = e1000_shift_in_eec_bits(hw, 16);
518 : 0 : e1000_standby_nvm(hw);
519 : : }
520 : :
521 : 0 : release:
522 : 0 : nvm->ops.release(hw);
523 : :
524 : 0 : return ret_val;
525 : : }
526 : :
527 : : /**
528 : : * e1000_read_nvm_eerd - Reads EEPROM using EERD register
529 : : * @hw: pointer to the HW structure
530 : : * @offset: offset of word in the EEPROM to read
531 : : * @words: number of words to read
532 : : * @data: word read from the EEPROM
533 : : *
534 : : * Reads a 16 bit word from the EEPROM using the EERD register.
535 : : **/
536 : 0 : s32 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
537 : : {
538 : : struct e1000_nvm_info *nvm = &hw->nvm;
539 : : u32 i, eerd = 0;
540 : : s32 ret_val = E1000_SUCCESS;
541 : :
542 : 0 : DEBUGFUNC("e1000_read_nvm_eerd");
543 : :
544 : : /* A check for invalid values: offset too large, too many words,
545 : : * too many words for the offset, and not enough words.
546 : : */
547 [ # # # # : 0 : if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
# # ]
548 : : (words == 0)) {
549 : 0 : DEBUGOUT("nvm parameter(s) out of bounds\n");
550 : 0 : return -E1000_ERR_NVM;
551 : : }
552 : :
553 [ # # ]: 0 : for (i = 0; i < words; i++) {
554 : 0 : eerd = ((offset + i) << E1000_NVM_RW_ADDR_SHIFT) +
555 : : E1000_NVM_RW_REG_START;
556 : :
557 : 0 : E1000_WRITE_REG(hw, E1000_EERD, eerd);
558 : 0 : ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
559 [ # # ]: 0 : if (ret_val)
560 : : break;
561 : :
562 : 0 : data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
563 : : E1000_NVM_RW_REG_DATA);
564 : : }
565 : :
566 [ # # ]: 0 : if (ret_val)
567 : 0 : DEBUGOUT1("NVM read error: %d\n", ret_val);
568 : :
569 : : return ret_val;
570 : : }
571 : :
572 : : /**
573 : : * e1000_write_nvm_spi - Write to EEPROM using SPI
574 : : * @hw: pointer to the HW structure
575 : : * @offset: offset within the EEPROM to be written to
576 : : * @words: number of words to write
577 : : * @data: 16 bit word(s) to be written to the EEPROM
578 : : *
579 : : * Writes data to EEPROM at offset using SPI interface.
580 : : *
581 : : * If e1000_update_nvm_checksum is not called after this function , the
582 : : * EEPROM will most likely contain an invalid checksum.
583 : : **/
584 : 0 : s32 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
585 : : {
586 : : struct e1000_nvm_info *nvm = &hw->nvm;
587 : : s32 ret_val = -E1000_ERR_NVM;
588 : : u16 widx = 0;
589 : :
590 : 0 : DEBUGFUNC("e1000_write_nvm_spi");
591 : :
592 : : /* A check for invalid values: offset too large, too many words,
593 : : * and not enough words.
594 : : */
595 [ # # # # : 0 : if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
# # ]
596 : : (words == 0)) {
597 : 0 : DEBUGOUT("nvm parameter(s) out of bounds\n");
598 : 0 : return -E1000_ERR_NVM;
599 : : }
600 : :
601 [ # # ]: 0 : while (widx < words) {
602 : : u8 write_opcode = NVM_WRITE_OPCODE_SPI;
603 : :
604 : 0 : ret_val = nvm->ops.acquire(hw);
605 [ # # ]: 0 : if (ret_val)
606 : 0 : return ret_val;
607 : :
608 : 0 : ret_val = e1000_ready_nvm_eeprom(hw);
609 [ # # ]: 0 : if (ret_val) {
610 : 0 : nvm->ops.release(hw);
611 : 0 : return ret_val;
612 : : }
613 : :
614 : 0 : e1000_standby_nvm(hw);
615 : :
616 : : /* Send the WRITE ENABLE command (8 bit opcode) */
617 : 0 : e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
618 : 0 : nvm->opcode_bits);
619 : :
620 : 0 : e1000_standby_nvm(hw);
621 : :
622 : : /* Some SPI eeproms use the 8th address bit embedded in the
623 : : * opcode
624 : : */
625 [ # # # # ]: 0 : if ((nvm->address_bits == 8) && (offset >= 128))
626 : : write_opcode |= NVM_A8_OPCODE_SPI;
627 : :
628 : : /* Send the Write command (8-bit opcode + addr) */
629 : 0 : e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
630 : 0 : e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
631 : 0 : nvm->address_bits);
632 : :
633 : : /* Loop to allow for up to whole page write of eeprom */
634 [ # # ]: 0 : while (widx < words) {
635 : 0 : u16 word_out = data[widx];
636 : 0 : word_out = (word_out >> 8) | (word_out << 8);
637 : 0 : e1000_shift_out_eec_bits(hw, word_out, 16);
638 : 0 : widx++;
639 : :
640 [ # # ]: 0 : if ((((offset + widx) * 2) % nvm->page_size) == 0) {
641 : 0 : e1000_standby_nvm(hw);
642 : 0 : break;
643 : : }
644 : : }
645 : 0 : msec_delay(10);
646 : 0 : nvm->ops.release(hw);
647 : : }
648 : :
649 : : return ret_val;
650 : : }
651 : :
652 : : /**
653 : : * e1000_write_nvm_microwire - Writes EEPROM using microwire
654 : : * @hw: pointer to the HW structure
655 : : * @offset: offset within the EEPROM to be written to
656 : : * @words: number of words to write
657 : : * @data: 16 bit word(s) to be written to the EEPROM
658 : : *
659 : : * Writes data to EEPROM at offset using microwire interface.
660 : : *
661 : : * If e1000_update_nvm_checksum is not called after this function , the
662 : : * EEPROM will most likely contain an invalid checksum.
663 : : **/
664 : 0 : s32 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
665 : : u16 *data)
666 : : {
667 : : struct e1000_nvm_info *nvm = &hw->nvm;
668 : : s32 ret_val;
669 : : u32 eecd;
670 : : u16 words_written = 0;
671 : : u16 widx = 0;
672 : :
673 : 0 : DEBUGFUNC("e1000_write_nvm_microwire");
674 : :
675 : : /* A check for invalid values: offset too large, too many words,
676 : : * and not enough words.
677 : : */
678 [ # # # # : 0 : if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
# # ]
679 : : (words == 0)) {
680 : 0 : DEBUGOUT("nvm parameter(s) out of bounds\n");
681 : 0 : return -E1000_ERR_NVM;
682 : : }
683 : :
684 : 0 : ret_val = nvm->ops.acquire(hw);
685 [ # # ]: 0 : if (ret_val)
686 : : return ret_val;
687 : :
688 : 0 : ret_val = e1000_ready_nvm_eeprom(hw);
689 [ # # ]: 0 : if (ret_val)
690 : 0 : goto release;
691 : :
692 : 0 : e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
693 : 0 : (u16)(nvm->opcode_bits + 2));
694 : :
695 : 0 : e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
696 : :
697 : 0 : e1000_standby_nvm(hw);
698 : :
699 [ # # ]: 0 : while (words_written < words) {
700 : 0 : e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
701 : 0 : nvm->opcode_bits);
702 : :
703 : 0 : e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
704 : 0 : nvm->address_bits);
705 : :
706 : 0 : e1000_shift_out_eec_bits(hw, data[words_written], 16);
707 : :
708 : 0 : e1000_standby_nvm(hw);
709 : :
710 [ # # ]: 0 : for (widx = 0; widx < 200; widx++) {
711 : 0 : eecd = E1000_READ_REG(hw, E1000_EECD);
712 [ # # ]: 0 : if (eecd & E1000_EECD_DO)
713 : : break;
714 : 0 : usec_delay(50);
715 : : }
716 : :
717 [ # # ]: 0 : if (widx == 200) {
718 : 0 : DEBUGOUT("NVM Write did not complete\n");
719 : : ret_val = -E1000_ERR_NVM;
720 : 0 : goto release;
721 : : }
722 : :
723 : 0 : e1000_standby_nvm(hw);
724 : :
725 : 0 : words_written++;
726 : : }
727 : :
728 : 0 : e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
729 : 0 : (u16)(nvm->opcode_bits + 2));
730 : :
731 : 0 : e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
732 : :
733 : 0 : release:
734 : 0 : nvm->ops.release(hw);
735 : :
736 : 0 : return ret_val;
737 : : }
738 : :
739 : : /**
740 : : * e1000_read_pba_string_generic - Read device part number
741 : : * @hw: pointer to the HW structure
742 : : * @pba_num: pointer to device part number
743 : : * @pba_num_size: size of part number buffer
744 : : *
745 : : * Reads the product board assembly (PBA) number from the EEPROM and stores
746 : : * the value in pba_num.
747 : : **/
748 : 0 : s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num,
749 : : u32 pba_num_size)
750 : : {
751 : : s32 ret_val;
752 : : u16 nvm_data;
753 : : u16 pba_ptr;
754 : : u16 offset;
755 : : u16 length;
756 : :
757 : 0 : DEBUGFUNC("e1000_read_pba_string_generic");
758 : :
759 [ # # ]: 0 : if ((hw->mac.type == e1000_i210 ||
760 [ # # ]: 0 : hw->mac.type == e1000_i211) &&
761 : 0 : !e1000_get_flash_presence_i210(hw)) {
762 : 0 : DEBUGOUT("Flashless no PBA string\n");
763 : 0 : return -E1000_ERR_NVM_PBA_SECTION;
764 : : }
765 : :
766 [ # # ]: 0 : if (pba_num == NULL) {
767 : 0 : DEBUGOUT("PBA string buffer was null\n");
768 : 0 : return -E1000_ERR_INVALID_ARGUMENT;
769 : : }
770 : :
771 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
772 [ # # ]: 0 : if (ret_val) {
773 : 0 : DEBUGOUT("NVM Read Error\n");
774 : 0 : return ret_val;
775 : : }
776 : :
777 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
778 [ # # ]: 0 : if (ret_val) {
779 : 0 : DEBUGOUT("NVM Read Error\n");
780 : 0 : return ret_val;
781 : : }
782 : :
783 : : /* if nvm_data is not ptr guard the PBA must be in legacy format which
784 : : * means pba_ptr is actually our second data word for the PBA number
785 : : * and we can decode it into an ascii string
786 : : */
787 [ # # ]: 0 : if (nvm_data != NVM_PBA_PTR_GUARD) {
788 : 0 : DEBUGOUT("NVM PBA number is not stored as string\n");
789 : :
790 : : /* make sure callers buffer is big enough to store the PBA */
791 [ # # ]: 0 : if (pba_num_size < E1000_PBANUM_LENGTH) {
792 : 0 : DEBUGOUT("PBA string buffer too small\n");
793 : 0 : return E1000_ERR_NO_SPACE;
794 : : }
795 : :
796 : : /* extract hex string from data and pba_ptr */
797 : 0 : pba_num[0] = (nvm_data >> 12) & 0xF;
798 : 0 : pba_num[1] = (nvm_data >> 8) & 0xF;
799 : 0 : pba_num[2] = (nvm_data >> 4) & 0xF;
800 : 0 : pba_num[3] = nvm_data & 0xF;
801 : 0 : pba_num[4] = (pba_ptr >> 12) & 0xF;
802 : 0 : pba_num[5] = (pba_ptr >> 8) & 0xF;
803 : 0 : pba_num[6] = '-';
804 : 0 : pba_num[7] = 0;
805 : 0 : pba_num[8] = (pba_ptr >> 4) & 0xF;
806 : 0 : pba_num[9] = pba_ptr & 0xF;
807 : :
808 : : /* put a null character on the end of our string */
809 : 0 : pba_num[10] = '\0';
810 : :
811 : : /* switch all the data but the '-' to hex char */
812 [ # # ]: 0 : for (offset = 0; offset < 10; offset++) {
813 [ # # ]: 0 : if (pba_num[offset] < 0xA)
814 : 0 : pba_num[offset] += '0';
815 [ # # ]: 0 : else if (pba_num[offset] < 0x10)
816 : 0 : pba_num[offset] += 'A' - 0xA;
817 : : }
818 : :
819 : : return E1000_SUCCESS;
820 : : }
821 : :
822 : 0 : ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
823 [ # # ]: 0 : if (ret_val) {
824 : 0 : DEBUGOUT("NVM Read Error\n");
825 : 0 : return ret_val;
826 : : }
827 : :
828 [ # # ]: 0 : if (length == 0xFFFF || length == 0) {
829 : 0 : DEBUGOUT("NVM PBA number section invalid length\n");
830 : 0 : return -E1000_ERR_NVM_PBA_SECTION;
831 : : }
832 : : /* check if pba_num buffer is big enough */
833 [ # # ]: 0 : if (pba_num_size < (((u32)length * 2) - 1)) {
834 : 0 : DEBUGOUT("PBA string buffer too small\n");
835 : 0 : return -E1000_ERR_NO_SPACE;
836 : : }
837 : :
838 : : /* trim pba length from start of string */
839 : 0 : pba_ptr++;
840 : 0 : length--;
841 : :
842 [ # # ]: 0 : for (offset = 0; offset < length; offset++) {
843 : 0 : ret_val = hw->nvm.ops.read(hw, pba_ptr + offset, 1, &nvm_data);
844 [ # # ]: 0 : if (ret_val) {
845 : 0 : DEBUGOUT("NVM Read Error\n");
846 : 0 : return ret_val;
847 : : }
848 : 0 : pba_num[offset * 2] = (u8)(nvm_data >> 8);
849 : 0 : pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
850 : : }
851 : 0 : pba_num[offset * 2] = '\0';
852 : :
853 : 0 : return E1000_SUCCESS;
854 : : }
855 : :
856 : : /**
857 : : * e1000_read_pba_length_generic - Read device part number length
858 : : * @hw: pointer to the HW structure
859 : : * @pba_num_size: size of part number buffer
860 : : *
861 : : * Reads the product board assembly (PBA) number length from the EEPROM and
862 : : * stores the value in pba_num_size.
863 : : **/
864 : 0 : s32 e1000_read_pba_length_generic(struct e1000_hw *hw, u32 *pba_num_size)
865 : : {
866 : : s32 ret_val;
867 : : u16 nvm_data;
868 : : u16 pba_ptr;
869 : : u16 length;
870 : :
871 : 0 : DEBUGFUNC("e1000_read_pba_length_generic");
872 : :
873 [ # # ]: 0 : if (pba_num_size == NULL) {
874 : 0 : DEBUGOUT("PBA buffer size was null\n");
875 : 0 : return -E1000_ERR_INVALID_ARGUMENT;
876 : : }
877 : :
878 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
879 [ # # ]: 0 : if (ret_val) {
880 : 0 : DEBUGOUT("NVM Read Error\n");
881 : 0 : return ret_val;
882 : : }
883 : :
884 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
885 [ # # ]: 0 : if (ret_val) {
886 : 0 : DEBUGOUT("NVM Read Error\n");
887 : 0 : return ret_val;
888 : : }
889 : :
890 : : /* if data is not ptr guard the PBA must be in legacy format */
891 [ # # ]: 0 : if (nvm_data != NVM_PBA_PTR_GUARD) {
892 : 0 : *pba_num_size = E1000_PBANUM_LENGTH;
893 : 0 : return E1000_SUCCESS;
894 : : }
895 : :
896 : 0 : ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
897 [ # # ]: 0 : if (ret_val) {
898 : 0 : DEBUGOUT("NVM Read Error\n");
899 : 0 : return ret_val;
900 : : }
901 : :
902 [ # # ]: 0 : if (length == 0xFFFF || length == 0) {
903 : 0 : DEBUGOUT("NVM PBA number section invalid length\n");
904 : 0 : return -E1000_ERR_NVM_PBA_SECTION;
905 : : }
906 : :
907 : : /* Convert from length in u16 values to u8 chars, add 1 for NULL,
908 : : * and subtract 2 because length field is included in length.
909 : : */
910 : 0 : *pba_num_size = ((u32)length * 2) - 1;
911 : :
912 : 0 : return E1000_SUCCESS;
913 : : }
914 : :
915 : : /**
916 : : * e1000_read_pba_num_generic - Read device part number
917 : : * @hw: pointer to the HW structure
918 : : * @pba_num: pointer to device part number
919 : : *
920 : : * Reads the product board assembly (PBA) number from the EEPROM and stores
921 : : * the value in pba_num.
922 : : **/
923 : 0 : s32 e1000_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num)
924 : : {
925 : : s32 ret_val;
926 : : u16 nvm_data;
927 : :
928 : 0 : DEBUGFUNC("e1000_read_pba_num_generic");
929 : :
930 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
931 [ # # ]: 0 : if (ret_val) {
932 : 0 : DEBUGOUT("NVM Read Error\n");
933 : 0 : return ret_val;
934 [ # # ]: 0 : } else if (nvm_data == NVM_PBA_PTR_GUARD) {
935 : 0 : DEBUGOUT("NVM Not Supported\n");
936 : 0 : return -E1000_NOT_IMPLEMENTED;
937 : : }
938 : 0 : *pba_num = (u32)(nvm_data << 16);
939 : :
940 : 0 : ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
941 [ # # ]: 0 : if (ret_val) {
942 : 0 : DEBUGOUT("NVM Read Error\n");
943 : 0 : return ret_val;
944 : : }
945 : 0 : *pba_num |= nvm_data;
946 : :
947 : 0 : return E1000_SUCCESS;
948 : : }
949 : :
950 : :
951 : : /**
952 : : * e1000_read_pba_raw
953 : : * @hw: pointer to the HW structure
954 : : * @eeprom_buf: optional pointer to EEPROM image
955 : : * @eeprom_buf_size: size of EEPROM image in words
956 : : * @max_pba_block_size: PBA block size limit
957 : : * @pba: pointer to output PBA structure
958 : : *
959 : : * Reads PBA from EEPROM image when eeprom_buf is not NULL.
960 : : * Reads PBA from physical EEPROM device when eeprom_buf is NULL.
961 : : *
962 : : **/
963 : 0 : s32 e1000_read_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
964 : : u32 eeprom_buf_size, u16 max_pba_block_size,
965 : : struct e1000_pba *pba)
966 : : {
967 : : s32 ret_val;
968 : : u16 pba_block_size;
969 : :
970 [ # # ]: 0 : if (pba == NULL)
971 : : return -E1000_ERR_PARAM;
972 : :
973 [ # # ]: 0 : if (eeprom_buf == NULL) {
974 : 0 : ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2,
975 : : &pba->word[0]);
976 [ # # ]: 0 : if (ret_val)
977 : : return ret_val;
978 : : } else {
979 [ # # ]: 0 : if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
980 : 0 : pba->word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
981 : 0 : pba->word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
982 : : } else {
983 : : return -E1000_ERR_PARAM;
984 : : }
985 : : }
986 : :
987 [ # # ]: 0 : if (pba->word[0] == NVM_PBA_PTR_GUARD) {
988 [ # # ]: 0 : if (pba->pba_block == NULL)
989 : : return -E1000_ERR_PARAM;
990 : :
991 : 0 : ret_val = e1000_get_pba_block_size(hw, eeprom_buf,
992 : : eeprom_buf_size,
993 : : &pba_block_size);
994 [ # # ]: 0 : if (ret_val)
995 : : return ret_val;
996 : :
997 [ # # ]: 0 : if (pba_block_size > max_pba_block_size)
998 : : return -E1000_ERR_PARAM;
999 : :
1000 [ # # ]: 0 : if (eeprom_buf == NULL) {
1001 : 0 : ret_val = e1000_read_nvm(hw, pba->word[1],
1002 : : pba_block_size,
1003 : : pba->pba_block);
1004 [ # # ]: 0 : if (ret_val)
1005 : 0 : return ret_val;
1006 : : } else {
1007 [ # # ]: 0 : if (eeprom_buf_size > (u32)(pba->word[1] +
1008 : : pba_block_size)) {
1009 : 0 : memcpy(pba->pba_block,
1010 : 0 : &eeprom_buf[pba->word[1]],
1011 : : pba_block_size * sizeof(u16));
1012 : : } else {
1013 : : return -E1000_ERR_PARAM;
1014 : : }
1015 : : }
1016 : : }
1017 : :
1018 : : return E1000_SUCCESS;
1019 : : }
1020 : :
1021 : : /**
1022 : : * e1000_write_pba_raw
1023 : : * @hw: pointer to the HW structure
1024 : : * @eeprom_buf: optional pointer to EEPROM image
1025 : : * @eeprom_buf_size: size of EEPROM image in words
1026 : : * @pba: pointer to PBA structure
1027 : : *
1028 : : * Writes PBA to EEPROM image when eeprom_buf is not NULL.
1029 : : * Writes PBA to physical EEPROM device when eeprom_buf is NULL.
1030 : : *
1031 : : **/
1032 : 0 : s32 e1000_write_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
1033 : : u32 eeprom_buf_size, struct e1000_pba *pba)
1034 : : {
1035 : : s32 ret_val;
1036 : :
1037 [ # # ]: 0 : if (pba == NULL)
1038 : : return -E1000_ERR_PARAM;
1039 : :
1040 [ # # ]: 0 : if (eeprom_buf == NULL) {
1041 : 0 : ret_val = e1000_write_nvm(hw, NVM_PBA_OFFSET_0, 2,
1042 : : &pba->word[0]);
1043 [ # # ]: 0 : if (ret_val)
1044 : : return ret_val;
1045 : : } else {
1046 [ # # ]: 0 : if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1047 : 0 : eeprom_buf[NVM_PBA_OFFSET_0] = pba->word[0];
1048 : 0 : eeprom_buf[NVM_PBA_OFFSET_1] = pba->word[1];
1049 : : } else {
1050 : : return -E1000_ERR_PARAM;
1051 : : }
1052 : : }
1053 : :
1054 [ # # ]: 0 : if (pba->word[0] == NVM_PBA_PTR_GUARD) {
1055 [ # # ]: 0 : if (pba->pba_block == NULL)
1056 : : return -E1000_ERR_PARAM;
1057 : :
1058 [ # # ]: 0 : if (eeprom_buf == NULL) {
1059 : 0 : ret_val = e1000_write_nvm(hw, pba->word[1],
1060 : 0 : pba->pba_block[0],
1061 : : pba->pba_block);
1062 [ # # ]: 0 : if (ret_val)
1063 : 0 : return ret_val;
1064 : : } else {
1065 : 0 : if (eeprom_buf_size > (u32)(pba->word[1] +
1066 [ # # ]: 0 : pba->pba_block[0])) {
1067 : 0 : memcpy(&eeprom_buf[pba->word[1]],
1068 : : pba->pba_block,
1069 : 0 : pba->pba_block[0] * sizeof(u16));
1070 : : } else {
1071 : : return -E1000_ERR_PARAM;
1072 : : }
1073 : : }
1074 : : }
1075 : :
1076 : : return E1000_SUCCESS;
1077 : : }
1078 : :
1079 : : /**
1080 : : * e1000_get_pba_block_size
1081 : : * @hw: pointer to the HW structure
1082 : : * @eeprom_buf: optional pointer to EEPROM image
1083 : : * @eeprom_buf_size: size of EEPROM image in words
1084 : : * @pba_data_size: pointer to output variable
1085 : : *
1086 : : * Returns the size of the PBA block in words. Function operates on EEPROM
1087 : : * image if the eeprom_buf pointer is not NULL otherwise it accesses physical
1088 : : * EEPROM device.
1089 : : *
1090 : : **/
1091 : 0 : s32 e1000_get_pba_block_size(struct e1000_hw *hw, u16 *eeprom_buf,
1092 : : u32 eeprom_buf_size, u16 *pba_block_size)
1093 : : {
1094 : : s32 ret_val;
1095 : : u16 pba_word[2];
1096 : : u16 length;
1097 : :
1098 : 0 : DEBUGFUNC("e1000_get_pba_block_size");
1099 : :
1100 [ # # ]: 0 : if (eeprom_buf == NULL) {
1101 : 0 : ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2, &pba_word[0]);
1102 [ # # ]: 0 : if (ret_val)
1103 : : return ret_val;
1104 : : } else {
1105 [ # # ]: 0 : if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1106 : 0 : pba_word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
1107 : 0 : pba_word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
1108 : : } else {
1109 : : return -E1000_ERR_PARAM;
1110 : : }
1111 : : }
1112 : :
1113 [ # # ]: 0 : if (pba_word[0] == NVM_PBA_PTR_GUARD) {
1114 [ # # ]: 0 : if (eeprom_buf == NULL) {
1115 : 0 : ret_val = e1000_read_nvm(hw, pba_word[1] + 0, 1,
1116 : : &length);
1117 [ # # ]: 0 : if (ret_val)
1118 : : return ret_val;
1119 : : } else {
1120 [ # # ]: 0 : if (eeprom_buf_size > pba_word[1])
1121 : 0 : length = eeprom_buf[pba_word[1] + 0];
1122 : : else
1123 : : return -E1000_ERR_PARAM;
1124 : : }
1125 : :
1126 [ # # ]: 0 : if (length == 0xFFFF || length == 0)
1127 : : return -E1000_ERR_NVM_PBA_SECTION;
1128 : : } else {
1129 : : /* PBA number in legacy format, there is no PBA Block. */
1130 : 0 : length = 0;
1131 : : }
1132 : :
1133 [ # # ]: 0 : if (pba_block_size != NULL)
1134 : 0 : *pba_block_size = length;
1135 : :
1136 : : return E1000_SUCCESS;
1137 : : }
1138 : :
1139 : : /**
1140 : : * e1000_read_mac_addr_generic - Read device MAC address
1141 : : * @hw: pointer to the HW structure
1142 : : *
1143 : : * Reads the device MAC address from the EEPROM and stores the value.
1144 : : * Since devices with two ports use the same EEPROM, we increment the
1145 : : * last bit in the MAC address for the second port.
1146 : : **/
1147 : 0 : s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
1148 : : {
1149 : : u32 rar_high;
1150 : : u32 rar_low;
1151 : : u16 i;
1152 : :
1153 : 0 : rar_high = E1000_READ_REG(hw, E1000_RAH(0));
1154 : 0 : rar_low = E1000_READ_REG(hw, E1000_RAL(0));
1155 : :
1156 [ # # ]: 0 : for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
1157 : 0 : hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
1158 : :
1159 [ # # ]: 0 : for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
1160 : 0 : hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
1161 : :
1162 [ # # ]: 0 : for (i = 0; i < ETH_ADDR_LEN; i++)
1163 : 0 : hw->mac.addr[i] = hw->mac.perm_addr[i];
1164 : :
1165 : 0 : return E1000_SUCCESS;
1166 : : }
1167 : :
1168 : : /**
1169 : : * e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
1170 : : * @hw: pointer to the HW structure
1171 : : *
1172 : : * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
1173 : : * and then verifies that the sum of the EEPROM is equal to 0xBABA.
1174 : : **/
1175 : 0 : s32 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
1176 : : {
1177 : : s32 ret_val;
1178 : : u16 checksum = 0;
1179 : : u16 i, nvm_data;
1180 : :
1181 : 0 : DEBUGFUNC("e1000_validate_nvm_checksum_generic");
1182 : :
1183 [ # # ]: 0 : for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
1184 : 0 : ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1185 [ # # ]: 0 : if (ret_val) {
1186 : 0 : DEBUGOUT("NVM Read Error\n");
1187 : 0 : return ret_val;
1188 : : }
1189 : 0 : checksum += nvm_data;
1190 : : }
1191 : :
1192 [ # # ]: 0 : if (checksum != (u16) NVM_SUM) {
1193 : 0 : DEBUGOUT("NVM Checksum Invalid\n");
1194 : 0 : return -E1000_ERR_NVM;
1195 : : }
1196 : :
1197 : : return E1000_SUCCESS;
1198 : : }
1199 : :
1200 : : /**
1201 : : * e1000_update_nvm_checksum_generic - Update EEPROM checksum
1202 : : * @hw: pointer to the HW structure
1203 : : *
1204 : : * Updates the EEPROM checksum by reading/adding each word of the EEPROM
1205 : : * up to the checksum. Then calculates the EEPROM checksum and writes the
1206 : : * value to the EEPROM.
1207 : : **/
1208 : 0 : s32 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
1209 : : {
1210 : : s32 ret_val;
1211 : 0 : u16 checksum = 0;
1212 : : u16 i, nvm_data;
1213 : :
1214 : 0 : DEBUGFUNC("e1000_update_nvm_checksum");
1215 : :
1216 [ # # ]: 0 : for (i = 0; i < NVM_CHECKSUM_REG; i++) {
1217 : 0 : ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1218 [ # # ]: 0 : if (ret_val) {
1219 : 0 : DEBUGOUT("NVM Read Error while updating checksum.\n");
1220 : 0 : return ret_val;
1221 : : }
1222 : 0 : checksum += nvm_data;
1223 : : }
1224 : 0 : checksum = (u16) NVM_SUM - checksum;
1225 : 0 : ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
1226 [ # # ]: 0 : if (ret_val)
1227 : 0 : DEBUGOUT("NVM Write Error while updating checksum.\n");
1228 : :
1229 : : return ret_val;
1230 : : }
1231 : :
1232 : : /**
1233 : : * e1000_reload_nvm_generic - Reloads EEPROM
1234 : : * @hw: pointer to the HW structure
1235 : : *
1236 : : * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
1237 : : * extended control register.
1238 : : **/
1239 : 0 : STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw)
1240 : : {
1241 : : u32 ctrl_ext;
1242 : :
1243 : 0 : DEBUGFUNC("e1000_reload_nvm_generic");
1244 : :
1245 : 0 : usec_delay(10);
1246 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1247 : 0 : ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1248 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1249 : 0 : E1000_WRITE_FLUSH(hw);
1250 : 0 : }
1251 : :
1252 : : /**
1253 : : * e1000_get_fw_version - Get firmware version information
1254 : : * @hw: pointer to the HW structure
1255 : : * @fw_vers: pointer to output version structure
1256 : : *
1257 : : * unsupported/not present features return 0 in version structure
1258 : : **/
1259 [ # # # # : 0 : void e1000_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
# ]
1260 : : {
1261 : : u16 eeprom_verh, eeprom_verl, etrack_test, fw_version;
1262 : : u8 q, hval, rem, result;
1263 : : u16 comb_verh, comb_verl, comb_offset;
1264 : :
1265 : : memset(fw_vers, 0, sizeof(struct e1000_fw_version));
1266 : :
1267 : : /* basic eeprom version numbers, bits used vary by part and by tool
1268 : : * used to create the nvm images */
1269 : : /* Check which data format we have */
1270 [ # # # # : 0 : switch (hw->mac.type) {
# ]
1271 : 0 : case e1000_i211:
1272 : 0 : e1000_read_invm_version(hw, fw_vers);
1273 : 0 : return;
1274 : 0 : case e1000_82575:
1275 : : case e1000_82576:
1276 : : case e1000_82580:
1277 : : case e1000_i354:
1278 : 0 : hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1279 : : /* Use this format, unless EETRACK ID exists,
1280 : : * then use alternate format
1281 : : */
1282 [ # # ]: 0 : if ((etrack_test & NVM_MAJOR_MASK) != NVM_ETRACK_VALID) {
1283 : 0 : hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1284 : 0 : fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
1285 : 0 : >> NVM_MAJOR_SHIFT;
1286 : 0 : fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK)
1287 : 0 : >> NVM_MINOR_SHIFT;
1288 : 0 : fw_vers->eep_build = (fw_version & NVM_IMAGE_ID_MASK);
1289 : 0 : goto etrack_id;
1290 : : }
1291 : : break;
1292 : 0 : case e1000_i210:
1293 [ # # ]: 0 : if (!(e1000_get_flash_presence_i210(hw))) {
1294 : 0 : e1000_read_invm_version(hw, fw_vers);
1295 : 0 : return;
1296 : : }
1297 : : /* fall through */
1298 : : case e1000_i350:
1299 : 0 : hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1300 : : /* find combo image version */
1301 : 0 : hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset);
1302 [ # # ]: 0 : if ((comb_offset != 0x0) &&
1303 : : (comb_offset != NVM_VER_INVALID)) {
1304 : :
1305 : 0 : hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset
1306 : 0 : + 1), 1, &comb_verh);
1307 : 0 : hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset),
1308 : : 1, &comb_verl);
1309 : :
1310 : : /* get Option Rom version if it exists and is valid */
1311 [ # # # # : 0 : if ((comb_verh && comb_verl) &&
# # ]
1312 [ # # ]: 0 : ((comb_verh != NVM_VER_INVALID) &&
1313 : : (comb_verl != NVM_VER_INVALID))) {
1314 : :
1315 : 0 : fw_vers->or_valid = true;
1316 : 0 : fw_vers->or_major =
1317 : : comb_verl >> NVM_COMB_VER_SHFT;
1318 : 0 : fw_vers->or_build =
1319 : 0 : (comb_verl << NVM_COMB_VER_SHFT)
1320 : 0 : | (comb_verh >> NVM_COMB_VER_SHFT);
1321 : 0 : fw_vers->or_patch =
1322 : 0 : comb_verh & NVM_COMB_VER_MASK;
1323 : : }
1324 : : }
1325 : : break;
1326 : 0 : default:
1327 : 0 : hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1328 : 0 : return;
1329 : : }
1330 : 0 : hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1331 : 0 : fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
1332 : 0 : >> NVM_MAJOR_SHIFT;
1333 : :
1334 : : /* check for old style version format in newer images*/
1335 [ # # ]: 0 : if ((fw_version & NVM_NEW_DEC_MASK) == 0x0) {
1336 : 0 : eeprom_verl = (fw_version & NVM_COMB_VER_MASK);
1337 : : } else {
1338 : 0 : eeprom_verl = (fw_version & NVM_MINOR_MASK)
1339 : 0 : >> NVM_MINOR_SHIFT;
1340 : : }
1341 : : /* Convert minor value to hex before assigning to output struct
1342 : : * Val to be converted will not be higher than 99, per tool output
1343 : : */
1344 : 0 : q = eeprom_verl / NVM_HEX_CONV;
1345 : 0 : hval = q * NVM_HEX_TENS;
1346 : 0 : rem = eeprom_verl % NVM_HEX_CONV;
1347 : 0 : result = hval + rem;
1348 : 0 : fw_vers->eep_minor = result;
1349 : :
1350 : 0 : etrack_id:
1351 [ # # ]: 0 : if ((etrack_test & NVM_MAJOR_MASK) == NVM_ETRACK_VALID) {
1352 : 0 : hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl);
1353 : 0 : hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh);
1354 : 0 : fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT)
1355 : 0 : | eeprom_verl;
1356 [ # # ]: 0 : } else if ((etrack_test & NVM_ETRACK_VALID) == 0) {
1357 : 0 : hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verh);
1358 : 0 : hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verl);
1359 : 0 : fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) |
1360 : : eeprom_verl;
1361 : : }
1362 : : }
1363 : :
1364 : :
|