1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
4 #include <linux/unaligned.h>
6 #include <linux/types.h>
7 #include <net/devlink.h>
11 #define FBNIC_SN_STR_LEN 24
13 static int fbnic_version_running_put(struct devlink_info_req
*req
,
14 struct fbnic_fw_ver
*fw_ver
,
17 char running_ver
[FBNIC_FW_VER_MAX_SIZE
];
20 fbnic_mk_fw_ver_str(fw_ver
->version
, running_ver
);
21 err
= devlink_info_version_running_put(req
, ver_name
, running_ver
);
25 if (strlen(fw_ver
->commit
) > 0) {
26 char commit_name
[FBNIC_SN_STR_LEN
];
28 snprintf(commit_name
, FBNIC_SN_STR_LEN
, "%s.commit", ver_name
);
29 err
= devlink_info_version_running_put(req
, commit_name
,
38 static int fbnic_version_stored_put(struct devlink_info_req
*req
,
39 struct fbnic_fw_ver
*fw_ver
,
42 char stored_ver
[FBNIC_FW_VER_MAX_SIZE
];
45 fbnic_mk_fw_ver_str(fw_ver
->version
, stored_ver
);
46 err
= devlink_info_version_stored_put(req
, ver_name
, stored_ver
);
50 if (strlen(fw_ver
->commit
) > 0) {
51 char commit_name
[FBNIC_SN_STR_LEN
];
53 snprintf(commit_name
, FBNIC_SN_STR_LEN
, "%s.commit", ver_name
);
54 err
= devlink_info_version_stored_put(req
, commit_name
,
63 static int fbnic_devlink_info_get(struct devlink
*devlink
,
64 struct devlink_info_req
*req
,
65 struct netlink_ext_ack
*extack
)
67 struct fbnic_dev
*fbd
= devlink_priv(devlink
);
70 err
= fbnic_version_running_put(req
, &fbd
->fw_cap
.running
.mgmt
,
71 DEVLINK_INFO_VERSION_GENERIC_FW
);
75 err
= fbnic_version_running_put(req
, &fbd
->fw_cap
.running
.bootloader
,
76 DEVLINK_INFO_VERSION_GENERIC_FW_BOOTLOADER
);
80 err
= fbnic_version_stored_put(req
, &fbd
->fw_cap
.stored
.mgmt
,
81 DEVLINK_INFO_VERSION_GENERIC_FW
);
85 err
= fbnic_version_stored_put(req
, &fbd
->fw_cap
.stored
.bootloader
,
86 DEVLINK_INFO_VERSION_GENERIC_FW_BOOTLOADER
);
90 err
= fbnic_version_stored_put(req
, &fbd
->fw_cap
.stored
.undi
,
91 DEVLINK_INFO_VERSION_GENERIC_FW_UNDI
);
96 unsigned char serial
[FBNIC_SN_STR_LEN
];
99 put_unaligned_be64(fbd
->dsn
, dsn
);
100 err
= snprintf(serial
, FBNIC_SN_STR_LEN
, "%8phD", dsn
);
104 err
= devlink_info_serial_number_put(req
, serial
);
112 static const struct devlink_ops fbnic_devlink_ops
= {
113 .info_get
= fbnic_devlink_info_get
,
116 void fbnic_devlink_free(struct fbnic_dev
*fbd
)
118 struct devlink
*devlink
= priv_to_devlink(fbd
);
120 devlink_free(devlink
);
123 struct fbnic_dev
*fbnic_devlink_alloc(struct pci_dev
*pdev
)
125 void __iomem
* const *iomap_table
;
126 struct devlink
*devlink
;
127 struct fbnic_dev
*fbd
;
129 devlink
= devlink_alloc(&fbnic_devlink_ops
, sizeof(struct fbnic_dev
),
134 fbd
= devlink_priv(devlink
);
135 pci_set_drvdata(pdev
, fbd
);
136 fbd
->dev
= &pdev
->dev
;
138 iomap_table
= pcim_iomap_table(pdev
);
139 fbd
->uc_addr0
= iomap_table
[0];
140 fbd
->uc_addr4
= iomap_table
[4];
142 fbd
->dsn
= pci_get_dsn(pdev
);
143 fbd
->mps
= pcie_get_mps(pdev
);
144 fbd
->readrq
= pcie_get_readrq(pdev
);
146 fbd
->mac_addr_boundary
= FBNIC_RPC_TCAM_MACDA_DEFAULT_BOUNDARY
;
151 void fbnic_devlink_register(struct fbnic_dev
*fbd
)
153 struct devlink
*devlink
= priv_to_devlink(fbd
);
155 devlink_register(devlink
);
158 void fbnic_devlink_unregister(struct fbnic_dev
*fbd
)
160 struct devlink
*devlink
= priv_to_devlink(fbd
);
162 devlink_unregister(devlink
);