1 /****************************************************************************
2 * Support for Solarflare Solarstorm network controllers and boards
3 * Copyright 2010 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10 #include <stdio.h>
11 #include <errno.h>
12 #include "internal.h"
13 #include "sff-common.h"
14 #include "netlink/extapi.h"
15
16 #define SFF8079_PAGE_SIZE 0x80
17 #define SFF8079_I2C_ADDRESS_LOW 0x50
18 #define SFF8079_I2C_ADDRESS_HIGH 0x51
19
sff8079_show_identifier(const __u8 * id)20 static void sff8079_show_identifier(const __u8 *id)
21 {
22 sff8024_show_identifier(id, 0);
23 }
24
sff8079_show_ext_identifier(const __u8 * id)25 static void sff8079_show_ext_identifier(const __u8 *id)
26 {
27 printf("\t%-41s : 0x%02x", "Extended identifier", id[1]);
28 if (id[1] == 0x00)
29 printf(" (GBIC not specified / not MOD_DEF compliant)\n");
30 else if (id[1] == 0x04)
31 printf(" (GBIC/SFP defined by 2-wire interface ID)\n");
32 else if (id[1] <= 0x07)
33 printf(" (GBIC compliant with MOD_DEF %u)\n", id[1]);
34 else
35 printf(" (unknown)\n");
36 }
37
sff8079_show_connector(const __u8 * id)38 static void sff8079_show_connector(const __u8 *id)
39 {
40 sff8024_show_connector(id, 2);
41 }
42
sff8079_show_transceiver(const __u8 * id)43 static void sff8079_show_transceiver(const __u8 *id)
44 {
45 static const char *pfx =
46 "\tTransceiver type :";
47
48 printf("\t%-41s : 0x%02x 0x%02x 0x%02x " \
49 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
50 "Transceiver codes",
51 id[3], id[4], id[5], id[6],
52 id[7], id[8], id[9], id[10], id[36]);
53 /* 10G Ethernet Compliance Codes */
54 if (id[3] & (1 << 7))
55 printf("%s 10G Ethernet: 10G Base-ER" \
56 " [SFF-8472 rev10.4 onwards]\n", pfx);
57 if (id[3] & (1 << 6))
58 printf("%s 10G Ethernet: 10G Base-LRM\n", pfx);
59 if (id[3] & (1 << 5))
60 printf("%s 10G Ethernet: 10G Base-LR\n", pfx);
61 if (id[3] & (1 << 4))
62 printf("%s 10G Ethernet: 10G Base-SR\n", pfx);
63 /* Infiniband Compliance Codes */
64 if (id[3] & (1 << 3))
65 printf("%s Infiniband: 1X SX\n", pfx);
66 if (id[3] & (1 << 2))
67 printf("%s Infiniband: 1X LX\n", pfx);
68 if (id[3] & (1 << 1))
69 printf("%s Infiniband: 1X Copper Active\n", pfx);
70 if (id[3] & (1 << 0))
71 printf("%s Infiniband: 1X Copper Passive\n", pfx);
72 /* ESCON Compliance Codes */
73 if (id[4] & (1 << 7))
74 printf("%s ESCON: ESCON MMF, 1310nm LED\n", pfx);
75 if (id[4] & (1 << 6))
76 printf("%s ESCON: ESCON SMF, 1310nm Laser\n", pfx);
77 /* SONET Compliance Codes */
78 if (id[4] & (1 << 5))
79 printf("%s SONET: OC-192, short reach\n", pfx);
80 if (id[4] & (1 << 4))
81 printf("%s SONET: SONET reach specifier bit 1\n", pfx);
82 if (id[4] & (1 << 3))
83 printf("%s SONET: SONET reach specifier bit 2\n", pfx);
84 if (id[4] & (1 << 2))
85 printf("%s SONET: OC-48, long reach\n", pfx);
86 if (id[4] & (1 << 1))
87 printf("%s SONET: OC-48, intermediate reach\n", pfx);
88 if (id[4] & (1 << 0))
89 printf("%s SONET: OC-48, short reach\n", pfx);
90 if (id[5] & (1 << 6))
91 printf("%s SONET: OC-12, single mode, long reach\n", pfx);
92 if (id[5] & (1 << 5))
93 printf("%s SONET: OC-12, single mode, inter. reach\n", pfx);
94 if (id[5] & (1 << 4))
95 printf("%s SONET: OC-12, short reach\n", pfx);
96 if (id[5] & (1 << 2))
97 printf("%s SONET: OC-3, single mode, long reach\n", pfx);
98 if (id[5] & (1 << 1))
99 printf("%s SONET: OC-3, single mode, inter. reach\n", pfx);
100 if (id[5] & (1 << 0))
101 printf("%s SONET: OC-3, short reach\n", pfx);
102 /* Ethernet Compliance Codes */
103 if (id[6] & (1 << 7))
104 printf("%s Ethernet: BASE-PX\n", pfx);
105 if (id[6] & (1 << 6))
106 printf("%s Ethernet: BASE-BX10\n", pfx);
107 if (id[6] & (1 << 5))
108 printf("%s Ethernet: 100BASE-FX\n", pfx);
109 if (id[6] & (1 << 4))
110 printf("%s Ethernet: 100BASE-LX/LX10\n", pfx);
111 if (id[6] & (1 << 3))
112 printf("%s Ethernet: 1000BASE-T\n", pfx);
113 if (id[6] & (1 << 2))
114 printf("%s Ethernet: 1000BASE-CX\n", pfx);
115 if (id[6] & (1 << 1))
116 printf("%s Ethernet: 1000BASE-LX\n", pfx);
117 if (id[6] & (1 << 0))
118 printf("%s Ethernet: 1000BASE-SX\n", pfx);
119 /* Fibre Channel link length */
120 if (id[7] & (1 << 7))
121 printf("%s FC: very long distance (V)\n", pfx);
122 if (id[7] & (1 << 6))
123 printf("%s FC: short distance (S)\n", pfx);
124 if (id[7] & (1 << 5))
125 printf("%s FC: intermediate distance (I)\n", pfx);
126 if (id[7] & (1 << 4))
127 printf("%s FC: long distance (L)\n", pfx);
128 if (id[7] & (1 << 3))
129 printf("%s FC: medium distance (M)\n", pfx);
130 /* Fibre Channel transmitter technology */
131 if (id[7] & (1 << 2))
132 printf("%s FC: Shortwave laser, linear Rx (SA)\n", pfx);
133 if (id[7] & (1 << 1))
134 printf("%s FC: Longwave laser (LC)\n", pfx);
135 if (id[7] & (1 << 0))
136 printf("%s FC: Electrical inter-enclosure (EL)\n", pfx);
137 if (id[8] & (1 << 7))
138 printf("%s FC: Electrical intra-enclosure (EL)\n", pfx);
139 if (id[8] & (1 << 6))
140 printf("%s FC: Shortwave laser w/o OFC (SN)\n", pfx);
141 if (id[8] & (1 << 5))
142 printf("%s FC: Shortwave laser with OFC (SL)\n", pfx);
143 if (id[8] & (1 << 4))
144 printf("%s FC: Longwave laser (LL)\n", pfx);
145 if (id[8] & (1 << 3))
146 printf("%s Active Cable\n", pfx);
147 if (id[8] & (1 << 2))
148 printf("%s Passive Cable\n", pfx);
149 if (id[8] & (1 << 1))
150 printf("%s FC: Copper FC-BaseT\n", pfx);
151 /* Fibre Channel transmission media */
152 if (id[9] & (1 << 7))
153 printf("%s FC: Twin Axial Pair (TW)\n", pfx);
154 if (id[9] & (1 << 6))
155 printf("%s FC: Twisted Pair (TP)\n", pfx);
156 if (id[9] & (1 << 5))
157 printf("%s FC: Miniature Coax (MI)\n", pfx);
158 if (id[9] & (1 << 4))
159 printf("%s FC: Video Coax (TV)\n", pfx);
160 if (id[9] & (1 << 3))
161 printf("%s FC: Multimode, 62.5um (M6)\n", pfx);
162 if (id[9] & (1 << 2))
163 printf("%s FC: Multimode, 50um (M5)\n", pfx);
164 if (id[9] & (1 << 0))
165 printf("%s FC: Single Mode (SM)\n", pfx);
166 /* Fibre Channel speed */
167 if (id[10] & (1 << 7))
168 printf("%s FC: 1200 MBytes/sec\n", pfx);
169 if (id[10] & (1 << 6))
170 printf("%s FC: 800 MBytes/sec\n", pfx);
171 if (id[10] & (1 << 4))
172 printf("%s FC: 400 MBytes/sec\n", pfx);
173 if (id[10] & (1 << 2))
174 printf("%s FC: 200 MBytes/sec\n", pfx);
175 if (id[10] & (1 << 0))
176 printf("%s FC: 100 MBytes/sec\n", pfx);
177 /* Extended Specification Compliance Codes from SFF-8024 */
178 if (id[36] == 0x1)
179 printf("%s Extended: 100G AOC or 25GAUI C2M AOC with worst BER of 5x10^(-5)\n", pfx);
180 if (id[36] == 0x2)
181 printf("%s Extended: 100G Base-SR4 or 25GBase-SR\n", pfx);
182 if (id[36] == 0x3)
183 printf("%s Extended: 100G Base-LR4 or 25GBase-LR\n", pfx);
184 if (id[36] == 0x4)
185 printf("%s Extended: 100G Base-ER4 or 25GBase-ER\n", pfx);
186 if (id[36] == 0x8)
187 printf("%s Extended: 100G ACC or 25GAUI C2M ACC with worst BER of 5x10^(-5)\n", pfx);
188 if (id[36] == 0xb)
189 printf("%s Extended: 100G Base-CR4 or 25G Base-CR CA-L\n", pfx);
190 if (id[36] == 0xc)
191 printf("%s Extended: 25G Base-CR CA-S\n", pfx);
192 if (id[36] == 0xd)
193 printf("%s Extended: 25G Base-CR CA-N\n", pfx);
194 if (id[36] == 0x16)
195 printf("%s Extended: 10Gbase-T with SFI electrical interface\n", pfx);
196 if (id[36] == 0x18)
197 printf("%s Extended: 100G AOC or 25GAUI C2M AOC with worst BER of 10^(-12)\n", pfx);
198 if (id[36] == 0x19)
199 printf("%s Extended: 100G ACC or 25GAUI C2M ACC with worst BER of 10^(-12)\n", pfx);
200 if (id[36] == 0x1a)
201 printf("%s Extended: 100GE-DWDM2 (DWDM transceiver using 2 wavelengths on a 1550 nm DWDM grid with a reach up to 80 km)\n",
202 pfx);
203 if (id[36] == 0x1b)
204 printf("%s Extended: 100G 1550nm WDM (4 wavelengths)\n", pfx);
205 if (id[36] == 0x1c)
206 printf("%s Extended: 10Gbase-T Short Reach\n", pfx);
207 if (id[36] == 0x1d)
208 printf("%s Extended: 5GBASE-T\n", pfx);
209 if (id[36] == 0x1e)
210 printf("%s Extended: 2.5GBASE-T\n", pfx);
211 if (id[36] == 0x1f)
212 printf("%s Extended: 40G SWDM4\n", pfx);
213 if (id[36] == 0x20)
214 printf("%s Extended: 100G SWDM4\n", pfx);
215 if (id[36] == 0x21)
216 printf("%s Extended: 100G PAM4 BiDi\n", pfx);
217 if (id[36] == 0x22)
218 printf("%s Extended: 4WDM-10 MSA (10km version of 100G CWDM4 with same RS(528,514) FEC in host system)\n",
219 pfx);
220 if (id[36] == 0x23)
221 printf("%s Extended: 4WDM-20 MSA (20km version of 100GBASE-LR4 with RS(528,514) FEC in host system)\n",
222 pfx);
223 if (id[36] == 0x24)
224 printf("%s Extended: 4WDM-40 MSA (40km reach with APD receiver and RS(528,514) FEC in host system)\n",
225 pfx);
226 if (id[36] == 0x25)
227 printf("%s Extended: 100GBASE-DR (clause 140), CAUI-4 (no FEC)\n", pfx);
228 if (id[36] == 0x26)
229 printf("%s Extended: 100G-FR or 100GBASE-FR1 (clause 140), CAUI-4 (no FEC)\n", pfx);
230 if (id[36] == 0x27)
231 printf("%s Extended: 100G-LR or 100GBASE-LR1 (clause 140), CAUI-4 (no FEC)\n", pfx);
232 if (id[36] == 0x30)
233 printf("%s Extended: Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below\n",
234 pfx);
235 if (id[36] == 0x31)
236 printf("%s Extended: Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below\n",
237 pfx);
238 if (id[36] == 0x32)
239 printf("%s Extended: Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below\n",
240 pfx);
241 if (id[36] == 0x33)
242 printf("%s Extended: Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below\n",
243 pfx);
244 if (id[36] == 0x40)
245 printf("%s Extended: 50GBASE-CR, 100GBASE-CR2, or 200GBASE-CR4\n", pfx);
246 if (id[36] == 0x41)
247 printf("%s Extended: 50GBASE-SR, 100GBASE-SR2, or 200GBASE-SR4\n", pfx);
248 if (id[36] == 0x42)
249 printf("%s Extended: 50GBASE-FR or 200GBASE-DR4\n", pfx);
250 if (id[36] == 0x43)
251 printf("%s Extended: 200GBASE-FR4\n", pfx);
252 if (id[36] == 0x44)
253 printf("%s Extended: 200G 1550 nm PSM4\n", pfx);
254 if (id[36] == 0x45)
255 printf("%s Extended: 50GBASE-LR\n", pfx);
256 if (id[36] == 0x46)
257 printf("%s Extended: 200GBASE-LR4\n", pfx);
258 if (id[36] == 0x50)
259 printf("%s Extended: 64GFC EA\n", pfx);
260 if (id[36] == 0x51)
261 printf("%s Extended: 64GFC SW\n", pfx);
262 if (id[36] == 0x52)
263 printf("%s Extended: 64GFC LW\n", pfx);
264 if (id[36] == 0x53)
265 printf("%s Extended: 128GFC EA\n", pfx);
266 if (id[36] == 0x54)
267 printf("%s Extended: 128GFC SW\n", pfx);
268 if (id[36] == 0x55)
269 printf("%s Extended: 128GFC LW\n", pfx);
270 }
271
sff8079_show_encoding(const __u8 * id)272 static void sff8079_show_encoding(const __u8 *id)
273 {
274 sff8024_show_encoding(id, 11, ETH_MODULE_SFF_8472);
275 }
276
sff8079_show_rate_identifier(const __u8 * id)277 static void sff8079_show_rate_identifier(const __u8 *id)
278 {
279 printf("\t%-41s : 0x%02x", "Rate identifier", id[13]);
280 switch (id[13]) {
281 case 0x00:
282 printf(" (unspecified)\n");
283 break;
284 case 0x01:
285 printf(" (4/2/1G Rate_Select & AS0/AS1)\n");
286 break;
287 case 0x02:
288 printf(" (8/4/2G Rx Rate_Select only)\n");
289 break;
290 case 0x03:
291 printf(" (8/4/2G Independent Rx & Tx Rate_Select)\n");
292 break;
293 case 0x04:
294 printf(" (8/4/2G Tx Rate_Select only)\n");
295 break;
296 default:
297 printf(" (reserved or unknown)\n");
298 break;
299 }
300 }
301
sff8079_show_oui(const __u8 * id)302 static void sff8079_show_oui(const __u8 *id)
303 {
304 printf("\t%-41s : %02x:%02x:%02x\n", "Vendor OUI",
305 id[37], id[38], id[39]);
306 }
307
sff8079_show_wavelength_or_copper_compliance(const __u8 * id)308 static void sff8079_show_wavelength_or_copper_compliance(const __u8 *id)
309 {
310 if (id[8] & (1 << 2)) {
311 printf("\t%-41s : 0x%02x", "Passive Cu cmplnce.", id[60]);
312 switch (id[60]) {
313 case 0x00:
314 printf(" (unspecified)");
315 break;
316 case 0x01:
317 printf(" (SFF-8431 appendix E)");
318 break;
319 default:
320 printf(" (unknown)");
321 break;
322 }
323 printf(" [SFF-8472 rev10.4 only]\n");
324 } else if (id[8] & (1 << 3)) {
325 printf("\t%-41s : 0x%02x", "Active Cu cmplnce.", id[60]);
326 switch (id[60]) {
327 case 0x00:
328 printf(" (unspecified)");
329 break;
330 case 0x01:
331 printf(" (SFF-8431 appendix E)");
332 break;
333 case 0x04:
334 printf(" (SFF-8431 limiting)");
335 break;
336 default:
337 printf(" (unknown)");
338 break;
339 }
340 printf(" [SFF-8472 rev10.4 only]\n");
341 } else {
342 printf("\t%-41s : %unm\n", "Laser wavelength",
343 (id[60] << 8) | id[61]);
344 }
345 }
346
sff8079_show_value_with_unit(const __u8 * id,unsigned int reg,const char * name,unsigned int mult,const char * unit)347 static void sff8079_show_value_with_unit(const __u8 *id, unsigned int reg,
348 const char *name, unsigned int mult,
349 const char *unit)
350 {
351 unsigned int val = id[reg];
352
353 printf("\t%-41s : %u%s\n", name, val * mult, unit);
354 }
355
sff8079_show_ascii(const __u8 * id,unsigned int first_reg,unsigned int last_reg,const char * name)356 static void sff8079_show_ascii(const __u8 *id, unsigned int first_reg,
357 unsigned int last_reg, const char *name)
358 {
359 unsigned int reg, val;
360
361 printf("\t%-41s : ", name);
362 while (first_reg <= last_reg && id[last_reg] == ' ')
363 last_reg--;
364 for (reg = first_reg; reg <= last_reg; reg++) {
365 val = id[reg];
366 putchar(((val >= 32) && (val <= 126)) ? val : '_');
367 }
368 printf("\n");
369 }
370
sff8079_show_options(const __u8 * id)371 static void sff8079_show_options(const __u8 *id)
372 {
373 static const char *pfx =
374 "\tOption :";
375
376 printf("\t%-41s : 0x%02x 0x%02x\n", "Option values", id[64], id[65]);
377 if (id[65] & (1 << 1))
378 printf("%s RX_LOS implemented\n", pfx);
379 if (id[65] & (1 << 2))
380 printf("%s RX_LOS implemented, inverted\n", pfx);
381 if (id[65] & (1 << 3))
382 printf("%s TX_FAULT implemented\n", pfx);
383 if (id[65] & (1 << 4))
384 printf("%s TX_DISABLE implemented\n", pfx);
385 if (id[65] & (1 << 5))
386 printf("%s RATE_SELECT implemented\n", pfx);
387 if (id[65] & (1 << 6))
388 printf("%s Tunable transmitter technology\n", pfx);
389 if (id[65] & (1 << 7))
390 printf("%s Receiver decision threshold implemented\n", pfx);
391 if (id[64] & (1 << 0))
392 printf("%s Linear receiver output implemented\n", pfx);
393 if (id[64] & (1 << 1))
394 printf("%s Power level 2 requirement\n", pfx);
395 if (id[64] & (1 << 2))
396 printf("%s Cooled transceiver implemented\n", pfx);
397 if (id[64] & (1 << 3))
398 printf("%s Retimer or CDR implemented\n", pfx);
399 if (id[64] & (1 << 4))
400 printf("%s Paging implemented\n", pfx);
401 if (id[64] & (1 << 5))
402 printf("%s Power level 3 requirement\n", pfx);
403 }
404
sff8079_show_all_common(const __u8 * id)405 static void sff8079_show_all_common(const __u8 *id)
406 {
407 sff8079_show_identifier(id);
408 if (((id[0] == 0x02) || (id[0] == 0x03)) && (id[1] == 0x04)) {
409 unsigned int br_nom, br_min, br_max;
410
411 if (id[12] == 0) {
412 br_nom = br_min = br_max = 0;
413 } else if (id[12] == 255) {
414 br_nom = id[66] * 250;
415 br_max = id[67];
416 br_min = id[67];
417 } else {
418 br_nom = id[12] * 100;
419 br_max = id[66];
420 br_min = id[67];
421 }
422 sff8079_show_ext_identifier(id);
423 sff8079_show_connector(id);
424 sff8079_show_transceiver(id);
425 sff8079_show_encoding(id);
426 printf("\t%-41s : %u%s\n", "BR, Nominal", br_nom, "MBd");
427 sff8079_show_rate_identifier(id);
428 sff8079_show_value_with_unit(id, 14,
429 "Length (SMF,km)", 1, "km");
430 sff8079_show_value_with_unit(id, 15, "Length (SMF)", 100, "m");
431 sff8079_show_value_with_unit(id, 16, "Length (50um)", 10, "m");
432 sff8079_show_value_with_unit(id, 17,
433 "Length (62.5um)", 10, "m");
434 sff8079_show_value_with_unit(id, 18, "Length (Copper)", 1, "m");
435 sff8079_show_value_with_unit(id, 19, "Length (OM3)", 10, "m");
436 sff8079_show_wavelength_or_copper_compliance(id);
437 sff8079_show_ascii(id, 20, 35, "Vendor name");
438 sff8079_show_oui(id);
439 sff8079_show_ascii(id, 40, 55, "Vendor PN");
440 sff8079_show_ascii(id, 56, 59, "Vendor rev");
441 sff8079_show_options(id);
442 printf("\t%-41s : %u%s\n", "BR margin, max", br_max, "%");
443 printf("\t%-41s : %u%s\n", "BR margin, min", br_min, "%");
444 sff8079_show_ascii(id, 68, 83, "Vendor SN");
445 sff8079_show_ascii(id, 84, 91, "Date code");
446 }
447 }
448
sff8079_show_all_ioctl(const __u8 * id)449 void sff8079_show_all_ioctl(const __u8 *id)
450 {
451 sff8079_show_all_common(id);
452 }
453
sff8079_get_eeprom_page(struct cmd_context * ctx,u8 i2c_address,__u8 * buf)454 static int sff8079_get_eeprom_page(struct cmd_context *ctx, u8 i2c_address,
455 __u8 *buf)
456 {
457 struct ethtool_module_eeprom request = {
458 .length = SFF8079_PAGE_SIZE,
459 .i2c_address = i2c_address,
460 };
461 int ret;
462
463 ret = nl_get_eeprom_page(ctx, &request);
464 if (!ret)
465 memcpy(buf, request.data, SFF8079_PAGE_SIZE);
466
467 return ret;
468 }
469
sff8079_show_all_nl(struct cmd_context * ctx)470 int sff8079_show_all_nl(struct cmd_context *ctx)
471 {
472 u8 *buf;
473 int ret;
474
475 /* The SFF-8472 parser expects a single buffer that contains the
476 * concatenation of the first 256 bytes from addresses A0h and A2h,
477 * respectively.
478 */
479 buf = calloc(1, ETH_MODULE_SFF_8472_LEN);
480 if (!buf)
481 return -ENOMEM;
482
483 /* Read A0h page */
484 ret = sff8079_get_eeprom_page(ctx, SFF8079_I2C_ADDRESS_LOW, buf);
485 if (ret)
486 goto out;
487
488 sff8079_show_all_common(buf);
489
490 /* Finish if A2h page is not present */
491 if (!(buf[92] & (1 << 6)))
492 goto out;
493
494 /* Read A2h page */
495 ret = sff8079_get_eeprom_page(ctx, SFF8079_I2C_ADDRESS_HIGH,
496 buf + ETH_MODULE_SFF_8079_LEN);
497 if (ret)
498 goto out;
499
500 sff8472_show_all(buf);
501 out:
502 free(buf);
503
504 return ret;
505 }
506