Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bnxt: Move generic devlink code to new file

Moving generic devlink code (registration) out of VF-R code
into new bnxt_devlink file, in preparation for future work
to add additional devlink functionality to bnxt.

Signed-off-by: Steve Lin <steven.lin1@broadcom.com>
Acked-by: Andy Gospodarek <gospo@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Steve Lin and committed by
David S. Miller
3c467bf3 cb4dc41e

+112 -85
+1 -1
drivers/net/ethernet/broadcom/bnxt/Makefile
··· 1 1 obj-$(CONFIG_BNXT) += bnxt_en.o 2 2 3 - bnxt_en-y := bnxt.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o bnxt_xdp.o bnxt_vfr.o 3 + bnxt_en-y := bnxt.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o bnxt_xdp.o bnxt_vfr.o bnxt_devlink.o 4 4 bnxt_en-$(CONFIG_BNXT_FLOWER_OFFLOAD) += bnxt_tc.o
+1
drivers/net/ethernet/broadcom/bnxt/bnxt.c
··· 61 61 #include "bnxt_xdp.h" 62 62 #include "bnxt_vfr.h" 63 63 #include "bnxt_tc.h" 64 + #include "bnxt_devlink.h" 64 65 65 66 #define BNXT_TX_TIMEOUT (5 * HZ) 66 67
+65
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
··· 1 + /* Broadcom NetXtreme-C/E network driver. 2 + * 3 + * Copyright (c) 2017 Broadcom Limited 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation. 8 + */ 9 + 10 + #include <linux/pci.h> 11 + #include <linux/netdevice.h> 12 + #include "bnxt_hsi.h" 13 + #include "bnxt.h" 14 + #include "bnxt_vfr.h" 15 + #include "bnxt_devlink.h" 16 + 17 + static const struct devlink_ops bnxt_dl_ops = { 18 + #ifdef CONFIG_BNXT_SRIOV 19 + .eswitch_mode_set = bnxt_dl_eswitch_mode_set, 20 + .eswitch_mode_get = bnxt_dl_eswitch_mode_get, 21 + #endif /* CONFIG_BNXT_SRIOV */ 22 + }; 23 + 24 + int bnxt_dl_register(struct bnxt *bp) 25 + { 26 + struct devlink *dl; 27 + int rc; 28 + 29 + if (!pci_find_ext_capability(bp->pdev, PCI_EXT_CAP_ID_SRIOV)) 30 + return 0; 31 + 32 + if (bp->hwrm_spec_code < 0x10800) { 33 + netdev_warn(bp->dev, "Firmware does not support SR-IOV E-Switch SWITCHDEV mode.\n"); 34 + return -ENOTSUPP; 35 + } 36 + 37 + dl = devlink_alloc(&bnxt_dl_ops, sizeof(struct bnxt_dl)); 38 + if (!dl) { 39 + netdev_warn(bp->dev, "devlink_alloc failed"); 40 + return -ENOMEM; 41 + } 42 + 43 + bnxt_link_bp_to_dl(bp, dl); 44 + bp->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY; 45 + rc = devlink_register(dl, &bp->pdev->dev); 46 + if (rc) { 47 + bnxt_link_bp_to_dl(bp, NULL); 48 + devlink_free(dl); 49 + netdev_warn(bp->dev, "devlink_register failed. rc=%d", rc); 50 + return rc; 51 + } 52 + 53 + return 0; 54 + } 55 + 56 + void bnxt_dl_unregister(struct bnxt *bp) 57 + { 58 + struct devlink *dl = bp->dl; 59 + 60 + if (!dl) 61 + return; 62 + 63 + devlink_unregister(dl); 64 + devlink_free(dl); 65 + }
+39
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h
··· 1 + /* Broadcom NetXtreme-C/E network driver. 2 + * 3 + * Copyright (c) 2017 Broadcom Limited 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation. 8 + */ 9 + 10 + #ifndef BNXT_DEVLINK_H 11 + #define BNXT_DEVLINK_H 12 + 13 + /* Struct to hold housekeeping info needed by devlink interface */ 14 + struct bnxt_dl { 15 + struct bnxt *bp; /* back ptr to the controlling dev */ 16 + }; 17 + 18 + static inline struct bnxt *bnxt_get_bp_from_dl(struct devlink *dl) 19 + { 20 + return ((struct bnxt_dl *)devlink_priv(dl))->bp; 21 + } 22 + 23 + /* To clear devlink pointer from bp, pass NULL dl */ 24 + static inline void bnxt_link_bp_to_dl(struct bnxt *bp, struct devlink *dl) 25 + { 26 + bp->dl = dl; 27 + 28 + /* add a back pointer in dl to bp */ 29 + if (dl) { 30 + struct bnxt_dl *bp_dl = devlink_priv(dl); 31 + 32 + bp_dl->bp = bp; 33 + } 34 + } 35 + 36 + int bnxt_dl_register(struct bnxt *bp); 37 + void bnxt_dl_unregister(struct bnxt *bp); 38 + 39 + #endif /* BNXT_DEVLINK_H */
+3 -50
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c
··· 16 16 #include "bnxt_hsi.h" 17 17 #include "bnxt.h" 18 18 #include "bnxt_vfr.h" 19 + #include "bnxt_devlink.h" 19 20 #include "bnxt_tc.h" 20 21 21 22 #ifdef CONFIG_BNXT_SRIOV ··· 452 451 } 453 452 454 453 /* Devlink related routines */ 455 - static int bnxt_dl_eswitch_mode_get(struct devlink *devlink, u16 *mode) 454 + int bnxt_dl_eswitch_mode_get(struct devlink *devlink, u16 *mode) 456 455 { 457 456 struct bnxt *bp = bnxt_get_bp_from_dl(devlink); 458 457 ··· 460 459 return 0; 461 460 } 462 461 463 - static int bnxt_dl_eswitch_mode_set(struct devlink *devlink, u16 mode) 462 + int bnxt_dl_eswitch_mode_set(struct devlink *devlink, u16 mode) 464 463 { 465 464 struct bnxt *bp = bnxt_get_bp_from_dl(devlink); 466 465 int rc = 0; ··· 496 495 done: 497 496 mutex_unlock(&bp->sriov_lock); 498 497 return rc; 499 - } 500 - 501 - static const struct devlink_ops bnxt_dl_ops = { 502 - .eswitch_mode_set = bnxt_dl_eswitch_mode_set, 503 - .eswitch_mode_get = bnxt_dl_eswitch_mode_get 504 - }; 505 - 506 - int bnxt_dl_register(struct bnxt *bp) 507 - { 508 - struct devlink *dl; 509 - int rc; 510 - 511 - if (!pci_find_ext_capability(bp->pdev, PCI_EXT_CAP_ID_SRIOV)) 512 - return 0; 513 - 514 - if (bp->hwrm_spec_code < 0x10800) { 515 - netdev_warn(bp->dev, "Firmware does not support SR-IOV E-Switch SWITCHDEV mode.\n"); 516 - return -ENOTSUPP; 517 - } 518 - 519 - dl = devlink_alloc(&bnxt_dl_ops, sizeof(struct bnxt_dl)); 520 - if (!dl) { 521 - netdev_warn(bp->dev, "devlink_alloc failed"); 522 - return -ENOMEM; 523 - } 524 - 525 - bnxt_link_bp_to_dl(bp, dl); 526 - bp->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY; 527 - rc = devlink_register(dl, &bp->pdev->dev); 528 - if (rc) { 529 - bnxt_link_bp_to_dl(bp, NULL); 530 - devlink_free(dl); 531 - netdev_warn(bp->dev, "devlink_register failed. rc=%d", rc); 532 - return rc; 533 - } 534 - 535 - return 0; 536 - } 537 - 538 - void bnxt_dl_unregister(struct bnxt *bp) 539 - { 540 - struct devlink *dl = bp->dl; 541 - 542 - if (!dl) 543 - return; 544 - 545 - devlink_unregister(dl); 546 - devlink_free(dl); 547 498 } 548 499 549 500 #endif
+3 -34
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h
··· 14 14 15 15 #define MAX_CFA_CODE 65536 16 16 17 - /* Struct to hold housekeeping info needed by devlink interface */ 18 - struct bnxt_dl { 19 - struct bnxt *bp; /* back ptr to the controlling dev */ 20 - }; 21 - 22 - static inline struct bnxt *bnxt_get_bp_from_dl(struct devlink *dl) 23 - { 24 - return ((struct bnxt_dl *)devlink_priv(dl))->bp; 25 - } 26 - 27 - /* To clear devlink pointer from bp, pass NULL dl */ 28 - static inline void bnxt_link_bp_to_dl(struct bnxt *bp, struct devlink *dl) 29 - { 30 - bp->dl = dl; 31 - 32 - /* add a back pointer in dl to bp */ 33 - if (dl) { 34 - struct bnxt_dl *bp_dl = devlink_priv(dl); 35 - 36 - bp_dl->bp = bp; 37 - } 38 - } 39 - 40 - int bnxt_dl_register(struct bnxt *bp); 41 - void bnxt_dl_unregister(struct bnxt *bp); 42 17 void bnxt_vf_reps_destroy(struct bnxt *bp); 43 18 void bnxt_vf_reps_close(struct bnxt *bp); 44 19 void bnxt_vf_reps_open(struct bnxt *bp); ··· 28 53 return bp->pf.vf[vf_rep->vf_idx].fw_fid; 29 54 } 30 55 56 + int bnxt_dl_eswitch_mode_get(struct devlink *devlink, u16 *mode); 57 + int bnxt_dl_eswitch_mode_set(struct devlink *devlink, u16 mode); 58 + 31 59 #else 32 - 33 - static inline int bnxt_dl_register(struct bnxt *bp) 34 - { 35 - return 0; 36 - } 37 - 38 - static inline void bnxt_dl_unregister(struct bnxt *bp) 39 - { 40 - } 41 60 42 61 static inline void bnxt_vf_reps_close(struct bnxt *bp) 43 62 {