Skip to contentSkip to conversation

hinic: add firmware update support

PATCH Applied Luo bin 2 participants 2 messages Jul 15, 2020 – Jul 16, 2020

Subsystems (3)
lore
Share & tools
lore

Luo bin

author
#0 lore raw

PATCH v3 1/1 hinic: add firmware update support

add support to update firmware by the devlink flashing API

---
V2~V3: add error messages through extack
V1~V2: create separate devlink priv data structure and remove boot_flag V0~V1: remove the implementation from ethtool to devlink

 drivers/net/ethernet/huawei/hinic/Makefile    |   2 +-
 drivers/net/ethernet/huawei/hinic/hinic_dev.h |   5 +
 .../net/ethernet/huawei/hinic/hinic_devlink.c | 328 ++++++++++++++++++
 .../net/ethernet/huawei/hinic/hinic_devlink.h | 115 ++++++
 .../net/ethernet/huawei/hinic/hinic_hw_dev.c  |  28 ++
 .../net/ethernet/huawei/hinic/hinic_hw_dev.h  |  34 ++
 .../net/ethernet/huawei/hinic/hinic_hw_mgmt.h |   4 +-
 .../net/ethernet/huawei/hinic/hinic_main.c    |  28 +-
 .../net/ethernet/huawei/hinic/hinic_port.h    |  25 ++
 9 files changed, 565 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_devlink.c
 create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_devlink.h
drivers/net/ethernet/huawei/hinic/Makefile +1 -1
index 32a011ca44c3..67b59d0ba769 100644
@@ -4,4 +4,4 @@ obj-$(CONFIG_HINIC) += hinic.o
 hinic-y := hinic_main.o hinic_tx.o hinic_rx.o hinic_port.o hinic_hw_dev.o \
 	   hinic_hw_io.o hinic_hw_qp.o hinic_hw_cmdq.o hinic_hw_wq.o \
 	   hinic_hw_mgmt.o hinic_hw_api_cmd.o hinic_hw_eqs.o hinic_hw_if.o \
-	   hinic_common.o hinic_ethtool.o hinic_hw_mbox.o hinic_sriov.o
+	   hinic_common.o hinic_ethtool.o hinic_devlink.o hinic_hw_mbox.o hinic_sriov.o
drivers/net/ethernet/huawei/hinic/hinic_dev.h +5 -0
index 9adb755f0820..befd925c03dc 100644
@@ -97,6 +97,11 @@ struct hinic_dev {
 	int				lb_test_rx_idx;
 	int				lb_pkt_len;
 	u8				*lb_test_rx_buf;
+	struct devlink			*devlink;
+};
+
+struct hinic_devlink_priv {
+	struct hinic_hwdev		*hwdev;
 };
 
 #endif
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +328 -0

328 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic/hinic_devlink.h new file +115 -0

115 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c +28 -0
index 47c60d9752e4..9831c14324e6 100644
@@ -897,6 +897,8 @@ void hinic_free_hwdev(struct hinic_hwdev *hwdev)
 
 	set_resources_state(hwdev, HINIC_RES_CLEAN);
 
+	hinic_vf_func_free(hwdev);
+
 	free_pfhwdev(pfhwdev);
 
 	hinic_aeqs_free(&hwdev->aeqs);
