board: turris: Allow to specify first eth idx of first MAC address
Turris Omnia uses first MAC address from OTP for second ethernet interface.
Second MAC address for third interface and third MAC address for first
interface.
Other Turris routers do not have this rotate by one mapping. So add
function parameter for specifying id of the first ethernet interface.
Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
diff --git a/board/CZ.NIC/turris_atsha_otp.c b/board/CZ.NIC/turris_atsha_otp.c
index 840721a..7a39b7f 100644
--- a/board/CZ.NIC/turris_atsha_otp.c
+++ b/board/CZ.NIC/turris_atsha_otp.c
@@ -49,7 +49,7 @@
eth_env_set_enetaddr_by_index("eth", i, mac);
}
-int turris_atsha_otp_init_mac_addresses(void)
+int turris_atsha_otp_init_mac_addresses(int first_idx)
{
struct udevice *dev = get_atsha204a_dev();
u8 mac0[4], mac1[4], mac[6];
@@ -81,11 +81,11 @@
mac[4] = mac1[2];
mac[5] = mac1[3];
- set_mac_if_invalid(1, mac);
+ set_mac_if_invalid((first_idx + 0) % 3, mac);
increment_mac(mac);
- set_mac_if_invalid(2, mac);
+ set_mac_if_invalid((first_idx + 1) % 3, mac);
increment_mac(mac);
- set_mac_if_invalid(0, mac);
+ set_mac_if_invalid((first_idx + 2) % 3, mac);
return 0;
}
diff --git a/board/CZ.NIC/turris_atsha_otp.h b/board/CZ.NIC/turris_atsha_otp.h
index 667d01a..bd4308f 100644
--- a/board/CZ.NIC/turris_atsha_otp.h
+++ b/board/CZ.NIC/turris_atsha_otp.h
@@ -3,7 +3,7 @@
#ifndef TURRIS_ATSHA_OTP_H
#define TURRIS_ATSHA_OTP_H
-int turris_atsha_otp_init_mac_addresses(void);
+int turris_atsha_otp_init_mac_addresses(int first_idx);
int turris_atsha_otp_get_serial_number(u32 *version_num, u32 *serial_num);
#endif
diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c
index 719e875..da2fee5 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
@@ -606,7 +606,7 @@
int misc_init_r(void)
{
- turris_atsha_otp_init_mac_addresses();
+ turris_atsha_otp_init_mac_addresses(1);
return 0;
}