1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
3
4 #include <linux/module.h>
5 #include <linux/netdevice.h>
6
7 #include "ionic.h"
8 #include "ionic_bus.h"
9 #include "ionic_lif.h"
10 #include "ionic_devlink.h"
11
ionic_dl_flash_update(struct devlink * dl,struct devlink_flash_update_params * params,struct netlink_ext_ack * extack)12 static int ionic_dl_flash_update(struct devlink *dl,
13 struct devlink_flash_update_params *params,
14 struct netlink_ext_ack *extack)
15 {
16 struct ionic *ionic = devlink_priv(dl);
17
18 return ionic_firmware_update(ionic->lif, params->fw, extack);
19 }
20
ionic_dl_info_get(struct devlink * dl,struct devlink_info_req * req,struct netlink_ext_ack * extack)21 static int ionic_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
22 struct netlink_ext_ack *extack)
23 {
24 struct ionic *ionic = devlink_priv(dl);
25 struct ionic_dev *idev = &ionic->idev;
26 char buf[16];
27 int err = 0;
28
29 err = devlink_info_version_running_put(req,
30 DEVLINK_INFO_VERSION_GENERIC_FW,
31 idev->dev_info.fw_version);
32 if (err)
33 return err;
34
35 snprintf(buf, sizeof(buf), "0x%x", idev->dev_info.asic_type);
36 err = devlink_info_version_fixed_put(req,
37 DEVLINK_INFO_VERSION_GENERIC_ASIC_ID,
38 buf);
39 if (err)
40 return err;
41
42 snprintf(buf, sizeof(buf), "0x%x", idev->dev_info.asic_rev);
43 err = devlink_info_version_fixed_put(req,
44 DEVLINK_INFO_VERSION_GENERIC_ASIC_REV,
45 buf);
46 if (err)
47 return err;
48
49 err = devlink_info_serial_number_put(req, idev->dev_info.serial_num);
50
51 return err;
52 }
53
54 static const struct devlink_ops ionic_dl_ops = {
55 .info_get = ionic_dl_info_get,
56 .flash_update = ionic_dl_flash_update,
57 };
58
ionic_devlink_alloc(struct device * dev)59 struct ionic *ionic_devlink_alloc(struct device *dev)
60 {
61 struct devlink *dl;
62
63 dl = devlink_alloc(&ionic_dl_ops, sizeof(struct ionic), dev);
64 if (!dl)
65 return NULL;
66
67 return devlink_priv(dl);
68 }
69
ionic_devlink_free(struct ionic * ionic)70 void ionic_devlink_free(struct ionic *ionic)
71 {
72 struct devlink *dl = priv_to_devlink(ionic);
73
74 devlink_free(dl);
75 }
76
ionic_devlink_register(struct ionic * ionic)77 int ionic_devlink_register(struct ionic *ionic)
78 {
79 struct devlink *dl = priv_to_devlink(ionic);
80 struct devlink_port_attrs attrs = {};
81 int err;
82
83 attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
84 devlink_port_attrs_set(&ionic->dl_port, &attrs);
85 err = devlink_port_register(dl, &ionic->dl_port, 0);
86 if (err) {
87 dev_err(ionic->dev, "devlink_port_register failed: %d\n", err);
88 return err;
89 }
90
91 SET_NETDEV_DEVLINK_PORT(ionic->lif->netdev, &ionic->dl_port);
92 devlink_register(dl);
93 return 0;
94 }
95
ionic_devlink_unregister(struct ionic * ionic)96 void ionic_devlink_unregister(struct ionic *ionic)
97 {
98 struct devlink *dl = priv_to_devlink(ionic);
99
100 devlink_unregister(dl);
101 devlink_port_unregister(&ionic->dl_port);
102 }
103