xref: /linux/drivers/net/ethernet/pensando/ionic/ionic_devlink.c (revision 919d13a7e455c2e7676042d7a5f94c164e859d8a)
1df69ba43SShannon Nelson // SPDX-License-Identifier: GPL-2.0
2df69ba43SShannon Nelson /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
3df69ba43SShannon Nelson 
4df69ba43SShannon Nelson #include <linux/module.h>
5df69ba43SShannon Nelson #include <linux/netdevice.h>
6df69ba43SShannon Nelson 
7df69ba43SShannon Nelson #include "ionic.h"
8df69ba43SShannon Nelson #include "ionic_bus.h"
9beead698SShannon Nelson #include "ionic_lif.h"
10df69ba43SShannon Nelson #include "ionic_devlink.h"
11df69ba43SShannon Nelson 
1230b5191aSShannon Nelson static int ionic_dl_flash_update(struct devlink *dl,
13bc75c054SJacob Keller 				 struct devlink_flash_update_params *params,
1430b5191aSShannon Nelson 				 struct netlink_ext_ack *extack)
1530b5191aSShannon Nelson {
1630b5191aSShannon Nelson 	struct ionic *ionic = devlink_priv(dl);
1730b5191aSShannon Nelson 
18b44cfd4fSJacob Keller 	return ionic_firmware_update(ionic->lif, params->fw, extack);
1930b5191aSShannon Nelson }
2030b5191aSShannon Nelson 
21df69ba43SShannon Nelson static int ionic_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
22df69ba43SShannon Nelson 			     struct netlink_ext_ack *extack)
23df69ba43SShannon Nelson {
24fbfb8031SShannon Nelson 	struct ionic *ionic = devlink_priv(dl);
25fbfb8031SShannon Nelson 	struct ionic_dev *idev = &ionic->idev;
26fbfb8031SShannon Nelson 	char buf[16];
27fbfb8031SShannon Nelson 	int err = 0;
28fbfb8031SShannon Nelson 
29fbfb8031SShannon Nelson 	err = devlink_info_driver_name_put(req, IONIC_DRV_NAME);
30fbfb8031SShannon Nelson 	if (err)
31da0729e8SShannon Nelson 		return err;
32fbfb8031SShannon Nelson 
33fbfb8031SShannon Nelson 	err = devlink_info_version_running_put(req,
34fbfb8031SShannon Nelson 					       DEVLINK_INFO_VERSION_GENERIC_FW,
35fbfb8031SShannon Nelson 					       idev->dev_info.fw_version);
36fbfb8031SShannon Nelson 	if (err)
37da0729e8SShannon Nelson 		return err;
38fbfb8031SShannon Nelson 
39fbfb8031SShannon Nelson 	snprintf(buf, sizeof(buf), "0x%x", idev->dev_info.asic_type);
40fbfb8031SShannon Nelson 	err = devlink_info_version_fixed_put(req,
41fbfb8031SShannon Nelson 					     DEVLINK_INFO_VERSION_GENERIC_ASIC_ID,
42fbfb8031SShannon Nelson 					     buf);
43fbfb8031SShannon Nelson 	if (err)
44da0729e8SShannon Nelson 		return err;
45fbfb8031SShannon Nelson 
46fbfb8031SShannon Nelson 	snprintf(buf, sizeof(buf), "0x%x", idev->dev_info.asic_rev);
47fbfb8031SShannon Nelson 	err = devlink_info_version_fixed_put(req,
48fbfb8031SShannon Nelson 					     DEVLINK_INFO_VERSION_GENERIC_ASIC_REV,
49fbfb8031SShannon Nelson 					     buf);
50fbfb8031SShannon Nelson 	if (err)
51da0729e8SShannon Nelson 		return err;
52fbfb8031SShannon Nelson 
53fbfb8031SShannon Nelson 	err = devlink_info_serial_number_put(req, idev->dev_info.serial_num);
54fbfb8031SShannon Nelson 
55fbfb8031SShannon Nelson 	return err;
56df69ba43SShannon Nelson }
57df69ba43SShannon Nelson 
58df69ba43SShannon Nelson static const struct devlink_ops ionic_dl_ops = {
59df69ba43SShannon Nelson 	.info_get	= ionic_dl_info_get,
6030b5191aSShannon Nelson 	.flash_update	= ionic_dl_flash_update,
61df69ba43SShannon Nelson };
62df69ba43SShannon Nelson 
63df69ba43SShannon Nelson struct ionic *ionic_devlink_alloc(struct device *dev)
64df69ba43SShannon Nelson {
65df69ba43SShannon Nelson 	struct devlink *dl;
66df69ba43SShannon Nelson 
67*919d13a7SLeon Romanovsky 	dl = devlink_alloc(&ionic_dl_ops, sizeof(struct ionic), dev);
68df69ba43SShannon Nelson 
69df69ba43SShannon Nelson 	return devlink_priv(dl);
70df69ba43SShannon Nelson }
71df69ba43SShannon Nelson 
72df69ba43SShannon Nelson void ionic_devlink_free(struct ionic *ionic)
73df69ba43SShannon Nelson {
74df69ba43SShannon Nelson 	struct devlink *dl = priv_to_devlink(ionic);
75df69ba43SShannon Nelson 
76df69ba43SShannon Nelson 	devlink_free(dl);
77df69ba43SShannon Nelson }
78fbfb8031SShannon Nelson 
79fbfb8031SShannon Nelson int ionic_devlink_register(struct ionic *ionic)
80fbfb8031SShannon Nelson {
81fbfb8031SShannon Nelson 	struct devlink *dl = priv_to_devlink(ionic);
8271ad8d55SDanielle Ratson 	struct devlink_port_attrs attrs = {};
83fbfb8031SShannon Nelson 	int err;
84fbfb8031SShannon Nelson 
85*919d13a7SLeon Romanovsky 	err = devlink_register(dl);
86beead698SShannon Nelson 	if (err) {
87fbfb8031SShannon Nelson 		dev_warn(ionic->dev, "devlink_register failed: %d\n", err);
88beead698SShannon Nelson 		return err;
89beead698SShannon Nelson 	}
90beead698SShannon Nelson 
9171ad8d55SDanielle Ratson 	attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
9271ad8d55SDanielle Ratson 	devlink_port_attrs_set(&ionic->dl_port, &attrs);
93beead698SShannon Nelson 	err = devlink_port_register(dl, &ionic->dl_port, 0);
94c2255ff4SLeon Romanovsky 	if (err) {
95beead698SShannon Nelson 		dev_err(ionic->dev, "devlink_port_register failed: %d\n", err);
96c2255ff4SLeon Romanovsky 		devlink_unregister(dl);
97fbfb8031SShannon Nelson 		return err;
98fbfb8031SShannon Nelson 	}
99fbfb8031SShannon Nelson 
100c2255ff4SLeon Romanovsky 	devlink_port_type_eth_set(&ionic->dl_port, ionic->lif->netdev);
101c2255ff4SLeon Romanovsky 	return 0;
102c2255ff4SLeon Romanovsky }
103c2255ff4SLeon Romanovsky 
104fbfb8031SShannon Nelson void ionic_devlink_unregister(struct ionic *ionic)
105fbfb8031SShannon Nelson {
106fbfb8031SShannon Nelson 	struct devlink *dl = priv_to_devlink(ionic);
107fbfb8031SShannon Nelson 
108beead698SShannon Nelson 	devlink_port_unregister(&ionic->dl_port);
109fbfb8031SShannon Nelson 	devlink_unregister(dl);
110fbfb8031SShannon Nelson }
111