Commit d73cba9a authored by Cesar Prados's avatar Cesar Prados Committed by Alessandro Rubini

sdb-eeprom: add funcitons for MAC access

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 535fe62f
......@@ -15,6 +15,5 @@ obj-$(CONFIG_SDB_EEPROM) += dev/sdb-eeprom.o
obj-$(CONFIG_SOCKITOWM) += dev/onewire.o
obj-$(CONFIG_W1) += dev/w1.o dev/w1-hw.o
obj-$(CONFIG_W1) += dev/w1-temp.o dev/w1-eeprom.o
obj-$(CONFIG_W1) += dev/mac.o
obj-$(CONFIG_UART) += dev/uart.o
obj-$(CONFIG_UART_SW) += dev/uart-sw.o
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <wrc.h>
#include <w1.h>
/* This used to be part of dev/onewire.c, but is not onewire-specific */
/* 0 = success, -1 = error */
int8_t get_persistent_mac(uint8_t portnum, uint8_t * mac)
{
int i, class;
uint64_t rom;
for (i = 0; i < W1_MAX_DEVICES; i++) {
class = w1_class(wrpc_w1_bus.devs + i);
if (class != 0x28 && class != 0x42)
continue;
rom = wrpc_w1_bus.devs[i].rom;
mac[3] = rom >> 24;
mac[4] = rom >> 16;
mac[5] = rom >> 8;
return 0;
}
return -1;
/* FIXME: add eeprom support */
}
/* 0 = success, -1 = error */
int8_t set_persistent_mac(uint8_t portnum, uint8_t * mac)
{
/* FIXME: add eeprom support */
return -1;
}
......@@ -111,6 +111,66 @@ uint8_t eeprom_present(uint8_t i2cif, uint8_t i2c_addr)
return 0;
}
/*
* Reading/writing the MAC address used to be part of dev/onewire.c,
* but is not onewire-specific. What is w1-specific is the default
* setting if no sdbfs is there, but CONFIG_SDB_EEPROM depends on
* CONFIG_W1 anyways.
*/
int32_t get_persistent_mac(uint8_t portnum, uint8_t * mac)
{
int ret;
int i, class;
uint64_t rom;
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_MAC) < 0)
return -1;
ret = sdbfs_fread(&wrc_sdb, 0, mac, 6);
sdbfs_close(&wrc_sdb);
if(ret < 0)
pp_printf("%s: SDB error\n", __func__);
if (mac[0] == 0xff ||
(mac[0] | mac[1] | mac[2] | mac[3] | mac[4] | mac[5]) == 0) {
pp_printf("%s: SDB file is empty\n", __func__);
ret = -1;
}
if (ret < 0) {
pp_printf("%s: Using W1 serial number\n", __func__);
for (i = 0; i < W1_MAX_DEVICES; i++) {
class = w1_class(wrpc_w1_bus.devs + i);
if (class != 0x28 && class != 0x42)
continue;
rom = wrpc_w1_bus.devs[i].rom;
mac[3] = rom >> 24;
mac[4] = rom >> 16;
mac[5] = rom >> 8;
ret = 0;
}
}
if (ret < 0) {
pp_printf("%s: failure\n", __func__);
return -1;
}
return 0;
}
int8_t set_persistent_mac(uint8_t portnum, uint8_t * mac)
{
int ret;
ret = sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_MAC);
if (ret >= 0)
ret = sdbfs_fwrite(&wrc_sdb, 0, mac, 6);
sdbfs_close(&wrc_sdb);
if (ret < 0) {
pp_printf("%s: SDB error, can't save\n", __func__);
return -1;
}
return 0;
}
/*
* The SFP section is placed somewhere inside EEPROM (W1 or I2C), using sdbfs.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment