This source file includes following definitions.
- ixgb_raise_clock
- ixgb_lower_clock
- ixgb_shift_out_bits
- ixgb_shift_in_bits
- ixgb_setup_eeprom
- ixgb_standby_eeprom
- ixgb_clock_eeprom
- ixgb_cleanup_eeprom
- ixgb_wait_eeprom_command
- ixgb_validate_eeprom_checksum
- ixgb_update_eeprom_checksum
- ixgb_write_eeprom
- ixgb_read_eeprom
- ixgb_get_eeprom_data
- ixgb_check_and_get_eeprom_data
- ixgb_get_eeprom_word
- ixgb_get_ee_mac_addr
- ixgb_get_ee_pba_number
- ixgb_get_ee_device_id
1
2
3
4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
5
6 #include "ixgb_hw.h"
7 #include "ixgb_ee.h"
8
9 static u16 ixgb_shift_in_bits(struct ixgb_hw *hw);
10
11 static void ixgb_shift_out_bits(struct ixgb_hw *hw,
12 u16 data,
13 u16 count);
14 static void ixgb_standby_eeprom(struct ixgb_hw *hw);
15
16 static bool ixgb_wait_eeprom_command(struct ixgb_hw *hw);
17
18 static void ixgb_cleanup_eeprom(struct ixgb_hw *hw);
19
20
21
22
23
24
25
26 static void
27 ixgb_raise_clock(struct ixgb_hw *hw,
28 u32 *eecd_reg)
29 {
30
31
32
33 *eecd_reg = *eecd_reg | IXGB_EECD_SK;
34 IXGB_WRITE_REG(hw, EECD, *eecd_reg);
35 IXGB_WRITE_FLUSH(hw);
36 udelay(50);
37 }
38
39
40
41
42
43
44
45 static void
46 ixgb_lower_clock(struct ixgb_hw *hw,
47 u32 *eecd_reg)
48 {
49
50
51
52 *eecd_reg = *eecd_reg & ~IXGB_EECD_SK;
53 IXGB_WRITE_REG(hw, EECD, *eecd_reg);
54 IXGB_WRITE_FLUSH(hw);
55 udelay(50);
56 }
57
58
59
60
61
62
63
64
65 static void
66 ixgb_shift_out_bits(struct ixgb_hw *hw,
67 u16 data,
68 u16 count)
69 {
70 u32 eecd_reg;
71 u32 mask;
72
73
74
75
76
77 mask = 0x01 << (count - 1);
78 eecd_reg = IXGB_READ_REG(hw, EECD);
79 eecd_reg &= ~(IXGB_EECD_DO | IXGB_EECD_DI);
80 do {
81
82
83
84
85
86 eecd_reg &= ~IXGB_EECD_DI;
87
88 if (data & mask)
89 eecd_reg |= IXGB_EECD_DI;
90
91 IXGB_WRITE_REG(hw, EECD, eecd_reg);
92 IXGB_WRITE_FLUSH(hw);
93
94 udelay(50);
95
96 ixgb_raise_clock(hw, &eecd_reg);
97 ixgb_lower_clock(hw, &eecd_reg);
98
99 mask = mask >> 1;
100
101 } while (mask);
102
103
104 eecd_reg &= ~IXGB_EECD_DI;
105 IXGB_WRITE_REG(hw, EECD, eecd_reg);
106 }
107
108
109
110
111
112
113 static u16
114 ixgb_shift_in_bits(struct ixgb_hw *hw)
115 {
116 u32 eecd_reg;
117 u32 i;
118 u16 data;
119
120
121
122
123
124
125
126
127 eecd_reg = IXGB_READ_REG(hw, EECD);
128
129 eecd_reg &= ~(IXGB_EECD_DO | IXGB_EECD_DI);
130 data = 0;
131
132 for (i = 0; i < 16; i++) {
133 data = data << 1;
134 ixgb_raise_clock(hw, &eecd_reg);
135
136 eecd_reg = IXGB_READ_REG(hw, EECD);
137
138 eecd_reg &= ~(IXGB_EECD_DI);
139 if (eecd_reg & IXGB_EECD_DO)
140 data |= 1;
141
142 ixgb_lower_clock(hw, &eecd_reg);
143 }
144
145 return data;
146 }
147
148
149
150
151
152
153
154
155
156 static void
157 ixgb_setup_eeprom(struct ixgb_hw *hw)
158 {
159 u32 eecd_reg;
160
161 eecd_reg = IXGB_READ_REG(hw, EECD);
162
163
164 eecd_reg &= ~(IXGB_EECD_SK | IXGB_EECD_DI);
165 IXGB_WRITE_REG(hw, EECD, eecd_reg);
166
167
168 eecd_reg |= IXGB_EECD_CS;
169 IXGB_WRITE_REG(hw, EECD, eecd_reg);
170 }
171
172
173
174
175
176
177 static void
178 ixgb_standby_eeprom(struct ixgb_hw *hw)
179 {
180 u32 eecd_reg;
181
182 eecd_reg = IXGB_READ_REG(hw, EECD);
183
184
185 eecd_reg &= ~(IXGB_EECD_CS | IXGB_EECD_SK);
186 IXGB_WRITE_REG(hw, EECD, eecd_reg);
187 IXGB_WRITE_FLUSH(hw);
188 udelay(50);
189
190
191 eecd_reg |= IXGB_EECD_SK;
192 IXGB_WRITE_REG(hw, EECD, eecd_reg);
193 IXGB_WRITE_FLUSH(hw);
194 udelay(50);
195
196
197 eecd_reg |= IXGB_EECD_CS;
198 IXGB_WRITE_REG(hw, EECD, eecd_reg);
199 IXGB_WRITE_FLUSH(hw);
200 udelay(50);
201
202
203 eecd_reg &= ~IXGB_EECD_SK;
204 IXGB_WRITE_REG(hw, EECD, eecd_reg);
205 IXGB_WRITE_FLUSH(hw);
206 udelay(50);
207 }
208
209
210
211
212
213
214 static void
215 ixgb_clock_eeprom(struct ixgb_hw *hw)
216 {
217 u32 eecd_reg;
218
219 eecd_reg = IXGB_READ_REG(hw, EECD);
220
221
222 eecd_reg |= IXGB_EECD_SK;
223 IXGB_WRITE_REG(hw, EECD, eecd_reg);
224 IXGB_WRITE_FLUSH(hw);
225 udelay(50);
226
227
228 eecd_reg &= ~IXGB_EECD_SK;
229 IXGB_WRITE_REG(hw, EECD, eecd_reg);
230 IXGB_WRITE_FLUSH(hw);
231 udelay(50);
232 }
233
234
235
236
237
238
239 static void
240 ixgb_cleanup_eeprom(struct ixgb_hw *hw)
241 {
242 u32 eecd_reg;
243
244 eecd_reg = IXGB_READ_REG(hw, EECD);
245
246 eecd_reg &= ~(IXGB_EECD_CS | IXGB_EECD_DI);
247
248 IXGB_WRITE_REG(hw, EECD, eecd_reg);
249
250 ixgb_clock_eeprom(hw);
251 }
252
253
254
255
256
257
258
259
260
261
262
263
264 static bool
265 ixgb_wait_eeprom_command(struct ixgb_hw *hw)
266 {
267 u32 eecd_reg;
268 u32 i;
269
270
271
272
273 ixgb_standby_eeprom(hw);
274
275
276
277
278
279 for (i = 0; i < 200; i++) {
280 eecd_reg = IXGB_READ_REG(hw, EECD);
281
282 if (eecd_reg & IXGB_EECD_DO)
283 return true;
284
285 udelay(50);
286 }
287 ASSERT(0);
288 return false;
289 }
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304 bool
305 ixgb_validate_eeprom_checksum(struct ixgb_hw *hw)
306 {
307 u16 checksum = 0;
308 u16 i;
309
310 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++)
311 checksum += ixgb_read_eeprom(hw, i);
312
313 if (checksum == (u16) EEPROM_SUM)
314 return true;
315 else
316 return false;
317 }
318
319
320
321
322
323
324
325
326
327 void
328 ixgb_update_eeprom_checksum(struct ixgb_hw *hw)
329 {
330 u16 checksum = 0;
331 u16 i;
332
333 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
334 checksum += ixgb_read_eeprom(hw, i);
335
336 checksum = (u16) EEPROM_SUM - checksum;
337
338 ixgb_write_eeprom(hw, EEPROM_CHECKSUM_REG, checksum);
339 }
340
341
342
343
344
345
346
347
348
349
350
351
352 void
353 ixgb_write_eeprom(struct ixgb_hw *hw, u16 offset, u16 data)
354 {
355 struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
356
357
358 ixgb_setup_eeprom(hw);
359
360
361
362
363 ixgb_shift_out_bits(hw, EEPROM_EWEN_OPCODE, 5);
364 ixgb_shift_out_bits(hw, 0, 4);
365
366
367 ixgb_standby_eeprom(hw);
368
369
370 ixgb_shift_out_bits(hw, EEPROM_WRITE_OPCODE, 3);
371 ixgb_shift_out_bits(hw, offset, 6);
372
373
374 ixgb_shift_out_bits(hw, data, 16);
375
376 ixgb_wait_eeprom_command(hw);
377
378
379 ixgb_standby_eeprom(hw);
380
381
382
383
384
385 ixgb_shift_out_bits(hw, EEPROM_EWDS_OPCODE, 5);
386 ixgb_shift_out_bits(hw, 0, 4);
387
388
389 ixgb_cleanup_eeprom(hw);
390
391
392 ee_map->init_ctrl_reg_1 = cpu_to_le16(EEPROM_ICW1_SIGNATURE_CLEAR);
393 }
394
395
396
397
398
399
400
401
402
403
404 u16
405 ixgb_read_eeprom(struct ixgb_hw *hw,
406 u16 offset)
407 {
408 u16 data;
409
410
411 ixgb_setup_eeprom(hw);
412
413
414 ixgb_shift_out_bits(hw, EEPROM_READ_OPCODE, 3);
415
416
417
418 ixgb_shift_out_bits(hw, offset, 6);
419
420
421 data = ixgb_shift_in_bits(hw);
422
423
424 ixgb_standby_eeprom(hw);
425
426 return data;
427 }
428
429
430
431
432
433
434
435
436
437
438
439 bool
440 ixgb_get_eeprom_data(struct ixgb_hw *hw)
441 {
442 u16 i;
443 u16 checksum = 0;
444 struct ixgb_ee_map_type *ee_map;
445
446 ENTER();
447
448 ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
449
450 pr_debug("Reading eeprom data\n");
451 for (i = 0; i < IXGB_EEPROM_SIZE ; i++) {
452 u16 ee_data;
453 ee_data = ixgb_read_eeprom(hw, i);
454 checksum += ee_data;
455 hw->eeprom[i] = cpu_to_le16(ee_data);
456 }
457
458 if (checksum != (u16) EEPROM_SUM) {
459 pr_debug("Checksum invalid\n");
460
461
462 ee_map->init_ctrl_reg_1 = cpu_to_le16(EEPROM_ICW1_SIGNATURE_CLEAR);
463 return false;
464 }
465
466 if ((ee_map->init_ctrl_reg_1 & cpu_to_le16(EEPROM_ICW1_SIGNATURE_MASK))
467 != cpu_to_le16(EEPROM_ICW1_SIGNATURE_VALID)) {
468 pr_debug("Signature invalid\n");
469 return false;
470 }
471
472 return true;
473 }
474
475
476
477
478
479
480
481
482
483
484
485 static bool
486 ixgb_check_and_get_eeprom_data (struct ixgb_hw* hw)
487 {
488 struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
489
490 if ((ee_map->init_ctrl_reg_1 & cpu_to_le16(EEPROM_ICW1_SIGNATURE_MASK))
491 == cpu_to_le16(EEPROM_ICW1_SIGNATURE_VALID)) {
492 return true;
493 } else {
494 return ixgb_get_eeprom_data(hw);
495 }
496 }
497
498
499
500
501
502
503
504
505
506
507 __le16
508 ixgb_get_eeprom_word(struct ixgb_hw *hw, u16 index)
509 {
510
511 if (index < IXGB_EEPROM_SIZE && ixgb_check_and_get_eeprom_data(hw))
512 return hw->eeprom[index];
513
514 return 0;
515 }
516
517
518
519
520
521
522
523
524
525 void
526 ixgb_get_ee_mac_addr(struct ixgb_hw *hw,
527 u8 *mac_addr)
528 {
529 int i;
530 struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
531
532 ENTER();
533
534 if (ixgb_check_and_get_eeprom_data(hw)) {
535 for (i = 0; i < ETH_ALEN; i++) {
536 mac_addr[i] = ee_map->mac_addr[i];
537 }
538 pr_debug("eeprom mac address = %pM\n", mac_addr);
539 }
540 }
541
542
543
544
545
546
547
548
549
550
551 u32
552 ixgb_get_ee_pba_number(struct ixgb_hw *hw)
553 {
554 if (ixgb_check_and_get_eeprom_data(hw))
555 return le16_to_cpu(hw->eeprom[EEPROM_PBA_1_2_REG])
556 | (le16_to_cpu(hw->eeprom[EEPROM_PBA_3_4_REG])<<16);
557
558 return 0;
559 }
560
561
562
563
564
565
566
567
568
569
570 u16
571 ixgb_get_ee_device_id(struct ixgb_hw *hw)
572 {
573 struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
574
575 if (ixgb_check_and_get_eeprom_data(hw))
576 return le16_to_cpu(ee_map->device_id);
577
578 return 0;
579 }
580