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 return err; 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 return err; 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 return err; 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 return err; 43 44 err = devlink_info_serial_number_put(req, idev->dev_info.serial_num); 45 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 return err; 78 } 79 80 /* don't register the mgmt_nic as a port */ 81 if (ionic->is_mgmt_nic) 82 return 0; 83 84 devlink_port_attrs_set(&ionic->dl_port, DEVLINK_PORT_FLAVOUR_PHYSICAL, 85 0, false, 0, NULL, 0); 86 err = devlink_port_register(dl, &ionic->dl_port, 0); 87 if (err) 88 dev_err(ionic->dev, "devlink_port_register failed: %d\n", err); 89 else 90 devlink_port_type_eth_set(&ionic->dl_port, 91 ionic->master_lif->netdev); 92 93 return err; 94 } 95 96 void ionic_devlink_unregister(struct ionic *ionic) 97 { 98 struct devlink *dl = priv_to_devlink(ionic); 99 100 if (ionic->dl_port.registered) 101 devlink_port_unregister(&ionic->dl_port); 102 devlink_unregister(dl); 103 } 104