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