Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/ncsi: add get MAC address command to get Intel i210 MAC address

This patch adds OEM Intel GMA command and response handler for it.

Signed-off-by: Brad Ho <Brad_Ho@phoenix.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Signed-off-by: Ivan Mikhaylov <i.mikhaylov@yadro.com>
Link: https://lore.kernel.org/r/20210830171806.119857-2-i.mikhaylov@yadro.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ivan Mikhaylov and committed by
Jakub Kicinski
205b95fe 5240118f

+75 -1
+3
net/ncsi/internal.h
··· 80 80 #define NCSI_OEM_MFR_BCM_ID 0x113d 81 81 #define NCSI_OEM_MFR_INTEL_ID 0x157 82 82 /* Intel specific OEM command */ 83 + #define NCSI_OEM_INTEL_CMD_GMA 0x06 /* CMD ID for Get MAC */ 83 84 #define NCSI_OEM_INTEL_CMD_KEEP_PHY 0x20 /* CMD ID for Keep PHY up */ 84 85 /* Broadcom specific OEM Command */ 85 86 #define NCSI_OEM_BCM_CMD_GMA 0x01 /* CMD ID for Get MAC */ ··· 90 89 #define NCSI_OEM_MLX_CMD_SMAF 0x01 /* CMD ID for Set MC Affinity */ 91 90 #define NCSI_OEM_MLX_CMD_SMAF_PARAM 0x07 /* Parameter for SMAF */ 92 91 /* OEM Command payload lengths*/ 92 + #define NCSI_OEM_INTEL_CMD_GMA_LEN 5 93 93 #define NCSI_OEM_INTEL_CMD_KEEP_PHY_LEN 7 94 94 #define NCSI_OEM_BCM_CMD_GMA_LEN 12 95 95 #define NCSI_OEM_MLX_CMD_GMA_LEN 8 ··· 101 99 /* Mac address offset in OEM response */ 102 100 #define BCM_MAC_ADDR_OFFSET 28 103 101 #define MLX_MAC_ADDR_OFFSET 8 102 + #define INTEL_MAC_ADDR_OFFSET 1 104 103 105 104 106 105 struct ncsi_channel_version {
+24 -1
net/ncsi/ncsi-manage.c
··· 795 795 return ret; 796 796 } 797 797 798 + static int ncsi_oem_gma_handler_intel(struct ncsi_cmd_arg *nca) 799 + { 800 + unsigned char data[NCSI_OEM_INTEL_CMD_GMA_LEN]; 801 + int ret = 0; 802 + 803 + nca->payload = NCSI_OEM_INTEL_CMD_GMA_LEN; 804 + 805 + memset(data, 0, NCSI_OEM_INTEL_CMD_GMA_LEN); 806 + *(unsigned int *)data = ntohl((__force __be32)NCSI_OEM_MFR_INTEL_ID); 807 + data[4] = NCSI_OEM_INTEL_CMD_GMA; 808 + 809 + nca->data = data; 810 + 811 + ret = ncsi_xmit_cmd(nca); 812 + if (ret) 813 + netdev_err(nca->ndp->ndev.dev, 814 + "NCSI: Failed to transmit cmd 0x%x during configure\n", 815 + nca->type); 816 + 817 + return ret; 818 + } 819 + 798 820 /* OEM Command handlers initialization */ 799 821 static struct ncsi_oem_gma_handler { 800 822 unsigned int mfr_id; 801 823 int (*handler)(struct ncsi_cmd_arg *nca); 802 824 } ncsi_oem_gma_handlers[] = { 803 825 { NCSI_OEM_MFR_BCM_ID, ncsi_oem_gma_handler_bcm }, 804 - { NCSI_OEM_MFR_MLX_ID, ncsi_oem_gma_handler_mlx } 826 + { NCSI_OEM_MFR_MLX_ID, ncsi_oem_gma_handler_mlx }, 827 + { NCSI_OEM_MFR_INTEL_ID, ncsi_oem_gma_handler_intel } 805 828 }; 806 829 807 830 static int ncsi_gma_handler(struct ncsi_cmd_arg *nca, unsigned int mf_id)
+6
net/ncsi/ncsi-pkt.h
··· 178 178 unsigned char data[]; /* Cmd specific Data */ 179 179 }; 180 180 181 + /* Intel Response Data */ 182 + struct ncsi_rsp_oem_intel_pkt { 183 + unsigned char cmd; /* OEM Command ID */ 184 + unsigned char data[]; /* Cmd specific Data */ 185 + }; 186 + 181 187 /* Get Link Status */ 182 188 struct ncsi_rsp_gls_pkt { 183 189 struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+42
net/ncsi/ncsi-rsp.c
··· 699 699 return 0; 700 700 } 701 701 702 + /* Response handler for Intel command Get Mac Address */ 703 + static int ncsi_rsp_handler_oem_intel_gma(struct ncsi_request *nr) 704 + { 705 + struct ncsi_dev_priv *ndp = nr->ndp; 706 + struct net_device *ndev = ndp->ndev.dev; 707 + const struct net_device_ops *ops = ndev->netdev_ops; 708 + struct ncsi_rsp_oem_pkt *rsp; 709 + struct sockaddr saddr; 710 + int ret = 0; 711 + 712 + /* Get the response header */ 713 + rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp); 714 + 715 + saddr.sa_family = ndev->type; 716 + ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 717 + memcpy(saddr.sa_data, &rsp->data[INTEL_MAC_ADDR_OFFSET], ETH_ALEN); 718 + /* Increase mac address by 1 for BMC's address */ 719 + eth_addr_inc((u8 *)saddr.sa_data); 720 + if (!is_valid_ether_addr((const u8 *)saddr.sa_data)) 721 + return -ENXIO; 722 + 723 + /* Set the flag for GMA command which should only be called once */ 724 + ndp->gma_flag = 1; 725 + 726 + ret = ops->ndo_set_mac_address(ndev, &saddr); 727 + if (ret < 0) 728 + netdev_warn(ndev, 729 + "NCSI: 'Writing mac address to device failed\n"); 730 + 731 + return ret; 732 + } 733 + 702 734 /* Response handler for Intel card */ 703 735 static int ncsi_rsp_handler_oem_intel(struct ncsi_request *nr) 704 736 { 737 + struct ncsi_rsp_oem_intel_pkt *intel; 738 + struct ncsi_rsp_oem_pkt *rsp; 739 + 740 + /* Get the response header */ 741 + rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp); 742 + intel = (struct ncsi_rsp_oem_intel_pkt *)(rsp->data); 743 + 744 + if (intel->cmd == NCSI_OEM_INTEL_CMD_GMA) 745 + return ncsi_rsp_handler_oem_intel_gma(nr); 746 + 705 747 return 0; 706 748 } 707 749