From 6871a7de705b6f6a4046f0d19da9bcd689c3bc8e Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 20 Mar 2022 15:00:18 +0000 Subject: [PATCH] [intelxl] Use admin queue to set port MAC address and maximum frame size Remove knowledge of the PRTGL_SA[HL] registers, and instead use the admin queue to set the MAC address and maximum frame size. Signed-off-by: Michael Brown --- src/drivers/net/intelxl.c | 79 +++++++++++++++++++++++++++++++++------ src/drivers/net/intelxl.h | 53 ++++++++++++++++++-------- 2 files changed, 105 insertions(+), 27 deletions(-) diff --git a/src/drivers/net/intelxl.c b/src/drivers/net/intelxl.c index dcc8db56207..c8c527d53ad 100644 --- a/src/drivers/net/intelxl.c +++ b/src/drivers/net/intelxl.c @@ -535,6 +535,40 @@ static int intelxl_admin_mac_read ( struct net_device *netdev ) { return 0; } +/** + * Set MAC address + * + * @v netdev Network device + * @ret rc Return status code + */ +static int intelxl_admin_mac_write ( struct net_device *netdev ) { + struct intelxl_nic *intelxl = netdev->priv; + struct intelxl_admin_descriptor *cmd; + struct intelxl_admin_mac_write_params *write; + union { + uint8_t raw[ETH_ALEN]; + struct { + uint16_t high; + uint32_t low; + } __attribute__ (( packed )); + } mac; + int rc; + + /* Populate descriptor */ + cmd = intelxl_admin_command_descriptor ( intelxl ); + cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_MAC_WRITE ); + write = &cmd->params.mac_write; + memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN ); + write->high = bswap_16 ( mac.high ); + write->low = bswap_32 ( mac.low ); + + /* Issue command */ + if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 ) + return rc; + + return 0; +} + /** * Clear PXE mode * @@ -686,6 +720,31 @@ static int intelxl_admin_promisc ( struct intelxl_nic *intelxl ) { return 0; } +/** + * Set MAC configuration + * + * @v intelxl Intel device + * @ret rc Return status code + */ +static int intelxl_admin_mac_config ( struct intelxl_nic *intelxl ) { + struct intelxl_admin_descriptor *cmd; + struct intelxl_admin_mac_config_params *config; + int rc; + + /* Populate descriptor */ + cmd = intelxl_admin_command_descriptor ( intelxl ); + cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_MAC_CONFIG ); + config = &cmd->params.mac_config; + config->mfs = cpu_to_le16 ( intelxl->mfs ); + config->flags = INTELXL_ADMIN_MAC_CONFIG_FL_CRC; + + /* Issue command */ + if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 ) + return rc; + + return 0; +} + /** * Restart autonegotiation * @@ -1348,24 +1407,20 @@ void intelxl_empty_rx ( struct intelxl_nic *intelxl ) { */ static int intelxl_open ( struct net_device *netdev ) { struct intelxl_nic *intelxl = netdev->priv; - union intelxl_receive_address mac; unsigned int queue; - uint32_t prtgl_sal; - uint32_t prtgl_sah; int rc; /* Calculate maximum frame size */ intelxl->mfs = ( ( ETH_HLEN + netdev->mtu + 4 /* CRC */ + INTELXL_ALIGN - 1 ) & ~( INTELXL_ALIGN - 1 ) ); - /* Program MAC address and maximum frame size */ - memset ( &mac, 0, sizeof ( mac ) ); - memcpy ( mac.raw, netdev->ll_addr, sizeof ( mac.raw ) ); - prtgl_sal = le32_to_cpu ( mac.reg.low ); - prtgl_sah = ( le32_to_cpu ( mac.reg.high ) | - INTELXL_PRTGL_SAH_MFS ( intelxl->mfs ) ); - writel ( prtgl_sal, intelxl->regs + INTELXL_PRTGL_SAL ); - writel ( prtgl_sah, intelxl->regs + INTELXL_PRTGL_SAH ); + /* Set MAC address */ + if ( ( rc = intelxl_admin_mac_write ( netdev ) ) != 0 ) + goto err_mac_write; + + /* Set maximum frame size */ + if ( ( rc = intelxl_admin_mac_config ( intelxl ) ) != 0 ) + goto err_mac_config; /* Associate transmit queue to PF */ writel ( ( INTELXL_QXX_CTL_PFVF_Q_PF | @@ -1408,6 +1463,8 @@ static int intelxl_open ( struct net_device *netdev ) { err_create_tx: intelxl_destroy_ring ( intelxl, &intelxl->rx ); err_create_rx: + err_mac_config: + err_mac_write: return rc; } diff --git a/src/drivers/net/intelxl.h b/src/drivers/net/intelxl.h index 610b3014012..ad15ca99f46 100644 --- a/src/drivers/net/intelxl.h +++ b/src/drivers/net/intelxl.h @@ -171,6 +171,23 @@ struct intelxl_admin_mac_read_buffer { uint8_t wol[ETH_ALEN]; } __attribute__ (( packed )); +/** Admin queue Manage MAC Address Write command */ +#define INTELXL_ADMIN_MAC_WRITE 0x0108 + +/** Admin queue Manage MAC Address Write command parameters */ +struct intelxl_admin_mac_write_params { + /** Reserved */ + uint8_t reserved_a[1]; + /** Write type */ + uint8_t type; + /** MAC address first 16 bits, byte-swapped */ + uint16_t high; + /** MAC address last 32 bits, byte-swapped */ + uint32_t low; + /** Reserved */ + uint8_t reserved_b[8]; +} __attribute__ (( packed )); + /** Admin queue Clear PXE Mode command */ #define INTELXL_ADMIN_CLEAR_PXE 0x0110 @@ -289,6 +306,22 @@ struct intelxl_admin_promisc_params { /** Promiscuous VLAN mode */ #define INTELXL_ADMIN_PROMISC_FL_VLAN 0x0010 +/** Admin queue Set MAC Configuration command */ +#define INTELXL_ADMIN_MAC_CONFIG 0x0603 + +/** Admin queue Set MAC Configuration command parameters */ +struct intelxl_admin_mac_config_params { + /** Maximum frame size */ + uint16_t mfs; + /** Flags */ + uint8_t flags; + /** Reserved */ + uint8_t reserved[13]; +} __attribute__ (( packed )); + +/** Append CRC on transmit */ +#define INTELXL_ADMIN_MAC_CONFIG_FL_CRC 0x04 + /** Admin queue Restart Autonegotiation command */ #define INTELXL_ADMIN_AUTONEG 0x0605 @@ -343,6 +376,8 @@ union intelxl_admin_params { struct intelxl_admin_shutdown_params shutdown; /** Manage MAC Address Read command parameters */ struct intelxl_admin_mac_read_params mac_read; + /** Manage MAC Address Write command parameters */ + struct intelxl_admin_mac_write_params mac_write; /** Clear PXE Mode command parameters */ struct intelxl_admin_clear_pxe_params pxe; /** Get Switch Configuration command parameters */ @@ -351,6 +386,8 @@ union intelxl_admin_params { struct intelxl_admin_vsi_params vsi; /** Set VSI Promiscuous Modes command parameters */ struct intelxl_admin_promisc_params promisc; + /** Set MAC Configuration command parameters */ + struct intelxl_admin_mac_config_params mac_config; /** Restart Autonegotiation command parameters */ struct intelxl_admin_autoneg_params autoneg; /** Get Link Status command parameters */ @@ -854,22 +891,6 @@ intelxl_init_ring ( struct intelxl_ring *ring, unsigned int count, size_t len, #define INTELXL_PFGEN_PORTNUM_PORT_NUM(x) \ ( ( (x) >> 0 ) & 0x3 ) /**< Port number */ -/** Port MAC Address Low Register */ -#define INTELXL_PRTGL_SAL 0x1e2120 - -/** Port MAC Address High Register */ -#define INTELXL_PRTGL_SAH 0x1e2140 -#define INTELXL_PRTGL_SAH_MFS(x) ( (x) << 16 ) /**< Max frame size */ - -/** Receive address */ -union intelxl_receive_address { - struct { - uint32_t low; - uint32_t high; - } __attribute__ (( packed )) reg; - uint8_t raw[ETH_ALEN]; -}; - /** MSI-X interrupt */ struct intelxl_msix { /** PCI capability */