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_devlink.h" 10 11 static int ionic_dl_info_get(struct devlink *dl, struct devlink_info_req *req, 12 struct netlink_ext_ack *extack) 13 { 14 struct ionic *ionic = devlink_priv(dl); 15 struct ionic_dev *idev = &ionic->idev; 16 char buf[16]; 17 int err = 0; 18 19 err = devlink_info_driver_name_put(req, IONIC_DRV_NAME); 20 if (err) 21 goto info_out; 22 23 err = devlink_info_version_running_put(req, 24 DEVLINK_INFO_VERSION_GENERIC_FW, 25 idev->dev_info.fw_version); 26 if (err) 27 goto info_out; 28 29 snprintf(buf, sizeof(buf), "0x%x", idev->dev_info.asic_type); 30 err = devlink_info_version_fixed_put(req, 31 DEVLINK_INFO_VERSION_GENERIC_ASIC_ID, 32 buf); 33 if (err) 34 goto info_out; 35 36 snprintf(buf, sizeof(buf), "0x%x", idev->dev_info.asic_rev); 37 err = devlink_info_version_fixed_put(req, 38 DEVLINK_INFO_VERSION_GENERIC_ASIC_REV, 39 buf); 40 if (err) 41 goto info_out; 42 43 err = devlink_info_serial_number_put(req, idev->dev_info.serial_num); 44 45 info_out: 46 return err; 47 } 48 49 static const struct devlink_ops ionic_dl_ops = { 50 .info_get = ionic_dl_info_get, 51 }; 52 53 struct ionic *ionic_devlink_alloc(struct device *dev) 54 { 55 struct devlink *dl; 56 57 dl = devlink_alloc(&ionic_dl_ops, sizeof(struct ionic)); 58 59 return devlink_priv(dl); 60 } 61 62 void ionic_devlink_free(struct ionic *ionic) 63 { 64 struct devlink *dl = priv_to_devlink(ionic); 65 66 devlink_free(dl); 67 } 68 69 int ionic_devlink_register(struct ionic *ionic) 70 { 71 struct devlink *dl = priv_to_devlink(ionic); 72 int err; 73 74 err = devlink_register(dl, ionic->dev); 75 if (err) 76 dev_warn(ionic->dev, "devlink_register failed: %d\n", err); 77 78 return err; 79 } 80 81 void ionic_devlink_unregister(struct ionic *ionic) 82 { 83 struct devlink *dl = priv_to_devlink(ionic); 84 85 devlink_unregister(dl); 86 } 87