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", 17619b3751fSMichael Chan "rx_buf_errors", 177ee79566eSMichael Chan "missed_irqs", 178ee79566eSMichael Chan }; 179c0c050c5SMichael Chan 1808ddc9aaaSMichael Chan #define BNXT_RX_STATS_ENTRY(counter) \ 1818ddc9aaaSMichael Chan { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) } 1828ddc9aaaSMichael Chan 1838ddc9aaaSMichael Chan #define BNXT_TX_STATS_ENTRY(counter) \ 1848ddc9aaaSMichael Chan { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) } 1858ddc9aaaSMichael Chan 18600db3cbaSVasundhara Volam #define BNXT_RX_STATS_EXT_ENTRY(counter) \ 18700db3cbaSVasundhara Volam { BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) } 18800db3cbaSVasundhara Volam 18936e53349SMichael Chan #define BNXT_TX_STATS_EXT_ENTRY(counter) \ 19036e53349SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter), __stringify(counter) } 19136e53349SMichael Chan 19236e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRY(n) \ 19336e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_duration_us), \ 19436e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_transitions) 19536e53349SMichael Chan 19636e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRY(n) \ 19736e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_duration_us), \ 19836e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_transitions) 19936e53349SMichael Chan 20036e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRIES \ 20136e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(0), \ 20236e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(1), \ 20336e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(2), \ 20436e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(3), \ 20536e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(4), \ 20636e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(5), \ 20736e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(6), \ 20836e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(7) 20936e53349SMichael Chan 21036e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRIES \ 21136e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(0), \ 21236e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(1), \ 21336e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(2), \ 21436e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(3), \ 21536e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(4), \ 21636e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(5), \ 21736e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(6), \ 21836e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(7) 21936e53349SMichael Chan 22036e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRY(n) \ 22136e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bytes_cos##n), \ 22236e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_packets_cos##n) 22336e53349SMichael Chan 22436e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRY(n) \ 22536e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_bytes_cos##n), \ 22636e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_packets_cos##n) 22736e53349SMichael Chan 22836e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRIES \ 22936e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(0), \ 23036e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(1), \ 23136e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(2), \ 23236e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(3), \ 23336e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(4), \ 23436e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(5), \ 23536e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(6), \ 23636e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(7) \ 23736e53349SMichael Chan 23836e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRIES \ 23936e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(0), \ 24036e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(1), \ 24136e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(2), \ 24236e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(3), \ 24336e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(4), \ 24436e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(5), \ 24536e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(6), \ 24636e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(7) \ 24736e53349SMichael Chan 2482792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(n) \ 2492792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_bytes_cos##n), \ 2502792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_packets_cos##n) 2512792b5b9SMichael Chan 2522792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES \ 2532792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(0), \ 2542792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(1), \ 2552792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(2), \ 2562792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(3), \ 2572792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(4), \ 2582792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(5), \ 2592792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(6), \ 2602792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(7) 2612792b5b9SMichael Chan 262e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRY(counter, n) \ 263e37fed79SMichael Chan { BNXT_RX_STATS_EXT_OFFSET(counter##_cos0), \ 264e37fed79SMichael Chan __stringify(counter##_pri##n) } 265e37fed79SMichael Chan 266e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRY(counter, n) \ 267e37fed79SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter##_cos0), \ 268e37fed79SMichael Chan __stringify(counter##_pri##n) } 269e37fed79SMichael Chan 270e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRIES(counter) \ 271e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 0), \ 272e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 1), \ 273e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 2), \ 274e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 3), \ 275e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 4), \ 276e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 5), \ 277e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 6), \ 278e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 7) 279e37fed79SMichael Chan 280e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRIES(counter) \ 281e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 0), \ 282e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 1), \ 283e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 2), \ 284e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 3), \ 285e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 4), \ 286e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 5), \ 287e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 6), \ 288e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 7) 289e37fed79SMichael Chan 29055e4398dSVasundhara Volam #define BNXT_PCIE_STATS_ENTRY(counter) \ 29155e4398dSVasundhara Volam { BNXT_PCIE_STATS_OFFSET(counter), __stringify(counter) } 29255e4398dSVasundhara Volam 29320c1d28eSVasundhara Volam enum { 29420c1d28eSVasundhara Volam RX_TOTAL_DISCARDS, 29520c1d28eSVasundhara Volam TX_TOTAL_DISCARDS, 29620c1d28eSVasundhara Volam }; 29720c1d28eSVasundhara Volam 29820c1d28eSVasundhara Volam static struct { 29920c1d28eSVasundhara Volam u64 counter; 30020c1d28eSVasundhara Volam char string[ETH_GSTRING_LEN]; 30120c1d28eSVasundhara Volam } bnxt_sw_func_stats[] = { 30220c1d28eSVasundhara Volam {0, "rx_total_discard_pkts"}, 30320c1d28eSVasundhara Volam {0, "tx_total_discard_pkts"}, 30420c1d28eSVasundhara Volam }; 30520c1d28eSVasundhara Volam 3068ddc9aaaSMichael Chan static const struct { 3078ddc9aaaSMichael Chan long offset; 3088ddc9aaaSMichael Chan char string[ETH_GSTRING_LEN]; 3098ddc9aaaSMichael Chan } bnxt_port_stats_arr[] = { 3108ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_64b_frames), 3118ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_65b_127b_frames), 3128ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_128b_255b_frames), 3138ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_256b_511b_frames), 3148ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames), 3156fc92c33SMichael Chan BNXT_RX_STATS_ENTRY(rx_1024b_1518b_frames), 3168ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_vlan_frames), 3178ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames), 3188ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames), 3198ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames), 3208ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames), 3218ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_total_frames), 3228ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ucast_frames), 3238ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mcast_frames), 3248ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bcast_frames), 3258ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_fcs_err_frames), 3268ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ctrl_frames), 3278ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pause_frames), 3288ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_frames), 3298ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_align_err_frames), 3308ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ovrsz_frames), 3318ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_jbr_frames), 3328ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mtu_err_frames), 3338ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_tagged_frames), 3348ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_double_tagged_frames), 3358ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_frames), 336c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0), 337c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1), 338c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2), 339c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3), 340c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4), 341c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5), 342c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6), 343c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7), 3448ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_undrsz_frames), 3458ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_events), 3468ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration), 3478ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bytes), 3488ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_bytes), 3498ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_frames), 350699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_discard), 351699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_err), 3528ddc9aaaSMichael Chan 3538ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_64b_frames), 3548ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_65b_127b_frames), 3558ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_128b_255b_frames), 3568ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_256b_511b_frames), 3578ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames), 3586fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1024b_1518b_frames), 3598ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_vlan_frames), 3606fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1519b_2047b_frames), 3618ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames), 3628ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames), 3638ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames), 3648ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_frames), 3658ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_frames), 3668ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_ucast_frames), 3678ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_mcast_frames), 3688ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bcast_frames), 3698ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pause_frames), 3708ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_frames), 3718ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_jabber_frames), 3728ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fcs_err_frames), 3738ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_err), 3748ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fifo_underruns), 375c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0), 376c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1), 377c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2), 378c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3), 379c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4), 380c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5), 381c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6), 382c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7), 3838ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_events), 3848ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration), 3858ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_collisions), 3868ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bytes), 387699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_xthol_frames), 388699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_discard), 389699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_error), 3908ddc9aaaSMichael Chan }; 3918ddc9aaaSMichael Chan 39200db3cbaSVasundhara Volam static const struct { 39300db3cbaSVasundhara Volam long offset; 39400db3cbaSVasundhara Volam char string[ETH_GSTRING_LEN]; 39500db3cbaSVasundhara Volam } bnxt_port_stats_ext_arr[] = { 39600db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(link_down_events), 39700db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events), 39800db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_pause_events), 39900db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events), 40000db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events), 40136e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRIES, 40236e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRIES, 4034a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bits), 4044a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_buffer_passed_threshold), 4054a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_pcs_symbol_err), 4064a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_corrected_bits), 4072792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES, 40836e53349SMichael Chan }; 40936e53349SMichael Chan 41036e53349SMichael Chan static const struct { 41136e53349SMichael Chan long offset; 41236e53349SMichael Chan char string[ETH_GSTRING_LEN]; 41336e53349SMichael Chan } bnxt_tx_port_stats_ext_arr[] = { 41436e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRIES, 41536e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRIES, 41600db3cbaSVasundhara Volam }; 41700db3cbaSVasundhara Volam 418e37fed79SMichael Chan static const struct { 419e37fed79SMichael Chan long base_off; 420e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 421e37fed79SMichael Chan } bnxt_rx_bytes_pri_arr[] = { 422e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_bytes), 423e37fed79SMichael Chan }; 424e37fed79SMichael Chan 425e37fed79SMichael Chan static const struct { 426e37fed79SMichael Chan long base_off; 427e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 428e37fed79SMichael Chan } bnxt_rx_pkts_pri_arr[] = { 429e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_packets), 430e37fed79SMichael Chan }; 431e37fed79SMichael Chan 432e37fed79SMichael Chan static const struct { 433e37fed79SMichael Chan long base_off; 434e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 435e37fed79SMichael Chan } bnxt_tx_bytes_pri_arr[] = { 436e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_bytes), 437e37fed79SMichael Chan }; 438e37fed79SMichael Chan 439e37fed79SMichael Chan static const struct { 440e37fed79SMichael Chan long base_off; 441e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 442e37fed79SMichael Chan } bnxt_tx_pkts_pri_arr[] = { 443e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_packets), 444e37fed79SMichael Chan }; 445e37fed79SMichael Chan 44655e4398dSVasundhara Volam static const struct { 44755e4398dSVasundhara Volam long offset; 44855e4398dSVasundhara Volam char string[ETH_GSTRING_LEN]; 44955e4398dSVasundhara Volam } bnxt_pcie_stats_arr[] = { 45055e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_pl_signal_integrity), 45155e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_dl_signal_integrity), 45255e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tl_signal_integrity), 45355e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_link_integrity), 45455e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tx_traffic_rate), 45555e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_rx_traffic_rate), 45655e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tx_dllp_statistics), 45755e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_rx_dllp_statistics), 45855e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_equalization_time), 45955e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[0]), 46055e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[2]), 46155e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_recovery_histogram), 46255e4398dSVasundhara Volam }; 46355e4398dSVasundhara Volam 46420c1d28eSVasundhara Volam #define BNXT_NUM_SW_FUNC_STATS ARRAY_SIZE(bnxt_sw_func_stats) 4658ddc9aaaSMichael Chan #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr) 466e37fed79SMichael Chan #define BNXT_NUM_STATS_PRI \ 467e37fed79SMichael Chan (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \ 468e37fed79SMichael Chan ARRAY_SIZE(bnxt_rx_pkts_pri_arr) + \ 469e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_bytes_pri_arr) + \ 470e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_pkts_pri_arr)) 47155e4398dSVasundhara Volam #define BNXT_NUM_PCIE_STATS ARRAY_SIZE(bnxt_pcie_stats_arr) 4728ddc9aaaSMichael Chan 47378e7b866SMichael Chan static int bnxt_get_num_tpa_ring_stats(struct bnxt *bp) 47478e7b866SMichael Chan { 47578e7b866SMichael Chan if (BNXT_SUPPORTS_TPA(bp)) { 47678e7b866SMichael Chan if (bp->max_tpa_v2) 47778e7b866SMichael Chan return ARRAY_SIZE(bnxt_ring_tpa2_stats_str); 47878e7b866SMichael Chan return ARRAY_SIZE(bnxt_ring_tpa_stats_str); 47978e7b866SMichael Chan } 48078e7b866SMichael Chan return 0; 48178e7b866SMichael Chan } 48278e7b866SMichael Chan 483ee79566eSMichael Chan static int bnxt_get_num_ring_stats(struct bnxt *bp) 484ee79566eSMichael Chan { 485ee79566eSMichael Chan int num_stats; 486ee79566eSMichael Chan 487ee79566eSMichael Chan num_stats = ARRAY_SIZE(bnxt_ring_stats_str) + 48878e7b866SMichael Chan ARRAY_SIZE(bnxt_ring_sw_stats_str) + 48978e7b866SMichael Chan bnxt_get_num_tpa_ring_stats(bp); 490ee79566eSMichael Chan return num_stats * bp->cp_nr_rings; 491ee79566eSMichael Chan } 492ee79566eSMichael Chan 4935c8227d0SMichael Chan static int bnxt_get_num_stats(struct bnxt *bp) 494c0c050c5SMichael Chan { 495ee79566eSMichael Chan int num_stats = bnxt_get_num_ring_stats(bp); 4968ddc9aaaSMichael Chan 49720c1d28eSVasundhara Volam num_stats += BNXT_NUM_SW_FUNC_STATS; 49820c1d28eSVasundhara Volam 4998ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) 5008ddc9aaaSMichael Chan num_stats += BNXT_NUM_PORT_STATS; 5018ddc9aaaSMichael Chan 502e37fed79SMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 50336e53349SMichael Chan num_stats += bp->fw_rx_stats_ext_size + 50436e53349SMichael Chan bp->fw_tx_stats_ext_size; 505e37fed79SMichael Chan if (bp->pri2cos_valid) 506e37fed79SMichael Chan num_stats += BNXT_NUM_STATS_PRI; 507e37fed79SMichael Chan } 50800db3cbaSVasundhara Volam 50955e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) 51055e4398dSVasundhara Volam num_stats += BNXT_NUM_PCIE_STATS; 51155e4398dSVasundhara Volam 5128ddc9aaaSMichael Chan return num_stats; 5138ddc9aaaSMichael Chan } 5145c8227d0SMichael Chan 5155c8227d0SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 5165c8227d0SMichael Chan { 5175c8227d0SMichael Chan struct bnxt *bp = netdev_priv(dev); 5185c8227d0SMichael Chan 5195c8227d0SMichael Chan switch (sset) { 5205c8227d0SMichael Chan case ETH_SS_STATS: 5215c8227d0SMichael Chan return bnxt_get_num_stats(bp); 522eb513658SMichael Chan case ETH_SS_TEST: 523eb513658SMichael Chan if (!bp->num_tests) 524eb513658SMichael Chan return -EOPNOTSUPP; 525eb513658SMichael Chan return bp->num_tests; 526c0c050c5SMichael Chan default: 527c0c050c5SMichael Chan return -EOPNOTSUPP; 528c0c050c5SMichael Chan } 529c0c050c5SMichael Chan } 530c0c050c5SMichael Chan 531c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 532c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 533c0c050c5SMichael Chan { 534c0c050c5SMichael Chan u32 i, j = 0; 535c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 53678e7b866SMichael Chan u32 stat_fields = ARRAY_SIZE(bnxt_ring_stats_str) + 53778e7b866SMichael Chan bnxt_get_num_tpa_ring_stats(bp); 538c0c050c5SMichael Chan 539fd3ab1c7SMichael Chan if (!bp->bnapi) { 540ee79566eSMichael Chan j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS; 541fd3ab1c7SMichael Chan goto skip_ring_stats; 542fd3ab1c7SMichael Chan } 543c0c050c5SMichael Chan 54420c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) 54520c1d28eSVasundhara Volam bnxt_sw_func_stats[i].counter = 0; 54620c1d28eSVasundhara Volam 547c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 548c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 549c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 550c0c050c5SMichael Chan __le64 *hw_stats = (__le64 *)cpr->hw_stats; 551c0c050c5SMichael Chan int k; 552c0c050c5SMichael Chan 553c0c050c5SMichael Chan for (k = 0; k < stat_fields; j++, k++) 554c0c050c5SMichael Chan buf[j] = le64_to_cpu(hw_stats[k]); 555c0c050c5SMichael Chan buf[j++] = cpr->rx_l4_csum_errors; 55619b3751fSMichael Chan buf[j++] = cpr->rx_buf_errors; 55783eb5c5cSMichael Chan buf[j++] = cpr->missed_irqs; 55820c1d28eSVasundhara Volam 55920c1d28eSVasundhara Volam bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter += 56020c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->rx_discard_pkts); 56120c1d28eSVasundhara Volam bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter += 56220c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->tx_discard_pkts); 563c0c050c5SMichael Chan } 56420c1d28eSVasundhara Volam 56520c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++) 56620c1d28eSVasundhara Volam buf[j] = bnxt_sw_func_stats[i].counter; 56720c1d28eSVasundhara Volam 568fd3ab1c7SMichael Chan skip_ring_stats: 5698ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 5708ddc9aaaSMichael Chan __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats; 5718ddc9aaaSMichael Chan 5728ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) { 5738ddc9aaaSMichael Chan buf[j] = le64_to_cpu(*(port_stats + 5748ddc9aaaSMichael Chan bnxt_port_stats_arr[i].offset)); 5758ddc9aaaSMichael Chan } 5768ddc9aaaSMichael Chan } 57700db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 57836e53349SMichael Chan __le64 *rx_port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext; 57936e53349SMichael Chan __le64 *tx_port_stats_ext = (__le64 *)bp->hw_tx_port_stats_ext; 58000db3cbaSVasundhara Volam 58136e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) { 58236e53349SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + 58300db3cbaSVasundhara Volam bnxt_port_stats_ext_arr[i].offset)); 58400db3cbaSVasundhara Volam } 58536e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++, j++) { 58636e53349SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + 58736e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].offset)); 58836e53349SMichael Chan } 589e37fed79SMichael Chan if (bp->pri2cos_valid) { 590e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 591e37fed79SMichael Chan long n = bnxt_rx_bytes_pri_arr[i].base_off + 592e37fed79SMichael Chan bp->pri2cos[i]; 593e37fed79SMichael Chan 594e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 595e37fed79SMichael Chan } 596e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 597e37fed79SMichael Chan long n = bnxt_rx_pkts_pri_arr[i].base_off + 598e37fed79SMichael Chan bp->pri2cos[i]; 599e37fed79SMichael Chan 600e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 601e37fed79SMichael Chan } 602e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 603e37fed79SMichael Chan long n = bnxt_tx_bytes_pri_arr[i].base_off + 604e37fed79SMichael Chan bp->pri2cos[i]; 605e37fed79SMichael Chan 606e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 607e37fed79SMichael Chan } 608e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 609e37fed79SMichael Chan long n = bnxt_tx_pkts_pri_arr[i].base_off + 610e37fed79SMichael Chan bp->pri2cos[i]; 611e37fed79SMichael Chan 612e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 613e37fed79SMichael Chan } 614e37fed79SMichael Chan } 61500db3cbaSVasundhara Volam } 61655e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) { 61755e4398dSVasundhara Volam __le64 *pcie_stats = (__le64 *)bp->hw_pcie_stats; 61855e4398dSVasundhara Volam 61955e4398dSVasundhara Volam for (i = 0; i < BNXT_NUM_PCIE_STATS; i++, j++) { 62055e4398dSVasundhara Volam buf[j] = le64_to_cpu(*(pcie_stats + 62155e4398dSVasundhara Volam bnxt_pcie_stats_arr[i].offset)); 62255e4398dSVasundhara Volam } 62355e4398dSVasundhara Volam } 624c0c050c5SMichael Chan } 625c0c050c5SMichael Chan 626c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 627c0c050c5SMichael Chan { 628c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 62978e7b866SMichael Chan static const char * const *str; 630ee79566eSMichael Chan u32 i, j, num_str; 631c0c050c5SMichael Chan 632c0c050c5SMichael Chan switch (stringset) { 633c0c050c5SMichael Chan case ETH_SS_STATS: 634c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 635ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_stats_str); 636ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 637ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 638ee79566eSMichael Chan bnxt_ring_stats_str[j]); 639c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 640ee79566eSMichael Chan } 641ee79566eSMichael Chan if (!BNXT_SUPPORTS_TPA(bp)) 642ee79566eSMichael Chan goto skip_tpa_stats; 643ee79566eSMichael Chan 64478e7b866SMichael Chan if (bp->max_tpa_v2) { 64578e7b866SMichael Chan num_str = ARRAY_SIZE(bnxt_ring_tpa2_stats_str); 64678e7b866SMichael Chan str = bnxt_ring_tpa2_stats_str; 64778e7b866SMichael Chan } else { 648ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_tpa_stats_str); 64978e7b866SMichael Chan str = bnxt_ring_tpa_stats_str; 65078e7b866SMichael Chan } 651ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 65278e7b866SMichael Chan sprintf(buf, "[%d]: %s", i, str[j]); 653c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 654ee79566eSMichael Chan } 655ee79566eSMichael Chan skip_tpa_stats: 656ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_sw_stats_str); 657ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 658ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 659ee79566eSMichael Chan bnxt_ring_sw_stats_str[j]); 660c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 661ee79566eSMichael Chan } 662c0c050c5SMichael Chan } 66320c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) { 66420c1d28eSVasundhara Volam strcpy(buf, bnxt_sw_func_stats[i].string); 66520c1d28eSVasundhara Volam buf += ETH_GSTRING_LEN; 66620c1d28eSVasundhara Volam } 66720c1d28eSVasundhara Volam 6688ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 6698ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++) { 6708ddc9aaaSMichael Chan strcpy(buf, bnxt_port_stats_arr[i].string); 6718ddc9aaaSMichael Chan buf += ETH_GSTRING_LEN; 6728ddc9aaaSMichael Chan } 6738ddc9aaaSMichael Chan } 67400db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 67536e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++) { 67600db3cbaSVasundhara Volam strcpy(buf, bnxt_port_stats_ext_arr[i].string); 67700db3cbaSVasundhara Volam buf += ETH_GSTRING_LEN; 67800db3cbaSVasundhara Volam } 67936e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++) { 68036e53349SMichael Chan strcpy(buf, 68136e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].string); 68236e53349SMichael Chan buf += ETH_GSTRING_LEN; 68336e53349SMichael Chan } 684e37fed79SMichael Chan if (bp->pri2cos_valid) { 685e37fed79SMichael Chan for (i = 0; i < 8; i++) { 686e37fed79SMichael Chan strcpy(buf, 687e37fed79SMichael Chan bnxt_rx_bytes_pri_arr[i].string); 688e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 689e37fed79SMichael Chan } 690e37fed79SMichael Chan for (i = 0; i < 8; i++) { 691e37fed79SMichael Chan strcpy(buf, 692e37fed79SMichael Chan bnxt_rx_pkts_pri_arr[i].string); 693e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 694e37fed79SMichael Chan } 695e37fed79SMichael Chan for (i = 0; i < 8; i++) { 696e37fed79SMichael Chan strcpy(buf, 697e37fed79SMichael Chan bnxt_tx_bytes_pri_arr[i].string); 698e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 699e37fed79SMichael Chan } 700e37fed79SMichael Chan for (i = 0; i < 8; i++) { 701e37fed79SMichael Chan strcpy(buf, 702e37fed79SMichael Chan bnxt_tx_pkts_pri_arr[i].string); 703e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 704e37fed79SMichael Chan } 705e37fed79SMichael Chan } 70600db3cbaSVasundhara Volam } 70755e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) { 70855e4398dSVasundhara Volam for (i = 0; i < BNXT_NUM_PCIE_STATS; i++) { 70955e4398dSVasundhara Volam strcpy(buf, bnxt_pcie_stats_arr[i].string); 71055e4398dSVasundhara Volam buf += ETH_GSTRING_LEN; 71155e4398dSVasundhara Volam } 71255e4398dSVasundhara Volam } 713c0c050c5SMichael Chan break; 714eb513658SMichael Chan case ETH_SS_TEST: 715eb513658SMichael Chan if (bp->num_tests) 716eb513658SMichael Chan memcpy(buf, bp->test_info->string, 717eb513658SMichael Chan bp->num_tests * ETH_GSTRING_LEN); 718eb513658SMichael Chan break; 719c0c050c5SMichael Chan default: 720c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 721c0c050c5SMichael Chan stringset); 722c0c050c5SMichael Chan break; 723c0c050c5SMichael Chan } 724c0c050c5SMichael Chan } 725c0c050c5SMichael Chan 726c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 727c0c050c5SMichael Chan struct ethtool_ringparam *ering) 728c0c050c5SMichael Chan { 729c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 730c0c050c5SMichael Chan 731c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 732c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 733c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 734c0c050c5SMichael Chan 735c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 736c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 737c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 738c0c050c5SMichael Chan } 739c0c050c5SMichael Chan 740c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 741c0c050c5SMichael Chan struct ethtool_ringparam *ering) 742c0c050c5SMichael Chan { 743c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 744c0c050c5SMichael Chan 745c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 746c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 747c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 748c0c050c5SMichael Chan return -EINVAL; 749c0c050c5SMichael Chan 750c0c050c5SMichael Chan if (netif_running(dev)) 751c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 752c0c050c5SMichael Chan 753c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 754c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 755c0c050c5SMichael Chan bnxt_set_ring_params(bp); 756c0c050c5SMichael Chan 757c0c050c5SMichael Chan if (netif_running(dev)) 758c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 759c0c050c5SMichael Chan 760c0c050c5SMichael Chan return 0; 761c0c050c5SMichael Chan } 762c0c050c5SMichael Chan 763c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 764c0c050c5SMichael Chan struct ethtool_channels *channel) 765c0c050c5SMichael Chan { 766c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 767db4723b3SMichael Chan struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 768c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 769db4723b3SMichael Chan int max_tx_sch_inputs; 770db4723b3SMichael Chan 771db4723b3SMichael Chan /* Get the most up-to-date max_tx_sch_inputs. */ 772f1ca94deSMichael Chan if (BNXT_NEW_RM(bp)) 773db4723b3SMichael Chan bnxt_hwrm_func_resc_qcaps(bp, false); 774db4723b3SMichael Chan max_tx_sch_inputs = hw_resc->max_tx_sch_inputs; 775c0c050c5SMichael Chan 7766e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 777db4723b3SMichael Chan if (max_tx_sch_inputs) 778db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 779a79a5276SMichael Chan channel->max_combined = min_t(int, max_rx_rings, max_tx_rings); 780068c9ec6SMichael Chan 78118d6e4e2SSatish Baddipadige if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) { 78218d6e4e2SSatish Baddipadige max_rx_rings = 0; 78318d6e4e2SSatish Baddipadige max_tx_rings = 0; 78418d6e4e2SSatish Baddipadige } 785db4723b3SMichael Chan if (max_tx_sch_inputs) 786db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 78718d6e4e2SSatish Baddipadige 788c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 789c0c050c5SMichael Chan if (tcs > 1) 790c0c050c5SMichael Chan max_tx_rings /= tcs; 791c0c050c5SMichael Chan 792c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 793c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 794c0c050c5SMichael Chan channel->max_other = 0; 795068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 796068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 79776595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp)) 79876595193SPrashant Sreedharan channel->combined_count--; 799068c9ec6SMichael Chan } else { 80076595193SPrashant Sreedharan if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) { 801c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 802c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 803c0c050c5SMichael Chan } 804068c9ec6SMichael Chan } 80576595193SPrashant Sreedharan } 806c0c050c5SMichael Chan 807c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 808c0c050c5SMichael Chan struct ethtool_channels *channel) 809c0c050c5SMichael Chan { 810c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 811d1e7925eSMichael Chan int req_tx_rings, req_rx_rings, tcs; 812068c9ec6SMichael Chan bool sh = false; 8135f449249SMichael Chan int tx_xdp = 0; 814d1e7925eSMichael Chan int rc = 0; 815c0c050c5SMichael Chan 816068c9ec6SMichael Chan if (channel->other_count) 817c0c050c5SMichael Chan return -EINVAL; 818c0c050c5SMichael Chan 819068c9ec6SMichael Chan if (!channel->combined_count && 820068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 821068c9ec6SMichael Chan return -EINVAL; 822068c9ec6SMichael Chan 823068c9ec6SMichael Chan if (channel->combined_count && 824068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 825068c9ec6SMichael Chan return -EINVAL; 826068c9ec6SMichael Chan 82776595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count || 82876595193SPrashant Sreedharan channel->tx_count)) 82976595193SPrashant Sreedharan return -EINVAL; 83076595193SPrashant Sreedharan 831068c9ec6SMichael Chan if (channel->combined_count) 832068c9ec6SMichael Chan sh = true; 833068c9ec6SMichael Chan 834c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 835c0c050c5SMichael Chan 836391be5c2SMichael Chan req_tx_rings = sh ? channel->combined_count : channel->tx_count; 837d1e7925eSMichael Chan req_rx_rings = sh ? channel->combined_count : channel->rx_count; 8385f449249SMichael Chan if (bp->tx_nr_rings_xdp) { 8395f449249SMichael Chan if (!sh) { 8405f449249SMichael Chan netdev_err(dev, "Only combined mode supported when XDP is enabled.\n"); 8415f449249SMichael Chan return -EINVAL; 8425f449249SMichael Chan } 8435f449249SMichael Chan tx_xdp = req_rx_rings; 8445f449249SMichael Chan } 84598fdbe73SMichael Chan rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp); 846d1e7925eSMichael Chan if (rc) { 847d1e7925eSMichael Chan netdev_warn(dev, "Unable to allocate the requested rings\n"); 848d1e7925eSMichael Chan return rc; 849391be5c2SMichael Chan } 850391be5c2SMichael Chan 851c0c050c5SMichael Chan if (netif_running(dev)) { 852c0c050c5SMichael Chan if (BNXT_PF(bp)) { 853c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 854c0c050c5SMichael Chan * before PF unload 855c0c050c5SMichael Chan */ 856c0c050c5SMichael Chan } 857c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 858c0c050c5SMichael Chan if (rc) { 859c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 860c0c050c5SMichael Chan rc); 861c0c050c5SMichael Chan return rc; 862c0c050c5SMichael Chan } 863c0c050c5SMichael Chan } 864c0c050c5SMichael Chan 865068c9ec6SMichael Chan if (sh) { 866068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 867d1e7925eSMichael Chan bp->rx_nr_rings = channel->combined_count; 868d1e7925eSMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 869068c9ec6SMichael Chan } else { 870068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 871c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 872c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 873068c9ec6SMichael Chan } 8745f449249SMichael Chan bp->tx_nr_rings_xdp = tx_xdp; 8755f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp; 876c0c050c5SMichael Chan if (tcs > 1) 8775f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp; 878068c9ec6SMichael Chan 879068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 880068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 881068c9ec6SMichael Chan 8822bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 8832bcfa6f6SMichael Chan netdev_update_features(dev); 884c0c050c5SMichael Chan if (netif_running(dev)) { 885c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 886c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 887c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 888c0c050c5SMichael Chan * to renable 889c0c050c5SMichael Chan */ 890c0c050c5SMichael Chan } 891d8c09f19SMichael Chan } else { 8921b3f0b75SMichael Chan rc = bnxt_reserve_rings(bp, true); 893c0c050c5SMichael Chan } 894c0c050c5SMichael Chan 895c0c050c5SMichael Chan return rc; 896c0c050c5SMichael Chan } 897c0c050c5SMichael Chan 898c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 899c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 900c0c050c5SMichael Chan u32 *rule_locs) 901c0c050c5SMichael Chan { 902c0c050c5SMichael Chan int i, j = 0; 903c0c050c5SMichael Chan 904c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 905c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 906c0c050c5SMichael Chan struct hlist_head *head; 907c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 908c0c050c5SMichael Chan 909c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 910c0c050c5SMichael Chan rcu_read_lock(); 911c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 912c0c050c5SMichael Chan if (j == cmd->rule_cnt) 913c0c050c5SMichael Chan break; 914c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 915c0c050c5SMichael Chan } 916c0c050c5SMichael Chan rcu_read_unlock(); 917c0c050c5SMichael Chan if (j == cmd->rule_cnt) 918c0c050c5SMichael Chan break; 919c0c050c5SMichael Chan } 920c0c050c5SMichael Chan cmd->rule_cnt = j; 921c0c050c5SMichael Chan return 0; 922c0c050c5SMichael Chan } 923c0c050c5SMichael Chan 924c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 925c0c050c5SMichael Chan { 926c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 927c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 928c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 929c0c050c5SMichael Chan struct flow_keys *fkeys; 930c0c050c5SMichael Chan int i, rc = -EINVAL; 931c0c050c5SMichael Chan 932b721cfafSstephen hemminger if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 933c0c050c5SMichael Chan return rc; 934c0c050c5SMichael Chan 935c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 936c0c050c5SMichael Chan struct hlist_head *head; 937c0c050c5SMichael Chan 938c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 939c0c050c5SMichael Chan rcu_read_lock(); 940c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 941c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 942c0c050c5SMichael Chan goto fltr_found; 943c0c050c5SMichael Chan } 944c0c050c5SMichael Chan rcu_read_unlock(); 945c0c050c5SMichael Chan } 946c0c050c5SMichael Chan return rc; 947c0c050c5SMichael Chan 948c0c050c5SMichael Chan fltr_found: 949c0c050c5SMichael Chan fkeys = &fltr->fkeys; 950dda0e746SMichael Chan if (fkeys->basic.n_proto == htons(ETH_P_IP)) { 951c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 952c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 953c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 954c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 955c0c050c5SMichael Chan else 956c0c050c5SMichael Chan goto fltr_err; 957c0c050c5SMichael Chan 958c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 959c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 960c0c050c5SMichael Chan 961c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 962c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 963c0c050c5SMichael Chan 964c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 965c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 966c0c050c5SMichael Chan 967c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 968c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 969dda0e746SMichael Chan } else { 970dda0e746SMichael Chan int i; 971dda0e746SMichael Chan 972dda0e746SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 973dda0e746SMichael Chan fs->flow_type = TCP_V6_FLOW; 974dda0e746SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 975dda0e746SMichael Chan fs->flow_type = UDP_V6_FLOW; 976dda0e746SMichael Chan else 977dda0e746SMichael Chan goto fltr_err; 978dda0e746SMichael Chan 979dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] = 980dda0e746SMichael Chan fkeys->addrs.v6addrs.src; 981dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] = 982dda0e746SMichael Chan fkeys->addrs.v6addrs.dst; 983dda0e746SMichael Chan for (i = 0; i < 4; i++) { 984dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0); 985dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0); 986dda0e746SMichael Chan } 987dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src; 988dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0); 989dda0e746SMichael Chan 990dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst; 991dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0); 992dda0e746SMichael Chan } 993c0c050c5SMichael Chan 994c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 995c0c050c5SMichael Chan rc = 0; 996c0c050c5SMichael Chan 997c0c050c5SMichael Chan fltr_err: 998c0c050c5SMichael Chan rcu_read_unlock(); 999c0c050c5SMichael Chan 1000c0c050c5SMichael Chan return rc; 1001c0c050c5SMichael Chan } 1002a011952aSMichael Chan #endif 1003a011952aSMichael Chan 1004a011952aSMichael Chan static u64 get_ethtool_ipv4_rss(struct bnxt *bp) 1005a011952aSMichael Chan { 1006a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4) 1007a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 1008a011952aSMichael Chan return 0; 1009a011952aSMichael Chan } 1010a011952aSMichael Chan 1011a011952aSMichael Chan static u64 get_ethtool_ipv6_rss(struct bnxt *bp) 1012a011952aSMichael Chan { 1013a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6) 1014a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 1015a011952aSMichael Chan return 0; 1016a011952aSMichael Chan } 1017a011952aSMichael Chan 1018a011952aSMichael Chan static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1019a011952aSMichael Chan { 1020a011952aSMichael Chan cmd->data = 0; 1021a011952aSMichael Chan switch (cmd->flow_type) { 1022a011952aSMichael Chan case TCP_V4_FLOW: 1023a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) 1024a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1025a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1026a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1027a011952aSMichael Chan break; 1028a011952aSMichael Chan case UDP_V4_FLOW: 1029a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4) 1030a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1031a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1032a011952aSMichael Chan /* fall through */ 1033a011952aSMichael Chan case SCTP_V4_FLOW: 1034a011952aSMichael Chan case AH_ESP_V4_FLOW: 1035a011952aSMichael Chan case AH_V4_FLOW: 1036a011952aSMichael Chan case ESP_V4_FLOW: 1037a011952aSMichael Chan case IPV4_FLOW: 1038a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1039a011952aSMichael Chan break; 1040a011952aSMichael Chan 1041a011952aSMichael Chan case TCP_V6_FLOW: 1042a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) 1043a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1044a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1045a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1046a011952aSMichael Chan break; 1047a011952aSMichael Chan case UDP_V6_FLOW: 1048a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6) 1049a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1050a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1051a011952aSMichael Chan /* fall through */ 1052a011952aSMichael Chan case SCTP_V6_FLOW: 1053a011952aSMichael Chan case AH_ESP_V6_FLOW: 1054a011952aSMichael Chan case AH_V6_FLOW: 1055a011952aSMichael Chan case ESP_V6_FLOW: 1056a011952aSMichael Chan case IPV6_FLOW: 1057a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1058a011952aSMichael Chan break; 1059a011952aSMichael Chan } 1060a011952aSMichael Chan return 0; 1061a011952aSMichael Chan } 1062a011952aSMichael Chan 1063a011952aSMichael Chan #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3) 1064a011952aSMichael Chan #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST) 1065a011952aSMichael Chan 1066a011952aSMichael Chan static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1067a011952aSMichael Chan { 1068a011952aSMichael Chan u32 rss_hash_cfg = bp->rss_hash_cfg; 1069a011952aSMichael Chan int tuple, rc = 0; 1070a011952aSMichael Chan 1071a011952aSMichael Chan if (cmd->data == RXH_4TUPLE) 1072a011952aSMichael Chan tuple = 4; 1073a011952aSMichael Chan else if (cmd->data == RXH_2TUPLE) 1074a011952aSMichael Chan tuple = 2; 1075a011952aSMichael Chan else if (!cmd->data) 1076a011952aSMichael Chan tuple = 0; 1077a011952aSMichael Chan else 1078a011952aSMichael Chan return -EINVAL; 1079a011952aSMichael Chan 1080a011952aSMichael Chan if (cmd->flow_type == TCP_V4_FLOW) { 1081a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1082a011952aSMichael Chan if (tuple == 4) 1083a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1084a011952aSMichael Chan } else if (cmd->flow_type == UDP_V4_FLOW) { 1085a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1086a011952aSMichael Chan return -EINVAL; 1087a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1088a011952aSMichael Chan if (tuple == 4) 1089a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1090a011952aSMichael Chan } else if (cmd->flow_type == TCP_V6_FLOW) { 1091a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1092a011952aSMichael Chan if (tuple == 4) 1093a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1094a011952aSMichael Chan } else if (cmd->flow_type == UDP_V6_FLOW) { 1095a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1096a011952aSMichael Chan return -EINVAL; 1097a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1098a011952aSMichael Chan if (tuple == 4) 1099a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1100a011952aSMichael Chan } else if (tuple == 4) { 1101a011952aSMichael Chan return -EINVAL; 1102a011952aSMichael Chan } 1103a011952aSMichael Chan 1104a011952aSMichael Chan switch (cmd->flow_type) { 1105a011952aSMichael Chan case TCP_V4_FLOW: 1106a011952aSMichael Chan case UDP_V4_FLOW: 1107a011952aSMichael Chan case SCTP_V4_FLOW: 1108a011952aSMichael Chan case AH_ESP_V4_FLOW: 1109a011952aSMichael Chan case AH_V4_FLOW: 1110a011952aSMichael Chan case ESP_V4_FLOW: 1111a011952aSMichael Chan case IPV4_FLOW: 1112a011952aSMichael Chan if (tuple == 2) 1113a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1114a011952aSMichael Chan else if (!tuple) 1115a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1116a011952aSMichael Chan break; 1117a011952aSMichael Chan 1118a011952aSMichael Chan case TCP_V6_FLOW: 1119a011952aSMichael Chan case UDP_V6_FLOW: 1120a011952aSMichael Chan case SCTP_V6_FLOW: 1121a011952aSMichael Chan case AH_ESP_V6_FLOW: 1122a011952aSMichael Chan case AH_V6_FLOW: 1123a011952aSMichael Chan case ESP_V6_FLOW: 1124a011952aSMichael Chan case IPV6_FLOW: 1125a011952aSMichael Chan if (tuple == 2) 1126a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1127a011952aSMichael Chan else if (!tuple) 1128a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1129a011952aSMichael Chan break; 1130a011952aSMichael Chan } 1131a011952aSMichael Chan 1132a011952aSMichael Chan if (bp->rss_hash_cfg == rss_hash_cfg) 1133a011952aSMichael Chan return 0; 1134a011952aSMichael Chan 1135a011952aSMichael Chan bp->rss_hash_cfg = rss_hash_cfg; 1136a011952aSMichael Chan if (netif_running(bp->dev)) { 1137a011952aSMichael Chan bnxt_close_nic(bp, false, false); 1138a011952aSMichael Chan rc = bnxt_open_nic(bp, false, false); 1139a011952aSMichael Chan } 1140a011952aSMichael Chan return rc; 1141a011952aSMichael Chan } 1142c0c050c5SMichael Chan 1143c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 1144c0c050c5SMichael Chan u32 *rule_locs) 1145c0c050c5SMichael Chan { 1146c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1147c0c050c5SMichael Chan int rc = 0; 1148c0c050c5SMichael Chan 1149c0c050c5SMichael Chan switch (cmd->cmd) { 1150a011952aSMichael Chan #ifdef CONFIG_RFS_ACCEL 1151c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 1152c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 1153c0c050c5SMichael Chan break; 1154c0c050c5SMichael Chan 1155c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 1156c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 1157c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 1158c0c050c5SMichael Chan break; 1159c0c050c5SMichael Chan 1160c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 1161c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 1162c0c050c5SMichael Chan break; 1163c0c050c5SMichael Chan 1164c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 1165c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 1166c0c050c5SMichael Chan break; 1167a011952aSMichael Chan #endif 1168a011952aSMichael Chan 1169a011952aSMichael Chan case ETHTOOL_GRXFH: 1170a011952aSMichael Chan rc = bnxt_grxfh(bp, cmd); 1171a011952aSMichael Chan break; 1172c0c050c5SMichael Chan 1173c0c050c5SMichael Chan default: 1174c0c050c5SMichael Chan rc = -EOPNOTSUPP; 1175c0c050c5SMichael Chan break; 1176c0c050c5SMichael Chan } 1177c0c050c5SMichael Chan 1178c0c050c5SMichael Chan return rc; 1179c0c050c5SMichael Chan } 1180a011952aSMichael Chan 1181a011952aSMichael Chan static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) 1182a011952aSMichael Chan { 1183a011952aSMichael Chan struct bnxt *bp = netdev_priv(dev); 1184a011952aSMichael Chan int rc; 1185a011952aSMichael Chan 1186a011952aSMichael Chan switch (cmd->cmd) { 1187a011952aSMichael Chan case ETHTOOL_SRXFH: 1188a011952aSMichael Chan rc = bnxt_srxfh(bp, cmd); 1189a011952aSMichael Chan break; 1190a011952aSMichael Chan 1191a011952aSMichael Chan default: 1192a011952aSMichael Chan rc = -EOPNOTSUPP; 1193a011952aSMichael Chan break; 1194a011952aSMichael Chan } 1195a011952aSMichael Chan return rc; 1196a011952aSMichael Chan } 1197c0c050c5SMichael Chan 1198c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 1199c0c050c5SMichael Chan { 1200c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 1201c0c050c5SMichael Chan } 1202c0c050c5SMichael Chan 1203c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 1204c0c050c5SMichael Chan { 1205c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 1206c0c050c5SMichael Chan } 1207c0c050c5SMichael Chan 1208c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 1209c0c050c5SMichael Chan u8 *hfunc) 1210c0c050c5SMichael Chan { 1211c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 12127991cb9cSMichael Chan struct bnxt_vnic_info *vnic; 1213c0c050c5SMichael Chan int i = 0; 1214c0c050c5SMichael Chan 1215c0c050c5SMichael Chan if (hfunc) 1216c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 1217c0c050c5SMichael Chan 12187991cb9cSMichael Chan if (!bp->vnic_info) 12197991cb9cSMichael Chan return 0; 12207991cb9cSMichael Chan 12217991cb9cSMichael Chan vnic = &bp->vnic_info[0]; 12227991cb9cSMichael Chan if (indir && vnic->rss_table) { 1223c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 1224c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 12257991cb9cSMichael Chan } 1226c0c050c5SMichael Chan 12277991cb9cSMichael Chan if (key && vnic->rss_hash_key) 1228c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 1229c0c050c5SMichael Chan 1230c0c050c5SMichael Chan return 0; 1231c0c050c5SMichael Chan } 1232c0c050c5SMichael Chan 1233c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 1234c0c050c5SMichael Chan struct ethtool_drvinfo *info) 1235c0c050c5SMichael Chan { 1236c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1237c0c050c5SMichael Chan 1238c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 1239c0c050c5SMichael Chan strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 1240431aa1ebSMichael Chan strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); 1241c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 12425c8227d0SMichael Chan info->n_stats = bnxt_get_num_stats(bp); 1243eb513658SMichael Chan info->testinfo_len = bp->num_tests; 1244c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 1245c0c050c5SMichael Chan info->eedump_len = 0; 1246c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 1247c0c050c5SMichael Chan info->regdump_len = 0; 1248c0c050c5SMichael Chan } 1249c0c050c5SMichael Chan 12508e202366SMichael Chan static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 12518e202366SMichael Chan { 12528e202366SMichael Chan struct bnxt *bp = netdev_priv(dev); 12538e202366SMichael Chan 12548e202366SMichael Chan wol->supported = 0; 12558e202366SMichael Chan wol->wolopts = 0; 12568e202366SMichael Chan memset(&wol->sopass, 0, sizeof(wol->sopass)); 12578e202366SMichael Chan if (bp->flags & BNXT_FLAG_WOL_CAP) { 12588e202366SMichael Chan wol->supported = WAKE_MAGIC; 12598e202366SMichael Chan if (bp->wol) 12608e202366SMichael Chan wol->wolopts = WAKE_MAGIC; 12618e202366SMichael Chan } 12628e202366SMichael Chan } 12638e202366SMichael Chan 12645282db6cSMichael Chan static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 12655282db6cSMichael Chan { 12665282db6cSMichael Chan struct bnxt *bp = netdev_priv(dev); 12675282db6cSMichael Chan 12685282db6cSMichael Chan if (wol->wolopts & ~WAKE_MAGIC) 12695282db6cSMichael Chan return -EINVAL; 12705282db6cSMichael Chan 12715282db6cSMichael Chan if (wol->wolopts & WAKE_MAGIC) { 12725282db6cSMichael Chan if (!(bp->flags & BNXT_FLAG_WOL_CAP)) 12735282db6cSMichael Chan return -EINVAL; 12745282db6cSMichael Chan if (!bp->wol) { 12755282db6cSMichael Chan if (bnxt_hwrm_alloc_wol_fltr(bp)) 12765282db6cSMichael Chan return -EBUSY; 12775282db6cSMichael Chan bp->wol = 1; 12785282db6cSMichael Chan } 12795282db6cSMichael Chan } else { 12805282db6cSMichael Chan if (bp->wol) { 12815282db6cSMichael Chan if (bnxt_hwrm_free_wol_fltr(bp)) 12825282db6cSMichael Chan return -EBUSY; 12835282db6cSMichael Chan bp->wol = 0; 12845282db6cSMichael Chan } 12855282db6cSMichael Chan } 12865282db6cSMichael Chan return 0; 12875282db6cSMichael Chan } 12885282db6cSMichael Chan 1289170ce013SMichael Chan u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause) 1290c0c050c5SMichael Chan { 1291c0c050c5SMichael Chan u32 speed_mask = 0; 1292c0c050c5SMichael Chan 1293c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 1294c0c050c5SMichael Chan /* set the advertised speeds */ 1295c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 1296c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 1297c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 1298c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 1299c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 1300c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 1301c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 1302c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 1303c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 13041c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 130527c4d578SMichael Chan 130627c4d578SMichael Chan if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH) 130727c4d578SMichael Chan speed_mask |= ADVERTISED_Pause; 130827c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_TX) 130927c4d578SMichael Chan speed_mask |= ADVERTISED_Asym_Pause; 131027c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_RX) 131127c4d578SMichael Chan speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 131227c4d578SMichael Chan 1313c0c050c5SMichael Chan return speed_mask; 1314c0c050c5SMichael Chan } 1315c0c050c5SMichael Chan 131600c04a92SMichael Chan #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\ 131700c04a92SMichael Chan { \ 131800c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \ 131900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 132000c04a92SMichael Chan 100baseT_Full); \ 132100c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \ 132200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 132300c04a92SMichael Chan 1000baseT_Full); \ 132400c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \ 132500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 132600c04a92SMichael Chan 10000baseT_Full); \ 132700c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \ 132800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 132900c04a92SMichael Chan 25000baseCR_Full); \ 133000c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \ 133100c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 133200c04a92SMichael Chan 40000baseCR4_Full);\ 133300c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \ 133400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 133500c04a92SMichael Chan 50000baseCR2_Full);\ 133638a21b34SDeepak Khungar if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \ 133738a21b34SDeepak Khungar ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 133838a21b34SDeepak Khungar 100000baseCR4_Full);\ 133900c04a92SMichael Chan if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \ 134000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 134100c04a92SMichael Chan Pause); \ 134200c04a92SMichael Chan if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \ 134300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode( \ 134400c04a92SMichael Chan lk_ksettings, name, Asym_Pause);\ 134500c04a92SMichael Chan } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \ 134600c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 134700c04a92SMichael Chan Asym_Pause); \ 134800c04a92SMichael Chan } \ 134900c04a92SMichael Chan } 135000c04a92SMichael Chan 135100c04a92SMichael Chan #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \ 135200c04a92SMichael Chan { \ 135300c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135400c04a92SMichael Chan 100baseT_Full) || \ 135500c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135600c04a92SMichael Chan 100baseT_Half)) \ 135700c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \ 135800c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135900c04a92SMichael Chan 1000baseT_Full) || \ 136000c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 136100c04a92SMichael Chan 1000baseT_Half)) \ 136200c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \ 136300c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 136400c04a92SMichael Chan 10000baseT_Full)) \ 136500c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \ 136600c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 136700c04a92SMichael Chan 25000baseCR_Full)) \ 136800c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \ 136900c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 137000c04a92SMichael Chan 40000baseCR4_Full)) \ 137100c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \ 137200c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 137300c04a92SMichael Chan 50000baseCR2_Full)) \ 137400c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \ 137538a21b34SDeepak Khungar if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 137638a21b34SDeepak Khungar 100000baseCR4_Full)) \ 137738a21b34SDeepak Khungar (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \ 137800c04a92SMichael Chan } 137900c04a92SMichael Chan 138000c04a92SMichael Chan static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info, 138100c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 138227c4d578SMichael Chan { 138368515a18SMichael Chan u16 fw_speeds = link_info->advertising; 138427c4d578SMichael Chan u8 fw_pause = 0; 138527c4d578SMichael Chan 138627c4d578SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 138727c4d578SMichael Chan fw_pause = link_info->auto_pause_setting; 138827c4d578SMichael Chan 138900c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising); 139027c4d578SMichael Chan } 139127c4d578SMichael Chan 139200c04a92SMichael Chan static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info, 139300c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 13943277360eSMichael Chan { 13953277360eSMichael Chan u16 fw_speeds = link_info->lp_auto_link_speeds; 13963277360eSMichael Chan u8 fw_pause = 0; 13973277360eSMichael Chan 13983277360eSMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 13993277360eSMichael Chan fw_pause = link_info->lp_pause; 14003277360eSMichael Chan 140100c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, 140200c04a92SMichael Chan lp_advertising); 14033277360eSMichael Chan } 14043277360eSMichael Chan 140500c04a92SMichael Chan static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info, 140600c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 14074b32caccSMichael Chan { 14084b32caccSMichael Chan u16 fw_speeds = link_info->support_speeds; 14094b32caccSMichael Chan 141000c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported); 14114b32caccSMichael Chan 141200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause); 141300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 141400c04a92SMichael Chan Asym_Pause); 141593ed8117SMichael Chan 141600c04a92SMichael Chan if (link_info->support_auto_speeds) 141700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 141800c04a92SMichael Chan Autoneg); 141993ed8117SMichael Chan } 142093ed8117SMichael Chan 1421c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 1422c0c050c5SMichael Chan { 1423c0c050c5SMichael Chan switch (fw_link_speed) { 1424c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 1425c0c050c5SMichael Chan return SPEED_100; 1426c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 1427c0c050c5SMichael Chan return SPEED_1000; 1428c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 1429c0c050c5SMichael Chan return SPEED_2500; 1430c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 1431c0c050c5SMichael Chan return SPEED_10000; 1432c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 1433c0c050c5SMichael Chan return SPEED_20000; 1434c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 1435c0c050c5SMichael Chan return SPEED_25000; 1436c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 1437c0c050c5SMichael Chan return SPEED_40000; 1438c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 1439c0c050c5SMichael Chan return SPEED_50000; 144038a21b34SDeepak Khungar case BNXT_LINK_SPEED_100GB: 144138a21b34SDeepak Khungar return SPEED_100000; 1442c0c050c5SMichael Chan default: 1443c0c050c5SMichael Chan return SPEED_UNKNOWN; 1444c0c050c5SMichael Chan } 1445c0c050c5SMichael Chan } 1446c0c050c5SMichael Chan 144700c04a92SMichael Chan static int bnxt_get_link_ksettings(struct net_device *dev, 144800c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 1449c0c050c5SMichael Chan { 1450c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1451c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 145200c04a92SMichael Chan struct ethtool_link_settings *base = &lk_ksettings->base; 145300c04a92SMichael Chan u32 ethtool_speed; 1454c0c050c5SMichael Chan 145500c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported); 1456e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 145700c04a92SMichael Chan bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings); 1458c0c050c5SMichael Chan 145900c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising); 1460b763499eSMichael Chan if (link_info->autoneg) { 146100c04a92SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings); 146200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, 146300c04a92SMichael Chan advertising, Autoneg); 146400c04a92SMichael Chan base->autoneg = AUTONEG_ENABLE; 14653277360eSMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) 146600c04a92SMichael Chan bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings); 146729c262feSMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 146829c262feSMichael Chan if (!netif_carrier_ok(dev)) 146900c04a92SMichael Chan base->duplex = DUPLEX_UNKNOWN; 147029c262feSMichael Chan else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 147100c04a92SMichael Chan base->duplex = DUPLEX_FULL; 147229c262feSMichael Chan else 147300c04a92SMichael Chan base->duplex = DUPLEX_HALF; 1474c0c050c5SMichael Chan } else { 147500c04a92SMichael Chan base->autoneg = AUTONEG_DISABLE; 147629c262feSMichael Chan ethtool_speed = 147729c262feSMichael Chan bnxt_fw_to_ethtool_speed(link_info->req_link_speed); 147800c04a92SMichael Chan base->duplex = DUPLEX_HALF; 147929c262feSMichael Chan if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL) 148000c04a92SMichael Chan base->duplex = DUPLEX_FULL; 1481c0c050c5SMichael Chan } 148200c04a92SMichael Chan base->speed = ethtool_speed; 1483c0c050c5SMichael Chan 148400c04a92SMichael Chan base->port = PORT_NONE; 1485c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 148600c04a92SMichael Chan base->port = PORT_TP; 148700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 148800c04a92SMichael Chan TP); 148900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 149000c04a92SMichael Chan TP); 1491c0c050c5SMichael Chan } else { 149200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 149300c04a92SMichael Chan FIBRE); 149400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 149500c04a92SMichael Chan FIBRE); 1496c0c050c5SMichael Chan 1497c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 149800c04a92SMichael Chan base->port = PORT_DA; 1499c0c050c5SMichael Chan else if (link_info->media_type == 1500c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 150100c04a92SMichael Chan base->port = PORT_FIBRE; 1502c0c050c5SMichael Chan } 150300c04a92SMichael Chan base->phy_address = link_info->phy_addr; 1504e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1505c0c050c5SMichael Chan 1506c0c050c5SMichael Chan return 0; 1507c0c050c5SMichael Chan } 1508c0c050c5SMichael Chan 150938a21b34SDeepak Khungar static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed) 1510c0c050c5SMichael Chan { 15119d9cee08SMichael Chan struct bnxt *bp = netdev_priv(dev); 15129d9cee08SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 15139d9cee08SMichael Chan u16 support_spds = link_info->support_speeds; 15149d9cee08SMichael Chan u32 fw_speed = 0; 15159d9cee08SMichael Chan 1516c0c050c5SMichael Chan switch (ethtool_speed) { 1517c0c050c5SMichael Chan case SPEED_100: 15189d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_100MB) 15199d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 15209d9cee08SMichael Chan break; 1521c0c050c5SMichael Chan case SPEED_1000: 15229d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_1GB) 15239d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 15249d9cee08SMichael Chan break; 1525c0c050c5SMichael Chan case SPEED_2500: 15269d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB) 15279d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 15289d9cee08SMichael Chan break; 1529c0c050c5SMichael Chan case SPEED_10000: 15309d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_10GB) 15319d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 15329d9cee08SMichael Chan break; 1533c0c050c5SMichael Chan case SPEED_20000: 15349d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_20GB) 15359d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 15369d9cee08SMichael Chan break; 1537c0c050c5SMichael Chan case SPEED_25000: 15389d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_25GB) 15399d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 15409d9cee08SMichael Chan break; 1541c0c050c5SMichael Chan case SPEED_40000: 15429d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_40GB) 15439d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 15449d9cee08SMichael Chan break; 1545c0c050c5SMichael Chan case SPEED_50000: 15469d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_50GB) 15479d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 15489d9cee08SMichael Chan break; 154938a21b34SDeepak Khungar case SPEED_100000: 155038a21b34SDeepak Khungar if (support_spds & BNXT_LINK_SPEED_MSK_100GB) 155138a21b34SDeepak Khungar fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB; 155238a21b34SDeepak Khungar break; 1553c0c050c5SMichael Chan default: 1554c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 1555c0c050c5SMichael Chan break; 1556c0c050c5SMichael Chan } 15579d9cee08SMichael Chan return fw_speed; 1558c0c050c5SMichael Chan } 1559c0c050c5SMichael Chan 1560939f7f0cSMichael Chan u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 1561c0c050c5SMichael Chan { 1562c0c050c5SMichael Chan u16 fw_speed_mask = 0; 1563c0c050c5SMichael Chan 1564c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 1565c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 1566c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 1567c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 1568c0c050c5SMichael Chan } 1569c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 1570c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 1571c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 1572c0c050c5SMichael Chan } 1573c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 1574c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 1575c0c050c5SMichael Chan 15761c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 15771c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 15781c49c421SMichael Chan 1579c0c050c5SMichael Chan return fw_speed_mask; 1580c0c050c5SMichael Chan } 1581c0c050c5SMichael Chan 158200c04a92SMichael Chan static int bnxt_set_link_ksettings(struct net_device *dev, 158300c04a92SMichael Chan const struct ethtool_link_ksettings *lk_ksettings) 1584c0c050c5SMichael Chan { 1585c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1586c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 158700c04a92SMichael Chan const struct ethtool_link_settings *base = &lk_ksettings->base; 1588c0c050c5SMichael Chan bool set_pause = false; 158968515a18SMichael Chan u16 fw_advertising = 0; 159068515a18SMichael Chan u32 speed; 159100c04a92SMichael Chan int rc = 0; 1592c0c050c5SMichael Chan 1593567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 159400c04a92SMichael Chan return -EOPNOTSUPP; 1595c0c050c5SMichael Chan 1596e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 159700c04a92SMichael Chan if (base->autoneg == AUTONEG_ENABLE) { 159800c04a92SMichael Chan BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings, 159900c04a92SMichael Chan advertising); 1600c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 1601c0c050c5SMichael Chan if (!fw_advertising) 160293ed8117SMichael Chan link_info->advertising = link_info->support_auto_speeds; 1603c0c050c5SMichael Chan else 1604c0c050c5SMichael Chan link_info->advertising = fw_advertising; 1605c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 1606c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 1607c0c050c5SMichael Chan */ 1608c0c050c5SMichael Chan set_pause = true; 1609c0c050c5SMichael Chan } else { 16109d9cee08SMichael Chan u16 fw_speed; 161103efbec0SMichael Chan u8 phy_type = link_info->phy_type; 16129d9cee08SMichael Chan 161303efbec0SMichael Chan if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET || 161403efbec0SMichael Chan phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE || 161503efbec0SMichael Chan link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 161603efbec0SMichael Chan netdev_err(dev, "10GBase-T devices must autoneg\n"); 161703efbec0SMichael Chan rc = -EINVAL; 161803efbec0SMichael Chan goto set_setting_exit; 161903efbec0SMichael Chan } 162000c04a92SMichael Chan if (base->duplex == DUPLEX_HALF) { 1621c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 1622c0c050c5SMichael Chan rc = -EINVAL; 1623c0c050c5SMichael Chan goto set_setting_exit; 1624c0c050c5SMichael Chan } 162500c04a92SMichael Chan speed = base->speed; 16269d9cee08SMichael Chan fw_speed = bnxt_get_fw_speed(dev, speed); 16279d9cee08SMichael Chan if (!fw_speed) { 16289d9cee08SMichael Chan rc = -EINVAL; 16299d9cee08SMichael Chan goto set_setting_exit; 16309d9cee08SMichael Chan } 16319d9cee08SMichael Chan link_info->req_link_speed = fw_speed; 1632c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 1633b763499eSMichael Chan link_info->autoneg = 0; 1634c0c050c5SMichael Chan link_info->advertising = 0; 1635c0c050c5SMichael Chan } 1636c0c050c5SMichael Chan 1637c0c050c5SMichael Chan if (netif_running(dev)) 1638939f7f0cSMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause, false); 1639c0c050c5SMichael Chan 1640c0c050c5SMichael Chan set_setting_exit: 1641e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1642c0c050c5SMichael Chan return rc; 1643c0c050c5SMichael Chan } 1644c0c050c5SMichael Chan 1645c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 1646c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1647c0c050c5SMichael Chan { 1648c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1649c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1650c0c050c5SMichael Chan 1651c0c050c5SMichael Chan if (BNXT_VF(bp)) 1652c0c050c5SMichael Chan return; 1653b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 16543c02d1bbSMichael Chan epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX); 16553c02d1bbSMichael Chan epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX); 1656c0c050c5SMichael Chan } 1657c0c050c5SMichael Chan 1658c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 1659c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1660c0c050c5SMichael Chan { 1661c0c050c5SMichael Chan int rc = 0; 1662c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1663c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1664c0c050c5SMichael Chan 1665567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 166675362a3fSMichael Chan return -EOPNOTSUPP; 1667c0c050c5SMichael Chan 1668c0c050c5SMichael Chan if (epause->autoneg) { 1669b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 1670b763499eSMichael Chan return -EINVAL; 1671b763499eSMichael Chan 1672c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 1673c9ee9516SMichael Chan if (bp->hwrm_spec_code >= 0x10201) 1674c9ee9516SMichael Chan link_info->req_flow_ctrl = 1675c9ee9516SMichael Chan PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; 1676c0c050c5SMichael Chan } else { 1677c0c050c5SMichael Chan /* when transition from auto pause to force pause, 1678c0c050c5SMichael Chan * force a link change 1679c0c050c5SMichael Chan */ 1680c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 1681c0c050c5SMichael Chan link_info->force_link_chng = true; 1682c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 1683c9ee9516SMichael Chan link_info->req_flow_ctrl = 0; 1684c0c050c5SMichael Chan } 1685c0c050c5SMichael Chan if (epause->rx_pause) 1686c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 1687c0c050c5SMichael Chan 1688c0c050c5SMichael Chan if (epause->tx_pause) 1689c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 1690c0c050c5SMichael Chan 1691c0c050c5SMichael Chan if (netif_running(dev)) 1692c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 1693c0c050c5SMichael Chan return rc; 1694c0c050c5SMichael Chan } 1695c0c050c5SMichael Chan 1696c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 1697c0c050c5SMichael Chan { 1698c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1699c0c050c5SMichael Chan 1700c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 1701c0c050c5SMichael Chan return bp->link_info.link_up; 1702c0c050c5SMichael Chan } 1703c0c050c5SMichael Chan 1704b3b0ddd0SMichael Chan static void bnxt_print_admin_err(struct bnxt *bp) 1705b3b0ddd0SMichael Chan { 1706b3b0ddd0SMichael Chan netdev_info(bp->dev, "PF does not have admin privileges to flash or reset the device\n"); 1707b3b0ddd0SMichael Chan } 1708b3b0ddd0SMichael Chan 17095ac67d8bSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 17105ac67d8bSRob Swindell u16 ext, u16 *index, u32 *item_length, 17115ac67d8bSRob Swindell u32 *data_length); 17125ac67d8bSRob Swindell 1713c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 1714c0c050c5SMichael Chan u16 dir_type, 1715c0c050c5SMichael Chan u16 dir_ordinal, 1716c0c050c5SMichael Chan u16 dir_ext, 1717c0c050c5SMichael Chan u16 dir_attr, 1718c0c050c5SMichael Chan const u8 *data, 1719c0c050c5SMichael Chan size_t data_len) 1720c0c050c5SMichael Chan { 1721c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1722c0c050c5SMichael Chan int rc; 1723c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 1724c0c050c5SMichael Chan dma_addr_t dma_handle; 1725c0c050c5SMichael Chan u8 *kmem; 1726c0c050c5SMichael Chan 1727c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 1728c0c050c5SMichael Chan 1729c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 1730c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 1731c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 1732c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 1733c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 1734c0c050c5SMichael Chan 1735c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 1736c0c050c5SMichael Chan GFP_KERNEL); 1737c0c050c5SMichael Chan if (!kmem) { 1738c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1739c0c050c5SMichael Chan (unsigned)data_len); 1740c0c050c5SMichael Chan return -ENOMEM; 1741c0c050c5SMichael Chan } 1742c0c050c5SMichael Chan memcpy(kmem, data, data_len); 1743c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 1744c0c050c5SMichael Chan 1745c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 1746c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 1747c0c050c5SMichael Chan 1748d4f1420dSMichael Chan if (rc == -EACCES) 1749b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 1750c0c050c5SMichael Chan return rc; 1751c0c050c5SMichael Chan } 1752c0c050c5SMichael Chan 1753d2d6318cSRob Swindell static int bnxt_firmware_reset(struct net_device *dev, 1754d2d6318cSRob Swindell u16 dir_type) 1755d2d6318cSRob Swindell { 1756d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 17577c675421SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 17587c675421SVasundhara Volam int rc; 1759d2d6318cSRob Swindell 1760d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 1761d2d6318cSRob Swindell 1762d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 1763d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 1764d2d6318cSRob Swindell switch (dir_type) { 1765d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 1766d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 1767d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 1768d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 1769d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 1770d2d6318cSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1771d2d6318cSRob Swindell break; 1772d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 1773d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 1774d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 177508141e0bSRob Swindell /* Self-reset APE upon next PCIe reset: */ 177608141e0bSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1777d2d6318cSRob Swindell break; 1778d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 1779d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 1780d2d6318cSRob Swindell req.embedded_proc_type = 1781d2d6318cSRob Swindell FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 1782d2d6318cSRob Swindell break; 1783d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 1784d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1785d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 1786d2d6318cSRob Swindell break; 178749f7972fSVasundhara Volam case BNXT_FW_RESET_CHIP: 178849f7972fSVasundhara Volam req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP; 178949f7972fSVasundhara Volam req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP; 179049f7972fSVasundhara Volam break; 17916502ad59SScott Branden case BNXT_FW_RESET_AP: 17926502ad59SScott Branden req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP; 17936502ad59SScott Branden break; 1794d2d6318cSRob Swindell default: 1795d2d6318cSRob Swindell return -EINVAL; 1796d2d6318cSRob Swindell } 1797d2d6318cSRob Swindell 17987c675421SVasundhara Volam rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1799d4f1420dSMichael Chan if (rc == -EACCES) 1800b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 18017c675421SVasundhara Volam return rc; 1802d2d6318cSRob Swindell } 1803d2d6318cSRob Swindell 1804c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 1805c0c050c5SMichael Chan u16 dir_type, 1806c0c050c5SMichael Chan const u8 *fw_data, 1807c0c050c5SMichael Chan size_t fw_size) 1808c0c050c5SMichael Chan { 1809c0c050c5SMichael Chan int rc = 0; 1810c0c050c5SMichael Chan u16 code_type; 1811c0c050c5SMichael Chan u32 stored_crc; 1812c0c050c5SMichael Chan u32 calculated_crc; 1813c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 1814c0c050c5SMichael Chan 1815c0c050c5SMichael Chan switch (dir_type) { 1816c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1817c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1818c0c050c5SMichael Chan code_type = CODE_BOOT; 1819c0c050c5SMichael Chan break; 182093e0b4feSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 182193e0b4feSRob Swindell code_type = CODE_CHIMP_PATCH; 182293e0b4feSRob Swindell break; 18232731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 18242731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 18252731d70fSRob Swindell break; 182693e0b4feSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 182793e0b4feSRob Swindell code_type = CODE_APE_PATCH; 182893e0b4feSRob Swindell break; 182993e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_FW: 183093e0b4feSRob Swindell code_type = CODE_KONG_FW; 183193e0b4feSRob Swindell break; 183293e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 183393e0b4feSRob Swindell code_type = CODE_KONG_PATCH; 183493e0b4feSRob Swindell break; 183593e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 183693e0b4feSRob Swindell code_type = CODE_BONO_FW; 183793e0b4feSRob Swindell break; 183893e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 183993e0b4feSRob Swindell code_type = CODE_BONO_PATCH; 184093e0b4feSRob Swindell break; 1841c0c050c5SMichael Chan default: 1842c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 1843c0c050c5SMichael Chan dir_type); 1844c0c050c5SMichael Chan return -EINVAL; 1845c0c050c5SMichael Chan } 1846c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 1847c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 1848c0c050c5SMichael Chan (unsigned int)fw_size); 1849c0c050c5SMichael Chan return -EINVAL; 1850c0c050c5SMichael Chan } 1851c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 1852c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 1853c0c050c5SMichael Chan le32_to_cpu(header->signature)); 1854c0c050c5SMichael Chan return -EINVAL; 1855c0c050c5SMichael Chan } 1856c0c050c5SMichael Chan if (header->code_type != code_type) { 1857c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 1858c0c050c5SMichael Chan code_type, header->code_type); 1859c0c050c5SMichael Chan return -EINVAL; 1860c0c050c5SMichael Chan } 1861c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 1862c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 1863c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 1864c0c050c5SMichael Chan return -EINVAL; 1865c0c050c5SMichael Chan } 1866c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 1867c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 1868c0c050c5SMichael Chan sizeof(stored_crc))); 1869c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 1870c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 1871c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 1872c0c050c5SMichael Chan (unsigned long)stored_crc, 1873c0c050c5SMichael Chan (unsigned long)calculated_crc); 1874c0c050c5SMichael Chan return -EINVAL; 1875c0c050c5SMichael Chan } 1876c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1877c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 1878d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 1879d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 1880d2d6318cSRob Swindell 1881c0c050c5SMichael Chan return rc; 1882c0c050c5SMichael Chan } 1883c0c050c5SMichael Chan 18845ac67d8bSRob Swindell static int bnxt_flash_microcode(struct net_device *dev, 18855ac67d8bSRob Swindell u16 dir_type, 18865ac67d8bSRob Swindell const u8 *fw_data, 18875ac67d8bSRob Swindell size_t fw_size) 18885ac67d8bSRob Swindell { 18895ac67d8bSRob Swindell struct bnxt_ucode_trailer *trailer; 18905ac67d8bSRob Swindell u32 calculated_crc; 18915ac67d8bSRob Swindell u32 stored_crc; 18925ac67d8bSRob Swindell int rc = 0; 18935ac67d8bSRob Swindell 18945ac67d8bSRob Swindell if (fw_size < sizeof(struct bnxt_ucode_trailer)) { 18955ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode file size: %u\n", 18965ac67d8bSRob Swindell (unsigned int)fw_size); 18975ac67d8bSRob Swindell return -EINVAL; 18985ac67d8bSRob Swindell } 18995ac67d8bSRob Swindell trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size - 19005ac67d8bSRob Swindell sizeof(*trailer))); 19015ac67d8bSRob Swindell if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) { 19025ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer signature: %08X\n", 19035ac67d8bSRob Swindell le32_to_cpu(trailer->sig)); 19045ac67d8bSRob Swindell return -EINVAL; 19055ac67d8bSRob Swindell } 19065ac67d8bSRob Swindell if (le16_to_cpu(trailer->dir_type) != dir_type) { 19075ac67d8bSRob Swindell netdev_err(dev, "Expected microcode type: %d, read: %d\n", 19085ac67d8bSRob Swindell dir_type, le16_to_cpu(trailer->dir_type)); 19095ac67d8bSRob Swindell return -EINVAL; 19105ac67d8bSRob Swindell } 19115ac67d8bSRob Swindell if (le16_to_cpu(trailer->trailer_length) < 19125ac67d8bSRob Swindell sizeof(struct bnxt_ucode_trailer)) { 19135ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer length: %d\n", 19145ac67d8bSRob Swindell le16_to_cpu(trailer->trailer_length)); 19155ac67d8bSRob Swindell return -EINVAL; 19165ac67d8bSRob Swindell } 19175ac67d8bSRob Swindell 19185ac67d8bSRob Swindell /* Confirm the CRC32 checksum of the file: */ 19195ac67d8bSRob Swindell stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 19205ac67d8bSRob Swindell sizeof(stored_crc))); 19215ac67d8bSRob Swindell calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 19225ac67d8bSRob Swindell if (calculated_crc != stored_crc) { 19235ac67d8bSRob Swindell netdev_err(dev, 19245ac67d8bSRob Swindell "CRC32 (%08lX) does not match calculated: %08lX\n", 19255ac67d8bSRob Swindell (unsigned long)stored_crc, 19265ac67d8bSRob Swindell (unsigned long)calculated_crc); 19275ac67d8bSRob Swindell return -EINVAL; 19285ac67d8bSRob Swindell } 19295ac67d8bSRob Swindell rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 19305ac67d8bSRob Swindell 0, 0, fw_data, fw_size); 19315ac67d8bSRob Swindell 19325ac67d8bSRob Swindell return rc; 19335ac67d8bSRob Swindell } 19345ac67d8bSRob Swindell 1935c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 1936c0c050c5SMichael Chan { 1937c0c050c5SMichael Chan switch (dir_type) { 1938c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 1939c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1940c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1941c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 1942c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 1943c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 1944c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 194593e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 194693e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1947c0c050c5SMichael Chan return true; 1948c0c050c5SMichael Chan } 1949c0c050c5SMichael Chan 1950c0c050c5SMichael Chan return false; 1951c0c050c5SMichael Chan } 1952c0c050c5SMichael Chan 19535ac67d8bSRob Swindell static bool bnxt_dir_type_is_other_exec_format(u16 dir_type) 1954c0c050c5SMichael Chan { 1955c0c050c5SMichael Chan switch (dir_type) { 1956c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 1957c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 1958c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 1959c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 1960c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 1961c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 1962c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 1963c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 1964c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 1965c0c050c5SMichael Chan return true; 1966c0c050c5SMichael Chan } 1967c0c050c5SMichael Chan 1968c0c050c5SMichael Chan return false; 1969c0c050c5SMichael Chan } 1970c0c050c5SMichael Chan 1971c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 1972c0c050c5SMichael Chan { 1973c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 19745ac67d8bSRob Swindell bnxt_dir_type_is_other_exec_format(dir_type); 1975c0c050c5SMichael Chan } 1976c0c050c5SMichael Chan 1977c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 1978c0c050c5SMichael Chan u16 dir_type, 1979c0c050c5SMichael Chan const char *filename) 1980c0c050c5SMichael Chan { 1981c0c050c5SMichael Chan const struct firmware *fw; 1982c0c050c5SMichael Chan int rc; 1983c0c050c5SMichael Chan 1984c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 1985c0c050c5SMichael Chan if (rc != 0) { 1986c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 1987c0c050c5SMichael Chan rc, filename); 1988c0c050c5SMichael Chan return rc; 1989c0c050c5SMichael Chan } 1990c0c050c5SMichael Chan if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) 1991c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 19925ac67d8bSRob Swindell else if (bnxt_dir_type_is_other_exec_format(dir_type) == true) 19935ac67d8bSRob Swindell rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size); 1994c0c050c5SMichael Chan else 1995c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1996c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 1997c0c050c5SMichael Chan release_firmware(fw); 1998c0c050c5SMichael Chan return rc; 1999c0c050c5SMichael Chan } 2000c0c050c5SMichael Chan 2001c0c050c5SMichael Chan static int bnxt_flash_package_from_file(struct net_device *dev, 20025ac67d8bSRob Swindell char *filename, u32 install_type) 2003c0c050c5SMichael Chan { 20045ac67d8bSRob Swindell struct bnxt *bp = netdev_priv(dev); 20055ac67d8bSRob Swindell struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr; 20065ac67d8bSRob Swindell struct hwrm_nvm_install_update_input install = {0}; 20075ac67d8bSRob Swindell const struct firmware *fw; 20087c675421SVasundhara Volam int rc, hwrm_err = 0; 20095ac67d8bSRob Swindell u32 item_len; 20105ac67d8bSRob Swindell u16 index; 20115ac67d8bSRob Swindell 20125ac67d8bSRob Swindell bnxt_hwrm_fw_set_time(bp); 20135ac67d8bSRob Swindell 20145ac67d8bSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE, 20155ac67d8bSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 20165ac67d8bSRob Swindell &index, &item_len, NULL) != 0) { 20175ac67d8bSRob Swindell netdev_err(dev, "PKG update area not created in nvram\n"); 20185ac67d8bSRob Swindell return -ENOBUFS; 20195ac67d8bSRob Swindell } 20205ac67d8bSRob Swindell 20215ac67d8bSRob Swindell rc = request_firmware(&fw, filename, &dev->dev); 20225ac67d8bSRob Swindell if (rc != 0) { 20235ac67d8bSRob Swindell netdev_err(dev, "PKG error %d requesting file: %s\n", 20245ac67d8bSRob Swindell rc, filename); 20255ac67d8bSRob Swindell return rc; 20265ac67d8bSRob Swindell } 20275ac67d8bSRob Swindell 20285ac67d8bSRob Swindell if (fw->size > item_len) { 20295ac67d8bSRob Swindell netdev_err(dev, "PKG insufficient update area in nvram: %lu", 20305ac67d8bSRob Swindell (unsigned long)fw->size); 20315ac67d8bSRob Swindell rc = -EFBIG; 20325ac67d8bSRob Swindell } else { 20335ac67d8bSRob Swindell dma_addr_t dma_handle; 20345ac67d8bSRob Swindell u8 *kmem; 20355ac67d8bSRob Swindell struct hwrm_nvm_modify_input modify = {0}; 20365ac67d8bSRob Swindell 20375ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1); 20385ac67d8bSRob Swindell 20395ac67d8bSRob Swindell modify.dir_idx = cpu_to_le16(index); 20405ac67d8bSRob Swindell modify.len = cpu_to_le32(fw->size); 20415ac67d8bSRob Swindell 20425ac67d8bSRob Swindell kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size, 20435ac67d8bSRob Swindell &dma_handle, GFP_KERNEL); 20445ac67d8bSRob Swindell if (!kmem) { 20455ac67d8bSRob Swindell netdev_err(dev, 20465ac67d8bSRob Swindell "dma_alloc_coherent failure, length = %u\n", 20475ac67d8bSRob Swindell (unsigned int)fw->size); 20485ac67d8bSRob Swindell rc = -ENOMEM; 20495ac67d8bSRob Swindell } else { 20505ac67d8bSRob Swindell memcpy(kmem, fw->data, fw->size); 20515ac67d8bSRob Swindell modify.host_src_addr = cpu_to_le64(dma_handle); 20525ac67d8bSRob Swindell 20537c675421SVasundhara Volam hwrm_err = hwrm_send_message(bp, &modify, 20547c675421SVasundhara Volam sizeof(modify), 20555ac67d8bSRob Swindell FLASH_PACKAGE_TIMEOUT); 20565ac67d8bSRob Swindell dma_free_coherent(&bp->pdev->dev, fw->size, kmem, 20575ac67d8bSRob Swindell dma_handle); 20585ac67d8bSRob Swindell } 20595ac67d8bSRob Swindell } 20605ac67d8bSRob Swindell release_firmware(fw); 20617c675421SVasundhara Volam if (rc || hwrm_err) 20627c675421SVasundhara Volam goto err_exit; 20635ac67d8bSRob Swindell 20645ac67d8bSRob Swindell if ((install_type & 0xffff) == 0) 20655ac67d8bSRob Swindell install_type >>= 16; 20665ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1); 20675ac67d8bSRob Swindell install.install_type = cpu_to_le32(install_type); 20685ac67d8bSRob Swindell 2069cb4d1d62SKshitij Soni mutex_lock(&bp->hwrm_cmd_lock); 20707c675421SVasundhara Volam hwrm_err = _hwrm_send_message(bp, &install, sizeof(install), 20715ac67d8bSRob Swindell INSTALL_PACKAGE_TIMEOUT); 2072dd2ebf34SVasundhara Volam if (hwrm_err) { 2073cb4d1d62SKshitij Soni u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err; 2074cb4d1d62SKshitij Soni 2075dd2ebf34SVasundhara Volam if (resp->error_code && error_code == 2076dd2ebf34SVasundhara Volam NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) { 2077cb4d1d62SKshitij Soni install.flags |= cpu_to_le16( 2078cb4d1d62SKshitij Soni NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG); 20797c675421SVasundhara Volam hwrm_err = _hwrm_send_message(bp, &install, 20807c675421SVasundhara Volam sizeof(install), 2081cb4d1d62SKshitij Soni INSTALL_PACKAGE_TIMEOUT); 2082dd2ebf34SVasundhara Volam } 20837c675421SVasundhara Volam if (hwrm_err) 2084cb4d1d62SKshitij Soni goto flash_pkg_exit; 2085cb4d1d62SKshitij Soni } 20865ac67d8bSRob Swindell 20875ac67d8bSRob Swindell if (resp->result) { 20885ac67d8bSRob Swindell netdev_err(dev, "PKG install error = %d, problem_item = %d\n", 20895ac67d8bSRob Swindell (s8)resp->result, (int)resp->problem_item); 2090cb4d1d62SKshitij Soni rc = -ENOPKG; 20915ac67d8bSRob Swindell } 2092cb4d1d62SKshitij Soni flash_pkg_exit: 2093cb4d1d62SKshitij Soni mutex_unlock(&bp->hwrm_cmd_lock); 20947c675421SVasundhara Volam err_exit: 2095d4f1420dSMichael Chan if (hwrm_err == -EACCES) 2096b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 2097cb4d1d62SKshitij Soni return rc; 2098c0c050c5SMichael Chan } 2099c0c050c5SMichael Chan 2100c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 2101c0c050c5SMichael Chan struct ethtool_flash *flash) 2102c0c050c5SMichael Chan { 2103c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 2104c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 2105c0c050c5SMichael Chan return -EINVAL; 2106c0c050c5SMichael Chan } 2107c0c050c5SMichael Chan 21085ac67d8bSRob Swindell if (flash->region == ETHTOOL_FLASH_ALL_REGIONS || 21095ac67d8bSRob Swindell flash->region > 0xffff) 21105ac67d8bSRob Swindell return bnxt_flash_package_from_file(dev, flash->data, 21115ac67d8bSRob Swindell flash->region); 2112c0c050c5SMichael Chan 2113c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 2114c0c050c5SMichael Chan } 2115c0c050c5SMichael Chan 2116c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 2117c0c050c5SMichael Chan { 2118c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2119c0c050c5SMichael Chan int rc; 2120c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 2121c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 2122c0c050c5SMichael Chan 2123c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 2124c0c050c5SMichael Chan 2125c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2126c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2127c0c050c5SMichael Chan if (!rc) { 2128c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 2129c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 2130c0c050c5SMichael Chan } 2131c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2132c0c050c5SMichael Chan return rc; 2133c0c050c5SMichael Chan } 2134c0c050c5SMichael Chan 2135c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 2136c0c050c5SMichael Chan { 21374cebbacaSMichael Chan struct bnxt *bp = netdev_priv(dev); 21384cebbacaSMichael Chan 21394cebbacaSMichael Chan if (BNXT_VF(bp)) 21404cebbacaSMichael Chan return 0; 21414cebbacaSMichael Chan 2142c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 2143c0c050c5SMichael Chan * passed via the ethtool command-line utility. 2144c0c050c5SMichael Chan */ 2145c0c050c5SMichael Chan return -1; 2146c0c050c5SMichael Chan } 2147c0c050c5SMichael Chan 2148c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 2149c0c050c5SMichael Chan { 2150c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2151c0c050c5SMichael Chan int rc; 2152c0c050c5SMichael Chan u32 dir_entries; 2153c0c050c5SMichael Chan u32 entry_length; 2154c0c050c5SMichael Chan u8 *buf; 2155c0c050c5SMichael Chan size_t buflen; 2156c0c050c5SMichael Chan dma_addr_t dma_handle; 2157c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 2158c0c050c5SMichael Chan 2159c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 2160c0c050c5SMichael Chan if (rc != 0) 2161c0c050c5SMichael Chan return rc; 2162c0c050c5SMichael Chan 2163c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 2164c0c050c5SMichael Chan if (len < 2) 2165c0c050c5SMichael Chan return -EINVAL; 2166c0c050c5SMichael Chan 2167c0c050c5SMichael Chan *data++ = dir_entries; 2168c0c050c5SMichael Chan *data++ = entry_length; 2169c0c050c5SMichael Chan len -= 2; 2170c0c050c5SMichael Chan memset(data, 0xff, len); 2171c0c050c5SMichael Chan 2172c0c050c5SMichael Chan buflen = dir_entries * entry_length; 2173c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 2174c0c050c5SMichael Chan GFP_KERNEL); 2175c0c050c5SMichael Chan if (!buf) { 2176c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2177c0c050c5SMichael Chan (unsigned)buflen); 2178c0c050c5SMichael Chan return -ENOMEM; 2179c0c050c5SMichael Chan } 2180c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 2181c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2182c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2183c0c050c5SMichael Chan if (rc == 0) 2184c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 2185c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 2186c0c050c5SMichael Chan return rc; 2187c0c050c5SMichael Chan } 2188c0c050c5SMichael Chan 2189c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 2190c0c050c5SMichael Chan u32 length, u8 *data) 2191c0c050c5SMichael Chan { 2192c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2193c0c050c5SMichael Chan int rc; 2194c0c050c5SMichael Chan u8 *buf; 2195c0c050c5SMichael Chan dma_addr_t dma_handle; 2196c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 2197c0c050c5SMichael Chan 2198e0ad8fc5SMichael Chan if (!length) 2199e0ad8fc5SMichael Chan return -EINVAL; 2200e0ad8fc5SMichael Chan 2201c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 2202c0c050c5SMichael Chan GFP_KERNEL); 2203c0c050c5SMichael Chan if (!buf) { 2204c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2205c0c050c5SMichael Chan (unsigned)length); 2206c0c050c5SMichael Chan return -ENOMEM; 2207c0c050c5SMichael Chan } 2208c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 2209c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2210c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2211c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 2212c0c050c5SMichael Chan req.len = cpu_to_le32(length); 2213c0c050c5SMichael Chan 2214c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2215c0c050c5SMichael Chan if (rc == 0) 2216c0c050c5SMichael Chan memcpy(data, buf, length); 2217c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 2218c0c050c5SMichael Chan return rc; 2219c0c050c5SMichael Chan } 2220c0c050c5SMichael Chan 22213ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 22223ebf6f0aSRob Swindell u16 ext, u16 *index, u32 *item_length, 22233ebf6f0aSRob Swindell u32 *data_length) 22243ebf6f0aSRob Swindell { 22253ebf6f0aSRob Swindell struct bnxt *bp = netdev_priv(dev); 22263ebf6f0aSRob Swindell int rc; 22273ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_input req = {0}; 22283ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr; 22293ebf6f0aSRob Swindell 22303ebf6f0aSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1); 22313ebf6f0aSRob Swindell req.enables = 0; 22323ebf6f0aSRob Swindell req.dir_idx = 0; 22333ebf6f0aSRob Swindell req.dir_type = cpu_to_le16(type); 22343ebf6f0aSRob Swindell req.dir_ordinal = cpu_to_le16(ordinal); 22353ebf6f0aSRob Swindell req.dir_ext = cpu_to_le16(ext); 22363ebf6f0aSRob Swindell req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ; 2237cc72f3b1SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2238cc72f3b1SMichael Chan rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 22393ebf6f0aSRob Swindell if (rc == 0) { 22403ebf6f0aSRob Swindell if (index) 22413ebf6f0aSRob Swindell *index = le16_to_cpu(output->dir_idx); 22423ebf6f0aSRob Swindell if (item_length) 22433ebf6f0aSRob Swindell *item_length = le32_to_cpu(output->dir_item_length); 22443ebf6f0aSRob Swindell if (data_length) 22453ebf6f0aSRob Swindell *data_length = le32_to_cpu(output->dir_data_length); 22463ebf6f0aSRob Swindell } 2247cc72f3b1SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 22483ebf6f0aSRob Swindell return rc; 22493ebf6f0aSRob Swindell } 22503ebf6f0aSRob Swindell 22513ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen) 22523ebf6f0aSRob Swindell { 22533ebf6f0aSRob Swindell char *retval = NULL; 22543ebf6f0aSRob Swindell char *p; 22553ebf6f0aSRob Swindell char *value; 22563ebf6f0aSRob Swindell int field = 0; 22573ebf6f0aSRob Swindell 22583ebf6f0aSRob Swindell if (datalen < 1) 22593ebf6f0aSRob Swindell return NULL; 22603ebf6f0aSRob Swindell /* null-terminate the log data (removing last '\n'): */ 22613ebf6f0aSRob Swindell data[datalen - 1] = 0; 22623ebf6f0aSRob Swindell for (p = data; *p != 0; p++) { 22633ebf6f0aSRob Swindell field = 0; 22643ebf6f0aSRob Swindell retval = NULL; 22653ebf6f0aSRob Swindell while (*p != 0 && *p != '\n') { 22663ebf6f0aSRob Swindell value = p; 22673ebf6f0aSRob Swindell while (*p != 0 && *p != '\t' && *p != '\n') 22683ebf6f0aSRob Swindell p++; 22693ebf6f0aSRob Swindell if (field == desired_field) 22703ebf6f0aSRob Swindell retval = value; 22713ebf6f0aSRob Swindell if (*p != '\t') 22723ebf6f0aSRob Swindell break; 22733ebf6f0aSRob Swindell *p = 0; 22743ebf6f0aSRob Swindell field++; 22753ebf6f0aSRob Swindell p++; 22763ebf6f0aSRob Swindell } 22773ebf6f0aSRob Swindell if (*p == 0) 22783ebf6f0aSRob Swindell break; 22793ebf6f0aSRob Swindell *p = 0; 22803ebf6f0aSRob Swindell } 22813ebf6f0aSRob Swindell return retval; 22823ebf6f0aSRob Swindell } 22833ebf6f0aSRob Swindell 2284a60faa60SVasundhara Volam static void bnxt_get_pkgver(struct net_device *dev) 22853ebf6f0aSRob Swindell { 2286a60faa60SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 22873ebf6f0aSRob Swindell u16 index = 0; 2288a60faa60SVasundhara Volam char *pkgver; 2289a60faa60SVasundhara Volam u32 pkglen; 2290a60faa60SVasundhara Volam u8 *pkgbuf; 2291a60faa60SVasundhara Volam int len; 22923ebf6f0aSRob Swindell 22933ebf6f0aSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG, 22943ebf6f0aSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 2295a60faa60SVasundhara Volam &index, NULL, &pkglen) != 0) 2296a60faa60SVasundhara Volam return; 22973ebf6f0aSRob Swindell 2298a60faa60SVasundhara Volam pkgbuf = kzalloc(pkglen, GFP_KERNEL); 2299a60faa60SVasundhara Volam if (!pkgbuf) { 2300a60faa60SVasundhara Volam dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n", 2301a60faa60SVasundhara Volam pkglen); 2302a60faa60SVasundhara Volam return; 2303a60faa60SVasundhara Volam } 23043ebf6f0aSRob Swindell 2305a60faa60SVasundhara Volam if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf)) 2306a60faa60SVasundhara Volam goto err; 2307a60faa60SVasundhara Volam 2308a60faa60SVasundhara Volam pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf, 2309a60faa60SVasundhara Volam pkglen); 2310a60faa60SVasundhara Volam if (pkgver && *pkgver != 0 && isdigit(*pkgver)) { 2311a60faa60SVasundhara Volam len = strlen(bp->fw_ver_str); 2312a60faa60SVasundhara Volam snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1, 2313a60faa60SVasundhara Volam "/pkg %s", pkgver); 2314a60faa60SVasundhara Volam } 2315a60faa60SVasundhara Volam err: 2316a60faa60SVasundhara Volam kfree(pkgbuf); 23173ebf6f0aSRob Swindell } 23183ebf6f0aSRob Swindell 2319c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 2320c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2321c0c050c5SMichael Chan u8 *data) 2322c0c050c5SMichael Chan { 2323c0c050c5SMichael Chan u32 index; 2324c0c050c5SMichael Chan u32 offset; 2325c0c050c5SMichael Chan 2326c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 2327c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 2328c0c050c5SMichael Chan 2329c0c050c5SMichael Chan index = eeprom->offset >> 24; 2330c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 2331c0c050c5SMichael Chan 2332c0c050c5SMichael Chan if (index == 0) { 2333c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 2334c0c050c5SMichael Chan return -EINVAL; 2335c0c050c5SMichael Chan } 2336c0c050c5SMichael Chan 2337c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 2338c0c050c5SMichael Chan } 2339c0c050c5SMichael Chan 2340c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 2341c0c050c5SMichael Chan { 2342c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2343c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 2344c0c050c5SMichael Chan 2345c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 2346c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2347c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2348c0c050c5SMichael Chan } 2349c0c050c5SMichael Chan 2350c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 2351c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2352c0c050c5SMichael Chan u8 *data) 2353c0c050c5SMichael Chan { 2354c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2355c0c050c5SMichael Chan u8 index, dir_op; 2356c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 2357c0c050c5SMichael Chan 2358c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 2359c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 2360c0c050c5SMichael Chan return -EINVAL; 2361c0c050c5SMichael Chan } 2362c0c050c5SMichael Chan 2363c0c050c5SMichael Chan type = eeprom->magic >> 16; 2364c0c050c5SMichael Chan 2365c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 2366c0c050c5SMichael Chan index = eeprom->magic & 0xff; 2367c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 2368c0c050c5SMichael Chan if (index == 0) 2369c0c050c5SMichael Chan return -EINVAL; 2370c0c050c5SMichael Chan switch (dir_op) { 2371c0c050c5SMichael Chan case 0x0e: /* erase */ 2372c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 2373c0c050c5SMichael Chan return -EINVAL; 2374c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 2375c0c050c5SMichael Chan default: 2376c0c050c5SMichael Chan return -EINVAL; 2377c0c050c5SMichael Chan } 2378c0c050c5SMichael Chan } 2379c0c050c5SMichael Chan 2380c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 2381c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(type) == true) 23825ac67d8bSRob Swindell return -EOPNOTSUPP; 2383c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 2384c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 2385c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 2386c0c050c5SMichael Chan 2387c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 2388c0c050c5SMichael Chan eeprom->len); 2389c0c050c5SMichael Chan } 2390c0c050c5SMichael Chan 239172b34f04SMichael Chan static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata) 239272b34f04SMichael Chan { 239372b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 239472b34f04SMichael Chan struct ethtool_eee *eee = &bp->eee; 239572b34f04SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 239672b34f04SMichael Chan u32 advertising = 239772b34f04SMichael Chan _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); 239872b34f04SMichael Chan int rc = 0; 239972b34f04SMichael Chan 2400567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 240175362a3fSMichael Chan return -EOPNOTSUPP; 240272b34f04SMichael Chan 240372b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 240472b34f04SMichael Chan return -EOPNOTSUPP; 240572b34f04SMichael Chan 240672b34f04SMichael Chan if (!edata->eee_enabled) 240772b34f04SMichael Chan goto eee_ok; 240872b34f04SMichael Chan 240972b34f04SMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { 241072b34f04SMichael Chan netdev_warn(dev, "EEE requires autoneg\n"); 241172b34f04SMichael Chan return -EINVAL; 241272b34f04SMichael Chan } 241372b34f04SMichael Chan if (edata->tx_lpi_enabled) { 241472b34f04SMichael Chan if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi || 241572b34f04SMichael Chan edata->tx_lpi_timer < bp->lpi_tmr_lo)) { 241672b34f04SMichael Chan netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n", 241772b34f04SMichael Chan bp->lpi_tmr_lo, bp->lpi_tmr_hi); 241872b34f04SMichael Chan return -EINVAL; 241972b34f04SMichael Chan } else if (!bp->lpi_tmr_hi) { 242072b34f04SMichael Chan edata->tx_lpi_timer = eee->tx_lpi_timer; 242172b34f04SMichael Chan } 242272b34f04SMichael Chan } 242372b34f04SMichael Chan if (!edata->advertised) { 242472b34f04SMichael Chan edata->advertised = advertising & eee->supported; 242572b34f04SMichael Chan } else if (edata->advertised & ~advertising) { 242672b34f04SMichael Chan netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", 242772b34f04SMichael Chan edata->advertised, advertising); 242872b34f04SMichael Chan return -EINVAL; 242972b34f04SMichael Chan } 243072b34f04SMichael Chan 243172b34f04SMichael Chan eee->advertised = edata->advertised; 243272b34f04SMichael Chan eee->tx_lpi_enabled = edata->tx_lpi_enabled; 243372b34f04SMichael Chan eee->tx_lpi_timer = edata->tx_lpi_timer; 243472b34f04SMichael Chan eee_ok: 243572b34f04SMichael Chan eee->eee_enabled = edata->eee_enabled; 243672b34f04SMichael Chan 243772b34f04SMichael Chan if (netif_running(dev)) 243872b34f04SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, false, true); 243972b34f04SMichael Chan 244072b34f04SMichael Chan return rc; 244172b34f04SMichael Chan } 244272b34f04SMichael Chan 244372b34f04SMichael Chan static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata) 244472b34f04SMichael Chan { 244572b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 244672b34f04SMichael Chan 244772b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 244872b34f04SMichael Chan return -EOPNOTSUPP; 244972b34f04SMichael Chan 245072b34f04SMichael Chan *edata = bp->eee; 245172b34f04SMichael Chan if (!bp->eee.eee_enabled) { 245272b34f04SMichael Chan /* Preserve tx_lpi_timer so that the last value will be used 245372b34f04SMichael Chan * by default when it is re-enabled. 245472b34f04SMichael Chan */ 245572b34f04SMichael Chan edata->advertised = 0; 245672b34f04SMichael Chan edata->tx_lpi_enabled = 0; 245772b34f04SMichael Chan } 245872b34f04SMichael Chan 245972b34f04SMichael Chan if (!bp->eee.eee_active) 246072b34f04SMichael Chan edata->lp_advertised = 0; 246172b34f04SMichael Chan 246272b34f04SMichael Chan return 0; 246372b34f04SMichael Chan } 246472b34f04SMichael Chan 246542ee18feSAjit Khaparde static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr, 246642ee18feSAjit Khaparde u16 page_number, u16 start_addr, 246742ee18feSAjit Khaparde u16 data_length, u8 *buf) 246842ee18feSAjit Khaparde { 246942ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_input req = {0}; 247042ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr; 247142ee18feSAjit Khaparde int rc, byte_offset = 0; 247242ee18feSAjit Khaparde 247342ee18feSAjit Khaparde bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1); 247442ee18feSAjit Khaparde req.i2c_slave_addr = i2c_addr; 247542ee18feSAjit Khaparde req.page_number = cpu_to_le16(page_number); 247642ee18feSAjit Khaparde req.port_id = cpu_to_le16(bp->pf.port_id); 247742ee18feSAjit Khaparde do { 247842ee18feSAjit Khaparde u16 xfer_size; 247942ee18feSAjit Khaparde 248042ee18feSAjit Khaparde xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE); 248142ee18feSAjit Khaparde data_length -= xfer_size; 248242ee18feSAjit Khaparde req.page_offset = cpu_to_le16(start_addr + byte_offset); 248342ee18feSAjit Khaparde req.data_length = xfer_size; 248442ee18feSAjit Khaparde req.enables = cpu_to_le32(start_addr + byte_offset ? 248542ee18feSAjit Khaparde PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0); 248642ee18feSAjit Khaparde mutex_lock(&bp->hwrm_cmd_lock); 248742ee18feSAjit Khaparde rc = _hwrm_send_message(bp, &req, sizeof(req), 248842ee18feSAjit Khaparde HWRM_CMD_TIMEOUT); 248942ee18feSAjit Khaparde if (!rc) 249042ee18feSAjit Khaparde memcpy(buf + byte_offset, output->data, xfer_size); 249142ee18feSAjit Khaparde mutex_unlock(&bp->hwrm_cmd_lock); 249242ee18feSAjit Khaparde byte_offset += xfer_size; 249342ee18feSAjit Khaparde } while (!rc && data_length > 0); 249442ee18feSAjit Khaparde 249542ee18feSAjit Khaparde return rc; 249642ee18feSAjit Khaparde } 249742ee18feSAjit Khaparde 249842ee18feSAjit Khaparde static int bnxt_get_module_info(struct net_device *dev, 249942ee18feSAjit Khaparde struct ethtool_modinfo *modinfo) 250042ee18feSAjit Khaparde { 25017328a23cSVasundhara Volam u8 data[SFF_DIAG_SUPPORT_OFFSET + 1]; 250242ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 250342ee18feSAjit Khaparde int rc; 250442ee18feSAjit Khaparde 250542ee18feSAjit Khaparde /* No point in going further if phy status indicates 250642ee18feSAjit Khaparde * module is not inserted or if it is powered down or 250742ee18feSAjit Khaparde * if it is of type 10GBase-T 250842ee18feSAjit Khaparde */ 250942ee18feSAjit Khaparde if (bp->link_info.module_status > 251042ee18feSAjit Khaparde PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG) 251142ee18feSAjit Khaparde return -EOPNOTSUPP; 251242ee18feSAjit Khaparde 251342ee18feSAjit Khaparde /* This feature is not supported in older firmware versions */ 251442ee18feSAjit Khaparde if (bp->hwrm_spec_code < 0x10202) 251542ee18feSAjit Khaparde return -EOPNOTSUPP; 251642ee18feSAjit Khaparde 25177328a23cSVasundhara Volam rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0, 25187328a23cSVasundhara Volam SFF_DIAG_SUPPORT_OFFSET + 1, 25197328a23cSVasundhara Volam data); 252042ee18feSAjit Khaparde if (!rc) { 25217328a23cSVasundhara Volam u8 module_id = data[0]; 25227328a23cSVasundhara Volam u8 diag_supported = data[SFF_DIAG_SUPPORT_OFFSET]; 252342ee18feSAjit Khaparde 252442ee18feSAjit Khaparde switch (module_id) { 252542ee18feSAjit Khaparde case SFF_MODULE_ID_SFP: 252642ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8472; 252742ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 25287328a23cSVasundhara Volam if (!diag_supported) 25297328a23cSVasundhara Volam modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 253042ee18feSAjit Khaparde break; 253142ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP: 253242ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP_PLUS: 253342ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8436; 253442ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 253542ee18feSAjit Khaparde break; 253642ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP28: 253742ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8636; 253842ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 253942ee18feSAjit Khaparde break; 254042ee18feSAjit Khaparde default: 254142ee18feSAjit Khaparde rc = -EOPNOTSUPP; 254242ee18feSAjit Khaparde break; 254342ee18feSAjit Khaparde } 254442ee18feSAjit Khaparde } 254542ee18feSAjit Khaparde return rc; 254642ee18feSAjit Khaparde } 254742ee18feSAjit Khaparde 254842ee18feSAjit Khaparde static int bnxt_get_module_eeprom(struct net_device *dev, 254942ee18feSAjit Khaparde struct ethtool_eeprom *eeprom, 255042ee18feSAjit Khaparde u8 *data) 255142ee18feSAjit Khaparde { 255242ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 255342ee18feSAjit Khaparde u16 start = eeprom->offset, length = eeprom->len; 2554f3ea3119SColin Ian King int rc = 0; 255542ee18feSAjit Khaparde 255642ee18feSAjit Khaparde memset(data, 0, eeprom->len); 255742ee18feSAjit Khaparde 255842ee18feSAjit Khaparde /* Read A0 portion of the EEPROM */ 255942ee18feSAjit Khaparde if (start < ETH_MODULE_SFF_8436_LEN) { 256042ee18feSAjit Khaparde if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN) 256142ee18feSAjit Khaparde length = ETH_MODULE_SFF_8436_LEN - start; 256242ee18feSAjit Khaparde rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 256342ee18feSAjit Khaparde start, length, data); 256442ee18feSAjit Khaparde if (rc) 256542ee18feSAjit Khaparde return rc; 256642ee18feSAjit Khaparde start += length; 256742ee18feSAjit Khaparde data += length; 256842ee18feSAjit Khaparde length = eeprom->len - length; 256942ee18feSAjit Khaparde } 257042ee18feSAjit Khaparde 257142ee18feSAjit Khaparde /* Read A2 portion of the EEPROM */ 257242ee18feSAjit Khaparde if (length) { 257342ee18feSAjit Khaparde start -= ETH_MODULE_SFF_8436_LEN; 2574dea521a2SChristophe JAILLET rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1, 2575dea521a2SChristophe JAILLET start, length, data); 257642ee18feSAjit Khaparde } 257742ee18feSAjit Khaparde return rc; 257842ee18feSAjit Khaparde } 257942ee18feSAjit Khaparde 2580ae8e98a6SDeepak Khungar static int bnxt_nway_reset(struct net_device *dev) 2581ae8e98a6SDeepak Khungar { 2582ae8e98a6SDeepak Khungar int rc = 0; 2583ae8e98a6SDeepak Khungar 2584ae8e98a6SDeepak Khungar struct bnxt *bp = netdev_priv(dev); 2585ae8e98a6SDeepak Khungar struct bnxt_link_info *link_info = &bp->link_info; 2586ae8e98a6SDeepak Khungar 2587ae8e98a6SDeepak Khungar if (!BNXT_SINGLE_PF(bp)) 2588ae8e98a6SDeepak Khungar return -EOPNOTSUPP; 2589ae8e98a6SDeepak Khungar 2590ae8e98a6SDeepak Khungar if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 2591ae8e98a6SDeepak Khungar return -EINVAL; 2592ae8e98a6SDeepak Khungar 2593ae8e98a6SDeepak Khungar if (netif_running(dev)) 2594ae8e98a6SDeepak Khungar rc = bnxt_hwrm_set_link_setting(bp, true, false); 2595ae8e98a6SDeepak Khungar 2596ae8e98a6SDeepak Khungar return rc; 2597ae8e98a6SDeepak Khungar } 2598ae8e98a6SDeepak Khungar 25995ad2cbeeSMichael Chan static int bnxt_set_phys_id(struct net_device *dev, 26005ad2cbeeSMichael Chan enum ethtool_phys_id_state state) 26015ad2cbeeSMichael Chan { 26025ad2cbeeSMichael Chan struct hwrm_port_led_cfg_input req = {0}; 26035ad2cbeeSMichael Chan struct bnxt *bp = netdev_priv(dev); 26045ad2cbeeSMichael Chan struct bnxt_pf_info *pf = &bp->pf; 26055ad2cbeeSMichael Chan struct bnxt_led_cfg *led_cfg; 26065ad2cbeeSMichael Chan u8 led_state; 26075ad2cbeeSMichael Chan __le16 duration; 26085ad2cbeeSMichael Chan int i, rc; 26095ad2cbeeSMichael Chan 26105ad2cbeeSMichael Chan if (!bp->num_leds || BNXT_VF(bp)) 26115ad2cbeeSMichael Chan return -EOPNOTSUPP; 26125ad2cbeeSMichael Chan 26135ad2cbeeSMichael Chan if (state == ETHTOOL_ID_ACTIVE) { 26145ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT; 26155ad2cbeeSMichael Chan duration = cpu_to_le16(500); 26165ad2cbeeSMichael Chan } else if (state == ETHTOOL_ID_INACTIVE) { 26175ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT; 26185ad2cbeeSMichael Chan duration = cpu_to_le16(0); 26195ad2cbeeSMichael Chan } else { 26205ad2cbeeSMichael Chan return -EINVAL; 26215ad2cbeeSMichael Chan } 26225ad2cbeeSMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1); 26235ad2cbeeSMichael Chan req.port_id = cpu_to_le16(pf->port_id); 26245ad2cbeeSMichael Chan req.num_leds = bp->num_leds; 26255ad2cbeeSMichael Chan led_cfg = (struct bnxt_led_cfg *)&req.led0_id; 26265ad2cbeeSMichael Chan for (i = 0; i < bp->num_leds; i++, led_cfg++) { 26275ad2cbeeSMichael Chan req.enables |= BNXT_LED_DFLT_ENABLES(i); 26285ad2cbeeSMichael Chan led_cfg->led_id = bp->leds[i].led_id; 26295ad2cbeeSMichael Chan led_cfg->led_state = led_state; 26305ad2cbeeSMichael Chan led_cfg->led_blink_on = duration; 26315ad2cbeeSMichael Chan led_cfg->led_blink_off = duration; 26325ad2cbeeSMichael Chan led_cfg->led_group_id = bp->leds[i].led_group_id; 26335ad2cbeeSMichael Chan } 26345ad2cbeeSMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 26355ad2cbeeSMichael Chan return rc; 26365ad2cbeeSMichael Chan } 26375ad2cbeeSMichael Chan 263867fea463SMichael Chan static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring) 263967fea463SMichael Chan { 264067fea463SMichael Chan struct hwrm_selftest_irq_input req = {0}; 264167fea463SMichael Chan 264267fea463SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1); 264367fea463SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 264467fea463SMichael Chan } 264567fea463SMichael Chan 264667fea463SMichael Chan static int bnxt_test_irq(struct bnxt *bp) 264767fea463SMichael Chan { 264867fea463SMichael Chan int i; 264967fea463SMichael Chan 265067fea463SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 265167fea463SMichael Chan u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id; 265267fea463SMichael Chan int rc; 265367fea463SMichael Chan 265467fea463SMichael Chan rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring); 265567fea463SMichael Chan if (rc) 265667fea463SMichael Chan return rc; 265767fea463SMichael Chan } 265867fea463SMichael Chan return 0; 265967fea463SMichael Chan } 266067fea463SMichael Chan 2661f7dc1ea6SMichael Chan static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable) 2662f7dc1ea6SMichael Chan { 2663f7dc1ea6SMichael Chan struct hwrm_port_mac_cfg_input req = {0}; 2664f7dc1ea6SMichael Chan 2665f7dc1ea6SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1); 2666f7dc1ea6SMichael Chan 2667f7dc1ea6SMichael Chan req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK); 2668f7dc1ea6SMichael Chan if (enable) 2669f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL; 2670f7dc1ea6SMichael Chan else 2671f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE; 2672f7dc1ea6SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2673f7dc1ea6SMichael Chan } 2674f7dc1ea6SMichael Chan 267556d37462SVasundhara Volam static int bnxt_query_force_speeds(struct bnxt *bp, u16 *force_speeds) 267656d37462SVasundhara Volam { 267756d37462SVasundhara Volam struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; 267856d37462SVasundhara Volam struct hwrm_port_phy_qcaps_input req = {0}; 267956d37462SVasundhara Volam int rc; 268056d37462SVasundhara Volam 268156d37462SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); 268256d37462SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 268356d37462SVasundhara Volam rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 268456d37462SVasundhara Volam if (!rc) 268556d37462SVasundhara Volam *force_speeds = le16_to_cpu(resp->supported_speeds_force_mode); 268656d37462SVasundhara Volam 268756d37462SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 268856d37462SVasundhara Volam return rc; 268956d37462SVasundhara Volam } 269056d37462SVasundhara Volam 269191725d89SMichael Chan static int bnxt_disable_an_for_lpbk(struct bnxt *bp, 269291725d89SMichael Chan struct hwrm_port_phy_cfg_input *req) 269391725d89SMichael Chan { 269491725d89SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 269556d37462SVasundhara Volam u16 fw_advertising; 269691725d89SMichael Chan u16 fw_speed; 269791725d89SMichael Chan int rc; 269891725d89SMichael Chan 269991725d89SMichael Chan if (!link_info->autoneg) 270091725d89SMichael Chan return 0; 270191725d89SMichael Chan 270256d37462SVasundhara Volam rc = bnxt_query_force_speeds(bp, &fw_advertising); 270356d37462SVasundhara Volam if (rc) 270456d37462SVasundhara Volam return rc; 270556d37462SVasundhara Volam 270691725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB; 270791725d89SMichael Chan if (netif_carrier_ok(bp->dev)) 270891725d89SMichael Chan fw_speed = bp->link_info.link_speed; 270991725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB) 271091725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB; 271191725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB) 271291725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB; 271391725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB) 271491725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB; 271591725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB) 271691725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB; 271791725d89SMichael Chan 271891725d89SMichael Chan req->force_link_speed = cpu_to_le16(fw_speed); 271991725d89SMichael Chan req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE | 272091725d89SMichael Chan PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); 272191725d89SMichael Chan rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT); 272291725d89SMichael Chan req->flags = 0; 272391725d89SMichael Chan req->force_link_speed = cpu_to_le16(0); 272491725d89SMichael Chan return rc; 272591725d89SMichael Chan } 272691725d89SMichael Chan 272755fd0cf3SMichael Chan static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable, bool ext) 272891725d89SMichael Chan { 272991725d89SMichael Chan struct hwrm_port_phy_cfg_input req = {0}; 273091725d89SMichael Chan 273191725d89SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); 273291725d89SMichael Chan 273391725d89SMichael Chan if (enable) { 273491725d89SMichael Chan bnxt_disable_an_for_lpbk(bp, &req); 273555fd0cf3SMichael Chan if (ext) 273655fd0cf3SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_EXTERNAL; 273755fd0cf3SMichael Chan else 273891725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL; 273991725d89SMichael Chan } else { 274091725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE; 274191725d89SMichael Chan } 274291725d89SMichael Chan req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK); 274391725d89SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 274491725d89SMichael Chan } 274591725d89SMichael Chan 2746e44758b7SMichael Chan static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2747f7dc1ea6SMichael Chan u32 raw_cons, int pkt_size) 2748f7dc1ea6SMichael Chan { 2749e44758b7SMichael Chan struct bnxt_napi *bnapi = cpr->bnapi; 2750e44758b7SMichael Chan struct bnxt_rx_ring_info *rxr; 2751f7dc1ea6SMichael Chan struct bnxt_sw_rx_bd *rx_buf; 2752f7dc1ea6SMichael Chan struct rx_cmp *rxcmp; 2753f7dc1ea6SMichael Chan u16 cp_cons, cons; 2754f7dc1ea6SMichael Chan u8 *data; 2755f7dc1ea6SMichael Chan u32 len; 2756f7dc1ea6SMichael Chan int i; 2757f7dc1ea6SMichael Chan 2758e44758b7SMichael Chan rxr = bnapi->rx_ring; 2759f7dc1ea6SMichael Chan cp_cons = RING_CMP(raw_cons); 2760f7dc1ea6SMichael Chan rxcmp = (struct rx_cmp *) 2761f7dc1ea6SMichael Chan &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; 2762f7dc1ea6SMichael Chan cons = rxcmp->rx_cmp_opaque; 2763f7dc1ea6SMichael Chan rx_buf = &rxr->rx_buf_ring[cons]; 2764f7dc1ea6SMichael Chan data = rx_buf->data_ptr; 2765f7dc1ea6SMichael Chan len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT; 2766f7dc1ea6SMichael Chan if (len != pkt_size) 2767f7dc1ea6SMichael Chan return -EIO; 2768f7dc1ea6SMichael Chan i = ETH_ALEN; 2769f7dc1ea6SMichael Chan if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr)) 2770f7dc1ea6SMichael Chan return -EIO; 2771f7dc1ea6SMichael Chan i += ETH_ALEN; 2772f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) { 2773f7dc1ea6SMichael Chan if (data[i] != (u8)(i & 0xff)) 2774f7dc1ea6SMichael Chan return -EIO; 2775f7dc1ea6SMichael Chan } 2776f7dc1ea6SMichael Chan return 0; 2777f7dc1ea6SMichael Chan } 2778f7dc1ea6SMichael Chan 2779e44758b7SMichael Chan static int bnxt_poll_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2780e44758b7SMichael Chan int pkt_size) 2781f7dc1ea6SMichael Chan { 2782f7dc1ea6SMichael Chan struct tx_cmp *txcmp; 2783f7dc1ea6SMichael Chan int rc = -EIO; 2784f7dc1ea6SMichael Chan u32 raw_cons; 2785f7dc1ea6SMichael Chan u32 cons; 2786f7dc1ea6SMichael Chan int i; 2787f7dc1ea6SMichael Chan 2788f7dc1ea6SMichael Chan raw_cons = cpr->cp_raw_cons; 2789f7dc1ea6SMichael Chan for (i = 0; i < 200; i++) { 2790f7dc1ea6SMichael Chan cons = RING_CMP(raw_cons); 2791f7dc1ea6SMichael Chan txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; 2792f7dc1ea6SMichael Chan 2793f7dc1ea6SMichael Chan if (!TX_CMP_VALID(txcmp, raw_cons)) { 2794f7dc1ea6SMichael Chan udelay(5); 2795f7dc1ea6SMichael Chan continue; 2796f7dc1ea6SMichael Chan } 2797f7dc1ea6SMichael Chan 2798f7dc1ea6SMichael Chan /* The valid test of the entry must be done first before 2799f7dc1ea6SMichael Chan * reading any further. 2800f7dc1ea6SMichael Chan */ 2801f7dc1ea6SMichael Chan dma_rmb(); 2802f7dc1ea6SMichael Chan if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) { 2803e44758b7SMichael Chan rc = bnxt_rx_loopback(bp, cpr, raw_cons, pkt_size); 2804f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2805f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2806f7dc1ea6SMichael Chan break; 2807f7dc1ea6SMichael Chan } 2808f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2809f7dc1ea6SMichael Chan } 2810f7dc1ea6SMichael Chan cpr->cp_raw_cons = raw_cons; 2811f7dc1ea6SMichael Chan return rc; 2812f7dc1ea6SMichael Chan } 2813f7dc1ea6SMichael Chan 2814f7dc1ea6SMichael Chan static int bnxt_run_loopback(struct bnxt *bp) 2815f7dc1ea6SMichael Chan { 2816f7dc1ea6SMichael Chan struct bnxt_tx_ring_info *txr = &bp->tx_ring[0]; 281784404d5fSMichael Chan struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0]; 2818e44758b7SMichael Chan struct bnxt_cp_ring_info *cpr; 2819f7dc1ea6SMichael Chan int pkt_size, i = 0; 2820f7dc1ea6SMichael Chan struct sk_buff *skb; 2821f7dc1ea6SMichael Chan dma_addr_t map; 2822f7dc1ea6SMichael Chan u8 *data; 2823f7dc1ea6SMichael Chan int rc; 2824f7dc1ea6SMichael Chan 282584404d5fSMichael Chan cpr = &rxr->bnapi->cp_ring; 282684404d5fSMichael Chan if (bp->flags & BNXT_FLAG_CHIP_P5) 282784404d5fSMichael Chan cpr = cpr->cp_ring_arr[BNXT_RX_HDL]; 2828f7dc1ea6SMichael Chan pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh); 2829f7dc1ea6SMichael Chan skb = netdev_alloc_skb(bp->dev, pkt_size); 2830f7dc1ea6SMichael Chan if (!skb) 2831f7dc1ea6SMichael Chan return -ENOMEM; 2832f7dc1ea6SMichael Chan data = skb_put(skb, pkt_size); 2833f7dc1ea6SMichael Chan eth_broadcast_addr(data); 2834f7dc1ea6SMichael Chan i += ETH_ALEN; 2835f7dc1ea6SMichael Chan ether_addr_copy(&data[i], bp->dev->dev_addr); 2836f7dc1ea6SMichael Chan i += ETH_ALEN; 2837f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) 2838f7dc1ea6SMichael Chan data[i] = (u8)(i & 0xff); 2839f7dc1ea6SMichael Chan 2840f7dc1ea6SMichael Chan map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size, 2841f7dc1ea6SMichael Chan PCI_DMA_TODEVICE); 2842f7dc1ea6SMichael Chan if (dma_mapping_error(&bp->pdev->dev, map)) { 2843f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2844f7dc1ea6SMichael Chan return -EIO; 2845f7dc1ea6SMichael Chan } 2846c1ba92a8SMichael Chan bnxt_xmit_bd(bp, txr, map, pkt_size); 2847f7dc1ea6SMichael Chan 2848f7dc1ea6SMichael Chan /* Sync BD data before updating doorbell */ 2849f7dc1ea6SMichael Chan wmb(); 2850f7dc1ea6SMichael Chan 2851697197e5SMichael Chan bnxt_db_write(bp, &txr->tx_db, txr->tx_prod); 2852e44758b7SMichael Chan rc = bnxt_poll_loopback(bp, cpr, pkt_size); 2853f7dc1ea6SMichael Chan 2854f7dc1ea6SMichael Chan dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE); 2855f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2856f7dc1ea6SMichael Chan return rc; 2857f7dc1ea6SMichael Chan } 2858f7dc1ea6SMichael Chan 2859eb513658SMichael Chan static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results) 2860eb513658SMichael Chan { 2861eb513658SMichael Chan struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr; 2862eb513658SMichael Chan struct hwrm_selftest_exec_input req = {0}; 2863eb513658SMichael Chan int rc; 2864eb513658SMichael Chan 2865eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1); 2866eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2867eb513658SMichael Chan resp->test_success = 0; 2868eb513658SMichael Chan req.flags = test_mask; 2869eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout); 2870eb513658SMichael Chan *test_results = resp->test_success; 2871eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2872eb513658SMichael Chan return rc; 2873eb513658SMichael Chan } 2874eb513658SMichael Chan 287555fd0cf3SMichael Chan #define BNXT_DRV_TESTS 4 2876f7dc1ea6SMichael Chan #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS) 287791725d89SMichael Chan #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1) 287855fd0cf3SMichael Chan #define BNXT_EXTLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2) 287955fd0cf3SMichael Chan #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 3) 2880eb513658SMichael Chan 2881eb513658SMichael Chan static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest, 2882eb513658SMichael Chan u64 *buf) 2883eb513658SMichael Chan { 2884eb513658SMichael Chan struct bnxt *bp = netdev_priv(dev); 288555fd0cf3SMichael Chan bool do_ext_lpbk = false; 2886eb513658SMichael Chan bool offline = false; 2887eb513658SMichael Chan u8 test_results = 0; 2888eb513658SMichael Chan u8 test_mask = 0; 2889d27e2ca1SMichael Chan int rc = 0, i; 2890eb513658SMichael Chan 2891eb513658SMichael Chan if (!bp->num_tests || !BNXT_SINGLE_PF(bp)) 2892eb513658SMichael Chan return; 2893eb513658SMichael Chan memset(buf, 0, sizeof(u64) * bp->num_tests); 2894eb513658SMichael Chan if (!netif_running(dev)) { 2895eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2896eb513658SMichael Chan return; 2897eb513658SMichael Chan } 2898eb513658SMichael Chan 289955fd0cf3SMichael Chan if ((etest->flags & ETH_TEST_FL_EXTERNAL_LB) && 290055fd0cf3SMichael Chan (bp->test_info->flags & BNXT_TEST_FL_EXT_LPBK)) 290155fd0cf3SMichael Chan do_ext_lpbk = true; 290255fd0cf3SMichael Chan 2903eb513658SMichael Chan if (etest->flags & ETH_TEST_FL_OFFLINE) { 2904eb513658SMichael Chan if (bp->pf.active_vfs) { 2905eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2906eb513658SMichael Chan netdev_warn(dev, "Offline tests cannot be run with active VFs\n"); 2907eb513658SMichael Chan return; 2908eb513658SMichael Chan } 2909eb513658SMichael Chan offline = true; 2910eb513658SMichael Chan } 2911eb513658SMichael Chan 2912eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 2913eb513658SMichael Chan u8 bit_val = 1 << i; 2914eb513658SMichael Chan 2915eb513658SMichael Chan if (!(bp->test_info->offline_mask & bit_val)) 2916eb513658SMichael Chan test_mask |= bit_val; 2917eb513658SMichael Chan else if (offline) 2918eb513658SMichael Chan test_mask |= bit_val; 2919eb513658SMichael Chan } 2920eb513658SMichael Chan if (!offline) { 2921eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 2922eb513658SMichael Chan } else { 2923eb513658SMichael Chan rc = bnxt_close_nic(bp, false, false); 2924eb513658SMichael Chan if (rc) 2925eb513658SMichael Chan return; 2926eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 2927f7dc1ea6SMichael Chan 2928f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 1; 2929f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, true); 2930f7dc1ea6SMichael Chan msleep(250); 2931f7dc1ea6SMichael Chan rc = bnxt_half_open_nic(bp); 2932f7dc1ea6SMichael Chan if (rc) { 2933f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 2934f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2935f7dc1ea6SMichael Chan return; 2936f7dc1ea6SMichael Chan } 2937f7dc1ea6SMichael Chan if (bnxt_run_loopback(bp)) 2938f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2939f7dc1ea6SMichael Chan else 2940f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 0; 2941f7dc1ea6SMichael Chan 2942f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 294355fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, false); 294491725d89SMichael Chan msleep(1000); 294591725d89SMichael Chan if (bnxt_run_loopback(bp)) { 294691725d89SMichael Chan buf[BNXT_PHYLPBK_TEST_IDX] = 1; 294791725d89SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 294891725d89SMichael Chan } 294955fd0cf3SMichael Chan if (do_ext_lpbk) { 295055fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; 295155fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, true); 295255fd0cf3SMichael Chan msleep(1000); 295355fd0cf3SMichael Chan if (bnxt_run_loopback(bp)) { 295455fd0cf3SMichael Chan buf[BNXT_EXTLPBK_TEST_IDX] = 1; 295555fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 295655fd0cf3SMichael Chan } 295755fd0cf3SMichael Chan } 295855fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, false, false); 295991725d89SMichael Chan bnxt_half_close_nic(bp); 2960d27e2ca1SMichael Chan rc = bnxt_open_nic(bp, false, true); 2961eb513658SMichael Chan } 2962d27e2ca1SMichael Chan if (rc || bnxt_test_irq(bp)) { 296367fea463SMichael Chan buf[BNXT_IRQ_TEST_IDX] = 1; 296467fea463SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 296567fea463SMichael Chan } 2966eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 2967eb513658SMichael Chan u8 bit_val = 1 << i; 2968eb513658SMichael Chan 2969eb513658SMichael Chan if ((test_mask & bit_val) && !(test_results & bit_val)) { 2970eb513658SMichael Chan buf[i] = 1; 2971eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2972eb513658SMichael Chan } 2973eb513658SMichael Chan } 2974eb513658SMichael Chan } 2975eb513658SMichael Chan 297649f7972fSVasundhara Volam static int bnxt_reset(struct net_device *dev, u32 *flags) 297749f7972fSVasundhara Volam { 297849f7972fSVasundhara Volam struct bnxt *bp = netdev_priv(dev); 297949f7972fSVasundhara Volam int rc = 0; 298049f7972fSVasundhara Volam 298149f7972fSVasundhara Volam if (!BNXT_PF(bp)) { 298249f7972fSVasundhara Volam netdev_err(dev, "Reset is not supported from a VF\n"); 298349f7972fSVasundhara Volam return -EOPNOTSUPP; 298449f7972fSVasundhara Volam } 298549f7972fSVasundhara Volam 298649f7972fSVasundhara Volam if (pci_vfs_assigned(bp->pdev)) { 298749f7972fSVasundhara Volam netdev_err(dev, 298849f7972fSVasundhara Volam "Reset not allowed when VFs are assigned to VMs\n"); 298949f7972fSVasundhara Volam return -EBUSY; 299049f7972fSVasundhara Volam } 299149f7972fSVasundhara Volam 299249f7972fSVasundhara Volam if (*flags == ETH_RESET_ALL) { 299349f7972fSVasundhara Volam /* This feature is not supported in older firmware versions */ 299449f7972fSVasundhara Volam if (bp->hwrm_spec_code < 0x10803) 299549f7972fSVasundhara Volam return -EOPNOTSUPP; 299649f7972fSVasundhara Volam 299749f7972fSVasundhara Volam rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_CHIP); 29982373d8d6SScott Branden if (!rc) { 299949f7972fSVasundhara Volam netdev_info(dev, "Reset request successful. Reload driver to complete reset\n"); 30002373d8d6SScott Branden *flags = 0; 30012373d8d6SScott Branden } 30026502ad59SScott Branden } else if (*flags == ETH_RESET_AP) { 30036502ad59SScott Branden /* This feature is not supported in older firmware versions */ 30046502ad59SScott Branden if (bp->hwrm_spec_code < 0x10803) 30056502ad59SScott Branden return -EOPNOTSUPP; 30066502ad59SScott Branden 30076502ad59SScott Branden rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_AP); 30082373d8d6SScott Branden if (!rc) { 30096502ad59SScott Branden netdev_info(dev, "Reset Application Processor request successful.\n"); 30102373d8d6SScott Branden *flags = 0; 30112373d8d6SScott Branden } 301249f7972fSVasundhara Volam } else { 301349f7972fSVasundhara Volam rc = -EINVAL; 301449f7972fSVasundhara Volam } 301549f7972fSVasundhara Volam 301649f7972fSVasundhara Volam return rc; 301749f7972fSVasundhara Volam } 301849f7972fSVasundhara Volam 30196c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg, int msg_len, 30206c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info *info) 30216c5657d0SVasundhara Volam { 30226c5657d0SVasundhara Volam struct hwrm_dbg_cmn_output *cmn_resp = bp->hwrm_cmd_resp_addr; 30236c5657d0SVasundhara Volam struct hwrm_dbg_cmn_input *cmn_req = msg; 30246c5657d0SVasundhara Volam __le16 *seq_ptr = msg + info->seq_off; 30256c5657d0SVasundhara Volam u16 seq = 0, len, segs_off; 30266c5657d0SVasundhara Volam void *resp = cmn_resp; 30276c5657d0SVasundhara Volam dma_addr_t dma_handle; 30286c5657d0SVasundhara Volam int rc, off = 0; 30296c5657d0SVasundhara Volam void *dma_buf; 30306c5657d0SVasundhara Volam 30316c5657d0SVasundhara Volam dma_buf = dma_alloc_coherent(&bp->pdev->dev, info->dma_len, &dma_handle, 30326c5657d0SVasundhara Volam GFP_KERNEL); 30336c5657d0SVasundhara Volam if (!dma_buf) 30346c5657d0SVasundhara Volam return -ENOMEM; 30356c5657d0SVasundhara Volam 30366c5657d0SVasundhara Volam segs_off = offsetof(struct hwrm_dbg_coredump_list_output, 30376c5657d0SVasundhara Volam total_segments); 30386c5657d0SVasundhara Volam cmn_req->host_dest_addr = cpu_to_le64(dma_handle); 30396c5657d0SVasundhara Volam cmn_req->host_buf_len = cpu_to_le32(info->dma_len); 30406c5657d0SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 30416c5657d0SVasundhara Volam while (1) { 30426c5657d0SVasundhara Volam *seq_ptr = cpu_to_le16(seq); 30436c5657d0SVasundhara Volam rc = _hwrm_send_message(bp, msg, msg_len, HWRM_CMD_TIMEOUT); 30446c5657d0SVasundhara Volam if (rc) 30456c5657d0SVasundhara Volam break; 30466c5657d0SVasundhara Volam 30476c5657d0SVasundhara Volam len = le16_to_cpu(*((__le16 *)(resp + info->data_len_off))); 30486c5657d0SVasundhara Volam if (!seq && 30496c5657d0SVasundhara Volam cmn_req->req_type == cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) { 30506c5657d0SVasundhara Volam info->segs = le16_to_cpu(*((__le16 *)(resp + 30516c5657d0SVasundhara Volam segs_off))); 30526c5657d0SVasundhara Volam if (!info->segs) { 30536c5657d0SVasundhara Volam rc = -EIO; 30546c5657d0SVasundhara Volam break; 30556c5657d0SVasundhara Volam } 30566c5657d0SVasundhara Volam 30576c5657d0SVasundhara Volam info->dest_buf_size = info->segs * 30586c5657d0SVasundhara Volam sizeof(struct coredump_segment_record); 30596c5657d0SVasundhara Volam info->dest_buf = kmalloc(info->dest_buf_size, 30606c5657d0SVasundhara Volam GFP_KERNEL); 30616c5657d0SVasundhara Volam if (!info->dest_buf) { 30626c5657d0SVasundhara Volam rc = -ENOMEM; 30636c5657d0SVasundhara Volam break; 30646c5657d0SVasundhara Volam } 30656c5657d0SVasundhara Volam } 30666c5657d0SVasundhara Volam 30676c5657d0SVasundhara Volam if (info->dest_buf) 30686c5657d0SVasundhara Volam memcpy(info->dest_buf + off, dma_buf, len); 30696c5657d0SVasundhara Volam 30706c5657d0SVasundhara Volam if (cmn_req->req_type == 30716c5657d0SVasundhara Volam cpu_to_le16(HWRM_DBG_COREDUMP_RETRIEVE)) 30726c5657d0SVasundhara Volam info->dest_buf_size += len; 30736c5657d0SVasundhara Volam 30746c5657d0SVasundhara Volam if (!(cmn_resp->flags & HWRM_DBG_CMN_FLAGS_MORE)) 30756c5657d0SVasundhara Volam break; 30766c5657d0SVasundhara Volam 30776c5657d0SVasundhara Volam seq++; 30786c5657d0SVasundhara Volam off += len; 30796c5657d0SVasundhara Volam } 30806c5657d0SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 30816c5657d0SVasundhara Volam dma_free_coherent(&bp->pdev->dev, info->dma_len, dma_buf, dma_handle); 30826c5657d0SVasundhara Volam return rc; 30836c5657d0SVasundhara Volam } 30846c5657d0SVasundhara Volam 30856c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_list(struct bnxt *bp, 30866c5657d0SVasundhara Volam struct bnxt_coredump *coredump) 30876c5657d0SVasundhara Volam { 30886c5657d0SVasundhara Volam struct hwrm_dbg_coredump_list_input req = {0}; 30896c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 30906c5657d0SVasundhara Volam int rc; 30916c5657d0SVasundhara Volam 30926c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_LIST, -1, -1); 30936c5657d0SVasundhara Volam 30946c5657d0SVasundhara Volam info.dma_len = COREDUMP_LIST_BUF_LEN; 30956c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_list_input, seq_no); 30966c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_list_output, 30976c5657d0SVasundhara Volam data_len); 30986c5657d0SVasundhara Volam 30996c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 31006c5657d0SVasundhara Volam if (!rc) { 31016c5657d0SVasundhara Volam coredump->data = info.dest_buf; 31026c5657d0SVasundhara Volam coredump->data_size = info.dest_buf_size; 31036c5657d0SVasundhara Volam coredump->total_segs = info.segs; 31046c5657d0SVasundhara Volam } 31056c5657d0SVasundhara Volam return rc; 31066c5657d0SVasundhara Volam } 31076c5657d0SVasundhara Volam 31086c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_initiate(struct bnxt *bp, u16 component_id, 31096c5657d0SVasundhara Volam u16 segment_id) 31106c5657d0SVasundhara Volam { 31116c5657d0SVasundhara Volam struct hwrm_dbg_coredump_initiate_input req = {0}; 31126c5657d0SVasundhara Volam 31136c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_INITIATE, -1, -1); 31146c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 31156c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 31166c5657d0SVasundhara Volam 311757a8730bSVasundhara Volam return hwrm_send_message(bp, &req, sizeof(req), HWRM_COREDUMP_TIMEOUT); 31186c5657d0SVasundhara Volam } 31196c5657d0SVasundhara Volam 31206c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_retrieve(struct bnxt *bp, u16 component_id, 31216c5657d0SVasundhara Volam u16 segment_id, u32 *seg_len, 31226c5657d0SVasundhara Volam void *buf, u32 offset) 31236c5657d0SVasundhara Volam { 31246c5657d0SVasundhara Volam struct hwrm_dbg_coredump_retrieve_input req = {0}; 31256c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 31266c5657d0SVasundhara Volam int rc; 31276c5657d0SVasundhara Volam 31286c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_RETRIEVE, -1, -1); 31296c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 31306c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 31316c5657d0SVasundhara Volam 31326c5657d0SVasundhara Volam info.dma_len = COREDUMP_RETRIEVE_BUF_LEN; 31336c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_retrieve_input, 31346c5657d0SVasundhara Volam seq_no); 31356c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_retrieve_output, 31366c5657d0SVasundhara Volam data_len); 31376c5657d0SVasundhara Volam if (buf) 31386c5657d0SVasundhara Volam info.dest_buf = buf + offset; 31396c5657d0SVasundhara Volam 31406c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 31416c5657d0SVasundhara Volam if (!rc) 31426c5657d0SVasundhara Volam *seg_len = info.dest_buf_size; 31436c5657d0SVasundhara Volam 31446c5657d0SVasundhara Volam return rc; 31456c5657d0SVasundhara Volam } 31466c5657d0SVasundhara Volam 31476c5657d0SVasundhara Volam static void 31486c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(struct bnxt *bp, 31496c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr *seg_hdr, 31506c5657d0SVasundhara Volam struct coredump_segment_record *seg_rec, u32 seg_len, 31516c5657d0SVasundhara Volam int status, u32 duration, u32 instance) 31526c5657d0SVasundhara Volam { 31536c5657d0SVasundhara Volam memset(seg_hdr, 0, sizeof(*seg_hdr)); 31548605212aSVasundhara Volam memcpy(seg_hdr->signature, "sEgM", 4); 31556c5657d0SVasundhara Volam if (seg_rec) { 31566c5657d0SVasundhara Volam seg_hdr->component_id = (__force __le32)seg_rec->component_id; 31576c5657d0SVasundhara Volam seg_hdr->segment_id = (__force __le32)seg_rec->segment_id; 31586c5657d0SVasundhara Volam seg_hdr->low_version = seg_rec->version_low; 31596c5657d0SVasundhara Volam seg_hdr->high_version = seg_rec->version_hi; 31606c5657d0SVasundhara Volam } else { 31616c5657d0SVasundhara Volam /* For hwrm_ver_get response Component id = 2 31626c5657d0SVasundhara Volam * and Segment id = 0 31636c5657d0SVasundhara Volam */ 31646c5657d0SVasundhara Volam seg_hdr->component_id = cpu_to_le32(2); 31656c5657d0SVasundhara Volam seg_hdr->segment_id = 0; 31666c5657d0SVasundhara Volam } 31676c5657d0SVasundhara Volam seg_hdr->function_id = cpu_to_le16(bp->pdev->devfn); 31686c5657d0SVasundhara Volam seg_hdr->length = cpu_to_le32(seg_len); 31696c5657d0SVasundhara Volam seg_hdr->status = cpu_to_le32(status); 31706c5657d0SVasundhara Volam seg_hdr->duration = cpu_to_le32(duration); 31716c5657d0SVasundhara Volam seg_hdr->data_offset = cpu_to_le32(sizeof(*seg_hdr)); 31726c5657d0SVasundhara Volam seg_hdr->instance = cpu_to_le32(instance); 31736c5657d0SVasundhara Volam } 31746c5657d0SVasundhara Volam 31756c5657d0SVasundhara Volam static void 31766c5657d0SVasundhara Volam bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record, 31776c5657d0SVasundhara Volam time64_t start, s16 start_utc, u16 total_segs, 31786c5657d0SVasundhara Volam int status) 31796c5657d0SVasundhara Volam { 31806c5657d0SVasundhara Volam time64_t end = ktime_get_real_seconds(); 31816c5657d0SVasundhara Volam u32 os_ver_major = 0, os_ver_minor = 0; 31826c5657d0SVasundhara Volam struct tm tm; 31836c5657d0SVasundhara Volam 31846c5657d0SVasundhara Volam time64_to_tm(start, 0, &tm); 31856c5657d0SVasundhara Volam memset(record, 0, sizeof(*record)); 31868605212aSVasundhara Volam memcpy(record->signature, "cOrE", 4); 31876c5657d0SVasundhara Volam record->flags = 0; 31886c5657d0SVasundhara Volam record->low_version = 0; 31896c5657d0SVasundhara Volam record->high_version = 1; 31906c5657d0SVasundhara Volam record->asic_state = 0; 31913d46eee5SArnd Bergmann strlcpy(record->system_name, utsname()->nodename, 31923d46eee5SArnd Bergmann sizeof(record->system_name)); 31938dc5ae2dSVasundhara Volam record->year = cpu_to_le16(tm.tm_year + 1900); 31948dc5ae2dSVasundhara Volam record->month = cpu_to_le16(tm.tm_mon + 1); 31956c5657d0SVasundhara Volam record->day = cpu_to_le16(tm.tm_mday); 31966c5657d0SVasundhara Volam record->hour = cpu_to_le16(tm.tm_hour); 31976c5657d0SVasundhara Volam record->minute = cpu_to_le16(tm.tm_min); 31986c5657d0SVasundhara Volam record->second = cpu_to_le16(tm.tm_sec); 31996c5657d0SVasundhara Volam record->utc_bias = cpu_to_le16(start_utc); 32006c5657d0SVasundhara Volam strcpy(record->commandline, "ethtool -w"); 32016c5657d0SVasundhara Volam record->total_segments = cpu_to_le32(total_segs); 32026c5657d0SVasundhara Volam 32036c5657d0SVasundhara Volam sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor); 32046c5657d0SVasundhara Volam record->os_ver_major = cpu_to_le32(os_ver_major); 32056c5657d0SVasundhara Volam record->os_ver_minor = cpu_to_le32(os_ver_minor); 32066c5657d0SVasundhara Volam 32078605212aSVasundhara Volam strlcpy(record->os_name, utsname()->sysname, 32); 32086c5657d0SVasundhara Volam time64_to_tm(end, 0, &tm); 32096c5657d0SVasundhara Volam record->end_year = cpu_to_le16(tm.tm_year + 1900); 32106c5657d0SVasundhara Volam record->end_month = cpu_to_le16(tm.tm_mon + 1); 32116c5657d0SVasundhara Volam record->end_day = cpu_to_le16(tm.tm_mday); 32126c5657d0SVasundhara Volam record->end_hour = cpu_to_le16(tm.tm_hour); 32136c5657d0SVasundhara Volam record->end_minute = cpu_to_le16(tm.tm_min); 32146c5657d0SVasundhara Volam record->end_second = cpu_to_le16(tm.tm_sec); 32156c5657d0SVasundhara Volam record->end_utc_bias = cpu_to_le16(sys_tz.tz_minuteswest * 60); 32166c5657d0SVasundhara Volam record->asic_id1 = cpu_to_le32(bp->chip_num << 16 | 32176c5657d0SVasundhara Volam bp->ver_resp.chip_rev << 8 | 32186c5657d0SVasundhara Volam bp->ver_resp.chip_metal); 32196c5657d0SVasundhara Volam record->asic_id2 = 0; 32206c5657d0SVasundhara Volam record->coredump_status = cpu_to_le32(status); 32216c5657d0SVasundhara Volam record->ioctl_low_version = 0; 32226c5657d0SVasundhara Volam record->ioctl_high_version = 0; 32236c5657d0SVasundhara Volam } 32246c5657d0SVasundhara Volam 32256c5657d0SVasundhara Volam static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len) 32266c5657d0SVasundhara Volam { 32276c5657d0SVasundhara Volam u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output); 32286c5657d0SVasundhara Volam struct coredump_segment_record *seg_record = NULL; 32296c5657d0SVasundhara Volam u32 offset = 0, seg_hdr_len, seg_record_len; 32306c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr seg_hdr; 32316c5657d0SVasundhara Volam struct bnxt_coredump coredump = {NULL}; 32326c5657d0SVasundhara Volam time64_t start_time; 32336c5657d0SVasundhara Volam u16 start_utc; 32346c5657d0SVasundhara Volam int rc = 0, i; 32356c5657d0SVasundhara Volam 32366c5657d0SVasundhara Volam start_time = ktime_get_real_seconds(); 32376c5657d0SVasundhara Volam start_utc = sys_tz.tz_minuteswest * 60; 32386c5657d0SVasundhara Volam seg_hdr_len = sizeof(seg_hdr); 32396c5657d0SVasundhara Volam 32406c5657d0SVasundhara Volam /* First segment should be hwrm_ver_get response */ 32416c5657d0SVasundhara Volam *dump_len = seg_hdr_len + ver_get_resp_len; 32426c5657d0SVasundhara Volam if (buf) { 32436c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, NULL, ver_get_resp_len, 32446c5657d0SVasundhara Volam 0, 0, 0); 32456c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 32466c5657d0SVasundhara Volam offset += seg_hdr_len; 32476c5657d0SVasundhara Volam memcpy(buf + offset, &bp->ver_resp, ver_get_resp_len); 32486c5657d0SVasundhara Volam offset += ver_get_resp_len; 32496c5657d0SVasundhara Volam } 32506c5657d0SVasundhara Volam 32516c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_list(bp, &coredump); 32526c5657d0SVasundhara Volam if (rc) { 32536c5657d0SVasundhara Volam netdev_err(bp->dev, "Failed to get coredump segment list\n"); 32546c5657d0SVasundhara Volam goto err; 32556c5657d0SVasundhara Volam } 32566c5657d0SVasundhara Volam 32576c5657d0SVasundhara Volam *dump_len += seg_hdr_len * coredump.total_segs; 32586c5657d0SVasundhara Volam 32596c5657d0SVasundhara Volam seg_record = (struct coredump_segment_record *)coredump.data; 32606c5657d0SVasundhara Volam seg_record_len = sizeof(*seg_record); 32616c5657d0SVasundhara Volam 32626c5657d0SVasundhara Volam for (i = 0; i < coredump.total_segs; i++) { 32636c5657d0SVasundhara Volam u16 comp_id = le16_to_cpu(seg_record->component_id); 32646c5657d0SVasundhara Volam u16 seg_id = le16_to_cpu(seg_record->segment_id); 32656c5657d0SVasundhara Volam u32 duration = 0, seg_len = 0; 32666c5657d0SVasundhara Volam unsigned long start, end; 32676c5657d0SVasundhara Volam 32686c5657d0SVasundhara Volam start = jiffies; 32696c5657d0SVasundhara Volam 32706c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_initiate(bp, comp_id, seg_id); 32716c5657d0SVasundhara Volam if (rc) { 32726c5657d0SVasundhara Volam netdev_err(bp->dev, 32736c5657d0SVasundhara Volam "Failed to initiate coredump for seg = %d\n", 32746c5657d0SVasundhara Volam seg_record->segment_id); 32756c5657d0SVasundhara Volam goto next_seg; 32766c5657d0SVasundhara Volam } 32776c5657d0SVasundhara Volam 32786c5657d0SVasundhara Volam /* Write segment data into the buffer */ 32796c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_retrieve(bp, comp_id, seg_id, 32806c5657d0SVasundhara Volam &seg_len, buf, 32816c5657d0SVasundhara Volam offset + seg_hdr_len); 32826c5657d0SVasundhara Volam if (rc) 32836c5657d0SVasundhara Volam netdev_err(bp->dev, 32846c5657d0SVasundhara Volam "Failed to retrieve coredump for seg = %d\n", 32856c5657d0SVasundhara Volam seg_record->segment_id); 32866c5657d0SVasundhara Volam 32876c5657d0SVasundhara Volam next_seg: 32886c5657d0SVasundhara Volam end = jiffies; 32896c5657d0SVasundhara Volam duration = jiffies_to_msecs(end - start); 32906c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, seg_record, seg_len, 32916c5657d0SVasundhara Volam rc, duration, 0); 32926c5657d0SVasundhara Volam 32936c5657d0SVasundhara Volam if (buf) { 32946c5657d0SVasundhara Volam /* Write segment header into the buffer */ 32956c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 32966c5657d0SVasundhara Volam offset += seg_hdr_len + seg_len; 32976c5657d0SVasundhara Volam } 32986c5657d0SVasundhara Volam 32996c5657d0SVasundhara Volam *dump_len += seg_len; 33006c5657d0SVasundhara Volam seg_record = 33016c5657d0SVasundhara Volam (struct coredump_segment_record *)((u8 *)seg_record + 33026c5657d0SVasundhara Volam seg_record_len); 33036c5657d0SVasundhara Volam } 33046c5657d0SVasundhara Volam 33056c5657d0SVasundhara Volam err: 33061bbf3aedSArnd Bergmann if (buf) 33071bbf3aedSArnd Bergmann bnxt_fill_coredump_record(bp, buf + offset, start_time, 33086c5657d0SVasundhara Volam start_utc, coredump.total_segs + 1, 33096c5657d0SVasundhara Volam rc); 33106c5657d0SVasundhara Volam kfree(coredump.data); 33111bbf3aedSArnd Bergmann *dump_len += sizeof(struct bnxt_coredump_record); 33126c5657d0SVasundhara Volam 33136c5657d0SVasundhara Volam return rc; 33146c5657d0SVasundhara Volam } 33156c5657d0SVasundhara Volam 33160b0eacf3SVasundhara Volam static int bnxt_set_dump(struct net_device *dev, struct ethtool_dump *dump) 33170b0eacf3SVasundhara Volam { 33180b0eacf3SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 33190b0eacf3SVasundhara Volam 33200b0eacf3SVasundhara Volam if (dump->flag > BNXT_DUMP_CRASH) { 33210b0eacf3SVasundhara Volam netdev_info(dev, "Supports only Live(0) and Crash(1) dumps.\n"); 33220b0eacf3SVasundhara Volam return -EINVAL; 33230b0eacf3SVasundhara Volam } 33240b0eacf3SVasundhara Volam 33250b0eacf3SVasundhara Volam if (!IS_ENABLED(CONFIG_TEE_BNXT_FW) && dump->flag == BNXT_DUMP_CRASH) { 33260b0eacf3SVasundhara Volam netdev_info(dev, "Cannot collect crash dump as TEE_BNXT_FW config option is not enabled.\n"); 33270b0eacf3SVasundhara Volam return -EOPNOTSUPP; 33280b0eacf3SVasundhara Volam } 33290b0eacf3SVasundhara Volam 33300b0eacf3SVasundhara Volam bp->dump_flag = dump->flag; 33310b0eacf3SVasundhara Volam return 0; 33320b0eacf3SVasundhara Volam } 33330b0eacf3SVasundhara Volam 33346c5657d0SVasundhara Volam static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump) 33356c5657d0SVasundhara Volam { 33366c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 33376c5657d0SVasundhara Volam 33386c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 33396c5657d0SVasundhara Volam return -EOPNOTSUPP; 33406c5657d0SVasundhara Volam 33416c5657d0SVasundhara Volam dump->version = bp->ver_resp.hwrm_fw_maj_8b << 24 | 33426c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_min_8b << 16 | 33436c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_bld_8b << 8 | 33446c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_rsvd_8b; 33456c5657d0SVasundhara Volam 33460b0eacf3SVasundhara Volam dump->flag = bp->dump_flag; 33470b0eacf3SVasundhara Volam if (bp->dump_flag == BNXT_DUMP_CRASH) 33480b0eacf3SVasundhara Volam dump->len = BNXT_CRASH_DUMP_LEN; 33490b0eacf3SVasundhara Volam else 33500b0eacf3SVasundhara Volam bnxt_get_coredump(bp, NULL, &dump->len); 33510b0eacf3SVasundhara Volam return 0; 33526c5657d0SVasundhara Volam } 33536c5657d0SVasundhara Volam 33546c5657d0SVasundhara Volam static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump, 33556c5657d0SVasundhara Volam void *buf) 33566c5657d0SVasundhara Volam { 33576c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 33586c5657d0SVasundhara Volam 33596c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 33606c5657d0SVasundhara Volam return -EOPNOTSUPP; 33616c5657d0SVasundhara Volam 33626c5657d0SVasundhara Volam memset(buf, 0, dump->len); 33636c5657d0SVasundhara Volam 33640b0eacf3SVasundhara Volam dump->flag = bp->dump_flag; 33650b0eacf3SVasundhara Volam if (dump->flag == BNXT_DUMP_CRASH) { 33660b0eacf3SVasundhara Volam #ifdef CONFIG_TEE_BNXT_FW 33670b0eacf3SVasundhara Volam return tee_bnxt_copy_coredump(buf, 0, dump->len); 33680b0eacf3SVasundhara Volam #endif 33690b0eacf3SVasundhara Volam } else { 33706c5657d0SVasundhara Volam return bnxt_get_coredump(bp, buf, &dump->len); 33716c5657d0SVasundhara Volam } 33726c5657d0SVasundhara Volam 33730b0eacf3SVasundhara Volam return 0; 33740b0eacf3SVasundhara Volam } 33750b0eacf3SVasundhara Volam 3376eb513658SMichael Chan void bnxt_ethtool_init(struct bnxt *bp) 3377eb513658SMichael Chan { 3378eb513658SMichael Chan struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr; 3379eb513658SMichael Chan struct hwrm_selftest_qlist_input req = {0}; 3380eb513658SMichael Chan struct bnxt_test_info *test_info; 3381431aa1ebSMichael Chan struct net_device *dev = bp->dev; 3382eb513658SMichael Chan int i, rc; 3383eb513658SMichael Chan 3384691aa620SVasundhara Volam if (!(bp->fw_cap & BNXT_FW_CAP_PKG_VER)) 3385a60faa60SVasundhara Volam bnxt_get_pkgver(dev); 3386431aa1ebSMichael Chan 3387ba642ab7SMichael Chan bp->num_tests = 0; 3388eb513658SMichael Chan if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp)) 3389eb513658SMichael Chan return; 3390eb513658SMichael Chan 3391eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1); 3392eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 3393eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 3394eb513658SMichael Chan if (rc) 3395eb513658SMichael Chan goto ethtool_init_exit; 3396eb513658SMichael Chan 3397ba642ab7SMichael Chan test_info = bp->test_info; 3398ba642ab7SMichael Chan if (!test_info) 3399eb513658SMichael Chan test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL); 3400eb513658SMichael Chan if (!test_info) 3401eb513658SMichael Chan goto ethtool_init_exit; 3402eb513658SMichael Chan 3403eb513658SMichael Chan bp->test_info = test_info; 3404eb513658SMichael Chan bp->num_tests = resp->num_tests + BNXT_DRV_TESTS; 3405eb513658SMichael Chan if (bp->num_tests > BNXT_MAX_TEST) 3406eb513658SMichael Chan bp->num_tests = BNXT_MAX_TEST; 3407eb513658SMichael Chan 3408eb513658SMichael Chan test_info->offline_mask = resp->offline_tests; 3409eb513658SMichael Chan test_info->timeout = le16_to_cpu(resp->test_timeout); 3410eb513658SMichael Chan if (!test_info->timeout) 3411eb513658SMichael Chan test_info->timeout = HWRM_CMD_TIMEOUT; 3412eb513658SMichael Chan for (i = 0; i < bp->num_tests; i++) { 3413eb513658SMichael Chan char *str = test_info->string[i]; 3414eb513658SMichael Chan char *fw_str = resp->test0_name + i * 32; 3415eb513658SMichael Chan 3416f7dc1ea6SMichael Chan if (i == BNXT_MACLPBK_TEST_IDX) { 3417f7dc1ea6SMichael Chan strcpy(str, "Mac loopback test (offline)"); 341891725d89SMichael Chan } else if (i == BNXT_PHYLPBK_TEST_IDX) { 341991725d89SMichael Chan strcpy(str, "Phy loopback test (offline)"); 342055fd0cf3SMichael Chan } else if (i == BNXT_EXTLPBK_TEST_IDX) { 342155fd0cf3SMichael Chan strcpy(str, "Ext loopback test (offline)"); 342267fea463SMichael Chan } else if (i == BNXT_IRQ_TEST_IDX) { 342367fea463SMichael Chan strcpy(str, "Interrupt_test (offline)"); 3424f7dc1ea6SMichael Chan } else { 3425eb513658SMichael Chan strlcpy(str, fw_str, ETH_GSTRING_LEN); 3426eb513658SMichael Chan strncat(str, " test", ETH_GSTRING_LEN - strlen(str)); 3427eb513658SMichael Chan if (test_info->offline_mask & (1 << i)) 3428eb513658SMichael Chan strncat(str, " (offline)", 3429eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3430eb513658SMichael Chan else 3431eb513658SMichael Chan strncat(str, " (online)", 3432eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3433eb513658SMichael Chan } 3434f7dc1ea6SMichael Chan } 3435eb513658SMichael Chan 3436eb513658SMichael Chan ethtool_init_exit: 3437eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 3438eb513658SMichael Chan } 3439eb513658SMichael Chan 3440eb513658SMichael Chan void bnxt_ethtool_free(struct bnxt *bp) 3441eb513658SMichael Chan { 3442eb513658SMichael Chan kfree(bp->test_info); 3443eb513658SMichael Chan bp->test_info = NULL; 3444eb513658SMichael Chan } 3445eb513658SMichael Chan 3446c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 344700c04a92SMichael Chan .get_link_ksettings = bnxt_get_link_ksettings, 344800c04a92SMichael Chan .set_link_ksettings = bnxt_set_link_ksettings, 3449c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 3450c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 3451c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 34528e202366SMichael Chan .get_wol = bnxt_get_wol, 34535282db6cSMichael Chan .set_wol = bnxt_set_wol, 3454c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 3455c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 3456c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 3457c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 3458c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 3459c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 3460c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 3461c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 3462c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 3463c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 3464c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 3465c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 3466a011952aSMichael Chan .set_rxnfc = bnxt_set_rxnfc, 3467c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 3468c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 3469c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 3470c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 3471c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 3472c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 3473c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 3474c0c050c5SMichael Chan .get_link = bnxt_get_link, 347572b34f04SMichael Chan .get_eee = bnxt_get_eee, 347672b34f04SMichael Chan .set_eee = bnxt_set_eee, 347742ee18feSAjit Khaparde .get_module_info = bnxt_get_module_info, 347842ee18feSAjit Khaparde .get_module_eeprom = bnxt_get_module_eeprom, 34795ad2cbeeSMichael Chan .nway_reset = bnxt_nway_reset, 34805ad2cbeeSMichael Chan .set_phys_id = bnxt_set_phys_id, 3481eb513658SMichael Chan .self_test = bnxt_self_test, 348249f7972fSVasundhara Volam .reset = bnxt_reset, 34830b0eacf3SVasundhara Volam .set_dump = bnxt_set_dump, 34846c5657d0SVasundhara Volam .get_dump_flag = bnxt_get_dump_flag, 34856c5657d0SVasundhara Volam .get_dump_data = bnxt_get_dump_data, 3486c0c050c5SMichael Chan }; 3487