drivers/intel/i210: Define MAC_ADDR_LEN

Define and use the MAC_ADDR_LEN macro in place of the `6` magic value.

Change-Id: Icfa2ad9bca6668bea3d84b10f613d01e437ac6a2
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/47404
Tested-by: siemens-bot
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
This commit is contained in:
Angel Pons 2020-11-10 17:08:11 +01:00 committed by Patrick Georgi
parent a9db4bd989
commit c19a9a5278
2 changed files with 7 additions and 6 deletions

View File

@ -27,9 +27,10 @@
#define I210_CHECKSUM_ERROR 0x00000010 #define I210_CHECKSUM_ERROR 0x00000010
#define I210_FLASH_UPDATE_ERROR 0x00000020 #define I210_FLASH_UPDATE_ERROR 0x00000020
#define MAC_ADDR_LEN 6
/* We need one function we can call to get a MAC address to use */ /* We need one function we can call to get a MAC address to use */
/* This function can be coded somewhere else but must exist. */ /* This function can be coded somewhere else but must exist. */
extern enum cb_err mainboard_get_mac_address(struct device *dev, extern enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[MAC_ADDR_LEN]);
uint8_t mac[6]);
#endif /* _INTEL_I210_H_ */ #endif /* _INTEL_I210_H_ */

View File

@ -33,9 +33,9 @@
* @param mac Buffer to the MAC address to check * @param mac Buffer to the MAC address to check
* @return 0 if address is not valid, otherwise 1 * @return 0 if address is not valid, otherwise 1
*/ */
static uint8_t is_mac_adr_valid(uint8_t mac[6]) static uint8_t is_mac_adr_valid(uint8_t mac[MAC_ADDR_LEN])
{ {
uint8_t buf[6]; uint8_t buf[MAC_ADDR_LEN];
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
if (!memcmp(buf, mac, sizeof(buf))) if (!memcmp(buf, mac, sizeof(buf)))
@ -52,7 +52,7 @@ static uint8_t is_mac_adr_valid(uint8_t mac[6])
* @param mac buffer where to store the MAC address * @param mac buffer where to store the MAC address
* @return cb_err CB_ERR or CB_SUCCESS * @return cb_err CB_ERR or CB_SUCCESS
*/ */
enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[6]) enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[MAC_ADDR_LEN])
{ {
struct bus *parent = dev->bus; struct bus *parent = dev->bus;
uint8_t buf[16], mapping[16], i = 0, chain_len = 0; uint8_t buf[16], mapping[16], i = 0, chain_len = 0;
@ -92,7 +92,7 @@ enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[6])
if (memcmp(buf, mapping, chain_len + 4)) if (memcmp(buf, mapping, chain_len + 4))
continue; continue;
/* There is a matching mapping available, get MAC address. */ /* There is a matching mapping available, get MAC address. */
if (hwilib_get_field(XMac1 + i, mac, 6) == 6) { if (hwilib_get_field(XMac1 + i, mac, MAC_ADDR_LEN) == MAC_ADDR_LEN) {
if (is_mac_adr_valid(mac)) if (is_mac_adr_valid(mac))
return CB_SUCCESS; return CB_SUCCESS;
} }