@@ -1047,3 +1049,29 @@ void hinic_hwdev_set_msix_state(struct hinic_hwdev *hwdev, u16 msix_index,
 {
 	hinic_set_msix_state(hwdev->hwif, msix_index, flag);
 }
+
+int hinic_get_board_info(struct hinic_hwdev *hwdev,
+			 struct hinic_comm_board_info *board_info)
+{
+	u16 out_size = sizeof(*board_info);
+	struct hinic_pfhwdev *pfhwdev;
+	int err;
+
+	if (!hwdev || !board_info)
+		return -EINVAL;
+
+	pfhwdev = container_of(hwdev, struct hinic_pfhwdev, hwdev);
+
+	err = hinic_msg_to_mgmt(&pfhwdev->pf_to_mgmt, HINIC_MOD_COMM,
+				HINIC_COMM_CMD_GET_BOARD_INFO,
+				board_info, sizeof(*board_info),
+				board_info, &out_size, HINIC_MGMT_MSG_SYNC);
+	if (err || board_info->status || !out_size) {
+		dev_err(&hwdev->hwif->pdev->dev,
+			"Failed to get board info, err: %d, status: 0x%x, out size: 0x%x\n",
+			err, board_info->status, out_size);
+		return -EIO;
+	}
+
+	return 0;
+}
drivers/net/ethernet/huawei/hinic/hinic_hw_dev.h +34 -0
index 958ea1a6a60d..94593a8ad667 100644
@@ -116,6 +116,8 @@ enum hinic_port_cmd {
 
 	HINIC_PORT_CMD_SET_TSO          = 112,
 
+	HINIC_PORT_CMD_UPDATE_FW	= 114,
+
 	HINIC_PORT_CMD_SET_RQ_IQ_MAP	= 115,
 
 	HINIC_PORT_CMD_LINK_STATUS_REPORT = 160,
@@ -307,6 +309,35 @@ struct hinic_msix_config {
 	u8	rsvd1[3];
 };
 
+struct hinic_board_info {
+	u32	board_type;
+	u32	port_num;
+	u32	port_speed;
+	u32	pcie_width;
+	u32	host_num;
+	u32	pf_num;
+	u32	vf_total_num;
+	u32	tile_num;
+	u32	qcm_num;
+	u32	core_num;
+	u32	work_mode;
+	u32	service_mode;
+	u32	pcie_mode;
+	u32	cfg_addr;
+	u32	boot_sel;
+	u32	board_id;
+};
+
+struct hinic_comm_board_info {
+	u8	status;
+	u8	version;
+	u8	rsvd0[6];
+
+	struct hinic_board_info info;
+
+	u32	rsvd1[4];
+};
+
 struct hinic_hwdev {
 	struct hinic_hwif               *hwif;
 	struct msix_entry               *msix_entries;
@@ -407,4 +438,7 @@ int hinic_get_interrupt_cfg(struct hinic_hwdev *hwdev,
 int hinic_set_interrupt_cfg(struct hinic_hwdev *hwdev,
 			    struct hinic_msix_config *interrupt_info);
 
+int hinic_get_board_info(struct hinic_hwdev *hwdev,
+			 struct hinic_comm_board_info *board_info);
+
 #endif
drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.h +3 -1
index e8a55b53c855..21b93b654d6b 100644
@@ -87,7 +87,9 @@ enum hinic_comm_cmd {
 
 	HINIC_COMM_CMD_PAGESIZE_SET	= 0x50,
 
-	HINIC_COMM_CMD_MAX              = 0x51,
+	HINIC_COMM_CMD_GET_BOARD_INFO	= 0x52,
+
+	HINIC_COMM_CMD_MAX,
 };
 
 enum hinic_mgmt_cb_state {
drivers/net/ethernet/huawei/hinic/hinic_main.c +26 -2
index 834a20a0043c..c4c6f9c29f0e 100644
@@ -18,6 +18,7 @@
 #include <linux/semaphore.h>
 #include <linux/workqueue.h>
 #include <net/ip.h>
+#include <net/devlink.h>
 #include <linux/bitops.h>
 #include <linux/bitmap.h>
 #include <linux/delay.h>
@@ -25,6 +26,7 @@
 
 #include "hinic_hw_qp.h"
 #include "hinic_hw_dev.h"
+#include "hinic_devlink.h"
 #include "hinic_port.h"
 #include "hinic_tx.h"
 #include "hinic_rx.h"
@@ -1075,9 +1077,11 @@ static int nic_dev_init(struct pci_dev *pdev)
 	struct hinic_rx_mode_work *rx_mode_work;
 	struct hinic_txq_stats *tx_stats;
 	struct hinic_rxq_stats *rx_stats;
+	struct hinic_devlink_priv *priv;
 	struct hinic_dev *nic_dev;
 	struct net_device *netdev;
 	struct hinic_hwdev *hwdev;
+	struct devlink *devlink;
 	int err, num_qps;
 
 	hwdev = hinic_init_hwdev(pdev);
@@ -1086,6 +1090,16 @@ static int nic_dev_init(struct pci_dev *pdev)
 		return PTR_ERR(hwdev);
 	}
 
+	devlink = hinic_devlink_alloc();
+	if (!devlink) {
+		dev_err(&pdev->dev, "Hinic devlink alloc failed\n");
+		err = -ENOMEM;
+		goto err_devlink_alloc;
+	}
+
+	priv = devlink_priv(devlink);
+	priv->hwdev = hwdev;
+
 	num_qps = hinic_hwdev_num_qps(hwdev);
 	if (num_qps <= 0) {
 		dev_err(&pdev->dev, "Invalid number of QPS\n");
@@ -1121,6 +1135,7 @@ static int nic_dev_init(struct pci_dev *pdev)
 	nic_dev->sriov_info.hwdev = hwdev;
 	nic_dev->sriov_info.pdev = pdev;
 	nic_dev->max_qps = num_qps;
+	nic_dev->devlink = devlink;
 
 	hinic_set_ethtool_ops(netdev);
 
@@ -1146,6 +1161,10 @@ static int nic_dev_init(struct pci_dev *pdev)
 		goto err_workq;
 	}
 
+	err = hinic_devlink_register(devlink, &pdev->dev);
+	if (err)
+		goto err_devlink_reg;
+
 	pci_set_drvdata(pdev, netdev);
 
 	err = hinic_port_get_mac(nic_dev, netdev->dev_addr);
@@ -1223,9 +1242,11 @@ static int nic_dev_init(struct pci_dev *pdev)
 	cancel_work_sync(&rx_mode_work->work);
 
 err_set_mtu:
-err_get_mac:
+	hinic_port_del_mac(nic_dev, netdev->dev_addr, 0);
 err_add_mac:
+err_get_mac:
 	pci_set_drvdata(pdev, NULL);
+err_devlink_reg:
 	destroy_workqueue(nic_dev->workq);
 
 err_workq:
@@ -1234,6 +1255,7 @@ static int nic_dev_init(struct pci_dev *pdev)
 
 err_alloc_etherdev:
 err_num_qps:
+err_devlink_alloc:
 	hinic_free_hwdev(hwdev);
 	return err;
 }
@@ -1342,9 +1364,11 @@ static void hinic_remove(struct pci_dev *pdev)
 
 	pci_set_drvdata(pdev, NULL);
 
+	hinic_devlink_unregister(nic_dev->devlink);
+
 	destroy_workqueue(nic_dev->workq);
 
-	hinic_vf_func_free(nic_dev->hwdev);
+	hinic_devlink_free(nic_dev->devlink);
 
 	hinic_free_hwdev(nic_dev->hwdev);
 
drivers/net/ethernet/huawei/hinic/hinic_port.h +25 -0
index 0e444d2c02bb..14931adaffb8 100644
@@ -703,6 +703,31 @@ struct hinic_cmd_get_std_sfp_info {
 	u8 sfp_info[STD_SFP_INFO_MAX_SIZE];
 };
 
+struct hinic_cmd_update_fw {
+	u8 status;
+	u8 version;
+	u8 rsvd0[6];
+
+	struct {
+		u32 SL:1;
+		u32 SF:1;
+		u32 flag:1;
+		u32 reserved:13;
+		u32 fragment_len:16;
+	} ctl_info;
+
+	struct {
+		u32 FW_section_CRC;
+		u32 FW_section_type;
+	} section_info;
+
+	u32 total_len;
+	u32 setion_total_len;
+	u32 fw_section_version;
+	u32 section_offset;
+	u32 data[384];
+};
+
 int hinic_port_add_mac(struct hinic_dev *nic_dev, const u8 *addr,
 		       u16 vlan_id);
 
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 3 lines · On Wed, 15 Jul 2020 15:30:23 +0800 Luo bin wrote:

add support to update firmware by the devlink flashing API

Applied, thank you.