hinic: add firmware update support
Subsystems (3)
PATCH 1/1 hinic: add firmware update support
add support to update firmware by the devlink flashing API
---
V0~V1: remove the implementation from ethtool to devlink
drivers/net/ethernet/huawei/hinic/Makefile | 2 +- drivers/net/ethernet/huawei/hinic/hinic_dev.h | 1 + .../net/ethernet/huawei/hinic/hinic_devlink.c | 325 ++++++++++++++++++ .../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, 558 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
@@ -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 +1 -0
@@ -97,6 +97,7 @@ struct hinic_dev {int lb_test_rx_idx;int lb_pkt_len;u8 *lb_test_rx_buf; + struct devlink *devlink; };#endif
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +325 -0
325 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
@@ -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
@@ -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
@@ -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
@@ -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_dev *devlink_dev;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,15 @@ 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; + } + + devlink_dev =devlink_priv (devlink); + num_qps =hinic_hwdev_num_qps (hwdev);if (num_qps <=0 ) {dev_err (&pdev->dev,"Invalid number of QPS\n" );
@@ -1121,6 +1134,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 +1160,11 @@ static int nic_dev_init(struct pci_dev *pdev) goto err_workq; } +memcpy (devlink_dev, nic_dev,sizeof (*nic_dev)); + 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,10 @@ static int nic_dev_init(struct pci_dev *pdev)cancel_work_sync (&rx_mode_work->work); err_set_mtu: -err_get_mac: err_add_mac: +err_get_mac:pci_set_drvdata (pdev,NULL ); +err_devlink_reg:destroy_workqueue (nic_dev->workq); err_workq:
@@ -1234,6 +1254,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; }
@@ -1321,6 +1342,7 @@ static void hinic_remove(struct pci_dev *pdev) {struct net_device *netdev =pci_get_drvdata (pdev);struct hinic_dev *nic_dev =netdev_priv (netdev); +struct devlink *devlink = nic_dev->devlink;struct hinic_rx_mode_work *rx_mode_work;if (!HINIC_IS_VF (nic_dev->hwdev->hwif)) {
@@ -1342,9 +1364,11 @@ static void hinic_remove(struct pci_dev *pdev)pci_set_drvdata (pdev,NULL ); +hinic_devlink_unregister (devlink); +destroy_workqueue (nic_dev->workq); -hinic_vf_func_free (nic_dev->hwdev); +hinic_devlink_free (devlink);hinic_free_hwdev (nic_dev->hwdev);
drivers/net/ethernet/huawei/hinic/hinic_port.h +25 -0
@@ -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
Jakub Kicinski
maintainerQuoted 5 lines · On Mon, 13 Jul 2020 22:05:22 +0800 Luo bin wrote:
add support to update firmware by the devlink flashing API
Signed-off-by Luo bin <[email protected]>---
V0~V1: remove the implementation from ethtool to devlink
Thanks!
drivers/net/ethernet/huawei/hinic/hinic_devlink.c line 112
Quoted 9 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +9
-0+static int check_image_device_type (struct hinic_dev *nic_dev, +u32 image_device_type) +{ +struct hinic_comm_board_info board_info = {0 }; + +if (image_device_type) { +if (!hinic_get_board_info (nic_dev->hwdev, &board_info)) { +if (image_device_type == board_info.info.board_type) +return true;
Please simplify this, you shouldn't need more than 1 indentation level here.
drivers/net/ethernet/huawei/hinic/hinic_devlink.c line 126
Quoted 13 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +13
-0+dev_err (&nic_dev->hwdev->hwif->pdev->dev,"The device type of upgrade file doesn't match the device type of current firmware, please check the upgrade file\n" ); +dev_err (&nic_dev->hwdev->hwif->pdev->dev,"The image device type: 0x%x, firmware device type: 0x%x\n" , + image_device_type, board_info.info.board_type); + +return false; + } + } + +return false; +} + +static int hinic_flash_fw (struct hinic_dev *nic_dev,const u8 *data, +struct host_image_st *host_image,u32 boot_flag)
You seem to always pass boot_flag = 0, AFAICT, please remove the parameter and related code.
Quoted 6 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +6
-0+{ +u32 section_remain_send_len, send_fragment_len, send_pos, up_total_len; +struct hinic_cmd_update_fw *fw_update_msg =NULL ; +u32 section_type, section_crc, section_version; +u32 i, len, section_len, section_offset; +u16 out_size =sizeof (*fw_update_msg);
drivers/net/ethernet/huawei/hinic/hinic_devlink.c
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +9
-0+int total_len_flag =0 ; +int err; +int hinic_devlink_register (struct devlink *devlink,struct device *dev) +{ +int err; + + err =devlink_register (devlink, dev); + +return err;
No need for temporary variable.
Quoted 64 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +6
-0+} + +void hinic_devlink_unregister (struct devlink *devlink) +{ +devlink_unregister (devlink); +}drivers/net/ethernet/huawei/hinic/hinic_main.c +14
-0@@ -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_dev *devlink_dev;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,15 @@ 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; + } + + devlink_dev =devlink_priv (devlink); + num_qps =hinic_hwdev_num_qps (hwdev);if (num_qps <=0 ) {dev_err (&pdev->dev,"Invalid number of QPS\n" );@@ -1121,6 +1134,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);
drivers/net/ethernet/huawei/hinic/hinic_main.c static int nic_dev_init(struct pci_dev *pdev) · line 1163
Quoted 4 lines
drivers/net/ethernet/huawei/hinic/hinic_main.c +1
-0@@ -1146,6 +1160,11 @@ static int nic_dev_init(struct pci_dev *pdev) goto err_workq; } +memcpy (devlink_dev, nic_dev,sizeof (*nic_dev));
Please create a separate structure for the devlink-level priv. This doesn't look right.
Quoted 7 lines
drivers/net/ethernet/huawei/hinic/hinic_main.c +4
-0+ 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);
Quoted 136 lines · Jakub Kicinski
Quoted 5 lines · On Mon, 13 Jul 2020 22:05:22 +0800 Luo bin wrote:
add support to update firmware by the devlink flashing API
Signed-off-by Luo bin <[email protected]>---
V0~V1: remove the implementation from ethtool to devlinkThanks!
drivers/net/ethernet/huawei/hinic/hinic_devlink.c line 112
Quoted 9 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +9
-0+static int check_image_device_type (struct hinic_dev *nic_dev, +u32 image_device_type) +{ +struct hinic_comm_board_info board_info = {0 }; + +if (image_device_type) { +if (!hinic_get_board_info (nic_dev->hwdev, &board_info)) { +if (image_device_type == board_info.info.board_type) +return true;Please simplify this, you shouldn't need more than 1 indentation level here.
drivers/net/ethernet/huawei/hinic/hinic_devlink.c line 126
Quoted 13 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +13
-0+dev_err (&nic_dev->hwdev->hwif->pdev->dev,"The device type of upgrade file doesn't match the device type of current firmware, please check the upgrade file\n" ); +dev_err (&nic_dev->hwdev->hwif->pdev->dev,"The image device type: 0x%x, firmware device type: 0x%x\n" , + image_device_type, board_info.info.board_type); + +return false; + } + } + +return false; +} + +static int hinic_flash_fw (struct hinic_dev *nic_dev,const u8 *data, +struct host_image_st *host_image,u32 boot_flag)You seem to always pass
boot_flag= 0, AFAICT, please remove the parameter and related code.Quoted 6 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +6
-0+{ +u32 section_remain_send_len, send_fragment_len, send_pos, up_total_len; +struct hinic_cmd_update_fw *fw_update_msg =NULL ; +u32 section_type, section_crc, section_version; +u32 i, len, section_len, section_offset; +u16 out_size =sizeof (*fw_update_msg);drivers/net/ethernet/huawei/hinic/hinic_devlink.c
Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +9
-0+int total_len_flag =0 ; +int err; +int hinic_devlink_register (struct devlink *devlink,struct device *dev) +{ +int err; + + err =devlink_register (devlink, dev); + +return err;No need for temporary variable.
Quoted 64 lines
drivers/net/ethernet/huawei/hinic/hinic_devlink.c new file +6
-0+} + +void hinic_devlink_unregister (struct devlink *devlink) +{ +devlink_unregister (devlink); +}drivers/net/ethernet/huawei/hinic/hinic_main.c +14
-0@@ -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_dev *devlink_dev;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,15 @@ 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; + } + + devlink_dev =devlink_priv (devlink); + num_qps =hinic_hwdev_num_qps (hwdev);if (num_qps <=0 ) {dev_err (&pdev->dev,"Invalid number of QPS\n" );@@ -1121,6 +1134,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);drivers/net/ethernet/huawei/hinic/hinic_main.c static int nic_dev_init(struct pci_dev *pdev) · line 1163
Quoted 4 lines
drivers/net/ethernet/huawei/hinic/hinic_main.c +1
-0@@ -1146,6 +1160,11 @@ static int nic_dev_init(struct pci_dev *pdev) goto err_workq; } +memcpy (devlink_dev, nic_dev,sizeof (*nic_dev));Please create a separate structure for the devlink-level priv. This doesn't look right.
Quoted 6 lines
drivers/net/ethernet/huawei/hinic/hinic_main.c +4
-0+ err =hinic_devlink_register (devlink, &pdev->dev); +if (err) + goto err_devlink_reg; +pci_set_drvdata (pdev, netdev);
Quoted 4 lines
drivers/net/ethernet/huawei/hinic/hinic_main.c static int nic_dev_init(struct pci_dev *pdev) · line 1170
Quoted 1 line
drivers/net/ethernet/huawei/hinic/hinic_main.c +0
-0err =hinic_port_get_mac (nic_dev, netdev->dev_addr);.
Will fix all. Thanks for your review.