1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
4 #include <linux/module.h>
5 #include <linux/netdevice.h>
10 #include "ionic_devlink.h"
12 static int ionic_dl_flash_update(struct devlink *dl,
13 struct devlink_flash_update_params *params,
14 struct netlink_ext_ack *extack)
16 struct ionic *ionic = devlink_priv(dl);
18 return ionic_firmware_update(ionic->lif, params->file_name, extack);
21 static int ionic_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
22 struct netlink_ext_ack *extack)
24 struct ionic *ionic = devlink_priv(dl);
25 struct ionic_dev *idev = &ionic->idev;
29 err = devlink_info_driver_name_put(req, IONIC_DRV_NAME);
33 err = devlink_info_version_running_put(req,
34 DEVLINK_INFO_VERSION_GENERIC_FW,
35 idev->dev_info.fw_version);
39 snprintf(buf, sizeof(buf), "0x%x", idev->dev_info.asic_type);
40 err = devlink_info_version_fixed_put(req,
41 DEVLINK_INFO_VERSION_GENERIC_ASIC_ID,
46 snprintf(buf, sizeof(buf), "0x%x", idev->dev_info.asic_rev);
47 err = devlink_info_version_fixed_put(req,
48 DEVLINK_INFO_VERSION_GENERIC_ASIC_REV,
53 err = devlink_info_serial_number_put(req, idev->dev_info.serial_num);
58 static const struct devlink_ops ionic_dl_ops = {
59 .info_get = ionic_dl_info_get,
60 .flash_update = ionic_dl_flash_update,
63 struct ionic *ionic_devlink_alloc(struct device *dev)
67 dl = devlink_alloc(&ionic_dl_ops, sizeof(struct ionic));
69 return devlink_priv(dl);
72 void ionic_devlink_free(struct ionic *ionic)
74 struct devlink *dl = priv_to_devlink(ionic);
79 int ionic_devlink_register(struct ionic *ionic)
81 struct devlink *dl = priv_to_devlink(ionic);
82 struct devlink_port_attrs attrs = {};
85 err = devlink_register(dl, ionic->dev);
87 dev_warn(ionic->dev, "devlink_register failed: %d\n", err);
91 attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
92 devlink_port_attrs_set(&ionic->dl_port, &attrs);
93 err = devlink_port_register(dl, &ionic->dl_port, 0);
95 dev_err(ionic->dev, "devlink_port_register failed: %d\n", err);
97 devlink_port_type_eth_set(&ionic->dl_port,
103 void ionic_devlink_unregister(struct ionic *ionic)
105 struct devlink *dl = priv_to_devlink(ionic);
107 if (ionic->dl_port.registered)
108 devlink_port_unregister(&ionic->dl_port);
109 devlink_unregister(dl);