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 1403316d509SMichael Chan static const char * const bnxt_ring_rx_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", 1493316d509SMichael Chan }; 1503316d509SMichael Chan 1513316d509SMichael Chan static const char * const bnxt_ring_tx_stats_str[] = { 152ee79566eSMichael Chan "tx_ucast_packets", 153ee79566eSMichael Chan "tx_mcast_packets", 154ee79566eSMichael Chan "tx_bcast_packets", 155ee79566eSMichael Chan "tx_discards", 156ee79566eSMichael Chan "tx_drops", 157ee79566eSMichael Chan "tx_ucast_bytes", 158ee79566eSMichael Chan "tx_mcast_bytes", 159ee79566eSMichael Chan "tx_bcast_bytes", 160ee79566eSMichael Chan }; 161ee79566eSMichael Chan 162ee79566eSMichael Chan static const char * const bnxt_ring_tpa_stats_str[] = { 163ee79566eSMichael Chan "tpa_packets", 164ee79566eSMichael Chan "tpa_bytes", 165ee79566eSMichael Chan "tpa_events", 166ee79566eSMichael Chan "tpa_aborts", 167ee79566eSMichael Chan }; 168ee79566eSMichael Chan 16978e7b866SMichael Chan static const char * const bnxt_ring_tpa2_stats_str[] = { 17078e7b866SMichael Chan "rx_tpa_eligible_pkt", 17178e7b866SMichael Chan "rx_tpa_eligible_bytes", 17278e7b866SMichael Chan "rx_tpa_pkt", 17378e7b866SMichael Chan "rx_tpa_bytes", 17478e7b866SMichael Chan "rx_tpa_errors", 17578e7b866SMichael Chan }; 17678e7b866SMichael Chan 1779d8b5f05SMichael Chan static const char * const bnxt_rx_sw_stats_str[] = { 178ee79566eSMichael Chan "rx_l4_csum_errors", 17919b3751fSMichael Chan "rx_buf_errors", 1809d8b5f05SMichael Chan }; 1819d8b5f05SMichael Chan 1829d8b5f05SMichael Chan static const char * const bnxt_cmn_sw_stats_str[] = { 183ee79566eSMichael Chan "missed_irqs", 184ee79566eSMichael Chan }; 185c0c050c5SMichael Chan 1868ddc9aaaSMichael Chan #define BNXT_RX_STATS_ENTRY(counter) \ 1878ddc9aaaSMichael Chan { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) } 1888ddc9aaaSMichael Chan 1898ddc9aaaSMichael Chan #define BNXT_TX_STATS_ENTRY(counter) \ 1908ddc9aaaSMichael Chan { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) } 1918ddc9aaaSMichael Chan 19200db3cbaSVasundhara Volam #define BNXT_RX_STATS_EXT_ENTRY(counter) \ 19300db3cbaSVasundhara Volam { BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) } 19400db3cbaSVasundhara Volam 19536e53349SMichael Chan #define BNXT_TX_STATS_EXT_ENTRY(counter) \ 19636e53349SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter), __stringify(counter) } 19736e53349SMichael Chan 19836e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRY(n) \ 19936e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_duration_us), \ 20036e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_transitions) 20136e53349SMichael Chan 20236e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRY(n) \ 20336e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_duration_us), \ 20436e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_transitions) 20536e53349SMichael Chan 20636e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRIES \ 20736e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(0), \ 20836e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(1), \ 20936e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(2), \ 21036e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(3), \ 21136e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(4), \ 21236e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(5), \ 21336e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(6), \ 21436e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(7) 21536e53349SMichael Chan 21636e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRIES \ 21736e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(0), \ 21836e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(1), \ 21936e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(2), \ 22036e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(3), \ 22136e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(4), \ 22236e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(5), \ 22336e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(6), \ 22436e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(7) 22536e53349SMichael Chan 22636e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRY(n) \ 22736e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bytes_cos##n), \ 22836e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_packets_cos##n) 22936e53349SMichael Chan 23036e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRY(n) \ 23136e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_bytes_cos##n), \ 23236e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_packets_cos##n) 23336e53349SMichael Chan 23436e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRIES \ 23536e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(0), \ 23636e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(1), \ 23736e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(2), \ 23836e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(3), \ 23936e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(4), \ 24036e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(5), \ 24136e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(6), \ 24236e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(7) \ 24336e53349SMichael Chan 24436e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRIES \ 24536e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(0), \ 24636e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(1), \ 24736e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(2), \ 24836e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(3), \ 24936e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(4), \ 25036e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(5), \ 25136e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(6), \ 25236e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(7) \ 25336e53349SMichael Chan 2542792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(n) \ 2552792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_bytes_cos##n), \ 2562792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_packets_cos##n) 2572792b5b9SMichael Chan 2582792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES \ 2592792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(0), \ 2602792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(1), \ 2612792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(2), \ 2622792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(3), \ 2632792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(4), \ 2642792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(5), \ 2652792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(6), \ 2662792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(7) 2672792b5b9SMichael Chan 268e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRY(counter, n) \ 269e37fed79SMichael Chan { BNXT_RX_STATS_EXT_OFFSET(counter##_cos0), \ 270e37fed79SMichael Chan __stringify(counter##_pri##n) } 271e37fed79SMichael Chan 272e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRY(counter, n) \ 273e37fed79SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter##_cos0), \ 274e37fed79SMichael Chan __stringify(counter##_pri##n) } 275e37fed79SMichael Chan 276e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRIES(counter) \ 277e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 0), \ 278e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 1), \ 279e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 2), \ 280e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 3), \ 281e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 4), \ 282e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 5), \ 283e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 6), \ 284e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 7) 285e37fed79SMichael Chan 286e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRIES(counter) \ 287e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 0), \ 288e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 1), \ 289e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 2), \ 290e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 3), \ 291e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 4), \ 292e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 5), \ 293e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 6), \ 294e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 7) 295e37fed79SMichael Chan 29655e4398dSVasundhara Volam #define BNXT_PCIE_STATS_ENTRY(counter) \ 29755e4398dSVasundhara Volam { BNXT_PCIE_STATS_OFFSET(counter), __stringify(counter) } 29855e4398dSVasundhara Volam 29920c1d28eSVasundhara Volam enum { 30020c1d28eSVasundhara Volam RX_TOTAL_DISCARDS, 30120c1d28eSVasundhara Volam TX_TOTAL_DISCARDS, 30220c1d28eSVasundhara Volam }; 30320c1d28eSVasundhara Volam 30420c1d28eSVasundhara Volam static struct { 30520c1d28eSVasundhara Volam u64 counter; 30620c1d28eSVasundhara Volam char string[ETH_GSTRING_LEN]; 30720c1d28eSVasundhara Volam } bnxt_sw_func_stats[] = { 30820c1d28eSVasundhara Volam {0, "rx_total_discard_pkts"}, 30920c1d28eSVasundhara Volam {0, "tx_total_discard_pkts"}, 31020c1d28eSVasundhara Volam }; 31120c1d28eSVasundhara Volam 3123316d509SMichael Chan #define NUM_RING_RX_SW_STATS ARRAY_SIZE(bnxt_rx_sw_stats_str) 3133316d509SMichael Chan #define NUM_RING_CMN_SW_STATS ARRAY_SIZE(bnxt_cmn_sw_stats_str) 3143316d509SMichael Chan #define NUM_RING_RX_HW_STATS ARRAY_SIZE(bnxt_ring_rx_stats_str) 3153316d509SMichael Chan #define NUM_RING_TX_HW_STATS ARRAY_SIZE(bnxt_ring_tx_stats_str) 3163316d509SMichael Chan 3178ddc9aaaSMichael Chan static const struct { 3188ddc9aaaSMichael Chan long offset; 3198ddc9aaaSMichael Chan char string[ETH_GSTRING_LEN]; 3208ddc9aaaSMichael Chan } bnxt_port_stats_arr[] = { 3218ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_64b_frames), 3228ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_65b_127b_frames), 3238ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_128b_255b_frames), 3248ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_256b_511b_frames), 3258ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames), 3266fc92c33SMichael Chan BNXT_RX_STATS_ENTRY(rx_1024b_1518b_frames), 3278ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_vlan_frames), 3288ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames), 3298ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames), 3308ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames), 3318ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames), 3328ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_total_frames), 3338ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ucast_frames), 3348ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mcast_frames), 3358ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bcast_frames), 3368ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_fcs_err_frames), 3378ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ctrl_frames), 3388ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pause_frames), 3398ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_frames), 3408ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_align_err_frames), 3418ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ovrsz_frames), 3428ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_jbr_frames), 3438ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mtu_err_frames), 3448ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_tagged_frames), 3458ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_double_tagged_frames), 3468ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_frames), 347c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0), 348c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1), 349c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2), 350c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3), 351c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4), 352c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5), 353c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6), 354c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7), 3558ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_undrsz_frames), 3568ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_events), 3578ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration), 3588ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bytes), 3598ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_bytes), 3608ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_frames), 361699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_discard), 362699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_err), 3638ddc9aaaSMichael Chan 3648ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_64b_frames), 3658ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_65b_127b_frames), 3668ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_128b_255b_frames), 3678ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_256b_511b_frames), 3688ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames), 3696fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1024b_1518b_frames), 3708ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_vlan_frames), 3716fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1519b_2047b_frames), 3728ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames), 3738ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames), 3748ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames), 3758ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_frames), 3768ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_frames), 3778ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_ucast_frames), 3788ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_mcast_frames), 3798ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bcast_frames), 3808ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pause_frames), 3818ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_frames), 3828ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_jabber_frames), 3838ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fcs_err_frames), 3848ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_err), 3858ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fifo_underruns), 386c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0), 387c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1), 388c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2), 389c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3), 390c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4), 391c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5), 392c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6), 393c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7), 3948ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_events), 3958ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration), 3968ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_collisions), 3978ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bytes), 398699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_xthol_frames), 399699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_discard), 400699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_error), 4018ddc9aaaSMichael Chan }; 4028ddc9aaaSMichael Chan 40300db3cbaSVasundhara Volam static const struct { 40400db3cbaSVasundhara Volam long offset; 40500db3cbaSVasundhara Volam char string[ETH_GSTRING_LEN]; 40600db3cbaSVasundhara Volam } bnxt_port_stats_ext_arr[] = { 40700db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(link_down_events), 40800db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events), 40900db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_pause_events), 41000db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events), 41100db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events), 41236e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRIES, 41336e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRIES, 4144a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bits), 4154a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_buffer_passed_threshold), 4164a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_pcs_symbol_err), 4174a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_corrected_bits), 4182792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES, 41936e53349SMichael Chan }; 42036e53349SMichael Chan 42136e53349SMichael Chan static const struct { 42236e53349SMichael Chan long offset; 42336e53349SMichael Chan char string[ETH_GSTRING_LEN]; 42436e53349SMichael Chan } bnxt_tx_port_stats_ext_arr[] = { 42536e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRIES, 42636e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRIES, 42700db3cbaSVasundhara Volam }; 42800db3cbaSVasundhara Volam 429e37fed79SMichael Chan static const struct { 430e37fed79SMichael Chan long base_off; 431e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 432e37fed79SMichael Chan } bnxt_rx_bytes_pri_arr[] = { 433e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_bytes), 434e37fed79SMichael Chan }; 435e37fed79SMichael Chan 436e37fed79SMichael Chan static const struct { 437e37fed79SMichael Chan long base_off; 438e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 439e37fed79SMichael Chan } bnxt_rx_pkts_pri_arr[] = { 440e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_packets), 441e37fed79SMichael Chan }; 442e37fed79SMichael Chan 443e37fed79SMichael Chan static const struct { 444e37fed79SMichael Chan long base_off; 445e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 446e37fed79SMichael Chan } bnxt_tx_bytes_pri_arr[] = { 447e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_bytes), 448e37fed79SMichael Chan }; 449e37fed79SMichael Chan 450e37fed79SMichael Chan static const struct { 451e37fed79SMichael Chan long base_off; 452e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 453e37fed79SMichael Chan } bnxt_tx_pkts_pri_arr[] = { 454e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_packets), 455e37fed79SMichael Chan }; 456e37fed79SMichael Chan 45755e4398dSVasundhara Volam static const struct { 45855e4398dSVasundhara Volam long offset; 45955e4398dSVasundhara Volam char string[ETH_GSTRING_LEN]; 46055e4398dSVasundhara Volam } bnxt_pcie_stats_arr[] = { 46155e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_pl_signal_integrity), 46255e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_dl_signal_integrity), 46355e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tl_signal_integrity), 46455e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_link_integrity), 46555e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tx_traffic_rate), 46655e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_rx_traffic_rate), 46755e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tx_dllp_statistics), 46855e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_rx_dllp_statistics), 46955e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_equalization_time), 47055e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[0]), 47155e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[2]), 47255e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_recovery_histogram), 47355e4398dSVasundhara Volam }; 47455e4398dSVasundhara Volam 47520c1d28eSVasundhara Volam #define BNXT_NUM_SW_FUNC_STATS ARRAY_SIZE(bnxt_sw_func_stats) 4768ddc9aaaSMichael Chan #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr) 477e37fed79SMichael Chan #define BNXT_NUM_STATS_PRI \ 478e37fed79SMichael Chan (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \ 479e37fed79SMichael Chan ARRAY_SIZE(bnxt_rx_pkts_pri_arr) + \ 480e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_bytes_pri_arr) + \ 481e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_pkts_pri_arr)) 48255e4398dSVasundhara Volam #define BNXT_NUM_PCIE_STATS ARRAY_SIZE(bnxt_pcie_stats_arr) 4838ddc9aaaSMichael Chan 48478e7b866SMichael Chan static int bnxt_get_num_tpa_ring_stats(struct bnxt *bp) 48578e7b866SMichael Chan { 48678e7b866SMichael Chan if (BNXT_SUPPORTS_TPA(bp)) { 48778e7b866SMichael Chan if (bp->max_tpa_v2) 48878e7b866SMichael Chan return ARRAY_SIZE(bnxt_ring_tpa2_stats_str); 48978e7b866SMichael Chan return ARRAY_SIZE(bnxt_ring_tpa_stats_str); 49078e7b866SMichael Chan } 49178e7b866SMichael Chan return 0; 49278e7b866SMichael Chan } 49378e7b866SMichael Chan 494ee79566eSMichael Chan static int bnxt_get_num_ring_stats(struct bnxt *bp) 495ee79566eSMichael Chan { 4963316d509SMichael Chan int rx, tx, cmn; 497125592fbSRajesh Ravi bool sh = false; 498125592fbSRajesh Ravi 499125592fbSRajesh Ravi if (bp->flags & BNXT_FLAG_SHARED_RINGS) 500125592fbSRajesh Ravi sh = true; 501ee79566eSMichael Chan 5023316d509SMichael Chan rx = NUM_RING_RX_HW_STATS + NUM_RING_RX_SW_STATS + 50378e7b866SMichael Chan bnxt_get_num_tpa_ring_stats(bp); 5043316d509SMichael Chan tx = NUM_RING_TX_HW_STATS; 5053316d509SMichael Chan cmn = NUM_RING_CMN_SW_STATS; 506125592fbSRajesh Ravi if (sh) 5073316d509SMichael Chan return (rx + tx + cmn) * bp->cp_nr_rings; 508125592fbSRajesh Ravi else 509125592fbSRajesh Ravi return rx * bp->rx_nr_rings + tx * bp->tx_nr_rings + 510125592fbSRajesh Ravi cmn * bp->cp_nr_rings; 511ee79566eSMichael Chan } 512ee79566eSMichael Chan 5135c8227d0SMichael Chan static int bnxt_get_num_stats(struct bnxt *bp) 514c0c050c5SMichael Chan { 515ee79566eSMichael Chan int num_stats = bnxt_get_num_ring_stats(bp); 5168ddc9aaaSMichael Chan 51720c1d28eSVasundhara Volam num_stats += BNXT_NUM_SW_FUNC_STATS; 51820c1d28eSVasundhara Volam 5198ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) 5208ddc9aaaSMichael Chan num_stats += BNXT_NUM_PORT_STATS; 5218ddc9aaaSMichael Chan 522e37fed79SMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 52336e53349SMichael Chan num_stats += bp->fw_rx_stats_ext_size + 52436e53349SMichael Chan bp->fw_tx_stats_ext_size; 525e37fed79SMichael Chan if (bp->pri2cos_valid) 526e37fed79SMichael Chan num_stats += BNXT_NUM_STATS_PRI; 527e37fed79SMichael Chan } 52800db3cbaSVasundhara Volam 52955e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) 53055e4398dSVasundhara Volam num_stats += BNXT_NUM_PCIE_STATS; 53155e4398dSVasundhara Volam 5328ddc9aaaSMichael Chan return num_stats; 5338ddc9aaaSMichael Chan } 5345c8227d0SMichael Chan 5355c8227d0SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 5365c8227d0SMichael Chan { 5375c8227d0SMichael Chan struct bnxt *bp = netdev_priv(dev); 5385c8227d0SMichael Chan 5395c8227d0SMichael Chan switch (sset) { 5405c8227d0SMichael Chan case ETH_SS_STATS: 5415c8227d0SMichael Chan return bnxt_get_num_stats(bp); 542eb513658SMichael Chan case ETH_SS_TEST: 543eb513658SMichael Chan if (!bp->num_tests) 544eb513658SMichael Chan return -EOPNOTSUPP; 545eb513658SMichael Chan return bp->num_tests; 546c0c050c5SMichael Chan default: 547c0c050c5SMichael Chan return -EOPNOTSUPP; 548c0c050c5SMichael Chan } 549c0c050c5SMichael Chan } 550c0c050c5SMichael Chan 551125592fbSRajesh Ravi static bool is_rx_ring(struct bnxt *bp, int ring_num) 552125592fbSRajesh Ravi { 553125592fbSRajesh Ravi return ring_num < bp->rx_nr_rings; 554125592fbSRajesh Ravi } 555125592fbSRajesh Ravi 556125592fbSRajesh Ravi static bool is_tx_ring(struct bnxt *bp, int ring_num) 557125592fbSRajesh Ravi { 558125592fbSRajesh Ravi int tx_base = 0; 559125592fbSRajesh Ravi 560125592fbSRajesh Ravi if (!(bp->flags & BNXT_FLAG_SHARED_RINGS)) 561125592fbSRajesh Ravi tx_base = bp->rx_nr_rings; 562125592fbSRajesh Ravi 563125592fbSRajesh Ravi if (ring_num >= tx_base && ring_num < (tx_base + bp->tx_nr_rings)) 564125592fbSRajesh Ravi return true; 565125592fbSRajesh Ravi return false; 566125592fbSRajesh Ravi } 567125592fbSRajesh Ravi 568c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 569c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 570c0c050c5SMichael Chan { 571c0c050c5SMichael Chan u32 i, j = 0; 572c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 573125592fbSRajesh Ravi u32 tpa_stats; 574c0c050c5SMichael Chan 575fd3ab1c7SMichael Chan if (!bp->bnapi) { 576ee79566eSMichael Chan j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS; 577fd3ab1c7SMichael Chan goto skip_ring_stats; 578fd3ab1c7SMichael Chan } 579c0c050c5SMichael Chan 58020c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) 58120c1d28eSVasundhara Volam bnxt_sw_func_stats[i].counter = 0; 58220c1d28eSVasundhara Volam 583125592fbSRajesh Ravi tpa_stats = bnxt_get_num_tpa_ring_stats(bp); 584c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 585c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 586c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 587c0c050c5SMichael Chan __le64 *hw_stats = (__le64 *)cpr->hw_stats; 5889d8b5f05SMichael Chan u64 *sw; 589c0c050c5SMichael Chan int k; 590c0c050c5SMichael Chan 591125592fbSRajesh Ravi if (is_rx_ring(bp, i)) { 592125592fbSRajesh Ravi for (k = 0; k < NUM_RING_RX_HW_STATS; j++, k++) 593125592fbSRajesh Ravi buf[j] = le64_to_cpu(hw_stats[k]); 594125592fbSRajesh Ravi } 595125592fbSRajesh Ravi if (is_tx_ring(bp, i)) { 596125592fbSRajesh Ravi k = NUM_RING_RX_HW_STATS; 597125592fbSRajesh Ravi for (; k < NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS; 598125592fbSRajesh Ravi j++, k++) 599125592fbSRajesh Ravi buf[j] = le64_to_cpu(hw_stats[k]); 600125592fbSRajesh Ravi } 601125592fbSRajesh Ravi if (!tpa_stats || !is_rx_ring(bp, i)) 602125592fbSRajesh Ravi goto skip_tpa_ring_stats; 603125592fbSRajesh Ravi 604125592fbSRajesh Ravi k = NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS; 605125592fbSRajesh Ravi for (; k < NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS + 606125592fbSRajesh Ravi tpa_stats; j++, k++) 607c0c050c5SMichael Chan buf[j] = le64_to_cpu(hw_stats[k]); 6089d8b5f05SMichael Chan 609125592fbSRajesh Ravi skip_tpa_ring_stats: 6109d8b5f05SMichael Chan sw = (u64 *)&cpr->sw_stats.rx; 611125592fbSRajesh Ravi if (is_rx_ring(bp, i)) { 6123316d509SMichael Chan for (k = 0; k < NUM_RING_RX_SW_STATS; j++, k++) 6139d8b5f05SMichael Chan buf[j] = sw[k]; 614125592fbSRajesh Ravi } 6159d8b5f05SMichael Chan 6169d8b5f05SMichael Chan sw = (u64 *)&cpr->sw_stats.cmn; 6173316d509SMichael Chan for (k = 0; k < NUM_RING_CMN_SW_STATS; j++, k++) 6189d8b5f05SMichael Chan buf[j] = sw[k]; 61920c1d28eSVasundhara Volam 62020c1d28eSVasundhara Volam bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter += 62120c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->rx_discard_pkts); 62220c1d28eSVasundhara Volam bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter += 62320c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->tx_discard_pkts); 624c0c050c5SMichael Chan } 62520c1d28eSVasundhara Volam 62620c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++) 62720c1d28eSVasundhara Volam buf[j] = bnxt_sw_func_stats[i].counter; 62820c1d28eSVasundhara Volam 629fd3ab1c7SMichael Chan skip_ring_stats: 6308ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 6318ddc9aaaSMichael Chan __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats; 6328ddc9aaaSMichael Chan 6338ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) { 6348ddc9aaaSMichael Chan buf[j] = le64_to_cpu(*(port_stats + 6358ddc9aaaSMichael Chan bnxt_port_stats_arr[i].offset)); 6368ddc9aaaSMichael Chan } 6378ddc9aaaSMichael Chan } 63800db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 63936e53349SMichael Chan __le64 *rx_port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext; 64036e53349SMichael Chan __le64 *tx_port_stats_ext = (__le64 *)bp->hw_tx_port_stats_ext; 64100db3cbaSVasundhara Volam 64236e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) { 64336e53349SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + 64400db3cbaSVasundhara Volam bnxt_port_stats_ext_arr[i].offset)); 64500db3cbaSVasundhara Volam } 64636e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++, j++) { 64736e53349SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + 64836e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].offset)); 64936e53349SMichael Chan } 650e37fed79SMichael Chan if (bp->pri2cos_valid) { 651e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 652e37fed79SMichael Chan long n = bnxt_rx_bytes_pri_arr[i].base_off + 653a24ec322SMichael Chan bp->pri2cos_idx[i]; 654e37fed79SMichael Chan 655e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 656e37fed79SMichael Chan } 657e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 658e37fed79SMichael Chan long n = bnxt_rx_pkts_pri_arr[i].base_off + 659a24ec322SMichael Chan bp->pri2cos_idx[i]; 660e37fed79SMichael Chan 661e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 662e37fed79SMichael Chan } 663e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 664e37fed79SMichael Chan long n = bnxt_tx_bytes_pri_arr[i].base_off + 665a24ec322SMichael Chan bp->pri2cos_idx[i]; 666e37fed79SMichael Chan 667e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 668e37fed79SMichael Chan } 669e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 670e37fed79SMichael Chan long n = bnxt_tx_pkts_pri_arr[i].base_off + 671a24ec322SMichael Chan bp->pri2cos_idx[i]; 672e37fed79SMichael Chan 673e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 674e37fed79SMichael Chan } 675e37fed79SMichael Chan } 67600db3cbaSVasundhara Volam } 67755e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) { 67855e4398dSVasundhara Volam __le64 *pcie_stats = (__le64 *)bp->hw_pcie_stats; 67955e4398dSVasundhara Volam 68055e4398dSVasundhara Volam for (i = 0; i < BNXT_NUM_PCIE_STATS; i++, j++) { 68155e4398dSVasundhara Volam buf[j] = le64_to_cpu(*(pcie_stats + 68255e4398dSVasundhara Volam bnxt_pcie_stats_arr[i].offset)); 68355e4398dSVasundhara Volam } 68455e4398dSVasundhara Volam } 685c0c050c5SMichael Chan } 686c0c050c5SMichael Chan 687c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 688c0c050c5SMichael Chan { 689c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 69078e7b866SMichael Chan static const char * const *str; 691ee79566eSMichael Chan u32 i, j, num_str; 692c0c050c5SMichael Chan 693c0c050c5SMichael Chan switch (stringset) { 694c0c050c5SMichael Chan case ETH_SS_STATS: 695c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 696125592fbSRajesh Ravi if (is_rx_ring(bp, i)) { 6973316d509SMichael Chan num_str = NUM_RING_RX_HW_STATS; 698ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 699ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 7003316d509SMichael Chan bnxt_ring_rx_stats_str[j]); 701c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 702ee79566eSMichael Chan } 703125592fbSRajesh Ravi } 704125592fbSRajesh Ravi if (is_tx_ring(bp, i)) { 7053316d509SMichael Chan num_str = NUM_RING_TX_HW_STATS; 7063316d509SMichael Chan for (j = 0; j < num_str; j++) { 7073316d509SMichael Chan sprintf(buf, "[%d]: %s", i, 7083316d509SMichael Chan bnxt_ring_tx_stats_str[j]); 7093316d509SMichael Chan buf += ETH_GSTRING_LEN; 7103316d509SMichael Chan } 711125592fbSRajesh Ravi } 7123316d509SMichael Chan num_str = bnxt_get_num_tpa_ring_stats(bp); 713125592fbSRajesh Ravi if (!num_str || !is_rx_ring(bp, i)) 714ee79566eSMichael Chan goto skip_tpa_stats; 715ee79566eSMichael Chan 7163316d509SMichael Chan if (bp->max_tpa_v2) 71778e7b866SMichael Chan str = bnxt_ring_tpa2_stats_str; 7183316d509SMichael Chan else 71978e7b866SMichael Chan str = bnxt_ring_tpa_stats_str; 7203316d509SMichael Chan 721ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 72278e7b866SMichael Chan sprintf(buf, "[%d]: %s", i, str[j]); 723c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 724ee79566eSMichael Chan } 725ee79566eSMichael Chan skip_tpa_stats: 726125592fbSRajesh Ravi if (is_rx_ring(bp, i)) { 7273316d509SMichael Chan num_str = NUM_RING_RX_SW_STATS; 728ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 729ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 7309d8b5f05SMichael Chan bnxt_rx_sw_stats_str[j]); 7319d8b5f05SMichael Chan buf += ETH_GSTRING_LEN; 7329d8b5f05SMichael Chan } 733125592fbSRajesh Ravi } 7343316d509SMichael Chan num_str = NUM_RING_CMN_SW_STATS; 7359d8b5f05SMichael Chan for (j = 0; j < num_str; j++) { 7369d8b5f05SMichael Chan sprintf(buf, "[%d]: %s", i, 7379d8b5f05SMichael Chan bnxt_cmn_sw_stats_str[j]); 738c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 739ee79566eSMichael Chan } 740c0c050c5SMichael Chan } 74120c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) { 74220c1d28eSVasundhara Volam strcpy(buf, bnxt_sw_func_stats[i].string); 74320c1d28eSVasundhara Volam buf += ETH_GSTRING_LEN; 74420c1d28eSVasundhara Volam } 74520c1d28eSVasundhara Volam 7468ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 7478ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++) { 7488ddc9aaaSMichael Chan strcpy(buf, bnxt_port_stats_arr[i].string); 7498ddc9aaaSMichael Chan buf += ETH_GSTRING_LEN; 7508ddc9aaaSMichael Chan } 7518ddc9aaaSMichael Chan } 75200db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 75336e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++) { 75400db3cbaSVasundhara Volam strcpy(buf, bnxt_port_stats_ext_arr[i].string); 75500db3cbaSVasundhara Volam buf += ETH_GSTRING_LEN; 75600db3cbaSVasundhara Volam } 75736e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++) { 75836e53349SMichael Chan strcpy(buf, 75936e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].string); 76036e53349SMichael Chan buf += ETH_GSTRING_LEN; 76136e53349SMichael Chan } 762e37fed79SMichael Chan if (bp->pri2cos_valid) { 763e37fed79SMichael Chan for (i = 0; i < 8; i++) { 764e37fed79SMichael Chan strcpy(buf, 765e37fed79SMichael Chan bnxt_rx_bytes_pri_arr[i].string); 766e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 767e37fed79SMichael Chan } 768e37fed79SMichael Chan for (i = 0; i < 8; i++) { 769e37fed79SMichael Chan strcpy(buf, 770e37fed79SMichael Chan bnxt_rx_pkts_pri_arr[i].string); 771e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 772e37fed79SMichael Chan } 773e37fed79SMichael Chan for (i = 0; i < 8; i++) { 774e37fed79SMichael Chan strcpy(buf, 775e37fed79SMichael Chan bnxt_tx_bytes_pri_arr[i].string); 776e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 777e37fed79SMichael Chan } 778e37fed79SMichael Chan for (i = 0; i < 8; i++) { 779e37fed79SMichael Chan strcpy(buf, 780e37fed79SMichael Chan bnxt_tx_pkts_pri_arr[i].string); 781e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 782e37fed79SMichael Chan } 783e37fed79SMichael Chan } 78400db3cbaSVasundhara Volam } 78555e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) { 78655e4398dSVasundhara Volam for (i = 0; i < BNXT_NUM_PCIE_STATS; i++) { 78755e4398dSVasundhara Volam strcpy(buf, bnxt_pcie_stats_arr[i].string); 78855e4398dSVasundhara Volam buf += ETH_GSTRING_LEN; 78955e4398dSVasundhara Volam } 79055e4398dSVasundhara Volam } 791c0c050c5SMichael Chan break; 792eb513658SMichael Chan case ETH_SS_TEST: 793eb513658SMichael Chan if (bp->num_tests) 794eb513658SMichael Chan memcpy(buf, bp->test_info->string, 795eb513658SMichael Chan bp->num_tests * ETH_GSTRING_LEN); 796eb513658SMichael Chan break; 797c0c050c5SMichael Chan default: 798c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 799c0c050c5SMichael Chan stringset); 800c0c050c5SMichael Chan break; 801c0c050c5SMichael Chan } 802c0c050c5SMichael Chan } 803c0c050c5SMichael Chan 804c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 805c0c050c5SMichael Chan struct ethtool_ringparam *ering) 806c0c050c5SMichael Chan { 807c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 808c0c050c5SMichael Chan 809c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 810c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 811c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 812c0c050c5SMichael Chan 813c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 814c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 815c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 816c0c050c5SMichael Chan } 817c0c050c5SMichael Chan 818c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 819c0c050c5SMichael Chan struct ethtool_ringparam *ering) 820c0c050c5SMichael Chan { 821c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 822c0c050c5SMichael Chan 823c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 824c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 825c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 826c0c050c5SMichael Chan return -EINVAL; 827c0c050c5SMichael Chan 828c0c050c5SMichael Chan if (netif_running(dev)) 829c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 830c0c050c5SMichael Chan 831c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 832c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 833c0c050c5SMichael Chan bnxt_set_ring_params(bp); 834c0c050c5SMichael Chan 835c0c050c5SMichael Chan if (netif_running(dev)) 836c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 837c0c050c5SMichael Chan 838c0c050c5SMichael Chan return 0; 839c0c050c5SMichael Chan } 840c0c050c5SMichael Chan 841c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 842c0c050c5SMichael Chan struct ethtool_channels *channel) 843c0c050c5SMichael Chan { 844c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 845db4723b3SMichael Chan struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 846c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 847db4723b3SMichael Chan int max_tx_sch_inputs; 848db4723b3SMichael Chan 849db4723b3SMichael Chan /* Get the most up-to-date max_tx_sch_inputs. */ 850f1ca94deSMichael Chan if (BNXT_NEW_RM(bp)) 851db4723b3SMichael Chan bnxt_hwrm_func_resc_qcaps(bp, false); 852db4723b3SMichael Chan max_tx_sch_inputs = hw_resc->max_tx_sch_inputs; 853c0c050c5SMichael Chan 8546e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 855db4723b3SMichael Chan if (max_tx_sch_inputs) 856db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 857a79a5276SMichael Chan channel->max_combined = min_t(int, max_rx_rings, max_tx_rings); 858068c9ec6SMichael Chan 85918d6e4e2SSatish Baddipadige if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) { 86018d6e4e2SSatish Baddipadige max_rx_rings = 0; 86118d6e4e2SSatish Baddipadige max_tx_rings = 0; 86218d6e4e2SSatish Baddipadige } 863db4723b3SMichael Chan if (max_tx_sch_inputs) 864db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 86518d6e4e2SSatish Baddipadige 866c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 867c0c050c5SMichael Chan if (tcs > 1) 868c0c050c5SMichael Chan max_tx_rings /= tcs; 869c0c050c5SMichael Chan 870c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 871c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 872c0c050c5SMichael Chan channel->max_other = 0; 873068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 874068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 87576595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp)) 87676595193SPrashant Sreedharan channel->combined_count--; 877068c9ec6SMichael Chan } else { 87876595193SPrashant Sreedharan if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) { 879c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 880c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 881c0c050c5SMichael Chan } 882068c9ec6SMichael Chan } 88376595193SPrashant Sreedharan } 884c0c050c5SMichael Chan 885c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 886c0c050c5SMichael Chan struct ethtool_channels *channel) 887c0c050c5SMichael Chan { 888c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 889d1e7925eSMichael Chan int req_tx_rings, req_rx_rings, tcs; 890068c9ec6SMichael Chan bool sh = false; 8915f449249SMichael Chan int tx_xdp = 0; 892d1e7925eSMichael Chan int rc = 0; 893c0c050c5SMichael Chan 894068c9ec6SMichael Chan if (channel->other_count) 895c0c050c5SMichael Chan return -EINVAL; 896c0c050c5SMichael Chan 897068c9ec6SMichael Chan if (!channel->combined_count && 898068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 899068c9ec6SMichael Chan return -EINVAL; 900068c9ec6SMichael Chan 901068c9ec6SMichael Chan if (channel->combined_count && 902068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 903068c9ec6SMichael Chan return -EINVAL; 904068c9ec6SMichael Chan 90576595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count || 90676595193SPrashant Sreedharan channel->tx_count)) 90776595193SPrashant Sreedharan return -EINVAL; 90876595193SPrashant Sreedharan 909068c9ec6SMichael Chan if (channel->combined_count) 910068c9ec6SMichael Chan sh = true; 911068c9ec6SMichael Chan 912c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 913c0c050c5SMichael Chan 914391be5c2SMichael Chan req_tx_rings = sh ? channel->combined_count : channel->tx_count; 915d1e7925eSMichael Chan req_rx_rings = sh ? channel->combined_count : channel->rx_count; 9165f449249SMichael Chan if (bp->tx_nr_rings_xdp) { 9175f449249SMichael Chan if (!sh) { 9185f449249SMichael Chan netdev_err(dev, "Only combined mode supported when XDP is enabled.\n"); 9195f449249SMichael Chan return -EINVAL; 9205f449249SMichael Chan } 9215f449249SMichael Chan tx_xdp = req_rx_rings; 9225f449249SMichael Chan } 92398fdbe73SMichael Chan rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp); 924d1e7925eSMichael Chan if (rc) { 925d1e7925eSMichael Chan netdev_warn(dev, "Unable to allocate the requested rings\n"); 926d1e7925eSMichael Chan return rc; 927391be5c2SMichael Chan } 928391be5c2SMichael Chan 929c0c050c5SMichael Chan if (netif_running(dev)) { 930c0c050c5SMichael Chan if (BNXT_PF(bp)) { 931c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 932c0c050c5SMichael Chan * before PF unload 933c0c050c5SMichael Chan */ 934c0c050c5SMichael Chan } 935c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 936c0c050c5SMichael Chan if (rc) { 937c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 938c0c050c5SMichael Chan rc); 939c0c050c5SMichael Chan return rc; 940c0c050c5SMichael Chan } 941c0c050c5SMichael Chan } 942c0c050c5SMichael Chan 943068c9ec6SMichael Chan if (sh) { 944068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 945d1e7925eSMichael Chan bp->rx_nr_rings = channel->combined_count; 946d1e7925eSMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 947068c9ec6SMichael Chan } else { 948068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 949c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 950c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 951068c9ec6SMichael Chan } 9525f449249SMichael Chan bp->tx_nr_rings_xdp = tx_xdp; 9535f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp; 954c0c050c5SMichael Chan if (tcs > 1) 9555f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp; 956068c9ec6SMichael Chan 957068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 958068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 959068c9ec6SMichael Chan 9602bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 9612bcfa6f6SMichael Chan netdev_update_features(dev); 962c0c050c5SMichael Chan if (netif_running(dev)) { 963c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 964c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 965c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 966c0c050c5SMichael Chan * to renable 967c0c050c5SMichael Chan */ 968c0c050c5SMichael Chan } 969d8c09f19SMichael Chan } else { 9701b3f0b75SMichael Chan rc = bnxt_reserve_rings(bp, true); 971c0c050c5SMichael Chan } 972c0c050c5SMichael Chan 973c0c050c5SMichael Chan return rc; 974c0c050c5SMichael Chan } 975c0c050c5SMichael Chan 976c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 977c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 978c0c050c5SMichael Chan u32 *rule_locs) 979c0c050c5SMichael Chan { 980c0c050c5SMichael Chan int i, j = 0; 981c0c050c5SMichael Chan 982c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 983c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 984c0c050c5SMichael Chan struct hlist_head *head; 985c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 986c0c050c5SMichael Chan 987c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 988c0c050c5SMichael Chan rcu_read_lock(); 989c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 990c0c050c5SMichael Chan if (j == cmd->rule_cnt) 991c0c050c5SMichael Chan break; 992c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 993c0c050c5SMichael Chan } 994c0c050c5SMichael Chan rcu_read_unlock(); 995c0c050c5SMichael Chan if (j == cmd->rule_cnt) 996c0c050c5SMichael Chan break; 997c0c050c5SMichael Chan } 998c0c050c5SMichael Chan cmd->rule_cnt = j; 999c0c050c5SMichael Chan return 0; 1000c0c050c5SMichael Chan } 1001c0c050c5SMichael Chan 1002c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1003c0c050c5SMichael Chan { 1004c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 1005c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 1006c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 1007c0c050c5SMichael Chan struct flow_keys *fkeys; 1008c0c050c5SMichael Chan int i, rc = -EINVAL; 1009c0c050c5SMichael Chan 1010b721cfafSstephen hemminger if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 1011c0c050c5SMichael Chan return rc; 1012c0c050c5SMichael Chan 1013c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 1014c0c050c5SMichael Chan struct hlist_head *head; 1015c0c050c5SMichael Chan 1016c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 1017c0c050c5SMichael Chan rcu_read_lock(); 1018c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 1019c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 1020c0c050c5SMichael Chan goto fltr_found; 1021c0c050c5SMichael Chan } 1022c0c050c5SMichael Chan rcu_read_unlock(); 1023c0c050c5SMichael Chan } 1024c0c050c5SMichael Chan return rc; 1025c0c050c5SMichael Chan 1026c0c050c5SMichael Chan fltr_found: 1027c0c050c5SMichael Chan fkeys = &fltr->fkeys; 1028dda0e746SMichael Chan if (fkeys->basic.n_proto == htons(ETH_P_IP)) { 1029c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 1030c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 1031c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 1032c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 1033c0c050c5SMichael Chan else 1034c0c050c5SMichael Chan goto fltr_err; 1035c0c050c5SMichael Chan 1036c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 1037c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 1038c0c050c5SMichael Chan 1039c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 1040c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 1041c0c050c5SMichael Chan 1042c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 1043c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 1044c0c050c5SMichael Chan 1045c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 1046c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 1047dda0e746SMichael Chan } else { 1048dda0e746SMichael Chan int i; 1049dda0e746SMichael Chan 1050dda0e746SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 1051dda0e746SMichael Chan fs->flow_type = TCP_V6_FLOW; 1052dda0e746SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 1053dda0e746SMichael Chan fs->flow_type = UDP_V6_FLOW; 1054dda0e746SMichael Chan else 1055dda0e746SMichael Chan goto fltr_err; 1056dda0e746SMichael Chan 1057dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] = 1058dda0e746SMichael Chan fkeys->addrs.v6addrs.src; 1059dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] = 1060dda0e746SMichael Chan fkeys->addrs.v6addrs.dst; 1061dda0e746SMichael Chan for (i = 0; i < 4; i++) { 1062dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0); 1063dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0); 1064dda0e746SMichael Chan } 1065dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src; 1066dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0); 1067dda0e746SMichael Chan 1068dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst; 1069dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0); 1070dda0e746SMichael Chan } 1071c0c050c5SMichael Chan 1072c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 1073c0c050c5SMichael Chan rc = 0; 1074c0c050c5SMichael Chan 1075c0c050c5SMichael Chan fltr_err: 1076c0c050c5SMichael Chan rcu_read_unlock(); 1077c0c050c5SMichael Chan 1078c0c050c5SMichael Chan return rc; 1079c0c050c5SMichael Chan } 1080a011952aSMichael Chan #endif 1081a011952aSMichael Chan 1082a011952aSMichael Chan static u64 get_ethtool_ipv4_rss(struct bnxt *bp) 1083a011952aSMichael Chan { 1084a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4) 1085a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 1086a011952aSMichael Chan return 0; 1087a011952aSMichael Chan } 1088a011952aSMichael Chan 1089a011952aSMichael Chan static u64 get_ethtool_ipv6_rss(struct bnxt *bp) 1090a011952aSMichael Chan { 1091a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6) 1092a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 1093a011952aSMichael Chan return 0; 1094a011952aSMichael Chan } 1095a011952aSMichael Chan 1096a011952aSMichael Chan static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1097a011952aSMichael Chan { 1098a011952aSMichael Chan cmd->data = 0; 1099a011952aSMichael Chan switch (cmd->flow_type) { 1100a011952aSMichael Chan case TCP_V4_FLOW: 1101a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) 1102a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1103a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1104a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1105a011952aSMichael Chan break; 1106a011952aSMichael Chan case UDP_V4_FLOW: 1107a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4) 1108a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1109a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1110a011952aSMichael Chan /* fall through */ 1111a011952aSMichael Chan case SCTP_V4_FLOW: 1112a011952aSMichael Chan case AH_ESP_V4_FLOW: 1113a011952aSMichael Chan case AH_V4_FLOW: 1114a011952aSMichael Chan case ESP_V4_FLOW: 1115a011952aSMichael Chan case IPV4_FLOW: 1116a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1117a011952aSMichael Chan break; 1118a011952aSMichael Chan 1119a011952aSMichael Chan case TCP_V6_FLOW: 1120a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) 1121a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1122a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1123a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1124a011952aSMichael Chan break; 1125a011952aSMichael Chan case UDP_V6_FLOW: 1126a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6) 1127a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1128a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1129a011952aSMichael Chan /* fall through */ 1130a011952aSMichael Chan case SCTP_V6_FLOW: 1131a011952aSMichael Chan case AH_ESP_V6_FLOW: 1132a011952aSMichael Chan case AH_V6_FLOW: 1133a011952aSMichael Chan case ESP_V6_FLOW: 1134a011952aSMichael Chan case IPV6_FLOW: 1135a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1136a011952aSMichael Chan break; 1137a011952aSMichael Chan } 1138a011952aSMichael Chan return 0; 1139a011952aSMichael Chan } 1140a011952aSMichael Chan 1141a011952aSMichael Chan #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3) 1142a011952aSMichael Chan #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST) 1143a011952aSMichael Chan 1144a011952aSMichael Chan static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1145a011952aSMichael Chan { 1146a011952aSMichael Chan u32 rss_hash_cfg = bp->rss_hash_cfg; 1147a011952aSMichael Chan int tuple, rc = 0; 1148a011952aSMichael Chan 1149a011952aSMichael Chan if (cmd->data == RXH_4TUPLE) 1150a011952aSMichael Chan tuple = 4; 1151a011952aSMichael Chan else if (cmd->data == RXH_2TUPLE) 1152a011952aSMichael Chan tuple = 2; 1153a011952aSMichael Chan else if (!cmd->data) 1154a011952aSMichael Chan tuple = 0; 1155a011952aSMichael Chan else 1156a011952aSMichael Chan return -EINVAL; 1157a011952aSMichael Chan 1158a011952aSMichael Chan if (cmd->flow_type == TCP_V4_FLOW) { 1159a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1160a011952aSMichael Chan if (tuple == 4) 1161a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1162a011952aSMichael Chan } else if (cmd->flow_type == UDP_V4_FLOW) { 1163a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1164a011952aSMichael Chan return -EINVAL; 1165a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1166a011952aSMichael Chan if (tuple == 4) 1167a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1168a011952aSMichael Chan } else if (cmd->flow_type == TCP_V6_FLOW) { 1169a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1170a011952aSMichael Chan if (tuple == 4) 1171a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1172a011952aSMichael Chan } else if (cmd->flow_type == UDP_V6_FLOW) { 1173a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1174a011952aSMichael Chan return -EINVAL; 1175a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1176a011952aSMichael Chan if (tuple == 4) 1177a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1178a011952aSMichael Chan } else if (tuple == 4) { 1179a011952aSMichael Chan return -EINVAL; 1180a011952aSMichael Chan } 1181a011952aSMichael Chan 1182a011952aSMichael Chan switch (cmd->flow_type) { 1183a011952aSMichael Chan case TCP_V4_FLOW: 1184a011952aSMichael Chan case UDP_V4_FLOW: 1185a011952aSMichael Chan case SCTP_V4_FLOW: 1186a011952aSMichael Chan case AH_ESP_V4_FLOW: 1187a011952aSMichael Chan case AH_V4_FLOW: 1188a011952aSMichael Chan case ESP_V4_FLOW: 1189a011952aSMichael Chan case IPV4_FLOW: 1190a011952aSMichael Chan if (tuple == 2) 1191a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1192a011952aSMichael Chan else if (!tuple) 1193a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1194a011952aSMichael Chan break; 1195a011952aSMichael Chan 1196a011952aSMichael Chan case TCP_V6_FLOW: 1197a011952aSMichael Chan case UDP_V6_FLOW: 1198a011952aSMichael Chan case SCTP_V6_FLOW: 1199a011952aSMichael Chan case AH_ESP_V6_FLOW: 1200a011952aSMichael Chan case AH_V6_FLOW: 1201a011952aSMichael Chan case ESP_V6_FLOW: 1202a011952aSMichael Chan case IPV6_FLOW: 1203a011952aSMichael Chan if (tuple == 2) 1204a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1205a011952aSMichael Chan else if (!tuple) 1206a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1207a011952aSMichael Chan break; 1208a011952aSMichael Chan } 1209a011952aSMichael Chan 1210a011952aSMichael Chan if (bp->rss_hash_cfg == rss_hash_cfg) 1211a011952aSMichael Chan return 0; 1212a011952aSMichael Chan 1213a011952aSMichael Chan bp->rss_hash_cfg = rss_hash_cfg; 1214a011952aSMichael Chan if (netif_running(bp->dev)) { 1215a011952aSMichael Chan bnxt_close_nic(bp, false, false); 1216a011952aSMichael Chan rc = bnxt_open_nic(bp, false, false); 1217a011952aSMichael Chan } 1218a011952aSMichael Chan return rc; 1219a011952aSMichael Chan } 1220c0c050c5SMichael Chan 1221c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 1222c0c050c5SMichael Chan u32 *rule_locs) 1223c0c050c5SMichael Chan { 1224c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1225c0c050c5SMichael Chan int rc = 0; 1226c0c050c5SMichael Chan 1227c0c050c5SMichael Chan switch (cmd->cmd) { 1228a011952aSMichael Chan #ifdef CONFIG_RFS_ACCEL 1229c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 1230c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 1231c0c050c5SMichael Chan break; 1232c0c050c5SMichael Chan 1233c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 1234c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 1235c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 1236c0c050c5SMichael Chan break; 1237c0c050c5SMichael Chan 1238c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 1239c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 1240c0c050c5SMichael Chan break; 1241c0c050c5SMichael Chan 1242c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 1243c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 1244c0c050c5SMichael Chan break; 1245a011952aSMichael Chan #endif 1246a011952aSMichael Chan 1247a011952aSMichael Chan case ETHTOOL_GRXFH: 1248a011952aSMichael Chan rc = bnxt_grxfh(bp, cmd); 1249a011952aSMichael Chan break; 1250c0c050c5SMichael Chan 1251c0c050c5SMichael Chan default: 1252c0c050c5SMichael Chan rc = -EOPNOTSUPP; 1253c0c050c5SMichael Chan break; 1254c0c050c5SMichael Chan } 1255c0c050c5SMichael Chan 1256c0c050c5SMichael Chan return rc; 1257c0c050c5SMichael Chan } 1258a011952aSMichael Chan 1259a011952aSMichael Chan static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) 1260a011952aSMichael Chan { 1261a011952aSMichael Chan struct bnxt *bp = netdev_priv(dev); 1262a011952aSMichael Chan int rc; 1263a011952aSMichael Chan 1264a011952aSMichael Chan switch (cmd->cmd) { 1265a011952aSMichael Chan case ETHTOOL_SRXFH: 1266a011952aSMichael Chan rc = bnxt_srxfh(bp, cmd); 1267a011952aSMichael Chan break; 1268a011952aSMichael Chan 1269a011952aSMichael Chan default: 1270a011952aSMichael Chan rc = -EOPNOTSUPP; 1271a011952aSMichael Chan break; 1272a011952aSMichael Chan } 1273a011952aSMichael Chan return rc; 1274a011952aSMichael Chan } 1275c0c050c5SMichael Chan 1276b73c1d08SMichael Chan u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 1277c0c050c5SMichael Chan { 1278b73c1d08SMichael Chan struct bnxt *bp = netdev_priv(dev); 1279b73c1d08SMichael Chan 1280b73c1d08SMichael Chan if (bp->flags & BNXT_FLAG_CHIP_P5) 1281b73c1d08SMichael Chan return ALIGN(bp->rx_nr_rings, BNXT_RSS_TABLE_ENTRIES_P5); 1282c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 1283c0c050c5SMichael Chan } 1284c0c050c5SMichael Chan 1285c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 1286c0c050c5SMichael Chan { 1287c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 1288c0c050c5SMichael Chan } 1289c0c050c5SMichael Chan 1290c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 1291c0c050c5SMichael Chan u8 *hfunc) 1292c0c050c5SMichael Chan { 1293c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 12947991cb9cSMichael Chan struct bnxt_vnic_info *vnic; 1295c0c050c5SMichael Chan int i = 0; 1296c0c050c5SMichael Chan 1297c0c050c5SMichael Chan if (hfunc) 1298c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 1299c0c050c5SMichael Chan 13007991cb9cSMichael Chan if (!bp->vnic_info) 13017991cb9cSMichael Chan return 0; 13027991cb9cSMichael Chan 13037991cb9cSMichael Chan vnic = &bp->vnic_info[0]; 13047991cb9cSMichael Chan if (indir && vnic->rss_table) { 1305c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 1306c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 13077991cb9cSMichael Chan } 1308c0c050c5SMichael Chan 13097991cb9cSMichael Chan if (key && vnic->rss_hash_key) 1310c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 1311c0c050c5SMichael Chan 1312c0c050c5SMichael Chan return 0; 1313c0c050c5SMichael Chan } 1314c0c050c5SMichael Chan 1315c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 1316c0c050c5SMichael Chan struct ethtool_drvinfo *info) 1317c0c050c5SMichael Chan { 1318c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1319c0c050c5SMichael Chan 1320c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 1321431aa1ebSMichael Chan strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); 1322c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 13235c8227d0SMichael Chan info->n_stats = bnxt_get_num_stats(bp); 1324eb513658SMichael Chan info->testinfo_len = bp->num_tests; 1325c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 1326c0c050c5SMichael Chan info->eedump_len = 0; 1327c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 1328c0c050c5SMichael Chan info->regdump_len = 0; 1329c0c050c5SMichael Chan } 1330c0c050c5SMichael Chan 13318e202366SMichael Chan static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 13328e202366SMichael Chan { 13338e202366SMichael Chan struct bnxt *bp = netdev_priv(dev); 13348e202366SMichael Chan 13358e202366SMichael Chan wol->supported = 0; 13368e202366SMichael Chan wol->wolopts = 0; 13378e202366SMichael Chan memset(&wol->sopass, 0, sizeof(wol->sopass)); 13388e202366SMichael Chan if (bp->flags & BNXT_FLAG_WOL_CAP) { 13398e202366SMichael Chan wol->supported = WAKE_MAGIC; 13408e202366SMichael Chan if (bp->wol) 13418e202366SMichael Chan wol->wolopts = WAKE_MAGIC; 13428e202366SMichael Chan } 13438e202366SMichael Chan } 13448e202366SMichael Chan 13455282db6cSMichael Chan static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 13465282db6cSMichael Chan { 13475282db6cSMichael Chan struct bnxt *bp = netdev_priv(dev); 13485282db6cSMichael Chan 13495282db6cSMichael Chan if (wol->wolopts & ~WAKE_MAGIC) 13505282db6cSMichael Chan return -EINVAL; 13515282db6cSMichael Chan 13525282db6cSMichael Chan if (wol->wolopts & WAKE_MAGIC) { 13535282db6cSMichael Chan if (!(bp->flags & BNXT_FLAG_WOL_CAP)) 13545282db6cSMichael Chan return -EINVAL; 13555282db6cSMichael Chan if (!bp->wol) { 13565282db6cSMichael Chan if (bnxt_hwrm_alloc_wol_fltr(bp)) 13575282db6cSMichael Chan return -EBUSY; 13585282db6cSMichael Chan bp->wol = 1; 13595282db6cSMichael Chan } 13605282db6cSMichael Chan } else { 13615282db6cSMichael Chan if (bp->wol) { 13625282db6cSMichael Chan if (bnxt_hwrm_free_wol_fltr(bp)) 13635282db6cSMichael Chan return -EBUSY; 13645282db6cSMichael Chan bp->wol = 0; 13655282db6cSMichael Chan } 13665282db6cSMichael Chan } 13675282db6cSMichael Chan return 0; 13685282db6cSMichael Chan } 13695282db6cSMichael Chan 1370170ce013SMichael Chan u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause) 1371c0c050c5SMichael Chan { 1372c0c050c5SMichael Chan u32 speed_mask = 0; 1373c0c050c5SMichael Chan 1374c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 1375c0c050c5SMichael Chan /* set the advertised speeds */ 1376c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 1377c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 1378c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 1379c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 1380c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 1381c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 1382c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 1383c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 1384c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 13851c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 138627c4d578SMichael Chan 138727c4d578SMichael Chan if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH) 138827c4d578SMichael Chan speed_mask |= ADVERTISED_Pause; 138927c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_TX) 139027c4d578SMichael Chan speed_mask |= ADVERTISED_Asym_Pause; 139127c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_RX) 139227c4d578SMichael Chan speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 139327c4d578SMichael Chan 1394c0c050c5SMichael Chan return speed_mask; 1395c0c050c5SMichael Chan } 1396c0c050c5SMichael Chan 139700c04a92SMichael Chan #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\ 139800c04a92SMichael Chan { \ 139900c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \ 140000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 140100c04a92SMichael Chan 100baseT_Full); \ 140200c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \ 140300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 140400c04a92SMichael Chan 1000baseT_Full); \ 140500c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \ 140600c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 140700c04a92SMichael Chan 10000baseT_Full); \ 140800c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \ 140900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 141000c04a92SMichael Chan 25000baseCR_Full); \ 141100c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \ 141200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 141300c04a92SMichael Chan 40000baseCR4_Full);\ 141400c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \ 141500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 141600c04a92SMichael Chan 50000baseCR2_Full);\ 141738a21b34SDeepak Khungar if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \ 141838a21b34SDeepak Khungar ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 141938a21b34SDeepak Khungar 100000baseCR4_Full);\ 142000c04a92SMichael Chan if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \ 142100c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 142200c04a92SMichael Chan Pause); \ 142300c04a92SMichael Chan if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \ 142400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode( \ 142500c04a92SMichael Chan lk_ksettings, name, Asym_Pause);\ 142600c04a92SMichael Chan } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \ 142700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 142800c04a92SMichael Chan Asym_Pause); \ 142900c04a92SMichael Chan } \ 143000c04a92SMichael Chan } 143100c04a92SMichael Chan 143200c04a92SMichael Chan #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \ 143300c04a92SMichael Chan { \ 143400c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 143500c04a92SMichael Chan 100baseT_Full) || \ 143600c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 143700c04a92SMichael Chan 100baseT_Half)) \ 143800c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \ 143900c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 144000c04a92SMichael Chan 1000baseT_Full) || \ 144100c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 144200c04a92SMichael Chan 1000baseT_Half)) \ 144300c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \ 144400c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 144500c04a92SMichael Chan 10000baseT_Full)) \ 144600c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \ 144700c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 144800c04a92SMichael Chan 25000baseCR_Full)) \ 144900c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \ 145000c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 145100c04a92SMichael Chan 40000baseCR4_Full)) \ 145200c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \ 145300c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 145400c04a92SMichael Chan 50000baseCR2_Full)) \ 145500c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \ 145638a21b34SDeepak Khungar if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 145738a21b34SDeepak Khungar 100000baseCR4_Full)) \ 145838a21b34SDeepak Khungar (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \ 145900c04a92SMichael Chan } 146000c04a92SMichael Chan 146100c04a92SMichael Chan static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info, 146200c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 146327c4d578SMichael Chan { 146468515a18SMichael Chan u16 fw_speeds = link_info->advertising; 146527c4d578SMichael Chan u8 fw_pause = 0; 146627c4d578SMichael Chan 146727c4d578SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 146827c4d578SMichael Chan fw_pause = link_info->auto_pause_setting; 146927c4d578SMichael Chan 147000c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising); 147127c4d578SMichael Chan } 147227c4d578SMichael Chan 147300c04a92SMichael Chan static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info, 147400c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 14753277360eSMichael Chan { 14763277360eSMichael Chan u16 fw_speeds = link_info->lp_auto_link_speeds; 14773277360eSMichael Chan u8 fw_pause = 0; 14783277360eSMichael Chan 14793277360eSMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 14803277360eSMichael Chan fw_pause = link_info->lp_pause; 14813277360eSMichael Chan 148200c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, 148300c04a92SMichael Chan lp_advertising); 14843277360eSMichael Chan } 14853277360eSMichael Chan 148600c04a92SMichael Chan static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info, 148700c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 14884b32caccSMichael Chan { 14894b32caccSMichael Chan u16 fw_speeds = link_info->support_speeds; 14904b32caccSMichael Chan 149100c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported); 14924b32caccSMichael Chan 149300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause); 149400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 149500c04a92SMichael Chan Asym_Pause); 149693ed8117SMichael Chan 149700c04a92SMichael Chan if (link_info->support_auto_speeds) 149800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 149900c04a92SMichael Chan Autoneg); 150093ed8117SMichael Chan } 150193ed8117SMichael Chan 1502c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 1503c0c050c5SMichael Chan { 1504c0c050c5SMichael Chan switch (fw_link_speed) { 1505c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 1506c0c050c5SMichael Chan return SPEED_100; 1507c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 1508c0c050c5SMichael Chan return SPEED_1000; 1509c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 1510c0c050c5SMichael Chan return SPEED_2500; 1511c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 1512c0c050c5SMichael Chan return SPEED_10000; 1513c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 1514c0c050c5SMichael Chan return SPEED_20000; 1515c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 1516c0c050c5SMichael Chan return SPEED_25000; 1517c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 1518c0c050c5SMichael Chan return SPEED_40000; 1519c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 1520c0c050c5SMichael Chan return SPEED_50000; 152138a21b34SDeepak Khungar case BNXT_LINK_SPEED_100GB: 152238a21b34SDeepak Khungar return SPEED_100000; 1523c0c050c5SMichael Chan default: 1524c0c050c5SMichael Chan return SPEED_UNKNOWN; 1525c0c050c5SMichael Chan } 1526c0c050c5SMichael Chan } 1527c0c050c5SMichael Chan 152800c04a92SMichael Chan static int bnxt_get_link_ksettings(struct net_device *dev, 152900c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 1530c0c050c5SMichael Chan { 1531c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1532c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 153300c04a92SMichael Chan struct ethtool_link_settings *base = &lk_ksettings->base; 153400c04a92SMichael Chan u32 ethtool_speed; 1535c0c050c5SMichael Chan 153600c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported); 1537e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 153800c04a92SMichael Chan bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings); 1539c0c050c5SMichael Chan 154000c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising); 1541b763499eSMichael Chan if (link_info->autoneg) { 154200c04a92SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings); 154300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, 154400c04a92SMichael Chan advertising, Autoneg); 154500c04a92SMichael Chan base->autoneg = AUTONEG_ENABLE; 154600c04a92SMichael Chan base->duplex = DUPLEX_UNKNOWN; 154783d8f5e9SMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) { 154883d8f5e9SMichael Chan bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings); 154983d8f5e9SMichael Chan if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 155000c04a92SMichael Chan base->duplex = DUPLEX_FULL; 155129c262feSMichael Chan else 155200c04a92SMichael Chan base->duplex = DUPLEX_HALF; 155383d8f5e9SMichael Chan } 155483d8f5e9SMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 1555c0c050c5SMichael Chan } else { 155600c04a92SMichael Chan base->autoneg = AUTONEG_DISABLE; 155729c262feSMichael Chan ethtool_speed = 155829c262feSMichael Chan bnxt_fw_to_ethtool_speed(link_info->req_link_speed); 155900c04a92SMichael Chan base->duplex = DUPLEX_HALF; 156029c262feSMichael Chan if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL) 156100c04a92SMichael Chan base->duplex = DUPLEX_FULL; 1562c0c050c5SMichael Chan } 156300c04a92SMichael Chan base->speed = ethtool_speed; 1564c0c050c5SMichael Chan 156500c04a92SMichael Chan base->port = PORT_NONE; 1566c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 156700c04a92SMichael Chan base->port = PORT_TP; 156800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 156900c04a92SMichael Chan TP); 157000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 157100c04a92SMichael Chan TP); 1572c0c050c5SMichael Chan } else { 157300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 157400c04a92SMichael Chan FIBRE); 157500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 157600c04a92SMichael Chan FIBRE); 1577c0c050c5SMichael Chan 1578c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 157900c04a92SMichael Chan base->port = PORT_DA; 1580c0c050c5SMichael Chan else if (link_info->media_type == 1581c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 158200c04a92SMichael Chan base->port = PORT_FIBRE; 1583c0c050c5SMichael Chan } 158400c04a92SMichael Chan base->phy_address = link_info->phy_addr; 1585e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1586c0c050c5SMichael Chan 1587c0c050c5SMichael Chan return 0; 1588c0c050c5SMichael Chan } 1589c0c050c5SMichael Chan 159038a21b34SDeepak Khungar static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed) 1591c0c050c5SMichael Chan { 15929d9cee08SMichael Chan struct bnxt *bp = netdev_priv(dev); 15939d9cee08SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 15949d9cee08SMichael Chan u16 support_spds = link_info->support_speeds; 15959d9cee08SMichael Chan u32 fw_speed = 0; 15969d9cee08SMichael Chan 1597c0c050c5SMichael Chan switch (ethtool_speed) { 1598c0c050c5SMichael Chan case SPEED_100: 15999d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_100MB) 16009d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 16019d9cee08SMichael Chan break; 1602c0c050c5SMichael Chan case SPEED_1000: 16039d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_1GB) 16049d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 16059d9cee08SMichael Chan break; 1606c0c050c5SMichael Chan case SPEED_2500: 16079d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB) 16089d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 16099d9cee08SMichael Chan break; 1610c0c050c5SMichael Chan case SPEED_10000: 16119d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_10GB) 16129d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 16139d9cee08SMichael Chan break; 1614c0c050c5SMichael Chan case SPEED_20000: 16159d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_20GB) 16169d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 16179d9cee08SMichael Chan break; 1618c0c050c5SMichael Chan case SPEED_25000: 16199d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_25GB) 16209d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 16219d9cee08SMichael Chan break; 1622c0c050c5SMichael Chan case SPEED_40000: 16239d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_40GB) 16249d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 16259d9cee08SMichael Chan break; 1626c0c050c5SMichael Chan case SPEED_50000: 16279d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_50GB) 16289d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 16299d9cee08SMichael Chan break; 163038a21b34SDeepak Khungar case SPEED_100000: 163138a21b34SDeepak Khungar if (support_spds & BNXT_LINK_SPEED_MSK_100GB) 163238a21b34SDeepak Khungar fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB; 163338a21b34SDeepak Khungar break; 1634c0c050c5SMichael Chan default: 1635c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 1636c0c050c5SMichael Chan break; 1637c0c050c5SMichael Chan } 16389d9cee08SMichael Chan return fw_speed; 1639c0c050c5SMichael Chan } 1640c0c050c5SMichael Chan 1641939f7f0cSMichael Chan u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 1642c0c050c5SMichael Chan { 1643c0c050c5SMichael Chan u16 fw_speed_mask = 0; 1644c0c050c5SMichael Chan 1645c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 1646c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 1647c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 1648c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 1649c0c050c5SMichael Chan } 1650c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 1651c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 1652c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 1653c0c050c5SMichael Chan } 1654c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 1655c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 1656c0c050c5SMichael Chan 16571c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 16581c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 16591c49c421SMichael Chan 1660c0c050c5SMichael Chan return fw_speed_mask; 1661c0c050c5SMichael Chan } 1662c0c050c5SMichael Chan 166300c04a92SMichael Chan static int bnxt_set_link_ksettings(struct net_device *dev, 166400c04a92SMichael Chan const struct ethtool_link_ksettings *lk_ksettings) 1665c0c050c5SMichael Chan { 1666c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1667c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 166800c04a92SMichael Chan const struct ethtool_link_settings *base = &lk_ksettings->base; 1669c0c050c5SMichael Chan bool set_pause = false; 167068515a18SMichael Chan u16 fw_advertising = 0; 167168515a18SMichael Chan u32 speed; 167200c04a92SMichael Chan int rc = 0; 1673c0c050c5SMichael Chan 1674c7e457f4SMichael Chan if (!BNXT_PHY_CFG_ABLE(bp)) 167500c04a92SMichael Chan return -EOPNOTSUPP; 1676c0c050c5SMichael Chan 1677e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 167800c04a92SMichael Chan if (base->autoneg == AUTONEG_ENABLE) { 167900c04a92SMichael Chan BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings, 168000c04a92SMichael Chan advertising); 1681c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 1682c0c050c5SMichael Chan if (!fw_advertising) 168393ed8117SMichael Chan link_info->advertising = link_info->support_auto_speeds; 1684c0c050c5SMichael Chan else 1685c0c050c5SMichael Chan link_info->advertising = fw_advertising; 1686c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 1687c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 1688c0c050c5SMichael Chan */ 1689c0c050c5SMichael Chan set_pause = true; 1690c0c050c5SMichael Chan } else { 16919d9cee08SMichael Chan u16 fw_speed; 169203efbec0SMichael Chan u8 phy_type = link_info->phy_type; 16939d9cee08SMichael Chan 169403efbec0SMichael Chan if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET || 169503efbec0SMichael Chan phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE || 169603efbec0SMichael Chan link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 169703efbec0SMichael Chan netdev_err(dev, "10GBase-T devices must autoneg\n"); 169803efbec0SMichael Chan rc = -EINVAL; 169903efbec0SMichael Chan goto set_setting_exit; 170003efbec0SMichael Chan } 170100c04a92SMichael Chan if (base->duplex == DUPLEX_HALF) { 1702c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 1703c0c050c5SMichael Chan rc = -EINVAL; 1704c0c050c5SMichael Chan goto set_setting_exit; 1705c0c050c5SMichael Chan } 170600c04a92SMichael Chan speed = base->speed; 17079d9cee08SMichael Chan fw_speed = bnxt_get_fw_speed(dev, speed); 17089d9cee08SMichael Chan if (!fw_speed) { 17099d9cee08SMichael Chan rc = -EINVAL; 17109d9cee08SMichael Chan goto set_setting_exit; 17119d9cee08SMichael Chan } 17129d9cee08SMichael Chan link_info->req_link_speed = fw_speed; 1713c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 1714b763499eSMichael Chan link_info->autoneg = 0; 1715c0c050c5SMichael Chan link_info->advertising = 0; 1716c0c050c5SMichael Chan } 1717c0c050c5SMichael Chan 1718c0c050c5SMichael Chan if (netif_running(dev)) 1719939f7f0cSMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause, false); 1720c0c050c5SMichael Chan 1721c0c050c5SMichael Chan set_setting_exit: 1722e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1723c0c050c5SMichael Chan return rc; 1724c0c050c5SMichael Chan } 1725c0c050c5SMichael Chan 1726c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 1727c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1728c0c050c5SMichael Chan { 1729c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1730c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1731c0c050c5SMichael Chan 1732c0c050c5SMichael Chan if (BNXT_VF(bp)) 1733c0c050c5SMichael Chan return; 1734b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 17353c02d1bbSMichael Chan epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX); 17363c02d1bbSMichael Chan epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX); 1737c0c050c5SMichael Chan } 1738c0c050c5SMichael Chan 1739c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 1740c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1741c0c050c5SMichael Chan { 1742c0c050c5SMichael Chan int rc = 0; 1743c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1744c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1745c0c050c5SMichael Chan 1746c7e457f4SMichael Chan if (!BNXT_PHY_CFG_ABLE(bp)) 174775362a3fSMichael Chan return -EOPNOTSUPP; 1748c0c050c5SMichael Chan 1749c0c050c5SMichael Chan if (epause->autoneg) { 1750b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 1751b763499eSMichael Chan return -EINVAL; 1752b763499eSMichael Chan 1753c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 1754c9ee9516SMichael Chan if (bp->hwrm_spec_code >= 0x10201) 1755c9ee9516SMichael Chan link_info->req_flow_ctrl = 1756c9ee9516SMichael Chan PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; 1757c0c050c5SMichael Chan } else { 1758c0c050c5SMichael Chan /* when transition from auto pause to force pause, 1759c0c050c5SMichael Chan * force a link change 1760c0c050c5SMichael Chan */ 1761c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 1762c0c050c5SMichael Chan link_info->force_link_chng = true; 1763c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 1764c9ee9516SMichael Chan link_info->req_flow_ctrl = 0; 1765c0c050c5SMichael Chan } 1766c0c050c5SMichael Chan if (epause->rx_pause) 1767c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 1768c0c050c5SMichael Chan 1769c0c050c5SMichael Chan if (epause->tx_pause) 1770c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 1771c0c050c5SMichael Chan 1772c0c050c5SMichael Chan if (netif_running(dev)) 1773c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 1774c0c050c5SMichael Chan return rc; 1775c0c050c5SMichael Chan } 1776c0c050c5SMichael Chan 1777c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 1778c0c050c5SMichael Chan { 1779c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1780c0c050c5SMichael Chan 1781c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 1782c0c050c5SMichael Chan return bp->link_info.link_up; 1783c0c050c5SMichael Chan } 1784c0c050c5SMichael Chan 1785b3b0ddd0SMichael Chan static void bnxt_print_admin_err(struct bnxt *bp) 1786b3b0ddd0SMichael Chan { 1787b3b0ddd0SMichael Chan netdev_info(bp->dev, "PF does not have admin privileges to flash or reset the device\n"); 1788b3b0ddd0SMichael Chan } 1789b3b0ddd0SMichael Chan 17905ac67d8bSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 17915ac67d8bSRob Swindell u16 ext, u16 *index, u32 *item_length, 17925ac67d8bSRob Swindell u32 *data_length); 17935ac67d8bSRob Swindell 1794c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 1795c0c050c5SMichael Chan u16 dir_type, 1796c0c050c5SMichael Chan u16 dir_ordinal, 1797c0c050c5SMichael Chan u16 dir_ext, 1798c0c050c5SMichael Chan u16 dir_attr, 1799c0c050c5SMichael Chan const u8 *data, 1800c0c050c5SMichael Chan size_t data_len) 1801c0c050c5SMichael Chan { 1802c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1803c0c050c5SMichael Chan int rc; 1804c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 1805c0c050c5SMichael Chan dma_addr_t dma_handle; 1806c0c050c5SMichael Chan u8 *kmem; 1807c0c050c5SMichael Chan 1808c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 1809c0c050c5SMichael Chan 1810c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 1811c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 1812c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 1813c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 1814c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 1815c0c050c5SMichael Chan 1816c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 1817c0c050c5SMichael Chan GFP_KERNEL); 1818c0c050c5SMichael Chan if (!kmem) { 1819c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1820c0c050c5SMichael Chan (unsigned)data_len); 1821c0c050c5SMichael Chan return -ENOMEM; 1822c0c050c5SMichael Chan } 1823c0c050c5SMichael Chan memcpy(kmem, data, data_len); 1824c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 1825c0c050c5SMichael Chan 1826c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 1827c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 1828c0c050c5SMichael Chan 1829d4f1420dSMichael Chan if (rc == -EACCES) 1830b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 1831c0c050c5SMichael Chan return rc; 1832c0c050c5SMichael Chan } 1833c0c050c5SMichael Chan 183495fec034SEdwin Peer static int bnxt_hwrm_firmware_reset(struct net_device *dev, u8 proc_type, 183595fec034SEdwin Peer u8 self_reset, u8 flags) 1836d2d6318cSRob Swindell { 1837d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 18387c675421SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 18397c675421SVasundhara Volam int rc; 1840d2d6318cSRob Swindell 1841d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 1842d2d6318cSRob Swindell 184395fec034SEdwin Peer req.embedded_proc_type = proc_type; 184495fec034SEdwin Peer req.selfrst_status = self_reset; 184595fec034SEdwin Peer req.flags = flags; 184695fec034SEdwin Peer 18478cec0940SEdwin Peer if (proc_type == FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP) { 18488cec0940SEdwin Peer rc = hwrm_send_message_silent(bp, &req, sizeof(req), 18498cec0940SEdwin Peer HWRM_CMD_TIMEOUT); 18508cec0940SEdwin Peer } else { 185195fec034SEdwin Peer rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 185295fec034SEdwin Peer if (rc == -EACCES) 185395fec034SEdwin Peer bnxt_print_admin_err(bp); 18548cec0940SEdwin Peer } 185595fec034SEdwin Peer return rc; 185695fec034SEdwin Peer } 185795fec034SEdwin Peer 185894f17e89SEdwin Peer static int bnxt_firmware_reset(struct net_device *dev, 185994f17e89SEdwin Peer enum bnxt_nvm_directory_type dir_type) 186095fec034SEdwin Peer { 186195fec034SEdwin Peer u8 self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTNONE; 186295fec034SEdwin Peer u8 proc_type, flags = 0; 186395fec034SEdwin Peer 1864d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 1865d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 1866d2d6318cSRob Swindell switch (dir_type) { 1867d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 1868d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 1869d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 187095fec034SEdwin Peer proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 1871d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 187295fec034SEdwin Peer self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1873d2d6318cSRob Swindell break; 1874d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 1875d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 187695fec034SEdwin Peer proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 187708141e0bSRob Swindell /* Self-reset APE upon next PCIe reset: */ 187895fec034SEdwin Peer self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1879d2d6318cSRob Swindell break; 1880d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 1881d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 188295fec034SEdwin Peer proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 1883d2d6318cSRob Swindell break; 1884d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 1885d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 188695fec034SEdwin Peer proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 1887d2d6318cSRob Swindell break; 1888d2d6318cSRob Swindell default: 1889d2d6318cSRob Swindell return -EINVAL; 1890d2d6318cSRob Swindell } 1891d2d6318cSRob Swindell 189295fec034SEdwin Peer return bnxt_hwrm_firmware_reset(dev, proc_type, self_reset, flags); 1893d2d6318cSRob Swindell } 1894d2d6318cSRob Swindell 189594f17e89SEdwin Peer static int bnxt_firmware_reset_chip(struct net_device *dev) 189694f17e89SEdwin Peer { 189794f17e89SEdwin Peer struct bnxt *bp = netdev_priv(dev); 189894f17e89SEdwin Peer u8 flags = 0; 189994f17e89SEdwin Peer 190094f17e89SEdwin Peer if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET) 190194f17e89SEdwin Peer flags = FW_RESET_REQ_FLAGS_RESET_GRACEFUL; 190294f17e89SEdwin Peer 190394f17e89SEdwin Peer return bnxt_hwrm_firmware_reset(dev, 190494f17e89SEdwin Peer FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP, 190594f17e89SEdwin Peer FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP, 190694f17e89SEdwin Peer flags); 190794f17e89SEdwin Peer } 190894f17e89SEdwin Peer 190994f17e89SEdwin Peer static int bnxt_firmware_reset_ap(struct net_device *dev) 191094f17e89SEdwin Peer { 191194f17e89SEdwin Peer return bnxt_hwrm_firmware_reset(dev, FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP, 191294f17e89SEdwin Peer FW_RESET_REQ_SELFRST_STATUS_SELFRSTNONE, 191394f17e89SEdwin Peer 0); 191494f17e89SEdwin Peer } 191594f17e89SEdwin Peer 1916c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 1917c0c050c5SMichael Chan u16 dir_type, 1918c0c050c5SMichael Chan const u8 *fw_data, 1919c0c050c5SMichael Chan size_t fw_size) 1920c0c050c5SMichael Chan { 1921c0c050c5SMichael Chan int rc = 0; 1922c0c050c5SMichael Chan u16 code_type; 1923c0c050c5SMichael Chan u32 stored_crc; 1924c0c050c5SMichael Chan u32 calculated_crc; 1925c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 1926c0c050c5SMichael Chan 1927c0c050c5SMichael Chan switch (dir_type) { 1928c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1929c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1930c0c050c5SMichael Chan code_type = CODE_BOOT; 1931c0c050c5SMichael Chan break; 193293e0b4feSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 193393e0b4feSRob Swindell code_type = CODE_CHIMP_PATCH; 193493e0b4feSRob Swindell break; 19352731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 19362731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 19372731d70fSRob Swindell break; 193893e0b4feSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 193993e0b4feSRob Swindell code_type = CODE_APE_PATCH; 194093e0b4feSRob Swindell break; 194193e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_FW: 194293e0b4feSRob Swindell code_type = CODE_KONG_FW; 194393e0b4feSRob Swindell break; 194493e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 194593e0b4feSRob Swindell code_type = CODE_KONG_PATCH; 194693e0b4feSRob Swindell break; 194793e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 194893e0b4feSRob Swindell code_type = CODE_BONO_FW; 194993e0b4feSRob Swindell break; 195093e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 195193e0b4feSRob Swindell code_type = CODE_BONO_PATCH; 195293e0b4feSRob Swindell break; 1953c0c050c5SMichael Chan default: 1954c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 1955c0c050c5SMichael Chan dir_type); 1956c0c050c5SMichael Chan return -EINVAL; 1957c0c050c5SMichael Chan } 1958c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 1959c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 1960c0c050c5SMichael Chan (unsigned int)fw_size); 1961c0c050c5SMichael Chan return -EINVAL; 1962c0c050c5SMichael Chan } 1963c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 1964c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 1965c0c050c5SMichael Chan le32_to_cpu(header->signature)); 1966c0c050c5SMichael Chan return -EINVAL; 1967c0c050c5SMichael Chan } 1968c0c050c5SMichael Chan if (header->code_type != code_type) { 1969c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 1970c0c050c5SMichael Chan code_type, header->code_type); 1971c0c050c5SMichael Chan return -EINVAL; 1972c0c050c5SMichael Chan } 1973c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 1974c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 1975c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 1976c0c050c5SMichael Chan return -EINVAL; 1977c0c050c5SMichael Chan } 1978c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 1979c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 1980c0c050c5SMichael Chan sizeof(stored_crc))); 1981c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 1982c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 1983c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 1984c0c050c5SMichael Chan (unsigned long)stored_crc, 1985c0c050c5SMichael Chan (unsigned long)calculated_crc); 1986c0c050c5SMichael Chan return -EINVAL; 1987c0c050c5SMichael Chan } 1988c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1989c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 1990d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 1991d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 1992d2d6318cSRob Swindell 1993c0c050c5SMichael Chan return rc; 1994c0c050c5SMichael Chan } 1995c0c050c5SMichael Chan 19965ac67d8bSRob Swindell static int bnxt_flash_microcode(struct net_device *dev, 19975ac67d8bSRob Swindell u16 dir_type, 19985ac67d8bSRob Swindell const u8 *fw_data, 19995ac67d8bSRob Swindell size_t fw_size) 20005ac67d8bSRob Swindell { 20015ac67d8bSRob Swindell struct bnxt_ucode_trailer *trailer; 20025ac67d8bSRob Swindell u32 calculated_crc; 20035ac67d8bSRob Swindell u32 stored_crc; 20045ac67d8bSRob Swindell int rc = 0; 20055ac67d8bSRob Swindell 20065ac67d8bSRob Swindell if (fw_size < sizeof(struct bnxt_ucode_trailer)) { 20075ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode file size: %u\n", 20085ac67d8bSRob Swindell (unsigned int)fw_size); 20095ac67d8bSRob Swindell return -EINVAL; 20105ac67d8bSRob Swindell } 20115ac67d8bSRob Swindell trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size - 20125ac67d8bSRob Swindell sizeof(*trailer))); 20135ac67d8bSRob Swindell if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) { 20145ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer signature: %08X\n", 20155ac67d8bSRob Swindell le32_to_cpu(trailer->sig)); 20165ac67d8bSRob Swindell return -EINVAL; 20175ac67d8bSRob Swindell } 20185ac67d8bSRob Swindell if (le16_to_cpu(trailer->dir_type) != dir_type) { 20195ac67d8bSRob Swindell netdev_err(dev, "Expected microcode type: %d, read: %d\n", 20205ac67d8bSRob Swindell dir_type, le16_to_cpu(trailer->dir_type)); 20215ac67d8bSRob Swindell return -EINVAL; 20225ac67d8bSRob Swindell } 20235ac67d8bSRob Swindell if (le16_to_cpu(trailer->trailer_length) < 20245ac67d8bSRob Swindell sizeof(struct bnxt_ucode_trailer)) { 20255ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer length: %d\n", 20265ac67d8bSRob Swindell le16_to_cpu(trailer->trailer_length)); 20275ac67d8bSRob Swindell return -EINVAL; 20285ac67d8bSRob Swindell } 20295ac67d8bSRob Swindell 20305ac67d8bSRob Swindell /* Confirm the CRC32 checksum of the file: */ 20315ac67d8bSRob Swindell stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 20325ac67d8bSRob Swindell sizeof(stored_crc))); 20335ac67d8bSRob Swindell calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 20345ac67d8bSRob Swindell if (calculated_crc != stored_crc) { 20355ac67d8bSRob Swindell netdev_err(dev, 20365ac67d8bSRob Swindell "CRC32 (%08lX) does not match calculated: %08lX\n", 20375ac67d8bSRob Swindell (unsigned long)stored_crc, 20385ac67d8bSRob Swindell (unsigned long)calculated_crc); 20395ac67d8bSRob Swindell return -EINVAL; 20405ac67d8bSRob Swindell } 20415ac67d8bSRob Swindell rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 20425ac67d8bSRob Swindell 0, 0, fw_data, fw_size); 20435ac67d8bSRob Swindell 20445ac67d8bSRob Swindell return rc; 20455ac67d8bSRob Swindell } 20465ac67d8bSRob Swindell 2047c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 2048c0c050c5SMichael Chan { 2049c0c050c5SMichael Chan switch (dir_type) { 2050c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 2051c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 2052c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 2053c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 2054c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 2055c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 2056c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 205793e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 205893e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 2059c0c050c5SMichael Chan return true; 2060c0c050c5SMichael Chan } 2061c0c050c5SMichael Chan 2062c0c050c5SMichael Chan return false; 2063c0c050c5SMichael Chan } 2064c0c050c5SMichael Chan 20655ac67d8bSRob Swindell static bool bnxt_dir_type_is_other_exec_format(u16 dir_type) 2066c0c050c5SMichael Chan { 2067c0c050c5SMichael Chan switch (dir_type) { 2068c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 2069c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 2070c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 2071c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 2072c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 2073c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 2074c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 2075c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 2076c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 2077c0c050c5SMichael Chan return true; 2078c0c050c5SMichael Chan } 2079c0c050c5SMichael Chan 2080c0c050c5SMichael Chan return false; 2081c0c050c5SMichael Chan } 2082c0c050c5SMichael Chan 2083c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 2084c0c050c5SMichael Chan { 2085c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 20865ac67d8bSRob Swindell bnxt_dir_type_is_other_exec_format(dir_type); 2087c0c050c5SMichael Chan } 2088c0c050c5SMichael Chan 2089c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 2090c0c050c5SMichael Chan u16 dir_type, 2091c0c050c5SMichael Chan const char *filename) 2092c0c050c5SMichael Chan { 2093c0c050c5SMichael Chan const struct firmware *fw; 2094c0c050c5SMichael Chan int rc; 2095c0c050c5SMichael Chan 2096c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 2097c0c050c5SMichael Chan if (rc != 0) { 2098c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 2099c0c050c5SMichael Chan rc, filename); 2100c0c050c5SMichael Chan return rc; 2101c0c050c5SMichael Chan } 2102ba425800SJason Yan if (bnxt_dir_type_is_ape_bin_format(dir_type)) 2103c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 2104ba425800SJason Yan else if (bnxt_dir_type_is_other_exec_format(dir_type)) 21055ac67d8bSRob Swindell rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size); 2106c0c050c5SMichael Chan else 2107c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 2108c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 2109c0c050c5SMichael Chan release_firmware(fw); 2110c0c050c5SMichael Chan return rc; 2111c0c050c5SMichael Chan } 2112c0c050c5SMichael Chan 2113d168f328SVasundhara Volam int bnxt_flash_package_from_file(struct net_device *dev, const char *filename, 2114d168f328SVasundhara Volam u32 install_type) 2115c0c050c5SMichael Chan { 21165ac67d8bSRob Swindell struct bnxt *bp = netdev_priv(dev); 21175ac67d8bSRob Swindell struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr; 21185ac67d8bSRob Swindell struct hwrm_nvm_install_update_input install = {0}; 21195ac67d8bSRob Swindell const struct firmware *fw; 21205ac67d8bSRob Swindell u32 item_len; 212122630e28SEdwin Peer int rc = 0; 21225ac67d8bSRob Swindell u16 index; 21235ac67d8bSRob Swindell 21245ac67d8bSRob Swindell bnxt_hwrm_fw_set_time(bp); 21255ac67d8bSRob Swindell 212695ec1f47SVasundhara Volam rc = bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE, 21275ac67d8bSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 212895ec1f47SVasundhara Volam &index, &item_len, NULL); 212995ec1f47SVasundhara Volam if (rc) { 21305ac67d8bSRob Swindell netdev_err(dev, "PKG update area not created in nvram\n"); 213195ec1f47SVasundhara Volam return rc; 21325ac67d8bSRob Swindell } 21335ac67d8bSRob Swindell 21345ac67d8bSRob Swindell rc = request_firmware(&fw, filename, &dev->dev); 21355ac67d8bSRob Swindell if (rc != 0) { 21365ac67d8bSRob Swindell netdev_err(dev, "PKG error %d requesting file: %s\n", 21375ac67d8bSRob Swindell rc, filename); 21385ac67d8bSRob Swindell return rc; 21395ac67d8bSRob Swindell } 21405ac67d8bSRob Swindell 21415ac67d8bSRob Swindell if (fw->size > item_len) { 21429a005c38SJonathan Lemon netdev_err(dev, "PKG insufficient update area in nvram: %lu\n", 21435ac67d8bSRob Swindell (unsigned long)fw->size); 21445ac67d8bSRob Swindell rc = -EFBIG; 21455ac67d8bSRob Swindell } else { 21465ac67d8bSRob Swindell dma_addr_t dma_handle; 21475ac67d8bSRob Swindell u8 *kmem; 21485ac67d8bSRob Swindell struct hwrm_nvm_modify_input modify = {0}; 21495ac67d8bSRob Swindell 21505ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1); 21515ac67d8bSRob Swindell 21525ac67d8bSRob Swindell modify.dir_idx = cpu_to_le16(index); 21535ac67d8bSRob Swindell modify.len = cpu_to_le32(fw->size); 21545ac67d8bSRob Swindell 21555ac67d8bSRob Swindell kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size, 21565ac67d8bSRob Swindell &dma_handle, GFP_KERNEL); 21575ac67d8bSRob Swindell if (!kmem) { 21585ac67d8bSRob Swindell netdev_err(dev, 21595ac67d8bSRob Swindell "dma_alloc_coherent failure, length = %u\n", 21605ac67d8bSRob Swindell (unsigned int)fw->size); 21615ac67d8bSRob Swindell rc = -ENOMEM; 21625ac67d8bSRob Swindell } else { 21635ac67d8bSRob Swindell memcpy(kmem, fw->data, fw->size); 21645ac67d8bSRob Swindell modify.host_src_addr = cpu_to_le64(dma_handle); 21655ac67d8bSRob Swindell 216622630e28SEdwin Peer rc = hwrm_send_message(bp, &modify, sizeof(modify), 21675ac67d8bSRob Swindell FLASH_PACKAGE_TIMEOUT); 21685ac67d8bSRob Swindell dma_free_coherent(&bp->pdev->dev, fw->size, kmem, 21695ac67d8bSRob Swindell dma_handle); 21705ac67d8bSRob Swindell } 21715ac67d8bSRob Swindell } 21725ac67d8bSRob Swindell release_firmware(fw); 217322630e28SEdwin Peer if (rc) 21747c675421SVasundhara Volam goto err_exit; 21755ac67d8bSRob Swindell 21765ac67d8bSRob Swindell if ((install_type & 0xffff) == 0) 21775ac67d8bSRob Swindell install_type >>= 16; 21785ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1); 21795ac67d8bSRob Swindell install.install_type = cpu_to_le32(install_type); 21805ac67d8bSRob Swindell 2181cb4d1d62SKshitij Soni mutex_lock(&bp->hwrm_cmd_lock); 218222630e28SEdwin Peer rc = _hwrm_send_message(bp, &install, sizeof(install), 21835ac67d8bSRob Swindell INSTALL_PACKAGE_TIMEOUT); 218422630e28SEdwin Peer if (rc) { 2185cb4d1d62SKshitij Soni u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err; 2186cb4d1d62SKshitij Soni 2187dd2ebf34SVasundhara Volam if (resp->error_code && error_code == 2188dd2ebf34SVasundhara Volam NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) { 2189cb4d1d62SKshitij Soni install.flags |= cpu_to_le16( 2190cb4d1d62SKshitij Soni NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG); 219122630e28SEdwin Peer rc = _hwrm_send_message(bp, &install, sizeof(install), 2192cb4d1d62SKshitij Soni INSTALL_PACKAGE_TIMEOUT); 2193dd2ebf34SVasundhara Volam } 219422630e28SEdwin Peer if (rc) 2195cb4d1d62SKshitij Soni goto flash_pkg_exit; 2196cb4d1d62SKshitij Soni } 21975ac67d8bSRob Swindell 21985ac67d8bSRob Swindell if (resp->result) { 21995ac67d8bSRob Swindell netdev_err(dev, "PKG install error = %d, problem_item = %d\n", 22005ac67d8bSRob Swindell (s8)resp->result, (int)resp->problem_item); 2201cb4d1d62SKshitij Soni rc = -ENOPKG; 22025ac67d8bSRob Swindell } 2203cb4d1d62SKshitij Soni flash_pkg_exit: 2204cb4d1d62SKshitij Soni mutex_unlock(&bp->hwrm_cmd_lock); 22057c675421SVasundhara Volam err_exit: 220622630e28SEdwin Peer if (rc == -EACCES) 2207b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 2208cb4d1d62SKshitij Soni return rc; 2209c0c050c5SMichael Chan } 2210c0c050c5SMichael Chan 2211c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 2212c0c050c5SMichael Chan struct ethtool_flash *flash) 2213c0c050c5SMichael Chan { 2214c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 2215c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 2216c0c050c5SMichael Chan return -EINVAL; 2217c0c050c5SMichael Chan } 2218c0c050c5SMichael Chan 22195ac67d8bSRob Swindell if (flash->region == ETHTOOL_FLASH_ALL_REGIONS || 22205ac67d8bSRob Swindell flash->region > 0xffff) 22215ac67d8bSRob Swindell return bnxt_flash_package_from_file(dev, flash->data, 22225ac67d8bSRob Swindell flash->region); 2223c0c050c5SMichael Chan 2224c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 2225c0c050c5SMichael Chan } 2226c0c050c5SMichael Chan 2227c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 2228c0c050c5SMichael Chan { 2229c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2230c0c050c5SMichael Chan int rc; 2231c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 2232c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 2233c0c050c5SMichael Chan 2234c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 2235c0c050c5SMichael Chan 2236c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2237c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2238c0c050c5SMichael Chan if (!rc) { 2239c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 2240c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 2241c0c050c5SMichael Chan } 2242c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2243c0c050c5SMichael Chan return rc; 2244c0c050c5SMichael Chan } 2245c0c050c5SMichael Chan 2246c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 2247c0c050c5SMichael Chan { 22484cebbacaSMichael Chan struct bnxt *bp = netdev_priv(dev); 22494cebbacaSMichael Chan 22504cebbacaSMichael Chan if (BNXT_VF(bp)) 22514cebbacaSMichael Chan return 0; 22524cebbacaSMichael Chan 2253c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 2254c0c050c5SMichael Chan * passed via the ethtool command-line utility. 2255c0c050c5SMichael Chan */ 2256c0c050c5SMichael Chan return -1; 2257c0c050c5SMichael Chan } 2258c0c050c5SMichael Chan 2259c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 2260c0c050c5SMichael Chan { 2261c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2262c0c050c5SMichael Chan int rc; 2263c0c050c5SMichael Chan u32 dir_entries; 2264c0c050c5SMichael Chan u32 entry_length; 2265c0c050c5SMichael Chan u8 *buf; 2266c0c050c5SMichael Chan size_t buflen; 2267c0c050c5SMichael Chan dma_addr_t dma_handle; 2268c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 2269c0c050c5SMichael Chan 2270c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 2271c0c050c5SMichael Chan if (rc != 0) 2272c0c050c5SMichael Chan return rc; 2273c0c050c5SMichael Chan 2274c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 2275c0c050c5SMichael Chan if (len < 2) 2276c0c050c5SMichael Chan return -EINVAL; 2277c0c050c5SMichael Chan 2278c0c050c5SMichael Chan *data++ = dir_entries; 2279c0c050c5SMichael Chan *data++ = entry_length; 2280c0c050c5SMichael Chan len -= 2; 2281c0c050c5SMichael Chan memset(data, 0xff, len); 2282c0c050c5SMichael Chan 2283c0c050c5SMichael Chan buflen = dir_entries * entry_length; 2284c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 2285c0c050c5SMichael Chan GFP_KERNEL); 2286c0c050c5SMichael Chan if (!buf) { 2287c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2288c0c050c5SMichael Chan (unsigned)buflen); 2289c0c050c5SMichael Chan return -ENOMEM; 2290c0c050c5SMichael Chan } 2291c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 2292c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2293c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2294c0c050c5SMichael Chan if (rc == 0) 2295c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 2296c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 2297c0c050c5SMichael Chan return rc; 2298c0c050c5SMichael Chan } 2299c0c050c5SMichael Chan 2300c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 2301c0c050c5SMichael Chan u32 length, u8 *data) 2302c0c050c5SMichael Chan { 2303c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2304c0c050c5SMichael Chan int rc; 2305c0c050c5SMichael Chan u8 *buf; 2306c0c050c5SMichael Chan dma_addr_t dma_handle; 2307c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 2308c0c050c5SMichael Chan 2309e0ad8fc5SMichael Chan if (!length) 2310e0ad8fc5SMichael Chan return -EINVAL; 2311e0ad8fc5SMichael Chan 2312c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 2313c0c050c5SMichael Chan GFP_KERNEL); 2314c0c050c5SMichael Chan if (!buf) { 2315c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2316c0c050c5SMichael Chan (unsigned)length); 2317c0c050c5SMichael Chan return -ENOMEM; 2318c0c050c5SMichael Chan } 2319c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 2320c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2321c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2322c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 2323c0c050c5SMichael Chan req.len = cpu_to_le32(length); 2324c0c050c5SMichael Chan 2325c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2326c0c050c5SMichael Chan if (rc == 0) 2327c0c050c5SMichael Chan memcpy(data, buf, length); 2328c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 2329c0c050c5SMichael Chan return rc; 2330c0c050c5SMichael Chan } 2331c0c050c5SMichael Chan 23323ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 23333ebf6f0aSRob Swindell u16 ext, u16 *index, u32 *item_length, 23343ebf6f0aSRob Swindell u32 *data_length) 23353ebf6f0aSRob Swindell { 23363ebf6f0aSRob Swindell struct bnxt *bp = netdev_priv(dev); 23373ebf6f0aSRob Swindell int rc; 23383ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_input req = {0}; 23393ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr; 23403ebf6f0aSRob Swindell 23413ebf6f0aSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1); 23423ebf6f0aSRob Swindell req.enables = 0; 23433ebf6f0aSRob Swindell req.dir_idx = 0; 23443ebf6f0aSRob Swindell req.dir_type = cpu_to_le16(type); 23453ebf6f0aSRob Swindell req.dir_ordinal = cpu_to_le16(ordinal); 23463ebf6f0aSRob Swindell req.dir_ext = cpu_to_le16(ext); 23473ebf6f0aSRob Swindell req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ; 2348cc72f3b1SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2349cc72f3b1SMichael Chan rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 23503ebf6f0aSRob Swindell if (rc == 0) { 23513ebf6f0aSRob Swindell if (index) 23523ebf6f0aSRob Swindell *index = le16_to_cpu(output->dir_idx); 23533ebf6f0aSRob Swindell if (item_length) 23543ebf6f0aSRob Swindell *item_length = le32_to_cpu(output->dir_item_length); 23553ebf6f0aSRob Swindell if (data_length) 23563ebf6f0aSRob Swindell *data_length = le32_to_cpu(output->dir_data_length); 23573ebf6f0aSRob Swindell } 2358cc72f3b1SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 23593ebf6f0aSRob Swindell return rc; 23603ebf6f0aSRob Swindell } 23613ebf6f0aSRob Swindell 23623ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen) 23633ebf6f0aSRob Swindell { 23643ebf6f0aSRob Swindell char *retval = NULL; 23653ebf6f0aSRob Swindell char *p; 23663ebf6f0aSRob Swindell char *value; 23673ebf6f0aSRob Swindell int field = 0; 23683ebf6f0aSRob Swindell 23693ebf6f0aSRob Swindell if (datalen < 1) 23703ebf6f0aSRob Swindell return NULL; 23713ebf6f0aSRob Swindell /* null-terminate the log data (removing last '\n'): */ 23723ebf6f0aSRob Swindell data[datalen - 1] = 0; 23733ebf6f0aSRob Swindell for (p = data; *p != 0; p++) { 23743ebf6f0aSRob Swindell field = 0; 23753ebf6f0aSRob Swindell retval = NULL; 23763ebf6f0aSRob Swindell while (*p != 0 && *p != '\n') { 23773ebf6f0aSRob Swindell value = p; 23783ebf6f0aSRob Swindell while (*p != 0 && *p != '\t' && *p != '\n') 23793ebf6f0aSRob Swindell p++; 23803ebf6f0aSRob Swindell if (field == desired_field) 23813ebf6f0aSRob Swindell retval = value; 23823ebf6f0aSRob Swindell if (*p != '\t') 23833ebf6f0aSRob Swindell break; 23843ebf6f0aSRob Swindell *p = 0; 23853ebf6f0aSRob Swindell field++; 23863ebf6f0aSRob Swindell p++; 23873ebf6f0aSRob Swindell } 23883ebf6f0aSRob Swindell if (*p == 0) 23893ebf6f0aSRob Swindell break; 23903ebf6f0aSRob Swindell *p = 0; 23913ebf6f0aSRob Swindell } 23923ebf6f0aSRob Swindell return retval; 23933ebf6f0aSRob Swindell } 23943ebf6f0aSRob Swindell 2395a60faa60SVasundhara Volam static void bnxt_get_pkgver(struct net_device *dev) 23963ebf6f0aSRob Swindell { 2397a60faa60SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 23983ebf6f0aSRob Swindell u16 index = 0; 2399a60faa60SVasundhara Volam char *pkgver; 2400a60faa60SVasundhara Volam u32 pkglen; 2401a60faa60SVasundhara Volam u8 *pkgbuf; 2402a60faa60SVasundhara Volam int len; 24033ebf6f0aSRob Swindell 24043ebf6f0aSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG, 24053ebf6f0aSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 2406a60faa60SVasundhara Volam &index, NULL, &pkglen) != 0) 2407a60faa60SVasundhara Volam return; 24083ebf6f0aSRob Swindell 2409a60faa60SVasundhara Volam pkgbuf = kzalloc(pkglen, GFP_KERNEL); 2410a60faa60SVasundhara Volam if (!pkgbuf) { 2411a60faa60SVasundhara Volam dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n", 2412a60faa60SVasundhara Volam pkglen); 2413a60faa60SVasundhara Volam return; 2414a60faa60SVasundhara Volam } 24153ebf6f0aSRob Swindell 2416a60faa60SVasundhara Volam if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf)) 2417a60faa60SVasundhara Volam goto err; 2418a60faa60SVasundhara Volam 2419a60faa60SVasundhara Volam pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf, 2420a60faa60SVasundhara Volam pkglen); 2421a60faa60SVasundhara Volam if (pkgver && *pkgver != 0 && isdigit(*pkgver)) { 2422a60faa60SVasundhara Volam len = strlen(bp->fw_ver_str); 2423a60faa60SVasundhara Volam snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1, 2424a60faa60SVasundhara Volam "/pkg %s", pkgver); 2425a60faa60SVasundhara Volam } 2426a60faa60SVasundhara Volam err: 2427a60faa60SVasundhara Volam kfree(pkgbuf); 24283ebf6f0aSRob Swindell } 24293ebf6f0aSRob Swindell 2430c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 2431c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2432c0c050c5SMichael Chan u8 *data) 2433c0c050c5SMichael Chan { 2434c0c050c5SMichael Chan u32 index; 2435c0c050c5SMichael Chan u32 offset; 2436c0c050c5SMichael Chan 2437c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 2438c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 2439c0c050c5SMichael Chan 2440c0c050c5SMichael Chan index = eeprom->offset >> 24; 2441c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 2442c0c050c5SMichael Chan 2443c0c050c5SMichael Chan if (index == 0) { 2444c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 2445c0c050c5SMichael Chan return -EINVAL; 2446c0c050c5SMichael Chan } 2447c0c050c5SMichael Chan 2448c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 2449c0c050c5SMichael Chan } 2450c0c050c5SMichael Chan 2451c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 2452c0c050c5SMichael Chan { 2453c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2454c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 2455c0c050c5SMichael Chan 2456c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 2457c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2458c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2459c0c050c5SMichael Chan } 2460c0c050c5SMichael Chan 2461c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 2462c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2463c0c050c5SMichael Chan u8 *data) 2464c0c050c5SMichael Chan { 2465c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2466c0c050c5SMichael Chan u8 index, dir_op; 2467c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 2468c0c050c5SMichael Chan 2469c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 2470c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 2471c0c050c5SMichael Chan return -EINVAL; 2472c0c050c5SMichael Chan } 2473c0c050c5SMichael Chan 2474c0c050c5SMichael Chan type = eeprom->magic >> 16; 2475c0c050c5SMichael Chan 2476c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 2477c0c050c5SMichael Chan index = eeprom->magic & 0xff; 2478c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 2479c0c050c5SMichael Chan if (index == 0) 2480c0c050c5SMichael Chan return -EINVAL; 2481c0c050c5SMichael Chan switch (dir_op) { 2482c0c050c5SMichael Chan case 0x0e: /* erase */ 2483c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 2484c0c050c5SMichael Chan return -EINVAL; 2485c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 2486c0c050c5SMichael Chan default: 2487c0c050c5SMichael Chan return -EINVAL; 2488c0c050c5SMichael Chan } 2489c0c050c5SMichael Chan } 2490c0c050c5SMichael Chan 2491c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 2492ba425800SJason Yan if (bnxt_dir_type_is_executable(type)) 24935ac67d8bSRob Swindell return -EOPNOTSUPP; 2494c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 2495c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 2496c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 2497c0c050c5SMichael Chan 2498c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 2499c0c050c5SMichael Chan eeprom->len); 2500c0c050c5SMichael Chan } 2501c0c050c5SMichael Chan 250272b34f04SMichael Chan static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata) 250372b34f04SMichael Chan { 250472b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 250572b34f04SMichael Chan struct ethtool_eee *eee = &bp->eee; 250672b34f04SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 250772b34f04SMichael Chan u32 advertising = 250872b34f04SMichael Chan _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); 250972b34f04SMichael Chan int rc = 0; 251072b34f04SMichael Chan 2511c7e457f4SMichael Chan if (!BNXT_PHY_CFG_ABLE(bp)) 251275362a3fSMichael Chan return -EOPNOTSUPP; 251372b34f04SMichael Chan 251472b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 251572b34f04SMichael Chan return -EOPNOTSUPP; 251672b34f04SMichael Chan 251772b34f04SMichael Chan if (!edata->eee_enabled) 251872b34f04SMichael Chan goto eee_ok; 251972b34f04SMichael Chan 252072b34f04SMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { 252172b34f04SMichael Chan netdev_warn(dev, "EEE requires autoneg\n"); 252272b34f04SMichael Chan return -EINVAL; 252372b34f04SMichael Chan } 252472b34f04SMichael Chan if (edata->tx_lpi_enabled) { 252572b34f04SMichael Chan if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi || 252672b34f04SMichael Chan edata->tx_lpi_timer < bp->lpi_tmr_lo)) { 252772b34f04SMichael Chan netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n", 252872b34f04SMichael Chan bp->lpi_tmr_lo, bp->lpi_tmr_hi); 252972b34f04SMichael Chan return -EINVAL; 253072b34f04SMichael Chan } else if (!bp->lpi_tmr_hi) { 253172b34f04SMichael Chan edata->tx_lpi_timer = eee->tx_lpi_timer; 253272b34f04SMichael Chan } 253372b34f04SMichael Chan } 253472b34f04SMichael Chan if (!edata->advertised) { 253572b34f04SMichael Chan edata->advertised = advertising & eee->supported; 253672b34f04SMichael Chan } else if (edata->advertised & ~advertising) { 253772b34f04SMichael Chan netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", 253872b34f04SMichael Chan edata->advertised, advertising); 253972b34f04SMichael Chan return -EINVAL; 254072b34f04SMichael Chan } 254172b34f04SMichael Chan 254272b34f04SMichael Chan eee->advertised = edata->advertised; 254372b34f04SMichael Chan eee->tx_lpi_enabled = edata->tx_lpi_enabled; 254472b34f04SMichael Chan eee->tx_lpi_timer = edata->tx_lpi_timer; 254572b34f04SMichael Chan eee_ok: 254672b34f04SMichael Chan eee->eee_enabled = edata->eee_enabled; 254772b34f04SMichael Chan 254872b34f04SMichael Chan if (netif_running(dev)) 254972b34f04SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, false, true); 255072b34f04SMichael Chan 255172b34f04SMichael Chan return rc; 255272b34f04SMichael Chan } 255372b34f04SMichael Chan 255472b34f04SMichael Chan static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata) 255572b34f04SMichael Chan { 255672b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 255772b34f04SMichael Chan 255872b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 255972b34f04SMichael Chan return -EOPNOTSUPP; 256072b34f04SMichael Chan 256172b34f04SMichael Chan *edata = bp->eee; 256272b34f04SMichael Chan if (!bp->eee.eee_enabled) { 256372b34f04SMichael Chan /* Preserve tx_lpi_timer so that the last value will be used 256472b34f04SMichael Chan * by default when it is re-enabled. 256572b34f04SMichael Chan */ 256672b34f04SMichael Chan edata->advertised = 0; 256772b34f04SMichael Chan edata->tx_lpi_enabled = 0; 256872b34f04SMichael Chan } 256972b34f04SMichael Chan 257072b34f04SMichael Chan if (!bp->eee.eee_active) 257172b34f04SMichael Chan edata->lp_advertised = 0; 257272b34f04SMichael Chan 257372b34f04SMichael Chan return 0; 257472b34f04SMichael Chan } 257572b34f04SMichael Chan 257642ee18feSAjit Khaparde static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr, 257742ee18feSAjit Khaparde u16 page_number, u16 start_addr, 257842ee18feSAjit Khaparde u16 data_length, u8 *buf) 257942ee18feSAjit Khaparde { 258042ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_input req = {0}; 258142ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr; 258242ee18feSAjit Khaparde int rc, byte_offset = 0; 258342ee18feSAjit Khaparde 258442ee18feSAjit Khaparde bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1); 258542ee18feSAjit Khaparde req.i2c_slave_addr = i2c_addr; 258642ee18feSAjit Khaparde req.page_number = cpu_to_le16(page_number); 258742ee18feSAjit Khaparde req.port_id = cpu_to_le16(bp->pf.port_id); 258842ee18feSAjit Khaparde do { 258942ee18feSAjit Khaparde u16 xfer_size; 259042ee18feSAjit Khaparde 259142ee18feSAjit Khaparde xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE); 259242ee18feSAjit Khaparde data_length -= xfer_size; 259342ee18feSAjit Khaparde req.page_offset = cpu_to_le16(start_addr + byte_offset); 259442ee18feSAjit Khaparde req.data_length = xfer_size; 259542ee18feSAjit Khaparde req.enables = cpu_to_le32(start_addr + byte_offset ? 259642ee18feSAjit Khaparde PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0); 259742ee18feSAjit Khaparde mutex_lock(&bp->hwrm_cmd_lock); 259842ee18feSAjit Khaparde rc = _hwrm_send_message(bp, &req, sizeof(req), 259942ee18feSAjit Khaparde HWRM_CMD_TIMEOUT); 260042ee18feSAjit Khaparde if (!rc) 260142ee18feSAjit Khaparde memcpy(buf + byte_offset, output->data, xfer_size); 260242ee18feSAjit Khaparde mutex_unlock(&bp->hwrm_cmd_lock); 260342ee18feSAjit Khaparde byte_offset += xfer_size; 260442ee18feSAjit Khaparde } while (!rc && data_length > 0); 260542ee18feSAjit Khaparde 260642ee18feSAjit Khaparde return rc; 260742ee18feSAjit Khaparde } 260842ee18feSAjit Khaparde 260942ee18feSAjit Khaparde static int bnxt_get_module_info(struct net_device *dev, 261042ee18feSAjit Khaparde struct ethtool_modinfo *modinfo) 261142ee18feSAjit Khaparde { 26127328a23cSVasundhara Volam u8 data[SFF_DIAG_SUPPORT_OFFSET + 1]; 261342ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 261442ee18feSAjit Khaparde int rc; 261542ee18feSAjit Khaparde 261642ee18feSAjit Khaparde /* No point in going further if phy status indicates 261742ee18feSAjit Khaparde * module is not inserted or if it is powered down or 261842ee18feSAjit Khaparde * if it is of type 10GBase-T 261942ee18feSAjit Khaparde */ 262042ee18feSAjit Khaparde if (bp->link_info.module_status > 262142ee18feSAjit Khaparde PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG) 262242ee18feSAjit Khaparde return -EOPNOTSUPP; 262342ee18feSAjit Khaparde 262442ee18feSAjit Khaparde /* This feature is not supported in older firmware versions */ 262542ee18feSAjit Khaparde if (bp->hwrm_spec_code < 0x10202) 262642ee18feSAjit Khaparde return -EOPNOTSUPP; 262742ee18feSAjit Khaparde 26287328a23cSVasundhara Volam rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0, 26297328a23cSVasundhara Volam SFF_DIAG_SUPPORT_OFFSET + 1, 26307328a23cSVasundhara Volam data); 263142ee18feSAjit Khaparde if (!rc) { 26327328a23cSVasundhara Volam u8 module_id = data[0]; 26337328a23cSVasundhara Volam u8 diag_supported = data[SFF_DIAG_SUPPORT_OFFSET]; 263442ee18feSAjit Khaparde 263542ee18feSAjit Khaparde switch (module_id) { 263642ee18feSAjit Khaparde case SFF_MODULE_ID_SFP: 263742ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8472; 263842ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 26397328a23cSVasundhara Volam if (!diag_supported) 26407328a23cSVasundhara Volam modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 264142ee18feSAjit Khaparde break; 264242ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP: 264342ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP_PLUS: 264442ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8436; 264542ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 264642ee18feSAjit Khaparde break; 264742ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP28: 264842ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8636; 264942ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 265042ee18feSAjit Khaparde break; 265142ee18feSAjit Khaparde default: 265242ee18feSAjit Khaparde rc = -EOPNOTSUPP; 265342ee18feSAjit Khaparde break; 265442ee18feSAjit Khaparde } 265542ee18feSAjit Khaparde } 265642ee18feSAjit Khaparde return rc; 265742ee18feSAjit Khaparde } 265842ee18feSAjit Khaparde 265942ee18feSAjit Khaparde static int bnxt_get_module_eeprom(struct net_device *dev, 266042ee18feSAjit Khaparde struct ethtool_eeprom *eeprom, 266142ee18feSAjit Khaparde u8 *data) 266242ee18feSAjit Khaparde { 266342ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 266442ee18feSAjit Khaparde u16 start = eeprom->offset, length = eeprom->len; 2665f3ea3119SColin Ian King int rc = 0; 266642ee18feSAjit Khaparde 266742ee18feSAjit Khaparde memset(data, 0, eeprom->len); 266842ee18feSAjit Khaparde 266942ee18feSAjit Khaparde /* Read A0 portion of the EEPROM */ 267042ee18feSAjit Khaparde if (start < ETH_MODULE_SFF_8436_LEN) { 267142ee18feSAjit Khaparde if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN) 267242ee18feSAjit Khaparde length = ETH_MODULE_SFF_8436_LEN - start; 267342ee18feSAjit Khaparde rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 267442ee18feSAjit Khaparde start, length, data); 267542ee18feSAjit Khaparde if (rc) 267642ee18feSAjit Khaparde return rc; 267742ee18feSAjit Khaparde start += length; 267842ee18feSAjit Khaparde data += length; 267942ee18feSAjit Khaparde length = eeprom->len - length; 268042ee18feSAjit Khaparde } 268142ee18feSAjit Khaparde 268242ee18feSAjit Khaparde /* Read A2 portion of the EEPROM */ 268342ee18feSAjit Khaparde if (length) { 268442ee18feSAjit Khaparde start -= ETH_MODULE_SFF_8436_LEN; 2685dea521a2SChristophe JAILLET rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1, 2686dea521a2SChristophe JAILLET start, length, data); 268742ee18feSAjit Khaparde } 268842ee18feSAjit Khaparde return rc; 268942ee18feSAjit Khaparde } 269042ee18feSAjit Khaparde 2691ae8e98a6SDeepak Khungar static int bnxt_nway_reset(struct net_device *dev) 2692ae8e98a6SDeepak Khungar { 2693ae8e98a6SDeepak Khungar int rc = 0; 2694ae8e98a6SDeepak Khungar 2695ae8e98a6SDeepak Khungar struct bnxt *bp = netdev_priv(dev); 2696ae8e98a6SDeepak Khungar struct bnxt_link_info *link_info = &bp->link_info; 2697ae8e98a6SDeepak Khungar 2698c7e457f4SMichael Chan if (!BNXT_PHY_CFG_ABLE(bp)) 2699ae8e98a6SDeepak Khungar return -EOPNOTSUPP; 2700ae8e98a6SDeepak Khungar 2701ae8e98a6SDeepak Khungar if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 2702ae8e98a6SDeepak Khungar return -EINVAL; 2703ae8e98a6SDeepak Khungar 2704ae8e98a6SDeepak Khungar if (netif_running(dev)) 2705ae8e98a6SDeepak Khungar rc = bnxt_hwrm_set_link_setting(bp, true, false); 2706ae8e98a6SDeepak Khungar 2707ae8e98a6SDeepak Khungar return rc; 2708ae8e98a6SDeepak Khungar } 2709ae8e98a6SDeepak Khungar 27105ad2cbeeSMichael Chan static int bnxt_set_phys_id(struct net_device *dev, 27115ad2cbeeSMichael Chan enum ethtool_phys_id_state state) 27125ad2cbeeSMichael Chan { 27135ad2cbeeSMichael Chan struct hwrm_port_led_cfg_input req = {0}; 27145ad2cbeeSMichael Chan struct bnxt *bp = netdev_priv(dev); 27155ad2cbeeSMichael Chan struct bnxt_pf_info *pf = &bp->pf; 27165ad2cbeeSMichael Chan struct bnxt_led_cfg *led_cfg; 27175ad2cbeeSMichael Chan u8 led_state; 27185ad2cbeeSMichael Chan __le16 duration; 27199f90445cSVasundhara Volam int i; 27205ad2cbeeSMichael Chan 27215ad2cbeeSMichael Chan if (!bp->num_leds || BNXT_VF(bp)) 27225ad2cbeeSMichael Chan return -EOPNOTSUPP; 27235ad2cbeeSMichael Chan 27245ad2cbeeSMichael Chan if (state == ETHTOOL_ID_ACTIVE) { 27255ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT; 27265ad2cbeeSMichael Chan duration = cpu_to_le16(500); 27275ad2cbeeSMichael Chan } else if (state == ETHTOOL_ID_INACTIVE) { 27285ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT; 27295ad2cbeeSMichael Chan duration = cpu_to_le16(0); 27305ad2cbeeSMichael Chan } else { 27315ad2cbeeSMichael Chan return -EINVAL; 27325ad2cbeeSMichael Chan } 27335ad2cbeeSMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1); 27345ad2cbeeSMichael Chan req.port_id = cpu_to_le16(pf->port_id); 27355ad2cbeeSMichael Chan req.num_leds = bp->num_leds; 27365ad2cbeeSMichael Chan led_cfg = (struct bnxt_led_cfg *)&req.led0_id; 27375ad2cbeeSMichael Chan for (i = 0; i < bp->num_leds; i++, led_cfg++) { 27385ad2cbeeSMichael Chan req.enables |= BNXT_LED_DFLT_ENABLES(i); 27395ad2cbeeSMichael Chan led_cfg->led_id = bp->leds[i].led_id; 27405ad2cbeeSMichael Chan led_cfg->led_state = led_state; 27415ad2cbeeSMichael Chan led_cfg->led_blink_on = duration; 27425ad2cbeeSMichael Chan led_cfg->led_blink_off = duration; 27435ad2cbeeSMichael Chan led_cfg->led_group_id = bp->leds[i].led_group_id; 27445ad2cbeeSMichael Chan } 27459f90445cSVasundhara Volam return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 27465ad2cbeeSMichael Chan } 27475ad2cbeeSMichael Chan 274867fea463SMichael Chan static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring) 274967fea463SMichael Chan { 275067fea463SMichael Chan struct hwrm_selftest_irq_input req = {0}; 275167fea463SMichael Chan 275267fea463SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1); 275367fea463SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 275467fea463SMichael Chan } 275567fea463SMichael Chan 275667fea463SMichael Chan static int bnxt_test_irq(struct bnxt *bp) 275767fea463SMichael Chan { 275867fea463SMichael Chan int i; 275967fea463SMichael Chan 276067fea463SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 276167fea463SMichael Chan u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id; 276267fea463SMichael Chan int rc; 276367fea463SMichael Chan 276467fea463SMichael Chan rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring); 276567fea463SMichael Chan if (rc) 276667fea463SMichael Chan return rc; 276767fea463SMichael Chan } 276867fea463SMichael Chan return 0; 276967fea463SMichael Chan } 277067fea463SMichael Chan 2771f7dc1ea6SMichael Chan static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable) 2772f7dc1ea6SMichael Chan { 2773f7dc1ea6SMichael Chan struct hwrm_port_mac_cfg_input req = {0}; 2774f7dc1ea6SMichael Chan 2775f7dc1ea6SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1); 2776f7dc1ea6SMichael Chan 2777f7dc1ea6SMichael Chan req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK); 2778f7dc1ea6SMichael Chan if (enable) 2779f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL; 2780f7dc1ea6SMichael Chan else 2781f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE; 2782f7dc1ea6SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2783f7dc1ea6SMichael Chan } 2784f7dc1ea6SMichael Chan 278556d37462SVasundhara Volam static int bnxt_query_force_speeds(struct bnxt *bp, u16 *force_speeds) 278656d37462SVasundhara Volam { 278756d37462SVasundhara Volam struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; 278856d37462SVasundhara Volam struct hwrm_port_phy_qcaps_input req = {0}; 278956d37462SVasundhara Volam int rc; 279056d37462SVasundhara Volam 279156d37462SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); 279256d37462SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 279356d37462SVasundhara Volam rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 279456d37462SVasundhara Volam if (!rc) 279556d37462SVasundhara Volam *force_speeds = le16_to_cpu(resp->supported_speeds_force_mode); 279656d37462SVasundhara Volam 279756d37462SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 279856d37462SVasundhara Volam return rc; 279956d37462SVasundhara Volam } 280056d37462SVasundhara Volam 280191725d89SMichael Chan static int bnxt_disable_an_for_lpbk(struct bnxt *bp, 280291725d89SMichael Chan struct hwrm_port_phy_cfg_input *req) 280391725d89SMichael Chan { 280491725d89SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 280556d37462SVasundhara Volam u16 fw_advertising; 280691725d89SMichael Chan u16 fw_speed; 280791725d89SMichael Chan int rc; 280891725d89SMichael Chan 28098a60efd1SMichael Chan if (!link_info->autoneg || 28108a60efd1SMichael Chan (bp->test_info->flags & BNXT_TEST_FL_AN_PHY_LPBK)) 281191725d89SMichael Chan return 0; 281291725d89SMichael Chan 281356d37462SVasundhara Volam rc = bnxt_query_force_speeds(bp, &fw_advertising); 281456d37462SVasundhara Volam if (rc) 281556d37462SVasundhara Volam return rc; 281656d37462SVasundhara Volam 281791725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB; 281883d8f5e9SMichael Chan if (bp->link_info.link_up) 281991725d89SMichael Chan fw_speed = bp->link_info.link_speed; 282091725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB) 282191725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB; 282291725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB) 282391725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB; 282491725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB) 282591725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB; 282691725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB) 282791725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB; 282891725d89SMichael Chan 282991725d89SMichael Chan req->force_link_speed = cpu_to_le16(fw_speed); 283091725d89SMichael Chan req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE | 283191725d89SMichael Chan PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); 283291725d89SMichael Chan rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT); 283391725d89SMichael Chan req->flags = 0; 283491725d89SMichael Chan req->force_link_speed = cpu_to_le16(0); 283591725d89SMichael Chan return rc; 283691725d89SMichael Chan } 283791725d89SMichael Chan 283855fd0cf3SMichael Chan static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable, bool ext) 283991725d89SMichael Chan { 284091725d89SMichael Chan struct hwrm_port_phy_cfg_input req = {0}; 284191725d89SMichael Chan 284291725d89SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); 284391725d89SMichael Chan 284491725d89SMichael Chan if (enable) { 284591725d89SMichael Chan bnxt_disable_an_for_lpbk(bp, &req); 284655fd0cf3SMichael Chan if (ext) 284755fd0cf3SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_EXTERNAL; 284855fd0cf3SMichael Chan else 284991725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL; 285091725d89SMichael Chan } else { 285191725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE; 285291725d89SMichael Chan } 285391725d89SMichael Chan req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK); 285491725d89SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 285591725d89SMichael Chan } 285691725d89SMichael Chan 2857e44758b7SMichael Chan static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2858f7dc1ea6SMichael Chan u32 raw_cons, int pkt_size) 2859f7dc1ea6SMichael Chan { 2860e44758b7SMichael Chan struct bnxt_napi *bnapi = cpr->bnapi; 2861e44758b7SMichael Chan struct bnxt_rx_ring_info *rxr; 2862f7dc1ea6SMichael Chan struct bnxt_sw_rx_bd *rx_buf; 2863f7dc1ea6SMichael Chan struct rx_cmp *rxcmp; 2864f7dc1ea6SMichael Chan u16 cp_cons, cons; 2865f7dc1ea6SMichael Chan u8 *data; 2866f7dc1ea6SMichael Chan u32 len; 2867f7dc1ea6SMichael Chan int i; 2868f7dc1ea6SMichael Chan 2869e44758b7SMichael Chan rxr = bnapi->rx_ring; 2870f7dc1ea6SMichael Chan cp_cons = RING_CMP(raw_cons); 2871f7dc1ea6SMichael Chan rxcmp = (struct rx_cmp *) 2872f7dc1ea6SMichael Chan &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; 2873f7dc1ea6SMichael Chan cons = rxcmp->rx_cmp_opaque; 2874f7dc1ea6SMichael Chan rx_buf = &rxr->rx_buf_ring[cons]; 2875f7dc1ea6SMichael Chan data = rx_buf->data_ptr; 2876f7dc1ea6SMichael Chan len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT; 2877f7dc1ea6SMichael Chan if (len != pkt_size) 2878f7dc1ea6SMichael Chan return -EIO; 2879f7dc1ea6SMichael Chan i = ETH_ALEN; 2880f7dc1ea6SMichael Chan if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr)) 2881f7dc1ea6SMichael Chan return -EIO; 2882f7dc1ea6SMichael Chan i += ETH_ALEN; 2883f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) { 2884f7dc1ea6SMichael Chan if (data[i] != (u8)(i & 0xff)) 2885f7dc1ea6SMichael Chan return -EIO; 2886f7dc1ea6SMichael Chan } 2887f7dc1ea6SMichael Chan return 0; 2888f7dc1ea6SMichael Chan } 2889f7dc1ea6SMichael Chan 2890e44758b7SMichael Chan static int bnxt_poll_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2891e44758b7SMichael Chan int pkt_size) 2892f7dc1ea6SMichael Chan { 2893f7dc1ea6SMichael Chan struct tx_cmp *txcmp; 2894f7dc1ea6SMichael Chan int rc = -EIO; 2895f7dc1ea6SMichael Chan u32 raw_cons; 2896f7dc1ea6SMichael Chan u32 cons; 2897f7dc1ea6SMichael Chan int i; 2898f7dc1ea6SMichael Chan 2899f7dc1ea6SMichael Chan raw_cons = cpr->cp_raw_cons; 2900f7dc1ea6SMichael Chan for (i = 0; i < 200; i++) { 2901f7dc1ea6SMichael Chan cons = RING_CMP(raw_cons); 2902f7dc1ea6SMichael Chan txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; 2903f7dc1ea6SMichael Chan 2904f7dc1ea6SMichael Chan if (!TX_CMP_VALID(txcmp, raw_cons)) { 2905f7dc1ea6SMichael Chan udelay(5); 2906f7dc1ea6SMichael Chan continue; 2907f7dc1ea6SMichael Chan } 2908f7dc1ea6SMichael Chan 2909f7dc1ea6SMichael Chan /* The valid test of the entry must be done first before 2910f7dc1ea6SMichael Chan * reading any further. 2911f7dc1ea6SMichael Chan */ 2912f7dc1ea6SMichael Chan dma_rmb(); 2913f7dc1ea6SMichael Chan if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) { 2914e44758b7SMichael Chan rc = bnxt_rx_loopback(bp, cpr, raw_cons, pkt_size); 2915f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2916f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2917f7dc1ea6SMichael Chan break; 2918f7dc1ea6SMichael Chan } 2919f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2920f7dc1ea6SMichael Chan } 2921f7dc1ea6SMichael Chan cpr->cp_raw_cons = raw_cons; 2922f7dc1ea6SMichael Chan return rc; 2923f7dc1ea6SMichael Chan } 2924f7dc1ea6SMichael Chan 2925f7dc1ea6SMichael Chan static int bnxt_run_loopback(struct bnxt *bp) 2926f7dc1ea6SMichael Chan { 2927f7dc1ea6SMichael Chan struct bnxt_tx_ring_info *txr = &bp->tx_ring[0]; 292884404d5fSMichael Chan struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0]; 2929e44758b7SMichael Chan struct bnxt_cp_ring_info *cpr; 2930f7dc1ea6SMichael Chan int pkt_size, i = 0; 2931f7dc1ea6SMichael Chan struct sk_buff *skb; 2932f7dc1ea6SMichael Chan dma_addr_t map; 2933f7dc1ea6SMichael Chan u8 *data; 2934f7dc1ea6SMichael Chan int rc; 2935f7dc1ea6SMichael Chan 293684404d5fSMichael Chan cpr = &rxr->bnapi->cp_ring; 293784404d5fSMichael Chan if (bp->flags & BNXT_FLAG_CHIP_P5) 293884404d5fSMichael Chan cpr = cpr->cp_ring_arr[BNXT_RX_HDL]; 2939f7dc1ea6SMichael Chan pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh); 2940f7dc1ea6SMichael Chan skb = netdev_alloc_skb(bp->dev, pkt_size); 2941f7dc1ea6SMichael Chan if (!skb) 2942f7dc1ea6SMichael Chan return -ENOMEM; 2943f7dc1ea6SMichael Chan data = skb_put(skb, pkt_size); 2944f7dc1ea6SMichael Chan eth_broadcast_addr(data); 2945f7dc1ea6SMichael Chan i += ETH_ALEN; 2946f7dc1ea6SMichael Chan ether_addr_copy(&data[i], bp->dev->dev_addr); 2947f7dc1ea6SMichael Chan i += ETH_ALEN; 2948f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) 2949f7dc1ea6SMichael Chan data[i] = (u8)(i & 0xff); 2950f7dc1ea6SMichael Chan 2951f7dc1ea6SMichael Chan map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size, 2952f7dc1ea6SMichael Chan PCI_DMA_TODEVICE); 2953f7dc1ea6SMichael Chan if (dma_mapping_error(&bp->pdev->dev, map)) { 2954f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2955f7dc1ea6SMichael Chan return -EIO; 2956f7dc1ea6SMichael Chan } 2957c1ba92a8SMichael Chan bnxt_xmit_bd(bp, txr, map, pkt_size); 2958f7dc1ea6SMichael Chan 2959f7dc1ea6SMichael Chan /* Sync BD data before updating doorbell */ 2960f7dc1ea6SMichael Chan wmb(); 2961f7dc1ea6SMichael Chan 2962697197e5SMichael Chan bnxt_db_write(bp, &txr->tx_db, txr->tx_prod); 2963e44758b7SMichael Chan rc = bnxt_poll_loopback(bp, cpr, pkt_size); 2964f7dc1ea6SMichael Chan 2965f7dc1ea6SMichael Chan dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE); 2966f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2967f7dc1ea6SMichael Chan return rc; 2968f7dc1ea6SMichael Chan } 2969f7dc1ea6SMichael Chan 2970eb513658SMichael Chan static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results) 2971eb513658SMichael Chan { 2972eb513658SMichael Chan struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr; 2973eb513658SMichael Chan struct hwrm_selftest_exec_input req = {0}; 2974eb513658SMichael Chan int rc; 2975eb513658SMichael Chan 2976eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1); 2977eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2978eb513658SMichael Chan resp->test_success = 0; 2979eb513658SMichael Chan req.flags = test_mask; 2980eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout); 2981eb513658SMichael Chan *test_results = resp->test_success; 2982eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2983eb513658SMichael Chan return rc; 2984eb513658SMichael Chan } 2985eb513658SMichael Chan 298655fd0cf3SMichael Chan #define BNXT_DRV_TESTS 4 2987f7dc1ea6SMichael Chan #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS) 298891725d89SMichael Chan #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1) 298955fd0cf3SMichael Chan #define BNXT_EXTLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2) 299055fd0cf3SMichael Chan #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 3) 2991eb513658SMichael Chan 2992eb513658SMichael Chan static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest, 2993eb513658SMichael Chan u64 *buf) 2994eb513658SMichael Chan { 2995eb513658SMichael Chan struct bnxt *bp = netdev_priv(dev); 299655fd0cf3SMichael Chan bool do_ext_lpbk = false; 2997eb513658SMichael Chan bool offline = false; 2998eb513658SMichael Chan u8 test_results = 0; 2999eb513658SMichael Chan u8 test_mask = 0; 3000d27e2ca1SMichael Chan int rc = 0, i; 3001eb513658SMichael Chan 3002eb513658SMichael Chan if (!bp->num_tests || !BNXT_SINGLE_PF(bp)) 3003eb513658SMichael Chan return; 3004eb513658SMichael Chan memset(buf, 0, sizeof(u64) * bp->num_tests); 3005eb513658SMichael Chan if (!netif_running(dev)) { 3006eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3007eb513658SMichael Chan return; 3008eb513658SMichael Chan } 3009eb513658SMichael Chan 301055fd0cf3SMichael Chan if ((etest->flags & ETH_TEST_FL_EXTERNAL_LB) && 301155fd0cf3SMichael Chan (bp->test_info->flags & BNXT_TEST_FL_EXT_LPBK)) 301255fd0cf3SMichael Chan do_ext_lpbk = true; 301355fd0cf3SMichael Chan 3014eb513658SMichael Chan if (etest->flags & ETH_TEST_FL_OFFLINE) { 3015eb513658SMichael Chan if (bp->pf.active_vfs) { 3016eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3017eb513658SMichael Chan netdev_warn(dev, "Offline tests cannot be run with active VFs\n"); 3018eb513658SMichael Chan return; 3019eb513658SMichael Chan } 3020eb513658SMichael Chan offline = true; 3021eb513658SMichael Chan } 3022eb513658SMichael Chan 3023eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 3024eb513658SMichael Chan u8 bit_val = 1 << i; 3025eb513658SMichael Chan 3026eb513658SMichael Chan if (!(bp->test_info->offline_mask & bit_val)) 3027eb513658SMichael Chan test_mask |= bit_val; 3028eb513658SMichael Chan else if (offline) 3029eb513658SMichael Chan test_mask |= bit_val; 3030eb513658SMichael Chan } 3031eb513658SMichael Chan if (!offline) { 3032eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 3033eb513658SMichael Chan } else { 3034eb513658SMichael Chan rc = bnxt_close_nic(bp, false, false); 3035eb513658SMichael Chan if (rc) 3036eb513658SMichael Chan return; 3037eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 3038f7dc1ea6SMichael Chan 3039f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 1; 3040f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, true); 3041f7dc1ea6SMichael Chan msleep(250); 3042f7dc1ea6SMichael Chan rc = bnxt_half_open_nic(bp); 3043f7dc1ea6SMichael Chan if (rc) { 3044f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 3045f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3046f7dc1ea6SMichael Chan return; 3047f7dc1ea6SMichael Chan } 3048f7dc1ea6SMichael Chan if (bnxt_run_loopback(bp)) 3049f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3050f7dc1ea6SMichael Chan else 3051f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 0; 3052f7dc1ea6SMichael Chan 3053f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 305455fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, false); 305591725d89SMichael Chan msleep(1000); 305691725d89SMichael Chan if (bnxt_run_loopback(bp)) { 305791725d89SMichael Chan buf[BNXT_PHYLPBK_TEST_IDX] = 1; 305891725d89SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 305991725d89SMichael Chan } 306055fd0cf3SMichael Chan if (do_ext_lpbk) { 306155fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; 306255fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, true); 306355fd0cf3SMichael Chan msleep(1000); 306455fd0cf3SMichael Chan if (bnxt_run_loopback(bp)) { 306555fd0cf3SMichael Chan buf[BNXT_EXTLPBK_TEST_IDX] = 1; 306655fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 306755fd0cf3SMichael Chan } 306855fd0cf3SMichael Chan } 306955fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, false, false); 307091725d89SMichael Chan bnxt_half_close_nic(bp); 3071d27e2ca1SMichael Chan rc = bnxt_open_nic(bp, false, true); 3072eb513658SMichael Chan } 3073d27e2ca1SMichael Chan if (rc || bnxt_test_irq(bp)) { 307467fea463SMichael Chan buf[BNXT_IRQ_TEST_IDX] = 1; 307567fea463SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 307667fea463SMichael Chan } 3077eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 3078eb513658SMichael Chan u8 bit_val = 1 << i; 3079eb513658SMichael Chan 3080eb513658SMichael Chan if ((test_mask & bit_val) && !(test_results & bit_val)) { 3081eb513658SMichael Chan buf[i] = 1; 3082eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3083eb513658SMichael Chan } 3084eb513658SMichael Chan } 3085eb513658SMichael Chan } 3086eb513658SMichael Chan 308749f7972fSVasundhara Volam static int bnxt_reset(struct net_device *dev, u32 *flags) 308849f7972fSVasundhara Volam { 308949f7972fSVasundhara Volam struct bnxt *bp = netdev_priv(dev); 30908cec0940SEdwin Peer bool reload = false; 30917a13240eSEdwin Peer u32 req = *flags; 30927a13240eSEdwin Peer 30937a13240eSEdwin Peer if (!req) 30947a13240eSEdwin Peer return -EINVAL; 309549f7972fSVasundhara Volam 309649f7972fSVasundhara Volam if (!BNXT_PF(bp)) { 309749f7972fSVasundhara Volam netdev_err(dev, "Reset is not supported from a VF\n"); 309849f7972fSVasundhara Volam return -EOPNOTSUPP; 309949f7972fSVasundhara Volam } 310049f7972fSVasundhara Volam 31010a3f4e4fSVasundhara Volam if (pci_vfs_assigned(bp->pdev) && 31020a3f4e4fSVasundhara Volam !(bp->fw_cap & BNXT_FW_CAP_HOT_RESET)) { 310349f7972fSVasundhara Volam netdev_err(dev, 310449f7972fSVasundhara Volam "Reset not allowed when VFs are assigned to VMs\n"); 310549f7972fSVasundhara Volam return -EBUSY; 310649f7972fSVasundhara Volam } 310749f7972fSVasundhara Volam 31087a13240eSEdwin Peer if ((req & BNXT_FW_RESET_CHIP) == BNXT_FW_RESET_CHIP) { 310949f7972fSVasundhara Volam /* This feature is not supported in older firmware versions */ 31107a13240eSEdwin Peer if (bp->hwrm_spec_code >= 0x10803) { 31117a13240eSEdwin Peer if (!bnxt_firmware_reset_chip(dev)) { 31127a13240eSEdwin Peer netdev_info(dev, "Firmware reset request successful.\n"); 31130a3f4e4fSVasundhara Volam if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET)) 31148cec0940SEdwin Peer reload = true; 31157a13240eSEdwin Peer *flags &= ~BNXT_FW_RESET_CHIP; 31162373d8d6SScott Branden } 31177a13240eSEdwin Peer } else if (req == BNXT_FW_RESET_CHIP) { 31187a13240eSEdwin Peer return -EOPNOTSUPP; /* only request, fail hard */ 31197a13240eSEdwin Peer } 31207a13240eSEdwin Peer } 31217a13240eSEdwin Peer 31227a13240eSEdwin Peer if (req & BNXT_FW_RESET_AP) { 31236502ad59SScott Branden /* This feature is not supported in older firmware versions */ 31247a13240eSEdwin Peer if (bp->hwrm_spec_code >= 0x10803) { 31257a13240eSEdwin Peer if (!bnxt_firmware_reset_ap(dev)) { 31267a13240eSEdwin Peer netdev_info(dev, "Reset application processor successful.\n"); 31278cec0940SEdwin Peer reload = true; 31287a13240eSEdwin Peer *flags &= ~BNXT_FW_RESET_AP; 31292373d8d6SScott Branden } 31307a13240eSEdwin Peer } else if (req == BNXT_FW_RESET_AP) { 31317a13240eSEdwin Peer return -EOPNOTSUPP; /* only request, fail hard */ 31327a13240eSEdwin Peer } 313349f7972fSVasundhara Volam } 313449f7972fSVasundhara Volam 31358cec0940SEdwin Peer if (reload) 31368cec0940SEdwin Peer netdev_info(dev, "Reload driver to complete reset\n"); 31378cec0940SEdwin Peer 31387a13240eSEdwin Peer return 0; 313949f7972fSVasundhara Volam } 314049f7972fSVasundhara Volam 31416c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg, int msg_len, 31426c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info *info) 31436c5657d0SVasundhara Volam { 31446c5657d0SVasundhara Volam struct hwrm_dbg_cmn_output *cmn_resp = bp->hwrm_cmd_resp_addr; 31456c5657d0SVasundhara Volam struct hwrm_dbg_cmn_input *cmn_req = msg; 31466c5657d0SVasundhara Volam __le16 *seq_ptr = msg + info->seq_off; 31476c5657d0SVasundhara Volam u16 seq = 0, len, segs_off; 31486c5657d0SVasundhara Volam void *resp = cmn_resp; 31496c5657d0SVasundhara Volam dma_addr_t dma_handle; 31506c5657d0SVasundhara Volam int rc, off = 0; 31516c5657d0SVasundhara Volam void *dma_buf; 31526c5657d0SVasundhara Volam 31536c5657d0SVasundhara Volam dma_buf = dma_alloc_coherent(&bp->pdev->dev, info->dma_len, &dma_handle, 31546c5657d0SVasundhara Volam GFP_KERNEL); 31556c5657d0SVasundhara Volam if (!dma_buf) 31566c5657d0SVasundhara Volam return -ENOMEM; 31576c5657d0SVasundhara Volam 31586c5657d0SVasundhara Volam segs_off = offsetof(struct hwrm_dbg_coredump_list_output, 31596c5657d0SVasundhara Volam total_segments); 31606c5657d0SVasundhara Volam cmn_req->host_dest_addr = cpu_to_le64(dma_handle); 31616c5657d0SVasundhara Volam cmn_req->host_buf_len = cpu_to_le32(info->dma_len); 31626c5657d0SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 31636c5657d0SVasundhara Volam while (1) { 31646c5657d0SVasundhara Volam *seq_ptr = cpu_to_le16(seq); 31655b306bdeSVasundhara Volam rc = _hwrm_send_message(bp, msg, msg_len, 31665b306bdeSVasundhara Volam HWRM_COREDUMP_TIMEOUT); 31676c5657d0SVasundhara Volam if (rc) 31686c5657d0SVasundhara Volam break; 31696c5657d0SVasundhara Volam 31706c5657d0SVasundhara Volam len = le16_to_cpu(*((__le16 *)(resp + info->data_len_off))); 31716c5657d0SVasundhara Volam if (!seq && 31726c5657d0SVasundhara Volam cmn_req->req_type == cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) { 31736c5657d0SVasundhara Volam info->segs = le16_to_cpu(*((__le16 *)(resp + 31746c5657d0SVasundhara Volam segs_off))); 31756c5657d0SVasundhara Volam if (!info->segs) { 31766c5657d0SVasundhara Volam rc = -EIO; 31776c5657d0SVasundhara Volam break; 31786c5657d0SVasundhara Volam } 31796c5657d0SVasundhara Volam 31806c5657d0SVasundhara Volam info->dest_buf_size = info->segs * 31816c5657d0SVasundhara Volam sizeof(struct coredump_segment_record); 31826c5657d0SVasundhara Volam info->dest_buf = kmalloc(info->dest_buf_size, 31836c5657d0SVasundhara Volam GFP_KERNEL); 31846c5657d0SVasundhara Volam if (!info->dest_buf) { 31856c5657d0SVasundhara Volam rc = -ENOMEM; 31866c5657d0SVasundhara Volam break; 31876c5657d0SVasundhara Volam } 31886c5657d0SVasundhara Volam } 31896c5657d0SVasundhara Volam 3190c74751f4SVasundhara Volam if (info->dest_buf) { 3191c74751f4SVasundhara Volam if ((info->seg_start + off + len) <= 3192c74751f4SVasundhara Volam BNXT_COREDUMP_BUF_LEN(info->buf_len)) { 31936c5657d0SVasundhara Volam memcpy(info->dest_buf + off, dma_buf, len); 3194c74751f4SVasundhara Volam } else { 3195c74751f4SVasundhara Volam rc = -ENOBUFS; 3196c74751f4SVasundhara Volam break; 3197c74751f4SVasundhara Volam } 3198c74751f4SVasundhara Volam } 31996c5657d0SVasundhara Volam 32006c5657d0SVasundhara Volam if (cmn_req->req_type == 32016c5657d0SVasundhara Volam cpu_to_le16(HWRM_DBG_COREDUMP_RETRIEVE)) 32026c5657d0SVasundhara Volam info->dest_buf_size += len; 32036c5657d0SVasundhara Volam 32046c5657d0SVasundhara Volam if (!(cmn_resp->flags & HWRM_DBG_CMN_FLAGS_MORE)) 32056c5657d0SVasundhara Volam break; 32066c5657d0SVasundhara Volam 32076c5657d0SVasundhara Volam seq++; 32086c5657d0SVasundhara Volam off += len; 32096c5657d0SVasundhara Volam } 32106c5657d0SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 32116c5657d0SVasundhara Volam dma_free_coherent(&bp->pdev->dev, info->dma_len, dma_buf, dma_handle); 32126c5657d0SVasundhara Volam return rc; 32136c5657d0SVasundhara Volam } 32146c5657d0SVasundhara Volam 32156c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_list(struct bnxt *bp, 32166c5657d0SVasundhara Volam struct bnxt_coredump *coredump) 32176c5657d0SVasundhara Volam { 32186c5657d0SVasundhara Volam struct hwrm_dbg_coredump_list_input req = {0}; 32196c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 32206c5657d0SVasundhara Volam int rc; 32216c5657d0SVasundhara Volam 32226c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_LIST, -1, -1); 32236c5657d0SVasundhara Volam 32246c5657d0SVasundhara Volam info.dma_len = COREDUMP_LIST_BUF_LEN; 32256c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_list_input, seq_no); 32266c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_list_output, 32276c5657d0SVasundhara Volam data_len); 32286c5657d0SVasundhara Volam 32296c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 32306c5657d0SVasundhara Volam if (!rc) { 32316c5657d0SVasundhara Volam coredump->data = info.dest_buf; 32326c5657d0SVasundhara Volam coredump->data_size = info.dest_buf_size; 32336c5657d0SVasundhara Volam coredump->total_segs = info.segs; 32346c5657d0SVasundhara Volam } 32356c5657d0SVasundhara Volam return rc; 32366c5657d0SVasundhara Volam } 32376c5657d0SVasundhara Volam 32386c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_initiate(struct bnxt *bp, u16 component_id, 32396c5657d0SVasundhara Volam u16 segment_id) 32406c5657d0SVasundhara Volam { 32416c5657d0SVasundhara Volam struct hwrm_dbg_coredump_initiate_input req = {0}; 32426c5657d0SVasundhara Volam 32436c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_INITIATE, -1, -1); 32446c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 32456c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 32466c5657d0SVasundhara Volam 324757a8730bSVasundhara Volam return hwrm_send_message(bp, &req, sizeof(req), HWRM_COREDUMP_TIMEOUT); 32486c5657d0SVasundhara Volam } 32496c5657d0SVasundhara Volam 32506c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_retrieve(struct bnxt *bp, u16 component_id, 32516c5657d0SVasundhara Volam u16 segment_id, u32 *seg_len, 3252c74751f4SVasundhara Volam void *buf, u32 buf_len, u32 offset) 32536c5657d0SVasundhara Volam { 32546c5657d0SVasundhara Volam struct hwrm_dbg_coredump_retrieve_input req = {0}; 32556c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 32566c5657d0SVasundhara Volam int rc; 32576c5657d0SVasundhara Volam 32586c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_RETRIEVE, -1, -1); 32596c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 32606c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 32616c5657d0SVasundhara Volam 32626c5657d0SVasundhara Volam info.dma_len = COREDUMP_RETRIEVE_BUF_LEN; 32636c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_retrieve_input, 32646c5657d0SVasundhara Volam seq_no); 32656c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_retrieve_output, 32666c5657d0SVasundhara Volam data_len); 3267c74751f4SVasundhara Volam if (buf) { 32686c5657d0SVasundhara Volam info.dest_buf = buf + offset; 3269c74751f4SVasundhara Volam info.buf_len = buf_len; 3270c74751f4SVasundhara Volam info.seg_start = offset; 3271c74751f4SVasundhara Volam } 32726c5657d0SVasundhara Volam 32736c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 32746c5657d0SVasundhara Volam if (!rc) 32756c5657d0SVasundhara Volam *seg_len = info.dest_buf_size; 32766c5657d0SVasundhara Volam 32776c5657d0SVasundhara Volam return rc; 32786c5657d0SVasundhara Volam } 32796c5657d0SVasundhara Volam 32806c5657d0SVasundhara Volam static void 32816c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(struct bnxt *bp, 32826c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr *seg_hdr, 32836c5657d0SVasundhara Volam struct coredump_segment_record *seg_rec, u32 seg_len, 32846c5657d0SVasundhara Volam int status, u32 duration, u32 instance) 32856c5657d0SVasundhara Volam { 32866c5657d0SVasundhara Volam memset(seg_hdr, 0, sizeof(*seg_hdr)); 32878605212aSVasundhara Volam memcpy(seg_hdr->signature, "sEgM", 4); 32886c5657d0SVasundhara Volam if (seg_rec) { 32896c5657d0SVasundhara Volam seg_hdr->component_id = (__force __le32)seg_rec->component_id; 32906c5657d0SVasundhara Volam seg_hdr->segment_id = (__force __le32)seg_rec->segment_id; 32916c5657d0SVasundhara Volam seg_hdr->low_version = seg_rec->version_low; 32926c5657d0SVasundhara Volam seg_hdr->high_version = seg_rec->version_hi; 32936c5657d0SVasundhara Volam } else { 32946c5657d0SVasundhara Volam /* For hwrm_ver_get response Component id = 2 32956c5657d0SVasundhara Volam * and Segment id = 0 32966c5657d0SVasundhara Volam */ 32976c5657d0SVasundhara Volam seg_hdr->component_id = cpu_to_le32(2); 32986c5657d0SVasundhara Volam seg_hdr->segment_id = 0; 32996c5657d0SVasundhara Volam } 33006c5657d0SVasundhara Volam seg_hdr->function_id = cpu_to_le16(bp->pdev->devfn); 33016c5657d0SVasundhara Volam seg_hdr->length = cpu_to_le32(seg_len); 33026c5657d0SVasundhara Volam seg_hdr->status = cpu_to_le32(status); 33036c5657d0SVasundhara Volam seg_hdr->duration = cpu_to_le32(duration); 33046c5657d0SVasundhara Volam seg_hdr->data_offset = cpu_to_le32(sizeof(*seg_hdr)); 33056c5657d0SVasundhara Volam seg_hdr->instance = cpu_to_le32(instance); 33066c5657d0SVasundhara Volam } 33076c5657d0SVasundhara Volam 33086c5657d0SVasundhara Volam static void 33096c5657d0SVasundhara Volam bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record, 33106c5657d0SVasundhara Volam time64_t start, s16 start_utc, u16 total_segs, 33116c5657d0SVasundhara Volam int status) 33126c5657d0SVasundhara Volam { 33136c5657d0SVasundhara Volam time64_t end = ktime_get_real_seconds(); 33146c5657d0SVasundhara Volam u32 os_ver_major = 0, os_ver_minor = 0; 33156c5657d0SVasundhara Volam struct tm tm; 33166c5657d0SVasundhara Volam 33176c5657d0SVasundhara Volam time64_to_tm(start, 0, &tm); 33186c5657d0SVasundhara Volam memset(record, 0, sizeof(*record)); 33198605212aSVasundhara Volam memcpy(record->signature, "cOrE", 4); 33206c5657d0SVasundhara Volam record->flags = 0; 33216c5657d0SVasundhara Volam record->low_version = 0; 33226c5657d0SVasundhara Volam record->high_version = 1; 33236c5657d0SVasundhara Volam record->asic_state = 0; 33243d46eee5SArnd Bergmann strlcpy(record->system_name, utsname()->nodename, 33253d46eee5SArnd Bergmann sizeof(record->system_name)); 33268dc5ae2dSVasundhara Volam record->year = cpu_to_le16(tm.tm_year + 1900); 33278dc5ae2dSVasundhara Volam record->month = cpu_to_le16(tm.tm_mon + 1); 33286c5657d0SVasundhara Volam record->day = cpu_to_le16(tm.tm_mday); 33296c5657d0SVasundhara Volam record->hour = cpu_to_le16(tm.tm_hour); 33306c5657d0SVasundhara Volam record->minute = cpu_to_le16(tm.tm_min); 33316c5657d0SVasundhara Volam record->second = cpu_to_le16(tm.tm_sec); 33326c5657d0SVasundhara Volam record->utc_bias = cpu_to_le16(start_utc); 33336c5657d0SVasundhara Volam strcpy(record->commandline, "ethtool -w"); 33346c5657d0SVasundhara Volam record->total_segments = cpu_to_le32(total_segs); 33356c5657d0SVasundhara Volam 33366c5657d0SVasundhara Volam sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor); 33376c5657d0SVasundhara Volam record->os_ver_major = cpu_to_le32(os_ver_major); 33386c5657d0SVasundhara Volam record->os_ver_minor = cpu_to_le32(os_ver_minor); 33396c5657d0SVasundhara Volam 33408605212aSVasundhara Volam strlcpy(record->os_name, utsname()->sysname, 32); 33416c5657d0SVasundhara Volam time64_to_tm(end, 0, &tm); 33426c5657d0SVasundhara Volam record->end_year = cpu_to_le16(tm.tm_year + 1900); 33436c5657d0SVasundhara Volam record->end_month = cpu_to_le16(tm.tm_mon + 1); 33446c5657d0SVasundhara Volam record->end_day = cpu_to_le16(tm.tm_mday); 33456c5657d0SVasundhara Volam record->end_hour = cpu_to_le16(tm.tm_hour); 33466c5657d0SVasundhara Volam record->end_minute = cpu_to_le16(tm.tm_min); 33476c5657d0SVasundhara Volam record->end_second = cpu_to_le16(tm.tm_sec); 33486c5657d0SVasundhara Volam record->end_utc_bias = cpu_to_le16(sys_tz.tz_minuteswest * 60); 33496c5657d0SVasundhara Volam record->asic_id1 = cpu_to_le32(bp->chip_num << 16 | 33506c5657d0SVasundhara Volam bp->ver_resp.chip_rev << 8 | 33516c5657d0SVasundhara Volam bp->ver_resp.chip_metal); 33526c5657d0SVasundhara Volam record->asic_id2 = 0; 33536c5657d0SVasundhara Volam record->coredump_status = cpu_to_le32(status); 33546c5657d0SVasundhara Volam record->ioctl_low_version = 0; 33556c5657d0SVasundhara Volam record->ioctl_high_version = 0; 33566c5657d0SVasundhara Volam } 33576c5657d0SVasundhara Volam 33586c5657d0SVasundhara Volam static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len) 33596c5657d0SVasundhara Volam { 33606c5657d0SVasundhara Volam u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output); 3361c74751f4SVasundhara Volam u32 offset = 0, seg_hdr_len, seg_record_len, buf_len = 0; 33626c5657d0SVasundhara Volam struct coredump_segment_record *seg_record = NULL; 33636c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr seg_hdr; 33646c5657d0SVasundhara Volam struct bnxt_coredump coredump = {NULL}; 33656c5657d0SVasundhara Volam time64_t start_time; 33666c5657d0SVasundhara Volam u16 start_utc; 33676c5657d0SVasundhara Volam int rc = 0, i; 33686c5657d0SVasundhara Volam 3369c74751f4SVasundhara Volam if (buf) 3370c74751f4SVasundhara Volam buf_len = *dump_len; 3371c74751f4SVasundhara Volam 33726c5657d0SVasundhara Volam start_time = ktime_get_real_seconds(); 33736c5657d0SVasundhara Volam start_utc = sys_tz.tz_minuteswest * 60; 33746c5657d0SVasundhara Volam seg_hdr_len = sizeof(seg_hdr); 33756c5657d0SVasundhara Volam 33766c5657d0SVasundhara Volam /* First segment should be hwrm_ver_get response */ 33776c5657d0SVasundhara Volam *dump_len = seg_hdr_len + ver_get_resp_len; 33786c5657d0SVasundhara Volam if (buf) { 33796c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, NULL, ver_get_resp_len, 33806c5657d0SVasundhara Volam 0, 0, 0); 33816c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 33826c5657d0SVasundhara Volam offset += seg_hdr_len; 33836c5657d0SVasundhara Volam memcpy(buf + offset, &bp->ver_resp, ver_get_resp_len); 33846c5657d0SVasundhara Volam offset += ver_get_resp_len; 33856c5657d0SVasundhara Volam } 33866c5657d0SVasundhara Volam 33876c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_list(bp, &coredump); 33886c5657d0SVasundhara Volam if (rc) { 33896c5657d0SVasundhara Volam netdev_err(bp->dev, "Failed to get coredump segment list\n"); 33906c5657d0SVasundhara Volam goto err; 33916c5657d0SVasundhara Volam } 33926c5657d0SVasundhara Volam 33936c5657d0SVasundhara Volam *dump_len += seg_hdr_len * coredump.total_segs; 33946c5657d0SVasundhara Volam 33956c5657d0SVasundhara Volam seg_record = (struct coredump_segment_record *)coredump.data; 33966c5657d0SVasundhara Volam seg_record_len = sizeof(*seg_record); 33976c5657d0SVasundhara Volam 33986c5657d0SVasundhara Volam for (i = 0; i < coredump.total_segs; i++) { 33996c5657d0SVasundhara Volam u16 comp_id = le16_to_cpu(seg_record->component_id); 34006c5657d0SVasundhara Volam u16 seg_id = le16_to_cpu(seg_record->segment_id); 34016c5657d0SVasundhara Volam u32 duration = 0, seg_len = 0; 34026c5657d0SVasundhara Volam unsigned long start, end; 34036c5657d0SVasundhara Volam 3404c74751f4SVasundhara Volam if (buf && ((offset + seg_hdr_len) > 3405c74751f4SVasundhara Volam BNXT_COREDUMP_BUF_LEN(buf_len))) { 3406c74751f4SVasundhara Volam rc = -ENOBUFS; 3407c74751f4SVasundhara Volam goto err; 3408c74751f4SVasundhara Volam } 3409c74751f4SVasundhara Volam 34106c5657d0SVasundhara Volam start = jiffies; 34116c5657d0SVasundhara Volam 34126c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_initiate(bp, comp_id, seg_id); 34136c5657d0SVasundhara Volam if (rc) { 34146c5657d0SVasundhara Volam netdev_err(bp->dev, 34156c5657d0SVasundhara Volam "Failed to initiate coredump for seg = %d\n", 34166c5657d0SVasundhara Volam seg_record->segment_id); 34176c5657d0SVasundhara Volam goto next_seg; 34186c5657d0SVasundhara Volam } 34196c5657d0SVasundhara Volam 34206c5657d0SVasundhara Volam /* Write segment data into the buffer */ 34216c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_retrieve(bp, comp_id, seg_id, 3422c74751f4SVasundhara Volam &seg_len, buf, buf_len, 34236c5657d0SVasundhara Volam offset + seg_hdr_len); 3424c74751f4SVasundhara Volam if (rc && rc == -ENOBUFS) 3425c74751f4SVasundhara Volam goto err; 3426c74751f4SVasundhara Volam else if (rc) 34276c5657d0SVasundhara Volam netdev_err(bp->dev, 34286c5657d0SVasundhara Volam "Failed to retrieve coredump for seg = %d\n", 34296c5657d0SVasundhara Volam seg_record->segment_id); 34306c5657d0SVasundhara Volam 34316c5657d0SVasundhara Volam next_seg: 34326c5657d0SVasundhara Volam end = jiffies; 34336c5657d0SVasundhara Volam duration = jiffies_to_msecs(end - start); 34346c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, seg_record, seg_len, 34356c5657d0SVasundhara Volam rc, duration, 0); 34366c5657d0SVasundhara Volam 34376c5657d0SVasundhara Volam if (buf) { 34386c5657d0SVasundhara Volam /* Write segment header into the buffer */ 34396c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 34406c5657d0SVasundhara Volam offset += seg_hdr_len + seg_len; 34416c5657d0SVasundhara Volam } 34426c5657d0SVasundhara Volam 34436c5657d0SVasundhara Volam *dump_len += seg_len; 34446c5657d0SVasundhara Volam seg_record = 34456c5657d0SVasundhara Volam (struct coredump_segment_record *)((u8 *)seg_record + 34466c5657d0SVasundhara Volam seg_record_len); 34476c5657d0SVasundhara Volam } 34486c5657d0SVasundhara Volam 34496c5657d0SVasundhara Volam err: 34501bbf3aedSArnd Bergmann if (buf) 34511bbf3aedSArnd Bergmann bnxt_fill_coredump_record(bp, buf + offset, start_time, 34526c5657d0SVasundhara Volam start_utc, coredump.total_segs + 1, 34536c5657d0SVasundhara Volam rc); 34546c5657d0SVasundhara Volam kfree(coredump.data); 34551bbf3aedSArnd Bergmann *dump_len += sizeof(struct bnxt_coredump_record); 3456c74751f4SVasundhara Volam if (rc == -ENOBUFS) 34579a005c38SJonathan Lemon netdev_err(bp->dev, "Firmware returned large coredump buffer\n"); 34586c5657d0SVasundhara Volam return rc; 34596c5657d0SVasundhara Volam } 34606c5657d0SVasundhara Volam 34610b0eacf3SVasundhara Volam static int bnxt_set_dump(struct net_device *dev, struct ethtool_dump *dump) 34620b0eacf3SVasundhara Volam { 34630b0eacf3SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 34640b0eacf3SVasundhara Volam 34650b0eacf3SVasundhara Volam if (dump->flag > BNXT_DUMP_CRASH) { 34660b0eacf3SVasundhara Volam netdev_info(dev, "Supports only Live(0) and Crash(1) dumps.\n"); 34670b0eacf3SVasundhara Volam return -EINVAL; 34680b0eacf3SVasundhara Volam } 34690b0eacf3SVasundhara Volam 34700b0eacf3SVasundhara Volam if (!IS_ENABLED(CONFIG_TEE_BNXT_FW) && dump->flag == BNXT_DUMP_CRASH) { 34710b0eacf3SVasundhara Volam netdev_info(dev, "Cannot collect crash dump as TEE_BNXT_FW config option is not enabled.\n"); 34720b0eacf3SVasundhara Volam return -EOPNOTSUPP; 34730b0eacf3SVasundhara Volam } 34740b0eacf3SVasundhara Volam 34750b0eacf3SVasundhara Volam bp->dump_flag = dump->flag; 34760b0eacf3SVasundhara Volam return 0; 34770b0eacf3SVasundhara Volam } 34780b0eacf3SVasundhara Volam 34796c5657d0SVasundhara Volam static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump) 34806c5657d0SVasundhara Volam { 34816c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 34826c5657d0SVasundhara Volam 34836c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 34846c5657d0SVasundhara Volam return -EOPNOTSUPP; 34856c5657d0SVasundhara Volam 34866c5657d0SVasundhara Volam dump->version = bp->ver_resp.hwrm_fw_maj_8b << 24 | 34876c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_min_8b << 16 | 34886c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_bld_8b << 8 | 34896c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_rsvd_8b; 34906c5657d0SVasundhara Volam 34910b0eacf3SVasundhara Volam dump->flag = bp->dump_flag; 34920b0eacf3SVasundhara Volam if (bp->dump_flag == BNXT_DUMP_CRASH) 34930b0eacf3SVasundhara Volam dump->len = BNXT_CRASH_DUMP_LEN; 34940b0eacf3SVasundhara Volam else 34950b0eacf3SVasundhara Volam bnxt_get_coredump(bp, NULL, &dump->len); 34960b0eacf3SVasundhara Volam return 0; 34976c5657d0SVasundhara Volam } 34986c5657d0SVasundhara Volam 34996c5657d0SVasundhara Volam static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump, 35006c5657d0SVasundhara Volam void *buf) 35016c5657d0SVasundhara Volam { 35026c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 35036c5657d0SVasundhara Volam 35046c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 35056c5657d0SVasundhara Volam return -EOPNOTSUPP; 35066c5657d0SVasundhara Volam 35076c5657d0SVasundhara Volam memset(buf, 0, dump->len); 35086c5657d0SVasundhara Volam 35090b0eacf3SVasundhara Volam dump->flag = bp->dump_flag; 35100b0eacf3SVasundhara Volam if (dump->flag == BNXT_DUMP_CRASH) { 35110b0eacf3SVasundhara Volam #ifdef CONFIG_TEE_BNXT_FW 35120b0eacf3SVasundhara Volam return tee_bnxt_copy_coredump(buf, 0, dump->len); 35130b0eacf3SVasundhara Volam #endif 35140b0eacf3SVasundhara Volam } else { 35156c5657d0SVasundhara Volam return bnxt_get_coredump(bp, buf, &dump->len); 35166c5657d0SVasundhara Volam } 35176c5657d0SVasundhara Volam 35180b0eacf3SVasundhara Volam return 0; 35190b0eacf3SVasundhara Volam } 35200b0eacf3SVasundhara Volam 3521eb513658SMichael Chan void bnxt_ethtool_init(struct bnxt *bp) 3522eb513658SMichael Chan { 3523eb513658SMichael Chan struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr; 3524eb513658SMichael Chan struct hwrm_selftest_qlist_input req = {0}; 3525eb513658SMichael Chan struct bnxt_test_info *test_info; 3526431aa1ebSMichael Chan struct net_device *dev = bp->dev; 3527eb513658SMichael Chan int i, rc; 3528eb513658SMichael Chan 3529691aa620SVasundhara Volam if (!(bp->fw_cap & BNXT_FW_CAP_PKG_VER)) 3530a60faa60SVasundhara Volam bnxt_get_pkgver(dev); 3531431aa1ebSMichael Chan 3532ba642ab7SMichael Chan bp->num_tests = 0; 3533eb513658SMichael Chan if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp)) 3534eb513658SMichael Chan return; 3535eb513658SMichael Chan 3536eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1); 3537eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 3538eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 3539eb513658SMichael Chan if (rc) 3540eb513658SMichael Chan goto ethtool_init_exit; 3541eb513658SMichael Chan 3542ba642ab7SMichael Chan test_info = bp->test_info; 3543ba642ab7SMichael Chan if (!test_info) 3544eb513658SMichael Chan test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL); 3545eb513658SMichael Chan if (!test_info) 3546eb513658SMichael Chan goto ethtool_init_exit; 3547eb513658SMichael Chan 3548eb513658SMichael Chan bp->test_info = test_info; 3549eb513658SMichael Chan bp->num_tests = resp->num_tests + BNXT_DRV_TESTS; 3550eb513658SMichael Chan if (bp->num_tests > BNXT_MAX_TEST) 3551eb513658SMichael Chan bp->num_tests = BNXT_MAX_TEST; 3552eb513658SMichael Chan 3553eb513658SMichael Chan test_info->offline_mask = resp->offline_tests; 3554eb513658SMichael Chan test_info->timeout = le16_to_cpu(resp->test_timeout); 3555eb513658SMichael Chan if (!test_info->timeout) 3556eb513658SMichael Chan test_info->timeout = HWRM_CMD_TIMEOUT; 3557eb513658SMichael Chan for (i = 0; i < bp->num_tests; i++) { 3558eb513658SMichael Chan char *str = test_info->string[i]; 3559eb513658SMichael Chan char *fw_str = resp->test0_name + i * 32; 3560eb513658SMichael Chan 3561f7dc1ea6SMichael Chan if (i == BNXT_MACLPBK_TEST_IDX) { 3562f7dc1ea6SMichael Chan strcpy(str, "Mac loopback test (offline)"); 356391725d89SMichael Chan } else if (i == BNXT_PHYLPBK_TEST_IDX) { 356491725d89SMichael Chan strcpy(str, "Phy loopback test (offline)"); 356555fd0cf3SMichael Chan } else if (i == BNXT_EXTLPBK_TEST_IDX) { 356655fd0cf3SMichael Chan strcpy(str, "Ext loopback test (offline)"); 356767fea463SMichael Chan } else if (i == BNXT_IRQ_TEST_IDX) { 356867fea463SMichael Chan strcpy(str, "Interrupt_test (offline)"); 3569f7dc1ea6SMichael Chan } else { 3570eb513658SMichael Chan strlcpy(str, fw_str, ETH_GSTRING_LEN); 3571eb513658SMichael Chan strncat(str, " test", ETH_GSTRING_LEN - strlen(str)); 3572eb513658SMichael Chan if (test_info->offline_mask & (1 << i)) 3573eb513658SMichael Chan strncat(str, " (offline)", 3574eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3575eb513658SMichael Chan else 3576eb513658SMichael Chan strncat(str, " (online)", 3577eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3578eb513658SMichael Chan } 3579f7dc1ea6SMichael Chan } 3580eb513658SMichael Chan 3581eb513658SMichael Chan ethtool_init_exit: 3582eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 3583eb513658SMichael Chan } 3584eb513658SMichael Chan 3585eb513658SMichael Chan void bnxt_ethtool_free(struct bnxt *bp) 3586eb513658SMichael Chan { 3587eb513658SMichael Chan kfree(bp->test_info); 3588eb513658SMichael Chan bp->test_info = NULL; 3589eb513658SMichael Chan } 3590eb513658SMichael Chan 3591c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 3592f704d243SJakub Kicinski .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 3593f704d243SJakub Kicinski ETHTOOL_COALESCE_MAX_FRAMES | 3594f704d243SJakub Kicinski ETHTOOL_COALESCE_USECS_IRQ | 3595f704d243SJakub Kicinski ETHTOOL_COALESCE_MAX_FRAMES_IRQ | 3596f704d243SJakub Kicinski ETHTOOL_COALESCE_STATS_BLOCK_USECS | 3597f704d243SJakub Kicinski ETHTOOL_COALESCE_USE_ADAPTIVE_RX, 359800c04a92SMichael Chan .get_link_ksettings = bnxt_get_link_ksettings, 359900c04a92SMichael Chan .set_link_ksettings = bnxt_set_link_ksettings, 3600c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 3601c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 3602c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 36038e202366SMichael Chan .get_wol = bnxt_get_wol, 36045282db6cSMichael Chan .set_wol = bnxt_set_wol, 3605c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 3606c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 3607c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 3608c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 3609c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 3610c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 3611c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 3612c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 3613c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 3614c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 3615c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 3616c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 3617a011952aSMichael Chan .set_rxnfc = bnxt_set_rxnfc, 3618c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 3619c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 3620c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 3621c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 3622c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 3623c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 3624c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 3625c0c050c5SMichael Chan .get_link = bnxt_get_link, 362672b34f04SMichael Chan .get_eee = bnxt_get_eee, 362772b34f04SMichael Chan .set_eee = bnxt_set_eee, 362842ee18feSAjit Khaparde .get_module_info = bnxt_get_module_info, 362942ee18feSAjit Khaparde .get_module_eeprom = bnxt_get_module_eeprom, 36305ad2cbeeSMichael Chan .nway_reset = bnxt_nway_reset, 36315ad2cbeeSMichael Chan .set_phys_id = bnxt_set_phys_id, 3632eb513658SMichael Chan .self_test = bnxt_self_test, 363349f7972fSVasundhara Volam .reset = bnxt_reset, 36340b0eacf3SVasundhara Volam .set_dump = bnxt_set_dump, 36356c5657d0SVasundhara Volam .get_dump_flag = bnxt_get_dump_flag, 36366c5657d0SVasundhara Volam .get_dump_data = bnxt_get_dump_data, 3637c0c050c5SMichael Chan }; 3638