2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
20 import sigrokdecode as srd
25 0x02: 'Integrated module/connector',
39 4: "Temp high warning",
40 6: "Temp low warning",
41 16: "Bias high alarm",
43 20: "Bias high warning",
44 22: "Bias low warning",
45 24: "TX power high alarm",
46 26: "TX power low alarm",
47 28: "TX power high warning",
48 30: "TX power low warning",
49 32: "RX power high alarm",
50 34: "RX power low alarm",
51 36: "RX power high warning",
52 38: "RX power low warning",
53 40: "AUX 1 high alarm",
54 42: "AUX 1 low alarm",
55 44: "AUX 1 high warning",
56 46: "AUX 1 low warning",
57 48: "AUX 2 high alarm",
58 50: "AUX 2 low alarm",
59 52: "AUX 2 high warning",
60 54: "AUX 2 low warning",
64 0: "Module temperature",
66 6: "Measured TX output power",
67 8: "Measured RX input power",
68 10: "AUX 1 measurement",
69 12: "AUX 2 measurement",
90 0x02: "Fibre Channel style 1 copper",
91 0x03: "Fibre Channel style 2 copper",
93 0x05: "Fibre Channel coax",
99 0x0b: "Optical pigtail",
101 0x21: "Copper pigtail",
106 ["10GBASE-SR", "10GBASE-LR", "10GBASE-ER", "10GBASE-LRM", "10GBASE-SW",
107 "10GBASE-LW", "10GBASE-EW"],
109 ["1200-MX-SN-I", "1200-SM-LL-L", "Extended Reach 1550 nm",
110 "Intermediate reach 1300 nm FP"],
114 ["1000BASE-SX / 1xFC MMF", "1000BASE-LX / 1xFC SMF", "2xFC MMF",
115 "2xFC SMF", "OC48-SR", "OC48-IR", "OC48-LR"],
116 # 10GB SONET/SDH interconnect
117 ["I-64.1r", "I-64.1", "I-64.2r", "I-64.2", "I-64.3", "I-64.5"],
118 # 10GB SONET/SDH short haul
119 ["S-64.1", "S-64.2a", "S-64.2b", "S-64.3a", "S-64.3b", "S-64.5a", "S-64.5b"],
120 # 10GB SONET/SDH long haul
121 ["L-64.1", "L-64.2a", "L-64.2b", "L-64.2c", "L-64.3", "G.959.1 P1L1-2D2"],
122 # 10GB SONET/SDH very long haul
123 ["V-64.2a", "V-64.2b", "V-64.3"],
153 "lineside loopback mode",
158 ["no wavelength control", "sctive wavelength control"],
159 ["uncooled transmitter device", "cooled transmitter"],
160 ["PIN detector", "APD detector"],
161 ["transmitter not tunable", "transmitter tunable"],
168 "VPS LV regulator mode",
169 "VPS bypassed regulator mode",
170 "active FEC control",
171 "wavelength tunability",
183 "3.3V supply voltage",
184 "1.8V supply voltage",
185 "-5.2V supply voltage",
189 "3.3V supply current",
190 "1.8V supply current",
191 "-5.2V supply current",
194 class Decoder(srd.Decoder):
198 longname = '10 Gigabit Small Form Factor Pluggable Module (XFP)'
199 desc = 'Data structure describing display device capabilities.'
207 ['fieldnames-and-values', 'XFP structure field names and values'],
208 ['fields', 'XFP structure fields'],
211 def __init__(self, **kwargs):
212 # Received data items, used as an index into samplenum/data
214 # Start/end sample numbers per data item
216 # Multi-byte structure buffer
218 # Filled in by address 0x7f in low memory
219 self.cur_highmem_page = 0
220 # Filled in by extended ID value in table 2
221 self.have_clei = False
222 # Handlers for each field in the structure, keyed by the end
223 # index of that field. Each handler is fed all unhandled bytes
224 # up until that point, so mark unused space with the dummy
225 # handler self.ignore().
226 self.MAP_LOWER_MEMORY = {
229 57: self.alarm_warnings,
233 75: self.wavelength_cr,
236 109: self.ad_readout,
242 127: self.page_select,
244 self.MAP_HIGH_TABLE_1 = {
246 129: self.ext_module_id,
248 138: self.transceiver,
249 139: self.serial_encoding,
252 142: self.link_length_smf,
253 143: self.link_length_e50,
254 144: self.link_length_50um,
255 145: self.link_length_625um,
256 146: self.link_length_copper,
257 147: self.device_tech,
260 167: self.vendor_oui,
262 185: self.vendor_rev,
263 187: self.wavelength,
264 189: self.wavelength_tolerance,
265 190: self.max_case_temp,
267 195: self.power_supply,
269 219: self.manuf_date,
271 221: self.enhanced_opts,
274 255: self.maybe_ascii,
278 self.out_ann = self.register(srd.OUTPUT_ANN)
280 def decode(self, ss, es, data):
283 # We only care about actual data bytes that are read (for now).
284 if cmd != 'DATA READ':
288 self.sn.append([ss, es])
290 self.buf.append(data)
292 if self.cnt in self.MAP_LOWER_MEMORY:
293 self.MAP_LOWER_MEMORY[self.cnt](self.buf)
295 elif self.cnt < 0x0100 and self.cur_highmem_page == 0x01:
296 # Serial ID memory map
297 if self.cnt in self.MAP_HIGH_TABLE_1:
298 self.MAP_HIGH_TABLE_1[self.cnt](self.buf)
302 def annotate(self, key, value, start_cnt=None, end_cnt=None):
303 if start_cnt is None:
304 start_cnt = self.cnt - len(self.buf) + 1
307 self.put(self.sn[start_cnt][0], self.sn[end_cnt][1],
308 self.out_ann, [0, [key + ": " + value]])
309 self.put(self.sn[start_cnt][0], self.sn[end_cnt][1],
310 self.out_ann, [1, [value]])
312 # Placeholder handler, needed to advance the buffer past unused or
313 # reserved space in the structures.
314 def ignore(self, data):
317 # Show as ASCII if possible
318 def maybe_ascii(self, data):
319 for i in range(len(data)):
320 if data[i] >= 0x20 and data[i] < 0x7f:
321 cnt = self.cnt - len(data) + 1
322 self.annotate("Vendor ID", chr(data[i]), cnt, cnt)
324 # Convert 16-bit two's complement values, with each increment
325 # representing 1/256C, to degrees Celcius.
326 def to_temp(self, value):
328 value = -((value ^ 0xffff) + 1)
330 return "%.1f C" % temp
332 # TX bias current in uA. Each increment represents 0.2uA
333 def to_current(self, value):
334 current = value / 500000.0
335 return "%.1f mA" % current
337 # Power in mW, with each increment representing 0.1uW
338 def to_power(self, value):
339 power = value / 10000.0
340 return "%.2f mW" % power
342 # Wavelength in increments of 0.05nm
343 def to_wavelength(self, value):
347 # Wavelength in increments of 0.005nm
348 def to_wavelength_tolerance(self, value):
350 return "%.1f nm" % wl
352 def module_id(self, data):
353 self.annotate("Module identifier", MODULE_ID.get(data[0], "Unknown"))
355 def signal_cc(self, data):
356 # No good data available.
357 if (data[0] != 0x00):
358 self.annotate("Signal Conditioner Control", "%.2x" % data[0])
360 def alarm_warnings(self, data):
361 cnt_idx = self.cnt - len(data)
365 # Skip over reserved A/D flag thresholds
367 value = (data[idx] << 8) | data[idx + 1]
369 name = ALARM_THRESHOLDS.get(idx, "...")
370 if idx in (0, 2, 4, 6):
371 self.annotate(name, self.to_temp(value),
372 cnt_idx + idx, cnt_idx + idx + 1)
373 elif idx in (16, 18, 20, 22):
374 self.annotate(name, self.to_current(value),
375 cnt_idx + idx, cnt_idx + idx + 1)
376 elif idx in (24, 26, 28, 30, 32, 34, 36, 38):
377 self.annotate(name, self.to_power(value),
378 cnt_idx + idx, cnt_idx + idx + 1)
380 self.annotate(name, "%d" % name, value, cnt_idx + idx,
385 # No good data available.
387 self.annotate("VPS", "%.2x%.2x" % (data[0], data[1]))
390 # No good data available.
392 self.annotate("BER", str(data))
394 def wavelength_cr(self, data):
395 # No good data available.
396 if (data != [0, 0, 0, 0]):
397 self.annotate("WCR", str(data))
399 def fec_cr(self, data):
400 if (data != [0, 0, 0, 0]):
401 self.annotate("FEC", str(data))
403 def int_ctrl(self, data):
404 # No good data available. Also boring.
407 out.append("%.2x" % d)
408 self.annotate("Interrupt bits", ' '.join(out))
410 def ad_readout(self, data):
411 cnt_idx = self.cnt - len(data) + 1
415 # Skip over reserved field
417 value = (data[idx] << 8) | data[idx + 1]
418 name = AD_READOUTS.get(idx, "...")
421 self.annotate(name, self.to_temp(value),
422 cnt_idx + idx, cnt_idx + idx + 1)
424 self.annotate(name, self.to_current(value),
425 cnt_idx + idx, cnt_idx + idx + 1)
427 self.annotate(name, self.to_power(value),
428 cnt_idx + idx, cnt_idx + idx + 1)
430 self.annotate(name, str(value), cnt_idx + idx,
435 allbits = (data[0] << 8) | data[1]
439 out.append(GCS_BITS[b])
441 self.annotate("General Control/Status", ', '.join(out))
443 def page_select(self, data):
444 self.cur_highmem_page = data[0]
446 def ext_module_id(self, data):
447 out = ["Power level %d module" % ((data[0] >> 6) + 1)]
448 if data[0] & 0x20 == 0:
450 if data[0] & 0x10 == 0:
451 out.append("TX ref clock input required")
452 if data[0] & 0x08 == 0:
453 self.have_clei = True
454 self.annotate("Extended id", ', '.join(out))
456 def connector(self, data):
457 if data[0] in CONNECTOR:
458 self.annotate("Connector", CONNECTOR[data[0]])
460 def transceiver(self, data):
468 if len(TRANSCEIVER[t]) < b + 1:
469 out.append("(unknown)")
471 out.append(TRANSCEIVER[t][b])
473 self.annotate("Transceiver compliance", ', '.join(out))
475 def serial_encoding(self, data):
480 if len(SERIAL_ENCODING) < b + 1:
481 out.append("(unknown)")
483 out.append(SERIAL_ENCODING[b])
485 self.annotate("Serial encoding support", ', '.join(out))
487 def br_min(self, data):
488 # Increments represent 100Mb/s
489 rate = data[0] / 10.0
490 self.annotate("Minimum bit rate", "%.3f GB/s" % rate)
492 def br_max(self, data):
493 # Increments represent 100Mb/s
494 rate = data[0] / 10.0
495 self.annotate("Maximum bit rate", "%.3f GB/s" % rate)
497 def link_length_smf(self, data):
499 length = "(standard)"
503 length = "%d km" % data[0]
504 self.annotate("Link length (SMF)", length)
506 def link_length_e50(self, data):
508 length = "(standard)"
512 length = "%d m" % (data[0] * 2)
513 self.annotate("Link length (extended, 50μm MMF)", length)
515 def link_length_50um(self, data):
517 length = "(standard)"
521 length = "%d m" % data[0]
522 self.annotate("Link length (50μm MMF)", length)
524 def link_length_625um(self, data):
526 length = "(standard)"
530 length = "%d m" % (data[0])
531 self.annotate("Link length (62.5μm MMF)", length)
533 def link_length_copper(self, data):
539 length = "%d m" % (data[0] * 2)
540 self.annotate("Link length (copper)", length)
542 def device_tech(self, data):
545 if xmit <= len(XMIT_TECH) - 1:
546 out.append("%s transmitter" % XMIT_TECH[xmit])
549 out.append(DEVICE_TECH[b][(dev >> (3 - b)) & 0x01])
550 self.annotate("Device technology", ', '.join(out))
552 def vendor(self, data):
553 name = bytes(data).strip().decode('ascii').strip('\x00')
555 self.annotate("Vendor", name)
564 self.annotate("CDR support", ', '.join(out))
566 def vendor_oui(self, data):
567 if data != [0, 0, 0]:
568 self.annotate("Vendor OUI", "%.2X-%.2X-%.2X" % tuple(data))
570 def vendor_pn(self, data):
571 name = bytes(data).strip().decode('ascii').strip('\x00')
573 self.annotate("Vendor part number", name)
575 def vendor_rev(self, data):
576 name = bytes(data).strip().decode('ascii').strip('\x00')
578 self.annotate("Vendor revision", name)
580 def wavelength(self, data):
581 value = (data[0] << 8) | data[1]
582 self.annotate("Wavelength", self.to_wavelength(value))
584 def wavelength_tolerance(self, data):
585 value = (data[0] << 8) | data[1]
586 self.annotate("Wavelength tolerance", self.to_wavelength_tolerance(value))
588 def max_case_temp(self, data):
589 self.annotate("Maximum case temperature", "%d C" % data[0])
591 def power_supply(self, data):
593 self.annotate("Max power dissipation",
594 "%.3f W" % (data[0] * 0.02), self.cnt - 3, self.cnt - 3)
595 self.annotate("Max power dissipation (powered down)",
596 "%.3f W" % (data[1] * 0.01), self.cnt - 2, self.cnt - 2)
597 value = (data[2] >> 4) * 0.050
598 self.annotate("Max current required (5V supply)",
599 "%.3f A" % value, self.cnt - 1, self.cnt - 1)
600 value = (data[2] & 0x0f) * 0.100
601 self.annotate("Max current required (3.3V supply)",
602 "%.3f A" % value, self.cnt - 1, self.cnt - 1)
603 value = (data[3] >> 4) * 0.100
604 self.annotate("Max current required (1.8V supply)",
605 "%.3f A" % value, self.cnt, self.cnt)
606 value = (data[3] & 0x0f) * 0.050
607 self.annotate("Max current required (-5.2V supply)",
608 "%.3f A" % value, self.cnt, self.cnt)
610 def vendor_sn(self, data):
611 name = bytes(data).strip().decode('ascii').strip('\x00')
613 self.annotate("Vendor serial number", name)
615 def manuf_date(self, data):
616 y = int(bytes(data[0:2])) + 2000
617 m = int(bytes(data[2:4]))
618 d = int(bytes(data[4:6]))
619 mnf = "%.4d-%.2d-%.2d" % (y, m, d)
620 lot = bytes(data[6:]).strip().decode('ascii').strip('\x00')
623 self.annotate("Manufacturing date", mnf)
625 def diag_mon(self, data):
628 out.append("BER support")
630 out.append("no BER support")
632 out.append("average power measurement")
634 out.append("OMA power measurement")
635 self.annotate("Diagnostic monitoring", ', '.join(out))
637 def enhanced_opts(self, data):
642 out.append(ENHANCED_OPTS[b])
644 self.annotate("Enhanced option support", ', '.join(out))
646 def aux_mon(self, data):
647 aux = AUX_TYPES[data[0] >> 4]
648 self.annotate("AUX1 monitoring", aux)
649 aux = AUX_TYPES[data[0] & 0x0f]
650 self.annotate("AUX2 monitoring", aux)