1c0c050c5SMichael Chan /* Broadcom NetXtreme-C/E network driver. 2c0c050c5SMichael Chan * 311f15ed3SMichael Chan * Copyright (c) 2014-2016 Broadcom Corporation 48e202366SMichael Chan * Copyright (c) 2016-2017 Broadcom Limited 5c0c050c5SMichael Chan * 6c0c050c5SMichael Chan * This program is free software; you can redistribute it and/or modify 7c0c050c5SMichael Chan * it under the terms of the GNU General Public License as published by 8c0c050c5SMichael Chan * the Free Software Foundation. 9c0c050c5SMichael Chan */ 10c0c050c5SMichael Chan 113ebf6f0aSRob Swindell #include <linux/ctype.h> 128ddc9aaaSMichael Chan #include <linux/stringify.h> 13c0c050c5SMichael Chan #include <linux/ethtool.h> 14c0c050c5SMichael Chan #include <linux/interrupt.h> 15c0c050c5SMichael Chan #include <linux/pci.h> 16c0c050c5SMichael Chan #include <linux/etherdevice.h> 17c0c050c5SMichael Chan #include <linux/crc32.h> 18c0c050c5SMichael Chan #include <linux/firmware.h> 196c5657d0SVasundhara Volam #include <linux/utsname.h> 206c5657d0SVasundhara Volam #include <linux/time.h> 21c0c050c5SMichael Chan #include "bnxt_hsi.h" 22c0c050c5SMichael Chan #include "bnxt.h" 23f7dc1ea6SMichael Chan #include "bnxt_xdp.h" 24c0c050c5SMichael Chan #include "bnxt_ethtool.h" 25c0c050c5SMichael Chan #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */ 26c0c050c5SMichael Chan #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */ 276c5657d0SVasundhara Volam #include "bnxt_coredump.h" 28c0c050c5SMichael Chan #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100) 295ac67d8bSRob Swindell #define FLASH_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200) 305ac67d8bSRob Swindell #define INSTALL_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200) 31c0c050c5SMichael Chan 32c0c050c5SMichael Chan static u32 bnxt_get_msglevel(struct net_device *dev) 33c0c050c5SMichael Chan { 34c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 35c0c050c5SMichael Chan 36c0c050c5SMichael Chan return bp->msg_enable; 37c0c050c5SMichael Chan } 38c0c050c5SMichael Chan 39c0c050c5SMichael Chan static void bnxt_set_msglevel(struct net_device *dev, u32 value) 40c0c050c5SMichael Chan { 41c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 42c0c050c5SMichael Chan 43c0c050c5SMichael Chan bp->msg_enable = value; 44c0c050c5SMichael Chan } 45c0c050c5SMichael Chan 46c0c050c5SMichael Chan static int bnxt_get_coalesce(struct net_device *dev, 47c0c050c5SMichael Chan struct ethtool_coalesce *coal) 48c0c050c5SMichael Chan { 49c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 5018775aa8SMichael Chan struct bnxt_coal *hw_coal; 5118775aa8SMichael Chan u16 mult; 52c0c050c5SMichael Chan 53c0c050c5SMichael Chan memset(coal, 0, sizeof(*coal)); 54c0c050c5SMichael Chan 556a8788f2SAndy Gospodarek coal->use_adaptive_rx_coalesce = bp->flags & BNXT_FLAG_DIM; 566a8788f2SAndy Gospodarek 5718775aa8SMichael Chan hw_coal = &bp->rx_coal; 5818775aa8SMichael Chan mult = hw_coal->bufs_per_record; 5918775aa8SMichael Chan coal->rx_coalesce_usecs = hw_coal->coal_ticks; 6018775aa8SMichael Chan coal->rx_max_coalesced_frames = hw_coal->coal_bufs / mult; 6118775aa8SMichael Chan coal->rx_coalesce_usecs_irq = hw_coal->coal_ticks_irq; 6218775aa8SMichael Chan coal->rx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult; 63c0c050c5SMichael Chan 6418775aa8SMichael Chan hw_coal = &bp->tx_coal; 6518775aa8SMichael Chan mult = hw_coal->bufs_per_record; 6618775aa8SMichael Chan coal->tx_coalesce_usecs = hw_coal->coal_ticks; 6718775aa8SMichael Chan coal->tx_max_coalesced_frames = hw_coal->coal_bufs / mult; 6818775aa8SMichael Chan coal->tx_coalesce_usecs_irq = hw_coal->coal_ticks_irq; 6918775aa8SMichael Chan coal->tx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult; 70dfc9c94aSMichael Chan 7151f30785SMichael Chan coal->stats_block_coalesce_usecs = bp->stats_coal_ticks; 7251f30785SMichael Chan 73c0c050c5SMichael Chan return 0; 74c0c050c5SMichael Chan } 75c0c050c5SMichael Chan 76c0c050c5SMichael Chan static int bnxt_set_coalesce(struct net_device *dev, 77c0c050c5SMichael Chan struct ethtool_coalesce *coal) 78c0c050c5SMichael Chan { 79c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 8051f30785SMichael Chan bool update_stats = false; 8118775aa8SMichael Chan struct bnxt_coal *hw_coal; 82c0c050c5SMichael Chan int rc = 0; 8318775aa8SMichael Chan u16 mult; 84c0c050c5SMichael Chan 856a8788f2SAndy Gospodarek if (coal->use_adaptive_rx_coalesce) { 866a8788f2SAndy Gospodarek bp->flags |= BNXT_FLAG_DIM; 876a8788f2SAndy Gospodarek } else { 886a8788f2SAndy Gospodarek if (bp->flags & BNXT_FLAG_DIM) { 896a8788f2SAndy Gospodarek bp->flags &= ~(BNXT_FLAG_DIM); 906a8788f2SAndy Gospodarek goto reset_coalesce; 916a8788f2SAndy Gospodarek } 926a8788f2SAndy Gospodarek } 936a8788f2SAndy Gospodarek 9418775aa8SMichael Chan hw_coal = &bp->rx_coal; 9518775aa8SMichael Chan mult = hw_coal->bufs_per_record; 9618775aa8SMichael Chan hw_coal->coal_ticks = coal->rx_coalesce_usecs; 9718775aa8SMichael Chan hw_coal->coal_bufs = coal->rx_max_coalesced_frames * mult; 9818775aa8SMichael Chan hw_coal->coal_ticks_irq = coal->rx_coalesce_usecs_irq; 9918775aa8SMichael Chan hw_coal->coal_bufs_irq = coal->rx_max_coalesced_frames_irq * mult; 100c0c050c5SMichael Chan 101de4a10efSAndy Gospodarek hw_coal = &bp->tx_coal; 10218775aa8SMichael Chan mult = hw_coal->bufs_per_record; 10318775aa8SMichael Chan hw_coal->coal_ticks = coal->tx_coalesce_usecs; 10418775aa8SMichael Chan hw_coal->coal_bufs = coal->tx_max_coalesced_frames * mult; 10518775aa8SMichael Chan hw_coal->coal_ticks_irq = coal->tx_coalesce_usecs_irq; 10618775aa8SMichael Chan hw_coal->coal_bufs_irq = coal->tx_max_coalesced_frames_irq * mult; 107dfc9c94aSMichael Chan 10851f30785SMichael Chan if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) { 10951f30785SMichael Chan u32 stats_ticks = coal->stats_block_coalesce_usecs; 11051f30785SMichael Chan 111adcc331eSMichael Chan /* Allow 0, which means disable. */ 112adcc331eSMichael Chan if (stats_ticks) 11351f30785SMichael Chan stats_ticks = clamp_t(u32, stats_ticks, 11451f30785SMichael Chan BNXT_MIN_STATS_COAL_TICKS, 11551f30785SMichael Chan BNXT_MAX_STATS_COAL_TICKS); 11651f30785SMichael Chan stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS); 11751f30785SMichael Chan bp->stats_coal_ticks = stats_ticks; 118e795892eSMichael Chan if (bp->stats_coal_ticks) 119e795892eSMichael Chan bp->current_interval = 120e795892eSMichael Chan bp->stats_coal_ticks * HZ / 1000000; 121e795892eSMichael Chan else 122e795892eSMichael Chan bp->current_interval = BNXT_TIMER_INTERVAL; 12351f30785SMichael Chan update_stats = true; 12451f30785SMichael Chan } 12551f30785SMichael Chan 1266a8788f2SAndy Gospodarek reset_coalesce: 12751f30785SMichael Chan if (netif_running(dev)) { 12851f30785SMichael Chan if (update_stats) { 12951f30785SMichael Chan rc = bnxt_close_nic(bp, true, false); 13051f30785SMichael Chan if (!rc) 13151f30785SMichael Chan rc = bnxt_open_nic(bp, true, false); 13251f30785SMichael Chan } else { 133c0c050c5SMichael Chan rc = bnxt_hwrm_set_coal(bp); 13451f30785SMichael Chan } 13551f30785SMichael Chan } 136c0c050c5SMichael Chan 137c0c050c5SMichael Chan return rc; 138c0c050c5SMichael Chan } 139c0c050c5SMichael Chan 140ee79566eSMichael Chan static const char * const bnxt_ring_stats_str[] = { 141ee79566eSMichael Chan "rx_ucast_packets", 142ee79566eSMichael Chan "rx_mcast_packets", 143ee79566eSMichael Chan "rx_bcast_packets", 144ee79566eSMichael Chan "rx_discards", 145ee79566eSMichael Chan "rx_drops", 146ee79566eSMichael Chan "rx_ucast_bytes", 147ee79566eSMichael Chan "rx_mcast_bytes", 148ee79566eSMichael Chan "rx_bcast_bytes", 149ee79566eSMichael Chan "tx_ucast_packets", 150ee79566eSMichael Chan "tx_mcast_packets", 151ee79566eSMichael Chan "tx_bcast_packets", 152ee79566eSMichael Chan "tx_discards", 153ee79566eSMichael Chan "tx_drops", 154ee79566eSMichael Chan "tx_ucast_bytes", 155ee79566eSMichael Chan "tx_mcast_bytes", 156ee79566eSMichael Chan "tx_bcast_bytes", 157ee79566eSMichael Chan }; 158ee79566eSMichael Chan 159ee79566eSMichael Chan static const char * const bnxt_ring_tpa_stats_str[] = { 160ee79566eSMichael Chan "tpa_packets", 161ee79566eSMichael Chan "tpa_bytes", 162ee79566eSMichael Chan "tpa_events", 163ee79566eSMichael Chan "tpa_aborts", 164ee79566eSMichael Chan }; 165ee79566eSMichael Chan 166ee79566eSMichael Chan static const char * const bnxt_ring_sw_stats_str[] = { 167ee79566eSMichael Chan "rx_l4_csum_errors", 168ee79566eSMichael Chan "missed_irqs", 169ee79566eSMichael Chan }; 170c0c050c5SMichael Chan 1718ddc9aaaSMichael Chan #define BNXT_RX_STATS_ENTRY(counter) \ 1728ddc9aaaSMichael Chan { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) } 1738ddc9aaaSMichael Chan 1748ddc9aaaSMichael Chan #define BNXT_TX_STATS_ENTRY(counter) \ 1758ddc9aaaSMichael Chan { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) } 1768ddc9aaaSMichael Chan 17700db3cbaSVasundhara Volam #define BNXT_RX_STATS_EXT_ENTRY(counter) \ 17800db3cbaSVasundhara Volam { BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) } 17900db3cbaSVasundhara Volam 18036e53349SMichael Chan #define BNXT_TX_STATS_EXT_ENTRY(counter) \ 18136e53349SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter), __stringify(counter) } 18236e53349SMichael Chan 18336e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRY(n) \ 18436e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_duration_us), \ 18536e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_transitions) 18636e53349SMichael Chan 18736e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRY(n) \ 18836e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_duration_us), \ 18936e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_transitions) 19036e53349SMichael Chan 19136e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRIES \ 19236e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(0), \ 19336e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(1), \ 19436e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(2), \ 19536e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(3), \ 19636e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(4), \ 19736e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(5), \ 19836e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(6), \ 19936e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(7) 20036e53349SMichael Chan 20136e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRIES \ 20236e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(0), \ 20336e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(1), \ 20436e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(2), \ 20536e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(3), \ 20636e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(4), \ 20736e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(5), \ 20836e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(6), \ 20936e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(7) 21036e53349SMichael Chan 21136e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRY(n) \ 21236e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bytes_cos##n), \ 21336e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_packets_cos##n) 21436e53349SMichael Chan 21536e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRY(n) \ 21636e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_bytes_cos##n), \ 21736e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_packets_cos##n) 21836e53349SMichael Chan 21936e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRIES \ 22036e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(0), \ 22136e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(1), \ 22236e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(2), \ 22336e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(3), \ 22436e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(4), \ 22536e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(5), \ 22636e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(6), \ 22736e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(7) \ 22836e53349SMichael Chan 22936e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRIES \ 23036e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(0), \ 23136e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(1), \ 23236e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(2), \ 23336e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(3), \ 23436e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(4), \ 23536e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(5), \ 23636e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(6), \ 23736e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(7) \ 23836e53349SMichael Chan 2392792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(n) \ 2402792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_bytes_cos##n), \ 2412792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_packets_cos##n) 2422792b5b9SMichael Chan 2432792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES \ 2442792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(0), \ 2452792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(1), \ 2462792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(2), \ 2472792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(3), \ 2482792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(4), \ 2492792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(5), \ 2502792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(6), \ 2512792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(7) 2522792b5b9SMichael Chan 253e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRY(counter, n) \ 254e37fed79SMichael Chan { BNXT_RX_STATS_EXT_OFFSET(counter##_cos0), \ 255e37fed79SMichael Chan __stringify(counter##_pri##n) } 256e37fed79SMichael Chan 257e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRY(counter, n) \ 258e37fed79SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter##_cos0), \ 259e37fed79SMichael Chan __stringify(counter##_pri##n) } 260e37fed79SMichael Chan 261e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRIES(counter) \ 262e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 0), \ 263e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 1), \ 264e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 2), \ 265e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 3), \ 266e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 4), \ 267e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 5), \ 268e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 6), \ 269e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 7) 270e37fed79SMichael Chan 271e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRIES(counter) \ 272e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 0), \ 273e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 1), \ 274e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 2), \ 275e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 3), \ 276e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 4), \ 277e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 5), \ 278e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 6), \ 279e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 7) 280e37fed79SMichael Chan 28155e4398dSVasundhara Volam #define BNXT_PCIE_STATS_ENTRY(counter) \ 28255e4398dSVasundhara Volam { BNXT_PCIE_STATS_OFFSET(counter), __stringify(counter) } 28355e4398dSVasundhara Volam 28420c1d28eSVasundhara Volam enum { 28520c1d28eSVasundhara Volam RX_TOTAL_DISCARDS, 28620c1d28eSVasundhara Volam TX_TOTAL_DISCARDS, 28720c1d28eSVasundhara Volam }; 28820c1d28eSVasundhara Volam 28920c1d28eSVasundhara Volam static struct { 29020c1d28eSVasundhara Volam u64 counter; 29120c1d28eSVasundhara Volam char string[ETH_GSTRING_LEN]; 29220c1d28eSVasundhara Volam } bnxt_sw_func_stats[] = { 29320c1d28eSVasundhara Volam {0, "rx_total_discard_pkts"}, 29420c1d28eSVasundhara Volam {0, "tx_total_discard_pkts"}, 29520c1d28eSVasundhara Volam }; 29620c1d28eSVasundhara Volam 2978ddc9aaaSMichael Chan static const struct { 2988ddc9aaaSMichael Chan long offset; 2998ddc9aaaSMichael Chan char string[ETH_GSTRING_LEN]; 3008ddc9aaaSMichael Chan } bnxt_port_stats_arr[] = { 3018ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_64b_frames), 3028ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_65b_127b_frames), 3038ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_128b_255b_frames), 3048ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_256b_511b_frames), 3058ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames), 3066fc92c33SMichael Chan BNXT_RX_STATS_ENTRY(rx_1024b_1518b_frames), 3078ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_vlan_frames), 3088ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames), 3098ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames), 3108ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames), 3118ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames), 3128ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_total_frames), 3138ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ucast_frames), 3148ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mcast_frames), 3158ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bcast_frames), 3168ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_fcs_err_frames), 3178ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ctrl_frames), 3188ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pause_frames), 3198ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_frames), 3208ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_align_err_frames), 3218ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ovrsz_frames), 3228ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_jbr_frames), 3238ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mtu_err_frames), 3248ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_tagged_frames), 3258ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_double_tagged_frames), 3268ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_frames), 327c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0), 328c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1), 329c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2), 330c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3), 331c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4), 332c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5), 333c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6), 334c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7), 3358ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_undrsz_frames), 3368ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_events), 3378ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration), 3388ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bytes), 3398ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_bytes), 3408ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_frames), 341699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_discard), 342699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_err), 3438ddc9aaaSMichael Chan 3448ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_64b_frames), 3458ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_65b_127b_frames), 3468ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_128b_255b_frames), 3478ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_256b_511b_frames), 3488ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames), 3496fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1024b_1518b_frames), 3508ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_vlan_frames), 3516fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1519b_2047b_frames), 3528ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames), 3538ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames), 3548ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames), 3558ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_frames), 3568ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_frames), 3578ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_ucast_frames), 3588ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_mcast_frames), 3598ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bcast_frames), 3608ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pause_frames), 3618ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_frames), 3628ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_jabber_frames), 3638ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fcs_err_frames), 3648ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_err), 3658ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fifo_underruns), 366c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0), 367c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1), 368c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2), 369c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3), 370c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4), 371c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5), 372c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6), 373c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7), 3748ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_events), 3758ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration), 3768ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_collisions), 3778ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bytes), 378699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_xthol_frames), 379699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_discard), 380699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_error), 3818ddc9aaaSMichael Chan }; 3828ddc9aaaSMichael Chan 38300db3cbaSVasundhara Volam static const struct { 38400db3cbaSVasundhara Volam long offset; 38500db3cbaSVasundhara Volam char string[ETH_GSTRING_LEN]; 38600db3cbaSVasundhara Volam } bnxt_port_stats_ext_arr[] = { 38700db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(link_down_events), 38800db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events), 38900db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_pause_events), 39000db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events), 39100db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events), 39236e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRIES, 39336e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRIES, 3944a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bits), 3954a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_buffer_passed_threshold), 3964a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_pcs_symbol_err), 3974a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_corrected_bits), 3982792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES, 39936e53349SMichael Chan }; 40036e53349SMichael Chan 40136e53349SMichael Chan static const struct { 40236e53349SMichael Chan long offset; 40336e53349SMichael Chan char string[ETH_GSTRING_LEN]; 40436e53349SMichael Chan } bnxt_tx_port_stats_ext_arr[] = { 40536e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRIES, 40636e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRIES, 40700db3cbaSVasundhara Volam }; 40800db3cbaSVasundhara Volam 409e37fed79SMichael Chan static const struct { 410e37fed79SMichael Chan long base_off; 411e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 412e37fed79SMichael Chan } bnxt_rx_bytes_pri_arr[] = { 413e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_bytes), 414e37fed79SMichael Chan }; 415e37fed79SMichael Chan 416e37fed79SMichael Chan static const struct { 417e37fed79SMichael Chan long base_off; 418e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 419e37fed79SMichael Chan } bnxt_rx_pkts_pri_arr[] = { 420e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_packets), 421e37fed79SMichael Chan }; 422e37fed79SMichael Chan 423e37fed79SMichael Chan static const struct { 424e37fed79SMichael Chan long base_off; 425e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 426e37fed79SMichael Chan } bnxt_tx_bytes_pri_arr[] = { 427e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_bytes), 428e37fed79SMichael Chan }; 429e37fed79SMichael Chan 430e37fed79SMichael Chan static const struct { 431e37fed79SMichael Chan long base_off; 432e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 433e37fed79SMichael Chan } bnxt_tx_pkts_pri_arr[] = { 434e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_packets), 435e37fed79SMichael Chan }; 436e37fed79SMichael Chan 43755e4398dSVasundhara Volam static const struct { 43855e4398dSVasundhara Volam long offset; 43955e4398dSVasundhara Volam char string[ETH_GSTRING_LEN]; 44055e4398dSVasundhara Volam } bnxt_pcie_stats_arr[] = { 44155e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_pl_signal_integrity), 44255e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_dl_signal_integrity), 44355e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tl_signal_integrity), 44455e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_link_integrity), 44555e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tx_traffic_rate), 44655e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_rx_traffic_rate), 44755e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_tx_dllp_statistics), 44855e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_rx_dllp_statistics), 44955e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_equalization_time), 45055e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[0]), 45155e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[2]), 45255e4398dSVasundhara Volam BNXT_PCIE_STATS_ENTRY(pcie_recovery_histogram), 45355e4398dSVasundhara Volam }; 45455e4398dSVasundhara Volam 45520c1d28eSVasundhara Volam #define BNXT_NUM_SW_FUNC_STATS ARRAY_SIZE(bnxt_sw_func_stats) 4568ddc9aaaSMichael Chan #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr) 457e37fed79SMichael Chan #define BNXT_NUM_STATS_PRI \ 458e37fed79SMichael Chan (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \ 459e37fed79SMichael Chan ARRAY_SIZE(bnxt_rx_pkts_pri_arr) + \ 460e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_bytes_pri_arr) + \ 461e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_pkts_pri_arr)) 46255e4398dSVasundhara Volam #define BNXT_NUM_PCIE_STATS ARRAY_SIZE(bnxt_pcie_stats_arr) 4638ddc9aaaSMichael Chan 464ee79566eSMichael Chan static int bnxt_get_num_ring_stats(struct bnxt *bp) 465ee79566eSMichael Chan { 466ee79566eSMichael Chan int num_stats; 467ee79566eSMichael Chan 468ee79566eSMichael Chan num_stats = ARRAY_SIZE(bnxt_ring_stats_str) + 469ee79566eSMichael Chan ARRAY_SIZE(bnxt_ring_sw_stats_str); 470ee79566eSMichael Chan if (BNXT_SUPPORTS_TPA(bp)) 471ee79566eSMichael Chan num_stats += ARRAY_SIZE(bnxt_ring_tpa_stats_str); 472ee79566eSMichael Chan return num_stats * bp->cp_nr_rings; 473ee79566eSMichael Chan } 474ee79566eSMichael Chan 4755c8227d0SMichael Chan static int bnxt_get_num_stats(struct bnxt *bp) 476c0c050c5SMichael Chan { 477ee79566eSMichael Chan int num_stats = bnxt_get_num_ring_stats(bp); 4788ddc9aaaSMichael Chan 47920c1d28eSVasundhara Volam num_stats += BNXT_NUM_SW_FUNC_STATS; 48020c1d28eSVasundhara Volam 4818ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) 4828ddc9aaaSMichael Chan num_stats += BNXT_NUM_PORT_STATS; 4838ddc9aaaSMichael Chan 484e37fed79SMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 48536e53349SMichael Chan num_stats += bp->fw_rx_stats_ext_size + 48636e53349SMichael Chan bp->fw_tx_stats_ext_size; 487e37fed79SMichael Chan if (bp->pri2cos_valid) 488e37fed79SMichael Chan num_stats += BNXT_NUM_STATS_PRI; 489e37fed79SMichael Chan } 49000db3cbaSVasundhara Volam 49155e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) 49255e4398dSVasundhara Volam num_stats += BNXT_NUM_PCIE_STATS; 49355e4398dSVasundhara Volam 4948ddc9aaaSMichael Chan return num_stats; 4958ddc9aaaSMichael Chan } 4965c8227d0SMichael Chan 4975c8227d0SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 4985c8227d0SMichael Chan { 4995c8227d0SMichael Chan struct bnxt *bp = netdev_priv(dev); 5005c8227d0SMichael Chan 5015c8227d0SMichael Chan switch (sset) { 5025c8227d0SMichael Chan case ETH_SS_STATS: 5035c8227d0SMichael Chan return bnxt_get_num_stats(bp); 504eb513658SMichael Chan case ETH_SS_TEST: 505eb513658SMichael Chan if (!bp->num_tests) 506eb513658SMichael Chan return -EOPNOTSUPP; 507eb513658SMichael Chan return bp->num_tests; 508c0c050c5SMichael Chan default: 509c0c050c5SMichael Chan return -EOPNOTSUPP; 510c0c050c5SMichael Chan } 511c0c050c5SMichael Chan } 512c0c050c5SMichael Chan 513c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 514c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 515c0c050c5SMichael Chan { 516c0c050c5SMichael Chan u32 i, j = 0; 517c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 518ee79566eSMichael Chan u32 stat_fields = ARRAY_SIZE(bnxt_ring_stats_str); 519ee79566eSMichael Chan 520ee79566eSMichael Chan if (BNXT_SUPPORTS_TPA(bp)) 521ee79566eSMichael Chan stat_fields += ARRAY_SIZE(bnxt_ring_tpa_stats_str); 522c0c050c5SMichael Chan 523fd3ab1c7SMichael Chan if (!bp->bnapi) { 524ee79566eSMichael Chan j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS; 525fd3ab1c7SMichael Chan goto skip_ring_stats; 526fd3ab1c7SMichael Chan } 527c0c050c5SMichael Chan 52820c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) 52920c1d28eSVasundhara Volam bnxt_sw_func_stats[i].counter = 0; 53020c1d28eSVasundhara Volam 531c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 532c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 533c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 534c0c050c5SMichael Chan __le64 *hw_stats = (__le64 *)cpr->hw_stats; 535c0c050c5SMichael Chan int k; 536c0c050c5SMichael Chan 537c0c050c5SMichael Chan for (k = 0; k < stat_fields; j++, k++) 538c0c050c5SMichael Chan buf[j] = le64_to_cpu(hw_stats[k]); 539c0c050c5SMichael Chan buf[j++] = cpr->rx_l4_csum_errors; 54083eb5c5cSMichael Chan buf[j++] = cpr->missed_irqs; 54120c1d28eSVasundhara Volam 54220c1d28eSVasundhara Volam bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter += 54320c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->rx_discard_pkts); 54420c1d28eSVasundhara Volam bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter += 54520c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->tx_discard_pkts); 546c0c050c5SMichael Chan } 54720c1d28eSVasundhara Volam 54820c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++) 54920c1d28eSVasundhara Volam buf[j] = bnxt_sw_func_stats[i].counter; 55020c1d28eSVasundhara Volam 551fd3ab1c7SMichael Chan skip_ring_stats: 5528ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 5538ddc9aaaSMichael Chan __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats; 5548ddc9aaaSMichael Chan 5558ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) { 5568ddc9aaaSMichael Chan buf[j] = le64_to_cpu(*(port_stats + 5578ddc9aaaSMichael Chan bnxt_port_stats_arr[i].offset)); 5588ddc9aaaSMichael Chan } 5598ddc9aaaSMichael Chan } 56000db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 56136e53349SMichael Chan __le64 *rx_port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext; 56236e53349SMichael Chan __le64 *tx_port_stats_ext = (__le64 *)bp->hw_tx_port_stats_ext; 56300db3cbaSVasundhara Volam 56436e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) { 56536e53349SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + 56600db3cbaSVasundhara Volam bnxt_port_stats_ext_arr[i].offset)); 56700db3cbaSVasundhara Volam } 56836e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++, j++) { 56936e53349SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + 57036e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].offset)); 57136e53349SMichael Chan } 572e37fed79SMichael Chan if (bp->pri2cos_valid) { 573e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 574e37fed79SMichael Chan long n = bnxt_rx_bytes_pri_arr[i].base_off + 575e37fed79SMichael Chan bp->pri2cos[i]; 576e37fed79SMichael Chan 577e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 578e37fed79SMichael Chan } 579e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 580e37fed79SMichael Chan long n = bnxt_rx_pkts_pri_arr[i].base_off + 581e37fed79SMichael Chan bp->pri2cos[i]; 582e37fed79SMichael Chan 583e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 584e37fed79SMichael Chan } 585e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 586e37fed79SMichael Chan long n = bnxt_tx_bytes_pri_arr[i].base_off + 587e37fed79SMichael Chan bp->pri2cos[i]; 588e37fed79SMichael Chan 589e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 590e37fed79SMichael Chan } 591e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 592e37fed79SMichael Chan long n = bnxt_tx_pkts_pri_arr[i].base_off + 593e37fed79SMichael Chan bp->pri2cos[i]; 594e37fed79SMichael Chan 595e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 596e37fed79SMichael Chan } 597e37fed79SMichael Chan } 59800db3cbaSVasundhara Volam } 59955e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) { 60055e4398dSVasundhara Volam __le64 *pcie_stats = (__le64 *)bp->hw_pcie_stats; 60155e4398dSVasundhara Volam 60255e4398dSVasundhara Volam for (i = 0; i < BNXT_NUM_PCIE_STATS; i++, j++) { 60355e4398dSVasundhara Volam buf[j] = le64_to_cpu(*(pcie_stats + 60455e4398dSVasundhara Volam bnxt_pcie_stats_arr[i].offset)); 60555e4398dSVasundhara Volam } 60655e4398dSVasundhara Volam } 607c0c050c5SMichael Chan } 608c0c050c5SMichael Chan 609c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 610c0c050c5SMichael Chan { 611c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 612ee79566eSMichael Chan u32 i, j, num_str; 613c0c050c5SMichael Chan 614c0c050c5SMichael Chan switch (stringset) { 615c0c050c5SMichael Chan case ETH_SS_STATS: 616c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 617ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_stats_str); 618ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 619ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 620ee79566eSMichael Chan bnxt_ring_stats_str[j]); 621c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 622ee79566eSMichael Chan } 623ee79566eSMichael Chan if (!BNXT_SUPPORTS_TPA(bp)) 624ee79566eSMichael Chan goto skip_tpa_stats; 625ee79566eSMichael Chan 626ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_tpa_stats_str); 627ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 628ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 629ee79566eSMichael Chan bnxt_ring_tpa_stats_str[j]); 630c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 631ee79566eSMichael Chan } 632ee79566eSMichael Chan skip_tpa_stats: 633ee79566eSMichael Chan num_str = ARRAY_SIZE(bnxt_ring_sw_stats_str); 634ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 635ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 636ee79566eSMichael Chan bnxt_ring_sw_stats_str[j]); 637c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 638ee79566eSMichael Chan } 639c0c050c5SMichael Chan } 64020c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) { 64120c1d28eSVasundhara Volam strcpy(buf, bnxt_sw_func_stats[i].string); 64220c1d28eSVasundhara Volam buf += ETH_GSTRING_LEN; 64320c1d28eSVasundhara Volam } 64420c1d28eSVasundhara Volam 6458ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 6468ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++) { 6478ddc9aaaSMichael Chan strcpy(buf, bnxt_port_stats_arr[i].string); 6488ddc9aaaSMichael Chan buf += ETH_GSTRING_LEN; 6498ddc9aaaSMichael Chan } 6508ddc9aaaSMichael Chan } 65100db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 65236e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++) { 65300db3cbaSVasundhara Volam strcpy(buf, bnxt_port_stats_ext_arr[i].string); 65400db3cbaSVasundhara Volam buf += ETH_GSTRING_LEN; 65500db3cbaSVasundhara Volam } 65636e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++) { 65736e53349SMichael Chan strcpy(buf, 65836e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].string); 65936e53349SMichael Chan buf += ETH_GSTRING_LEN; 66036e53349SMichael Chan } 661e37fed79SMichael Chan if (bp->pri2cos_valid) { 662e37fed79SMichael Chan for (i = 0; i < 8; i++) { 663e37fed79SMichael Chan strcpy(buf, 664e37fed79SMichael Chan bnxt_rx_bytes_pri_arr[i].string); 665e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 666e37fed79SMichael Chan } 667e37fed79SMichael Chan for (i = 0; i < 8; i++) { 668e37fed79SMichael Chan strcpy(buf, 669e37fed79SMichael Chan bnxt_rx_pkts_pri_arr[i].string); 670e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 671e37fed79SMichael Chan } 672e37fed79SMichael Chan for (i = 0; i < 8; i++) { 673e37fed79SMichael Chan strcpy(buf, 674e37fed79SMichael Chan bnxt_tx_bytes_pri_arr[i].string); 675e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 676e37fed79SMichael Chan } 677e37fed79SMichael Chan for (i = 0; i < 8; i++) { 678e37fed79SMichael Chan strcpy(buf, 679e37fed79SMichael Chan bnxt_tx_pkts_pri_arr[i].string); 680e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 681e37fed79SMichael Chan } 682e37fed79SMichael Chan } 68300db3cbaSVasundhara Volam } 68455e4398dSVasundhara Volam if (bp->flags & BNXT_FLAG_PCIE_STATS) { 68555e4398dSVasundhara Volam for (i = 0; i < BNXT_NUM_PCIE_STATS; i++) { 68655e4398dSVasundhara Volam strcpy(buf, bnxt_pcie_stats_arr[i].string); 68755e4398dSVasundhara Volam buf += ETH_GSTRING_LEN; 68855e4398dSVasundhara Volam } 68955e4398dSVasundhara Volam } 690c0c050c5SMichael Chan break; 691eb513658SMichael Chan case ETH_SS_TEST: 692eb513658SMichael Chan if (bp->num_tests) 693eb513658SMichael Chan memcpy(buf, bp->test_info->string, 694eb513658SMichael Chan bp->num_tests * ETH_GSTRING_LEN); 695eb513658SMichael Chan break; 696c0c050c5SMichael Chan default: 697c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 698c0c050c5SMichael Chan stringset); 699c0c050c5SMichael Chan break; 700c0c050c5SMichael Chan } 701c0c050c5SMichael Chan } 702c0c050c5SMichael Chan 703c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 704c0c050c5SMichael Chan struct ethtool_ringparam *ering) 705c0c050c5SMichael Chan { 706c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 707c0c050c5SMichael Chan 708c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 709c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 710c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 711c0c050c5SMichael Chan 712c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 713c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 714c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 715c0c050c5SMichael Chan } 716c0c050c5SMichael Chan 717c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 718c0c050c5SMichael Chan struct ethtool_ringparam *ering) 719c0c050c5SMichael Chan { 720c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 721c0c050c5SMichael Chan 722c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 723c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 724c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 725c0c050c5SMichael Chan return -EINVAL; 726c0c050c5SMichael Chan 727c0c050c5SMichael Chan if (netif_running(dev)) 728c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 729c0c050c5SMichael Chan 730c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 731c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 732c0c050c5SMichael Chan bnxt_set_ring_params(bp); 733c0c050c5SMichael Chan 734c0c050c5SMichael Chan if (netif_running(dev)) 735c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 736c0c050c5SMichael Chan 737c0c050c5SMichael Chan return 0; 738c0c050c5SMichael Chan } 739c0c050c5SMichael Chan 740c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 741c0c050c5SMichael Chan struct ethtool_channels *channel) 742c0c050c5SMichael Chan { 743c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 744db4723b3SMichael Chan struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 745c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 746db4723b3SMichael Chan int max_tx_sch_inputs; 747db4723b3SMichael Chan 748db4723b3SMichael Chan /* Get the most up-to-date max_tx_sch_inputs. */ 749f1ca94deSMichael Chan if (BNXT_NEW_RM(bp)) 750db4723b3SMichael Chan bnxt_hwrm_func_resc_qcaps(bp, false); 751db4723b3SMichael Chan max_tx_sch_inputs = hw_resc->max_tx_sch_inputs; 752c0c050c5SMichael Chan 7536e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 754db4723b3SMichael Chan if (max_tx_sch_inputs) 755db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 756a79a5276SMichael Chan channel->max_combined = min_t(int, max_rx_rings, max_tx_rings); 757068c9ec6SMichael Chan 75818d6e4e2SSatish Baddipadige if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) { 75918d6e4e2SSatish Baddipadige max_rx_rings = 0; 76018d6e4e2SSatish Baddipadige max_tx_rings = 0; 76118d6e4e2SSatish Baddipadige } 762db4723b3SMichael Chan if (max_tx_sch_inputs) 763db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 76418d6e4e2SSatish Baddipadige 765c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 766c0c050c5SMichael Chan if (tcs > 1) 767c0c050c5SMichael Chan max_tx_rings /= tcs; 768c0c050c5SMichael Chan 769c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 770c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 771c0c050c5SMichael Chan channel->max_other = 0; 772068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 773068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 77476595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp)) 77576595193SPrashant Sreedharan channel->combined_count--; 776068c9ec6SMichael Chan } else { 77776595193SPrashant Sreedharan if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) { 778c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 779c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 780c0c050c5SMichael Chan } 781068c9ec6SMichael Chan } 78276595193SPrashant Sreedharan } 783c0c050c5SMichael Chan 784c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 785c0c050c5SMichael Chan struct ethtool_channels *channel) 786c0c050c5SMichael Chan { 787c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 788d1e7925eSMichael Chan int req_tx_rings, req_rx_rings, tcs; 789068c9ec6SMichael Chan bool sh = false; 7905f449249SMichael Chan int tx_xdp = 0; 791d1e7925eSMichael Chan int rc = 0; 792c0c050c5SMichael Chan 793068c9ec6SMichael Chan if (channel->other_count) 794c0c050c5SMichael Chan return -EINVAL; 795c0c050c5SMichael Chan 796068c9ec6SMichael Chan if (!channel->combined_count && 797068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 798068c9ec6SMichael Chan return -EINVAL; 799068c9ec6SMichael Chan 800068c9ec6SMichael Chan if (channel->combined_count && 801068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 802068c9ec6SMichael Chan return -EINVAL; 803068c9ec6SMichael Chan 80476595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count || 80576595193SPrashant Sreedharan channel->tx_count)) 80676595193SPrashant Sreedharan return -EINVAL; 80776595193SPrashant Sreedharan 808068c9ec6SMichael Chan if (channel->combined_count) 809068c9ec6SMichael Chan sh = true; 810068c9ec6SMichael Chan 811c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 812c0c050c5SMichael Chan 813391be5c2SMichael Chan req_tx_rings = sh ? channel->combined_count : channel->tx_count; 814d1e7925eSMichael Chan req_rx_rings = sh ? channel->combined_count : channel->rx_count; 8155f449249SMichael Chan if (bp->tx_nr_rings_xdp) { 8165f449249SMichael Chan if (!sh) { 8175f449249SMichael Chan netdev_err(dev, "Only combined mode supported when XDP is enabled.\n"); 8185f449249SMichael Chan return -EINVAL; 8195f449249SMichael Chan } 8205f449249SMichael Chan tx_xdp = req_rx_rings; 8215f449249SMichael Chan } 82298fdbe73SMichael Chan rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp); 823d1e7925eSMichael Chan if (rc) { 824d1e7925eSMichael Chan netdev_warn(dev, "Unable to allocate the requested rings\n"); 825d1e7925eSMichael Chan return rc; 826391be5c2SMichael Chan } 827391be5c2SMichael Chan 828c0c050c5SMichael Chan if (netif_running(dev)) { 829c0c050c5SMichael Chan if (BNXT_PF(bp)) { 830c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 831c0c050c5SMichael Chan * before PF unload 832c0c050c5SMichael Chan */ 833c0c050c5SMichael Chan } 834c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 835c0c050c5SMichael Chan if (rc) { 836c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 837c0c050c5SMichael Chan rc); 838c0c050c5SMichael Chan return rc; 839c0c050c5SMichael Chan } 840c0c050c5SMichael Chan } 841c0c050c5SMichael Chan 842068c9ec6SMichael Chan if (sh) { 843068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 844d1e7925eSMichael Chan bp->rx_nr_rings = channel->combined_count; 845d1e7925eSMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 846068c9ec6SMichael Chan } else { 847068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 848c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 849c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 850068c9ec6SMichael Chan } 8515f449249SMichael Chan bp->tx_nr_rings_xdp = tx_xdp; 8525f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp; 853c0c050c5SMichael Chan if (tcs > 1) 8545f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp; 855068c9ec6SMichael Chan 856068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 857068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 858068c9ec6SMichael Chan 8592bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 8602bcfa6f6SMichael Chan netdev_update_features(dev); 861c0c050c5SMichael Chan if (netif_running(dev)) { 862c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 863c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 864c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 865c0c050c5SMichael Chan * to renable 866c0c050c5SMichael Chan */ 867c0c050c5SMichael Chan } 868d8c09f19SMichael Chan } else { 8691b3f0b75SMichael Chan rc = bnxt_reserve_rings(bp, true); 870c0c050c5SMichael Chan } 871c0c050c5SMichael Chan 872c0c050c5SMichael Chan return rc; 873c0c050c5SMichael Chan } 874c0c050c5SMichael Chan 875c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 876c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 877c0c050c5SMichael Chan u32 *rule_locs) 878c0c050c5SMichael Chan { 879c0c050c5SMichael Chan int i, j = 0; 880c0c050c5SMichael Chan 881c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 882c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 883c0c050c5SMichael Chan struct hlist_head *head; 884c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 885c0c050c5SMichael Chan 886c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 887c0c050c5SMichael Chan rcu_read_lock(); 888c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 889c0c050c5SMichael Chan if (j == cmd->rule_cnt) 890c0c050c5SMichael Chan break; 891c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 892c0c050c5SMichael Chan } 893c0c050c5SMichael Chan rcu_read_unlock(); 894c0c050c5SMichael Chan if (j == cmd->rule_cnt) 895c0c050c5SMichael Chan break; 896c0c050c5SMichael Chan } 897c0c050c5SMichael Chan cmd->rule_cnt = j; 898c0c050c5SMichael Chan return 0; 899c0c050c5SMichael Chan } 900c0c050c5SMichael Chan 901c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 902c0c050c5SMichael Chan { 903c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 904c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 905c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 906c0c050c5SMichael Chan struct flow_keys *fkeys; 907c0c050c5SMichael Chan int i, rc = -EINVAL; 908c0c050c5SMichael Chan 909b721cfafSstephen hemminger if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 910c0c050c5SMichael Chan return rc; 911c0c050c5SMichael Chan 912c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 913c0c050c5SMichael Chan struct hlist_head *head; 914c0c050c5SMichael Chan 915c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 916c0c050c5SMichael Chan rcu_read_lock(); 917c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 918c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 919c0c050c5SMichael Chan goto fltr_found; 920c0c050c5SMichael Chan } 921c0c050c5SMichael Chan rcu_read_unlock(); 922c0c050c5SMichael Chan } 923c0c050c5SMichael Chan return rc; 924c0c050c5SMichael Chan 925c0c050c5SMichael Chan fltr_found: 926c0c050c5SMichael Chan fkeys = &fltr->fkeys; 927dda0e746SMichael Chan if (fkeys->basic.n_proto == htons(ETH_P_IP)) { 928c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 929c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 930c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 931c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 932c0c050c5SMichael Chan else 933c0c050c5SMichael Chan goto fltr_err; 934c0c050c5SMichael Chan 935c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 936c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 937c0c050c5SMichael Chan 938c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 939c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 940c0c050c5SMichael Chan 941c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 942c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 943c0c050c5SMichael Chan 944c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 945c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 946dda0e746SMichael Chan } else { 947dda0e746SMichael Chan int i; 948dda0e746SMichael Chan 949dda0e746SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 950dda0e746SMichael Chan fs->flow_type = TCP_V6_FLOW; 951dda0e746SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 952dda0e746SMichael Chan fs->flow_type = UDP_V6_FLOW; 953dda0e746SMichael Chan else 954dda0e746SMichael Chan goto fltr_err; 955dda0e746SMichael Chan 956dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] = 957dda0e746SMichael Chan fkeys->addrs.v6addrs.src; 958dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] = 959dda0e746SMichael Chan fkeys->addrs.v6addrs.dst; 960dda0e746SMichael Chan for (i = 0; i < 4; i++) { 961dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0); 962dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0); 963dda0e746SMichael Chan } 964dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src; 965dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0); 966dda0e746SMichael Chan 967dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst; 968dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0); 969dda0e746SMichael Chan } 970c0c050c5SMichael Chan 971c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 972c0c050c5SMichael Chan rc = 0; 973c0c050c5SMichael Chan 974c0c050c5SMichael Chan fltr_err: 975c0c050c5SMichael Chan rcu_read_unlock(); 976c0c050c5SMichael Chan 977c0c050c5SMichael Chan return rc; 978c0c050c5SMichael Chan } 979a011952aSMichael Chan #endif 980a011952aSMichael Chan 981a011952aSMichael Chan static u64 get_ethtool_ipv4_rss(struct bnxt *bp) 982a011952aSMichael Chan { 983a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4) 984a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 985a011952aSMichael Chan return 0; 986a011952aSMichael Chan } 987a011952aSMichael Chan 988a011952aSMichael Chan static u64 get_ethtool_ipv6_rss(struct bnxt *bp) 989a011952aSMichael Chan { 990a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6) 991a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 992a011952aSMichael Chan return 0; 993a011952aSMichael Chan } 994a011952aSMichael Chan 995a011952aSMichael Chan static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 996a011952aSMichael Chan { 997a011952aSMichael Chan cmd->data = 0; 998a011952aSMichael Chan switch (cmd->flow_type) { 999a011952aSMichael Chan case TCP_V4_FLOW: 1000a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) 1001a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1002a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1003a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1004a011952aSMichael Chan break; 1005a011952aSMichael Chan case UDP_V4_FLOW: 1006a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4) 1007a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1008a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1009a011952aSMichael Chan /* fall through */ 1010a011952aSMichael Chan case SCTP_V4_FLOW: 1011a011952aSMichael Chan case AH_ESP_V4_FLOW: 1012a011952aSMichael Chan case AH_V4_FLOW: 1013a011952aSMichael Chan case ESP_V4_FLOW: 1014a011952aSMichael Chan case IPV4_FLOW: 1015a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1016a011952aSMichael Chan break; 1017a011952aSMichael Chan 1018a011952aSMichael Chan case TCP_V6_FLOW: 1019a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) 1020a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1021a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1022a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1023a011952aSMichael Chan break; 1024a011952aSMichael Chan case UDP_V6_FLOW: 1025a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6) 1026a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1027a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1028a011952aSMichael Chan /* fall through */ 1029a011952aSMichael Chan case SCTP_V6_FLOW: 1030a011952aSMichael Chan case AH_ESP_V6_FLOW: 1031a011952aSMichael Chan case AH_V6_FLOW: 1032a011952aSMichael Chan case ESP_V6_FLOW: 1033a011952aSMichael Chan case IPV6_FLOW: 1034a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1035a011952aSMichael Chan break; 1036a011952aSMichael Chan } 1037a011952aSMichael Chan return 0; 1038a011952aSMichael Chan } 1039a011952aSMichael Chan 1040a011952aSMichael Chan #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3) 1041a011952aSMichael Chan #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST) 1042a011952aSMichael Chan 1043a011952aSMichael Chan static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1044a011952aSMichael Chan { 1045a011952aSMichael Chan u32 rss_hash_cfg = bp->rss_hash_cfg; 1046a011952aSMichael Chan int tuple, rc = 0; 1047a011952aSMichael Chan 1048a011952aSMichael Chan if (cmd->data == RXH_4TUPLE) 1049a011952aSMichael Chan tuple = 4; 1050a011952aSMichael Chan else if (cmd->data == RXH_2TUPLE) 1051a011952aSMichael Chan tuple = 2; 1052a011952aSMichael Chan else if (!cmd->data) 1053a011952aSMichael Chan tuple = 0; 1054a011952aSMichael Chan else 1055a011952aSMichael Chan return -EINVAL; 1056a011952aSMichael Chan 1057a011952aSMichael Chan if (cmd->flow_type == TCP_V4_FLOW) { 1058a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1059a011952aSMichael Chan if (tuple == 4) 1060a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1061a011952aSMichael Chan } else if (cmd->flow_type == UDP_V4_FLOW) { 1062a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1063a011952aSMichael Chan return -EINVAL; 1064a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1065a011952aSMichael Chan if (tuple == 4) 1066a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1067a011952aSMichael Chan } else if (cmd->flow_type == TCP_V6_FLOW) { 1068a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1069a011952aSMichael Chan if (tuple == 4) 1070a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1071a011952aSMichael Chan } else if (cmd->flow_type == UDP_V6_FLOW) { 1072a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1073a011952aSMichael Chan return -EINVAL; 1074a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1075a011952aSMichael Chan if (tuple == 4) 1076a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1077a011952aSMichael Chan } else if (tuple == 4) { 1078a011952aSMichael Chan return -EINVAL; 1079a011952aSMichael Chan } 1080a011952aSMichael Chan 1081a011952aSMichael Chan switch (cmd->flow_type) { 1082a011952aSMichael Chan case TCP_V4_FLOW: 1083a011952aSMichael Chan case UDP_V4_FLOW: 1084a011952aSMichael Chan case SCTP_V4_FLOW: 1085a011952aSMichael Chan case AH_ESP_V4_FLOW: 1086a011952aSMichael Chan case AH_V4_FLOW: 1087a011952aSMichael Chan case ESP_V4_FLOW: 1088a011952aSMichael Chan case IPV4_FLOW: 1089a011952aSMichael Chan if (tuple == 2) 1090a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1091a011952aSMichael Chan else if (!tuple) 1092a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1093a011952aSMichael Chan break; 1094a011952aSMichael Chan 1095a011952aSMichael Chan case TCP_V6_FLOW: 1096a011952aSMichael Chan case UDP_V6_FLOW: 1097a011952aSMichael Chan case SCTP_V6_FLOW: 1098a011952aSMichael Chan case AH_ESP_V6_FLOW: 1099a011952aSMichael Chan case AH_V6_FLOW: 1100a011952aSMichael Chan case ESP_V6_FLOW: 1101a011952aSMichael Chan case IPV6_FLOW: 1102a011952aSMichael Chan if (tuple == 2) 1103a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1104a011952aSMichael Chan else if (!tuple) 1105a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1106a011952aSMichael Chan break; 1107a011952aSMichael Chan } 1108a011952aSMichael Chan 1109a011952aSMichael Chan if (bp->rss_hash_cfg == rss_hash_cfg) 1110a011952aSMichael Chan return 0; 1111a011952aSMichael Chan 1112a011952aSMichael Chan bp->rss_hash_cfg = rss_hash_cfg; 1113a011952aSMichael Chan if (netif_running(bp->dev)) { 1114a011952aSMichael Chan bnxt_close_nic(bp, false, false); 1115a011952aSMichael Chan rc = bnxt_open_nic(bp, false, false); 1116a011952aSMichael Chan } 1117a011952aSMichael Chan return rc; 1118a011952aSMichael Chan } 1119c0c050c5SMichael Chan 1120c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 1121c0c050c5SMichael Chan u32 *rule_locs) 1122c0c050c5SMichael Chan { 1123c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1124c0c050c5SMichael Chan int rc = 0; 1125c0c050c5SMichael Chan 1126c0c050c5SMichael Chan switch (cmd->cmd) { 1127a011952aSMichael Chan #ifdef CONFIG_RFS_ACCEL 1128c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 1129c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 1130c0c050c5SMichael Chan break; 1131c0c050c5SMichael Chan 1132c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 1133c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 1134c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 1135c0c050c5SMichael Chan break; 1136c0c050c5SMichael Chan 1137c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 1138c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 1139c0c050c5SMichael Chan break; 1140c0c050c5SMichael Chan 1141c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 1142c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 1143c0c050c5SMichael Chan break; 1144a011952aSMichael Chan #endif 1145a011952aSMichael Chan 1146a011952aSMichael Chan case ETHTOOL_GRXFH: 1147a011952aSMichael Chan rc = bnxt_grxfh(bp, cmd); 1148a011952aSMichael Chan break; 1149c0c050c5SMichael Chan 1150c0c050c5SMichael Chan default: 1151c0c050c5SMichael Chan rc = -EOPNOTSUPP; 1152c0c050c5SMichael Chan break; 1153c0c050c5SMichael Chan } 1154c0c050c5SMichael Chan 1155c0c050c5SMichael Chan return rc; 1156c0c050c5SMichael Chan } 1157a011952aSMichael Chan 1158a011952aSMichael Chan static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) 1159a011952aSMichael Chan { 1160a011952aSMichael Chan struct bnxt *bp = netdev_priv(dev); 1161a011952aSMichael Chan int rc; 1162a011952aSMichael Chan 1163a011952aSMichael Chan switch (cmd->cmd) { 1164a011952aSMichael Chan case ETHTOOL_SRXFH: 1165a011952aSMichael Chan rc = bnxt_srxfh(bp, cmd); 1166a011952aSMichael Chan break; 1167a011952aSMichael Chan 1168a011952aSMichael Chan default: 1169a011952aSMichael Chan rc = -EOPNOTSUPP; 1170a011952aSMichael Chan break; 1171a011952aSMichael Chan } 1172a011952aSMichael Chan return rc; 1173a011952aSMichael Chan } 1174c0c050c5SMichael Chan 1175c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 1176c0c050c5SMichael Chan { 1177c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 1178c0c050c5SMichael Chan } 1179c0c050c5SMichael Chan 1180c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 1181c0c050c5SMichael Chan { 1182c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 1183c0c050c5SMichael Chan } 1184c0c050c5SMichael Chan 1185c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 1186c0c050c5SMichael Chan u8 *hfunc) 1187c0c050c5SMichael Chan { 1188c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 11897991cb9cSMichael Chan struct bnxt_vnic_info *vnic; 1190c0c050c5SMichael Chan int i = 0; 1191c0c050c5SMichael Chan 1192c0c050c5SMichael Chan if (hfunc) 1193c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 1194c0c050c5SMichael Chan 11957991cb9cSMichael Chan if (!bp->vnic_info) 11967991cb9cSMichael Chan return 0; 11977991cb9cSMichael Chan 11987991cb9cSMichael Chan vnic = &bp->vnic_info[0]; 11997991cb9cSMichael Chan if (indir && vnic->rss_table) { 1200c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 1201c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 12027991cb9cSMichael Chan } 1203c0c050c5SMichael Chan 12047991cb9cSMichael Chan if (key && vnic->rss_hash_key) 1205c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 1206c0c050c5SMichael Chan 1207c0c050c5SMichael Chan return 0; 1208c0c050c5SMichael Chan } 1209c0c050c5SMichael Chan 1210c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 1211c0c050c5SMichael Chan struct ethtool_drvinfo *info) 1212c0c050c5SMichael Chan { 1213c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1214c0c050c5SMichael Chan 1215c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 1216c0c050c5SMichael Chan strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 1217431aa1ebSMichael Chan strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); 1218c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 12195c8227d0SMichael Chan info->n_stats = bnxt_get_num_stats(bp); 1220eb513658SMichael Chan info->testinfo_len = bp->num_tests; 1221c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 1222c0c050c5SMichael Chan info->eedump_len = 0; 1223c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 1224c0c050c5SMichael Chan info->regdump_len = 0; 1225c0c050c5SMichael Chan } 1226c0c050c5SMichael Chan 12278e202366SMichael Chan static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 12288e202366SMichael Chan { 12298e202366SMichael Chan struct bnxt *bp = netdev_priv(dev); 12308e202366SMichael Chan 12318e202366SMichael Chan wol->supported = 0; 12328e202366SMichael Chan wol->wolopts = 0; 12338e202366SMichael Chan memset(&wol->sopass, 0, sizeof(wol->sopass)); 12348e202366SMichael Chan if (bp->flags & BNXT_FLAG_WOL_CAP) { 12358e202366SMichael Chan wol->supported = WAKE_MAGIC; 12368e202366SMichael Chan if (bp->wol) 12378e202366SMichael Chan wol->wolopts = WAKE_MAGIC; 12388e202366SMichael Chan } 12398e202366SMichael Chan } 12408e202366SMichael Chan 12415282db6cSMichael Chan static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 12425282db6cSMichael Chan { 12435282db6cSMichael Chan struct bnxt *bp = netdev_priv(dev); 12445282db6cSMichael Chan 12455282db6cSMichael Chan if (wol->wolopts & ~WAKE_MAGIC) 12465282db6cSMichael Chan return -EINVAL; 12475282db6cSMichael Chan 12485282db6cSMichael Chan if (wol->wolopts & WAKE_MAGIC) { 12495282db6cSMichael Chan if (!(bp->flags & BNXT_FLAG_WOL_CAP)) 12505282db6cSMichael Chan return -EINVAL; 12515282db6cSMichael Chan if (!bp->wol) { 12525282db6cSMichael Chan if (bnxt_hwrm_alloc_wol_fltr(bp)) 12535282db6cSMichael Chan return -EBUSY; 12545282db6cSMichael Chan bp->wol = 1; 12555282db6cSMichael Chan } 12565282db6cSMichael Chan } else { 12575282db6cSMichael Chan if (bp->wol) { 12585282db6cSMichael Chan if (bnxt_hwrm_free_wol_fltr(bp)) 12595282db6cSMichael Chan return -EBUSY; 12605282db6cSMichael Chan bp->wol = 0; 12615282db6cSMichael Chan } 12625282db6cSMichael Chan } 12635282db6cSMichael Chan return 0; 12645282db6cSMichael Chan } 12655282db6cSMichael Chan 1266170ce013SMichael Chan u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause) 1267c0c050c5SMichael Chan { 1268c0c050c5SMichael Chan u32 speed_mask = 0; 1269c0c050c5SMichael Chan 1270c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 1271c0c050c5SMichael Chan /* set the advertised speeds */ 1272c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 1273c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 1274c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 1275c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 1276c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 1277c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 1278c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 1279c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 1280c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 12811c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 128227c4d578SMichael Chan 128327c4d578SMichael Chan if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH) 128427c4d578SMichael Chan speed_mask |= ADVERTISED_Pause; 128527c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_TX) 128627c4d578SMichael Chan speed_mask |= ADVERTISED_Asym_Pause; 128727c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_RX) 128827c4d578SMichael Chan speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 128927c4d578SMichael Chan 1290c0c050c5SMichael Chan return speed_mask; 1291c0c050c5SMichael Chan } 1292c0c050c5SMichael Chan 129300c04a92SMichael Chan #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\ 129400c04a92SMichael Chan { \ 129500c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \ 129600c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 129700c04a92SMichael Chan 100baseT_Full); \ 129800c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \ 129900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 130000c04a92SMichael Chan 1000baseT_Full); \ 130100c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \ 130200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 130300c04a92SMichael Chan 10000baseT_Full); \ 130400c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \ 130500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 130600c04a92SMichael Chan 25000baseCR_Full); \ 130700c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \ 130800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 130900c04a92SMichael Chan 40000baseCR4_Full);\ 131000c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \ 131100c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 131200c04a92SMichael Chan 50000baseCR2_Full);\ 131338a21b34SDeepak Khungar if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \ 131438a21b34SDeepak Khungar ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 131538a21b34SDeepak Khungar 100000baseCR4_Full);\ 131600c04a92SMichael Chan if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \ 131700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 131800c04a92SMichael Chan Pause); \ 131900c04a92SMichael Chan if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \ 132000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode( \ 132100c04a92SMichael Chan lk_ksettings, name, Asym_Pause);\ 132200c04a92SMichael Chan } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \ 132300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 132400c04a92SMichael Chan Asym_Pause); \ 132500c04a92SMichael Chan } \ 132600c04a92SMichael Chan } 132700c04a92SMichael Chan 132800c04a92SMichael Chan #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \ 132900c04a92SMichael Chan { \ 133000c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 133100c04a92SMichael Chan 100baseT_Full) || \ 133200c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 133300c04a92SMichael Chan 100baseT_Half)) \ 133400c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \ 133500c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 133600c04a92SMichael Chan 1000baseT_Full) || \ 133700c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 133800c04a92SMichael Chan 1000baseT_Half)) \ 133900c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \ 134000c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 134100c04a92SMichael Chan 10000baseT_Full)) \ 134200c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \ 134300c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 134400c04a92SMichael Chan 25000baseCR_Full)) \ 134500c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \ 134600c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 134700c04a92SMichael Chan 40000baseCR4_Full)) \ 134800c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \ 134900c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135000c04a92SMichael Chan 50000baseCR2_Full)) \ 135100c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \ 135238a21b34SDeepak Khungar if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 135338a21b34SDeepak Khungar 100000baseCR4_Full)) \ 135438a21b34SDeepak Khungar (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \ 135500c04a92SMichael Chan } 135600c04a92SMichael Chan 135700c04a92SMichael Chan static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info, 135800c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 135927c4d578SMichael Chan { 136068515a18SMichael Chan u16 fw_speeds = link_info->advertising; 136127c4d578SMichael Chan u8 fw_pause = 0; 136227c4d578SMichael Chan 136327c4d578SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 136427c4d578SMichael Chan fw_pause = link_info->auto_pause_setting; 136527c4d578SMichael Chan 136600c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising); 136727c4d578SMichael Chan } 136827c4d578SMichael Chan 136900c04a92SMichael Chan static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info, 137000c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 13713277360eSMichael Chan { 13723277360eSMichael Chan u16 fw_speeds = link_info->lp_auto_link_speeds; 13733277360eSMichael Chan u8 fw_pause = 0; 13743277360eSMichael Chan 13753277360eSMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 13763277360eSMichael Chan fw_pause = link_info->lp_pause; 13773277360eSMichael Chan 137800c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, 137900c04a92SMichael Chan lp_advertising); 13803277360eSMichael Chan } 13813277360eSMichael Chan 138200c04a92SMichael Chan static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info, 138300c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 13844b32caccSMichael Chan { 13854b32caccSMichael Chan u16 fw_speeds = link_info->support_speeds; 13864b32caccSMichael Chan 138700c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported); 13884b32caccSMichael Chan 138900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause); 139000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 139100c04a92SMichael Chan Asym_Pause); 139293ed8117SMichael Chan 139300c04a92SMichael Chan if (link_info->support_auto_speeds) 139400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 139500c04a92SMichael Chan Autoneg); 139693ed8117SMichael Chan } 139793ed8117SMichael Chan 1398c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 1399c0c050c5SMichael Chan { 1400c0c050c5SMichael Chan switch (fw_link_speed) { 1401c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 1402c0c050c5SMichael Chan return SPEED_100; 1403c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 1404c0c050c5SMichael Chan return SPEED_1000; 1405c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 1406c0c050c5SMichael Chan return SPEED_2500; 1407c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 1408c0c050c5SMichael Chan return SPEED_10000; 1409c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 1410c0c050c5SMichael Chan return SPEED_20000; 1411c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 1412c0c050c5SMichael Chan return SPEED_25000; 1413c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 1414c0c050c5SMichael Chan return SPEED_40000; 1415c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 1416c0c050c5SMichael Chan return SPEED_50000; 141738a21b34SDeepak Khungar case BNXT_LINK_SPEED_100GB: 141838a21b34SDeepak Khungar return SPEED_100000; 1419c0c050c5SMichael Chan default: 1420c0c050c5SMichael Chan return SPEED_UNKNOWN; 1421c0c050c5SMichael Chan } 1422c0c050c5SMichael Chan } 1423c0c050c5SMichael Chan 142400c04a92SMichael Chan static int bnxt_get_link_ksettings(struct net_device *dev, 142500c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 1426c0c050c5SMichael Chan { 1427c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1428c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 142900c04a92SMichael Chan struct ethtool_link_settings *base = &lk_ksettings->base; 143000c04a92SMichael Chan u32 ethtool_speed; 1431c0c050c5SMichael Chan 143200c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported); 1433e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 143400c04a92SMichael Chan bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings); 1435c0c050c5SMichael Chan 143600c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising); 1437b763499eSMichael Chan if (link_info->autoneg) { 143800c04a92SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings); 143900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, 144000c04a92SMichael Chan advertising, Autoneg); 144100c04a92SMichael Chan base->autoneg = AUTONEG_ENABLE; 14423277360eSMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) 144300c04a92SMichael Chan bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings); 144429c262feSMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 144529c262feSMichael Chan if (!netif_carrier_ok(dev)) 144600c04a92SMichael Chan base->duplex = DUPLEX_UNKNOWN; 144729c262feSMichael Chan else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 144800c04a92SMichael Chan base->duplex = DUPLEX_FULL; 144929c262feSMichael Chan else 145000c04a92SMichael Chan base->duplex = DUPLEX_HALF; 1451c0c050c5SMichael Chan } else { 145200c04a92SMichael Chan base->autoneg = AUTONEG_DISABLE; 145329c262feSMichael Chan ethtool_speed = 145429c262feSMichael Chan bnxt_fw_to_ethtool_speed(link_info->req_link_speed); 145500c04a92SMichael Chan base->duplex = DUPLEX_HALF; 145629c262feSMichael Chan if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL) 145700c04a92SMichael Chan base->duplex = DUPLEX_FULL; 1458c0c050c5SMichael Chan } 145900c04a92SMichael Chan base->speed = ethtool_speed; 1460c0c050c5SMichael Chan 146100c04a92SMichael Chan base->port = PORT_NONE; 1462c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 146300c04a92SMichael Chan base->port = PORT_TP; 146400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 146500c04a92SMichael Chan TP); 146600c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 146700c04a92SMichael Chan TP); 1468c0c050c5SMichael Chan } else { 146900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 147000c04a92SMichael Chan FIBRE); 147100c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 147200c04a92SMichael Chan FIBRE); 1473c0c050c5SMichael Chan 1474c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 147500c04a92SMichael Chan base->port = PORT_DA; 1476c0c050c5SMichael Chan else if (link_info->media_type == 1477c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 147800c04a92SMichael Chan base->port = PORT_FIBRE; 1479c0c050c5SMichael Chan } 148000c04a92SMichael Chan base->phy_address = link_info->phy_addr; 1481e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1482c0c050c5SMichael Chan 1483c0c050c5SMichael Chan return 0; 1484c0c050c5SMichael Chan } 1485c0c050c5SMichael Chan 148638a21b34SDeepak Khungar static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed) 1487c0c050c5SMichael Chan { 14889d9cee08SMichael Chan struct bnxt *bp = netdev_priv(dev); 14899d9cee08SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 14909d9cee08SMichael Chan u16 support_spds = link_info->support_speeds; 14919d9cee08SMichael Chan u32 fw_speed = 0; 14929d9cee08SMichael Chan 1493c0c050c5SMichael Chan switch (ethtool_speed) { 1494c0c050c5SMichael Chan case SPEED_100: 14959d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_100MB) 14969d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 14979d9cee08SMichael Chan break; 1498c0c050c5SMichael Chan case SPEED_1000: 14999d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_1GB) 15009d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 15019d9cee08SMichael Chan break; 1502c0c050c5SMichael Chan case SPEED_2500: 15039d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB) 15049d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 15059d9cee08SMichael Chan break; 1506c0c050c5SMichael Chan case SPEED_10000: 15079d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_10GB) 15089d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 15099d9cee08SMichael Chan break; 1510c0c050c5SMichael Chan case SPEED_20000: 15119d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_20GB) 15129d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 15139d9cee08SMichael Chan break; 1514c0c050c5SMichael Chan case SPEED_25000: 15159d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_25GB) 15169d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 15179d9cee08SMichael Chan break; 1518c0c050c5SMichael Chan case SPEED_40000: 15199d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_40GB) 15209d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 15219d9cee08SMichael Chan break; 1522c0c050c5SMichael Chan case SPEED_50000: 15239d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_50GB) 15249d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 15259d9cee08SMichael Chan break; 152638a21b34SDeepak Khungar case SPEED_100000: 152738a21b34SDeepak Khungar if (support_spds & BNXT_LINK_SPEED_MSK_100GB) 152838a21b34SDeepak Khungar fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB; 152938a21b34SDeepak Khungar break; 1530c0c050c5SMichael Chan default: 1531c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 1532c0c050c5SMichael Chan break; 1533c0c050c5SMichael Chan } 15349d9cee08SMichael Chan return fw_speed; 1535c0c050c5SMichael Chan } 1536c0c050c5SMichael Chan 1537939f7f0cSMichael Chan u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 1538c0c050c5SMichael Chan { 1539c0c050c5SMichael Chan u16 fw_speed_mask = 0; 1540c0c050c5SMichael Chan 1541c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 1542c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 1543c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 1544c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 1545c0c050c5SMichael Chan } 1546c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 1547c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 1548c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 1549c0c050c5SMichael Chan } 1550c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 1551c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 1552c0c050c5SMichael Chan 15531c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 15541c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 15551c49c421SMichael Chan 1556c0c050c5SMichael Chan return fw_speed_mask; 1557c0c050c5SMichael Chan } 1558c0c050c5SMichael Chan 155900c04a92SMichael Chan static int bnxt_set_link_ksettings(struct net_device *dev, 156000c04a92SMichael Chan const struct ethtool_link_ksettings *lk_ksettings) 1561c0c050c5SMichael Chan { 1562c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1563c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 156400c04a92SMichael Chan const struct ethtool_link_settings *base = &lk_ksettings->base; 1565c0c050c5SMichael Chan bool set_pause = false; 156668515a18SMichael Chan u16 fw_advertising = 0; 156768515a18SMichael Chan u32 speed; 156800c04a92SMichael Chan int rc = 0; 1569c0c050c5SMichael Chan 1570567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 157100c04a92SMichael Chan return -EOPNOTSUPP; 1572c0c050c5SMichael Chan 1573e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 157400c04a92SMichael Chan if (base->autoneg == AUTONEG_ENABLE) { 157500c04a92SMichael Chan BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings, 157600c04a92SMichael Chan advertising); 1577c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 1578c0c050c5SMichael Chan if (!fw_advertising) 157993ed8117SMichael Chan link_info->advertising = link_info->support_auto_speeds; 1580c0c050c5SMichael Chan else 1581c0c050c5SMichael Chan link_info->advertising = fw_advertising; 1582c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 1583c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 1584c0c050c5SMichael Chan */ 1585c0c050c5SMichael Chan set_pause = true; 1586c0c050c5SMichael Chan } else { 15879d9cee08SMichael Chan u16 fw_speed; 158803efbec0SMichael Chan u8 phy_type = link_info->phy_type; 15899d9cee08SMichael Chan 159003efbec0SMichael Chan if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET || 159103efbec0SMichael Chan phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE || 159203efbec0SMichael Chan link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 159303efbec0SMichael Chan netdev_err(dev, "10GBase-T devices must autoneg\n"); 159403efbec0SMichael Chan rc = -EINVAL; 159503efbec0SMichael Chan goto set_setting_exit; 159603efbec0SMichael Chan } 159700c04a92SMichael Chan if (base->duplex == DUPLEX_HALF) { 1598c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 1599c0c050c5SMichael Chan rc = -EINVAL; 1600c0c050c5SMichael Chan goto set_setting_exit; 1601c0c050c5SMichael Chan } 160200c04a92SMichael Chan speed = base->speed; 16039d9cee08SMichael Chan fw_speed = bnxt_get_fw_speed(dev, speed); 16049d9cee08SMichael Chan if (!fw_speed) { 16059d9cee08SMichael Chan rc = -EINVAL; 16069d9cee08SMichael Chan goto set_setting_exit; 16079d9cee08SMichael Chan } 16089d9cee08SMichael Chan link_info->req_link_speed = fw_speed; 1609c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 1610b763499eSMichael Chan link_info->autoneg = 0; 1611c0c050c5SMichael Chan link_info->advertising = 0; 1612c0c050c5SMichael Chan } 1613c0c050c5SMichael Chan 1614c0c050c5SMichael Chan if (netif_running(dev)) 1615939f7f0cSMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause, false); 1616c0c050c5SMichael Chan 1617c0c050c5SMichael Chan set_setting_exit: 1618e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1619c0c050c5SMichael Chan return rc; 1620c0c050c5SMichael Chan } 1621c0c050c5SMichael Chan 1622c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 1623c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1624c0c050c5SMichael Chan { 1625c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1626c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1627c0c050c5SMichael Chan 1628c0c050c5SMichael Chan if (BNXT_VF(bp)) 1629c0c050c5SMichael Chan return; 1630b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 16313c02d1bbSMichael Chan epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX); 16323c02d1bbSMichael Chan epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX); 1633c0c050c5SMichael Chan } 1634c0c050c5SMichael Chan 1635c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 1636c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1637c0c050c5SMichael Chan { 1638c0c050c5SMichael Chan int rc = 0; 1639c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1640c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1641c0c050c5SMichael Chan 1642567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 164375362a3fSMichael Chan return -EOPNOTSUPP; 1644c0c050c5SMichael Chan 1645c0c050c5SMichael Chan if (epause->autoneg) { 1646b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 1647b763499eSMichael Chan return -EINVAL; 1648b763499eSMichael Chan 1649c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 1650c9ee9516SMichael Chan if (bp->hwrm_spec_code >= 0x10201) 1651c9ee9516SMichael Chan link_info->req_flow_ctrl = 1652c9ee9516SMichael Chan PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; 1653c0c050c5SMichael Chan } else { 1654c0c050c5SMichael Chan /* when transition from auto pause to force pause, 1655c0c050c5SMichael Chan * force a link change 1656c0c050c5SMichael Chan */ 1657c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 1658c0c050c5SMichael Chan link_info->force_link_chng = true; 1659c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 1660c9ee9516SMichael Chan link_info->req_flow_ctrl = 0; 1661c0c050c5SMichael Chan } 1662c0c050c5SMichael Chan if (epause->rx_pause) 1663c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 1664c0c050c5SMichael Chan 1665c0c050c5SMichael Chan if (epause->tx_pause) 1666c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 1667c0c050c5SMichael Chan 1668c0c050c5SMichael Chan if (netif_running(dev)) 1669c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 1670c0c050c5SMichael Chan return rc; 1671c0c050c5SMichael Chan } 1672c0c050c5SMichael Chan 1673c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 1674c0c050c5SMichael Chan { 1675c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1676c0c050c5SMichael Chan 1677c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 1678c0c050c5SMichael Chan return bp->link_info.link_up; 1679c0c050c5SMichael Chan } 1680c0c050c5SMichael Chan 16815ac67d8bSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 16825ac67d8bSRob Swindell u16 ext, u16 *index, u32 *item_length, 16835ac67d8bSRob Swindell u32 *data_length); 16845ac67d8bSRob Swindell 1685c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 1686c0c050c5SMichael Chan u16 dir_type, 1687c0c050c5SMichael Chan u16 dir_ordinal, 1688c0c050c5SMichael Chan u16 dir_ext, 1689c0c050c5SMichael Chan u16 dir_attr, 1690c0c050c5SMichael Chan const u8 *data, 1691c0c050c5SMichael Chan size_t data_len) 1692c0c050c5SMichael Chan { 1693c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1694c0c050c5SMichael Chan int rc; 1695c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 1696c0c050c5SMichael Chan dma_addr_t dma_handle; 1697c0c050c5SMichael Chan u8 *kmem; 1698c0c050c5SMichael Chan 1699c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 1700c0c050c5SMichael Chan 1701c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 1702c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 1703c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 1704c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 1705c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 1706c0c050c5SMichael Chan 1707c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 1708c0c050c5SMichael Chan GFP_KERNEL); 1709c0c050c5SMichael Chan if (!kmem) { 1710c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1711c0c050c5SMichael Chan (unsigned)data_len); 1712c0c050c5SMichael Chan return -ENOMEM; 1713c0c050c5SMichael Chan } 1714c0c050c5SMichael Chan memcpy(kmem, data, data_len); 1715c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 1716c0c050c5SMichael Chan 1717c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 1718c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 1719c0c050c5SMichael Chan 17207c675421SVasundhara Volam if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 17217c675421SVasundhara Volam netdev_info(dev, 17227c675421SVasundhara Volam "PF does not have admin privileges to flash the device\n"); 17237c675421SVasundhara Volam rc = -EACCES; 17247c675421SVasundhara Volam } else if (rc) { 17257c675421SVasundhara Volam rc = -EIO; 17267c675421SVasundhara Volam } 1727c0c050c5SMichael Chan return rc; 1728c0c050c5SMichael Chan } 1729c0c050c5SMichael Chan 1730d2d6318cSRob Swindell static int bnxt_firmware_reset(struct net_device *dev, 1731d2d6318cSRob Swindell u16 dir_type) 1732d2d6318cSRob Swindell { 1733d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 17347c675421SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 17357c675421SVasundhara Volam int rc; 1736d2d6318cSRob Swindell 1737d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 1738d2d6318cSRob Swindell 1739d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 1740d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 1741d2d6318cSRob Swindell switch (dir_type) { 1742d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 1743d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 1744d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 1745d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 1746d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 1747d2d6318cSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1748d2d6318cSRob Swindell break; 1749d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 1750d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 1751d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 175208141e0bSRob Swindell /* Self-reset APE upon next PCIe reset: */ 175308141e0bSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1754d2d6318cSRob Swindell break; 1755d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 1756d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 1757d2d6318cSRob Swindell req.embedded_proc_type = 1758d2d6318cSRob Swindell FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 1759d2d6318cSRob Swindell break; 1760d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 1761d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1762d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 1763d2d6318cSRob Swindell break; 176449f7972fSVasundhara Volam case BNXT_FW_RESET_CHIP: 176549f7972fSVasundhara Volam req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP; 176649f7972fSVasundhara Volam req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP; 176749f7972fSVasundhara Volam break; 17686502ad59SScott Branden case BNXT_FW_RESET_AP: 17696502ad59SScott Branden req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP; 17706502ad59SScott Branden break; 1771d2d6318cSRob Swindell default: 1772d2d6318cSRob Swindell return -EINVAL; 1773d2d6318cSRob Swindell } 1774d2d6318cSRob Swindell 17757c675421SVasundhara Volam rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 17767c675421SVasundhara Volam if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 17777c675421SVasundhara Volam netdev_info(dev, 17787c675421SVasundhara Volam "PF does not have admin privileges to reset the device\n"); 17797c675421SVasundhara Volam rc = -EACCES; 17807c675421SVasundhara Volam } else if (rc) { 17817c675421SVasundhara Volam rc = -EIO; 17827c675421SVasundhara Volam } 17837c675421SVasundhara Volam return rc; 1784d2d6318cSRob Swindell } 1785d2d6318cSRob Swindell 1786c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 1787c0c050c5SMichael Chan u16 dir_type, 1788c0c050c5SMichael Chan const u8 *fw_data, 1789c0c050c5SMichael Chan size_t fw_size) 1790c0c050c5SMichael Chan { 1791c0c050c5SMichael Chan int rc = 0; 1792c0c050c5SMichael Chan u16 code_type; 1793c0c050c5SMichael Chan u32 stored_crc; 1794c0c050c5SMichael Chan u32 calculated_crc; 1795c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 1796c0c050c5SMichael Chan 1797c0c050c5SMichael Chan switch (dir_type) { 1798c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1799c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1800c0c050c5SMichael Chan code_type = CODE_BOOT; 1801c0c050c5SMichael Chan break; 180293e0b4feSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 180393e0b4feSRob Swindell code_type = CODE_CHIMP_PATCH; 180493e0b4feSRob Swindell break; 18052731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 18062731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 18072731d70fSRob Swindell break; 180893e0b4feSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 180993e0b4feSRob Swindell code_type = CODE_APE_PATCH; 181093e0b4feSRob Swindell break; 181193e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_FW: 181293e0b4feSRob Swindell code_type = CODE_KONG_FW; 181393e0b4feSRob Swindell break; 181493e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 181593e0b4feSRob Swindell code_type = CODE_KONG_PATCH; 181693e0b4feSRob Swindell break; 181793e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 181893e0b4feSRob Swindell code_type = CODE_BONO_FW; 181993e0b4feSRob Swindell break; 182093e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 182193e0b4feSRob Swindell code_type = CODE_BONO_PATCH; 182293e0b4feSRob Swindell break; 1823c0c050c5SMichael Chan default: 1824c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 1825c0c050c5SMichael Chan dir_type); 1826c0c050c5SMichael Chan return -EINVAL; 1827c0c050c5SMichael Chan } 1828c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 1829c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 1830c0c050c5SMichael Chan (unsigned int)fw_size); 1831c0c050c5SMichael Chan return -EINVAL; 1832c0c050c5SMichael Chan } 1833c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 1834c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 1835c0c050c5SMichael Chan le32_to_cpu(header->signature)); 1836c0c050c5SMichael Chan return -EINVAL; 1837c0c050c5SMichael Chan } 1838c0c050c5SMichael Chan if (header->code_type != code_type) { 1839c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 1840c0c050c5SMichael Chan code_type, header->code_type); 1841c0c050c5SMichael Chan return -EINVAL; 1842c0c050c5SMichael Chan } 1843c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 1844c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 1845c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 1846c0c050c5SMichael Chan return -EINVAL; 1847c0c050c5SMichael Chan } 1848c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 1849c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 1850c0c050c5SMichael Chan sizeof(stored_crc))); 1851c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 1852c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 1853c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 1854c0c050c5SMichael Chan (unsigned long)stored_crc, 1855c0c050c5SMichael Chan (unsigned long)calculated_crc); 1856c0c050c5SMichael Chan return -EINVAL; 1857c0c050c5SMichael Chan } 1858c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1859c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 1860d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 1861d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 1862d2d6318cSRob Swindell 1863c0c050c5SMichael Chan return rc; 1864c0c050c5SMichael Chan } 1865c0c050c5SMichael Chan 18665ac67d8bSRob Swindell static int bnxt_flash_microcode(struct net_device *dev, 18675ac67d8bSRob Swindell u16 dir_type, 18685ac67d8bSRob Swindell const u8 *fw_data, 18695ac67d8bSRob Swindell size_t fw_size) 18705ac67d8bSRob Swindell { 18715ac67d8bSRob Swindell struct bnxt_ucode_trailer *trailer; 18725ac67d8bSRob Swindell u32 calculated_crc; 18735ac67d8bSRob Swindell u32 stored_crc; 18745ac67d8bSRob Swindell int rc = 0; 18755ac67d8bSRob Swindell 18765ac67d8bSRob Swindell if (fw_size < sizeof(struct bnxt_ucode_trailer)) { 18775ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode file size: %u\n", 18785ac67d8bSRob Swindell (unsigned int)fw_size); 18795ac67d8bSRob Swindell return -EINVAL; 18805ac67d8bSRob Swindell } 18815ac67d8bSRob Swindell trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size - 18825ac67d8bSRob Swindell sizeof(*trailer))); 18835ac67d8bSRob Swindell if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) { 18845ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer signature: %08X\n", 18855ac67d8bSRob Swindell le32_to_cpu(trailer->sig)); 18865ac67d8bSRob Swindell return -EINVAL; 18875ac67d8bSRob Swindell } 18885ac67d8bSRob Swindell if (le16_to_cpu(trailer->dir_type) != dir_type) { 18895ac67d8bSRob Swindell netdev_err(dev, "Expected microcode type: %d, read: %d\n", 18905ac67d8bSRob Swindell dir_type, le16_to_cpu(trailer->dir_type)); 18915ac67d8bSRob Swindell return -EINVAL; 18925ac67d8bSRob Swindell } 18935ac67d8bSRob Swindell if (le16_to_cpu(trailer->trailer_length) < 18945ac67d8bSRob Swindell sizeof(struct bnxt_ucode_trailer)) { 18955ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer length: %d\n", 18965ac67d8bSRob Swindell le16_to_cpu(trailer->trailer_length)); 18975ac67d8bSRob Swindell return -EINVAL; 18985ac67d8bSRob Swindell } 18995ac67d8bSRob Swindell 19005ac67d8bSRob Swindell /* Confirm the CRC32 checksum of the file: */ 19015ac67d8bSRob Swindell stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 19025ac67d8bSRob Swindell sizeof(stored_crc))); 19035ac67d8bSRob Swindell calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 19045ac67d8bSRob Swindell if (calculated_crc != stored_crc) { 19055ac67d8bSRob Swindell netdev_err(dev, 19065ac67d8bSRob Swindell "CRC32 (%08lX) does not match calculated: %08lX\n", 19075ac67d8bSRob Swindell (unsigned long)stored_crc, 19085ac67d8bSRob Swindell (unsigned long)calculated_crc); 19095ac67d8bSRob Swindell return -EINVAL; 19105ac67d8bSRob Swindell } 19115ac67d8bSRob Swindell rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 19125ac67d8bSRob Swindell 0, 0, fw_data, fw_size); 19135ac67d8bSRob Swindell 19145ac67d8bSRob Swindell return rc; 19155ac67d8bSRob Swindell } 19165ac67d8bSRob Swindell 1917c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 1918c0c050c5SMichael Chan { 1919c0c050c5SMichael Chan switch (dir_type) { 1920c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 1921c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1922c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1923c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 1924c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 1925c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 1926c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 192793e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 192893e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1929c0c050c5SMichael Chan return true; 1930c0c050c5SMichael Chan } 1931c0c050c5SMichael Chan 1932c0c050c5SMichael Chan return false; 1933c0c050c5SMichael Chan } 1934c0c050c5SMichael Chan 19355ac67d8bSRob Swindell static bool bnxt_dir_type_is_other_exec_format(u16 dir_type) 1936c0c050c5SMichael Chan { 1937c0c050c5SMichael Chan switch (dir_type) { 1938c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 1939c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 1940c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 1941c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 1942c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 1943c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 1944c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 1945c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 1946c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 1947c0c050c5SMichael Chan return true; 1948c0c050c5SMichael Chan } 1949c0c050c5SMichael Chan 1950c0c050c5SMichael Chan return false; 1951c0c050c5SMichael Chan } 1952c0c050c5SMichael Chan 1953c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 1954c0c050c5SMichael Chan { 1955c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 19565ac67d8bSRob Swindell bnxt_dir_type_is_other_exec_format(dir_type); 1957c0c050c5SMichael Chan } 1958c0c050c5SMichael Chan 1959c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 1960c0c050c5SMichael Chan u16 dir_type, 1961c0c050c5SMichael Chan const char *filename) 1962c0c050c5SMichael Chan { 1963c0c050c5SMichael Chan const struct firmware *fw; 1964c0c050c5SMichael Chan int rc; 1965c0c050c5SMichael Chan 1966c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 1967c0c050c5SMichael Chan if (rc != 0) { 1968c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 1969c0c050c5SMichael Chan rc, filename); 1970c0c050c5SMichael Chan return rc; 1971c0c050c5SMichael Chan } 1972c0c050c5SMichael Chan if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) 1973c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 19745ac67d8bSRob Swindell else if (bnxt_dir_type_is_other_exec_format(dir_type) == true) 19755ac67d8bSRob Swindell rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size); 1976c0c050c5SMichael Chan else 1977c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1978c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 1979c0c050c5SMichael Chan release_firmware(fw); 1980c0c050c5SMichael Chan return rc; 1981c0c050c5SMichael Chan } 1982c0c050c5SMichael Chan 1983c0c050c5SMichael Chan static int bnxt_flash_package_from_file(struct net_device *dev, 19845ac67d8bSRob Swindell char *filename, u32 install_type) 1985c0c050c5SMichael Chan { 19865ac67d8bSRob Swindell struct bnxt *bp = netdev_priv(dev); 19875ac67d8bSRob Swindell struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr; 19885ac67d8bSRob Swindell struct hwrm_nvm_install_update_input install = {0}; 19895ac67d8bSRob Swindell const struct firmware *fw; 19907c675421SVasundhara Volam int rc, hwrm_err = 0; 19915ac67d8bSRob Swindell u32 item_len; 19925ac67d8bSRob Swindell u16 index; 19935ac67d8bSRob Swindell 19945ac67d8bSRob Swindell bnxt_hwrm_fw_set_time(bp); 19955ac67d8bSRob Swindell 19965ac67d8bSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE, 19975ac67d8bSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 19985ac67d8bSRob Swindell &index, &item_len, NULL) != 0) { 19995ac67d8bSRob Swindell netdev_err(dev, "PKG update area not created in nvram\n"); 20005ac67d8bSRob Swindell return -ENOBUFS; 20015ac67d8bSRob Swindell } 20025ac67d8bSRob Swindell 20035ac67d8bSRob Swindell rc = request_firmware(&fw, filename, &dev->dev); 20045ac67d8bSRob Swindell if (rc != 0) { 20055ac67d8bSRob Swindell netdev_err(dev, "PKG error %d requesting file: %s\n", 20065ac67d8bSRob Swindell rc, filename); 20075ac67d8bSRob Swindell return rc; 20085ac67d8bSRob Swindell } 20095ac67d8bSRob Swindell 20105ac67d8bSRob Swindell if (fw->size > item_len) { 20115ac67d8bSRob Swindell netdev_err(dev, "PKG insufficient update area in nvram: %lu", 20125ac67d8bSRob Swindell (unsigned long)fw->size); 20135ac67d8bSRob Swindell rc = -EFBIG; 20145ac67d8bSRob Swindell } else { 20155ac67d8bSRob Swindell dma_addr_t dma_handle; 20165ac67d8bSRob Swindell u8 *kmem; 20175ac67d8bSRob Swindell struct hwrm_nvm_modify_input modify = {0}; 20185ac67d8bSRob Swindell 20195ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1); 20205ac67d8bSRob Swindell 20215ac67d8bSRob Swindell modify.dir_idx = cpu_to_le16(index); 20225ac67d8bSRob Swindell modify.len = cpu_to_le32(fw->size); 20235ac67d8bSRob Swindell 20245ac67d8bSRob Swindell kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size, 20255ac67d8bSRob Swindell &dma_handle, GFP_KERNEL); 20265ac67d8bSRob Swindell if (!kmem) { 20275ac67d8bSRob Swindell netdev_err(dev, 20285ac67d8bSRob Swindell "dma_alloc_coherent failure, length = %u\n", 20295ac67d8bSRob Swindell (unsigned int)fw->size); 20305ac67d8bSRob Swindell rc = -ENOMEM; 20315ac67d8bSRob Swindell } else { 20325ac67d8bSRob Swindell memcpy(kmem, fw->data, fw->size); 20335ac67d8bSRob Swindell modify.host_src_addr = cpu_to_le64(dma_handle); 20345ac67d8bSRob Swindell 20357c675421SVasundhara Volam hwrm_err = hwrm_send_message(bp, &modify, 20367c675421SVasundhara Volam sizeof(modify), 20375ac67d8bSRob Swindell FLASH_PACKAGE_TIMEOUT); 20385ac67d8bSRob Swindell dma_free_coherent(&bp->pdev->dev, fw->size, kmem, 20395ac67d8bSRob Swindell dma_handle); 20405ac67d8bSRob Swindell } 20415ac67d8bSRob Swindell } 20425ac67d8bSRob Swindell release_firmware(fw); 20437c675421SVasundhara Volam if (rc || hwrm_err) 20447c675421SVasundhara Volam goto err_exit; 20455ac67d8bSRob Swindell 20465ac67d8bSRob Swindell if ((install_type & 0xffff) == 0) 20475ac67d8bSRob Swindell install_type >>= 16; 20485ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1); 20495ac67d8bSRob Swindell install.install_type = cpu_to_le32(install_type); 20505ac67d8bSRob Swindell 2051cb4d1d62SKshitij Soni mutex_lock(&bp->hwrm_cmd_lock); 20527c675421SVasundhara Volam hwrm_err = _hwrm_send_message(bp, &install, sizeof(install), 20535ac67d8bSRob Swindell INSTALL_PACKAGE_TIMEOUT); 20547c675421SVasundhara Volam if (hwrm_err) 2055cb4d1d62SKshitij Soni goto flash_pkg_exit; 2056cb4d1d62SKshitij Soni 2057cb4d1d62SKshitij Soni if (resp->error_code) { 2058cb4d1d62SKshitij Soni u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err; 2059cb4d1d62SKshitij Soni 2060cb4d1d62SKshitij Soni if (error_code == NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) { 2061cb4d1d62SKshitij Soni install.flags |= cpu_to_le16( 2062cb4d1d62SKshitij Soni NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG); 20637c675421SVasundhara Volam hwrm_err = _hwrm_send_message(bp, &install, 20647c675421SVasundhara Volam sizeof(install), 2065cb4d1d62SKshitij Soni INSTALL_PACKAGE_TIMEOUT); 20667c675421SVasundhara Volam if (hwrm_err) 2067cb4d1d62SKshitij Soni goto flash_pkg_exit; 2068cb4d1d62SKshitij Soni } 2069cb4d1d62SKshitij Soni } 20705ac67d8bSRob Swindell 20715ac67d8bSRob Swindell if (resp->result) { 20725ac67d8bSRob Swindell netdev_err(dev, "PKG install error = %d, problem_item = %d\n", 20735ac67d8bSRob Swindell (s8)resp->result, (int)resp->problem_item); 2074cb4d1d62SKshitij Soni rc = -ENOPKG; 20755ac67d8bSRob Swindell } 2076cb4d1d62SKshitij Soni flash_pkg_exit: 2077cb4d1d62SKshitij Soni mutex_unlock(&bp->hwrm_cmd_lock); 20787c675421SVasundhara Volam err_exit: 20797c675421SVasundhara Volam if (hwrm_err == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 20807c675421SVasundhara Volam netdev_info(dev, 20817c675421SVasundhara Volam "PF does not have admin privileges to flash the device\n"); 20827c675421SVasundhara Volam rc = -EACCES; 20837c675421SVasundhara Volam } else if (hwrm_err) { 20847c675421SVasundhara Volam rc = -EOPNOTSUPP; 20857c675421SVasundhara Volam } 2086cb4d1d62SKshitij Soni return rc; 2087c0c050c5SMichael Chan } 2088c0c050c5SMichael Chan 2089c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 2090c0c050c5SMichael Chan struct ethtool_flash *flash) 2091c0c050c5SMichael Chan { 2092c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 2093c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 2094c0c050c5SMichael Chan return -EINVAL; 2095c0c050c5SMichael Chan } 2096c0c050c5SMichael Chan 20975ac67d8bSRob Swindell if (flash->region == ETHTOOL_FLASH_ALL_REGIONS || 20985ac67d8bSRob Swindell flash->region > 0xffff) 20995ac67d8bSRob Swindell return bnxt_flash_package_from_file(dev, flash->data, 21005ac67d8bSRob Swindell flash->region); 2101c0c050c5SMichael Chan 2102c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 2103c0c050c5SMichael Chan } 2104c0c050c5SMichael Chan 2105c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 2106c0c050c5SMichael Chan { 2107c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2108c0c050c5SMichael Chan int rc; 2109c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 2110c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 2111c0c050c5SMichael Chan 2112c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 2113c0c050c5SMichael Chan 2114c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2115c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2116c0c050c5SMichael Chan if (!rc) { 2117c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 2118c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 2119c0c050c5SMichael Chan } 2120c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2121c0c050c5SMichael Chan return rc; 2122c0c050c5SMichael Chan } 2123c0c050c5SMichael Chan 2124c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 2125c0c050c5SMichael Chan { 21264cebbacaSMichael Chan struct bnxt *bp = netdev_priv(dev); 21274cebbacaSMichael Chan 21284cebbacaSMichael Chan if (BNXT_VF(bp)) 21294cebbacaSMichael Chan return 0; 21304cebbacaSMichael Chan 2131c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 2132c0c050c5SMichael Chan * passed via the ethtool command-line utility. 2133c0c050c5SMichael Chan */ 2134c0c050c5SMichael Chan return -1; 2135c0c050c5SMichael Chan } 2136c0c050c5SMichael Chan 2137c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 2138c0c050c5SMichael Chan { 2139c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2140c0c050c5SMichael Chan int rc; 2141c0c050c5SMichael Chan u32 dir_entries; 2142c0c050c5SMichael Chan u32 entry_length; 2143c0c050c5SMichael Chan u8 *buf; 2144c0c050c5SMichael Chan size_t buflen; 2145c0c050c5SMichael Chan dma_addr_t dma_handle; 2146c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 2147c0c050c5SMichael Chan 2148c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 2149c0c050c5SMichael Chan if (rc != 0) 2150c0c050c5SMichael Chan return rc; 2151c0c050c5SMichael Chan 2152c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 2153c0c050c5SMichael Chan if (len < 2) 2154c0c050c5SMichael Chan return -EINVAL; 2155c0c050c5SMichael Chan 2156c0c050c5SMichael Chan *data++ = dir_entries; 2157c0c050c5SMichael Chan *data++ = entry_length; 2158c0c050c5SMichael Chan len -= 2; 2159c0c050c5SMichael Chan memset(data, 0xff, len); 2160c0c050c5SMichael Chan 2161c0c050c5SMichael Chan buflen = dir_entries * entry_length; 2162c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 2163c0c050c5SMichael Chan GFP_KERNEL); 2164c0c050c5SMichael Chan if (!buf) { 2165c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2166c0c050c5SMichael Chan (unsigned)buflen); 2167c0c050c5SMichael Chan return -ENOMEM; 2168c0c050c5SMichael Chan } 2169c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 2170c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2171c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2172c0c050c5SMichael Chan if (rc == 0) 2173c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 2174c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 2175c0c050c5SMichael Chan return rc; 2176c0c050c5SMichael Chan } 2177c0c050c5SMichael Chan 2178c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 2179c0c050c5SMichael Chan u32 length, u8 *data) 2180c0c050c5SMichael Chan { 2181c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2182c0c050c5SMichael Chan int rc; 2183c0c050c5SMichael Chan u8 *buf; 2184c0c050c5SMichael Chan dma_addr_t dma_handle; 2185c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 2186c0c050c5SMichael Chan 2187e0ad8fc5SMichael Chan if (!length) 2188e0ad8fc5SMichael Chan return -EINVAL; 2189e0ad8fc5SMichael Chan 2190c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 2191c0c050c5SMichael Chan GFP_KERNEL); 2192c0c050c5SMichael Chan if (!buf) { 2193c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2194c0c050c5SMichael Chan (unsigned)length); 2195c0c050c5SMichael Chan return -ENOMEM; 2196c0c050c5SMichael Chan } 2197c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 2198c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2199c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2200c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 2201c0c050c5SMichael Chan req.len = cpu_to_le32(length); 2202c0c050c5SMichael Chan 2203c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2204c0c050c5SMichael Chan if (rc == 0) 2205c0c050c5SMichael Chan memcpy(data, buf, length); 2206c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 2207c0c050c5SMichael Chan return rc; 2208c0c050c5SMichael Chan } 2209c0c050c5SMichael Chan 22103ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 22113ebf6f0aSRob Swindell u16 ext, u16 *index, u32 *item_length, 22123ebf6f0aSRob Swindell u32 *data_length) 22133ebf6f0aSRob Swindell { 22143ebf6f0aSRob Swindell struct bnxt *bp = netdev_priv(dev); 22153ebf6f0aSRob Swindell int rc; 22163ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_input req = {0}; 22173ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr; 22183ebf6f0aSRob Swindell 22193ebf6f0aSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1); 22203ebf6f0aSRob Swindell req.enables = 0; 22213ebf6f0aSRob Swindell req.dir_idx = 0; 22223ebf6f0aSRob Swindell req.dir_type = cpu_to_le16(type); 22233ebf6f0aSRob Swindell req.dir_ordinal = cpu_to_le16(ordinal); 22243ebf6f0aSRob Swindell req.dir_ext = cpu_to_le16(ext); 22253ebf6f0aSRob Swindell req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ; 2226cc72f3b1SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2227cc72f3b1SMichael Chan rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 22283ebf6f0aSRob Swindell if (rc == 0) { 22293ebf6f0aSRob Swindell if (index) 22303ebf6f0aSRob Swindell *index = le16_to_cpu(output->dir_idx); 22313ebf6f0aSRob Swindell if (item_length) 22323ebf6f0aSRob Swindell *item_length = le32_to_cpu(output->dir_item_length); 22333ebf6f0aSRob Swindell if (data_length) 22343ebf6f0aSRob Swindell *data_length = le32_to_cpu(output->dir_data_length); 22353ebf6f0aSRob Swindell } 2236cc72f3b1SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 22373ebf6f0aSRob Swindell return rc; 22383ebf6f0aSRob Swindell } 22393ebf6f0aSRob Swindell 22403ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen) 22413ebf6f0aSRob Swindell { 22423ebf6f0aSRob Swindell char *retval = NULL; 22433ebf6f0aSRob Swindell char *p; 22443ebf6f0aSRob Swindell char *value; 22453ebf6f0aSRob Swindell int field = 0; 22463ebf6f0aSRob Swindell 22473ebf6f0aSRob Swindell if (datalen < 1) 22483ebf6f0aSRob Swindell return NULL; 22493ebf6f0aSRob Swindell /* null-terminate the log data (removing last '\n'): */ 22503ebf6f0aSRob Swindell data[datalen - 1] = 0; 22513ebf6f0aSRob Swindell for (p = data; *p != 0; p++) { 22523ebf6f0aSRob Swindell field = 0; 22533ebf6f0aSRob Swindell retval = NULL; 22543ebf6f0aSRob Swindell while (*p != 0 && *p != '\n') { 22553ebf6f0aSRob Swindell value = p; 22563ebf6f0aSRob Swindell while (*p != 0 && *p != '\t' && *p != '\n') 22573ebf6f0aSRob Swindell p++; 22583ebf6f0aSRob Swindell if (field == desired_field) 22593ebf6f0aSRob Swindell retval = value; 22603ebf6f0aSRob Swindell if (*p != '\t') 22613ebf6f0aSRob Swindell break; 22623ebf6f0aSRob Swindell *p = 0; 22633ebf6f0aSRob Swindell field++; 22643ebf6f0aSRob Swindell p++; 22653ebf6f0aSRob Swindell } 22663ebf6f0aSRob Swindell if (*p == 0) 22673ebf6f0aSRob Swindell break; 22683ebf6f0aSRob Swindell *p = 0; 22693ebf6f0aSRob Swindell } 22703ebf6f0aSRob Swindell return retval; 22713ebf6f0aSRob Swindell } 22723ebf6f0aSRob Swindell 2273a60faa60SVasundhara Volam static void bnxt_get_pkgver(struct net_device *dev) 22743ebf6f0aSRob Swindell { 2275a60faa60SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 22763ebf6f0aSRob Swindell u16 index = 0; 2277a60faa60SVasundhara Volam char *pkgver; 2278a60faa60SVasundhara Volam u32 pkglen; 2279a60faa60SVasundhara Volam u8 *pkgbuf; 2280a60faa60SVasundhara Volam int len; 22813ebf6f0aSRob Swindell 22823ebf6f0aSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG, 22833ebf6f0aSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 2284a60faa60SVasundhara Volam &index, NULL, &pkglen) != 0) 2285a60faa60SVasundhara Volam return; 22863ebf6f0aSRob Swindell 2287a60faa60SVasundhara Volam pkgbuf = kzalloc(pkglen, GFP_KERNEL); 2288a60faa60SVasundhara Volam if (!pkgbuf) { 2289a60faa60SVasundhara Volam dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n", 2290a60faa60SVasundhara Volam pkglen); 2291a60faa60SVasundhara Volam return; 2292a60faa60SVasundhara Volam } 22933ebf6f0aSRob Swindell 2294a60faa60SVasundhara Volam if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf)) 2295a60faa60SVasundhara Volam goto err; 2296a60faa60SVasundhara Volam 2297a60faa60SVasundhara Volam pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf, 2298a60faa60SVasundhara Volam pkglen); 2299a60faa60SVasundhara Volam if (pkgver && *pkgver != 0 && isdigit(*pkgver)) { 2300a60faa60SVasundhara Volam len = strlen(bp->fw_ver_str); 2301a60faa60SVasundhara Volam snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1, 2302a60faa60SVasundhara Volam "/pkg %s", pkgver); 2303a60faa60SVasundhara Volam } 2304a60faa60SVasundhara Volam err: 2305a60faa60SVasundhara Volam kfree(pkgbuf); 23063ebf6f0aSRob Swindell } 23073ebf6f0aSRob Swindell 2308c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 2309c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2310c0c050c5SMichael Chan u8 *data) 2311c0c050c5SMichael Chan { 2312c0c050c5SMichael Chan u32 index; 2313c0c050c5SMichael Chan u32 offset; 2314c0c050c5SMichael Chan 2315c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 2316c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 2317c0c050c5SMichael Chan 2318c0c050c5SMichael Chan index = eeprom->offset >> 24; 2319c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 2320c0c050c5SMichael Chan 2321c0c050c5SMichael Chan if (index == 0) { 2322c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 2323c0c050c5SMichael Chan return -EINVAL; 2324c0c050c5SMichael Chan } 2325c0c050c5SMichael Chan 2326c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 2327c0c050c5SMichael Chan } 2328c0c050c5SMichael Chan 2329c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 2330c0c050c5SMichael Chan { 2331c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2332c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 2333c0c050c5SMichael Chan 2334c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 2335c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2336c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2337c0c050c5SMichael Chan } 2338c0c050c5SMichael Chan 2339c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 2340c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2341c0c050c5SMichael Chan u8 *data) 2342c0c050c5SMichael Chan { 2343c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2344c0c050c5SMichael Chan u8 index, dir_op; 2345c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 2346c0c050c5SMichael Chan 2347c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 2348c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 2349c0c050c5SMichael Chan return -EINVAL; 2350c0c050c5SMichael Chan } 2351c0c050c5SMichael Chan 2352c0c050c5SMichael Chan type = eeprom->magic >> 16; 2353c0c050c5SMichael Chan 2354c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 2355c0c050c5SMichael Chan index = eeprom->magic & 0xff; 2356c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 2357c0c050c5SMichael Chan if (index == 0) 2358c0c050c5SMichael Chan return -EINVAL; 2359c0c050c5SMichael Chan switch (dir_op) { 2360c0c050c5SMichael Chan case 0x0e: /* erase */ 2361c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 2362c0c050c5SMichael Chan return -EINVAL; 2363c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 2364c0c050c5SMichael Chan default: 2365c0c050c5SMichael Chan return -EINVAL; 2366c0c050c5SMichael Chan } 2367c0c050c5SMichael Chan } 2368c0c050c5SMichael Chan 2369c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 2370c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(type) == true) 23715ac67d8bSRob Swindell return -EOPNOTSUPP; 2372c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 2373c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 2374c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 2375c0c050c5SMichael Chan 2376c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 2377c0c050c5SMichael Chan eeprom->len); 2378c0c050c5SMichael Chan } 2379c0c050c5SMichael Chan 238072b34f04SMichael Chan static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata) 238172b34f04SMichael Chan { 238272b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 238372b34f04SMichael Chan struct ethtool_eee *eee = &bp->eee; 238472b34f04SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 238572b34f04SMichael Chan u32 advertising = 238672b34f04SMichael Chan _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); 238772b34f04SMichael Chan int rc = 0; 238872b34f04SMichael Chan 2389567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 239075362a3fSMichael Chan return -EOPNOTSUPP; 239172b34f04SMichael Chan 239272b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 239372b34f04SMichael Chan return -EOPNOTSUPP; 239472b34f04SMichael Chan 239572b34f04SMichael Chan if (!edata->eee_enabled) 239672b34f04SMichael Chan goto eee_ok; 239772b34f04SMichael Chan 239872b34f04SMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { 239972b34f04SMichael Chan netdev_warn(dev, "EEE requires autoneg\n"); 240072b34f04SMichael Chan return -EINVAL; 240172b34f04SMichael Chan } 240272b34f04SMichael Chan if (edata->tx_lpi_enabled) { 240372b34f04SMichael Chan if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi || 240472b34f04SMichael Chan edata->tx_lpi_timer < bp->lpi_tmr_lo)) { 240572b34f04SMichael Chan netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n", 240672b34f04SMichael Chan bp->lpi_tmr_lo, bp->lpi_tmr_hi); 240772b34f04SMichael Chan return -EINVAL; 240872b34f04SMichael Chan } else if (!bp->lpi_tmr_hi) { 240972b34f04SMichael Chan edata->tx_lpi_timer = eee->tx_lpi_timer; 241072b34f04SMichael Chan } 241172b34f04SMichael Chan } 241272b34f04SMichael Chan if (!edata->advertised) { 241372b34f04SMichael Chan edata->advertised = advertising & eee->supported; 241472b34f04SMichael Chan } else if (edata->advertised & ~advertising) { 241572b34f04SMichael Chan netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", 241672b34f04SMichael Chan edata->advertised, advertising); 241772b34f04SMichael Chan return -EINVAL; 241872b34f04SMichael Chan } 241972b34f04SMichael Chan 242072b34f04SMichael Chan eee->advertised = edata->advertised; 242172b34f04SMichael Chan eee->tx_lpi_enabled = edata->tx_lpi_enabled; 242272b34f04SMichael Chan eee->tx_lpi_timer = edata->tx_lpi_timer; 242372b34f04SMichael Chan eee_ok: 242472b34f04SMichael Chan eee->eee_enabled = edata->eee_enabled; 242572b34f04SMichael Chan 242672b34f04SMichael Chan if (netif_running(dev)) 242772b34f04SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, false, true); 242872b34f04SMichael Chan 242972b34f04SMichael Chan return rc; 243072b34f04SMichael Chan } 243172b34f04SMichael Chan 243272b34f04SMichael Chan static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata) 243372b34f04SMichael Chan { 243472b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 243572b34f04SMichael Chan 243672b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 243772b34f04SMichael Chan return -EOPNOTSUPP; 243872b34f04SMichael Chan 243972b34f04SMichael Chan *edata = bp->eee; 244072b34f04SMichael Chan if (!bp->eee.eee_enabled) { 244172b34f04SMichael Chan /* Preserve tx_lpi_timer so that the last value will be used 244272b34f04SMichael Chan * by default when it is re-enabled. 244372b34f04SMichael Chan */ 244472b34f04SMichael Chan edata->advertised = 0; 244572b34f04SMichael Chan edata->tx_lpi_enabled = 0; 244672b34f04SMichael Chan } 244772b34f04SMichael Chan 244872b34f04SMichael Chan if (!bp->eee.eee_active) 244972b34f04SMichael Chan edata->lp_advertised = 0; 245072b34f04SMichael Chan 245172b34f04SMichael Chan return 0; 245272b34f04SMichael Chan } 245372b34f04SMichael Chan 245442ee18feSAjit Khaparde static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr, 245542ee18feSAjit Khaparde u16 page_number, u16 start_addr, 245642ee18feSAjit Khaparde u16 data_length, u8 *buf) 245742ee18feSAjit Khaparde { 245842ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_input req = {0}; 245942ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr; 246042ee18feSAjit Khaparde int rc, byte_offset = 0; 246142ee18feSAjit Khaparde 246242ee18feSAjit Khaparde bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1); 246342ee18feSAjit Khaparde req.i2c_slave_addr = i2c_addr; 246442ee18feSAjit Khaparde req.page_number = cpu_to_le16(page_number); 246542ee18feSAjit Khaparde req.port_id = cpu_to_le16(bp->pf.port_id); 246642ee18feSAjit Khaparde do { 246742ee18feSAjit Khaparde u16 xfer_size; 246842ee18feSAjit Khaparde 246942ee18feSAjit Khaparde xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE); 247042ee18feSAjit Khaparde data_length -= xfer_size; 247142ee18feSAjit Khaparde req.page_offset = cpu_to_le16(start_addr + byte_offset); 247242ee18feSAjit Khaparde req.data_length = xfer_size; 247342ee18feSAjit Khaparde req.enables = cpu_to_le32(start_addr + byte_offset ? 247442ee18feSAjit Khaparde PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0); 247542ee18feSAjit Khaparde mutex_lock(&bp->hwrm_cmd_lock); 247642ee18feSAjit Khaparde rc = _hwrm_send_message(bp, &req, sizeof(req), 247742ee18feSAjit Khaparde HWRM_CMD_TIMEOUT); 247842ee18feSAjit Khaparde if (!rc) 247942ee18feSAjit Khaparde memcpy(buf + byte_offset, output->data, xfer_size); 248042ee18feSAjit Khaparde mutex_unlock(&bp->hwrm_cmd_lock); 248142ee18feSAjit Khaparde byte_offset += xfer_size; 248242ee18feSAjit Khaparde } while (!rc && data_length > 0); 248342ee18feSAjit Khaparde 248442ee18feSAjit Khaparde return rc; 248542ee18feSAjit Khaparde } 248642ee18feSAjit Khaparde 248742ee18feSAjit Khaparde static int bnxt_get_module_info(struct net_device *dev, 248842ee18feSAjit Khaparde struct ethtool_modinfo *modinfo) 248942ee18feSAjit Khaparde { 24907328a23cSVasundhara Volam u8 data[SFF_DIAG_SUPPORT_OFFSET + 1]; 249142ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 249242ee18feSAjit Khaparde int rc; 249342ee18feSAjit Khaparde 249442ee18feSAjit Khaparde /* No point in going further if phy status indicates 249542ee18feSAjit Khaparde * module is not inserted or if it is powered down or 249642ee18feSAjit Khaparde * if it is of type 10GBase-T 249742ee18feSAjit Khaparde */ 249842ee18feSAjit Khaparde if (bp->link_info.module_status > 249942ee18feSAjit Khaparde PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG) 250042ee18feSAjit Khaparde return -EOPNOTSUPP; 250142ee18feSAjit Khaparde 250242ee18feSAjit Khaparde /* This feature is not supported in older firmware versions */ 250342ee18feSAjit Khaparde if (bp->hwrm_spec_code < 0x10202) 250442ee18feSAjit Khaparde return -EOPNOTSUPP; 250542ee18feSAjit Khaparde 25067328a23cSVasundhara Volam rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0, 25077328a23cSVasundhara Volam SFF_DIAG_SUPPORT_OFFSET + 1, 25087328a23cSVasundhara Volam data); 250942ee18feSAjit Khaparde if (!rc) { 25107328a23cSVasundhara Volam u8 module_id = data[0]; 25117328a23cSVasundhara Volam u8 diag_supported = data[SFF_DIAG_SUPPORT_OFFSET]; 251242ee18feSAjit Khaparde 251342ee18feSAjit Khaparde switch (module_id) { 251442ee18feSAjit Khaparde case SFF_MODULE_ID_SFP: 251542ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8472; 251642ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 25177328a23cSVasundhara Volam if (!diag_supported) 25187328a23cSVasundhara Volam modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 251942ee18feSAjit Khaparde break; 252042ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP: 252142ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP_PLUS: 252242ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8436; 252342ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 252442ee18feSAjit Khaparde break; 252542ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP28: 252642ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8636; 252742ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 252842ee18feSAjit Khaparde break; 252942ee18feSAjit Khaparde default: 253042ee18feSAjit Khaparde rc = -EOPNOTSUPP; 253142ee18feSAjit Khaparde break; 253242ee18feSAjit Khaparde } 253342ee18feSAjit Khaparde } 253442ee18feSAjit Khaparde return rc; 253542ee18feSAjit Khaparde } 253642ee18feSAjit Khaparde 253742ee18feSAjit Khaparde static int bnxt_get_module_eeprom(struct net_device *dev, 253842ee18feSAjit Khaparde struct ethtool_eeprom *eeprom, 253942ee18feSAjit Khaparde u8 *data) 254042ee18feSAjit Khaparde { 254142ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 254242ee18feSAjit Khaparde u16 start = eeprom->offset, length = eeprom->len; 2543f3ea3119SColin Ian King int rc = 0; 254442ee18feSAjit Khaparde 254542ee18feSAjit Khaparde memset(data, 0, eeprom->len); 254642ee18feSAjit Khaparde 254742ee18feSAjit Khaparde /* Read A0 portion of the EEPROM */ 254842ee18feSAjit Khaparde if (start < ETH_MODULE_SFF_8436_LEN) { 254942ee18feSAjit Khaparde if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN) 255042ee18feSAjit Khaparde length = ETH_MODULE_SFF_8436_LEN - start; 255142ee18feSAjit Khaparde rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 255242ee18feSAjit Khaparde start, length, data); 255342ee18feSAjit Khaparde if (rc) 255442ee18feSAjit Khaparde return rc; 255542ee18feSAjit Khaparde start += length; 255642ee18feSAjit Khaparde data += length; 255742ee18feSAjit Khaparde length = eeprom->len - length; 255842ee18feSAjit Khaparde } 255942ee18feSAjit Khaparde 256042ee18feSAjit Khaparde /* Read A2 portion of the EEPROM */ 256142ee18feSAjit Khaparde if (length) { 256242ee18feSAjit Khaparde start -= ETH_MODULE_SFF_8436_LEN; 2563dea521a2SChristophe JAILLET rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1, 2564dea521a2SChristophe JAILLET start, length, data); 256542ee18feSAjit Khaparde } 256642ee18feSAjit Khaparde return rc; 256742ee18feSAjit Khaparde } 256842ee18feSAjit Khaparde 2569ae8e98a6SDeepak Khungar static int bnxt_nway_reset(struct net_device *dev) 2570ae8e98a6SDeepak Khungar { 2571ae8e98a6SDeepak Khungar int rc = 0; 2572ae8e98a6SDeepak Khungar 2573ae8e98a6SDeepak Khungar struct bnxt *bp = netdev_priv(dev); 2574ae8e98a6SDeepak Khungar struct bnxt_link_info *link_info = &bp->link_info; 2575ae8e98a6SDeepak Khungar 2576ae8e98a6SDeepak Khungar if (!BNXT_SINGLE_PF(bp)) 2577ae8e98a6SDeepak Khungar return -EOPNOTSUPP; 2578ae8e98a6SDeepak Khungar 2579ae8e98a6SDeepak Khungar if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 2580ae8e98a6SDeepak Khungar return -EINVAL; 2581ae8e98a6SDeepak Khungar 2582ae8e98a6SDeepak Khungar if (netif_running(dev)) 2583ae8e98a6SDeepak Khungar rc = bnxt_hwrm_set_link_setting(bp, true, false); 2584ae8e98a6SDeepak Khungar 2585ae8e98a6SDeepak Khungar return rc; 2586ae8e98a6SDeepak Khungar } 2587ae8e98a6SDeepak Khungar 25885ad2cbeeSMichael Chan static int bnxt_set_phys_id(struct net_device *dev, 25895ad2cbeeSMichael Chan enum ethtool_phys_id_state state) 25905ad2cbeeSMichael Chan { 25915ad2cbeeSMichael Chan struct hwrm_port_led_cfg_input req = {0}; 25925ad2cbeeSMichael Chan struct bnxt *bp = netdev_priv(dev); 25935ad2cbeeSMichael Chan struct bnxt_pf_info *pf = &bp->pf; 25945ad2cbeeSMichael Chan struct bnxt_led_cfg *led_cfg; 25955ad2cbeeSMichael Chan u8 led_state; 25965ad2cbeeSMichael Chan __le16 duration; 25975ad2cbeeSMichael Chan int i, rc; 25985ad2cbeeSMichael Chan 25995ad2cbeeSMichael Chan if (!bp->num_leds || BNXT_VF(bp)) 26005ad2cbeeSMichael Chan return -EOPNOTSUPP; 26015ad2cbeeSMichael Chan 26025ad2cbeeSMichael Chan if (state == ETHTOOL_ID_ACTIVE) { 26035ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT; 26045ad2cbeeSMichael Chan duration = cpu_to_le16(500); 26055ad2cbeeSMichael Chan } else if (state == ETHTOOL_ID_INACTIVE) { 26065ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT; 26075ad2cbeeSMichael Chan duration = cpu_to_le16(0); 26085ad2cbeeSMichael Chan } else { 26095ad2cbeeSMichael Chan return -EINVAL; 26105ad2cbeeSMichael Chan } 26115ad2cbeeSMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1); 26125ad2cbeeSMichael Chan req.port_id = cpu_to_le16(pf->port_id); 26135ad2cbeeSMichael Chan req.num_leds = bp->num_leds; 26145ad2cbeeSMichael Chan led_cfg = (struct bnxt_led_cfg *)&req.led0_id; 26155ad2cbeeSMichael Chan for (i = 0; i < bp->num_leds; i++, led_cfg++) { 26165ad2cbeeSMichael Chan req.enables |= BNXT_LED_DFLT_ENABLES(i); 26175ad2cbeeSMichael Chan led_cfg->led_id = bp->leds[i].led_id; 26185ad2cbeeSMichael Chan led_cfg->led_state = led_state; 26195ad2cbeeSMichael Chan led_cfg->led_blink_on = duration; 26205ad2cbeeSMichael Chan led_cfg->led_blink_off = duration; 26215ad2cbeeSMichael Chan led_cfg->led_group_id = bp->leds[i].led_group_id; 26225ad2cbeeSMichael Chan } 26235ad2cbeeSMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 26245ad2cbeeSMichael Chan if (rc) 26255ad2cbeeSMichael Chan rc = -EIO; 26265ad2cbeeSMichael Chan return rc; 26275ad2cbeeSMichael Chan } 26285ad2cbeeSMichael Chan 262967fea463SMichael Chan static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring) 263067fea463SMichael Chan { 263167fea463SMichael Chan struct hwrm_selftest_irq_input req = {0}; 263267fea463SMichael Chan 263367fea463SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1); 263467fea463SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 263567fea463SMichael Chan } 263667fea463SMichael Chan 263767fea463SMichael Chan static int bnxt_test_irq(struct bnxt *bp) 263867fea463SMichael Chan { 263967fea463SMichael Chan int i; 264067fea463SMichael Chan 264167fea463SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 264267fea463SMichael Chan u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id; 264367fea463SMichael Chan int rc; 264467fea463SMichael Chan 264567fea463SMichael Chan rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring); 264667fea463SMichael Chan if (rc) 264767fea463SMichael Chan return rc; 264867fea463SMichael Chan } 264967fea463SMichael Chan return 0; 265067fea463SMichael Chan } 265167fea463SMichael Chan 2652f7dc1ea6SMichael Chan static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable) 2653f7dc1ea6SMichael Chan { 2654f7dc1ea6SMichael Chan struct hwrm_port_mac_cfg_input req = {0}; 2655f7dc1ea6SMichael Chan 2656f7dc1ea6SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1); 2657f7dc1ea6SMichael Chan 2658f7dc1ea6SMichael Chan req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK); 2659f7dc1ea6SMichael Chan if (enable) 2660f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL; 2661f7dc1ea6SMichael Chan else 2662f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE; 2663f7dc1ea6SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2664f7dc1ea6SMichael Chan } 2665f7dc1ea6SMichael Chan 266656d37462SVasundhara Volam static int bnxt_query_force_speeds(struct bnxt *bp, u16 *force_speeds) 266756d37462SVasundhara Volam { 266856d37462SVasundhara Volam struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; 266956d37462SVasundhara Volam struct hwrm_port_phy_qcaps_input req = {0}; 267056d37462SVasundhara Volam int rc; 267156d37462SVasundhara Volam 267256d37462SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); 267356d37462SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 267456d37462SVasundhara Volam rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 267556d37462SVasundhara Volam if (!rc) 267656d37462SVasundhara Volam *force_speeds = le16_to_cpu(resp->supported_speeds_force_mode); 267756d37462SVasundhara Volam 267856d37462SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 267956d37462SVasundhara Volam return rc; 268056d37462SVasundhara Volam } 268156d37462SVasundhara Volam 268291725d89SMichael Chan static int bnxt_disable_an_for_lpbk(struct bnxt *bp, 268391725d89SMichael Chan struct hwrm_port_phy_cfg_input *req) 268491725d89SMichael Chan { 268591725d89SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 268656d37462SVasundhara Volam u16 fw_advertising; 268791725d89SMichael Chan u16 fw_speed; 268891725d89SMichael Chan int rc; 268991725d89SMichael Chan 269091725d89SMichael Chan if (!link_info->autoneg) 269191725d89SMichael Chan return 0; 269291725d89SMichael Chan 269356d37462SVasundhara Volam rc = bnxt_query_force_speeds(bp, &fw_advertising); 269456d37462SVasundhara Volam if (rc) 269556d37462SVasundhara Volam return rc; 269656d37462SVasundhara Volam 269791725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB; 269891725d89SMichael Chan if (netif_carrier_ok(bp->dev)) 269991725d89SMichael Chan fw_speed = bp->link_info.link_speed; 270091725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB) 270191725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB; 270291725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB) 270391725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB; 270491725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB) 270591725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB; 270691725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB) 270791725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB; 270891725d89SMichael Chan 270991725d89SMichael Chan req->force_link_speed = cpu_to_le16(fw_speed); 271091725d89SMichael Chan req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE | 271191725d89SMichael Chan PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); 271291725d89SMichael Chan rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT); 271391725d89SMichael Chan req->flags = 0; 271491725d89SMichael Chan req->force_link_speed = cpu_to_le16(0); 271591725d89SMichael Chan return rc; 271691725d89SMichael Chan } 271791725d89SMichael Chan 271855fd0cf3SMichael Chan static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable, bool ext) 271991725d89SMichael Chan { 272091725d89SMichael Chan struct hwrm_port_phy_cfg_input req = {0}; 272191725d89SMichael Chan 272291725d89SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); 272391725d89SMichael Chan 272491725d89SMichael Chan if (enable) { 272591725d89SMichael Chan bnxt_disable_an_for_lpbk(bp, &req); 272655fd0cf3SMichael Chan if (ext) 272755fd0cf3SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_EXTERNAL; 272855fd0cf3SMichael Chan else 272991725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL; 273091725d89SMichael Chan } else { 273191725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE; 273291725d89SMichael Chan } 273391725d89SMichael Chan req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK); 273491725d89SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 273591725d89SMichael Chan } 273691725d89SMichael Chan 2737e44758b7SMichael Chan static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2738f7dc1ea6SMichael Chan u32 raw_cons, int pkt_size) 2739f7dc1ea6SMichael Chan { 2740e44758b7SMichael Chan struct bnxt_napi *bnapi = cpr->bnapi; 2741e44758b7SMichael Chan struct bnxt_rx_ring_info *rxr; 2742f7dc1ea6SMichael Chan struct bnxt_sw_rx_bd *rx_buf; 2743f7dc1ea6SMichael Chan struct rx_cmp *rxcmp; 2744f7dc1ea6SMichael Chan u16 cp_cons, cons; 2745f7dc1ea6SMichael Chan u8 *data; 2746f7dc1ea6SMichael Chan u32 len; 2747f7dc1ea6SMichael Chan int i; 2748f7dc1ea6SMichael Chan 2749e44758b7SMichael Chan rxr = bnapi->rx_ring; 2750f7dc1ea6SMichael Chan cp_cons = RING_CMP(raw_cons); 2751f7dc1ea6SMichael Chan rxcmp = (struct rx_cmp *) 2752f7dc1ea6SMichael Chan &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; 2753f7dc1ea6SMichael Chan cons = rxcmp->rx_cmp_opaque; 2754f7dc1ea6SMichael Chan rx_buf = &rxr->rx_buf_ring[cons]; 2755f7dc1ea6SMichael Chan data = rx_buf->data_ptr; 2756f7dc1ea6SMichael Chan len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT; 2757f7dc1ea6SMichael Chan if (len != pkt_size) 2758f7dc1ea6SMichael Chan return -EIO; 2759f7dc1ea6SMichael Chan i = ETH_ALEN; 2760f7dc1ea6SMichael Chan if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr)) 2761f7dc1ea6SMichael Chan return -EIO; 2762f7dc1ea6SMichael Chan i += ETH_ALEN; 2763f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) { 2764f7dc1ea6SMichael Chan if (data[i] != (u8)(i & 0xff)) 2765f7dc1ea6SMichael Chan return -EIO; 2766f7dc1ea6SMichael Chan } 2767f7dc1ea6SMichael Chan return 0; 2768f7dc1ea6SMichael Chan } 2769f7dc1ea6SMichael Chan 2770e44758b7SMichael Chan static int bnxt_poll_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2771e44758b7SMichael Chan int pkt_size) 2772f7dc1ea6SMichael Chan { 2773f7dc1ea6SMichael Chan struct tx_cmp *txcmp; 2774f7dc1ea6SMichael Chan int rc = -EIO; 2775f7dc1ea6SMichael Chan u32 raw_cons; 2776f7dc1ea6SMichael Chan u32 cons; 2777f7dc1ea6SMichael Chan int i; 2778f7dc1ea6SMichael Chan 2779f7dc1ea6SMichael Chan raw_cons = cpr->cp_raw_cons; 2780f7dc1ea6SMichael Chan for (i = 0; i < 200; i++) { 2781f7dc1ea6SMichael Chan cons = RING_CMP(raw_cons); 2782f7dc1ea6SMichael Chan txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; 2783f7dc1ea6SMichael Chan 2784f7dc1ea6SMichael Chan if (!TX_CMP_VALID(txcmp, raw_cons)) { 2785f7dc1ea6SMichael Chan udelay(5); 2786f7dc1ea6SMichael Chan continue; 2787f7dc1ea6SMichael Chan } 2788f7dc1ea6SMichael Chan 2789f7dc1ea6SMichael Chan /* The valid test of the entry must be done first before 2790f7dc1ea6SMichael Chan * reading any further. 2791f7dc1ea6SMichael Chan */ 2792f7dc1ea6SMichael Chan dma_rmb(); 2793f7dc1ea6SMichael Chan if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) { 2794e44758b7SMichael Chan rc = bnxt_rx_loopback(bp, cpr, raw_cons, pkt_size); 2795f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2796f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2797f7dc1ea6SMichael Chan break; 2798f7dc1ea6SMichael Chan } 2799f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2800f7dc1ea6SMichael Chan } 2801f7dc1ea6SMichael Chan cpr->cp_raw_cons = raw_cons; 2802f7dc1ea6SMichael Chan return rc; 2803f7dc1ea6SMichael Chan } 2804f7dc1ea6SMichael Chan 2805f7dc1ea6SMichael Chan static int bnxt_run_loopback(struct bnxt *bp) 2806f7dc1ea6SMichael Chan { 2807f7dc1ea6SMichael Chan struct bnxt_tx_ring_info *txr = &bp->tx_ring[0]; 280884404d5fSMichael Chan struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0]; 2809e44758b7SMichael Chan struct bnxt_cp_ring_info *cpr; 2810f7dc1ea6SMichael Chan int pkt_size, i = 0; 2811f7dc1ea6SMichael Chan struct sk_buff *skb; 2812f7dc1ea6SMichael Chan dma_addr_t map; 2813f7dc1ea6SMichael Chan u8 *data; 2814f7dc1ea6SMichael Chan int rc; 2815f7dc1ea6SMichael Chan 281684404d5fSMichael Chan cpr = &rxr->bnapi->cp_ring; 281784404d5fSMichael Chan if (bp->flags & BNXT_FLAG_CHIP_P5) 281884404d5fSMichael Chan cpr = cpr->cp_ring_arr[BNXT_RX_HDL]; 2819f7dc1ea6SMichael Chan pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh); 2820f7dc1ea6SMichael Chan skb = netdev_alloc_skb(bp->dev, pkt_size); 2821f7dc1ea6SMichael Chan if (!skb) 2822f7dc1ea6SMichael Chan return -ENOMEM; 2823f7dc1ea6SMichael Chan data = skb_put(skb, pkt_size); 2824f7dc1ea6SMichael Chan eth_broadcast_addr(data); 2825f7dc1ea6SMichael Chan i += ETH_ALEN; 2826f7dc1ea6SMichael Chan ether_addr_copy(&data[i], bp->dev->dev_addr); 2827f7dc1ea6SMichael Chan i += ETH_ALEN; 2828f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) 2829f7dc1ea6SMichael Chan data[i] = (u8)(i & 0xff); 2830f7dc1ea6SMichael Chan 2831f7dc1ea6SMichael Chan map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size, 2832f7dc1ea6SMichael Chan PCI_DMA_TODEVICE); 2833f7dc1ea6SMichael Chan if (dma_mapping_error(&bp->pdev->dev, map)) { 2834f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2835f7dc1ea6SMichael Chan return -EIO; 2836f7dc1ea6SMichael Chan } 2837c1ba92a8SMichael Chan bnxt_xmit_bd(bp, txr, map, pkt_size); 2838f7dc1ea6SMichael Chan 2839f7dc1ea6SMichael Chan /* Sync BD data before updating doorbell */ 2840f7dc1ea6SMichael Chan wmb(); 2841f7dc1ea6SMichael Chan 2842697197e5SMichael Chan bnxt_db_write(bp, &txr->tx_db, txr->tx_prod); 2843e44758b7SMichael Chan rc = bnxt_poll_loopback(bp, cpr, pkt_size); 2844f7dc1ea6SMichael Chan 2845f7dc1ea6SMichael Chan dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE); 2846f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2847f7dc1ea6SMichael Chan return rc; 2848f7dc1ea6SMichael Chan } 2849f7dc1ea6SMichael Chan 2850eb513658SMichael Chan static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results) 2851eb513658SMichael Chan { 2852eb513658SMichael Chan struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr; 2853eb513658SMichael Chan struct hwrm_selftest_exec_input req = {0}; 2854eb513658SMichael Chan int rc; 2855eb513658SMichael Chan 2856eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1); 2857eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2858eb513658SMichael Chan resp->test_success = 0; 2859eb513658SMichael Chan req.flags = test_mask; 2860eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout); 2861eb513658SMichael Chan *test_results = resp->test_success; 2862eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2863eb513658SMichael Chan return rc; 2864eb513658SMichael Chan } 2865eb513658SMichael Chan 286655fd0cf3SMichael Chan #define BNXT_DRV_TESTS 4 2867f7dc1ea6SMichael Chan #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS) 286891725d89SMichael Chan #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1) 286955fd0cf3SMichael Chan #define BNXT_EXTLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2) 287055fd0cf3SMichael Chan #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 3) 2871eb513658SMichael Chan 2872eb513658SMichael Chan static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest, 2873eb513658SMichael Chan u64 *buf) 2874eb513658SMichael Chan { 2875eb513658SMichael Chan struct bnxt *bp = netdev_priv(dev); 287655fd0cf3SMichael Chan bool do_ext_lpbk = false; 2877eb513658SMichael Chan bool offline = false; 2878eb513658SMichael Chan u8 test_results = 0; 2879eb513658SMichael Chan u8 test_mask = 0; 2880d27e2ca1SMichael Chan int rc = 0, i; 2881eb513658SMichael Chan 2882eb513658SMichael Chan if (!bp->num_tests || !BNXT_SINGLE_PF(bp)) 2883eb513658SMichael Chan return; 2884eb513658SMichael Chan memset(buf, 0, sizeof(u64) * bp->num_tests); 2885eb513658SMichael Chan if (!netif_running(dev)) { 2886eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2887eb513658SMichael Chan return; 2888eb513658SMichael Chan } 2889eb513658SMichael Chan 289055fd0cf3SMichael Chan if ((etest->flags & ETH_TEST_FL_EXTERNAL_LB) && 289155fd0cf3SMichael Chan (bp->test_info->flags & BNXT_TEST_FL_EXT_LPBK)) 289255fd0cf3SMichael Chan do_ext_lpbk = true; 289355fd0cf3SMichael Chan 2894eb513658SMichael Chan if (etest->flags & ETH_TEST_FL_OFFLINE) { 2895eb513658SMichael Chan if (bp->pf.active_vfs) { 2896eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2897eb513658SMichael Chan netdev_warn(dev, "Offline tests cannot be run with active VFs\n"); 2898eb513658SMichael Chan return; 2899eb513658SMichael Chan } 2900eb513658SMichael Chan offline = true; 2901eb513658SMichael Chan } 2902eb513658SMichael Chan 2903eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 2904eb513658SMichael Chan u8 bit_val = 1 << i; 2905eb513658SMichael Chan 2906eb513658SMichael Chan if (!(bp->test_info->offline_mask & bit_val)) 2907eb513658SMichael Chan test_mask |= bit_val; 2908eb513658SMichael Chan else if (offline) 2909eb513658SMichael Chan test_mask |= bit_val; 2910eb513658SMichael Chan } 2911eb513658SMichael Chan if (!offline) { 2912eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 2913eb513658SMichael Chan } else { 2914eb513658SMichael Chan rc = bnxt_close_nic(bp, false, false); 2915eb513658SMichael Chan if (rc) 2916eb513658SMichael Chan return; 2917eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 2918f7dc1ea6SMichael Chan 2919f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 1; 2920f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, true); 2921f7dc1ea6SMichael Chan msleep(250); 2922f7dc1ea6SMichael Chan rc = bnxt_half_open_nic(bp); 2923f7dc1ea6SMichael Chan if (rc) { 2924f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 2925f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2926f7dc1ea6SMichael Chan return; 2927f7dc1ea6SMichael Chan } 2928f7dc1ea6SMichael Chan if (bnxt_run_loopback(bp)) 2929f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2930f7dc1ea6SMichael Chan else 2931f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 0; 2932f7dc1ea6SMichael Chan 2933f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 293455fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, false); 293591725d89SMichael Chan msleep(1000); 293691725d89SMichael Chan if (bnxt_run_loopback(bp)) { 293791725d89SMichael Chan buf[BNXT_PHYLPBK_TEST_IDX] = 1; 293891725d89SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 293991725d89SMichael Chan } 294055fd0cf3SMichael Chan if (do_ext_lpbk) { 294155fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; 294255fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, true); 294355fd0cf3SMichael Chan msleep(1000); 294455fd0cf3SMichael Chan if (bnxt_run_loopback(bp)) { 294555fd0cf3SMichael Chan buf[BNXT_EXTLPBK_TEST_IDX] = 1; 294655fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 294755fd0cf3SMichael Chan } 294855fd0cf3SMichael Chan } 294955fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, false, false); 295091725d89SMichael Chan bnxt_half_close_nic(bp); 2951d27e2ca1SMichael Chan rc = bnxt_open_nic(bp, false, true); 2952eb513658SMichael Chan } 2953d27e2ca1SMichael Chan if (rc || bnxt_test_irq(bp)) { 295467fea463SMichael Chan buf[BNXT_IRQ_TEST_IDX] = 1; 295567fea463SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 295667fea463SMichael Chan } 2957eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 2958eb513658SMichael Chan u8 bit_val = 1 << i; 2959eb513658SMichael Chan 2960eb513658SMichael Chan if ((test_mask & bit_val) && !(test_results & bit_val)) { 2961eb513658SMichael Chan buf[i] = 1; 2962eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2963eb513658SMichael Chan } 2964eb513658SMichael Chan } 2965eb513658SMichael Chan } 2966eb513658SMichael Chan 296749f7972fSVasundhara Volam static int bnxt_reset(struct net_device *dev, u32 *flags) 296849f7972fSVasundhara Volam { 296949f7972fSVasundhara Volam struct bnxt *bp = netdev_priv(dev); 297049f7972fSVasundhara Volam int rc = 0; 297149f7972fSVasundhara Volam 297249f7972fSVasundhara Volam if (!BNXT_PF(bp)) { 297349f7972fSVasundhara Volam netdev_err(dev, "Reset is not supported from a VF\n"); 297449f7972fSVasundhara Volam return -EOPNOTSUPP; 297549f7972fSVasundhara Volam } 297649f7972fSVasundhara Volam 297749f7972fSVasundhara Volam if (pci_vfs_assigned(bp->pdev)) { 297849f7972fSVasundhara Volam netdev_err(dev, 297949f7972fSVasundhara Volam "Reset not allowed when VFs are assigned to VMs\n"); 298049f7972fSVasundhara Volam return -EBUSY; 298149f7972fSVasundhara Volam } 298249f7972fSVasundhara Volam 298349f7972fSVasundhara Volam if (*flags == ETH_RESET_ALL) { 298449f7972fSVasundhara Volam /* This feature is not supported in older firmware versions */ 298549f7972fSVasundhara Volam if (bp->hwrm_spec_code < 0x10803) 298649f7972fSVasundhara Volam return -EOPNOTSUPP; 298749f7972fSVasundhara Volam 298849f7972fSVasundhara Volam rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_CHIP); 29892373d8d6SScott Branden if (!rc) { 299049f7972fSVasundhara Volam netdev_info(dev, "Reset request successful. Reload driver to complete reset\n"); 29912373d8d6SScott Branden *flags = 0; 29922373d8d6SScott Branden } 29936502ad59SScott Branden } else if (*flags == ETH_RESET_AP) { 29946502ad59SScott Branden /* This feature is not supported in older firmware versions */ 29956502ad59SScott Branden if (bp->hwrm_spec_code < 0x10803) 29966502ad59SScott Branden return -EOPNOTSUPP; 29976502ad59SScott Branden 29986502ad59SScott Branden rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_AP); 29992373d8d6SScott Branden if (!rc) { 30006502ad59SScott Branden netdev_info(dev, "Reset Application Processor request successful.\n"); 30012373d8d6SScott Branden *flags = 0; 30022373d8d6SScott Branden } 300349f7972fSVasundhara Volam } else { 300449f7972fSVasundhara Volam rc = -EINVAL; 300549f7972fSVasundhara Volam } 300649f7972fSVasundhara Volam 300749f7972fSVasundhara Volam return rc; 300849f7972fSVasundhara Volam } 300949f7972fSVasundhara Volam 30106c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg, int msg_len, 30116c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info *info) 30126c5657d0SVasundhara Volam { 30136c5657d0SVasundhara Volam struct hwrm_dbg_cmn_output *cmn_resp = bp->hwrm_cmd_resp_addr; 30146c5657d0SVasundhara Volam struct hwrm_dbg_cmn_input *cmn_req = msg; 30156c5657d0SVasundhara Volam __le16 *seq_ptr = msg + info->seq_off; 30166c5657d0SVasundhara Volam u16 seq = 0, len, segs_off; 30176c5657d0SVasundhara Volam void *resp = cmn_resp; 30186c5657d0SVasundhara Volam dma_addr_t dma_handle; 30196c5657d0SVasundhara Volam int rc, off = 0; 30206c5657d0SVasundhara Volam void *dma_buf; 30216c5657d0SVasundhara Volam 30226c5657d0SVasundhara Volam dma_buf = dma_alloc_coherent(&bp->pdev->dev, info->dma_len, &dma_handle, 30236c5657d0SVasundhara Volam GFP_KERNEL); 30246c5657d0SVasundhara Volam if (!dma_buf) 30256c5657d0SVasundhara Volam return -ENOMEM; 30266c5657d0SVasundhara Volam 30276c5657d0SVasundhara Volam segs_off = offsetof(struct hwrm_dbg_coredump_list_output, 30286c5657d0SVasundhara Volam total_segments); 30296c5657d0SVasundhara Volam cmn_req->host_dest_addr = cpu_to_le64(dma_handle); 30306c5657d0SVasundhara Volam cmn_req->host_buf_len = cpu_to_le32(info->dma_len); 30316c5657d0SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 30326c5657d0SVasundhara Volam while (1) { 30336c5657d0SVasundhara Volam *seq_ptr = cpu_to_le16(seq); 30346c5657d0SVasundhara Volam rc = _hwrm_send_message(bp, msg, msg_len, HWRM_CMD_TIMEOUT); 30356c5657d0SVasundhara Volam if (rc) 30366c5657d0SVasundhara Volam break; 30376c5657d0SVasundhara Volam 30386c5657d0SVasundhara Volam len = le16_to_cpu(*((__le16 *)(resp + info->data_len_off))); 30396c5657d0SVasundhara Volam if (!seq && 30406c5657d0SVasundhara Volam cmn_req->req_type == cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) { 30416c5657d0SVasundhara Volam info->segs = le16_to_cpu(*((__le16 *)(resp + 30426c5657d0SVasundhara Volam segs_off))); 30436c5657d0SVasundhara Volam if (!info->segs) { 30446c5657d0SVasundhara Volam rc = -EIO; 30456c5657d0SVasundhara Volam break; 30466c5657d0SVasundhara Volam } 30476c5657d0SVasundhara Volam 30486c5657d0SVasundhara Volam info->dest_buf_size = info->segs * 30496c5657d0SVasundhara Volam sizeof(struct coredump_segment_record); 30506c5657d0SVasundhara Volam info->dest_buf = kmalloc(info->dest_buf_size, 30516c5657d0SVasundhara Volam GFP_KERNEL); 30526c5657d0SVasundhara Volam if (!info->dest_buf) { 30536c5657d0SVasundhara Volam rc = -ENOMEM; 30546c5657d0SVasundhara Volam break; 30556c5657d0SVasundhara Volam } 30566c5657d0SVasundhara Volam } 30576c5657d0SVasundhara Volam 30586c5657d0SVasundhara Volam if (info->dest_buf) 30596c5657d0SVasundhara Volam memcpy(info->dest_buf + off, dma_buf, len); 30606c5657d0SVasundhara Volam 30616c5657d0SVasundhara Volam if (cmn_req->req_type == 30626c5657d0SVasundhara Volam cpu_to_le16(HWRM_DBG_COREDUMP_RETRIEVE)) 30636c5657d0SVasundhara Volam info->dest_buf_size += len; 30646c5657d0SVasundhara Volam 30656c5657d0SVasundhara Volam if (!(cmn_resp->flags & HWRM_DBG_CMN_FLAGS_MORE)) 30666c5657d0SVasundhara Volam break; 30676c5657d0SVasundhara Volam 30686c5657d0SVasundhara Volam seq++; 30696c5657d0SVasundhara Volam off += len; 30706c5657d0SVasundhara Volam } 30716c5657d0SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 30726c5657d0SVasundhara Volam dma_free_coherent(&bp->pdev->dev, info->dma_len, dma_buf, dma_handle); 30736c5657d0SVasundhara Volam return rc; 30746c5657d0SVasundhara Volam } 30756c5657d0SVasundhara Volam 30766c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_list(struct bnxt *bp, 30776c5657d0SVasundhara Volam struct bnxt_coredump *coredump) 30786c5657d0SVasundhara Volam { 30796c5657d0SVasundhara Volam struct hwrm_dbg_coredump_list_input req = {0}; 30806c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 30816c5657d0SVasundhara Volam int rc; 30826c5657d0SVasundhara Volam 30836c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_LIST, -1, -1); 30846c5657d0SVasundhara Volam 30856c5657d0SVasundhara Volam info.dma_len = COREDUMP_LIST_BUF_LEN; 30866c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_list_input, seq_no); 30876c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_list_output, 30886c5657d0SVasundhara Volam data_len); 30896c5657d0SVasundhara Volam 30906c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 30916c5657d0SVasundhara Volam if (!rc) { 30926c5657d0SVasundhara Volam coredump->data = info.dest_buf; 30936c5657d0SVasundhara Volam coredump->data_size = info.dest_buf_size; 30946c5657d0SVasundhara Volam coredump->total_segs = info.segs; 30956c5657d0SVasundhara Volam } 30966c5657d0SVasundhara Volam return rc; 30976c5657d0SVasundhara Volam } 30986c5657d0SVasundhara Volam 30996c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_initiate(struct bnxt *bp, u16 component_id, 31006c5657d0SVasundhara Volam u16 segment_id) 31016c5657d0SVasundhara Volam { 31026c5657d0SVasundhara Volam struct hwrm_dbg_coredump_initiate_input req = {0}; 31036c5657d0SVasundhara Volam 31046c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_INITIATE, -1, -1); 31056c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 31066c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 31076c5657d0SVasundhara Volam 31086c5657d0SVasundhara Volam return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 31096c5657d0SVasundhara Volam } 31106c5657d0SVasundhara Volam 31116c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_retrieve(struct bnxt *bp, u16 component_id, 31126c5657d0SVasundhara Volam u16 segment_id, u32 *seg_len, 31136c5657d0SVasundhara Volam void *buf, u32 offset) 31146c5657d0SVasundhara Volam { 31156c5657d0SVasundhara Volam struct hwrm_dbg_coredump_retrieve_input req = {0}; 31166c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 31176c5657d0SVasundhara Volam int rc; 31186c5657d0SVasundhara Volam 31196c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_RETRIEVE, -1, -1); 31206c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 31216c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 31226c5657d0SVasundhara Volam 31236c5657d0SVasundhara Volam info.dma_len = COREDUMP_RETRIEVE_BUF_LEN; 31246c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_retrieve_input, 31256c5657d0SVasundhara Volam seq_no); 31266c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_retrieve_output, 31276c5657d0SVasundhara Volam data_len); 31286c5657d0SVasundhara Volam if (buf) 31296c5657d0SVasundhara Volam info.dest_buf = buf + offset; 31306c5657d0SVasundhara Volam 31316c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 31326c5657d0SVasundhara Volam if (!rc) 31336c5657d0SVasundhara Volam *seg_len = info.dest_buf_size; 31346c5657d0SVasundhara Volam 31356c5657d0SVasundhara Volam return rc; 31366c5657d0SVasundhara Volam } 31376c5657d0SVasundhara Volam 31386c5657d0SVasundhara Volam static void 31396c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(struct bnxt *bp, 31406c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr *seg_hdr, 31416c5657d0SVasundhara Volam struct coredump_segment_record *seg_rec, u32 seg_len, 31426c5657d0SVasundhara Volam int status, u32 duration, u32 instance) 31436c5657d0SVasundhara Volam { 31446c5657d0SVasundhara Volam memset(seg_hdr, 0, sizeof(*seg_hdr)); 31458605212aSVasundhara Volam memcpy(seg_hdr->signature, "sEgM", 4); 31466c5657d0SVasundhara Volam if (seg_rec) { 31476c5657d0SVasundhara Volam seg_hdr->component_id = (__force __le32)seg_rec->component_id; 31486c5657d0SVasundhara Volam seg_hdr->segment_id = (__force __le32)seg_rec->segment_id; 31496c5657d0SVasundhara Volam seg_hdr->low_version = seg_rec->version_low; 31506c5657d0SVasundhara Volam seg_hdr->high_version = seg_rec->version_hi; 31516c5657d0SVasundhara Volam } else { 31526c5657d0SVasundhara Volam /* For hwrm_ver_get response Component id = 2 31536c5657d0SVasundhara Volam * and Segment id = 0 31546c5657d0SVasundhara Volam */ 31556c5657d0SVasundhara Volam seg_hdr->component_id = cpu_to_le32(2); 31566c5657d0SVasundhara Volam seg_hdr->segment_id = 0; 31576c5657d0SVasundhara Volam } 31586c5657d0SVasundhara Volam seg_hdr->function_id = cpu_to_le16(bp->pdev->devfn); 31596c5657d0SVasundhara Volam seg_hdr->length = cpu_to_le32(seg_len); 31606c5657d0SVasundhara Volam seg_hdr->status = cpu_to_le32(status); 31616c5657d0SVasundhara Volam seg_hdr->duration = cpu_to_le32(duration); 31626c5657d0SVasundhara Volam seg_hdr->data_offset = cpu_to_le32(sizeof(*seg_hdr)); 31636c5657d0SVasundhara Volam seg_hdr->instance = cpu_to_le32(instance); 31646c5657d0SVasundhara Volam } 31656c5657d0SVasundhara Volam 31666c5657d0SVasundhara Volam static void 31676c5657d0SVasundhara Volam bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record, 31686c5657d0SVasundhara Volam time64_t start, s16 start_utc, u16 total_segs, 31696c5657d0SVasundhara Volam int status) 31706c5657d0SVasundhara Volam { 31716c5657d0SVasundhara Volam time64_t end = ktime_get_real_seconds(); 31726c5657d0SVasundhara Volam u32 os_ver_major = 0, os_ver_minor = 0; 31736c5657d0SVasundhara Volam struct tm tm; 31746c5657d0SVasundhara Volam 31756c5657d0SVasundhara Volam time64_to_tm(start, 0, &tm); 31766c5657d0SVasundhara Volam memset(record, 0, sizeof(*record)); 31778605212aSVasundhara Volam memcpy(record->signature, "cOrE", 4); 31786c5657d0SVasundhara Volam record->flags = 0; 31796c5657d0SVasundhara Volam record->low_version = 0; 31806c5657d0SVasundhara Volam record->high_version = 1; 31816c5657d0SVasundhara Volam record->asic_state = 0; 31823d46eee5SArnd Bergmann strlcpy(record->system_name, utsname()->nodename, 31833d46eee5SArnd Bergmann sizeof(record->system_name)); 31848dc5ae2dSVasundhara Volam record->year = cpu_to_le16(tm.tm_year + 1900); 31858dc5ae2dSVasundhara Volam record->month = cpu_to_le16(tm.tm_mon + 1); 31866c5657d0SVasundhara Volam record->day = cpu_to_le16(tm.tm_mday); 31876c5657d0SVasundhara Volam record->hour = cpu_to_le16(tm.tm_hour); 31886c5657d0SVasundhara Volam record->minute = cpu_to_le16(tm.tm_min); 31896c5657d0SVasundhara Volam record->second = cpu_to_le16(tm.tm_sec); 31906c5657d0SVasundhara Volam record->utc_bias = cpu_to_le16(start_utc); 31916c5657d0SVasundhara Volam strcpy(record->commandline, "ethtool -w"); 31926c5657d0SVasundhara Volam record->total_segments = cpu_to_le32(total_segs); 31936c5657d0SVasundhara Volam 31946c5657d0SVasundhara Volam sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor); 31956c5657d0SVasundhara Volam record->os_ver_major = cpu_to_le32(os_ver_major); 31966c5657d0SVasundhara Volam record->os_ver_minor = cpu_to_le32(os_ver_minor); 31976c5657d0SVasundhara Volam 31988605212aSVasundhara Volam strlcpy(record->os_name, utsname()->sysname, 32); 31996c5657d0SVasundhara Volam time64_to_tm(end, 0, &tm); 32006c5657d0SVasundhara Volam record->end_year = cpu_to_le16(tm.tm_year + 1900); 32016c5657d0SVasundhara Volam record->end_month = cpu_to_le16(tm.tm_mon + 1); 32026c5657d0SVasundhara Volam record->end_day = cpu_to_le16(tm.tm_mday); 32036c5657d0SVasundhara Volam record->end_hour = cpu_to_le16(tm.tm_hour); 32046c5657d0SVasundhara Volam record->end_minute = cpu_to_le16(tm.tm_min); 32056c5657d0SVasundhara Volam record->end_second = cpu_to_le16(tm.tm_sec); 32066c5657d0SVasundhara Volam record->end_utc_bias = cpu_to_le16(sys_tz.tz_minuteswest * 60); 32076c5657d0SVasundhara Volam record->asic_id1 = cpu_to_le32(bp->chip_num << 16 | 32086c5657d0SVasundhara Volam bp->ver_resp.chip_rev << 8 | 32096c5657d0SVasundhara Volam bp->ver_resp.chip_metal); 32106c5657d0SVasundhara Volam record->asic_id2 = 0; 32116c5657d0SVasundhara Volam record->coredump_status = cpu_to_le32(status); 32126c5657d0SVasundhara Volam record->ioctl_low_version = 0; 32136c5657d0SVasundhara Volam record->ioctl_high_version = 0; 32146c5657d0SVasundhara Volam } 32156c5657d0SVasundhara Volam 32166c5657d0SVasundhara Volam static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len) 32176c5657d0SVasundhara Volam { 32186c5657d0SVasundhara Volam u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output); 32196c5657d0SVasundhara Volam struct coredump_segment_record *seg_record = NULL; 32206c5657d0SVasundhara Volam u32 offset = 0, seg_hdr_len, seg_record_len; 32216c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr seg_hdr; 32226c5657d0SVasundhara Volam struct bnxt_coredump coredump = {NULL}; 32236c5657d0SVasundhara Volam time64_t start_time; 32246c5657d0SVasundhara Volam u16 start_utc; 32256c5657d0SVasundhara Volam int rc = 0, i; 32266c5657d0SVasundhara Volam 32276c5657d0SVasundhara Volam start_time = ktime_get_real_seconds(); 32286c5657d0SVasundhara Volam start_utc = sys_tz.tz_minuteswest * 60; 32296c5657d0SVasundhara Volam seg_hdr_len = sizeof(seg_hdr); 32306c5657d0SVasundhara Volam 32316c5657d0SVasundhara Volam /* First segment should be hwrm_ver_get response */ 32326c5657d0SVasundhara Volam *dump_len = seg_hdr_len + ver_get_resp_len; 32336c5657d0SVasundhara Volam if (buf) { 32346c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, NULL, ver_get_resp_len, 32356c5657d0SVasundhara Volam 0, 0, 0); 32366c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 32376c5657d0SVasundhara Volam offset += seg_hdr_len; 32386c5657d0SVasundhara Volam memcpy(buf + offset, &bp->ver_resp, ver_get_resp_len); 32396c5657d0SVasundhara Volam offset += ver_get_resp_len; 32406c5657d0SVasundhara Volam } 32416c5657d0SVasundhara Volam 32426c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_list(bp, &coredump); 32436c5657d0SVasundhara Volam if (rc) { 32446c5657d0SVasundhara Volam netdev_err(bp->dev, "Failed to get coredump segment list\n"); 32456c5657d0SVasundhara Volam goto err; 32466c5657d0SVasundhara Volam } 32476c5657d0SVasundhara Volam 32486c5657d0SVasundhara Volam *dump_len += seg_hdr_len * coredump.total_segs; 32496c5657d0SVasundhara Volam 32506c5657d0SVasundhara Volam seg_record = (struct coredump_segment_record *)coredump.data; 32516c5657d0SVasundhara Volam seg_record_len = sizeof(*seg_record); 32526c5657d0SVasundhara Volam 32536c5657d0SVasundhara Volam for (i = 0; i < coredump.total_segs; i++) { 32546c5657d0SVasundhara Volam u16 comp_id = le16_to_cpu(seg_record->component_id); 32556c5657d0SVasundhara Volam u16 seg_id = le16_to_cpu(seg_record->segment_id); 32566c5657d0SVasundhara Volam u32 duration = 0, seg_len = 0; 32576c5657d0SVasundhara Volam unsigned long start, end; 32586c5657d0SVasundhara Volam 32596c5657d0SVasundhara Volam start = jiffies; 32606c5657d0SVasundhara Volam 32616c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_initiate(bp, comp_id, seg_id); 32626c5657d0SVasundhara Volam if (rc) { 32636c5657d0SVasundhara Volam netdev_err(bp->dev, 32646c5657d0SVasundhara Volam "Failed to initiate coredump for seg = %d\n", 32656c5657d0SVasundhara Volam seg_record->segment_id); 32666c5657d0SVasundhara Volam goto next_seg; 32676c5657d0SVasundhara Volam } 32686c5657d0SVasundhara Volam 32696c5657d0SVasundhara Volam /* Write segment data into the buffer */ 32706c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_retrieve(bp, comp_id, seg_id, 32716c5657d0SVasundhara Volam &seg_len, buf, 32726c5657d0SVasundhara Volam offset + seg_hdr_len); 32736c5657d0SVasundhara Volam if (rc) 32746c5657d0SVasundhara Volam netdev_err(bp->dev, 32756c5657d0SVasundhara Volam "Failed to retrieve coredump for seg = %d\n", 32766c5657d0SVasundhara Volam seg_record->segment_id); 32776c5657d0SVasundhara Volam 32786c5657d0SVasundhara Volam next_seg: 32796c5657d0SVasundhara Volam end = jiffies; 32806c5657d0SVasundhara Volam duration = jiffies_to_msecs(end - start); 32816c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, seg_record, seg_len, 32826c5657d0SVasundhara Volam rc, duration, 0); 32836c5657d0SVasundhara Volam 32846c5657d0SVasundhara Volam if (buf) { 32856c5657d0SVasundhara Volam /* Write segment header into the buffer */ 32866c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 32876c5657d0SVasundhara Volam offset += seg_hdr_len + seg_len; 32886c5657d0SVasundhara Volam } 32896c5657d0SVasundhara Volam 32906c5657d0SVasundhara Volam *dump_len += seg_len; 32916c5657d0SVasundhara Volam seg_record = 32926c5657d0SVasundhara Volam (struct coredump_segment_record *)((u8 *)seg_record + 32936c5657d0SVasundhara Volam seg_record_len); 32946c5657d0SVasundhara Volam } 32956c5657d0SVasundhara Volam 32966c5657d0SVasundhara Volam err: 32971bbf3aedSArnd Bergmann if (buf) 32981bbf3aedSArnd Bergmann bnxt_fill_coredump_record(bp, buf + offset, start_time, 32996c5657d0SVasundhara Volam start_utc, coredump.total_segs + 1, 33006c5657d0SVasundhara Volam rc); 33016c5657d0SVasundhara Volam kfree(coredump.data); 33021bbf3aedSArnd Bergmann *dump_len += sizeof(struct bnxt_coredump_record); 33036c5657d0SVasundhara Volam 33046c5657d0SVasundhara Volam return rc; 33056c5657d0SVasundhara Volam } 33066c5657d0SVasundhara Volam 33076c5657d0SVasundhara Volam static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump) 33086c5657d0SVasundhara Volam { 33096c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 33106c5657d0SVasundhara Volam 33116c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 33126c5657d0SVasundhara Volam return -EOPNOTSUPP; 33136c5657d0SVasundhara Volam 33146c5657d0SVasundhara Volam dump->version = bp->ver_resp.hwrm_fw_maj_8b << 24 | 33156c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_min_8b << 16 | 33166c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_bld_8b << 8 | 33176c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_rsvd_8b; 33186c5657d0SVasundhara Volam 33196c5657d0SVasundhara Volam return bnxt_get_coredump(bp, NULL, &dump->len); 33206c5657d0SVasundhara Volam } 33216c5657d0SVasundhara Volam 33226c5657d0SVasundhara Volam static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump, 33236c5657d0SVasundhara Volam void *buf) 33246c5657d0SVasundhara Volam { 33256c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 33266c5657d0SVasundhara Volam 33276c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 33286c5657d0SVasundhara Volam return -EOPNOTSUPP; 33296c5657d0SVasundhara Volam 33306c5657d0SVasundhara Volam memset(buf, 0, dump->len); 33316c5657d0SVasundhara Volam 33326c5657d0SVasundhara Volam return bnxt_get_coredump(bp, buf, &dump->len); 33336c5657d0SVasundhara Volam } 33346c5657d0SVasundhara Volam 3335eb513658SMichael Chan void bnxt_ethtool_init(struct bnxt *bp) 3336eb513658SMichael Chan { 3337eb513658SMichael Chan struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr; 3338eb513658SMichael Chan struct hwrm_selftest_qlist_input req = {0}; 3339eb513658SMichael Chan struct bnxt_test_info *test_info; 3340431aa1ebSMichael Chan struct net_device *dev = bp->dev; 3341eb513658SMichael Chan int i, rc; 3342eb513658SMichael Chan 3343691aa620SVasundhara Volam if (!(bp->fw_cap & BNXT_FW_CAP_PKG_VER)) 3344a60faa60SVasundhara Volam bnxt_get_pkgver(dev); 3345431aa1ebSMichael Chan 3346eb513658SMichael Chan if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp)) 3347eb513658SMichael Chan return; 3348eb513658SMichael Chan 3349eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1); 3350eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 3351eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 3352eb513658SMichael Chan if (rc) 3353eb513658SMichael Chan goto ethtool_init_exit; 3354eb513658SMichael Chan 3355eb513658SMichael Chan test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL); 3356eb513658SMichael Chan if (!test_info) 3357eb513658SMichael Chan goto ethtool_init_exit; 3358eb513658SMichael Chan 3359eb513658SMichael Chan bp->test_info = test_info; 3360eb513658SMichael Chan bp->num_tests = resp->num_tests + BNXT_DRV_TESTS; 3361eb513658SMichael Chan if (bp->num_tests > BNXT_MAX_TEST) 3362eb513658SMichael Chan bp->num_tests = BNXT_MAX_TEST; 3363eb513658SMichael Chan 3364eb513658SMichael Chan test_info->offline_mask = resp->offline_tests; 3365eb513658SMichael Chan test_info->timeout = le16_to_cpu(resp->test_timeout); 3366eb513658SMichael Chan if (!test_info->timeout) 3367eb513658SMichael Chan test_info->timeout = HWRM_CMD_TIMEOUT; 3368eb513658SMichael Chan for (i = 0; i < bp->num_tests; i++) { 3369eb513658SMichael Chan char *str = test_info->string[i]; 3370eb513658SMichael Chan char *fw_str = resp->test0_name + i * 32; 3371eb513658SMichael Chan 3372f7dc1ea6SMichael Chan if (i == BNXT_MACLPBK_TEST_IDX) { 3373f7dc1ea6SMichael Chan strcpy(str, "Mac loopback test (offline)"); 337491725d89SMichael Chan } else if (i == BNXT_PHYLPBK_TEST_IDX) { 337591725d89SMichael Chan strcpy(str, "Phy loopback test (offline)"); 337655fd0cf3SMichael Chan } else if (i == BNXT_EXTLPBK_TEST_IDX) { 337755fd0cf3SMichael Chan strcpy(str, "Ext loopback test (offline)"); 337867fea463SMichael Chan } else if (i == BNXT_IRQ_TEST_IDX) { 337967fea463SMichael Chan strcpy(str, "Interrupt_test (offline)"); 3380f7dc1ea6SMichael Chan } else { 3381eb513658SMichael Chan strlcpy(str, fw_str, ETH_GSTRING_LEN); 3382eb513658SMichael Chan strncat(str, " test", ETH_GSTRING_LEN - strlen(str)); 3383eb513658SMichael Chan if (test_info->offline_mask & (1 << i)) 3384eb513658SMichael Chan strncat(str, " (offline)", 3385eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3386eb513658SMichael Chan else 3387eb513658SMichael Chan strncat(str, " (online)", 3388eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3389eb513658SMichael Chan } 3390f7dc1ea6SMichael Chan } 3391eb513658SMichael Chan 3392eb513658SMichael Chan ethtool_init_exit: 3393eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 3394eb513658SMichael Chan } 3395eb513658SMichael Chan 3396eb513658SMichael Chan void bnxt_ethtool_free(struct bnxt *bp) 3397eb513658SMichael Chan { 3398eb513658SMichael Chan kfree(bp->test_info); 3399eb513658SMichael Chan bp->test_info = NULL; 3400eb513658SMichael Chan } 3401eb513658SMichael Chan 3402c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 340300c04a92SMichael Chan .get_link_ksettings = bnxt_get_link_ksettings, 340400c04a92SMichael Chan .set_link_ksettings = bnxt_set_link_ksettings, 3405c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 3406c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 3407c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 34088e202366SMichael Chan .get_wol = bnxt_get_wol, 34095282db6cSMichael Chan .set_wol = bnxt_set_wol, 3410c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 3411c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 3412c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 3413c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 3414c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 3415c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 3416c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 3417c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 3418c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 3419c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 3420c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 3421c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 3422a011952aSMichael Chan .set_rxnfc = bnxt_set_rxnfc, 3423c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 3424c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 3425c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 3426c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 3427c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 3428c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 3429c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 3430c0c050c5SMichael Chan .get_link = bnxt_get_link, 343172b34f04SMichael Chan .get_eee = bnxt_get_eee, 343272b34f04SMichael Chan .set_eee = bnxt_set_eee, 343342ee18feSAjit Khaparde .get_module_info = bnxt_get_module_info, 343442ee18feSAjit Khaparde .get_module_eeprom = bnxt_get_module_eeprom, 34355ad2cbeeSMichael Chan .nway_reset = bnxt_nway_reset, 34365ad2cbeeSMichael Chan .set_phys_id = bnxt_set_phys_id, 3437eb513658SMichael Chan .self_test = bnxt_self_test, 343849f7972fSVasundhara Volam .reset = bnxt_reset, 34396c5657d0SVasundhara Volam .get_dump_flag = bnxt_get_dump_flag, 34406c5657d0SVasundhara Volam .get_dump_data = bnxt_get_dump_data, 3441c0c050c5SMichael Chan }; 3442