1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
|
// SPDX-License-Identifier: GPL-2.0-only
/****************************************************************************
* Driver for AMD network controllers and boards
* Copyright (C) 2023, Advanced Micro Devices, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, incorporated herein by reference.
*/
#include "net_driver.h"
#include "ef100_nic.h"
#include "efx_devlink.h"
#include <linux/rtc.h>
#include "mcdi.h"
#include "mcdi_functions.h"
#include "mcdi_pcol.h"
#ifdef CONFIG_SFC_SRIOV
#include "mae.h"
#include "ef100_rep.h"
#endif
#include "efx_reflash.h"
struct efx_devlink {
struct efx_nic *efx;
};
#ifdef CONFIG_SFC_SRIOV
static int efx_devlink_port_addr_get(struct devlink_port *port, u8 *hw_addr,
int *hw_addr_len,
struct netlink_ext_ack *extack)
{
struct efx_devlink *devlink = devlink_priv(port->devlink);
struct mae_mport_desc *mport_desc;
efx_qword_t pciefn;
u32 client_id;
int rc = 0;
mport_desc = container_of(port, struct mae_mport_desc, dl_port);
if (!ef100_mport_on_local_intf(devlink->efx, mport_desc)) {
rc = -EINVAL;
NL_SET_ERR_MSG_FMT(extack,
"Port not on local interface (mport: %u)",
mport_desc->mport_id);
goto out;
}
if (ef100_mport_is_vf(mport_desc))
EFX_POPULATE_QWORD_3(pciefn,
PCIE_FUNCTION_PF, PCIE_FUNCTION_PF_NULL,
PCIE_FUNCTION_VF, mport_desc->vf_idx,
PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
else
EFX_POPULATE_QWORD_3(pciefn,
PCIE_FUNCTION_PF, mport_desc->pf_idx,
PCIE_FUNCTION_VF, PCIE_FUNCTION_VF_NULL,
PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
rc = efx_ef100_lookup_client_id(devlink->efx, pciefn, &client_id);
if (rc) {
NL_SET_ERR_MSG_FMT(extack,
"No internal client_ID for port (mport: %u)",
mport_desc->mport_id);
goto out;
}
rc = ef100_get_mac_address(devlink->efx, hw_addr, client_id, true);
if (rc != 0)
NL_SET_ERR_MSG_FMT(extack,
"No available MAC for port (mport: %u)",
mport_desc->mport_id);
out:
*hw_addr_len = ETH_ALEN;
return rc;
}
static int efx_devlink_port_addr_set(struct devlink_port *port,
const u8 *hw_addr, int hw_addr_len,
struct netlink_ext_ack *extack)
{
MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_CLIENT_MAC_ADDRESSES_IN_LEN(1));
struct efx_devlink *devlink = devlink_priv(port->devlink);
struct mae_mport_desc *mport_desc;
efx_qword_t pciefn;
u32 client_id;
int rc;
mport_desc = container_of(port, struct mae_mport_desc, dl_port);
if (!ef100_mport_is_vf(mport_desc)) {
NL_SET_ERR_MSG_FMT(extack,
"port mac change not allowed (mport: %u)",
mport_desc->mport_id);
return -EPERM;
}
EFX_POPULATE_QWORD_3(pciefn,
PCIE_FUNCTION_PF, PCIE_FUNCTION_PF_NULL,
PCIE_FUNCTION_VF, mport_desc->vf_idx,
PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
rc = efx_ef100_lookup_client_id(devlink->efx, pciefn, &client_id);
if (rc) {
NL_SET_ERR_MSG_FMT(extack,
"No internal client_ID for port (mport: %u)",
mport_desc->mport_id);
return rc;
}
MCDI_SET_DWORD(inbuf, SET_CLIENT_MAC_ADDRESSES_IN_CLIENT_HANDLE,
client_id);
ether_addr_copy(MCDI_PTR(inbuf, SET_CLIENT_MAC_ADDRESSES_IN_MAC_ADDRS),
hw_addr);
rc = efx_mcdi_rpc(devlink->efx, MC_CMD_SET_CLIENT_MAC_ADDRESSES, inbuf,
sizeof(inbuf), NULL, 0, NULL);
if (rc)
NL_SET_ERR_MSG_FMT(extack,
"sfc MC_CMD_SET_CLIENT_MAC_ADDRESSES mcdi error (mport: %u)",
mport_desc->mport_id);
return rc;
}
static const struct devlink_port_ops sfc_devlink_port_ops = {
.port_fn_hw_addr_get = efx_devlink_port_addr_get,
.port_fn_hw_addr_set = efx_devlink_port_addr_set,
};
static void efx_devlink_del_port(struct devlink_port *dl_port)
{
if (!dl_port)
return;
devl_port_unregister(dl_port);
}
static int efx_devlink_add_port(struct efx_nic *efx,
struct mae_mport_desc *mport)
{
bool external = false;
if (!ef100_mport_on_local_intf(efx, mport))
external = true;
switch (mport->mport_type) {
case MAE_MPORT_DESC_MPORT_TYPE_VNIC:
if (mport->vf_idx != MAE_MPORT_DESC_VF_IDX_NULL)
devlink_port_attrs_pci_vf_set(&mport->dl_port, 0, mport->pf_idx,
mport->vf_idx,
external);
else
devlink_port_attrs_pci_pf_set(&mport->dl_port, 0, mport->pf_idx,
external);
break;
default:
/* MAE_MPORT_DESC_MPORT_ALIAS and UNDEFINED */
return 0;
}
mport->dl_port.index = mport->mport_id;
return devl_port_register_with_ops(efx->devlink, &mport->dl_port,
mport->mport_id,
&sfc_devlink_port_ops);
}
#endif
static int efx_devlink_info_nvram_partition(struct efx_nic *efx,
struct devlink_info_req *req,
unsigned int partition_type,
const char *version_name)
{
char buf[EFX_MAX_VERSION_INFO_LEN];
u16 version[4];
int rc;
rc = efx_mcdi_nvram_metadata(efx, partition_type, NULL, version, NULL,
0);
/* If the partition does not exist, that is not an error. */
if (rc == -ENOENT)
return 0;
if (rc) {
netif_err(efx, drv, efx->net_dev, "mcdi nvram %s: failed (rc=%d)\n",
version_name, rc);
return rc;
}
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", version[0],
version[1], version[2], version[3]);
devlink_info_version_stored_put(req, version_name, buf);
return 0;
}
static int efx_devlink_info_stored_versions(struct efx_nic *efx,
struct devlink_info_req *req)
{
int err;
/* We do not care here about the specific error but just if an error
* happened. The specific error will be reported inside the call
* through system messages, and if any error happened in any call
* below, we report it through extack.
*/
err = efx_devlink_info_nvram_partition(efx, req,
NVRAM_PARTITION_TYPE_BUNDLE,
DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID);
err |= efx_devlink_info_nvram_partition(efx, req,
NVRAM_PARTITION_TYPE_MC_FIRMWARE,
DEVLINK_INFO_VERSION_GENERIC_FW_MGMT);
err |= efx_devlink_info_nvram_partition(efx, req,
NVRAM_PARTITION_TYPE_SUC_FIRMWARE,
EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC);
err |= efx_devlink_info_nvram_partition(efx, req,
NVRAM_PARTITION_TYPE_EXPANSION_ROM,
EFX_DEVLINK_INFO_VERSION_FW_EXPROM);
err |= efx_devlink_info_nvram_partition(efx, req,
NVRAM_PARTITION_TYPE_EXPANSION_UEFI,
EFX_DEVLINK_INFO_VERSION_FW_UEFI);
return err;
}
#define EFX_VER_FLAG(_f) \
(MC_CMD_GET_VERSION_V5_OUT_ ## _f ## _PRESENT_LBN)
static void efx_devlink_info_running_v2(struct efx_nic *efx,
struct devlink_info_req *req,
unsigned int flags, efx_dword_t *outbuf)
{
char buf[EFX_MAX_VERSION_INFO_LEN];
union {
const __le32 *dwords;
const __le16 *words;
const char *str;
} ver;
struct rtc_time build_date;
unsigned int build_id;
size_t offset;
__maybe_unused u64 tstamp;
if (flags & BIT(EFX_VER_FLAG(BOARD_EXT_INFO))) {
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%s",
MCDI_PTR(outbuf, GET_VERSION_V2_OUT_BOARD_NAME));
devlink_info_version_fixed_put(req,
DEVLINK_INFO_VERSION_GENERIC_BOARD_ID,
buf);
/* Favour full board version if present (in V5 or later) */
if (~flags & BIT(EFX_VER_FLAG(BOARD_VERSION))) {
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u",
MCDI_DWORD(outbuf,
GET_VERSION_V2_OUT_BOARD_REVISION));
devlink_info_version_fixed_put(req,
DEVLINK_INFO_VERSION_GENERIC_BOARD_REV,
buf);
}
ver.str = MCDI_PTR(outbuf, GET_VERSION_V2_OUT_BOARD_SERIAL);
if (ver.str[0])
devlink_info_board_serial_number_put(req, ver.str);
}
if (flags & BIT(EFX_VER_FLAG(FPGA_EXT_INFO))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V2_OUT_FPGA_VERSION);
offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u_%c%u",
le32_to_cpu(ver.dwords[0]),
'A' + le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]));
ver.str = MCDI_PTR(outbuf, GET_VERSION_V2_OUT_FPGA_EXTRA);
if (ver.str[0])
snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
" (%s)", ver.str);
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_FPGA_REV,
buf);
}
if (flags & BIT(EFX_VER_FLAG(CMC_EXT_INFO))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V2_OUT_CMCFW_VERSION);
offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le32_to_cpu(ver.dwords[0]),
le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]),
le32_to_cpu(ver.dwords[3]));
#ifdef CONFIG_RTC_LIB
tstamp = MCDI_QWORD(outbuf,
GET_VERSION_V2_OUT_CMCFW_BUILD_DATE);
if (tstamp) {
rtc_time64_to_tm(tstamp, &build_date);
snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
" (%ptRd)", &build_date);
}
#endif
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_FW_MGMT_CMC,
buf);
}
ver.words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_V2_OUT_VERSION);
offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le16_to_cpu(ver.words[0]), le16_to_cpu(ver.words[1]),
le16_to_cpu(ver.words[2]), le16_to_cpu(ver.words[3]));
if (flags & BIT(EFX_VER_FLAG(MCFW_EXT_INFO))) {
build_id = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_MCFW_BUILD_ID);
snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
" (%x) %s", build_id,
MCDI_PTR(outbuf, GET_VERSION_V2_OUT_MCFW_BUILD_NAME));
}
devlink_info_version_running_put(req,
DEVLINK_INFO_VERSION_GENERIC_FW_MGMT,
buf);
if (flags & BIT(EFX_VER_FLAG(SUCFW_EXT_INFO))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V2_OUT_SUCFW_VERSION);
#ifdef CONFIG_RTC_LIB
tstamp = MCDI_QWORD(outbuf,
GET_VERSION_V2_OUT_SUCFW_BUILD_DATE);
rtc_time64_to_tm(tstamp, &build_date);
#else
memset(&build_date, 0, sizeof(build_date));
#endif
build_id = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_SUCFW_CHIP_ID);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN,
"%u.%u.%u.%u type %x (%ptRd)",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]), le32_to_cpu(ver.dwords[3]),
build_id, &build_date);
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC,
buf);
}
}
static void efx_devlink_info_running_v3(struct efx_nic *efx,
struct devlink_info_req *req,
unsigned int flags, efx_dword_t *outbuf)
{
char buf[EFX_MAX_VERSION_INFO_LEN];
union {
const __le32 *dwords;
const __le16 *words;
const char *str;
} ver;
if (flags & BIT(EFX_VER_FLAG(DATAPATH_HW_VERSION))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V3_OUT_DATAPATH_HW_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]));
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_DATAPATH_HW,
buf);
}
if (flags & BIT(EFX_VER_FLAG(DATAPATH_FW_VERSION))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V3_OUT_DATAPATH_FW_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]));
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_DATAPATH_FW,
buf);
}
}
static void efx_devlink_info_running_v4(struct efx_nic *efx,
struct devlink_info_req *req,
unsigned int flags, efx_dword_t *outbuf)
{
char buf[EFX_MAX_VERSION_INFO_LEN];
union {
const __le32 *dwords;
const __le16 *words;
const char *str;
} ver;
if (flags & BIT(EFX_VER_FLAG(SOC_BOOT_VERSION))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V4_OUT_SOC_BOOT_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]),
le32_to_cpu(ver.dwords[3]));
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_SOC_BOOT,
buf);
}
if (flags & BIT(EFX_VER_FLAG(SOC_UBOOT_VERSION))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V4_OUT_SOC_UBOOT_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]),
le32_to_cpu(ver.dwords[3]));
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_SOC_UBOOT,
buf);
}
if (flags & BIT(EFX_VER_FLAG(SOC_MAIN_ROOTFS_VERSION))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V4_OUT_SOC_MAIN_ROOTFS_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]),
le32_to_cpu(ver.dwords[3]));
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_SOC_MAIN,
buf);
}
if (flags & BIT(EFX_VER_FLAG(SOC_RECOVERY_BUILDROOT_VERSION))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V4_OUT_SOC_RECOVERY_BUILDROOT_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]),
le32_to_cpu(ver.dwords[3]));
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_SOC_RECOVERY,
buf);
}
if (flags & BIT(EFX_VER_FLAG(SUCFW_VERSION)) &&
~flags & BIT(EFX_VER_FLAG(SUCFW_EXT_INFO))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V4_OUT_SUCFW_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]),
le32_to_cpu(ver.dwords[3]));
devlink_info_version_running_put(req,
EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC,
buf);
}
}
static void efx_devlink_info_running_v5(struct efx_nic *efx,
struct devlink_info_req *req,
unsigned int flags, efx_dword_t *outbuf)
{
char buf[EFX_MAX_VERSION_INFO_LEN];
union {
const __le32 *dwords;
const __le16 *words;
const char *str;
} ver;
if (flags & BIT(EFX_VER_FLAG(BOARD_VERSION))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V5_OUT_BOARD_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]),
le32_to_cpu(ver.dwords[3]));
devlink_info_version_running_put(req,
DEVLINK_INFO_VERSION_GENERIC_BOARD_REV,
buf);
}
if (flags & BIT(EFX_VER_FLAG(BUNDLE_VERSION))) {
ver.dwords = (__le32 *)MCDI_PTR(outbuf,
GET_VERSION_V5_OUT_BUNDLE_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
le32_to_cpu(ver.dwords[2]),
le32_to_cpu(ver.dwords[3]));
devlink_info_version_running_put(req,
DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID,
buf);
}
}
static int efx_devlink_info_running_versions(struct efx_nic *efx,
struct devlink_info_req *req)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_VERSION_V5_OUT_LEN);
MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_VERSION_EXT_IN_LEN);
char buf[EFX_MAX_VERSION_INFO_LEN];
union {
const __le32 *dwords;
const __le16 *words;
const char *str;
} ver;
size_t outlength;
unsigned int flags;
int rc;
rc = efx_mcdi_rpc(efx, MC_CMD_GET_VERSION, inbuf, sizeof(inbuf),
outbuf, sizeof(outbuf), &outlength);
if (rc || outlength < MC_CMD_GET_VERSION_OUT_LEN) {
netif_err(efx, drv, efx->net_dev,
"mcdi MC_CMD_GET_VERSION failed\n");
return rc;
}
/* Handle previous output */
if (outlength < MC_CMD_GET_VERSION_V2_OUT_LEN) {
ver.words = (__le16 *)MCDI_PTR(outbuf,
GET_VERSION_EXT_OUT_VERSION);
snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
le16_to_cpu(ver.words[0]),
le16_to_cpu(ver.words[1]),
le16_to_cpu(ver.words[2]),
le16_to_cpu(ver.words[3]));
devlink_info_version_running_put(req,
DEVLINK_INFO_VERSION_GENERIC_FW_MGMT,
buf);
return 0;
}
/* Handle V2 additions */
flags = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_FLAGS);
efx_devlink_info_running_v2(efx, req, flags, outbuf);
if (outlength < MC_CMD_GET_VERSION_V3_OUT_LEN)
return 0;
/* Handle V3 additions */
efx_devlink_info_running_v3(efx, req, flags, outbuf);
if (outlength < MC_CMD_GET_VERSION_V4_OUT_LEN)
return 0;
/* Handle V4 additions */
efx_devlink_info_running_v4(efx, req, flags, outbuf);
if (outlength < MC_CMD_GET_VERSION_V5_OUT_LEN)
return 0;
/* Handle V5 additions */
efx_devlink_info_running_v5(efx, req, flags, outbuf);
return 0;
}
#define EFX_MAX_SERIALNUM_LEN (ETH_ALEN * 2 + 1)
static int efx_devlink_info_board_cfg(struct efx_nic *efx,
struct devlink_info_req *req)
{
char sn[EFX_MAX_SERIALNUM_LEN];
u8 mac_address[ETH_ALEN];
int rc;
rc = efx_mcdi_get_board_cfg(efx, (u8 *)mac_address, NULL, NULL);
if (!rc) {
snprintf(sn, EFX_MAX_SERIALNUM_LEN, "%pm", mac_address);
devlink_info_serial_number_put(req, sn);
}
return rc;
}
static int efx_devlink_info_get(struct devlink *devlink,
struct devlink_info_req *req,
struct netlink_ext_ack *extack)
{
struct efx_devlink *devlink_private = devlink_priv(devlink);
struct efx_nic *efx = devlink_private->efx;
int err;
/* Several different MCDI commands are used. We report if errors
* happened through extack. Specific error information via system
* messages inside the calls.
*/
err = efx_devlink_info_board_cfg(efx, req);
err |= efx_devlink_info_stored_versions(efx, req);
err |= efx_devlink_info_running_versions(efx, req);
if (err)
NL_SET_ERR_MSG_MOD(extack, "Errors when getting device info. Check system messages");
return 0;
}
static int efx_devlink_flash_update(struct devlink *devlink,
struct devlink_flash_update_params *params,
struct netlink_ext_ack *extack)
{
struct efx_devlink *devlink_private = devlink_priv(devlink);
struct efx_nic *efx = devlink_private->efx;
return efx_reflash_flash_firmware(efx, params->fw, extack);
}
static const struct devlink_ops sfc_devlink_ops = {
.supported_flash_update_params = 0,
.flash_update = efx_devlink_flash_update,
.info_get = efx_devlink_info_get,
};
#ifdef CONFIG_SFC_SRIOV
static struct devlink_port *ef100_set_devlink_port(struct efx_nic *efx, u32 idx)
{
struct mae_mport_desc *mport;
u32 id;
int rc;
if (!efx->mae)
return NULL;
if (efx_mae_lookup_mport(efx, idx, &id)) {
/* This should not happen. */
if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
pci_warn_once(efx->pci_dev, "No mport ID found for PF.\n");
else
pci_warn_once(efx->pci_dev, "No mport ID found for VF %u.\n",
idx);
return NULL;
}
mport = efx_mae_get_mport(efx, id);
if (!mport) {
/* This should not happen. */
if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
pci_warn_once(efx->pci_dev, "No mport found for PF.\n");
else
pci_warn_once(efx->pci_dev, "No mport found for VF %u.\n",
idx);
return NULL;
}
rc = efx_devlink_add_port(efx, mport);
if (rc) {
if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
pci_warn(efx->pci_dev,
"devlink port creation for PF failed.\n");
else
pci_warn(efx->pci_dev,
"devlink_port creation for VF %u failed.\n",
idx);
return NULL;
}
return &mport->dl_port;
}
void ef100_rep_set_devlink_port(struct efx_rep *efv)
{
efv->dl_port = ef100_set_devlink_port(efv->parent, efv->idx);
}
void ef100_pf_set_devlink_port(struct efx_nic *efx)
{
efx->dl_port = ef100_set_devlink_port(efx, MAE_MPORT_DESC_VF_IDX_NULL);
}
void ef100_rep_unset_devlink_port(struct efx_rep *efv)
{
efx_devlink_del_port(efv->dl_port);
}
void ef100_pf_unset_devlink_port(struct efx_nic *efx)
{
efx_devlink_del_port(efx->dl_port);
}
#endif
void efx_fini_devlink_lock(struct efx_nic *efx)
{
if (efx->devlink)
devl_lock(efx->devlink);
}
void efx_fini_devlink_and_unlock(struct efx_nic *efx)
{
if (efx->devlink) {
devl_unregister(efx->devlink);
devl_unlock(efx->devlink);
devlink_free(efx->devlink);
efx->devlink = NULL;
}
}
int efx_probe_devlink_and_lock(struct efx_nic *efx)
{
struct efx_devlink *devlink_private;
if (efx->type->is_vf)
return 0;
efx->devlink = devlink_alloc(&sfc_devlink_ops,
sizeof(struct efx_devlink),
&efx->pci_dev->dev);
if (!efx->devlink)
return -ENOMEM;
devl_lock(efx->devlink);
devlink_private = devlink_priv(efx->devlink);
devlink_private->efx = efx;
devl_register(efx->devlink);
return 0;
}
void efx_probe_devlink_unlock(struct efx_nic *efx)
{
if (!efx->devlink)
return;
devl_unlock(efx->devlink);
}
|