1c0c050c5SMichael Chan /* Broadcom NetXtreme-C/E network driver. 2c0c050c5SMichael Chan * 311f15ed3SMichael Chan * Copyright (c) 2014-2016 Broadcom Corporation 48e202366SMichael Chan * Copyright (c) 2016-2017 Broadcom Limited 5c0c050c5SMichael Chan * 6c0c050c5SMichael Chan * This program is free software; you can redistribute it and/or modify 7c0c050c5SMichael Chan * it under the terms of the GNU General Public License as published by 8c0c050c5SMichael Chan * the Free Software Foundation. 9c0c050c5SMichael Chan */ 10c0c050c5SMichael Chan 113ebf6f0aSRob Swindell #include <linux/ctype.h> 128ddc9aaaSMichael Chan #include <linux/stringify.h> 13c0c050c5SMichael Chan #include <linux/ethtool.h> 14c0c050c5SMichael Chan #include <linux/interrupt.h> 15c0c050c5SMichael Chan #include <linux/pci.h> 16c0c050c5SMichael Chan #include <linux/etherdevice.h> 17c0c050c5SMichael Chan #include <linux/crc32.h> 18c0c050c5SMichael Chan #include <linux/firmware.h> 196c5657d0SVasundhara Volam #include <linux/utsname.h> 206c5657d0SVasundhara Volam #include <linux/time.h> 21c0c050c5SMichael Chan #include "bnxt_hsi.h" 22c0c050c5SMichael Chan #include "bnxt.h" 23f7dc1ea6SMichael Chan #include "bnxt_xdp.h" 24c0c050c5SMichael Chan #include "bnxt_ethtool.h" 25c0c050c5SMichael Chan #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */ 26c0c050c5SMichael Chan #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */ 276c5657d0SVasundhara Volam #include "bnxt_coredump.h" 28c0c050c5SMichael Chan #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100) 295ac67d8bSRob Swindell #define FLASH_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200) 305ac67d8bSRob Swindell #define INSTALL_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200) 31c0c050c5SMichael Chan 32c0c050c5SMichael Chan static u32 bnxt_get_msglevel(struct net_device *dev) 33c0c050c5SMichael Chan { 34c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 35c0c050c5SMichael Chan 36c0c050c5SMichael Chan return bp->msg_enable; 37c0c050c5SMichael Chan } 38c0c050c5SMichael Chan 39c0c050c5SMichael Chan static void bnxt_set_msglevel(struct net_device *dev, u32 value) 40c0c050c5SMichael Chan { 41c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 42c0c050c5SMichael Chan 43c0c050c5SMichael Chan bp->msg_enable = value; 44c0c050c5SMichael Chan } 45c0c050c5SMichael Chan 46c0c050c5SMichael Chan static int bnxt_get_coalesce(struct net_device *dev, 47c0c050c5SMichael Chan struct ethtool_coalesce *coal) 48c0c050c5SMichael Chan { 49c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 5018775aa8SMichael Chan struct bnxt_coal *hw_coal; 5118775aa8SMichael Chan u16 mult; 52c0c050c5SMichael Chan 53c0c050c5SMichael Chan memset(coal, 0, sizeof(*coal)); 54c0c050c5SMichael Chan 556a8788f2SAndy Gospodarek coal->use_adaptive_rx_coalesce = bp->flags & BNXT_FLAG_DIM; 566a8788f2SAndy Gospodarek 5718775aa8SMichael Chan hw_coal = &bp->rx_coal; 5818775aa8SMichael Chan mult = hw_coal->bufs_per_record; 5918775aa8SMichael Chan coal->rx_coalesce_usecs = hw_coal->coal_ticks; 6018775aa8SMichael Chan coal->rx_max_coalesced_frames = hw_coal->coal_bufs / mult; 6118775aa8SMichael Chan coal->rx_coalesce_usecs_irq = hw_coal->coal_ticks_irq; 6218775aa8SMichael Chan coal->rx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult; 63c0c050c5SMichael Chan 6418775aa8SMichael Chan hw_coal = &bp->tx_coal; 6518775aa8SMichael Chan mult = hw_coal->bufs_per_record; 6618775aa8SMichael Chan coal->tx_coalesce_usecs = hw_coal->coal_ticks; 6718775aa8SMichael Chan coal->tx_max_coalesced_frames = hw_coal->coal_bufs / mult; 6818775aa8SMichael Chan coal->tx_coalesce_usecs_irq = hw_coal->coal_ticks_irq; 6918775aa8SMichael Chan coal->tx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult; 70dfc9c94aSMichael Chan 7151f30785SMichael Chan coal->stats_block_coalesce_usecs = bp->stats_coal_ticks; 7251f30785SMichael Chan 73c0c050c5SMichael Chan return 0; 74c0c050c5SMichael Chan } 75c0c050c5SMichael Chan 76c0c050c5SMichael Chan static int bnxt_set_coalesce(struct net_device *dev, 77c0c050c5SMichael Chan struct ethtool_coalesce *coal) 78c0c050c5SMichael Chan { 79c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 8051f30785SMichael Chan bool update_stats = false; 8118775aa8SMichael Chan struct bnxt_coal *hw_coal; 82c0c050c5SMichael Chan int rc = 0; 8318775aa8SMichael Chan u16 mult; 84c0c050c5SMichael Chan 856a8788f2SAndy Gospodarek if (coal->use_adaptive_rx_coalesce) { 866a8788f2SAndy Gospodarek bp->flags |= BNXT_FLAG_DIM; 876a8788f2SAndy Gospodarek } else { 886a8788f2SAndy Gospodarek if (bp->flags & BNXT_FLAG_DIM) { 896a8788f2SAndy Gospodarek bp->flags &= ~(BNXT_FLAG_DIM); 906a8788f2SAndy Gospodarek goto reset_coalesce; 916a8788f2SAndy Gospodarek } 926a8788f2SAndy Gospodarek } 936a8788f2SAndy Gospodarek 9418775aa8SMichael Chan hw_coal = &bp->rx_coal; 9518775aa8SMichael Chan mult = hw_coal->bufs_per_record; 9618775aa8SMichael Chan hw_coal->coal_ticks = coal->rx_coalesce_usecs; 9718775aa8SMichael Chan hw_coal->coal_bufs = coal->rx_max_coalesced_frames * mult; 9818775aa8SMichael Chan hw_coal->coal_ticks_irq = coal->rx_coalesce_usecs_irq; 9918775aa8SMichael Chan hw_coal->coal_bufs_irq = coal->rx_max_coalesced_frames_irq * mult; 100c0c050c5SMichael Chan 101de4a10efSAndy Gospodarek hw_coal = &bp->tx_coal; 10218775aa8SMichael Chan mult = hw_coal->bufs_per_record; 10318775aa8SMichael Chan hw_coal->coal_ticks = coal->tx_coalesce_usecs; 10418775aa8SMichael Chan hw_coal->coal_bufs = coal->tx_max_coalesced_frames * mult; 10518775aa8SMichael Chan hw_coal->coal_ticks_irq = coal->tx_coalesce_usecs_irq; 10618775aa8SMichael Chan hw_coal->coal_bufs_irq = coal->tx_max_coalesced_frames_irq * mult; 107dfc9c94aSMichael Chan 10851f30785SMichael Chan if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) { 10951f30785SMichael Chan u32 stats_ticks = coal->stats_block_coalesce_usecs; 11051f30785SMichael Chan 111adcc331eSMichael Chan /* Allow 0, which means disable. */ 112adcc331eSMichael Chan if (stats_ticks) 11351f30785SMichael Chan stats_ticks = clamp_t(u32, stats_ticks, 11451f30785SMichael Chan BNXT_MIN_STATS_COAL_TICKS, 11551f30785SMichael Chan BNXT_MAX_STATS_COAL_TICKS); 11651f30785SMichael Chan stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS); 11751f30785SMichael Chan bp->stats_coal_ticks = stats_ticks; 118e795892eSMichael Chan if (bp->stats_coal_ticks) 119e795892eSMichael Chan bp->current_interval = 120e795892eSMichael Chan bp->stats_coal_ticks * HZ / 1000000; 121e795892eSMichael Chan else 122e795892eSMichael Chan bp->current_interval = BNXT_TIMER_INTERVAL; 12351f30785SMichael Chan update_stats = true; 12451f30785SMichael Chan } 12551f30785SMichael Chan 1266a8788f2SAndy Gospodarek reset_coalesce: 12751f30785SMichael Chan if (netif_running(dev)) { 12851f30785SMichael Chan if (update_stats) { 12951f30785SMichael Chan rc = bnxt_close_nic(bp, true, false); 13051f30785SMichael Chan if (!rc) 13151f30785SMichael Chan rc = bnxt_open_nic(bp, true, false); 13251f30785SMichael Chan } else { 133c0c050c5SMichael Chan rc = bnxt_hwrm_set_coal(bp); 13451f30785SMichael Chan } 13551f30785SMichael Chan } 136c0c050c5SMichael Chan 137c0c050c5SMichael Chan return rc; 138c0c050c5SMichael Chan } 139c0c050c5SMichael Chan 140ee79566eSMichael Chan static const char * const bnxt_ring_stats_str[] = { 141ee79566eSMichael Chan "rx_ucast_packets", 142ee79566eSMichael Chan "rx_mcast_packets", 143ee79566eSMichael Chan "rx_bcast_packets", 144ee79566eSMichael Chan "rx_discards", 145ee79566eSMichael Chan "rx_drops", 146ee79566eSMichael Chan "rx_ucast_bytes", 147ee79566eSMichael Chan "rx_mcast_bytes", 148ee79566eSMichael Chan "rx_bcast_bytes", 149ee79566eSMichael Chan "tx_ucast_packets", 150ee79566eSMichael Chan "tx_mcast_packets", 151ee79566eSMichael Chan "tx_bcast_packets", 152ee79566eSMichael Chan "tx_discards", 153ee79566eSMichael Chan "tx_drops", 154ee79566eSMichael Chan "tx_ucast_bytes", 155ee79566eSMichael Chan "tx_mcast_bytes", 156ee79566eSMichael Chan "tx_bcast_bytes", 157ee79566eSMichael Chan }; 158ee79566eSMichael Chan 159ee79566eSMichael Chan static const char * const bnxt_ring_tpa_stats_str[] = { 160ee79566eSMichael Chan "tpa_packets", 161ee79566eSMichael Chan "tpa_bytes", 162ee79566eSMichael Chan "tpa_events", 163ee79566eSMichael Chan "tpa_aborts", 164ee79566eSMichael Chan }; 165ee79566eSMichael Chan 16678e7b866SMichael Chan static const char * const bnxt_ring_tpa2_stats_str[] = { 16778e7b866SMichael Chan "rx_tpa_eligible_pkt", 16878e7b866SMichael Chan "rx_tpa_eligible_bytes", 16978e7b866SMichael Chan "rx_tpa_pkt", 17078e7b866SMichael Chan "rx_tpa_bytes", 17178e7b866SMichael Chan "rx_tpa_errors", 17278e7b866SMichael Chan }; 17378e7b866SMichael Chan 174ee79566eSMichael Chan static const char * const bnxt_ring_sw_stats_str[] = { 175ee79566eSMichael Chan "rx_l4_csum_errors", 176ee79566eSMichael Chan "missed_irqs", 177ee79566eSMichael Chan }; 178c0c050c5SMichael Chan 1798ddc9aaaSMichael Chan #define BNXT_RX_STATS_ENTRY(counter) \ 1808ddc9aaaSMichael Chan { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) } 1818ddc9aaaSMichael Chan 1828ddc9aaaSMichael Chan #define BNXT_TX_STATS_ENTRY(counter) \ 1838ddc9aaaSMichael Chan { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) } 1848ddc9aaaSMichael Chan 18500db3cbaSVasundhara Volam #define BNXT_RX_STATS_EXT_ENTRY(counter) \ 18600db3cbaSVasundhara Volam { BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) } 18700db3cbaSVasundhara Volam 18836e53349SMichael Chan #define BNXT_TX_STATS_EXT_ENTRY(counter) \ 18936e53349SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter), __stringify(counter) } 19036e53349SMichael Chan 19136e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRY(n) \ 19236e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_duration_us), \ 19336e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_transitions) 19436e53349SMichael Chan 19536e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRY(n) \ 19636e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_duration_us), \ 19736e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_transitions) 19836e53349SMichael Chan 19936e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRIES \ 20036e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(0), \ 20136e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(1), \ 20236e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(2), \ 20336e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(3), \ 20436e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(4), \ 20536e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(5), \ 20636e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(6), \ 20736e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(7) 20836e53349SMichael Chan 20936e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRIES \ 21036e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(0), \ 21136e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(1), \ 21236e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(2), \ 21336e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(3), \ 21436e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(4), \ 21536e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(5), \ 21636e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(6), \ 21736e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(7) 21836e53349SMichael Chan 21936e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRY(n) \ 22036e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bytes_cos##n), \ 22136e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_packets_cos##n) 22236e53349SMichael Chan 22336e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRY(n) \ 22436e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_bytes_cos##n), \ 22536e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_packets_cos##n) 22636e53349SMichael Chan 22736e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRIES \ 22836e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(0), \ 22936e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(1), \ 23036e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(2), \ 23136e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(3), \ 23236e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(4), \ 23336e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(5), \ 23436e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(6), \ 23536e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(7) \ 23636e53349SMichael Chan 23736e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRIES \ 23836e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(0), \ 23936e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(1), \ 24036e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(2), \ 24136e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(3), \ 24236e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(4), \ 24336e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(5), \ 24436e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(6), \ 24536e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(7) \ 24636e53349SMichael Chan 2472792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(n) \ 2482792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_bytes_cos##n), \ 2492792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_packets_cos##n) 2502792b5b9SMichael Chan 2512792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES \ 2522792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(0), \ 2532792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(1), \ 2542792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(2), \ 2552792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(3), \ 2562792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(4), \ 2572792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(5), \ 2582792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(6), \ 2592792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(7) 2602792b5b9SMichael Chan 261e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRY(counter, n) \ 262e37fed79SMichael Chan { BNXT_RX_STATS_EXT_OFFSET(counter##_cos0), \ 263e37fed79SMichael Chan __stringify(counter##_pri##n) } 264e37fed79SMichael Chan 265e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRY(counter, n) \ 266e37fed79SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter##_cos0), \ 267e37fed79SMichael Chan __stringify(counter##_pri##n) } 268e37fed79SMichael Chan 269e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRIES(counter) \ 270e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 0), \ 271e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 1), \ 272e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 2), \ 273e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 3), \ 274e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 4), \ 275e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 5), \ 276e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 6), \ 277e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 7) 278e37fed79SMichael Chan 279e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRIES(counter) \ 280e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 0), \ 281e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 1), \ 282e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 2), \ 283e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 3), \ 284e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 4), \ 285e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 5), \ 286e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 6), \ 287e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 7) 288e37fed79SMichael Chan 28955e4398dSVasundhara Volam #define BNXT_PCIE_STATS_ENTRY(counter) \ 29055e4398dSVasundhara Volam { BNXT_PCIE_STATS_OFFSET(counter), __stringify(counter) } 29155e4398dSVasundhara Volam 29220c1d28eSVasundhara Volam enum { 29320c1d28eSVasundhara Volam RX_TOTAL_DISCARDS, 29420c1d28eSVasundhara Volam TX_TOTAL_DISCARDS, 29520c1d28eSVasundhara Volam }; 29620c1d28eSVasundhara Volam 29720c1d28eSVasundhara Volam static struct { 29820c1d28eSVasundhara Volam u64 counter; 29920c1d28eSVasundhara Volam char string[ETH_GSTRING_LEN]; 30020c1d28eSVasundhara Volam } bnxt_sw_func_stats[] = { 30120c1d28eSVasundhara Volam {0, "rx_total_discard_pkts"}, 30220c1d28eSVasundhara Volam {0, "tx_total_discard_pkts"}, 30320c1d28eSVasundhara Volam }; 30420c1d28eSVasundhara Volam 3058ddc9aaaSMichael Chan static const struct { 3068ddc9aaaSMichael Chan long offset; 3078ddc9aaaSMichael Chan char string[ETH_GSTRING_LEN]; 3088ddc9aaaSMichael Chan } bnxt_port_stats_arr[] = { 3098ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_64b_frames), 3108ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_65b_127b_frames), 3118ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_128b_255b_frames), 3128ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_256b_511b_frames), 3138ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames), 3146fc92c33SMichael Chan BNXT_RX_STATS_ENTRY(rx_1024b_1518b_frames), 3158ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_vlan_frames), 3168ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames), 3178ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames), 3188ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames), 3198ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames), 3208ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_total_frames), 3218ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ucast_frames), 3228ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mcast_frames), 3238ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bcast_frames), 3248ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_fcs_err_frames), 3258ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ctrl_frames), 3268ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pause_frames), 3278ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_frames), 3288ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_align_err_frames), 3298ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ovrsz_frames), 3308ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_jbr_frames), 3318ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mtu_err_frames), 3328ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_tagged_frames), 3338ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_double_tagged_frames), 3348ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_frames), 335c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0), 336c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1), 337c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2), 338c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3), 339c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4), 340c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5), 341c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6), 342c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7), 3438ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_undrsz_frames), 3448ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_events), 3458ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration), 3468ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bytes), 3478ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_bytes), 3488ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_frames), 349699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_discard), 350699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_err), 3518ddc9aaaSMichael Chan 3528ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_64b_frames), 3538ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_65b_127b_frames), 3548ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_128b_255b_frames), 3558ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_256b_511b_frames), 3568ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames), 3576fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1024b_1518b_frames), 3588ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_vlan_frames), 3596fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1519b_2047b_frames), 3608ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames), 3618ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames), 3628ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames), 3638ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_frames), 3648ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_frames), 3658ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_ucast_frames), 3668ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_mcast_frames), 3678ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bcast_frames), 3688ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pause_frames), 3698ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_frames), 3708ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_jabber_frames), 3718ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fcs_err_frames), 3728ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_err), 3738ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fifo_underruns), 374c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0), 375c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1), 376c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2), 377c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3), 378c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4), 379c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5), 380c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6), 381c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7), 3828ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_events), 3838ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration), 3848ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_collisions), 3858ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bytes), 386699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_xthol_frames), 387699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_discard), 388699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_error), 3898ddc9aaaSMichael Chan }; 3908ddc9aaaSMichael Chan 39100db3cbaSVasundhara Volam static const struct { 39200db3cbaSVasundhara Volam long offset; 39300db3cbaSVasundhara Volam char string[ETH_GSTRING_LEN]; 39400db3cbaSVasundhara Volam } bnxt_port_stats_ext_arr[] = { 39500db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(link_down_events), 39600db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events), 39700db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_pause_events), 39800db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events), 39900db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events), 40036e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRIES, 40136e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRIES, 4024a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bits), 4034a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_buffer_passed_threshold), 4044a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_pcs_symbol_err), 4054a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_corrected_bits), 4062792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES, 40736e53349SMichael Chan }; 40836e53349SMichael Chan 40936e53349SMichael Chan static const struct { 41036e53349SMichael Chan long offset; 41136e53349SMichael Chan char string[ETH_GSTRING_LEN]; 41236e53349SMichael Chan } bnxt_tx_port_stats_ext_arr[] = { 41336e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRIES, 41436e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRIES, 41500db3cbaSVasundhara Volam }; 41600db3cbaSVasundhara Volam 417e37fed79SMichael Chan static const struct { 418e37fed79SMichael Chan long base_off; 419e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 420e37fed79SMichael Chan } bnxt_rx_bytes_pri_arr[] = { 421e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_bytes), 422e37fed79SMichael Chan }; 423e37fed79SMichael Chan 424e37fed79SMichael Chan static const struct { 425e37fed79SMichael Chan long base_off; 426e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 427e37fed79SMichael Chan } bnxt_rx_pkts_pri_arr[] = { 428e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_packets), 429e37fed79SMichael Chan }; 430e37fed79SMichael Chan 431e37fed79SMichael Chan static const struct { 432e37fed79SMichael Chan long base_off; 433e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 434e37fed79SMichael Chan } bnxt_tx_bytes_pri_arr[] = { 435e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_bytes), 436e37fed79SMichael Chan }; 437e37fed79SMichael Chan 438e37fed79SMichael Chan static const struct { 439e37fed79SMichael Chan long base_off; 440e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 441e37fed79SMichael Chan } bnxt_tx_pkts_pri_arr[] = { 442e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_packets), 443e37fed79SMichael Chan }; 444e37fed79SMichael Chan 44555e4398dSVasundhara Volam static const struct { 44655e4398dSVasundhara Volam long offset; 44755e4398dSVasundhara Volam char string[ETH_GSTRING_LEN]; 44855e4398dSVasundhara Volam } bnxt_pcie_stats_arr[] = { 44955e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_pl_signal_integrity), 45055e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_dl_signal_integrity), 45155e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tl_signal_integrity), 45255e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_link_integrity), 45355e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tx_traffic_rate), 45455e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_rx_traffic_rate), 45555e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tx_dllp_statistics), 45655e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_rx_dllp_statistics), 45755e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_equalization_time), 45855e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[0]), 45955e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[2]), 46055e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_recovery_histogram), 46155e4398dSVasundhara Volam }; 46255e4398dSVasundhara Volam 46320c1d28eSVasundhara Volam #define BNXT_NUM_SW_FUNC_STATS ARRAY_SIZE(bnxt_sw_func_stats) 4648ddc9aaaSMichael Chan #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr) 465e37fed79SMichael Chan #define BNXT_NUM_STATS_PRI \ 466e37fed79SMichael Chan (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \ 467e37fed79SMichael Chan ARRAY_SIZE(bnxt_rx_pkts_pri_arr) + \ 468e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_bytes_pri_arr) + \ 469e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_pkts_pri_arr)) 47055e4398dSVasundhara Volam #define BNXT_NUM_PCIE_STATS ARRAY_SIZE(bnxt_pcie_stats_arr) 4718ddc9aaaSMichael Chan 47278e7b866SMichael Chan static int bnxt_get_num_tpa_ring_stats(struct bnxt *bp) 47378e7b866SMichael Chan { 47478e7b866SMichael Chan if (BNXT_SUPPORTS_TPA(bp)) { 47578e7b866SMichael Chan if (bp->max_tpa_v2) 47678e7b866SMichael Chan return ARRAY_SIZE(bnxt_ring_tpa2_stats_str); 47778e7b866SMichael Chan return ARRAY_SIZE(bnxt_ring_tpa_stats_str); 47878e7b866SMichael Chan } 47978e7b866SMichael Chan return 0; 48078e7b866SMichael Chan } 48178e7b866SMichael Chan 482ee79566eSMichael Chan static int bnxt_get_num_ring_stats(struct bnxt *bp) 483ee79566eSMichael Chan { 484ee79566eSMichael Chan int num_stats; 485ee79566eSMichael Chan 486ee79566eSMichael Chan num_stats = ARRAY_SIZE(bnxt_ring_stats_str) + 48778e7b866SMichael Chan ARRAY_SIZE(bnxt_ring_sw_stats_str) + 48878e7b866SMichael Chan bnxt_get_num_tpa_ring_stats(bp); 489ee79566eSMichael Chan return num_stats * bp->cp_nr_rings; 490ee79566eSMichael Chan } 491ee79566eSMichael Chan 4925c8227d0SMichael Chan static int bnxt_get_num_stats(struct bnxt *bp) 493c0c050c5SMichael Chan { 494ee79566eSMichael Chan int num_stats = bnxt_get_num_ring_stats(bp); 4958ddc9aaaSMichael Chan 49620c1d28eSVasundhara Volam num_stats += BNXT_NUM_SW_FUNC_STATS; 49720c1d28eSVasundhara Volam 4988ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) 4998ddc9aaaSMichael Chan num_stats += BNXT_NUM_PORT_STATS; 5008ddc9aaaSMichael Chan 501e37fed79SMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 50236e53349SMichael Chan num_stats += bp->fw_rx_stats_ext_size + 50336e53349SMichael Chan bp->fw_tx_stats_ext_size; 504e37fed79SMichael Chan if (bp->pri2cos_valid) 505e37fed79SMichael Chan num_stats += BNXT_NUM_STATS_PRI; 506e37fed79SMichael Chan } 50700db3cbaSVasundhara Volam 50855e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) 50955e4398dSVasundhara Volam num_stats += BNXT_NUM_PCIE_STATS; 51055e4398dSVasundhara Volam 5118ddc9aaaSMichael Chan return num_stats; 5128ddc9aaaSMichael Chan } 5135c8227d0SMichael Chan 5145c8227d0SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 5155c8227d0SMichael Chan { 5165c8227d0SMichael Chan struct bnxt *bp = netdev_priv(dev); 5175c8227d0SMichael Chan 5185c8227d0SMichael Chan switch (sset) { 5195c8227d0SMichael Chan case ETH_SS_STATS: 5205c8227d0SMichael Chan return bnxt_get_num_stats(bp); 521eb513658SMichael Chan case ETH_SS_TEST: 522eb513658SMichael Chan if (!bp->num_tests) 523eb513658SMichael Chan return -EOPNOTSUPP; 524eb513658SMichael Chan return bp->num_tests; 525c0c050c5SMichael Chan default: 526c0c050c5SMichael Chan return -EOPNOTSUPP; 527c0c050c5SMichael Chan } 528c0c050c5SMichael Chan } 529c0c050c5SMichael Chan 530c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 531c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 532c0c050c5SMichael Chan { 533c0c050c5SMichael Chan u32 i, j = 0; 534c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 53578e7b866SMichael Chan u32 stat_fields = ARRAY_SIZE(bnxt_ring_stats_str) + 53678e7b866SMichael Chan bnxt_get_num_tpa_ring_stats(bp); 537c0c050c5SMichael Chan 538fd3ab1c7SMichael Chan if (!bp->bnapi) { 539ee79566eSMichael Chan j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS; 540fd3ab1c7SMichael Chan goto skip_ring_stats; 541fd3ab1c7SMichael Chan } 542c0c050c5SMichael Chan 54320c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) 54420c1d28eSVasundhara Volam bnxt_sw_func_stats[i].counter = 0; 54520c1d28eSVasundhara Volam 546c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 547c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 548c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 549c0c050c5SMichael Chan __le64 *hw_stats = (__le64 *)cpr->hw_stats; 550c0c050c5SMichael Chan int k; 551c0c050c5SMichael Chan 552c0c050c5SMichael Chan for (k = 0; k < stat_fields; j++, k++) 553c0c050c5SMichael Chan buf[j] = le64_to_cpu(hw_stats[k]); 554c0c050c5SMichael Chan buf[j++] = cpr->rx_l4_csum_errors; 55583eb5c5cSMichael Chan buf[j++] = cpr->missed_irqs; 55620c1d28eSVasundhara Volam 55720c1d28eSVasundhara Volam bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter += 55820c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->rx_discard_pkts); 55920c1d28eSVasundhara Volam bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter += 56020c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->tx_discard_pkts); 561c0c050c5SMichael Chan } 56220c1d28eSVasundhara Volam 56320c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++) 56420c1d28eSVasundhara Volam buf[j] = bnxt_sw_func_stats[i].counter; 56520c1d28eSVasundhara Volam 566fd3ab1c7SMichael Chan skip_ring_stats: 5678ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 5688ddc9aaaSMichael Chan __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats; 5698ddc9aaaSMichael Chan 5708ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) { 5718ddc9aaaSMichael Chan buf[j] = le64_to_cpu(*(port_stats + 5728ddc9aaaSMichael Chan bnxt_port_stats_arr[i].offset)); 5738ddc9aaaSMichael Chan } 5748ddc9aaaSMichael Chan } 57500db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 57636e53349SMichael Chan __le64 *rx_port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext; 57736e53349SMichael Chan __le64 *tx_port_stats_ext = (__le64 *)bp->hw_tx_port_stats_ext; 57800db3cbaSVasundhara Volam 57936e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) { 58036e53349SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + 58100db3cbaSVasundhara Volam bnxt_port_stats_ext_arr[i].offset)); 58200db3cbaSVasundhara Volam } 58336e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++, j++) { 58436e53349SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + 58536e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].offset)); 58636e53349SMichael Chan } 587e37fed79SMichael Chan if (bp->pri2cos_valid) { 588e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 589e37fed79SMichael Chan long n = bnxt_rx_bytes_pri_arr[i].base_off + 590e37fed79SMichael Chan bp->pri2cos[i]; 591e37fed79SMichael Chan 592e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 593e37fed79SMichael Chan } 594e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 595e37fed79SMichael Chan long n = bnxt_rx_pkts_pri_arr[i].base_off + 596e37fed79SMichael Chan bp->pri2cos[i]; 597e37fed79SMichael Chan 598e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 599e37fed79SMichael Chan } 600e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 601e37fed79SMichael Chan long n = bnxt_tx_bytes_pri_arr[i].base_off + 602e37fed79SMichael Chan bp->pri2cos[i]; 603e37fed79SMichael Chan 604e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 605e37fed79SMichael Chan } 606e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 607e37fed79SMichael Chan long n = bnxt_tx_pkts_pri_arr[i].base_off + 608e37fed79SMichael Chan bp->pri2cos[i]; 609e37fed79SMichael Chan 610e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 611e37fed79SMichael Chan } 612e37fed79SMichael Chan } 61300db3cbaSVasundhara Volam } 61455e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) { 61555e4398dSVasundhara Volam __le64 *pcie_stats = (__le64 *)bp->hw_pcie_stats; 61655e4398dSVasundhara Volam 61755e4398dSVasundhara Volam for (i = 0; i < BNXT_NUM_PCIE_STATS; i++, j++) { 61855e4398dSVasundhara Volam buf[j] = le64_to_cpu(*(pcie_stats + 61955e4398dSVasundhara Volam bnxt_pcie_stats_arr[i].offset)); 62055e4398dSVasundhara Volam } 62155e4398dSVasundhara Volam } 622c0c050c5SMichael Chan } 623c0c050c5SMichael Chan 624c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 625c0c050c5SMichael Chan { 626c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 62778e7b866SMichael Chan static const char * const *str; 628ee79566eSMichael Chan u32 i, j, num_str; 629c0c050c5SMichael Chan 630c0c050c5SMichael Chan switch (stringset) { 631c0c050c5SMichael Chan case ETH_SS_STATS: 632c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 633ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_stats_str); 634ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 635ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 636ee79566eSMichael Chan bnxt_ring_stats_str[j]); 637c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 638ee79566eSMichael Chan } 639ee79566eSMichael Chan if (!BNXT_SUPPORTS_TPA(bp)) 640ee79566eSMichael Chan goto skip_tpa_stats; 641ee79566eSMichael Chan 64278e7b866SMichael Chan if (bp->max_tpa_v2) { 64378e7b866SMichael Chan num_str = ARRAY_SIZE(bnxt_ring_tpa2_stats_str); 64478e7b866SMichael Chan str = bnxt_ring_tpa2_stats_str; 64578e7b866SMichael Chan } else { 646ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_tpa_stats_str); 64778e7b866SMichael Chan str = bnxt_ring_tpa_stats_str; 64878e7b866SMichael Chan } 649ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 65078e7b866SMichael Chan sprintf(buf, "[%d]: %s", i, str[j]); 651c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 652ee79566eSMichael Chan } 653ee79566eSMichael Chan skip_tpa_stats: 654ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_sw_stats_str); 655ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 656ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 657ee79566eSMichael Chan bnxt_ring_sw_stats_str[j]); 658c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 659ee79566eSMichael Chan } 660c0c050c5SMichael Chan } 66120c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) { 66220c1d28eSVasundhara Volam strcpy(buf, bnxt_sw_func_stats[i].string); 66320c1d28eSVasundhara Volam buf += ETH_GSTRING_LEN; 66420c1d28eSVasundhara Volam } 66520c1d28eSVasundhara Volam 6668ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 6678ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++) { 6688ddc9aaaSMichael Chan strcpy(buf, bnxt_port_stats_arr[i].string); 6698ddc9aaaSMichael Chan buf += ETH_GSTRING_LEN; 6708ddc9aaaSMichael Chan } 6718ddc9aaaSMichael Chan } 67200db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 67336e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++) { 67400db3cbaSVasundhara Volam strcpy(buf, bnxt_port_stats_ext_arr[i].string); 67500db3cbaSVasundhara Volam buf += ETH_GSTRING_LEN; 67600db3cbaSVasundhara Volam } 67736e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++) { 67836e53349SMichael Chan strcpy(buf, 67936e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].string); 68036e53349SMichael Chan buf += ETH_GSTRING_LEN; 68136e53349SMichael Chan } 682e37fed79SMichael Chan if (bp->pri2cos_valid) { 683e37fed79SMichael Chan for (i = 0; i < 8; i++) { 684e37fed79SMichael Chan strcpy(buf, 685e37fed79SMichael Chan bnxt_rx_bytes_pri_arr[i].string); 686e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 687e37fed79SMichael Chan } 688e37fed79SMichael Chan for (i = 0; i < 8; i++) { 689e37fed79SMichael Chan strcpy(buf, 690e37fed79SMichael Chan bnxt_rx_pkts_pri_arr[i].string); 691e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 692e37fed79SMichael Chan } 693e37fed79SMichael Chan for (i = 0; i < 8; i++) { 694e37fed79SMichael Chan strcpy(buf, 695e37fed79SMichael Chan bnxt_tx_bytes_pri_arr[i].string); 696e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 697e37fed79SMichael Chan } 698e37fed79SMichael Chan for (i = 0; i < 8; i++) { 699e37fed79SMichael Chan strcpy(buf, 700e37fed79SMichael Chan bnxt_tx_pkts_pri_arr[i].string); 701e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 702e37fed79SMichael Chan } 703e37fed79SMichael Chan } 70400db3cbaSVasundhara Volam } 70555e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) { 70655e4398dSVasundhara Volam for (i = 0; i < BNXT_NUM_PCIE_STATS; i++) { 70755e4398dSVasundhara Volam strcpy(buf, bnxt_pcie_stats_arr[i].string); 70855e4398dSVasundhara Volam buf += ETH_GSTRING_LEN; 70955e4398dSVasundhara Volam } 71055e4398dSVasundhara Volam } 711c0c050c5SMichael Chan break; 712eb513658SMichael Chan case ETH_SS_TEST: 713eb513658SMichael Chan if (bp->num_tests) 714eb513658SMichael Chan memcpy(buf, bp->test_info->string, 715eb513658SMichael Chan bp->num_tests * ETH_GSTRING_LEN); 716eb513658SMichael Chan break; 717c0c050c5SMichael Chan default: 718c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 719c0c050c5SMichael Chan stringset); 720c0c050c5SMichael Chan break; 721c0c050c5SMichael Chan } 722c0c050c5SMichael Chan } 723c0c050c5SMichael Chan 724c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 725c0c050c5SMichael Chan struct ethtool_ringparam *ering) 726c0c050c5SMichael Chan { 727c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 728c0c050c5SMichael Chan 729c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 730c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 731c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 732c0c050c5SMichael Chan 733c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 734c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 735c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 736c0c050c5SMichael Chan } 737c0c050c5SMichael Chan 738c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 739c0c050c5SMichael Chan struct ethtool_ringparam *ering) 740c0c050c5SMichael Chan { 741c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 742c0c050c5SMichael Chan 743c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 744c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 745c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 746c0c050c5SMichael Chan return -EINVAL; 747c0c050c5SMichael Chan 748c0c050c5SMichael Chan if (netif_running(dev)) 749c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 750c0c050c5SMichael Chan 751c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 752c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 753c0c050c5SMichael Chan bnxt_set_ring_params(bp); 754c0c050c5SMichael Chan 755c0c050c5SMichael Chan if (netif_running(dev)) 756c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 757c0c050c5SMichael Chan 758c0c050c5SMichael Chan return 0; 759c0c050c5SMichael Chan } 760c0c050c5SMichael Chan 761c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 762c0c050c5SMichael Chan struct ethtool_channels *channel) 763c0c050c5SMichael Chan { 764c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 765db4723b3SMichael Chan struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 766c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 767db4723b3SMichael Chan int max_tx_sch_inputs; 768db4723b3SMichael Chan 769db4723b3SMichael Chan /* Get the most up-to-date max_tx_sch_inputs. */ 770f1ca94deSMichael Chan if (BNXT_NEW_RM(bp)) 771db4723b3SMichael Chan bnxt_hwrm_func_resc_qcaps(bp, false); 772db4723b3SMichael Chan max_tx_sch_inputs = hw_resc->max_tx_sch_inputs; 773c0c050c5SMichael Chan 7746e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 775db4723b3SMichael Chan if (max_tx_sch_inputs) 776db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 777a79a5276SMichael Chan channel->max_combined = min_t(int, max_rx_rings, max_tx_rings); 778068c9ec6SMichael Chan 77918d6e4e2SSatish Baddipadige if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) { 78018d6e4e2SSatish Baddipadige max_rx_rings = 0; 78118d6e4e2SSatish Baddipadige max_tx_rings = 0; 78218d6e4e2SSatish Baddipadige } 783db4723b3SMichael Chan if (max_tx_sch_inputs) 784db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 78518d6e4e2SSatish Baddipadige 786c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 787c0c050c5SMichael Chan if (tcs > 1) 788c0c050c5SMichael Chan max_tx_rings /= tcs; 789c0c050c5SMichael Chan 790c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 791c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 792c0c050c5SMichael Chan channel->max_other = 0; 793068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 794068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 79576595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp)) 79676595193SPrashant Sreedharan channel->combined_count--; 797068c9ec6SMichael Chan } else { 79876595193SPrashant Sreedharan if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) { 799c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 800c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 801c0c050c5SMichael Chan } 802068c9ec6SMichael Chan } 80376595193SPrashant Sreedharan } 804c0c050c5SMichael Chan 805c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 806c0c050c5SMichael Chan struct ethtool_channels *channel) 807c0c050c5SMichael Chan { 808c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 809d1e7925eSMichael Chan int req_tx_rings, req_rx_rings, tcs; 810068c9ec6SMichael Chan bool sh = false; 8115f449249SMichael Chan int tx_xdp = 0; 812d1e7925eSMichael Chan int rc = 0; 813c0c050c5SMichael Chan 814068c9ec6SMichael Chan if (channel->other_count) 815c0c050c5SMichael Chan return -EINVAL; 816c0c050c5SMichael Chan 817068c9ec6SMichael Chan if (!channel->combined_count && 818068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 819068c9ec6SMichael Chan return -EINVAL; 820068c9ec6SMichael Chan 821068c9ec6SMichael Chan if (channel->combined_count && 822068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 823068c9ec6SMichael Chan return -EINVAL; 824068c9ec6SMichael Chan 82576595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count || 82676595193SPrashant Sreedharan channel->tx_count)) 82776595193SPrashant Sreedharan return -EINVAL; 82876595193SPrashant Sreedharan 829068c9ec6SMichael Chan if (channel->combined_count) 830068c9ec6SMichael Chan sh = true; 831068c9ec6SMichael Chan 832c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 833c0c050c5SMichael Chan 834391be5c2SMichael Chan req_tx_rings = sh ? channel->combined_count : channel->tx_count; 835d1e7925eSMichael Chan req_rx_rings = sh ? channel->combined_count : channel->rx_count; 8365f449249SMichael Chan if (bp->tx_nr_rings_xdp) { 8375f449249SMichael Chan if (!sh) { 8385f449249SMichael Chan netdev_err(dev, "Only combined mode supported when XDP is enabled.\n"); 8395f449249SMichael Chan return -EINVAL; 8405f449249SMichael Chan } 8415f449249SMichael Chan tx_xdp = req_rx_rings; 8425f449249SMichael Chan } 84398fdbe73SMichael Chan rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp); 844d1e7925eSMichael Chan if (rc) { 845d1e7925eSMichael Chan netdev_warn(dev, "Unable to allocate the requested rings\n"); 846d1e7925eSMichael Chan return rc; 847391be5c2SMichael Chan } 848391be5c2SMichael Chan 849c0c050c5SMichael Chan if (netif_running(dev)) { 850c0c050c5SMichael Chan if (BNXT_PF(bp)) { 851c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 852c0c050c5SMichael Chan * before PF unload 853c0c050c5SMichael Chan */ 854c0c050c5SMichael Chan } 855c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 856c0c050c5SMichael Chan if (rc) { 857c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 858c0c050c5SMichael Chan rc); 859c0c050c5SMichael Chan return rc; 860c0c050c5SMichael Chan } 861c0c050c5SMichael Chan } 862c0c050c5SMichael Chan 863068c9ec6SMichael Chan if (sh) { 864068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 865d1e7925eSMichael Chan bp->rx_nr_rings = channel->combined_count; 866d1e7925eSMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 867068c9ec6SMichael Chan } else { 868068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 869c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 870c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 871068c9ec6SMichael Chan } 8725f449249SMichael Chan bp->tx_nr_rings_xdp = tx_xdp; 8735f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp; 874c0c050c5SMichael Chan if (tcs > 1) 8755f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp; 876068c9ec6SMichael Chan 877068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 878068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 879068c9ec6SMichael Chan 8802bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 8812bcfa6f6SMichael Chan netdev_update_features(dev); 882c0c050c5SMichael Chan if (netif_running(dev)) { 883c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 884c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 885c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 886c0c050c5SMichael Chan * to renable 887c0c050c5SMichael Chan */ 888c0c050c5SMichael Chan } 889d8c09f19SMichael Chan } else { 8901b3f0b75SMichael Chan rc = bnxt_reserve_rings(bp, true); 891c0c050c5SMichael Chan } 892c0c050c5SMichael Chan 893c0c050c5SMichael Chan return rc; 894c0c050c5SMichael Chan } 895c0c050c5SMichael Chan 896c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 897c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 898c0c050c5SMichael Chan u32 *rule_locs) 899c0c050c5SMichael Chan { 900c0c050c5SMichael Chan int i, j = 0; 901c0c050c5SMichael Chan 902c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 903c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 904c0c050c5SMichael Chan struct hlist_head *head; 905c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 906c0c050c5SMichael Chan 907c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 908c0c050c5SMichael Chan rcu_read_lock(); 909c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 910c0c050c5SMichael Chan if (j == cmd->rule_cnt) 911c0c050c5SMichael Chan break; 912c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 913c0c050c5SMichael Chan } 914c0c050c5SMichael Chan rcu_read_unlock(); 915c0c050c5SMichael Chan if (j == cmd->rule_cnt) 916c0c050c5SMichael Chan break; 917c0c050c5SMichael Chan } 918c0c050c5SMichael Chan cmd->rule_cnt = j; 919c0c050c5SMichael Chan return 0; 920c0c050c5SMichael Chan } 921c0c050c5SMichael Chan 922c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 923c0c050c5SMichael Chan { 924c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 925c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 926c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 927c0c050c5SMichael Chan struct flow_keys *fkeys; 928c0c050c5SMichael Chan int i, rc = -EINVAL; 929c0c050c5SMichael Chan 930b721cfafSstephen hemminger if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 931c0c050c5SMichael Chan return rc; 932c0c050c5SMichael Chan 933c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 934c0c050c5SMichael Chan struct hlist_head *head; 935c0c050c5SMichael Chan 936c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 937c0c050c5SMichael Chan rcu_read_lock(); 938c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 939c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 940c0c050c5SMichael Chan goto fltr_found; 941c0c050c5SMichael Chan } 942c0c050c5SMichael Chan rcu_read_unlock(); 943c0c050c5SMichael Chan } 944c0c050c5SMichael Chan return rc; 945c0c050c5SMichael Chan 946c0c050c5SMichael Chan fltr_found: 947c0c050c5SMichael Chan fkeys = &fltr->fkeys; 948dda0e746SMichael Chan if (fkeys->basic.n_proto == htons(ETH_P_IP)) { 949c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 950c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 951c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 952c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 953c0c050c5SMichael Chan else 954c0c050c5SMichael Chan goto fltr_err; 955c0c050c5SMichael Chan 956c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 957c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 958c0c050c5SMichael Chan 959c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 960c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 961c0c050c5SMichael Chan 962c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 963c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 964c0c050c5SMichael Chan 965c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 966c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 967dda0e746SMichael Chan } else { 968dda0e746SMichael Chan int i; 969dda0e746SMichael Chan 970dda0e746SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 971dda0e746SMichael Chan fs->flow_type = TCP_V6_FLOW; 972dda0e746SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 973dda0e746SMichael Chan fs->flow_type = UDP_V6_FLOW; 974dda0e746SMichael Chan else 975dda0e746SMichael Chan goto fltr_err; 976dda0e746SMichael Chan 977dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] = 978dda0e746SMichael Chan fkeys->addrs.v6addrs.src; 979dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] = 980dda0e746SMichael Chan fkeys->addrs.v6addrs.dst; 981dda0e746SMichael Chan for (i = 0; i < 4; i++) { 982dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0); 983dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0); 984dda0e746SMichael Chan } 985dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src; 986dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0); 987dda0e746SMichael Chan 988dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst; 989dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0); 990dda0e746SMichael Chan } 991c0c050c5SMichael Chan 992c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 993c0c050c5SMichael Chan rc = 0; 994c0c050c5SMichael Chan 995c0c050c5SMichael Chan fltr_err: 996c0c050c5SMichael Chan rcu_read_unlock(); 997c0c050c5SMichael Chan 998c0c050c5SMichael Chan return rc; 999c0c050c5SMichael Chan } 1000a011952aSMichael Chan #endif 1001a011952aSMichael Chan 1002a011952aSMichael Chan static u64 get_ethtool_ipv4_rss(struct bnxt *bp) 1003a011952aSMichael Chan { 1004a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4) 1005a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 1006a011952aSMichael Chan return 0; 1007a011952aSMichael Chan } 1008a011952aSMichael Chan 1009a011952aSMichael Chan static u64 get_ethtool_ipv6_rss(struct bnxt *bp) 1010a011952aSMichael Chan { 1011a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6) 1012a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 1013a011952aSMichael Chan return 0; 1014a011952aSMichael Chan } 1015a011952aSMichael Chan 1016a011952aSMichael Chan static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1017a011952aSMichael Chan { 1018a011952aSMichael Chan cmd->data = 0; 1019a011952aSMichael Chan switch (cmd->flow_type) { 1020a011952aSMichael Chan case TCP_V4_FLOW: 1021a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) 1022a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1023a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1024a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1025a011952aSMichael Chan break; 1026a011952aSMichael Chan case UDP_V4_FLOW: 1027a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4) 1028a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1029a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1030a011952aSMichael Chan /* fall through */ 1031a011952aSMichael Chan case SCTP_V4_FLOW: 1032a011952aSMichael Chan case AH_ESP_V4_FLOW: 1033a011952aSMichael Chan case AH_V4_FLOW: 1034a011952aSMichael Chan case ESP_V4_FLOW: 1035a011952aSMichael Chan case IPV4_FLOW: 1036a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1037a011952aSMichael Chan break; 1038a011952aSMichael Chan 1039a011952aSMichael Chan case TCP_V6_FLOW: 1040a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) 1041a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1042a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1043a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1044a011952aSMichael Chan break; 1045a011952aSMichael Chan case UDP_V6_FLOW: 1046a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6) 1047a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1048a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1049a011952aSMichael Chan /* fall through */ 1050a011952aSMichael Chan case SCTP_V6_FLOW: 1051a011952aSMichael Chan case AH_ESP_V6_FLOW: 1052a011952aSMichael Chan case AH_V6_FLOW: 1053a011952aSMichael Chan case ESP_V6_FLOW: 1054a011952aSMichael Chan case IPV6_FLOW: 1055a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1056a011952aSMichael Chan break; 1057a011952aSMichael Chan } 1058a011952aSMichael Chan return 0; 1059a011952aSMichael Chan } 1060a011952aSMichael Chan 1061a011952aSMichael Chan #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3) 1062a011952aSMichael Chan #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST) 1063a011952aSMichael Chan 1064a011952aSMichael Chan static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1065a011952aSMichael Chan { 1066a011952aSMichael Chan u32 rss_hash_cfg = bp->rss_hash_cfg; 1067a011952aSMichael Chan int tuple, rc = 0; 1068a011952aSMichael Chan 1069a011952aSMichael Chan if (cmd->data == RXH_4TUPLE) 1070a011952aSMichael Chan tuple = 4; 1071a011952aSMichael Chan else if (cmd->data == RXH_2TUPLE) 1072a011952aSMichael Chan tuple = 2; 1073a011952aSMichael Chan else if (!cmd->data) 1074a011952aSMichael Chan tuple = 0; 1075a011952aSMichael Chan else 1076a011952aSMichael Chan return -EINVAL; 1077a011952aSMichael Chan 1078a011952aSMichael Chan if (cmd->flow_type == TCP_V4_FLOW) { 1079a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1080a011952aSMichael Chan if (tuple == 4) 1081a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1082a011952aSMichael Chan } else if (cmd->flow_type == UDP_V4_FLOW) { 1083a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1084a011952aSMichael Chan return -EINVAL; 1085a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1086a011952aSMichael Chan if (tuple == 4) 1087a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1088a011952aSMichael Chan } else if (cmd->flow_type == TCP_V6_FLOW) { 1089a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1090a011952aSMichael Chan if (tuple == 4) 1091a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1092a011952aSMichael Chan } else if (cmd->flow_type == UDP_V6_FLOW) { 1093a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1094a011952aSMichael Chan return -EINVAL; 1095a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1096a011952aSMichael Chan if (tuple == 4) 1097a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1098a011952aSMichael Chan } else if (tuple == 4) { 1099a011952aSMichael Chan return -EINVAL; 1100a011952aSMichael Chan } 1101a011952aSMichael Chan 1102a011952aSMichael Chan switch (cmd->flow_type) { 1103a011952aSMichael Chan case TCP_V4_FLOW: 1104a011952aSMichael Chan case UDP_V4_FLOW: 1105a011952aSMichael Chan case SCTP_V4_FLOW: 1106a011952aSMichael Chan case AH_ESP_V4_FLOW: 1107a011952aSMichael Chan case AH_V4_FLOW: 1108a011952aSMichael Chan case ESP_V4_FLOW: 1109a011952aSMichael Chan case IPV4_FLOW: 1110a011952aSMichael Chan if (tuple == 2) 1111a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1112a011952aSMichael Chan else if (!tuple) 1113a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1114a011952aSMichael Chan break; 1115a011952aSMichael Chan 1116a011952aSMichael Chan case TCP_V6_FLOW: 1117a011952aSMichael Chan case UDP_V6_FLOW: 1118a011952aSMichael Chan case SCTP_V6_FLOW: 1119a011952aSMichael Chan case AH_ESP_V6_FLOW: 1120a011952aSMichael Chan case AH_V6_FLOW: 1121a011952aSMichael Chan case ESP_V6_FLOW: 1122a011952aSMichael Chan case IPV6_FLOW: 1123a011952aSMichael Chan if (tuple == 2) 1124a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1125a011952aSMichael Chan else if (!tuple) 1126a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1127a011952aSMichael Chan break; 1128a011952aSMichael Chan } 1129a011952aSMichael Chan 1130a011952aSMichael Chan if (bp->rss_hash_cfg == rss_hash_cfg) 1131a011952aSMichael Chan return 0; 1132a011952aSMichael Chan 1133a011952aSMichael Chan bp->rss_hash_cfg = rss_hash_cfg; 1134a011952aSMichael Chan if (netif_running(bp->dev)) { 1135a011952aSMichael Chan bnxt_close_nic(bp, false, false); 1136a011952aSMichael Chan rc = bnxt_open_nic(bp, false, false); 1137a011952aSMichael Chan } 1138a011952aSMichael Chan return rc; 1139a011952aSMichael Chan } 1140c0c050c5SMichael Chan 1141c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 1142c0c050c5SMichael Chan u32 *rule_locs) 1143c0c050c5SMichael Chan { 1144c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1145c0c050c5SMichael Chan int rc = 0; 1146c0c050c5SMichael Chan 1147c0c050c5SMichael Chan switch (cmd->cmd) { 1148a011952aSMichael Chan #ifdef CONFIG_RFS_ACCEL 1149c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 1150c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 1151c0c050c5SMichael Chan break; 1152c0c050c5SMichael Chan 1153c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 1154c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 1155c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 1156c0c050c5SMichael Chan break; 1157c0c050c5SMichael Chan 1158c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 1159c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 1160c0c050c5SMichael Chan break; 1161c0c050c5SMichael Chan 1162c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 1163c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 1164c0c050c5SMichael Chan break; 1165a011952aSMichael Chan #endif 1166a011952aSMichael Chan 1167a011952aSMichael Chan case ETHTOOL_GRXFH: 1168a011952aSMichael Chan rc = bnxt_grxfh(bp, cmd); 1169a011952aSMichael Chan break; 1170c0c050c5SMichael Chan 1171c0c050c5SMichael Chan default: 1172c0c050c5SMichael Chan rc = -EOPNOTSUPP; 1173c0c050c5SMichael Chan break; 1174c0c050c5SMichael Chan } 1175c0c050c5SMichael Chan 1176c0c050c5SMichael Chan return rc; 1177c0c050c5SMichael Chan } 1178a011952aSMichael Chan 1179a011952aSMichael Chan static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) 1180a011952aSMichael Chan { 1181a011952aSMichael Chan struct bnxt *bp = netdev_priv(dev); 1182a011952aSMichael Chan int rc; 1183a011952aSMichael Chan 1184a011952aSMichael Chan switch (cmd->cmd) { 1185a011952aSMichael Chan case ETHTOOL_SRXFH: 1186a011952aSMichael Chan rc = bnxt_srxfh(bp, cmd); 1187a011952aSMichael Chan break; 1188a011952aSMichael Chan 1189a011952aSMichael Chan default: 1190a011952aSMichael Chan rc = -EOPNOTSUPP; 1191a011952aSMichael Chan break; 1192a011952aSMichael Chan } 1193a011952aSMichael Chan return rc; 1194a011952aSMichael Chan } 1195c0c050c5SMichael Chan 1196c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 1197c0c050c5SMichael Chan { 1198c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 1199c0c050c5SMichael Chan } 1200c0c050c5SMichael Chan 1201c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 1202c0c050c5SMichael Chan { 1203c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 1204c0c050c5SMichael Chan } 1205c0c050c5SMichael Chan 1206c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 1207c0c050c5SMichael Chan u8 *hfunc) 1208c0c050c5SMichael Chan { 1209c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 12107991cb9cSMichael Chan struct bnxt_vnic_info *vnic; 1211c0c050c5SMichael Chan int i = 0; 1212c0c050c5SMichael Chan 1213c0c050c5SMichael Chan if (hfunc) 1214c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 1215c0c050c5SMichael Chan 12167991cb9cSMichael Chan if (!bp->vnic_info) 12177991cb9cSMichael Chan return 0; 12187991cb9cSMichael Chan 12197991cb9cSMichael Chan vnic = &bp->vnic_info[0]; 12207991cb9cSMichael Chan if (indir && vnic->rss_table) { 1221c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 1222c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 12237991cb9cSMichael Chan } 1224c0c050c5SMichael Chan 12257991cb9cSMichael Chan if (key && vnic->rss_hash_key) 1226c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 1227c0c050c5SMichael Chan 1228c0c050c5SMichael Chan return 0; 1229c0c050c5SMichael Chan } 1230c0c050c5SMichael Chan 1231c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 1232c0c050c5SMichael Chan struct ethtool_drvinfo *info) 1233c0c050c5SMichael Chan { 1234c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1235c0c050c5SMichael Chan 1236c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 1237c0c050c5SMichael Chan strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 1238431aa1ebSMichael Chan strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); 1239c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 12405c8227d0SMichael Chan info->n_stats = bnxt_get_num_stats(bp); 1241eb513658SMichael Chan info->testinfo_len = bp->num_tests; 1242c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 1243c0c050c5SMichael Chan info->eedump_len = 0; 1244c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 1245c0c050c5SMichael Chan info->regdump_len = 0; 1246c0c050c5SMichael Chan } 1247c0c050c5SMichael Chan 12488e202366SMichael Chan static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 12498e202366SMichael Chan { 12508e202366SMichael Chan struct bnxt *bp = netdev_priv(dev); 12518e202366SMichael Chan 12528e202366SMichael Chan wol->supported = 0; 12538e202366SMichael Chan wol->wolopts = 0; 12548e202366SMichael Chan memset(&wol->sopass, 0, sizeof(wol->sopass)); 12558e202366SMichael Chan if (bp->flags & BNXT_FLAG_WOL_CAP) { 12568e202366SMichael Chan wol->supported = WAKE_MAGIC; 12578e202366SMichael Chan if (bp->wol) 12588e202366SMichael Chan wol->wolopts = WAKE_MAGIC; 12598e202366SMichael Chan } 12608e202366SMichael Chan } 12618e202366SMichael Chan 12625282db6cSMichael Chan static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 12635282db6cSMichael Chan { 12645282db6cSMichael Chan struct bnxt *bp = netdev_priv(dev); 12655282db6cSMichael Chan 12665282db6cSMichael Chan if (wol->wolopts & ~WAKE_MAGIC) 12675282db6cSMichael Chan return -EINVAL; 12685282db6cSMichael Chan 12695282db6cSMichael Chan if (wol->wolopts & WAKE_MAGIC) { 12705282db6cSMichael Chan if (!(bp->flags & BNXT_FLAG_WOL_CAP)) 12715282db6cSMichael Chan return -EINVAL; 12725282db6cSMichael Chan if (!bp->wol) { 12735282db6cSMichael Chan if (bnxt_hwrm_alloc_wol_fltr(bp)) 12745282db6cSMichael Chan return -EBUSY; 12755282db6cSMichael Chan bp->wol = 1; 12765282db6cSMichael Chan } 12775282db6cSMichael Chan } else { 12785282db6cSMichael Chan if (bp->wol) { 12795282db6cSMichael Chan if (bnxt_hwrm_free_wol_fltr(bp)) 12805282db6cSMichael Chan return -EBUSY; 12815282db6cSMichael Chan bp->wol = 0; 12825282db6cSMichael Chan } 12835282db6cSMichael Chan } 12845282db6cSMichael Chan return 0; 12855282db6cSMichael Chan } 12865282db6cSMichael Chan 1287170ce013SMichael Chan u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause) 1288c0c050c5SMichael Chan { 1289c0c050c5SMichael Chan u32 speed_mask = 0; 1290c0c050c5SMichael Chan 1291c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 1292c0c050c5SMichael Chan /* set the advertised speeds */ 1293c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 1294c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 1295c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 1296c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 1297c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 1298c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 1299c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 1300c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 1301c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 13021c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 130327c4d578SMichael Chan 130427c4d578SMichael Chan if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH) 130527c4d578SMichael Chan speed_mask |= ADVERTISED_Pause; 130627c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_TX) 130727c4d578SMichael Chan speed_mask |= ADVERTISED_Asym_Pause; 130827c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_RX) 130927c4d578SMichael Chan speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 131027c4d578SMichael Chan 1311c0c050c5SMichael Chan return speed_mask; 1312c0c050c5SMichael Chan } 1313c0c050c5SMichael Chan 131400c04a92SMichael Chan #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\ 131500c04a92SMichael Chan { \ 131600c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \ 131700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 131800c04a92SMichael Chan 100baseT_Full); \ 131900c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \ 132000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 132100c04a92SMichael Chan 1000baseT_Full); \ 132200c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \ 132300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 132400c04a92SMichael Chan 10000baseT_Full); \ 132500c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \ 132600c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 132700c04a92SMichael Chan 25000baseCR_Full); \ 132800c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \ 132900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 133000c04a92SMichael Chan 40000baseCR4_Full);\ 133100c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \ 133200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 133300c04a92SMichael Chan 50000baseCR2_Full);\ 133438a21b34SDeepak Khungar if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \ 133538a21b34SDeepak Khungar ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 133638a21b34SDeepak Khungar 100000baseCR4_Full);\ 133700c04a92SMichael Chan if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \ 133800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 133900c04a92SMichael Chan Pause); \ 134000c04a92SMichael Chan if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \ 134100c04a92SMichael Chan ethtool_link_ksettings_add_link_mode( \ 134200c04a92SMichael Chan lk_ksettings, name, Asym_Pause);\ 134300c04a92SMichael Chan } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \ 134400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 134500c04a92SMichael Chan Asym_Pause); \ 134600c04a92SMichael Chan } \ 134700c04a92SMichael Chan } 134800c04a92SMichael Chan 134900c04a92SMichael Chan #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \ 135000c04a92SMichael Chan { \ 135100c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135200c04a92SMichael Chan 100baseT_Full) || \ 135300c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135400c04a92SMichael Chan 100baseT_Half)) \ 135500c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \ 135600c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135700c04a92SMichael Chan 1000baseT_Full) || \ 135800c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135900c04a92SMichael Chan 1000baseT_Half)) \ 136000c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \ 136100c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 136200c04a92SMichael Chan 10000baseT_Full)) \ 136300c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \ 136400c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 136500c04a92SMichael Chan 25000baseCR_Full)) \ 136600c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \ 136700c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 136800c04a92SMichael Chan 40000baseCR4_Full)) \ 136900c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \ 137000c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 137100c04a92SMichael Chan 50000baseCR2_Full)) \ 137200c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \ 137338a21b34SDeepak Khungar if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 137438a21b34SDeepak Khungar 100000baseCR4_Full)) \ 137538a21b34SDeepak Khungar (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \ 137600c04a92SMichael Chan } 137700c04a92SMichael Chan 137800c04a92SMichael Chan static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info, 137900c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 138027c4d578SMichael Chan { 138168515a18SMichael Chan u16 fw_speeds = link_info->advertising; 138227c4d578SMichael Chan u8 fw_pause = 0; 138327c4d578SMichael Chan 138427c4d578SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 138527c4d578SMichael Chan fw_pause = link_info->auto_pause_setting; 138627c4d578SMichael Chan 138700c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising); 138827c4d578SMichael Chan } 138927c4d578SMichael Chan 139000c04a92SMichael Chan static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info, 139100c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 13923277360eSMichael Chan { 13933277360eSMichael Chan u16 fw_speeds = link_info->lp_auto_link_speeds; 13943277360eSMichael Chan u8 fw_pause = 0; 13953277360eSMichael Chan 13963277360eSMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 13973277360eSMichael Chan fw_pause = link_info->lp_pause; 13983277360eSMichael Chan 139900c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, 140000c04a92SMichael Chan lp_advertising); 14013277360eSMichael Chan } 14023277360eSMichael Chan 140300c04a92SMichael Chan static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info, 140400c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 14054b32caccSMichael Chan { 14064b32caccSMichael Chan u16 fw_speeds = link_info->support_speeds; 14074b32caccSMichael Chan 140800c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported); 14094b32caccSMichael Chan 141000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause); 141100c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 141200c04a92SMichael Chan Asym_Pause); 141393ed8117SMichael Chan 141400c04a92SMichael Chan if (link_info->support_auto_speeds) 141500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 141600c04a92SMichael Chan Autoneg); 141793ed8117SMichael Chan } 141893ed8117SMichael Chan 1419c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 1420c0c050c5SMichael Chan { 1421c0c050c5SMichael Chan switch (fw_link_speed) { 1422c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 1423c0c050c5SMichael Chan return SPEED_100; 1424c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 1425c0c050c5SMichael Chan return SPEED_1000; 1426c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 1427c0c050c5SMichael Chan return SPEED_2500; 1428c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 1429c0c050c5SMichael Chan return SPEED_10000; 1430c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 1431c0c050c5SMichael Chan return SPEED_20000; 1432c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 1433c0c050c5SMichael Chan return SPEED_25000; 1434c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 1435c0c050c5SMichael Chan return SPEED_40000; 1436c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 1437c0c050c5SMichael Chan return SPEED_50000; 143838a21b34SDeepak Khungar case BNXT_LINK_SPEED_100GB: 143938a21b34SDeepak Khungar return SPEED_100000; 1440c0c050c5SMichael Chan default: 1441c0c050c5SMichael Chan return SPEED_UNKNOWN; 1442c0c050c5SMichael Chan } 1443c0c050c5SMichael Chan } 1444c0c050c5SMichael Chan 144500c04a92SMichael Chan static int bnxt_get_link_ksettings(struct net_device *dev, 144600c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 1447c0c050c5SMichael Chan { 1448c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1449c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 145000c04a92SMichael Chan struct ethtool_link_settings *base = &lk_ksettings->base; 145100c04a92SMichael Chan u32 ethtool_speed; 1452c0c050c5SMichael Chan 145300c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported); 1454e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 145500c04a92SMichael Chan bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings); 1456c0c050c5SMichael Chan 145700c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising); 1458b763499eSMichael Chan if (link_info->autoneg) { 145900c04a92SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings); 146000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, 146100c04a92SMichael Chan advertising, Autoneg); 146200c04a92SMichael Chan base->autoneg = AUTONEG_ENABLE; 14633277360eSMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) 146400c04a92SMichael Chan bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings); 146529c262feSMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 146629c262feSMichael Chan if (!netif_carrier_ok(dev)) 146700c04a92SMichael Chan base->duplex = DUPLEX_UNKNOWN; 146829c262feSMichael Chan else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 146900c04a92SMichael Chan base->duplex = DUPLEX_FULL; 147029c262feSMichael Chan else 147100c04a92SMichael Chan base->duplex = DUPLEX_HALF; 1472c0c050c5SMichael Chan } else { 147300c04a92SMichael Chan base->autoneg = AUTONEG_DISABLE; 147429c262feSMichael Chan ethtool_speed = 147529c262feSMichael Chan bnxt_fw_to_ethtool_speed(link_info->req_link_speed); 147600c04a92SMichael Chan base->duplex = DUPLEX_HALF; 147729c262feSMichael Chan if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL) 147800c04a92SMichael Chan base->duplex = DUPLEX_FULL; 1479c0c050c5SMichael Chan } 148000c04a92SMichael Chan base->speed = ethtool_speed; 1481c0c050c5SMichael Chan 148200c04a92SMichael Chan base->port = PORT_NONE; 1483c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 148400c04a92SMichael Chan base->port = PORT_TP; 148500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 148600c04a92SMichael Chan TP); 148700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 148800c04a92SMichael Chan TP); 1489c0c050c5SMichael Chan } else { 149000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 149100c04a92SMichael Chan FIBRE); 149200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 149300c04a92SMichael Chan FIBRE); 1494c0c050c5SMichael Chan 1495c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 149600c04a92SMichael Chan base->port = PORT_DA; 1497c0c050c5SMichael Chan else if (link_info->media_type == 1498c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 149900c04a92SMichael Chan base->port = PORT_FIBRE; 1500c0c050c5SMichael Chan } 150100c04a92SMichael Chan base->phy_address = link_info->phy_addr; 1502e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1503c0c050c5SMichael Chan 1504c0c050c5SMichael Chan return 0; 1505c0c050c5SMichael Chan } 1506c0c050c5SMichael Chan 150738a21b34SDeepak Khungar static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed) 1508c0c050c5SMichael Chan { 15099d9cee08SMichael Chan struct bnxt *bp = netdev_priv(dev); 15109d9cee08SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 15119d9cee08SMichael Chan u16 support_spds = link_info->support_speeds; 15129d9cee08SMichael Chan u32 fw_speed = 0; 15139d9cee08SMichael Chan 1514c0c050c5SMichael Chan switch (ethtool_speed) { 1515c0c050c5SMichael Chan case SPEED_100: 15169d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_100MB) 15179d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 15189d9cee08SMichael Chan break; 1519c0c050c5SMichael Chan case SPEED_1000: 15209d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_1GB) 15219d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 15229d9cee08SMichael Chan break; 1523c0c050c5SMichael Chan case SPEED_2500: 15249d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB) 15259d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 15269d9cee08SMichael Chan break; 1527c0c050c5SMichael Chan case SPEED_10000: 15289d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_10GB) 15299d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 15309d9cee08SMichael Chan break; 1531c0c050c5SMichael Chan case SPEED_20000: 15329d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_20GB) 15339d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 15349d9cee08SMichael Chan break; 1535c0c050c5SMichael Chan case SPEED_25000: 15369d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_25GB) 15379d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 15389d9cee08SMichael Chan break; 1539c0c050c5SMichael Chan case SPEED_40000: 15409d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_40GB) 15419d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 15429d9cee08SMichael Chan break; 1543c0c050c5SMichael Chan case SPEED_50000: 15449d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_50GB) 15459d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 15469d9cee08SMichael Chan break; 154738a21b34SDeepak Khungar case SPEED_100000: 154838a21b34SDeepak Khungar if (support_spds & BNXT_LINK_SPEED_MSK_100GB) 154938a21b34SDeepak Khungar fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB; 155038a21b34SDeepak Khungar break; 1551c0c050c5SMichael Chan default: 1552c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 1553c0c050c5SMichael Chan break; 1554c0c050c5SMichael Chan } 15559d9cee08SMichael Chan return fw_speed; 1556c0c050c5SMichael Chan } 1557c0c050c5SMichael Chan 1558939f7f0cSMichael Chan u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 1559c0c050c5SMichael Chan { 1560c0c050c5SMichael Chan u16 fw_speed_mask = 0; 1561c0c050c5SMichael Chan 1562c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 1563c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 1564c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 1565c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 1566c0c050c5SMichael Chan } 1567c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 1568c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 1569c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 1570c0c050c5SMichael Chan } 1571c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 1572c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 1573c0c050c5SMichael Chan 15741c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 15751c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 15761c49c421SMichael Chan 1577c0c050c5SMichael Chan return fw_speed_mask; 1578c0c050c5SMichael Chan } 1579c0c050c5SMichael Chan 158000c04a92SMichael Chan static int bnxt_set_link_ksettings(struct net_device *dev, 158100c04a92SMichael Chan const struct ethtool_link_ksettings *lk_ksettings) 1582c0c050c5SMichael Chan { 1583c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1584c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 158500c04a92SMichael Chan const struct ethtool_link_settings *base = &lk_ksettings->base; 1586c0c050c5SMichael Chan bool set_pause = false; 158768515a18SMichael Chan u16 fw_advertising = 0; 158868515a18SMichael Chan u32 speed; 158900c04a92SMichael Chan int rc = 0; 1590c0c050c5SMichael Chan 1591567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 159200c04a92SMichael Chan return -EOPNOTSUPP; 1593c0c050c5SMichael Chan 1594e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 159500c04a92SMichael Chan if (base->autoneg == AUTONEG_ENABLE) { 159600c04a92SMichael Chan BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings, 159700c04a92SMichael Chan advertising); 1598c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 1599c0c050c5SMichael Chan if (!fw_advertising) 160093ed8117SMichael Chan link_info->advertising = link_info->support_auto_speeds; 1601c0c050c5SMichael Chan else 1602c0c050c5SMichael Chan link_info->advertising = fw_advertising; 1603c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 1604c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 1605c0c050c5SMichael Chan */ 1606c0c050c5SMichael Chan set_pause = true; 1607c0c050c5SMichael Chan } else { 16089d9cee08SMichael Chan u16 fw_speed; 160903efbec0SMichael Chan u8 phy_type = link_info->phy_type; 16109d9cee08SMichael Chan 161103efbec0SMichael Chan if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET || 161203efbec0SMichael Chan phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE || 161303efbec0SMichael Chan link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 161403efbec0SMichael Chan netdev_err(dev, "10GBase-T devices must autoneg\n"); 161503efbec0SMichael Chan rc = -EINVAL; 161603efbec0SMichael Chan goto set_setting_exit; 161703efbec0SMichael Chan } 161800c04a92SMichael Chan if (base->duplex == DUPLEX_HALF) { 1619c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 1620c0c050c5SMichael Chan rc = -EINVAL; 1621c0c050c5SMichael Chan goto set_setting_exit; 1622c0c050c5SMichael Chan } 162300c04a92SMichael Chan speed = base->speed; 16249d9cee08SMichael Chan fw_speed = bnxt_get_fw_speed(dev, speed); 16259d9cee08SMichael Chan if (!fw_speed) { 16269d9cee08SMichael Chan rc = -EINVAL; 16279d9cee08SMichael Chan goto set_setting_exit; 16289d9cee08SMichael Chan } 16299d9cee08SMichael Chan link_info->req_link_speed = fw_speed; 1630c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 1631b763499eSMichael Chan link_info->autoneg = 0; 1632c0c050c5SMichael Chan link_info->advertising = 0; 1633c0c050c5SMichael Chan } 1634c0c050c5SMichael Chan 1635c0c050c5SMichael Chan if (netif_running(dev)) 1636939f7f0cSMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause, false); 1637c0c050c5SMichael Chan 1638c0c050c5SMichael Chan set_setting_exit: 1639e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1640c0c050c5SMichael Chan return rc; 1641c0c050c5SMichael Chan } 1642c0c050c5SMichael Chan 1643c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 1644c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1645c0c050c5SMichael Chan { 1646c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1647c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1648c0c050c5SMichael Chan 1649c0c050c5SMichael Chan if (BNXT_VF(bp)) 1650c0c050c5SMichael Chan return; 1651b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 16523c02d1bbSMichael Chan epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX); 16533c02d1bbSMichael Chan epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX); 1654c0c050c5SMichael Chan } 1655c0c050c5SMichael Chan 1656c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 1657c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1658c0c050c5SMichael Chan { 1659c0c050c5SMichael Chan int rc = 0; 1660c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1661c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1662c0c050c5SMichael Chan 1663567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 166475362a3fSMichael Chan return -EOPNOTSUPP; 1665c0c050c5SMichael Chan 1666c0c050c5SMichael Chan if (epause->autoneg) { 1667b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 1668b763499eSMichael Chan return -EINVAL; 1669b763499eSMichael Chan 1670c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 1671c9ee9516SMichael Chan if (bp->hwrm_spec_code >= 0x10201) 1672c9ee9516SMichael Chan link_info->req_flow_ctrl = 1673c9ee9516SMichael Chan PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; 1674c0c050c5SMichael Chan } else { 1675c0c050c5SMichael Chan /* when transition from auto pause to force pause, 1676c0c050c5SMichael Chan * force a link change 1677c0c050c5SMichael Chan */ 1678c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 1679c0c050c5SMichael Chan link_info->force_link_chng = true; 1680c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 1681c9ee9516SMichael Chan link_info->req_flow_ctrl = 0; 1682c0c050c5SMichael Chan } 1683c0c050c5SMichael Chan if (epause->rx_pause) 1684c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 1685c0c050c5SMichael Chan 1686c0c050c5SMichael Chan if (epause->tx_pause) 1687c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 1688c0c050c5SMichael Chan 1689c0c050c5SMichael Chan if (netif_running(dev)) 1690c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 1691c0c050c5SMichael Chan return rc; 1692c0c050c5SMichael Chan } 1693c0c050c5SMichael Chan 1694c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 1695c0c050c5SMichael Chan { 1696c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1697c0c050c5SMichael Chan 1698c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 1699c0c050c5SMichael Chan return bp->link_info.link_up; 1700c0c050c5SMichael Chan } 1701c0c050c5SMichael Chan 1702b3b0ddd0SMichael Chan static void bnxt_print_admin_err(struct bnxt *bp) 1703b3b0ddd0SMichael Chan { 1704b3b0ddd0SMichael Chan netdev_info(bp->dev, "PF does not have admin privileges to flash or reset the device\n"); 1705b3b0ddd0SMichael Chan } 1706b3b0ddd0SMichael Chan 17075ac67d8bSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 17085ac67d8bSRob Swindell u16 ext, u16 *index, u32 *item_length, 17095ac67d8bSRob Swindell u32 *data_length); 17105ac67d8bSRob Swindell 1711c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 1712c0c050c5SMichael Chan u16 dir_type, 1713c0c050c5SMichael Chan u16 dir_ordinal, 1714c0c050c5SMichael Chan u16 dir_ext, 1715c0c050c5SMichael Chan u16 dir_attr, 1716c0c050c5SMichael Chan const u8 *data, 1717c0c050c5SMichael Chan size_t data_len) 1718c0c050c5SMichael Chan { 1719c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1720c0c050c5SMichael Chan int rc; 1721c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 1722c0c050c5SMichael Chan dma_addr_t dma_handle; 1723c0c050c5SMichael Chan u8 *kmem; 1724c0c050c5SMichael Chan 1725c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 1726c0c050c5SMichael Chan 1727c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 1728c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 1729c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 1730c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 1731c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 1732c0c050c5SMichael Chan 1733c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 1734c0c050c5SMichael Chan GFP_KERNEL); 1735c0c050c5SMichael Chan if (!kmem) { 1736c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1737c0c050c5SMichael Chan (unsigned)data_len); 1738c0c050c5SMichael Chan return -ENOMEM; 1739c0c050c5SMichael Chan } 1740c0c050c5SMichael Chan memcpy(kmem, data, data_len); 1741c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 1742c0c050c5SMichael Chan 1743c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 1744c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 1745c0c050c5SMichael Chan 1746d4f1420dSMichael Chan if (rc == -EACCES) 1747b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 1748c0c050c5SMichael Chan return rc; 1749c0c050c5SMichael Chan } 1750c0c050c5SMichael Chan 1751d2d6318cSRob Swindell static int bnxt_firmware_reset(struct net_device *dev, 1752d2d6318cSRob Swindell u16 dir_type) 1753d2d6318cSRob Swindell { 1754d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 17557c675421SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 17567c675421SVasundhara Volam int rc; 1757d2d6318cSRob Swindell 1758d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 1759d2d6318cSRob Swindell 1760d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 1761d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 1762d2d6318cSRob Swindell switch (dir_type) { 1763d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 1764d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 1765d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 1766d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 1767d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 1768d2d6318cSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1769d2d6318cSRob Swindell break; 1770d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 1771d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 1772d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 177308141e0bSRob Swindell /* Self-reset APE upon next PCIe reset: */ 177408141e0bSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1775d2d6318cSRob Swindell break; 1776d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 1777d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 1778d2d6318cSRob Swindell req.embedded_proc_type = 1779d2d6318cSRob Swindell FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 1780d2d6318cSRob Swindell break; 1781d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 1782d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1783d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 1784d2d6318cSRob Swindell break; 178549f7972fSVasundhara Volam case BNXT_FW_RESET_CHIP: 178649f7972fSVasundhara Volam req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP; 178749f7972fSVasundhara Volam req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP; 178849f7972fSVasundhara Volam break; 17896502ad59SScott Branden case BNXT_FW_RESET_AP: 17906502ad59SScott Branden req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP; 17916502ad59SScott Branden break; 1792d2d6318cSRob Swindell default: 1793d2d6318cSRob Swindell return -EINVAL; 1794d2d6318cSRob Swindell } 1795d2d6318cSRob Swindell 17967c675421SVasundhara Volam rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1797d4f1420dSMichael Chan if (rc == -EACCES) 1798b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 17997c675421SVasundhara Volam return rc; 1800d2d6318cSRob Swindell } 1801d2d6318cSRob Swindell 1802c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 1803c0c050c5SMichael Chan u16 dir_type, 1804c0c050c5SMichael Chan const u8 *fw_data, 1805c0c050c5SMichael Chan size_t fw_size) 1806c0c050c5SMichael Chan { 1807c0c050c5SMichael Chan int rc = 0; 1808c0c050c5SMichael Chan u16 code_type; 1809c0c050c5SMichael Chan u32 stored_crc; 1810c0c050c5SMichael Chan u32 calculated_crc; 1811c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 1812c0c050c5SMichael Chan 1813c0c050c5SMichael Chan switch (dir_type) { 1814c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1815c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1816c0c050c5SMichael Chan code_type = CODE_BOOT; 1817c0c050c5SMichael Chan break; 181893e0b4feSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 181993e0b4feSRob Swindell code_type = CODE_CHIMP_PATCH; 182093e0b4feSRob Swindell break; 18212731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 18222731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 18232731d70fSRob Swindell break; 182493e0b4feSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 182593e0b4feSRob Swindell code_type = CODE_APE_PATCH; 182693e0b4feSRob Swindell break; 182793e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_FW: 182893e0b4feSRob Swindell code_type = CODE_KONG_FW; 182993e0b4feSRob Swindell break; 183093e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 183193e0b4feSRob Swindell code_type = CODE_KONG_PATCH; 183293e0b4feSRob Swindell break; 183393e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 183493e0b4feSRob Swindell code_type = CODE_BONO_FW; 183593e0b4feSRob Swindell break; 183693e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 183793e0b4feSRob Swindell code_type = CODE_BONO_PATCH; 183893e0b4feSRob Swindell break; 1839c0c050c5SMichael Chan default: 1840c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 1841c0c050c5SMichael Chan dir_type); 1842c0c050c5SMichael Chan return -EINVAL; 1843c0c050c5SMichael Chan } 1844c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 1845c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 1846c0c050c5SMichael Chan (unsigned int)fw_size); 1847c0c050c5SMichael Chan return -EINVAL; 1848c0c050c5SMichael Chan } 1849c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 1850c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 1851c0c050c5SMichael Chan le32_to_cpu(header->signature)); 1852c0c050c5SMichael Chan return -EINVAL; 1853c0c050c5SMichael Chan } 1854c0c050c5SMichael Chan if (header->code_type != code_type) { 1855c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 1856c0c050c5SMichael Chan code_type, header->code_type); 1857c0c050c5SMichael Chan return -EINVAL; 1858c0c050c5SMichael Chan } 1859c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 1860c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 1861c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 1862c0c050c5SMichael Chan return -EINVAL; 1863c0c050c5SMichael Chan } 1864c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 1865c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 1866c0c050c5SMichael Chan sizeof(stored_crc))); 1867c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 1868c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 1869c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 1870c0c050c5SMichael Chan (unsigned long)stored_crc, 1871c0c050c5SMichael Chan (unsigned long)calculated_crc); 1872c0c050c5SMichael Chan return -EINVAL; 1873c0c050c5SMichael Chan } 1874c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1875c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 1876d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 1877d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 1878d2d6318cSRob Swindell 1879c0c050c5SMichael Chan return rc; 1880c0c050c5SMichael Chan } 1881c0c050c5SMichael Chan 18825ac67d8bSRob Swindell static int bnxt_flash_microcode(struct net_device *dev, 18835ac67d8bSRob Swindell u16 dir_type, 18845ac67d8bSRob Swindell const u8 *fw_data, 18855ac67d8bSRob Swindell size_t fw_size) 18865ac67d8bSRob Swindell { 18875ac67d8bSRob Swindell struct bnxt_ucode_trailer *trailer; 18885ac67d8bSRob Swindell u32 calculated_crc; 18895ac67d8bSRob Swindell u32 stored_crc; 18905ac67d8bSRob Swindell int rc = 0; 18915ac67d8bSRob Swindell 18925ac67d8bSRob Swindell if (fw_size < sizeof(struct bnxt_ucode_trailer)) { 18935ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode file size: %u\n", 18945ac67d8bSRob Swindell (unsigned int)fw_size); 18955ac67d8bSRob Swindell return -EINVAL; 18965ac67d8bSRob Swindell } 18975ac67d8bSRob Swindell trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size - 18985ac67d8bSRob Swindell sizeof(*trailer))); 18995ac67d8bSRob Swindell if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) { 19005ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer signature: %08X\n", 19015ac67d8bSRob Swindell le32_to_cpu(trailer->sig)); 19025ac67d8bSRob Swindell return -EINVAL; 19035ac67d8bSRob Swindell } 19045ac67d8bSRob Swindell if (le16_to_cpu(trailer->dir_type) != dir_type) { 19055ac67d8bSRob Swindell netdev_err(dev, "Expected microcode type: %d, read: %d\n", 19065ac67d8bSRob Swindell dir_type, le16_to_cpu(trailer->dir_type)); 19075ac67d8bSRob Swindell return -EINVAL; 19085ac67d8bSRob Swindell } 19095ac67d8bSRob Swindell if (le16_to_cpu(trailer->trailer_length) < 19105ac67d8bSRob Swindell sizeof(struct bnxt_ucode_trailer)) { 19115ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer length: %d\n", 19125ac67d8bSRob Swindell le16_to_cpu(trailer->trailer_length)); 19135ac67d8bSRob Swindell return -EINVAL; 19145ac67d8bSRob Swindell } 19155ac67d8bSRob Swindell 19165ac67d8bSRob Swindell /* Confirm the CRC32 checksum of the file: */ 19175ac67d8bSRob Swindell stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 19185ac67d8bSRob Swindell sizeof(stored_crc))); 19195ac67d8bSRob Swindell calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 19205ac67d8bSRob Swindell if (calculated_crc != stored_crc) { 19215ac67d8bSRob Swindell netdev_err(dev, 19225ac67d8bSRob Swindell "CRC32 (%08lX) does not match calculated: %08lX\n", 19235ac67d8bSRob Swindell (unsigned long)stored_crc, 19245ac67d8bSRob Swindell (unsigned long)calculated_crc); 19255ac67d8bSRob Swindell return -EINVAL; 19265ac67d8bSRob Swindell } 19275ac67d8bSRob Swindell rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 19285ac67d8bSRob Swindell 0, 0, fw_data, fw_size); 19295ac67d8bSRob Swindell 19305ac67d8bSRob Swindell return rc; 19315ac67d8bSRob Swindell } 19325ac67d8bSRob Swindell 1933c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 1934c0c050c5SMichael Chan { 1935c0c050c5SMichael Chan switch (dir_type) { 1936c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 1937c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1938c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1939c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 1940c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 1941c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 1942c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 194393e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 194493e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1945c0c050c5SMichael Chan return true; 1946c0c050c5SMichael Chan } 1947c0c050c5SMichael Chan 1948c0c050c5SMichael Chan return false; 1949c0c050c5SMichael Chan } 1950c0c050c5SMichael Chan 19515ac67d8bSRob Swindell static bool bnxt_dir_type_is_other_exec_format(u16 dir_type) 1952c0c050c5SMichael Chan { 1953c0c050c5SMichael Chan switch (dir_type) { 1954c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 1955c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 1956c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 1957c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 1958c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 1959c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 1960c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 1961c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 1962c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 1963c0c050c5SMichael Chan return true; 1964c0c050c5SMichael Chan } 1965c0c050c5SMichael Chan 1966c0c050c5SMichael Chan return false; 1967c0c050c5SMichael Chan } 1968c0c050c5SMichael Chan 1969c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 1970c0c050c5SMichael Chan { 1971c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 19725ac67d8bSRob Swindell bnxt_dir_type_is_other_exec_format(dir_type); 1973c0c050c5SMichael Chan } 1974c0c050c5SMichael Chan 1975c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 1976c0c050c5SMichael Chan u16 dir_type, 1977c0c050c5SMichael Chan const char *filename) 1978c0c050c5SMichael Chan { 1979c0c050c5SMichael Chan const struct firmware *fw; 1980c0c050c5SMichael Chan int rc; 1981c0c050c5SMichael Chan 1982c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 1983c0c050c5SMichael Chan if (rc != 0) { 1984c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 1985c0c050c5SMichael Chan rc, filename); 1986c0c050c5SMichael Chan return rc; 1987c0c050c5SMichael Chan } 1988c0c050c5SMichael Chan if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) 1989c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 19905ac67d8bSRob Swindell else if (bnxt_dir_type_is_other_exec_format(dir_type) == true) 19915ac67d8bSRob Swindell rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size); 1992c0c050c5SMichael Chan else 1993c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1994c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 1995c0c050c5SMichael Chan release_firmware(fw); 1996c0c050c5SMichael Chan return rc; 1997c0c050c5SMichael Chan } 1998c0c050c5SMichael Chan 1999c0c050c5SMichael Chan static int bnxt_flash_package_from_file(struct net_device *dev, 20005ac67d8bSRob Swindell char *filename, u32 install_type) 2001c0c050c5SMichael Chan { 20025ac67d8bSRob Swindell struct bnxt *bp = netdev_priv(dev); 20035ac67d8bSRob Swindell struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr; 20045ac67d8bSRob Swindell struct hwrm_nvm_install_update_input install = {0}; 20055ac67d8bSRob Swindell const struct firmware *fw; 20067c675421SVasundhara Volam int rc, hwrm_err = 0; 20075ac67d8bSRob Swindell u32 item_len; 20085ac67d8bSRob Swindell u16 index; 20095ac67d8bSRob Swindell 20105ac67d8bSRob Swindell bnxt_hwrm_fw_set_time(bp); 20115ac67d8bSRob Swindell 20125ac67d8bSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE, 20135ac67d8bSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 20145ac67d8bSRob Swindell &index, &item_len, NULL) != 0) { 20155ac67d8bSRob Swindell netdev_err(dev, "PKG update area not created in nvram\n"); 20165ac67d8bSRob Swindell return -ENOBUFS; 20175ac67d8bSRob Swindell } 20185ac67d8bSRob Swindell 20195ac67d8bSRob Swindell rc = request_firmware(&fw, filename, &dev->dev); 20205ac67d8bSRob Swindell if (rc != 0) { 20215ac67d8bSRob Swindell netdev_err(dev, "PKG error %d requesting file: %s\n", 20225ac67d8bSRob Swindell rc, filename); 20235ac67d8bSRob Swindell return rc; 20245ac67d8bSRob Swindell } 20255ac67d8bSRob Swindell 20265ac67d8bSRob Swindell if (fw->size > item_len) { 20275ac67d8bSRob Swindell netdev_err(dev, "PKG insufficient update area in nvram: %lu", 20285ac67d8bSRob Swindell (unsigned long)fw->size); 20295ac67d8bSRob Swindell rc = -EFBIG; 20305ac67d8bSRob Swindell } else { 20315ac67d8bSRob Swindell dma_addr_t dma_handle; 20325ac67d8bSRob Swindell u8 *kmem; 20335ac67d8bSRob Swindell struct hwrm_nvm_modify_input modify = {0}; 20345ac67d8bSRob Swindell 20355ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1); 20365ac67d8bSRob Swindell 20375ac67d8bSRob Swindell modify.dir_idx = cpu_to_le16(index); 20385ac67d8bSRob Swindell modify.len = cpu_to_le32(fw->size); 20395ac67d8bSRob Swindell 20405ac67d8bSRob Swindell kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size, 20415ac67d8bSRob Swindell &dma_handle, GFP_KERNEL); 20425ac67d8bSRob Swindell if (!kmem) { 20435ac67d8bSRob Swindell netdev_err(dev, 20445ac67d8bSRob Swindell "dma_alloc_coherent failure, length = %u\n", 20455ac67d8bSRob Swindell (unsigned int)fw->size); 20465ac67d8bSRob Swindell rc = -ENOMEM; 20475ac67d8bSRob Swindell } else { 20485ac67d8bSRob Swindell memcpy(kmem, fw->data, fw->size); 20495ac67d8bSRob Swindell modify.host_src_addr = cpu_to_le64(dma_handle); 20505ac67d8bSRob Swindell 20517c675421SVasundhara Volam hwrm_err = hwrm_send_message(bp, &modify, 20527c675421SVasundhara Volam sizeof(modify), 20535ac67d8bSRob Swindell FLASH_PACKAGE_TIMEOUT); 20545ac67d8bSRob Swindell dma_free_coherent(&bp->pdev->dev, fw->size, kmem, 20555ac67d8bSRob Swindell dma_handle); 20565ac67d8bSRob Swindell } 20575ac67d8bSRob Swindell } 20585ac67d8bSRob Swindell release_firmware(fw); 20597c675421SVasundhara Volam if (rc || hwrm_err) 20607c675421SVasundhara Volam goto err_exit; 20615ac67d8bSRob Swindell 20625ac67d8bSRob Swindell if ((install_type & 0xffff) == 0) 20635ac67d8bSRob Swindell install_type >>= 16; 20645ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1); 20655ac67d8bSRob Swindell install.install_type = cpu_to_le32(install_type); 20665ac67d8bSRob Swindell 2067cb4d1d62SKshitij Soni mutex_lock(&bp->hwrm_cmd_lock); 20687c675421SVasundhara Volam hwrm_err = _hwrm_send_message(bp, &install, sizeof(install), 20695ac67d8bSRob Swindell INSTALL_PACKAGE_TIMEOUT); 2070dd2ebf34SVasundhara Volam if (hwrm_err) { 2071cb4d1d62SKshitij Soni u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err; 2072cb4d1d62SKshitij Soni 2073dd2ebf34SVasundhara Volam if (resp->error_code && error_code == 2074dd2ebf34SVasundhara Volam NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) { 2075cb4d1d62SKshitij Soni install.flags |= cpu_to_le16( 2076cb4d1d62SKshitij Soni NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG); 20777c675421SVasundhara Volam hwrm_err = _hwrm_send_message(bp, &install, 20787c675421SVasundhara Volam sizeof(install), 2079cb4d1d62SKshitij Soni INSTALL_PACKAGE_TIMEOUT); 2080dd2ebf34SVasundhara Volam } 20817c675421SVasundhara Volam if (hwrm_err) 2082cb4d1d62SKshitij Soni goto flash_pkg_exit; 2083cb4d1d62SKshitij Soni } 20845ac67d8bSRob Swindell 20855ac67d8bSRob Swindell if (resp->result) { 20865ac67d8bSRob Swindell netdev_err(dev, "PKG install error = %d, problem_item = %d\n", 20875ac67d8bSRob Swindell (s8)resp->result, (int)resp->problem_item); 2088cb4d1d62SKshitij Soni rc = -ENOPKG; 20895ac67d8bSRob Swindell } 2090cb4d1d62SKshitij Soni flash_pkg_exit: 2091cb4d1d62SKshitij Soni mutex_unlock(&bp->hwrm_cmd_lock); 20927c675421SVasundhara Volam err_exit: 2093d4f1420dSMichael Chan if (hwrm_err == -EACCES) 2094b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 2095cb4d1d62SKshitij Soni return rc; 2096c0c050c5SMichael Chan } 2097c0c050c5SMichael Chan 2098c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 2099c0c050c5SMichael Chan struct ethtool_flash *flash) 2100c0c050c5SMichael Chan { 2101c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 2102c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 2103c0c050c5SMichael Chan return -EINVAL; 2104c0c050c5SMichael Chan } 2105c0c050c5SMichael Chan 21065ac67d8bSRob Swindell if (flash->region == ETHTOOL_FLASH_ALL_REGIONS || 21075ac67d8bSRob Swindell flash->region > 0xffff) 21085ac67d8bSRob Swindell return bnxt_flash_package_from_file(dev, flash->data, 21095ac67d8bSRob Swindell flash->region); 2110c0c050c5SMichael Chan 2111c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 2112c0c050c5SMichael Chan } 2113c0c050c5SMichael Chan 2114c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 2115c0c050c5SMichael Chan { 2116c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2117c0c050c5SMichael Chan int rc; 2118c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 2119c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 2120c0c050c5SMichael Chan 2121c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 2122c0c050c5SMichael Chan 2123c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2124c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2125c0c050c5SMichael Chan if (!rc) { 2126c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 2127c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 2128c0c050c5SMichael Chan } 2129c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2130c0c050c5SMichael Chan return rc; 2131c0c050c5SMichael Chan } 2132c0c050c5SMichael Chan 2133c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 2134c0c050c5SMichael Chan { 21354cebbacaSMichael Chan struct bnxt *bp = netdev_priv(dev); 21364cebbacaSMichael Chan 21374cebbacaSMichael Chan if (BNXT_VF(bp)) 21384cebbacaSMichael Chan return 0; 21394cebbacaSMichael Chan 2140c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 2141c0c050c5SMichael Chan * passed via the ethtool command-line utility. 2142c0c050c5SMichael Chan */ 2143c0c050c5SMichael Chan return -1; 2144c0c050c5SMichael Chan } 2145c0c050c5SMichael Chan 2146c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 2147c0c050c5SMichael Chan { 2148c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2149c0c050c5SMichael Chan int rc; 2150c0c050c5SMichael Chan u32 dir_entries; 2151c0c050c5SMichael Chan u32 entry_length; 2152c0c050c5SMichael Chan u8 *buf; 2153c0c050c5SMichael Chan size_t buflen; 2154c0c050c5SMichael Chan dma_addr_t dma_handle; 2155c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 2156c0c050c5SMichael Chan 2157c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 2158c0c050c5SMichael Chan if (rc != 0) 2159c0c050c5SMichael Chan return rc; 2160c0c050c5SMichael Chan 2161c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 2162c0c050c5SMichael Chan if (len < 2) 2163c0c050c5SMichael Chan return -EINVAL; 2164c0c050c5SMichael Chan 2165c0c050c5SMichael Chan *data++ = dir_entries; 2166c0c050c5SMichael Chan *data++ = entry_length; 2167c0c050c5SMichael Chan len -= 2; 2168c0c050c5SMichael Chan memset(data, 0xff, len); 2169c0c050c5SMichael Chan 2170c0c050c5SMichael Chan buflen = dir_entries * entry_length; 2171c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 2172c0c050c5SMichael Chan GFP_KERNEL); 2173c0c050c5SMichael Chan if (!buf) { 2174c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2175c0c050c5SMichael Chan (unsigned)buflen); 2176c0c050c5SMichael Chan return -ENOMEM; 2177c0c050c5SMichael Chan } 2178c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 2179c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2180c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2181c0c050c5SMichael Chan if (rc == 0) 2182c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 2183c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 2184c0c050c5SMichael Chan return rc; 2185c0c050c5SMichael Chan } 2186c0c050c5SMichael Chan 2187c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 2188c0c050c5SMichael Chan u32 length, u8 *data) 2189c0c050c5SMichael Chan { 2190c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2191c0c050c5SMichael Chan int rc; 2192c0c050c5SMichael Chan u8 *buf; 2193c0c050c5SMichael Chan dma_addr_t dma_handle; 2194c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 2195c0c050c5SMichael Chan 2196e0ad8fc5SMichael Chan if (!length) 2197e0ad8fc5SMichael Chan return -EINVAL; 2198e0ad8fc5SMichael Chan 2199c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 2200c0c050c5SMichael Chan GFP_KERNEL); 2201c0c050c5SMichael Chan if (!buf) { 2202c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2203c0c050c5SMichael Chan (unsigned)length); 2204c0c050c5SMichael Chan return -ENOMEM; 2205c0c050c5SMichael Chan } 2206c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 2207c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2208c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2209c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 2210c0c050c5SMichael Chan req.len = cpu_to_le32(length); 2211c0c050c5SMichael Chan 2212c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2213c0c050c5SMichael Chan if (rc == 0) 2214c0c050c5SMichael Chan memcpy(data, buf, length); 2215c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 2216c0c050c5SMichael Chan return rc; 2217c0c050c5SMichael Chan } 2218c0c050c5SMichael Chan 22193ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 22203ebf6f0aSRob Swindell u16 ext, u16 *index, u32 *item_length, 22213ebf6f0aSRob Swindell u32 *data_length) 22223ebf6f0aSRob Swindell { 22233ebf6f0aSRob Swindell struct bnxt *bp = netdev_priv(dev); 22243ebf6f0aSRob Swindell int rc; 22253ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_input req = {0}; 22263ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr; 22273ebf6f0aSRob Swindell 22283ebf6f0aSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1); 22293ebf6f0aSRob Swindell req.enables = 0; 22303ebf6f0aSRob Swindell req.dir_idx = 0; 22313ebf6f0aSRob Swindell req.dir_type = cpu_to_le16(type); 22323ebf6f0aSRob Swindell req.dir_ordinal = cpu_to_le16(ordinal); 22333ebf6f0aSRob Swindell req.dir_ext = cpu_to_le16(ext); 22343ebf6f0aSRob Swindell req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ; 2235cc72f3b1SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2236cc72f3b1SMichael Chan rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 22373ebf6f0aSRob Swindell if (rc == 0) { 22383ebf6f0aSRob Swindell if (index) 22393ebf6f0aSRob Swindell *index = le16_to_cpu(output->dir_idx); 22403ebf6f0aSRob Swindell if (item_length) 22413ebf6f0aSRob Swindell *item_length = le32_to_cpu(output->dir_item_length); 22423ebf6f0aSRob Swindell if (data_length) 22433ebf6f0aSRob Swindell *data_length = le32_to_cpu(output->dir_data_length); 22443ebf6f0aSRob Swindell } 2245cc72f3b1SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 22463ebf6f0aSRob Swindell return rc; 22473ebf6f0aSRob Swindell } 22483ebf6f0aSRob Swindell 22493ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen) 22503ebf6f0aSRob Swindell { 22513ebf6f0aSRob Swindell char *retval = NULL; 22523ebf6f0aSRob Swindell char *p; 22533ebf6f0aSRob Swindell char *value; 22543ebf6f0aSRob Swindell int field = 0; 22553ebf6f0aSRob Swindell 22563ebf6f0aSRob Swindell if (datalen < 1) 22573ebf6f0aSRob Swindell return NULL; 22583ebf6f0aSRob Swindell /* null-terminate the log data (removing last '\n'): */ 22593ebf6f0aSRob Swindell data[datalen - 1] = 0; 22603ebf6f0aSRob Swindell for (p = data; *p != 0; p++) { 22613ebf6f0aSRob Swindell field = 0; 22623ebf6f0aSRob Swindell retval = NULL; 22633ebf6f0aSRob Swindell while (*p != 0 && *p != '\n') { 22643ebf6f0aSRob Swindell value = p; 22653ebf6f0aSRob Swindell while (*p != 0 && *p != '\t' && *p != '\n') 22663ebf6f0aSRob Swindell p++; 22673ebf6f0aSRob Swindell if (field == desired_field) 22683ebf6f0aSRob Swindell retval = value; 22693ebf6f0aSRob Swindell if (*p != '\t') 22703ebf6f0aSRob Swindell break; 22713ebf6f0aSRob Swindell *p = 0; 22723ebf6f0aSRob Swindell field++; 22733ebf6f0aSRob Swindell p++; 22743ebf6f0aSRob Swindell } 22753ebf6f0aSRob Swindell if (*p == 0) 22763ebf6f0aSRob Swindell break; 22773ebf6f0aSRob Swindell *p = 0; 22783ebf6f0aSRob Swindell } 22793ebf6f0aSRob Swindell return retval; 22803ebf6f0aSRob Swindell } 22813ebf6f0aSRob Swindell 2282a60faa60SVasundhara Volam static void bnxt_get_pkgver(struct net_device *dev) 22833ebf6f0aSRob Swindell { 2284a60faa60SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 22853ebf6f0aSRob Swindell u16 index = 0; 2286a60faa60SVasundhara Volam char *pkgver; 2287a60faa60SVasundhara Volam u32 pkglen; 2288a60faa60SVasundhara Volam u8 *pkgbuf; 2289a60faa60SVasundhara Volam int len; 22903ebf6f0aSRob Swindell 22913ebf6f0aSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG, 22923ebf6f0aSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 2293a60faa60SVasundhara Volam &index, NULL, &pkglen) != 0) 2294a60faa60SVasundhara Volam return; 22953ebf6f0aSRob Swindell 2296a60faa60SVasundhara Volam pkgbuf = kzalloc(pkglen, GFP_KERNEL); 2297a60faa60SVasundhara Volam if (!pkgbuf) { 2298a60faa60SVasundhara Volam dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n", 2299a60faa60SVasundhara Volam pkglen); 2300a60faa60SVasundhara Volam return; 2301a60faa60SVasundhara Volam } 23023ebf6f0aSRob Swindell 2303a60faa60SVasundhara Volam if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf)) 2304a60faa60SVasundhara Volam goto err; 2305a60faa60SVasundhara Volam 2306a60faa60SVasundhara Volam pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf, 2307a60faa60SVasundhara Volam pkglen); 2308a60faa60SVasundhara Volam if (pkgver && *pkgver != 0 && isdigit(*pkgver)) { 2309a60faa60SVasundhara Volam len = strlen(bp->fw_ver_str); 2310a60faa60SVasundhara Volam snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1, 2311a60faa60SVasundhara Volam "/pkg %s", pkgver); 2312a60faa60SVasundhara Volam } 2313a60faa60SVasundhara Volam err: 2314a60faa60SVasundhara Volam kfree(pkgbuf); 23153ebf6f0aSRob Swindell } 23163ebf6f0aSRob Swindell 2317c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 2318c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2319c0c050c5SMichael Chan u8 *data) 2320c0c050c5SMichael Chan { 2321c0c050c5SMichael Chan u32 index; 2322c0c050c5SMichael Chan u32 offset; 2323c0c050c5SMichael Chan 2324c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 2325c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 2326c0c050c5SMichael Chan 2327c0c050c5SMichael Chan index = eeprom->offset >> 24; 2328c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 2329c0c050c5SMichael Chan 2330c0c050c5SMichael Chan if (index == 0) { 2331c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 2332c0c050c5SMichael Chan return -EINVAL; 2333c0c050c5SMichael Chan } 2334c0c050c5SMichael Chan 2335c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 2336c0c050c5SMichael Chan } 2337c0c050c5SMichael Chan 2338c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 2339c0c050c5SMichael Chan { 2340c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2341c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 2342c0c050c5SMichael Chan 2343c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 2344c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2345c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2346c0c050c5SMichael Chan } 2347c0c050c5SMichael Chan 2348c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 2349c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2350c0c050c5SMichael Chan u8 *data) 2351c0c050c5SMichael Chan { 2352c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2353c0c050c5SMichael Chan u8 index, dir_op; 2354c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 2355c0c050c5SMichael Chan 2356c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 2357c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 2358c0c050c5SMichael Chan return -EINVAL; 2359c0c050c5SMichael Chan } 2360c0c050c5SMichael Chan 2361c0c050c5SMichael Chan type = eeprom->magic >> 16; 2362c0c050c5SMichael Chan 2363c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 2364c0c050c5SMichael Chan index = eeprom->magic & 0xff; 2365c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 2366c0c050c5SMichael Chan if (index == 0) 2367c0c050c5SMichael Chan return -EINVAL; 2368c0c050c5SMichael Chan switch (dir_op) { 2369c0c050c5SMichael Chan case 0x0e: /* erase */ 2370c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 2371c0c050c5SMichael Chan return -EINVAL; 2372c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 2373c0c050c5SMichael Chan default: 2374c0c050c5SMichael Chan return -EINVAL; 2375c0c050c5SMichael Chan } 2376c0c050c5SMichael Chan } 2377c0c050c5SMichael Chan 2378c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 2379c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(type) == true) 23805ac67d8bSRob Swindell return -EOPNOTSUPP; 2381c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 2382c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 2383c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 2384c0c050c5SMichael Chan 2385c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 2386c0c050c5SMichael Chan eeprom->len); 2387c0c050c5SMichael Chan } 2388c0c050c5SMichael Chan 238972b34f04SMichael Chan static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata) 239072b34f04SMichael Chan { 239172b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 239272b34f04SMichael Chan struct ethtool_eee *eee = &bp->eee; 239372b34f04SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 239472b34f04SMichael Chan u32 advertising = 239572b34f04SMichael Chan _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); 239672b34f04SMichael Chan int rc = 0; 239772b34f04SMichael Chan 2398567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 239975362a3fSMichael Chan return -EOPNOTSUPP; 240072b34f04SMichael Chan 240172b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 240272b34f04SMichael Chan return -EOPNOTSUPP; 240372b34f04SMichael Chan 240472b34f04SMichael Chan if (!edata->eee_enabled) 240572b34f04SMichael Chan goto eee_ok; 240672b34f04SMichael Chan 240772b34f04SMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { 240872b34f04SMichael Chan netdev_warn(dev, "EEE requires autoneg\n"); 240972b34f04SMichael Chan return -EINVAL; 241072b34f04SMichael Chan } 241172b34f04SMichael Chan if (edata->tx_lpi_enabled) { 241272b34f04SMichael Chan if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi || 241372b34f04SMichael Chan edata->tx_lpi_timer < bp->lpi_tmr_lo)) { 241472b34f04SMichael Chan netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n", 241572b34f04SMichael Chan bp->lpi_tmr_lo, bp->lpi_tmr_hi); 241672b34f04SMichael Chan return -EINVAL; 241772b34f04SMichael Chan } else if (!bp->lpi_tmr_hi) { 241872b34f04SMichael Chan edata->tx_lpi_timer = eee->tx_lpi_timer; 241972b34f04SMichael Chan } 242072b34f04SMichael Chan } 242172b34f04SMichael Chan if (!edata->advertised) { 242272b34f04SMichael Chan edata->advertised = advertising & eee->supported; 242372b34f04SMichael Chan } else if (edata->advertised & ~advertising) { 242472b34f04SMichael Chan netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", 242572b34f04SMichael Chan edata->advertised, advertising); 242672b34f04SMichael Chan return -EINVAL; 242772b34f04SMichael Chan } 242872b34f04SMichael Chan 242972b34f04SMichael Chan eee->advertised = edata->advertised; 243072b34f04SMichael Chan eee->tx_lpi_enabled = edata->tx_lpi_enabled; 243172b34f04SMichael Chan eee->tx_lpi_timer = edata->tx_lpi_timer; 243272b34f04SMichael Chan eee_ok: 243372b34f04SMichael Chan eee->eee_enabled = edata->eee_enabled; 243472b34f04SMichael Chan 243572b34f04SMichael Chan if (netif_running(dev)) 243672b34f04SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, false, true); 243772b34f04SMichael Chan 243872b34f04SMichael Chan return rc; 243972b34f04SMichael Chan } 244072b34f04SMichael Chan 244172b34f04SMichael Chan static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata) 244272b34f04SMichael Chan { 244372b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 244472b34f04SMichael Chan 244572b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 244672b34f04SMichael Chan return -EOPNOTSUPP; 244772b34f04SMichael Chan 244872b34f04SMichael Chan *edata = bp->eee; 244972b34f04SMichael Chan if (!bp->eee.eee_enabled) { 245072b34f04SMichael Chan /* Preserve tx_lpi_timer so that the last value will be used 245172b34f04SMichael Chan * by default when it is re-enabled. 245272b34f04SMichael Chan */ 245372b34f04SMichael Chan edata->advertised = 0; 245472b34f04SMichael Chan edata->tx_lpi_enabled = 0; 245572b34f04SMichael Chan } 245672b34f04SMichael Chan 245772b34f04SMichael Chan if (!bp->eee.eee_active) 245872b34f04SMichael Chan edata->lp_advertised = 0; 245972b34f04SMichael Chan 246072b34f04SMichael Chan return 0; 246172b34f04SMichael Chan } 246272b34f04SMichael Chan 246342ee18feSAjit Khaparde static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr, 246442ee18feSAjit Khaparde u16 page_number, u16 start_addr, 246542ee18feSAjit Khaparde u16 data_length, u8 *buf) 246642ee18feSAjit Khaparde { 246742ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_input req = {0}; 246842ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr; 246942ee18feSAjit Khaparde int rc, byte_offset = 0; 247042ee18feSAjit Khaparde 247142ee18feSAjit Khaparde bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1); 247242ee18feSAjit Khaparde req.i2c_slave_addr = i2c_addr; 247342ee18feSAjit Khaparde req.page_number = cpu_to_le16(page_number); 247442ee18feSAjit Khaparde req.port_id = cpu_to_le16(bp->pf.port_id); 247542ee18feSAjit Khaparde do { 247642ee18feSAjit Khaparde u16 xfer_size; 247742ee18feSAjit Khaparde 247842ee18feSAjit Khaparde xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE); 247942ee18feSAjit Khaparde data_length -= xfer_size; 248042ee18feSAjit Khaparde req.page_offset = cpu_to_le16(start_addr + byte_offset); 248142ee18feSAjit Khaparde req.data_length = xfer_size; 248242ee18feSAjit Khaparde req.enables = cpu_to_le32(start_addr + byte_offset ? 248342ee18feSAjit Khaparde PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0); 248442ee18feSAjit Khaparde mutex_lock(&bp->hwrm_cmd_lock); 248542ee18feSAjit Khaparde rc = _hwrm_send_message(bp, &req, sizeof(req), 248642ee18feSAjit Khaparde HWRM_CMD_TIMEOUT); 248742ee18feSAjit Khaparde if (!rc) 248842ee18feSAjit Khaparde memcpy(buf + byte_offset, output->data, xfer_size); 248942ee18feSAjit Khaparde mutex_unlock(&bp->hwrm_cmd_lock); 249042ee18feSAjit Khaparde byte_offset += xfer_size; 249142ee18feSAjit Khaparde } while (!rc && data_length > 0); 249242ee18feSAjit Khaparde 249342ee18feSAjit Khaparde return rc; 249442ee18feSAjit Khaparde } 249542ee18feSAjit Khaparde 249642ee18feSAjit Khaparde static int bnxt_get_module_info(struct net_device *dev, 249742ee18feSAjit Khaparde struct ethtool_modinfo *modinfo) 249842ee18feSAjit Khaparde { 24997328a23cSVasundhara Volam u8 data[SFF_DIAG_SUPPORT_OFFSET + 1]; 250042ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 250142ee18feSAjit Khaparde int rc; 250242ee18feSAjit Khaparde 250342ee18feSAjit Khaparde /* No point in going further if phy status indicates 250442ee18feSAjit Khaparde * module is not inserted or if it is powered down or 250542ee18feSAjit Khaparde * if it is of type 10GBase-T 250642ee18feSAjit Khaparde */ 250742ee18feSAjit Khaparde if (bp->link_info.module_status > 250842ee18feSAjit Khaparde PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG) 250942ee18feSAjit Khaparde return -EOPNOTSUPP; 251042ee18feSAjit Khaparde 251142ee18feSAjit Khaparde /* This feature is not supported in older firmware versions */ 251242ee18feSAjit Khaparde if (bp->hwrm_spec_code < 0x10202) 251342ee18feSAjit Khaparde return -EOPNOTSUPP; 251442ee18feSAjit Khaparde 25157328a23cSVasundhara Volam rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0, 25167328a23cSVasundhara Volam SFF_DIAG_SUPPORT_OFFSET + 1, 25177328a23cSVasundhara Volam data); 251842ee18feSAjit Khaparde if (!rc) { 25197328a23cSVasundhara Volam u8 module_id = data[0]; 25207328a23cSVasundhara Volam u8 diag_supported = data[SFF_DIAG_SUPPORT_OFFSET]; 252142ee18feSAjit Khaparde 252242ee18feSAjit Khaparde switch (module_id) { 252342ee18feSAjit Khaparde case SFF_MODULE_ID_SFP: 252442ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8472; 252542ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 25267328a23cSVasundhara Volam if (!diag_supported) 25277328a23cSVasundhara Volam modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 252842ee18feSAjit Khaparde break; 252942ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP: 253042ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP_PLUS: 253142ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8436; 253242ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 253342ee18feSAjit Khaparde break; 253442ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP28: 253542ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8636; 253642ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 253742ee18feSAjit Khaparde break; 253842ee18feSAjit Khaparde default: 253942ee18feSAjit Khaparde rc = -EOPNOTSUPP; 254042ee18feSAjit Khaparde break; 254142ee18feSAjit Khaparde } 254242ee18feSAjit Khaparde } 254342ee18feSAjit Khaparde return rc; 254442ee18feSAjit Khaparde } 254542ee18feSAjit Khaparde 254642ee18feSAjit Khaparde static int bnxt_get_module_eeprom(struct net_device *dev, 254742ee18feSAjit Khaparde struct ethtool_eeprom *eeprom, 254842ee18feSAjit Khaparde u8 *data) 254942ee18feSAjit Khaparde { 255042ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 255142ee18feSAjit Khaparde u16 start = eeprom->offset, length = eeprom->len; 2552f3ea3119SColin Ian King int rc = 0; 255342ee18feSAjit Khaparde 255442ee18feSAjit Khaparde memset(data, 0, eeprom->len); 255542ee18feSAjit Khaparde 255642ee18feSAjit Khaparde /* Read A0 portion of the EEPROM */ 255742ee18feSAjit Khaparde if (start < ETH_MODULE_SFF_8436_LEN) { 255842ee18feSAjit Khaparde if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN) 255942ee18feSAjit Khaparde length = ETH_MODULE_SFF_8436_LEN - start; 256042ee18feSAjit Khaparde rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 256142ee18feSAjit Khaparde start, length, data); 256242ee18feSAjit Khaparde if (rc) 256342ee18feSAjit Khaparde return rc; 256442ee18feSAjit Khaparde start += length; 256542ee18feSAjit Khaparde data += length; 256642ee18feSAjit Khaparde length = eeprom->len - length; 256742ee18feSAjit Khaparde } 256842ee18feSAjit Khaparde 256942ee18feSAjit Khaparde /* Read A2 portion of the EEPROM */ 257042ee18feSAjit Khaparde if (length) { 257142ee18feSAjit Khaparde start -= ETH_MODULE_SFF_8436_LEN; 2572dea521a2SChristophe JAILLET rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1, 2573dea521a2SChristophe JAILLET start, length, data); 257442ee18feSAjit Khaparde } 257542ee18feSAjit Khaparde return rc; 257642ee18feSAjit Khaparde } 257742ee18feSAjit Khaparde 2578ae8e98a6SDeepak Khungar static int bnxt_nway_reset(struct net_device *dev) 2579ae8e98a6SDeepak Khungar { 2580ae8e98a6SDeepak Khungar int rc = 0; 2581ae8e98a6SDeepak Khungar 2582ae8e98a6SDeepak Khungar struct bnxt *bp = netdev_priv(dev); 2583ae8e98a6SDeepak Khungar struct bnxt_link_info *link_info = &bp->link_info; 2584ae8e98a6SDeepak Khungar 2585ae8e98a6SDeepak Khungar if (!BNXT_SINGLE_PF(bp)) 2586ae8e98a6SDeepak Khungar return -EOPNOTSUPP; 2587ae8e98a6SDeepak Khungar 2588ae8e98a6SDeepak Khungar if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 2589ae8e98a6SDeepak Khungar return -EINVAL; 2590ae8e98a6SDeepak Khungar 2591ae8e98a6SDeepak Khungar if (netif_running(dev)) 2592ae8e98a6SDeepak Khungar rc = bnxt_hwrm_set_link_setting(bp, true, false); 2593ae8e98a6SDeepak Khungar 2594ae8e98a6SDeepak Khungar return rc; 2595ae8e98a6SDeepak Khungar } 2596ae8e98a6SDeepak Khungar 25975ad2cbeeSMichael Chan static int bnxt_set_phys_id(struct net_device *dev, 25985ad2cbeeSMichael Chan enum ethtool_phys_id_state state) 25995ad2cbeeSMichael Chan { 26005ad2cbeeSMichael Chan struct hwrm_port_led_cfg_input req = {0}; 26015ad2cbeeSMichael Chan struct bnxt *bp = netdev_priv(dev); 26025ad2cbeeSMichael Chan struct bnxt_pf_info *pf = &bp->pf; 26035ad2cbeeSMichael Chan struct bnxt_led_cfg *led_cfg; 26045ad2cbeeSMichael Chan u8 led_state; 26055ad2cbeeSMichael Chan __le16 duration; 26065ad2cbeeSMichael Chan int i, rc; 26075ad2cbeeSMichael Chan 26085ad2cbeeSMichael Chan if (!bp->num_leds || BNXT_VF(bp)) 26095ad2cbeeSMichael Chan return -EOPNOTSUPP; 26105ad2cbeeSMichael Chan 26115ad2cbeeSMichael Chan if (state == ETHTOOL_ID_ACTIVE) { 26125ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT; 26135ad2cbeeSMichael Chan duration = cpu_to_le16(500); 26145ad2cbeeSMichael Chan } else if (state == ETHTOOL_ID_INACTIVE) { 26155ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT; 26165ad2cbeeSMichael Chan duration = cpu_to_le16(0); 26175ad2cbeeSMichael Chan } else { 26185ad2cbeeSMichael Chan return -EINVAL; 26195ad2cbeeSMichael Chan } 26205ad2cbeeSMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1); 26215ad2cbeeSMichael Chan req.port_id = cpu_to_le16(pf->port_id); 26225ad2cbeeSMichael Chan req.num_leds = bp->num_leds; 26235ad2cbeeSMichael Chan led_cfg = (struct bnxt_led_cfg *)&req.led0_id; 26245ad2cbeeSMichael Chan for (i = 0; i < bp->num_leds; i++, led_cfg++) { 26255ad2cbeeSMichael Chan req.enables |= BNXT_LED_DFLT_ENABLES(i); 26265ad2cbeeSMichael Chan led_cfg->led_id = bp->leds[i].led_id; 26275ad2cbeeSMichael Chan led_cfg->led_state = led_state; 26285ad2cbeeSMichael Chan led_cfg->led_blink_on = duration; 26295ad2cbeeSMichael Chan led_cfg->led_blink_off = duration; 26305ad2cbeeSMichael Chan led_cfg->led_group_id = bp->leds[i].led_group_id; 26315ad2cbeeSMichael Chan } 26325ad2cbeeSMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 26335ad2cbeeSMichael Chan return rc; 26345ad2cbeeSMichael Chan } 26355ad2cbeeSMichael Chan 263667fea463SMichael Chan static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring) 263767fea463SMichael Chan { 263867fea463SMichael Chan struct hwrm_selftest_irq_input req = {0}; 263967fea463SMichael Chan 264067fea463SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1); 264167fea463SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 264267fea463SMichael Chan } 264367fea463SMichael Chan 264467fea463SMichael Chan static int bnxt_test_irq(struct bnxt *bp) 264567fea463SMichael Chan { 264667fea463SMichael Chan int i; 264767fea463SMichael Chan 264867fea463SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 264967fea463SMichael Chan u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id; 265067fea463SMichael Chan int rc; 265167fea463SMichael Chan 265267fea463SMichael Chan rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring); 265367fea463SMichael Chan if (rc) 265467fea463SMichael Chan return rc; 265567fea463SMichael Chan } 265667fea463SMichael Chan return 0; 265767fea463SMichael Chan } 265867fea463SMichael Chan 2659f7dc1ea6SMichael Chan static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable) 2660f7dc1ea6SMichael Chan { 2661f7dc1ea6SMichael Chan struct hwrm_port_mac_cfg_input req = {0}; 2662f7dc1ea6SMichael Chan 2663f7dc1ea6SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1); 2664f7dc1ea6SMichael Chan 2665f7dc1ea6SMichael Chan req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK); 2666f7dc1ea6SMichael Chan if (enable) 2667f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL; 2668f7dc1ea6SMichael Chan else 2669f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE; 2670f7dc1ea6SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2671f7dc1ea6SMichael Chan } 2672f7dc1ea6SMichael Chan 267356d37462SVasundhara Volam static int bnxt_query_force_speeds(struct bnxt *bp, u16 *force_speeds) 267456d37462SVasundhara Volam { 267556d37462SVasundhara Volam struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; 267656d37462SVasundhara Volam struct hwrm_port_phy_qcaps_input req = {0}; 267756d37462SVasundhara Volam int rc; 267856d37462SVasundhara Volam 267956d37462SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); 268056d37462SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 268156d37462SVasundhara Volam rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 268256d37462SVasundhara Volam if (!rc) 268356d37462SVasundhara Volam *force_speeds = le16_to_cpu(resp->supported_speeds_force_mode); 268456d37462SVasundhara Volam 268556d37462SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 268656d37462SVasundhara Volam return rc; 268756d37462SVasundhara Volam } 268856d37462SVasundhara Volam 268991725d89SMichael Chan static int bnxt_disable_an_for_lpbk(struct bnxt *bp, 269091725d89SMichael Chan struct hwrm_port_phy_cfg_input *req) 269191725d89SMichael Chan { 269291725d89SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 269356d37462SVasundhara Volam u16 fw_advertising; 269491725d89SMichael Chan u16 fw_speed; 269591725d89SMichael Chan int rc; 269691725d89SMichael Chan 269791725d89SMichael Chan if (!link_info->autoneg) 269891725d89SMichael Chan return 0; 269991725d89SMichael Chan 270056d37462SVasundhara Volam rc = bnxt_query_force_speeds(bp, &fw_advertising); 270156d37462SVasundhara Volam if (rc) 270256d37462SVasundhara Volam return rc; 270356d37462SVasundhara Volam 270491725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB; 270591725d89SMichael Chan if (netif_carrier_ok(bp->dev)) 270691725d89SMichael Chan fw_speed = bp->link_info.link_speed; 270791725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB) 270891725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB; 270991725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB) 271091725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB; 271191725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB) 271291725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB; 271391725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB) 271491725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB; 271591725d89SMichael Chan 271691725d89SMichael Chan req->force_link_speed = cpu_to_le16(fw_speed); 271791725d89SMichael Chan req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE | 271891725d89SMichael Chan PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); 271991725d89SMichael Chan rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT); 272091725d89SMichael Chan req->flags = 0; 272191725d89SMichael Chan req->force_link_speed = cpu_to_le16(0); 272291725d89SMichael Chan return rc; 272391725d89SMichael Chan } 272491725d89SMichael Chan 272555fd0cf3SMichael Chan static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable, bool ext) 272691725d89SMichael Chan { 272791725d89SMichael Chan struct hwrm_port_phy_cfg_input req = {0}; 272891725d89SMichael Chan 272991725d89SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); 273091725d89SMichael Chan 273191725d89SMichael Chan if (enable) { 273291725d89SMichael Chan bnxt_disable_an_for_lpbk(bp, &req); 273355fd0cf3SMichael Chan if (ext) 273455fd0cf3SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_EXTERNAL; 273555fd0cf3SMichael Chan else 273691725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL; 273791725d89SMichael Chan } else { 273891725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE; 273991725d89SMichael Chan } 274091725d89SMichael Chan req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK); 274191725d89SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 274291725d89SMichael Chan } 274391725d89SMichael Chan 2744e44758b7SMichael Chan static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2745f7dc1ea6SMichael Chan u32 raw_cons, int pkt_size) 2746f7dc1ea6SMichael Chan { 2747e44758b7SMichael Chan struct bnxt_napi *bnapi = cpr->bnapi; 2748e44758b7SMichael Chan struct bnxt_rx_ring_info *rxr; 2749f7dc1ea6SMichael Chan struct bnxt_sw_rx_bd *rx_buf; 2750f7dc1ea6SMichael Chan struct rx_cmp *rxcmp; 2751f7dc1ea6SMichael Chan u16 cp_cons, cons; 2752f7dc1ea6SMichael Chan u8 *data; 2753f7dc1ea6SMichael Chan u32 len; 2754f7dc1ea6SMichael Chan int i; 2755f7dc1ea6SMichael Chan 2756e44758b7SMichael Chan rxr = bnapi->rx_ring; 2757f7dc1ea6SMichael Chan cp_cons = RING_CMP(raw_cons); 2758f7dc1ea6SMichael Chan rxcmp = (struct rx_cmp *) 2759f7dc1ea6SMichael Chan &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; 2760f7dc1ea6SMichael Chan cons = rxcmp->rx_cmp_opaque; 2761f7dc1ea6SMichael Chan rx_buf = &rxr->rx_buf_ring[cons]; 2762f7dc1ea6SMichael Chan data = rx_buf->data_ptr; 2763f7dc1ea6SMichael Chan len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT; 2764f7dc1ea6SMichael Chan if (len != pkt_size) 2765f7dc1ea6SMichael Chan return -EIO; 2766f7dc1ea6SMichael Chan i = ETH_ALEN; 2767f7dc1ea6SMichael Chan if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr)) 2768f7dc1ea6SMichael Chan return -EIO; 2769f7dc1ea6SMichael Chan i += ETH_ALEN; 2770f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) { 2771f7dc1ea6SMichael Chan if (data[i] != (u8)(i & 0xff)) 2772f7dc1ea6SMichael Chan return -EIO; 2773f7dc1ea6SMichael Chan } 2774f7dc1ea6SMichael Chan return 0; 2775f7dc1ea6SMichael Chan } 2776f7dc1ea6SMichael Chan 2777e44758b7SMichael Chan static int bnxt_poll_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2778e44758b7SMichael Chan int pkt_size) 2779f7dc1ea6SMichael Chan { 2780f7dc1ea6SMichael Chan struct tx_cmp *txcmp; 2781f7dc1ea6SMichael Chan int rc = -EIO; 2782f7dc1ea6SMichael Chan u32 raw_cons; 2783f7dc1ea6SMichael Chan u32 cons; 2784f7dc1ea6SMichael Chan int i; 2785f7dc1ea6SMichael Chan 2786f7dc1ea6SMichael Chan raw_cons = cpr->cp_raw_cons; 2787f7dc1ea6SMichael Chan for (i = 0; i < 200; i++) { 2788f7dc1ea6SMichael Chan cons = RING_CMP(raw_cons); 2789f7dc1ea6SMichael Chan txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; 2790f7dc1ea6SMichael Chan 2791f7dc1ea6SMichael Chan if (!TX_CMP_VALID(txcmp, raw_cons)) { 2792f7dc1ea6SMichael Chan udelay(5); 2793f7dc1ea6SMichael Chan continue; 2794f7dc1ea6SMichael Chan } 2795f7dc1ea6SMichael Chan 2796f7dc1ea6SMichael Chan /* The valid test of the entry must be done first before 2797f7dc1ea6SMichael Chan * reading any further. 2798f7dc1ea6SMichael Chan */ 2799f7dc1ea6SMichael Chan dma_rmb(); 2800f7dc1ea6SMichael Chan if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) { 2801e44758b7SMichael Chan rc = bnxt_rx_loopback(bp, cpr, raw_cons, pkt_size); 2802f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2803f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2804f7dc1ea6SMichael Chan break; 2805f7dc1ea6SMichael Chan } 2806f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2807f7dc1ea6SMichael Chan } 2808f7dc1ea6SMichael Chan cpr->cp_raw_cons = raw_cons; 2809f7dc1ea6SMichael Chan return rc; 2810f7dc1ea6SMichael Chan } 2811f7dc1ea6SMichael Chan 2812f7dc1ea6SMichael Chan static int bnxt_run_loopback(struct bnxt *bp) 2813f7dc1ea6SMichael Chan { 2814f7dc1ea6SMichael Chan struct bnxt_tx_ring_info *txr = &bp->tx_ring[0]; 281584404d5fSMichael Chan struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0]; 2816e44758b7SMichael Chan struct bnxt_cp_ring_info *cpr; 2817f7dc1ea6SMichael Chan int pkt_size, i = 0; 2818f7dc1ea6SMichael Chan struct sk_buff *skb; 2819f7dc1ea6SMichael Chan dma_addr_t map; 2820f7dc1ea6SMichael Chan u8 *data; 2821f7dc1ea6SMichael Chan int rc; 2822f7dc1ea6SMichael Chan 282384404d5fSMichael Chan cpr = &rxr->bnapi->cp_ring; 282484404d5fSMichael Chan if (bp->flags & BNXT_FLAG_CHIP_P5) 282584404d5fSMichael Chan cpr = cpr->cp_ring_arr[BNXT_RX_HDL]; 2826f7dc1ea6SMichael Chan pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh); 2827f7dc1ea6SMichael Chan skb = netdev_alloc_skb(bp->dev, pkt_size); 2828f7dc1ea6SMichael Chan if (!skb) 2829f7dc1ea6SMichael Chan return -ENOMEM; 2830f7dc1ea6SMichael Chan data = skb_put(skb, pkt_size); 2831f7dc1ea6SMichael Chan eth_broadcast_addr(data); 2832f7dc1ea6SMichael Chan i += ETH_ALEN; 2833f7dc1ea6SMichael Chan ether_addr_copy(&data[i], bp->dev->dev_addr); 2834f7dc1ea6SMichael Chan i += ETH_ALEN; 2835f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) 2836f7dc1ea6SMichael Chan data[i] = (u8)(i & 0xff); 2837f7dc1ea6SMichael Chan 2838f7dc1ea6SMichael Chan map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size, 2839f7dc1ea6SMichael Chan PCI_DMA_TODEVICE); 2840f7dc1ea6SMichael Chan if (dma_mapping_error(&bp->pdev->dev, map)) { 2841f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2842f7dc1ea6SMichael Chan return -EIO; 2843f7dc1ea6SMichael Chan } 2844c1ba92a8SMichael Chan bnxt_xmit_bd(bp, txr, map, pkt_size); 2845f7dc1ea6SMichael Chan 2846f7dc1ea6SMichael Chan /* Sync BD data before updating doorbell */ 2847f7dc1ea6SMichael Chan wmb(); 2848f7dc1ea6SMichael Chan 2849697197e5SMichael Chan bnxt_db_write(bp, &txr->tx_db, txr->tx_prod); 2850e44758b7SMichael Chan rc = bnxt_poll_loopback(bp, cpr, pkt_size); 2851f7dc1ea6SMichael Chan 2852f7dc1ea6SMichael Chan dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE); 2853f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2854f7dc1ea6SMichael Chan return rc; 2855f7dc1ea6SMichael Chan } 2856f7dc1ea6SMichael Chan 2857eb513658SMichael Chan static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results) 2858eb513658SMichael Chan { 2859eb513658SMichael Chan struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr; 2860eb513658SMichael Chan struct hwrm_selftest_exec_input req = {0}; 2861eb513658SMichael Chan int rc; 2862eb513658SMichael Chan 2863eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1); 2864eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2865eb513658SMichael Chan resp->test_success = 0; 2866eb513658SMichael Chan req.flags = test_mask; 2867eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout); 2868eb513658SMichael Chan *test_results = resp->test_success; 2869eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2870eb513658SMichael Chan return rc; 2871eb513658SMichael Chan } 2872eb513658SMichael Chan 287355fd0cf3SMichael Chan #define BNXT_DRV_TESTS 4 2874f7dc1ea6SMichael Chan #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS) 287591725d89SMichael Chan #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1) 287655fd0cf3SMichael Chan #define BNXT_EXTLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2) 287755fd0cf3SMichael Chan #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 3) 2878eb513658SMichael Chan 2879eb513658SMichael Chan static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest, 2880eb513658SMichael Chan u64 *buf) 2881eb513658SMichael Chan { 2882eb513658SMichael Chan struct bnxt *bp = netdev_priv(dev); 288355fd0cf3SMichael Chan bool do_ext_lpbk = false; 2884eb513658SMichael Chan bool offline = false; 2885eb513658SMichael Chan u8 test_results = 0; 2886eb513658SMichael Chan u8 test_mask = 0; 2887d27e2ca1SMichael Chan int rc = 0, i; 2888eb513658SMichael Chan 2889eb513658SMichael Chan if (!bp->num_tests || !BNXT_SINGLE_PF(bp)) 2890eb513658SMichael Chan return; 2891eb513658SMichael Chan memset(buf, 0, sizeof(u64) * bp->num_tests); 2892eb513658SMichael Chan if (!netif_running(dev)) { 2893eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2894eb513658SMichael Chan return; 2895eb513658SMichael Chan } 2896eb513658SMichael Chan 289755fd0cf3SMichael Chan if ((etest->flags & ETH_TEST_FL_EXTERNAL_LB) && 289855fd0cf3SMichael Chan (bp->test_info->flags & BNXT_TEST_FL_EXT_LPBK)) 289955fd0cf3SMichael Chan do_ext_lpbk = true; 290055fd0cf3SMichael Chan 2901eb513658SMichael Chan if (etest->flags & ETH_TEST_FL_OFFLINE) { 2902eb513658SMichael Chan if (bp->pf.active_vfs) { 2903eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2904eb513658SMichael Chan netdev_warn(dev, "Offline tests cannot be run with active VFs\n"); 2905eb513658SMichael Chan return; 2906eb513658SMichael Chan } 2907eb513658SMichael Chan offline = true; 2908eb513658SMichael Chan } 2909eb513658SMichael Chan 2910eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 2911eb513658SMichael Chan u8 bit_val = 1 << i; 2912eb513658SMichael Chan 2913eb513658SMichael Chan if (!(bp->test_info->offline_mask & bit_val)) 2914eb513658SMichael Chan test_mask |= bit_val; 2915eb513658SMichael Chan else if (offline) 2916eb513658SMichael Chan test_mask |= bit_val; 2917eb513658SMichael Chan } 2918eb513658SMichael Chan if (!offline) { 2919eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 2920eb513658SMichael Chan } else { 2921eb513658SMichael Chan rc = bnxt_close_nic(bp, false, false); 2922eb513658SMichael Chan if (rc) 2923eb513658SMichael Chan return; 2924eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 2925f7dc1ea6SMichael Chan 2926f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 1; 2927f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, true); 2928f7dc1ea6SMichael Chan msleep(250); 2929f7dc1ea6SMichael Chan rc = bnxt_half_open_nic(bp); 2930f7dc1ea6SMichael Chan if (rc) { 2931f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 2932f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2933f7dc1ea6SMichael Chan return; 2934f7dc1ea6SMichael Chan } 2935f7dc1ea6SMichael Chan if (bnxt_run_loopback(bp)) 2936f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2937f7dc1ea6SMichael Chan else 2938f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 0; 2939f7dc1ea6SMichael Chan 2940f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 294155fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, false); 294291725d89SMichael Chan msleep(1000); 294391725d89SMichael Chan if (bnxt_run_loopback(bp)) { 294491725d89SMichael Chan buf[BNXT_PHYLPBK_TEST_IDX] = 1; 294591725d89SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 294691725d89SMichael Chan } 294755fd0cf3SMichael Chan if (do_ext_lpbk) { 294855fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; 294955fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, true); 295055fd0cf3SMichael Chan msleep(1000); 295155fd0cf3SMichael Chan if (bnxt_run_loopback(bp)) { 295255fd0cf3SMichael Chan buf[BNXT_EXTLPBK_TEST_IDX] = 1; 295355fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 295455fd0cf3SMichael Chan } 295555fd0cf3SMichael Chan } 295655fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, false, false); 295791725d89SMichael Chan bnxt_half_close_nic(bp); 2958d27e2ca1SMichael Chan rc = bnxt_open_nic(bp, false, true); 2959eb513658SMichael Chan } 2960d27e2ca1SMichael Chan if (rc || bnxt_test_irq(bp)) { 296167fea463SMichael Chan buf[BNXT_IRQ_TEST_IDX] = 1; 296267fea463SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 296367fea463SMichael Chan } 2964eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 2965eb513658SMichael Chan u8 bit_val = 1 << i; 2966eb513658SMichael Chan 2967eb513658SMichael Chan if ((test_mask & bit_val) && !(test_results & bit_val)) { 2968eb513658SMichael Chan buf[i] = 1; 2969eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2970eb513658SMichael Chan } 2971eb513658SMichael Chan } 2972eb513658SMichael Chan } 2973eb513658SMichael Chan 297449f7972fSVasundhara Volam static int bnxt_reset(struct net_device *dev, u32 *flags) 297549f7972fSVasundhara Volam { 297649f7972fSVasundhara Volam struct bnxt *bp = netdev_priv(dev); 297749f7972fSVasundhara Volam int rc = 0; 297849f7972fSVasundhara Volam 297949f7972fSVasundhara Volam if (!BNXT_PF(bp)) { 298049f7972fSVasundhara Volam netdev_err(dev, "Reset is not supported from a VF\n"); 298149f7972fSVasundhara Volam return -EOPNOTSUPP; 298249f7972fSVasundhara Volam } 298349f7972fSVasundhara Volam 298449f7972fSVasundhara Volam if (pci_vfs_assigned(bp->pdev)) { 298549f7972fSVasundhara Volam netdev_err(dev, 298649f7972fSVasundhara Volam "Reset not allowed when VFs are assigned to VMs\n"); 298749f7972fSVasundhara Volam return -EBUSY; 298849f7972fSVasundhara Volam } 298949f7972fSVasundhara Volam 299049f7972fSVasundhara Volam if (*flags == ETH_RESET_ALL) { 299149f7972fSVasundhara Volam /* This feature is not supported in older firmware versions */ 299249f7972fSVasundhara Volam if (bp->hwrm_spec_code < 0x10803) 299349f7972fSVasundhara Volam return -EOPNOTSUPP; 299449f7972fSVasundhara Volam 299549f7972fSVasundhara Volam rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_CHIP); 29962373d8d6SScott Branden if (!rc) { 299749f7972fSVasundhara Volam netdev_info(dev, "Reset request successful. Reload driver to complete reset\n"); 29982373d8d6SScott Branden *flags = 0; 29992373d8d6SScott Branden } 30006502ad59SScott Branden } else if (*flags == ETH_RESET_AP) { 30016502ad59SScott Branden /* This feature is not supported in older firmware versions */ 30026502ad59SScott Branden if (bp->hwrm_spec_code < 0x10803) 30036502ad59SScott Branden return -EOPNOTSUPP; 30046502ad59SScott Branden 30056502ad59SScott Branden rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_AP); 30062373d8d6SScott Branden if (!rc) { 30076502ad59SScott Branden netdev_info(dev, "Reset Application Processor request successful.\n"); 30082373d8d6SScott Branden *flags = 0; 30092373d8d6SScott Branden } 301049f7972fSVasundhara Volam } else { 301149f7972fSVasundhara Volam rc = -EINVAL; 301249f7972fSVasundhara Volam } 301349f7972fSVasundhara Volam 301449f7972fSVasundhara Volam return rc; 301549f7972fSVasundhara Volam } 301649f7972fSVasundhara Volam 30176c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg, int msg_len, 30186c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info *info) 30196c5657d0SVasundhara Volam { 30206c5657d0SVasundhara Volam struct hwrm_dbg_cmn_output *cmn_resp = bp->hwrm_cmd_resp_addr; 30216c5657d0SVasundhara Volam struct hwrm_dbg_cmn_input *cmn_req = msg; 30226c5657d0SVasundhara Volam __le16 *seq_ptr = msg + info->seq_off; 30236c5657d0SVasundhara Volam u16 seq = 0, len, segs_off; 30246c5657d0SVasundhara Volam void *resp = cmn_resp; 30256c5657d0SVasundhara Volam dma_addr_t dma_handle; 30266c5657d0SVasundhara Volam int rc, off = 0; 30276c5657d0SVasundhara Volam void *dma_buf; 30286c5657d0SVasundhara Volam 30296c5657d0SVasundhara Volam dma_buf = dma_alloc_coherent(&bp->pdev->dev, info->dma_len, &dma_handle, 30306c5657d0SVasundhara Volam GFP_KERNEL); 30316c5657d0SVasundhara Volam if (!dma_buf) 30326c5657d0SVasundhara Volam return -ENOMEM; 30336c5657d0SVasundhara Volam 30346c5657d0SVasundhara Volam segs_off = offsetof(struct hwrm_dbg_coredump_list_output, 30356c5657d0SVasundhara Volam total_segments); 30366c5657d0SVasundhara Volam cmn_req->host_dest_addr = cpu_to_le64(dma_handle); 30376c5657d0SVasundhara Volam cmn_req->host_buf_len = cpu_to_le32(info->dma_len); 30386c5657d0SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 30396c5657d0SVasundhara Volam while (1) { 30406c5657d0SVasundhara Volam *seq_ptr = cpu_to_le16(seq); 30416c5657d0SVasundhara Volam rc = _hwrm_send_message(bp, msg, msg_len, HWRM_CMD_TIMEOUT); 30426c5657d0SVasundhara Volam if (rc) 30436c5657d0SVasundhara Volam break; 30446c5657d0SVasundhara Volam 30456c5657d0SVasundhara Volam len = le16_to_cpu(*((__le16 *)(resp + info->data_len_off))); 30466c5657d0SVasundhara Volam if (!seq && 30476c5657d0SVasundhara Volam cmn_req->req_type == cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) { 30486c5657d0SVasundhara Volam info->segs = le16_to_cpu(*((__le16 *)(resp + 30496c5657d0SVasundhara Volam segs_off))); 30506c5657d0SVasundhara Volam if (!info->segs) { 30516c5657d0SVasundhara Volam rc = -EIO; 30526c5657d0SVasundhara Volam break; 30536c5657d0SVasundhara Volam } 30546c5657d0SVasundhara Volam 30556c5657d0SVasundhara Volam info->dest_buf_size = info->segs * 30566c5657d0SVasundhara Volam sizeof(struct coredump_segment_record); 30576c5657d0SVasundhara Volam info->dest_buf = kmalloc(info->dest_buf_size, 30586c5657d0SVasundhara Volam GFP_KERNEL); 30596c5657d0SVasundhara Volam if (!info->dest_buf) { 30606c5657d0SVasundhara Volam rc = -ENOMEM; 30616c5657d0SVasundhara Volam break; 30626c5657d0SVasundhara Volam } 30636c5657d0SVasundhara Volam } 30646c5657d0SVasundhara Volam 30656c5657d0SVasundhara Volam if (info->dest_buf) 30666c5657d0SVasundhara Volam memcpy(info->dest_buf + off, dma_buf, len); 30676c5657d0SVasundhara Volam 30686c5657d0SVasundhara Volam if (cmn_req->req_type == 30696c5657d0SVasundhara Volam cpu_to_le16(HWRM_DBG_COREDUMP_RETRIEVE)) 30706c5657d0SVasundhara Volam info->dest_buf_size += len; 30716c5657d0SVasundhara Volam 30726c5657d0SVasundhara Volam if (!(cmn_resp->flags & HWRM_DBG_CMN_FLAGS_MORE)) 30736c5657d0SVasundhara Volam break; 30746c5657d0SVasundhara Volam 30756c5657d0SVasundhara Volam seq++; 30766c5657d0SVasundhara Volam off += len; 30776c5657d0SVasundhara Volam } 30786c5657d0SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 30796c5657d0SVasundhara Volam dma_free_coherent(&bp->pdev->dev, info->dma_len, dma_buf, dma_handle); 30806c5657d0SVasundhara Volam return rc; 30816c5657d0SVasundhara Volam } 30826c5657d0SVasundhara Volam 30836c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_list(struct bnxt *bp, 30846c5657d0SVasundhara Volam struct bnxt_coredump *coredump) 30856c5657d0SVasundhara Volam { 30866c5657d0SVasundhara Volam struct hwrm_dbg_coredump_list_input req = {0}; 30876c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 30886c5657d0SVasundhara Volam int rc; 30896c5657d0SVasundhara Volam 30906c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_LIST, -1, -1); 30916c5657d0SVasundhara Volam 30926c5657d0SVasundhara Volam info.dma_len = COREDUMP_LIST_BUF_LEN; 30936c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_list_input, seq_no); 30946c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_list_output, 30956c5657d0SVasundhara Volam data_len); 30966c5657d0SVasundhara Volam 30976c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 30986c5657d0SVasundhara Volam if (!rc) { 30996c5657d0SVasundhara Volam coredump->data = info.dest_buf; 31006c5657d0SVasundhara Volam coredump->data_size = info.dest_buf_size; 31016c5657d0SVasundhara Volam coredump->total_segs = info.segs; 31026c5657d0SVasundhara Volam } 31036c5657d0SVasundhara Volam return rc; 31046c5657d0SVasundhara Volam } 31056c5657d0SVasundhara Volam 31066c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_initiate(struct bnxt *bp, u16 component_id, 31076c5657d0SVasundhara Volam u16 segment_id) 31086c5657d0SVasundhara Volam { 31096c5657d0SVasundhara Volam struct hwrm_dbg_coredump_initiate_input req = {0}; 31106c5657d0SVasundhara Volam 31116c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_INITIATE, -1, -1); 31126c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 31136c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 31146c5657d0SVasundhara Volam 31156c5657d0SVasundhara Volam return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 31166c5657d0SVasundhara Volam } 31176c5657d0SVasundhara Volam 31186c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_retrieve(struct bnxt *bp, u16 component_id, 31196c5657d0SVasundhara Volam u16 segment_id, u32 *seg_len, 31206c5657d0SVasundhara Volam void *buf, u32 offset) 31216c5657d0SVasundhara Volam { 31226c5657d0SVasundhara Volam struct hwrm_dbg_coredump_retrieve_input req = {0}; 31236c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 31246c5657d0SVasundhara Volam int rc; 31256c5657d0SVasundhara Volam 31266c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_RETRIEVE, -1, -1); 31276c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 31286c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 31296c5657d0SVasundhara Volam 31306c5657d0SVasundhara Volam info.dma_len = COREDUMP_RETRIEVE_BUF_LEN; 31316c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_retrieve_input, 31326c5657d0SVasundhara Volam seq_no); 31336c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_retrieve_output, 31346c5657d0SVasundhara Volam data_len); 31356c5657d0SVasundhara Volam if (buf) 31366c5657d0SVasundhara Volam info.dest_buf = buf + offset; 31376c5657d0SVasundhara Volam 31386c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 31396c5657d0SVasundhara Volam if (!rc) 31406c5657d0SVasundhara Volam *seg_len = info.dest_buf_size; 31416c5657d0SVasundhara Volam 31426c5657d0SVasundhara Volam return rc; 31436c5657d0SVasundhara Volam } 31446c5657d0SVasundhara Volam 31456c5657d0SVasundhara Volam static void 31466c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(struct bnxt *bp, 31476c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr *seg_hdr, 31486c5657d0SVasundhara Volam struct coredump_segment_record *seg_rec, u32 seg_len, 31496c5657d0SVasundhara Volam int status, u32 duration, u32 instance) 31506c5657d0SVasundhara Volam { 31516c5657d0SVasundhara Volam memset(seg_hdr, 0, sizeof(*seg_hdr)); 31528605212aSVasundhara Volam memcpy(seg_hdr->signature, "sEgM", 4); 31536c5657d0SVasundhara Volam if (seg_rec) { 31546c5657d0SVasundhara Volam seg_hdr->component_id = (__force __le32)seg_rec->component_id; 31556c5657d0SVasundhara Volam seg_hdr->segment_id = (__force __le32)seg_rec->segment_id; 31566c5657d0SVasundhara Volam seg_hdr->low_version = seg_rec->version_low; 31576c5657d0SVasundhara Volam seg_hdr->high_version = seg_rec->version_hi; 31586c5657d0SVasundhara Volam } else { 31596c5657d0SVasundhara Volam /* For hwrm_ver_get response Component id = 2 31606c5657d0SVasundhara Volam * and Segment id = 0 31616c5657d0SVasundhara Volam */ 31626c5657d0SVasundhara Volam seg_hdr->component_id = cpu_to_le32(2); 31636c5657d0SVasundhara Volam seg_hdr->segment_id = 0; 31646c5657d0SVasundhara Volam } 31656c5657d0SVasundhara Volam seg_hdr->function_id = cpu_to_le16(bp->pdev->devfn); 31666c5657d0SVasundhara Volam seg_hdr->length = cpu_to_le32(seg_len); 31676c5657d0SVasundhara Volam seg_hdr->status = cpu_to_le32(status); 31686c5657d0SVasundhara Volam seg_hdr->duration = cpu_to_le32(duration); 31696c5657d0SVasundhara Volam seg_hdr->data_offset = cpu_to_le32(sizeof(*seg_hdr)); 31706c5657d0SVasundhara Volam seg_hdr->instance = cpu_to_le32(instance); 31716c5657d0SVasundhara Volam } 31726c5657d0SVasundhara Volam 31736c5657d0SVasundhara Volam static void 31746c5657d0SVasundhara Volam bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record, 31756c5657d0SVasundhara Volam time64_t start, s16 start_utc, u16 total_segs, 31766c5657d0SVasundhara Volam int status) 31776c5657d0SVasundhara Volam { 31786c5657d0SVasundhara Volam time64_t end = ktime_get_real_seconds(); 31796c5657d0SVasundhara Volam u32 os_ver_major = 0, os_ver_minor = 0; 31806c5657d0SVasundhara Volam struct tm tm; 31816c5657d0SVasundhara Volam 31826c5657d0SVasundhara Volam time64_to_tm(start, 0, &tm); 31836c5657d0SVasundhara Volam memset(record, 0, sizeof(*record)); 31848605212aSVasundhara Volam memcpy(record->signature, "cOrE", 4); 31856c5657d0SVasundhara Volam record->flags = 0; 31866c5657d0SVasundhara Volam record->low_version = 0; 31876c5657d0SVasundhara Volam record->high_version = 1; 31886c5657d0SVasundhara Volam record->asic_state = 0; 31893d46eee5SArnd Bergmann strlcpy(record->system_name, utsname()->nodename, 31903d46eee5SArnd Bergmann sizeof(record->system_name)); 31918dc5ae2dSVasundhara Volam record->year = cpu_to_le16(tm.tm_year + 1900); 31928dc5ae2dSVasundhara Volam record->month = cpu_to_le16(tm.tm_mon + 1); 31936c5657d0SVasundhara Volam record->day = cpu_to_le16(tm.tm_mday); 31946c5657d0SVasundhara Volam record->hour = cpu_to_le16(tm.tm_hour); 31956c5657d0SVasundhara Volam record->minute = cpu_to_le16(tm.tm_min); 31966c5657d0SVasundhara Volam record->second = cpu_to_le16(tm.tm_sec); 31976c5657d0SVasundhara Volam record->utc_bias = cpu_to_le16(start_utc); 31986c5657d0SVasundhara Volam strcpy(record->commandline, "ethtool -w"); 31996c5657d0SVasundhara Volam record->total_segments = cpu_to_le32(total_segs); 32006c5657d0SVasundhara Volam 32016c5657d0SVasundhara Volam sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor); 32026c5657d0SVasundhara Volam record->os_ver_major = cpu_to_le32(os_ver_major); 32036c5657d0SVasundhara Volam record->os_ver_minor = cpu_to_le32(os_ver_minor); 32046c5657d0SVasundhara Volam 32058605212aSVasundhara Volam strlcpy(record->os_name, utsname()->sysname, 32); 32066c5657d0SVasundhara Volam time64_to_tm(end, 0, &tm); 32076c5657d0SVasundhara Volam record->end_year = cpu_to_le16(tm.tm_year + 1900); 32086c5657d0SVasundhara Volam record->end_month = cpu_to_le16(tm.tm_mon + 1); 32096c5657d0SVasundhara Volam record->end_day = cpu_to_le16(tm.tm_mday); 32106c5657d0SVasundhara Volam record->end_hour = cpu_to_le16(tm.tm_hour); 32116c5657d0SVasundhara Volam record->end_minute = cpu_to_le16(tm.tm_min); 32126c5657d0SVasundhara Volam record->end_second = cpu_to_le16(tm.tm_sec); 32136c5657d0SVasundhara Volam record->end_utc_bias = cpu_to_le16(sys_tz.tz_minuteswest * 60); 32146c5657d0SVasundhara Volam record->asic_id1 = cpu_to_le32(bp->chip_num << 16 | 32156c5657d0SVasundhara Volam bp->ver_resp.chip_rev << 8 | 32166c5657d0SVasundhara Volam bp->ver_resp.chip_metal); 32176c5657d0SVasundhara Volam record->asic_id2 = 0; 32186c5657d0SVasundhara Volam record->coredump_status = cpu_to_le32(status); 32196c5657d0SVasundhara Volam record->ioctl_low_version = 0; 32206c5657d0SVasundhara Volam record->ioctl_high_version = 0; 32216c5657d0SVasundhara Volam } 32226c5657d0SVasundhara Volam 32236c5657d0SVasundhara Volam static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len) 32246c5657d0SVasundhara Volam { 32256c5657d0SVasundhara Volam u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output); 32266c5657d0SVasundhara Volam struct coredump_segment_record *seg_record = NULL; 32276c5657d0SVasundhara Volam u32 offset = 0, seg_hdr_len, seg_record_len; 32286c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr seg_hdr; 32296c5657d0SVasundhara Volam struct bnxt_coredump coredump = {NULL}; 32306c5657d0SVasundhara Volam time64_t start_time; 32316c5657d0SVasundhara Volam u16 start_utc; 32326c5657d0SVasundhara Volam int rc = 0, i; 32336c5657d0SVasundhara Volam 32346c5657d0SVasundhara Volam start_time = ktime_get_real_seconds(); 32356c5657d0SVasundhara Volam start_utc = sys_tz.tz_minuteswest * 60; 32366c5657d0SVasundhara Volam seg_hdr_len = sizeof(seg_hdr); 32376c5657d0SVasundhara Volam 32386c5657d0SVasundhara Volam /* First segment should be hwrm_ver_get response */ 32396c5657d0SVasundhara Volam *dump_len = seg_hdr_len + ver_get_resp_len; 32406c5657d0SVasundhara Volam if (buf) { 32416c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, NULL, ver_get_resp_len, 32426c5657d0SVasundhara Volam 0, 0, 0); 32436c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 32446c5657d0SVasundhara Volam offset += seg_hdr_len; 32456c5657d0SVasundhara Volam memcpy(buf + offset, &bp->ver_resp, ver_get_resp_len); 32466c5657d0SVasundhara Volam offset += ver_get_resp_len; 32476c5657d0SVasundhara Volam } 32486c5657d0SVasundhara Volam 32496c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_list(bp, &coredump); 32506c5657d0SVasundhara Volam if (rc) { 32516c5657d0SVasundhara Volam netdev_err(bp->dev, "Failed to get coredump segment list\n"); 32526c5657d0SVasundhara Volam goto err; 32536c5657d0SVasundhara Volam } 32546c5657d0SVasundhara Volam 32556c5657d0SVasundhara Volam *dump_len += seg_hdr_len * coredump.total_segs; 32566c5657d0SVasundhara Volam 32576c5657d0SVasundhara Volam seg_record = (struct coredump_segment_record *)coredump.data; 32586c5657d0SVasundhara Volam seg_record_len = sizeof(*seg_record); 32596c5657d0SVasundhara Volam 32606c5657d0SVasundhara Volam for (i = 0; i < coredump.total_segs; i++) { 32616c5657d0SVasundhara Volam u16 comp_id = le16_to_cpu(seg_record->component_id); 32626c5657d0SVasundhara Volam u16 seg_id = le16_to_cpu(seg_record->segment_id); 32636c5657d0SVasundhara Volam u32 duration = 0, seg_len = 0; 32646c5657d0SVasundhara Volam unsigned long start, end; 32656c5657d0SVasundhara Volam 32666c5657d0SVasundhara Volam start = jiffies; 32676c5657d0SVasundhara Volam 32686c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_initiate(bp, comp_id, seg_id); 32696c5657d0SVasundhara Volam if (rc) { 32706c5657d0SVasundhara Volam netdev_err(bp->dev, 32716c5657d0SVasundhara Volam "Failed to initiate coredump for seg = %d\n", 32726c5657d0SVasundhara Volam seg_record->segment_id); 32736c5657d0SVasundhara Volam goto next_seg; 32746c5657d0SVasundhara Volam } 32756c5657d0SVasundhara Volam 32766c5657d0SVasundhara Volam /* Write segment data into the buffer */ 32776c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_retrieve(bp, comp_id, seg_id, 32786c5657d0SVasundhara Volam &seg_len, buf, 32796c5657d0SVasundhara Volam offset + seg_hdr_len); 32806c5657d0SVasundhara Volam if (rc) 32816c5657d0SVasundhara Volam netdev_err(bp->dev, 32826c5657d0SVasundhara Volam "Failed to retrieve coredump for seg = %d\n", 32836c5657d0SVasundhara Volam seg_record->segment_id); 32846c5657d0SVasundhara Volam 32856c5657d0SVasundhara Volam next_seg: 32866c5657d0SVasundhara Volam end = jiffies; 32876c5657d0SVasundhara Volam duration = jiffies_to_msecs(end - start); 32886c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, seg_record, seg_len, 32896c5657d0SVasundhara Volam rc, duration, 0); 32906c5657d0SVasundhara Volam 32916c5657d0SVasundhara Volam if (buf) { 32926c5657d0SVasundhara Volam /* Write segment header into the buffer */ 32936c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 32946c5657d0SVasundhara Volam offset += seg_hdr_len + seg_len; 32956c5657d0SVasundhara Volam } 32966c5657d0SVasundhara Volam 32976c5657d0SVasundhara Volam *dump_len += seg_len; 32986c5657d0SVasundhara Volam seg_record = 32996c5657d0SVasundhara Volam (struct coredump_segment_record *)((u8 *)seg_record + 33006c5657d0SVasundhara Volam seg_record_len); 33016c5657d0SVasundhara Volam } 33026c5657d0SVasundhara Volam 33036c5657d0SVasundhara Volam err: 33041bbf3aedSArnd Bergmann if (buf) 33051bbf3aedSArnd Bergmann bnxt_fill_coredump_record(bp, buf + offset, start_time, 33066c5657d0SVasundhara Volam start_utc, coredump.total_segs + 1, 33076c5657d0SVasundhara Volam rc); 33086c5657d0SVasundhara Volam kfree(coredump.data); 33091bbf3aedSArnd Bergmann *dump_len += sizeof(struct bnxt_coredump_record); 33106c5657d0SVasundhara Volam 33116c5657d0SVasundhara Volam return rc; 33126c5657d0SVasundhara Volam } 33136c5657d0SVasundhara Volam 33146c5657d0SVasundhara Volam static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump) 33156c5657d0SVasundhara Volam { 33166c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 33176c5657d0SVasundhara Volam 33186c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 33196c5657d0SVasundhara Volam return -EOPNOTSUPP; 33206c5657d0SVasundhara Volam 33216c5657d0SVasundhara Volam dump->version = bp->ver_resp.hwrm_fw_maj_8b << 24 | 33226c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_min_8b << 16 | 33236c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_bld_8b << 8 | 33246c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_rsvd_8b; 33256c5657d0SVasundhara Volam 33266c5657d0SVasundhara Volam return bnxt_get_coredump(bp, NULL, &dump->len); 33276c5657d0SVasundhara Volam } 33286c5657d0SVasundhara Volam 33296c5657d0SVasundhara Volam static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump, 33306c5657d0SVasundhara Volam void *buf) 33316c5657d0SVasundhara Volam { 33326c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 33336c5657d0SVasundhara Volam 33346c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 33356c5657d0SVasundhara Volam return -EOPNOTSUPP; 33366c5657d0SVasundhara Volam 33376c5657d0SVasundhara Volam memset(buf, 0, dump->len); 33386c5657d0SVasundhara Volam 33396c5657d0SVasundhara Volam return bnxt_get_coredump(bp, buf, &dump->len); 33406c5657d0SVasundhara Volam } 33416c5657d0SVasundhara Volam 3342eb513658SMichael Chan void bnxt_ethtool_init(struct bnxt *bp) 3343eb513658SMichael Chan { 3344eb513658SMichael Chan struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr; 3345eb513658SMichael Chan struct hwrm_selftest_qlist_input req = {0}; 3346eb513658SMichael Chan struct bnxt_test_info *test_info; 3347431aa1ebSMichael Chan struct net_device *dev = bp->dev; 3348eb513658SMichael Chan int i, rc; 3349eb513658SMichael Chan 3350691aa620SVasundhara Volam if (!(bp->fw_cap & BNXT_FW_CAP_PKG_VER)) 3351a60faa60SVasundhara Volam bnxt_get_pkgver(dev); 3352431aa1ebSMichael Chan 3353ba642ab7SMichael Chan bp->num_tests = 0; 3354eb513658SMichael Chan if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp)) 3355eb513658SMichael Chan return; 3356eb513658SMichael Chan 3357eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1); 3358eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 3359eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 3360eb513658SMichael Chan if (rc) 3361eb513658SMichael Chan goto ethtool_init_exit; 3362eb513658SMichael Chan 3363ba642ab7SMichael Chan test_info = bp->test_info; 3364ba642ab7SMichael Chan if (!test_info) 3365eb513658SMichael Chan test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL); 3366eb513658SMichael Chan if (!test_info) 3367eb513658SMichael Chan goto ethtool_init_exit; 3368eb513658SMichael Chan 3369eb513658SMichael Chan bp->test_info = test_info; 3370eb513658SMichael Chan bp->num_tests = resp->num_tests + BNXT_DRV_TESTS; 3371eb513658SMichael Chan if (bp->num_tests > BNXT_MAX_TEST) 3372eb513658SMichael Chan bp->num_tests = BNXT_MAX_TEST; 3373eb513658SMichael Chan 3374eb513658SMichael Chan test_info->offline_mask = resp->offline_tests; 3375eb513658SMichael Chan test_info->timeout = le16_to_cpu(resp->test_timeout); 3376eb513658SMichael Chan if (!test_info->timeout) 3377eb513658SMichael Chan test_info->timeout = HWRM_CMD_TIMEOUT; 3378eb513658SMichael Chan for (i = 0; i < bp->num_tests; i++) { 3379eb513658SMichael Chan char *str = test_info->string[i]; 3380eb513658SMichael Chan char *fw_str = resp->test0_name + i * 32; 3381eb513658SMichael Chan 3382f7dc1ea6SMichael Chan if (i == BNXT_MACLPBK_TEST_IDX) { 3383f7dc1ea6SMichael Chan strcpy(str, "Mac loopback test (offline)"); 338491725d89SMichael Chan } else if (i == BNXT_PHYLPBK_TEST_IDX) { 338591725d89SMichael Chan strcpy(str, "Phy loopback test (offline)"); 338655fd0cf3SMichael Chan } else if (i == BNXT_EXTLPBK_TEST_IDX) { 338755fd0cf3SMichael Chan strcpy(str, "Ext loopback test (offline)"); 338867fea463SMichael Chan } else if (i == BNXT_IRQ_TEST_IDX) { 338967fea463SMichael Chan strcpy(str, "Interrupt_test (offline)"); 3390f7dc1ea6SMichael Chan } else { 3391eb513658SMichael Chan strlcpy(str, fw_str, ETH_GSTRING_LEN); 3392eb513658SMichael Chan strncat(str, " test", ETH_GSTRING_LEN - strlen(str)); 3393eb513658SMichael Chan if (test_info->offline_mask & (1 << i)) 3394eb513658SMichael Chan strncat(str, " (offline)", 3395eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3396eb513658SMichael Chan else 3397eb513658SMichael Chan strncat(str, " (online)", 3398eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3399eb513658SMichael Chan } 3400f7dc1ea6SMichael Chan } 3401eb513658SMichael Chan 3402eb513658SMichael Chan ethtool_init_exit: 3403eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 3404eb513658SMichael Chan } 3405eb513658SMichael Chan 3406eb513658SMichael Chan void bnxt_ethtool_free(struct bnxt *bp) 3407eb513658SMichael Chan { 3408eb513658SMichael Chan kfree(bp->test_info); 3409eb513658SMichael Chan bp->test_info = NULL; 3410eb513658SMichael Chan } 3411eb513658SMichael Chan 3412c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 341300c04a92SMichael Chan .get_link_ksettings = bnxt_get_link_ksettings, 341400c04a92SMichael Chan .set_link_ksettings = bnxt_set_link_ksettings, 3415c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 3416c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 3417c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 34188e202366SMichael Chan .get_wol = bnxt_get_wol, 34195282db6cSMichael Chan .set_wol = bnxt_set_wol, 3420c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 3421c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 3422c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 3423c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 3424c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 3425c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 3426c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 3427c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 3428c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 3429c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 3430c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 3431c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 3432a011952aSMichael Chan .set_rxnfc = bnxt_set_rxnfc, 3433c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 3434c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 3435c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 3436c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 3437c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 3438c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 3439c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 3440c0c050c5SMichael Chan .get_link = bnxt_get_link, 344172b34f04SMichael Chan .get_eee = bnxt_get_eee, 344272b34f04SMichael Chan .set_eee = bnxt_set_eee, 344342ee18feSAjit Khaparde .get_module_info = bnxt_get_module_info, 344442ee18feSAjit Khaparde .get_module_eeprom = bnxt_get_module_eeprom, 34455ad2cbeeSMichael Chan .nway_reset = bnxt_nway_reset, 34465ad2cbeeSMichael Chan .set_phys_id = bnxt_set_phys_id, 3447eb513658SMichael Chan .self_test = bnxt_self_test, 344849f7972fSVasundhara Volam .reset = bnxt_reset, 34496c5657d0SVasundhara Volam .get_dump_flag = bnxt_get_dump_flag, 34506c5657d0SVasundhara Volam .get_dump_data = bnxt_get_dump_data, 3451c0c050c5SMichael Chan }; 3452