Last active
October 13, 2024 12:26
-
-
Save bluecmd/039e432881ef3210c8cbb761b0779b6f to your computer and use it in GitHub Desktop.
Simple utility to test tuneable SFP modules implementing SFF-8690
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
int fd = open(argv[1], O_RDWR); | |
if (fd < 0) { | |
perror("open"); | |
return 1; | |
} | |
uint8_t ident = 0x0; | |
pread(fd, &ident, 1, 65); | |
if (((ident >> 6) & 0x1) == 0) { | |
printf("Not tuneable\n"); | |
return 1; | |
} | |
uint8_t page = 0x2; | |
pwrite(fd, &page, 1, 0x100 + 127); | |
pread(fd, &ident, 1, 0x180); | |
printf("Tunable features: (raw: 0x%x)\n", ident); | |
if ((ident & 0x1) != 0) { | |
printf(" - Tunable DWDM (selection in 50pm steps)\n"); | |
} | |
if ((ident & 0x2) != 0) { | |
printf(" - Tunable DWDM (selection by channel number)\n"); | |
} | |
if ((ident & 0x4) != 0) { | |
printf(" - Tx Dither Supported\n"); | |
} | |
if ((ident & 0x8) != 0) { | |
printf(" - Self Tuning via Smart Tunable MSA Supported\n"); | |
} | |
if ((ident & 0x10) != 0) { | |
printf(" - Tuning support via other methods supported\n"); | |
} | |
uint8_t status = 0; | |
pread(fd, &status, 1, 0x100 + 168); | |
printf("Current status: 0x%x\n", status); | |
if ((status & (1 << 4)) != 0) { | |
printf(" - TX not ready, tuning ...\n"); | |
} | |
if ((status & (1 << 5)) != 0) { | |
printf(" - Wavelength unlocked\n"); | |
} | |
if ((status & (1 << 6)) != 0) { | |
// What is TEC? | |
printf(" - TEC fault\n"); | |
} | |
uint16_t channel = 0; | |
uint16_t channel_set = 0; | |
pread(fd, &channel, 2, 0x100 + 144); | |
uint16_t laser_first_freq = 0; | |
uint16_t laser_first_freq_sub = 0; | |
pread(fd, &laser_first_freq, 2, 0x100 + 132); | |
pread(fd, &laser_first_freq_sub, 2, 0x100 + 134); | |
laser_first_freq = ((laser_first_freq & 0xff) << 8) | (laser_first_freq >> 8); | |
laser_first_freq_sub = ((laser_first_freq_sub & 0xff) << 8) | (laser_first_freq_sub >> 8); | |
uint16_t laser_last_freq = 0; | |
uint16_t laser_last_freq_sub = 0; | |
pread(fd, &laser_last_freq, 2, 0x100 + 136); | |
pread(fd, &laser_last_freq_sub, 2, 0x100 + 138); | |
laser_last_freq = ((laser_last_freq & 0xff) << 8) | (laser_last_freq >> 8); | |
laser_last_freq_sub = ((laser_last_freq_sub & 0xff) << 8) | (laser_last_freq_sub >> 8); | |
uint16_t laser_grid_spacing = 0; | |
pread(fd, &laser_grid_spacing, 2, 0x100 + 140); | |
laser_grid_spacing = ((laser_grid_spacing & 0xff) << 8) | (laser_grid_spacing >> 8); | |
printf("Laser first frequency: %d.%d THz\n", laser_first_freq, laser_first_freq_sub); | |
printf("Laser last frequency: %d.%d THz\n", laser_last_freq, laser_last_freq_sub); | |
printf("Laser grid spacing: %.2f GHz\n", (double)(laser_grid_spacing) / 10.0f); | |
channel = ((channel & 0xff) << 8) | (channel >> 8); | |
printf("Current channel: %d\n", channel); | |
printf("Offset: %.2f THz\n", laser_first_freq + (double)(laser_first_freq_sub) / 10000.0f +((channel-1) * ((double)(laser_grid_spacing) / 10.0f / 1000.0f))); | |
// Try to re-activate the channel | |
channel_set = channel; | |
if (argc == 3) { | |
channel_set = atoi(argv[2]); | |
} | |
printf("Activating channel %d ...\n", channel_set); | |
channel_set = ((channel_set & 0xff) << 8) | (channel_set >> 8); | |
pwrite(fd, &channel_set, 2, 0x100 + 144); | |
pread(fd, &channel, 2, 0x100 + 146); | |
channel = ((channel & 0xff) << 8) | (channel >> 8); | |
printf("Current wavelength: %.2f nm\n", channel * 0.05f); | |
pread(fd, &status, 1, 0x100 + 110); | |
printf("Current operational status: 0x%x\n", status); | |
if ((status & (1 << 0)) != 0) { | |
printf(" - Data_not_ready\n"); | |
} | |
if ((status & (1 << 1)) != 0) { | |
printf(" - Rx_LOS State\n"); | |
} | |
if ((status & (1 << 2)) != 0) { | |
printf(" - TX Fault State\n"); | |
} | |
if ((status & (1 << 7)) != 0) { | |
printf(" - TX disable state\n"); | |
} | |
if ((status & (1 << 6)) != 0) { | |
printf(" - Soft TX disable state\n"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cumulus@ixp-lab-sw1:mgmt:~$ sudo ./a.out /sys/devices/platform/cel_fpga_i2c.9/i2c-19/i2c-68/68-0050/eeprom 100 | |
Tunable features: (raw: 0x7) | |
- Tunable DWDM (selection in 50pm steps) | |
- Tunable DWDM (selection by channel number) | |
- Tx Dither Supported | |
Current status: 0x0 | |
Current channel: 102 | |
Activating channel 100 ... | |
Current wavelength: 1529.15 nm | |
Current operational status: 0x4 | |
- TX Fault State |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment