1c0c050c5SMichael Chan /* Broadcom NetXtreme-C/E network driver. 2c0c050c5SMichael Chan * 311f15ed3SMichael Chan * Copyright (c) 2014-2016 Broadcom Corporation 48e202366SMichael Chan * Copyright (c) 2016-2017 Broadcom Limited 5c0c050c5SMichael Chan * 6c0c050c5SMichael Chan * This program is free software; you can redistribute it and/or modify 7c0c050c5SMichael Chan * it under the terms of the GNU General Public License as published by 8c0c050c5SMichael Chan * the Free Software Foundation. 9c0c050c5SMichael Chan */ 10c0c050c5SMichael Chan 113ebf6f0aSRob Swindell #include <linux/ctype.h> 128ddc9aaaSMichael Chan #include <linux/stringify.h> 13c0c050c5SMichael Chan #include <linux/ethtool.h> 14c0c050c5SMichael Chan #include <linux/interrupt.h> 15c0c050c5SMichael Chan #include <linux/pci.h> 16c0c050c5SMichael Chan #include <linux/etherdevice.h> 17c0c050c5SMichael Chan #include <linux/crc32.h> 18c0c050c5SMichael Chan #include <linux/firmware.h> 196c5657d0SVasundhara Volam #include <linux/utsname.h> 206c5657d0SVasundhara Volam #include <linux/time.h> 21c0c050c5SMichael Chan #include "bnxt_hsi.h" 22c0c050c5SMichael Chan #include "bnxt.h" 23f7dc1ea6SMichael Chan #include "bnxt_xdp.h" 24c0c050c5SMichael Chan #include "bnxt_ethtool.h" 25c0c050c5SMichael Chan #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */ 26c0c050c5SMichael Chan #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */ 276c5657d0SVasundhara Volam #include "bnxt_coredump.h" 28c0c050c5SMichael Chan #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100) 295ac67d8bSRob Swindell #define FLASH_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200) 305ac67d8bSRob Swindell #define INSTALL_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200) 31c0c050c5SMichael Chan 32c0c050c5SMichael Chan static u32 bnxt_get_msglevel(struct net_device *dev) 33c0c050c5SMichael Chan { 34c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 35c0c050c5SMichael Chan 36c0c050c5SMichael Chan return bp->msg_enable; 37c0c050c5SMichael Chan } 38c0c050c5SMichael Chan 39c0c050c5SMichael Chan static void bnxt_set_msglevel(struct net_device *dev, u32 value) 40c0c050c5SMichael Chan { 41c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 42c0c050c5SMichael Chan 43c0c050c5SMichael Chan bp->msg_enable = value; 44c0c050c5SMichael Chan } 45c0c050c5SMichael Chan 46c0c050c5SMichael Chan static int bnxt_get_coalesce(struct net_device *dev, 47c0c050c5SMichael Chan struct ethtool_coalesce *coal) 48c0c050c5SMichael Chan { 49c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 5018775aa8SMichael Chan struct bnxt_coal *hw_coal; 5118775aa8SMichael Chan u16 mult; 52c0c050c5SMichael Chan 53c0c050c5SMichael Chan memset(coal, 0, sizeof(*coal)); 54c0c050c5SMichael Chan 556a8788f2SAndy Gospodarek coal->use_adaptive_rx_coalesce = bp->flags & BNXT_FLAG_DIM; 566a8788f2SAndy Gospodarek 5718775aa8SMichael Chan hw_coal = &bp->rx_coal; 5818775aa8SMichael Chan mult = hw_coal->bufs_per_record; 5918775aa8SMichael Chan coal->rx_coalesce_usecs = hw_coal->coal_ticks; 6018775aa8SMichael Chan coal->rx_max_coalesced_frames = hw_coal->coal_bufs / mult; 6118775aa8SMichael Chan coal->rx_coalesce_usecs_irq = hw_coal->coal_ticks_irq; 6218775aa8SMichael Chan coal->rx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult; 63c0c050c5SMichael Chan 6418775aa8SMichael Chan hw_coal = &bp->tx_coal; 6518775aa8SMichael Chan mult = hw_coal->bufs_per_record; 6618775aa8SMichael Chan coal->tx_coalesce_usecs = hw_coal->coal_ticks; 6718775aa8SMichael Chan coal->tx_max_coalesced_frames = hw_coal->coal_bufs / mult; 6818775aa8SMichael Chan coal->tx_coalesce_usecs_irq = hw_coal->coal_ticks_irq; 6918775aa8SMichael Chan coal->tx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult; 70dfc9c94aSMichael Chan 7151f30785SMichael Chan coal->stats_block_coalesce_usecs = bp->stats_coal_ticks; 7251f30785SMichael Chan 73c0c050c5SMichael Chan return 0; 74c0c050c5SMichael Chan } 75c0c050c5SMichael Chan 76c0c050c5SMichael Chan static int bnxt_set_coalesce(struct net_device *dev, 77c0c050c5SMichael Chan struct ethtool_coalesce *coal) 78c0c050c5SMichael Chan { 79c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 8051f30785SMichael Chan bool update_stats = false; 8118775aa8SMichael Chan struct bnxt_coal *hw_coal; 82c0c050c5SMichael Chan int rc = 0; 8318775aa8SMichael Chan u16 mult; 84c0c050c5SMichael Chan 856a8788f2SAndy Gospodarek if (coal->use_adaptive_rx_coalesce) { 866a8788f2SAndy Gospodarek bp->flags |= BNXT_FLAG_DIM; 876a8788f2SAndy Gospodarek } else { 886a8788f2SAndy Gospodarek if (bp->flags & BNXT_FLAG_DIM) { 896a8788f2SAndy Gospodarek bp->flags &= ~(BNXT_FLAG_DIM); 906a8788f2SAndy Gospodarek goto reset_coalesce; 916a8788f2SAndy Gospodarek } 926a8788f2SAndy Gospodarek } 936a8788f2SAndy Gospodarek 9418775aa8SMichael Chan hw_coal = &bp->rx_coal; 9518775aa8SMichael Chan mult = hw_coal->bufs_per_record; 9618775aa8SMichael Chan hw_coal->coal_ticks = coal->rx_coalesce_usecs; 9718775aa8SMichael Chan hw_coal->coal_bufs = coal->rx_max_coalesced_frames * mult; 9818775aa8SMichael Chan hw_coal->coal_ticks_irq = coal->rx_coalesce_usecs_irq; 9918775aa8SMichael Chan hw_coal->coal_bufs_irq = coal->rx_max_coalesced_frames_irq * mult; 100c0c050c5SMichael Chan 101de4a10efSAndy Gospodarek hw_coal = &bp->tx_coal; 10218775aa8SMichael Chan mult = hw_coal->bufs_per_record; 10318775aa8SMichael Chan hw_coal->coal_ticks = coal->tx_coalesce_usecs; 10418775aa8SMichael Chan hw_coal->coal_bufs = coal->tx_max_coalesced_frames * mult; 10518775aa8SMichael Chan hw_coal->coal_ticks_irq = coal->tx_coalesce_usecs_irq; 10618775aa8SMichael Chan hw_coal->coal_bufs_irq = coal->tx_max_coalesced_frames_irq * mult; 107dfc9c94aSMichael Chan 10851f30785SMichael Chan if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) { 10951f30785SMichael Chan u32 stats_ticks = coal->stats_block_coalesce_usecs; 11051f30785SMichael Chan 111adcc331eSMichael Chan /* Allow 0, which means disable. */ 112adcc331eSMichael Chan if (stats_ticks) 11351f30785SMichael Chan stats_ticks = clamp_t(u32, stats_ticks, 11451f30785SMichael Chan BNXT_MIN_STATS_COAL_TICKS, 11551f30785SMichael Chan BNXT_MAX_STATS_COAL_TICKS); 11651f30785SMichael Chan stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS); 11751f30785SMichael Chan bp->stats_coal_ticks = stats_ticks; 118e795892eSMichael Chan if (bp->stats_coal_ticks) 119e795892eSMichael Chan bp->current_interval = 120e795892eSMichael Chan bp->stats_coal_ticks * HZ / 1000000; 121e795892eSMichael Chan else 122e795892eSMichael Chan bp->current_interval = BNXT_TIMER_INTERVAL; 12351f30785SMichael Chan update_stats = true; 12451f30785SMichael Chan } 12551f30785SMichael Chan 1266a8788f2SAndy Gospodarek reset_coalesce: 12751f30785SMichael Chan if (netif_running(dev)) { 12851f30785SMichael Chan if (update_stats) { 12951f30785SMichael Chan rc = bnxt_close_nic(bp, true, false); 13051f30785SMichael Chan if (!rc) 13151f30785SMichael Chan rc = bnxt_open_nic(bp, true, false); 13251f30785SMichael Chan } else { 133c0c050c5SMichael Chan rc = bnxt_hwrm_set_coal(bp); 13451f30785SMichael Chan } 13551f30785SMichael Chan } 136c0c050c5SMichael Chan 137c0c050c5SMichael Chan return rc; 138c0c050c5SMichael Chan } 139c0c050c5SMichael Chan 1403316d509SMichael Chan static const char * const bnxt_ring_rx_stats_str[] = { 141ee79566eSMichael Chan "rx_ucast_packets", 142ee79566eSMichael Chan "rx_mcast_packets", 143ee79566eSMichael Chan "rx_bcast_packets", 144ee79566eSMichael Chan "rx_discards", 145bfc6e5fbSMichael Chan "rx_errors", 146ee79566eSMichael Chan "rx_ucast_bytes", 147ee79566eSMichael Chan "rx_mcast_bytes", 148ee79566eSMichael Chan "rx_bcast_bytes", 1493316d509SMichael Chan }; 1503316d509SMichael Chan 1513316d509SMichael Chan static const char * const bnxt_ring_tx_stats_str[] = { 152ee79566eSMichael Chan "tx_ucast_packets", 153ee79566eSMichael Chan "tx_mcast_packets", 154ee79566eSMichael Chan "tx_bcast_packets", 155bfc6e5fbSMichael Chan "tx_errors", 156ee79566eSMichael Chan "tx_discards", 157ee79566eSMichael Chan "tx_ucast_bytes", 158ee79566eSMichael Chan "tx_mcast_bytes", 159ee79566eSMichael Chan "tx_bcast_bytes", 160ee79566eSMichael Chan }; 161ee79566eSMichael Chan 162ee79566eSMichael Chan static const char * const bnxt_ring_tpa_stats_str[] = { 163ee79566eSMichael Chan "tpa_packets", 164ee79566eSMichael Chan "tpa_bytes", 165ee79566eSMichael Chan "tpa_events", 166ee79566eSMichael Chan "tpa_aborts", 167ee79566eSMichael Chan }; 168ee79566eSMichael Chan 16978e7b866SMichael Chan static const char * const bnxt_ring_tpa2_stats_str[] = { 17078e7b866SMichael Chan "rx_tpa_eligible_pkt", 17178e7b866SMichael Chan "rx_tpa_eligible_bytes", 17278e7b866SMichael Chan "rx_tpa_pkt", 17378e7b866SMichael Chan "rx_tpa_bytes", 17478e7b866SMichael Chan "rx_tpa_errors", 17578e7b866SMichael Chan }; 17678e7b866SMichael Chan 1779d8b5f05SMichael Chan static const char * const bnxt_rx_sw_stats_str[] = { 178ee79566eSMichael Chan "rx_l4_csum_errors", 17919b3751fSMichael Chan "rx_buf_errors", 1809d8b5f05SMichael Chan }; 1819d8b5f05SMichael Chan 1829d8b5f05SMichael Chan static const char * const bnxt_cmn_sw_stats_str[] = { 183ee79566eSMichael Chan "missed_irqs", 184ee79566eSMichael Chan }; 185c0c050c5SMichael Chan 1868ddc9aaaSMichael Chan #define BNXT_RX_STATS_ENTRY(counter) \ 1878ddc9aaaSMichael Chan { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) } 1888ddc9aaaSMichael Chan 1898ddc9aaaSMichael Chan #define BNXT_TX_STATS_ENTRY(counter) \ 1908ddc9aaaSMichael Chan { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) } 1918ddc9aaaSMichael Chan 19200db3cbaSVasundhara Volam #define BNXT_RX_STATS_EXT_ENTRY(counter) \ 19300db3cbaSVasundhara Volam { BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) } 19400db3cbaSVasundhara Volam 19536e53349SMichael Chan #define BNXT_TX_STATS_EXT_ENTRY(counter) \ 19636e53349SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter), __stringify(counter) } 19736e53349SMichael Chan 19836e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRY(n) \ 19936e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_duration_us), \ 20036e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_transitions) 20136e53349SMichael Chan 20236e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRY(n) \ 20336e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_duration_us), \ 20436e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_transitions) 20536e53349SMichael Chan 20636e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRIES \ 20736e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(0), \ 20836e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(1), \ 20936e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(2), \ 21036e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(3), \ 21136e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(4), \ 21236e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(5), \ 21336e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(6), \ 21436e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(7) 21536e53349SMichael Chan 21636e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRIES \ 21736e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(0), \ 21836e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(1), \ 21936e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(2), \ 22036e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(3), \ 22136e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(4), \ 22236e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(5), \ 22336e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(6), \ 22436e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(7) 22536e53349SMichael Chan 22636e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRY(n) \ 22736e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bytes_cos##n), \ 22836e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_packets_cos##n) 22936e53349SMichael Chan 23036e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRY(n) \ 23136e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_bytes_cos##n), \ 23236e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_packets_cos##n) 23336e53349SMichael Chan 23436e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRIES \ 23536e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(0), \ 23636e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(1), \ 23736e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(2), \ 23836e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(3), \ 23936e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(4), \ 24036e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(5), \ 24136e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(6), \ 24236e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(7) \ 24336e53349SMichael Chan 24436e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRIES \ 24536e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(0), \ 24636e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(1), \ 24736e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(2), \ 24836e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(3), \ 24936e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(4), \ 25036e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(5), \ 25136e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(6), \ 25236e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(7) \ 25336e53349SMichael Chan 2542792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(n) \ 2552792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_bytes_cos##n), \ 2562792b5b9SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_discard_packets_cos##n) 2572792b5b9SMichael Chan 2582792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES \ 2592792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(0), \ 2602792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(1), \ 2612792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(2), \ 2622792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(3), \ 2632792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(4), \ 2642792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(5), \ 2652792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(6), \ 2662792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(7) 2672792b5b9SMichael Chan 268e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRY(counter, n) \ 269e37fed79SMichael Chan { BNXT_RX_STATS_EXT_OFFSET(counter##_cos0), \ 270e37fed79SMichael Chan __stringify(counter##_pri##n) } 271e37fed79SMichael Chan 272e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRY(counter, n) \ 273e37fed79SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter##_cos0), \ 274e37fed79SMichael Chan __stringify(counter##_pri##n) } 275e37fed79SMichael Chan 276e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRIES(counter) \ 277e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 0), \ 278e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 1), \ 279e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 2), \ 280e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 3), \ 281e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 4), \ 282e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 5), \ 283e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 6), \ 284e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 7) 285e37fed79SMichael Chan 286e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRIES(counter) \ 287e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 0), \ 288e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 1), \ 289e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 2), \ 290e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 3), \ 291e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 4), \ 292e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 5), \ 293e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 6), \ 294e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 7) 295e37fed79SMichael Chan 29620c1d28eSVasundhara Volam enum { 29720c1d28eSVasundhara Volam RX_TOTAL_DISCARDS, 29820c1d28eSVasundhara Volam TX_TOTAL_DISCARDS, 29920c1d28eSVasundhara Volam }; 30020c1d28eSVasundhara Volam 30120c1d28eSVasundhara Volam static struct { 30220c1d28eSVasundhara Volam u64 counter; 30320c1d28eSVasundhara Volam char string[ETH_GSTRING_LEN]; 30420c1d28eSVasundhara Volam } bnxt_sw_func_stats[] = { 30520c1d28eSVasundhara Volam {0, "rx_total_discard_pkts"}, 30620c1d28eSVasundhara Volam {0, "tx_total_discard_pkts"}, 30720c1d28eSVasundhara Volam }; 30820c1d28eSVasundhara Volam 3093316d509SMichael Chan #define NUM_RING_RX_SW_STATS ARRAY_SIZE(bnxt_rx_sw_stats_str) 3103316d509SMichael Chan #define NUM_RING_CMN_SW_STATS ARRAY_SIZE(bnxt_cmn_sw_stats_str) 3113316d509SMichael Chan #define NUM_RING_RX_HW_STATS ARRAY_SIZE(bnxt_ring_rx_stats_str) 3123316d509SMichael Chan #define NUM_RING_TX_HW_STATS ARRAY_SIZE(bnxt_ring_tx_stats_str) 3133316d509SMichael Chan 3148ddc9aaaSMichael Chan static const struct { 3158ddc9aaaSMichael Chan long offset; 3168ddc9aaaSMichael Chan char string[ETH_GSTRING_LEN]; 3178ddc9aaaSMichael Chan } bnxt_port_stats_arr[] = { 3188ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_64b_frames), 3198ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_65b_127b_frames), 3208ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_128b_255b_frames), 3218ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_256b_511b_frames), 3228ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames), 3236fc92c33SMichael Chan BNXT_RX_STATS_ENTRY(rx_1024b_1518b_frames), 3248ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_vlan_frames), 3258ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames), 3268ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames), 3278ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames), 3288ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames), 3298ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_total_frames), 3308ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ucast_frames), 3318ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mcast_frames), 3328ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bcast_frames), 3338ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_fcs_err_frames), 3348ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ctrl_frames), 3358ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pause_frames), 3368ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_frames), 3378ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_align_err_frames), 3388ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ovrsz_frames), 3398ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_jbr_frames), 3408ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mtu_err_frames), 3418ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_tagged_frames), 3428ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_double_tagged_frames), 3438ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_frames), 344c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0), 345c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1), 346c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2), 347c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3), 348c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4), 349c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5), 350c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6), 351c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7), 3528ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_undrsz_frames), 3538ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_events), 3548ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration), 3558ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bytes), 3568ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_bytes), 3578ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_frames), 358699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_discard), 359699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_err), 3608ddc9aaaSMichael Chan 3618ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_64b_frames), 3628ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_65b_127b_frames), 3638ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_128b_255b_frames), 3648ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_256b_511b_frames), 3658ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames), 3666fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1024b_1518b_frames), 3678ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_vlan_frames), 3686fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1519b_2047b_frames), 3698ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames), 3708ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames), 3718ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames), 3728ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_frames), 3738ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_frames), 3748ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_ucast_frames), 3758ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_mcast_frames), 3768ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bcast_frames), 3778ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pause_frames), 3788ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_frames), 3798ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_jabber_frames), 3808ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fcs_err_frames), 3818ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_err), 3828ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fifo_underruns), 383c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0), 384c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1), 385c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2), 386c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3), 387c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4), 388c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5), 389c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6), 390c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7), 3918ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_events), 3928ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration), 3938ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_collisions), 3948ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bytes), 395699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_xthol_frames), 396699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_discard), 397699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_error), 3988ddc9aaaSMichael Chan }; 3998ddc9aaaSMichael Chan 40000db3cbaSVasundhara Volam static const struct { 40100db3cbaSVasundhara Volam long offset; 40200db3cbaSVasundhara Volam char string[ETH_GSTRING_LEN]; 40300db3cbaSVasundhara Volam } bnxt_port_stats_ext_arr[] = { 40400db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(link_down_events), 40500db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events), 40600db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_pause_events), 40700db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events), 40800db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events), 40936e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRIES, 41036e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRIES, 4114a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bits), 4124a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_buffer_passed_threshold), 4134a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_pcs_symbol_err), 4144a50ddc2SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_corrected_bits), 4152792b5b9SMichael Chan BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES, 41636e53349SMichael Chan }; 41736e53349SMichael Chan 41836e53349SMichael Chan static const struct { 41936e53349SMichael Chan long offset; 42036e53349SMichael Chan char string[ETH_GSTRING_LEN]; 42136e53349SMichael Chan } bnxt_tx_port_stats_ext_arr[] = { 42236e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRIES, 42336e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRIES, 42400db3cbaSVasundhara Volam }; 42500db3cbaSVasundhara Volam 426e37fed79SMichael Chan static const struct { 427e37fed79SMichael Chan long base_off; 428e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 429e37fed79SMichael Chan } bnxt_rx_bytes_pri_arr[] = { 430e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_bytes), 431e37fed79SMichael Chan }; 432e37fed79SMichael Chan 433e37fed79SMichael Chan static const struct { 434e37fed79SMichael Chan long base_off; 435e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 436e37fed79SMichael Chan } bnxt_rx_pkts_pri_arr[] = { 437e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_packets), 438e37fed79SMichael Chan }; 439e37fed79SMichael Chan 440e37fed79SMichael Chan static const struct { 441e37fed79SMichael Chan long base_off; 442e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 443e37fed79SMichael Chan } bnxt_tx_bytes_pri_arr[] = { 444e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_bytes), 445e37fed79SMichael Chan }; 446e37fed79SMichael Chan 447e37fed79SMichael Chan static const struct { 448e37fed79SMichael Chan long base_off; 449e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 450e37fed79SMichael Chan } bnxt_tx_pkts_pri_arr[] = { 451e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_packets), 452e37fed79SMichael Chan }; 453e37fed79SMichael Chan 45420c1d28eSVasundhara Volam #define BNXT_NUM_SW_FUNC_STATS ARRAY_SIZE(bnxt_sw_func_stats) 4558ddc9aaaSMichael Chan #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr) 456e37fed79SMichael Chan #define BNXT_NUM_STATS_PRI \ 457e37fed79SMichael Chan (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \ 458e37fed79SMichael Chan ARRAY_SIZE(bnxt_rx_pkts_pri_arr) + \ 459e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_bytes_pri_arr) + \ 460e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_pkts_pri_arr)) 4618ddc9aaaSMichael Chan 46278e7b866SMichael Chan static int bnxt_get_num_tpa_ring_stats(struct bnxt *bp) 46378e7b866SMichael Chan { 46478e7b866SMichael Chan if (BNXT_SUPPORTS_TPA(bp)) { 46578e7b866SMichael Chan if (bp->max_tpa_v2) 46678e7b866SMichael Chan return ARRAY_SIZE(bnxt_ring_tpa2_stats_str); 46778e7b866SMichael Chan return ARRAY_SIZE(bnxt_ring_tpa_stats_str); 46878e7b866SMichael Chan } 46978e7b866SMichael Chan return 0; 47078e7b866SMichael Chan } 47178e7b866SMichael Chan 472ee79566eSMichael Chan static int bnxt_get_num_ring_stats(struct bnxt *bp) 473ee79566eSMichael Chan { 4743316d509SMichael Chan int rx, tx, cmn; 475125592fbSRajesh Ravi bool sh = false; 476125592fbSRajesh Ravi 477125592fbSRajesh Ravi if (bp->flags & BNXT_FLAG_SHARED_RINGS) 478125592fbSRajesh Ravi sh = true; 479ee79566eSMichael Chan 4803316d509SMichael Chan rx = NUM_RING_RX_HW_STATS + NUM_RING_RX_SW_STATS + 48178e7b866SMichael Chan bnxt_get_num_tpa_ring_stats(bp); 4823316d509SMichael Chan tx = NUM_RING_TX_HW_STATS; 4833316d509SMichael Chan cmn = NUM_RING_CMN_SW_STATS; 484125592fbSRajesh Ravi if (sh) 4853316d509SMichael Chan return (rx + tx + cmn) * bp->cp_nr_rings; 486125592fbSRajesh Ravi else 487125592fbSRajesh Ravi return rx * bp->rx_nr_rings + tx * bp->tx_nr_rings + 488125592fbSRajesh Ravi cmn * bp->cp_nr_rings; 489ee79566eSMichael Chan } 490ee79566eSMichael Chan 4915c8227d0SMichael Chan static int bnxt_get_num_stats(struct bnxt *bp) 492c0c050c5SMichael Chan { 493ee79566eSMichael Chan int num_stats = bnxt_get_num_ring_stats(bp); 4948ddc9aaaSMichael Chan 49520c1d28eSVasundhara Volam num_stats += BNXT_NUM_SW_FUNC_STATS; 49620c1d28eSVasundhara Volam 4978ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) 4988ddc9aaaSMichael Chan num_stats += BNXT_NUM_PORT_STATS; 4998ddc9aaaSMichael Chan 500e37fed79SMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 50136e53349SMichael Chan num_stats += bp->fw_rx_stats_ext_size + 50236e53349SMichael Chan bp->fw_tx_stats_ext_size; 503e37fed79SMichael Chan if (bp->pri2cos_valid) 504e37fed79SMichael Chan num_stats += BNXT_NUM_STATS_PRI; 505e37fed79SMichael Chan } 50600db3cbaSVasundhara Volam 5078ddc9aaaSMichael Chan return num_stats; 5088ddc9aaaSMichael Chan } 5095c8227d0SMichael Chan 5105c8227d0SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 5115c8227d0SMichael Chan { 5125c8227d0SMichael Chan struct bnxt *bp = netdev_priv(dev); 5135c8227d0SMichael Chan 5145c8227d0SMichael Chan switch (sset) { 5155c8227d0SMichael Chan case ETH_SS_STATS: 5165c8227d0SMichael Chan return bnxt_get_num_stats(bp); 517eb513658SMichael Chan case ETH_SS_TEST: 518eb513658SMichael Chan if (!bp->num_tests) 519eb513658SMichael Chan return -EOPNOTSUPP; 520eb513658SMichael Chan return bp->num_tests; 521c0c050c5SMichael Chan default: 522c0c050c5SMichael Chan return -EOPNOTSUPP; 523c0c050c5SMichael Chan } 524c0c050c5SMichael Chan } 525c0c050c5SMichael Chan 526125592fbSRajesh Ravi static bool is_rx_ring(struct bnxt *bp, int ring_num) 527125592fbSRajesh Ravi { 528125592fbSRajesh Ravi return ring_num < bp->rx_nr_rings; 529125592fbSRajesh Ravi } 530125592fbSRajesh Ravi 531125592fbSRajesh Ravi static bool is_tx_ring(struct bnxt *bp, int ring_num) 532125592fbSRajesh Ravi { 533125592fbSRajesh Ravi int tx_base = 0; 534125592fbSRajesh Ravi 535125592fbSRajesh Ravi if (!(bp->flags & BNXT_FLAG_SHARED_RINGS)) 536125592fbSRajesh Ravi tx_base = bp->rx_nr_rings; 537125592fbSRajesh Ravi 538125592fbSRajesh Ravi if (ring_num >= tx_base && ring_num < (tx_base + bp->tx_nr_rings)) 539125592fbSRajesh Ravi return true; 540125592fbSRajesh Ravi return false; 541125592fbSRajesh Ravi } 542125592fbSRajesh Ravi 543c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 544c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 545c0c050c5SMichael Chan { 546c0c050c5SMichael Chan u32 i, j = 0; 547c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 548125592fbSRajesh Ravi u32 tpa_stats; 549c0c050c5SMichael Chan 550fd3ab1c7SMichael Chan if (!bp->bnapi) { 551ee79566eSMichael Chan j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS; 552fd3ab1c7SMichael Chan goto skip_ring_stats; 553fd3ab1c7SMichael Chan } 554c0c050c5SMichael Chan 55520c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) 55620c1d28eSVasundhara Volam bnxt_sw_func_stats[i].counter = 0; 55720c1d28eSVasundhara Volam 558125592fbSRajesh Ravi tpa_stats = bnxt_get_num_tpa_ring_stats(bp); 559c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 560c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 561c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 562a0c30621SMichael Chan u64 *sw_stats = cpr->stats.sw_stats; 5639d8b5f05SMichael Chan u64 *sw; 564c0c050c5SMichael Chan int k; 565c0c050c5SMichael Chan 566125592fbSRajesh Ravi if (is_rx_ring(bp, i)) { 567125592fbSRajesh Ravi for (k = 0; k < NUM_RING_RX_HW_STATS; j++, k++) 568a0c30621SMichael Chan buf[j] = sw_stats[k]; 569125592fbSRajesh Ravi } 570125592fbSRajesh Ravi if (is_tx_ring(bp, i)) { 571125592fbSRajesh Ravi k = NUM_RING_RX_HW_STATS; 572125592fbSRajesh Ravi for (; k < NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS; 573125592fbSRajesh Ravi j++, k++) 574a0c30621SMichael Chan buf[j] = sw_stats[k]; 575125592fbSRajesh Ravi } 576125592fbSRajesh Ravi if (!tpa_stats || !is_rx_ring(bp, i)) 577125592fbSRajesh Ravi goto skip_tpa_ring_stats; 578125592fbSRajesh Ravi 579125592fbSRajesh Ravi k = NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS; 580125592fbSRajesh Ravi for (; k < NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS + 581125592fbSRajesh Ravi tpa_stats; j++, k++) 582a0c30621SMichael Chan buf[j] = sw_stats[k]; 5839d8b5f05SMichael Chan 584125592fbSRajesh Ravi skip_tpa_ring_stats: 5859d8b5f05SMichael Chan sw = (u64 *)&cpr->sw_stats.rx; 586125592fbSRajesh Ravi if (is_rx_ring(bp, i)) { 5873316d509SMichael Chan for (k = 0; k < NUM_RING_RX_SW_STATS; j++, k++) 5889d8b5f05SMichael Chan buf[j] = sw[k]; 589125592fbSRajesh Ravi } 5909d8b5f05SMichael Chan 5919d8b5f05SMichael Chan sw = (u64 *)&cpr->sw_stats.cmn; 5923316d509SMichael Chan for (k = 0; k < NUM_RING_CMN_SW_STATS; j++, k++) 5939d8b5f05SMichael Chan buf[j] = sw[k]; 59420c1d28eSVasundhara Volam 59520c1d28eSVasundhara Volam bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter += 596a0c30621SMichael Chan BNXT_GET_RING_STATS64(sw_stats, rx_discard_pkts); 59720c1d28eSVasundhara Volam bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter += 598a0c30621SMichael Chan BNXT_GET_RING_STATS64(sw_stats, tx_discard_pkts); 599c0c050c5SMichael Chan } 60020c1d28eSVasundhara Volam 60120c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++) 60220c1d28eSVasundhara Volam buf[j] = bnxt_sw_func_stats[i].counter; 60320c1d28eSVasundhara Volam 604fd3ab1c7SMichael Chan skip_ring_stats: 6058ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 606a0c30621SMichael Chan u64 *port_stats = bp->port_stats.sw_stats; 6078ddc9aaaSMichael Chan 608a0c30621SMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) 609a0c30621SMichael Chan buf[j] = *(port_stats + bnxt_port_stats_arr[i].offset); 6108ddc9aaaSMichael Chan } 61100db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 612a0c30621SMichael Chan u64 *rx_port_stats_ext = bp->rx_port_stats_ext.sw_stats; 613a0c30621SMichael Chan u64 *tx_port_stats_ext = bp->tx_port_stats_ext.sw_stats; 61400db3cbaSVasundhara Volam 61536e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) { 616a0c30621SMichael Chan buf[j] = *(rx_port_stats_ext + 617a0c30621SMichael Chan bnxt_port_stats_ext_arr[i].offset); 61800db3cbaSVasundhara Volam } 61936e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++, j++) { 620a0c30621SMichael Chan buf[j] = *(tx_port_stats_ext + 621a0c30621SMichael Chan bnxt_tx_port_stats_ext_arr[i].offset); 62236e53349SMichael Chan } 623e37fed79SMichael Chan if (bp->pri2cos_valid) { 624e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 625e37fed79SMichael Chan long n = bnxt_rx_bytes_pri_arr[i].base_off + 626a24ec322SMichael Chan bp->pri2cos_idx[i]; 627e37fed79SMichael Chan 628a0c30621SMichael Chan buf[j] = *(rx_port_stats_ext + n); 629e37fed79SMichael Chan } 630e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 631e37fed79SMichael Chan long n = bnxt_rx_pkts_pri_arr[i].base_off + 632a24ec322SMichael Chan bp->pri2cos_idx[i]; 633e37fed79SMichael Chan 634a0c30621SMichael Chan buf[j] = *(rx_port_stats_ext + n); 635e37fed79SMichael Chan } 636e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 637e37fed79SMichael Chan long n = bnxt_tx_bytes_pri_arr[i].base_off + 638a24ec322SMichael Chan bp->pri2cos_idx[i]; 639e37fed79SMichael Chan 640a0c30621SMichael Chan buf[j] = *(tx_port_stats_ext + n); 641e37fed79SMichael Chan } 642e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 643e37fed79SMichael Chan long n = bnxt_tx_pkts_pri_arr[i].base_off + 644a24ec322SMichael Chan bp->pri2cos_idx[i]; 645e37fed79SMichael Chan 646a0c30621SMichael Chan buf[j] = *(tx_port_stats_ext + n); 647e37fed79SMichael Chan } 648e37fed79SMichael Chan } 64900db3cbaSVasundhara Volam } 650c0c050c5SMichael Chan } 651c0c050c5SMichael Chan 652c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 653c0c050c5SMichael Chan { 654c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 65578e7b866SMichael Chan static const char * const *str; 656ee79566eSMichael Chan u32 i, j, num_str; 657c0c050c5SMichael Chan 658c0c050c5SMichael Chan switch (stringset) { 659c0c050c5SMichael Chan case ETH_SS_STATS: 660c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 661125592fbSRajesh Ravi if (is_rx_ring(bp, i)) { 6623316d509SMichael Chan num_str = NUM_RING_RX_HW_STATS; 663ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 664ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 6653316d509SMichael Chan bnxt_ring_rx_stats_str[j]); 666c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 667ee79566eSMichael Chan } 668125592fbSRajesh Ravi } 669125592fbSRajesh Ravi if (is_tx_ring(bp, i)) { 6703316d509SMichael Chan num_str = NUM_RING_TX_HW_STATS; 6713316d509SMichael Chan for (j = 0; j < num_str; j++) { 6723316d509SMichael Chan sprintf(buf, "[%d]: %s", i, 6733316d509SMichael Chan bnxt_ring_tx_stats_str[j]); 6743316d509SMichael Chan buf += ETH_GSTRING_LEN; 6753316d509SMichael Chan } 676125592fbSRajesh Ravi } 6773316d509SMichael Chan num_str = bnxt_get_num_tpa_ring_stats(bp); 678125592fbSRajesh Ravi if (!num_str || !is_rx_ring(bp, i)) 679ee79566eSMichael Chan goto skip_tpa_stats; 680ee79566eSMichael Chan 6813316d509SMichael Chan if (bp->max_tpa_v2) 68278e7b866SMichael Chan str = bnxt_ring_tpa2_stats_str; 6833316d509SMichael Chan else 68478e7b866SMichael Chan str = bnxt_ring_tpa_stats_str; 6853316d509SMichael Chan 686ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 68778e7b866SMichael Chan sprintf(buf, "[%d]: %s", i, str[j]); 688c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 689ee79566eSMichael Chan } 690ee79566eSMichael Chan skip_tpa_stats: 691125592fbSRajesh Ravi if (is_rx_ring(bp, i)) { 6923316d509SMichael Chan num_str = NUM_RING_RX_SW_STATS; 693ee79566eSMichael Chan for (j = 0; j < num_str; j++) { 694ee79566eSMichael Chan sprintf(buf, "[%d]: %s", i, 6959d8b5f05SMichael Chan bnxt_rx_sw_stats_str[j]); 6969d8b5f05SMichael Chan buf += ETH_GSTRING_LEN; 6979d8b5f05SMichael Chan } 698125592fbSRajesh Ravi } 6993316d509SMichael Chan num_str = NUM_RING_CMN_SW_STATS; 7009d8b5f05SMichael Chan for (j = 0; j < num_str; j++) { 7019d8b5f05SMichael Chan sprintf(buf, "[%d]: %s", i, 7029d8b5f05SMichael Chan bnxt_cmn_sw_stats_str[j]); 703c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 704ee79566eSMichael Chan } 705c0c050c5SMichael Chan } 70620c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) { 70720c1d28eSVasundhara Volam strcpy(buf, bnxt_sw_func_stats[i].string); 70820c1d28eSVasundhara Volam buf += ETH_GSTRING_LEN; 70920c1d28eSVasundhara Volam } 71020c1d28eSVasundhara Volam 7118ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 7128ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++) { 7138ddc9aaaSMichael Chan strcpy(buf, bnxt_port_stats_arr[i].string); 7148ddc9aaaSMichael Chan buf += ETH_GSTRING_LEN; 7158ddc9aaaSMichael Chan } 7168ddc9aaaSMichael Chan } 71700db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 71836e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++) { 71900db3cbaSVasundhara Volam strcpy(buf, bnxt_port_stats_ext_arr[i].string); 72000db3cbaSVasundhara Volam buf += ETH_GSTRING_LEN; 72100db3cbaSVasundhara Volam } 72236e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++) { 72336e53349SMichael Chan strcpy(buf, 72436e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].string); 72536e53349SMichael Chan buf += ETH_GSTRING_LEN; 72636e53349SMichael Chan } 727e37fed79SMichael Chan if (bp->pri2cos_valid) { 728e37fed79SMichael Chan for (i = 0; i < 8; i++) { 729e37fed79SMichael Chan strcpy(buf, 730e37fed79SMichael Chan bnxt_rx_bytes_pri_arr[i].string); 731e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 732e37fed79SMichael Chan } 733e37fed79SMichael Chan for (i = 0; i < 8; i++) { 734e37fed79SMichael Chan strcpy(buf, 735e37fed79SMichael Chan bnxt_rx_pkts_pri_arr[i].string); 736e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 737e37fed79SMichael Chan } 738e37fed79SMichael Chan for (i = 0; i < 8; i++) { 739e37fed79SMichael Chan strcpy(buf, 740e37fed79SMichael Chan bnxt_tx_bytes_pri_arr[i].string); 741e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 742e37fed79SMichael Chan } 743e37fed79SMichael Chan for (i = 0; i < 8; i++) { 744e37fed79SMichael Chan strcpy(buf, 745e37fed79SMichael Chan bnxt_tx_pkts_pri_arr[i].string); 746e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 747e37fed79SMichael Chan } 748e37fed79SMichael Chan } 74900db3cbaSVasundhara Volam } 750c0c050c5SMichael Chan break; 751eb513658SMichael Chan case ETH_SS_TEST: 752eb513658SMichael Chan if (bp->num_tests) 753eb513658SMichael Chan memcpy(buf, bp->test_info->string, 754eb513658SMichael Chan bp->num_tests * ETH_GSTRING_LEN); 755eb513658SMichael Chan break; 756c0c050c5SMichael Chan default: 757c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 758c0c050c5SMichael Chan stringset); 759c0c050c5SMichael Chan break; 760c0c050c5SMichael Chan } 761c0c050c5SMichael Chan } 762c0c050c5SMichael Chan 763c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 764c0c050c5SMichael Chan struct ethtool_ringparam *ering) 765c0c050c5SMichael Chan { 766c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 767c0c050c5SMichael Chan 768c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 769c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 770c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 771c0c050c5SMichael Chan 772c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 773c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 774c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 775c0c050c5SMichael Chan } 776c0c050c5SMichael Chan 777c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 778c0c050c5SMichael Chan struct ethtool_ringparam *ering) 779c0c050c5SMichael Chan { 780c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 781c0c050c5SMichael Chan 782c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 783c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 784c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 785c0c050c5SMichael Chan return -EINVAL; 786c0c050c5SMichael Chan 787c0c050c5SMichael Chan if (netif_running(dev)) 788c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 789c0c050c5SMichael Chan 790c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 791c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 792c0c050c5SMichael Chan bnxt_set_ring_params(bp); 793c0c050c5SMichael Chan 794c0c050c5SMichael Chan if (netif_running(dev)) 795c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 796c0c050c5SMichael Chan 797c0c050c5SMichael Chan return 0; 798c0c050c5SMichael Chan } 799c0c050c5SMichael Chan 800c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 801c0c050c5SMichael Chan struct ethtool_channels *channel) 802c0c050c5SMichael Chan { 803c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 804db4723b3SMichael Chan struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 805c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 806db4723b3SMichael Chan int max_tx_sch_inputs; 807db4723b3SMichael Chan 808db4723b3SMichael Chan /* Get the most up-to-date max_tx_sch_inputs. */ 809f1ca94deSMichael Chan if (BNXT_NEW_RM(bp)) 810db4723b3SMichael Chan bnxt_hwrm_func_resc_qcaps(bp, false); 811db4723b3SMichael Chan max_tx_sch_inputs = hw_resc->max_tx_sch_inputs; 812c0c050c5SMichael Chan 8136e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 814db4723b3SMichael Chan if (max_tx_sch_inputs) 815db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 816a79a5276SMichael Chan channel->max_combined = min_t(int, max_rx_rings, max_tx_rings); 817068c9ec6SMichael Chan 81818d6e4e2SSatish Baddipadige if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) { 81918d6e4e2SSatish Baddipadige max_rx_rings = 0; 82018d6e4e2SSatish Baddipadige max_tx_rings = 0; 82118d6e4e2SSatish Baddipadige } 822db4723b3SMichael Chan if (max_tx_sch_inputs) 823db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 82418d6e4e2SSatish Baddipadige 825c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 826c0c050c5SMichael Chan if (tcs > 1) 827c0c050c5SMichael Chan max_tx_rings /= tcs; 828c0c050c5SMichael Chan 829c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 830c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 831c0c050c5SMichael Chan channel->max_other = 0; 832068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 833068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 83476595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp)) 83576595193SPrashant Sreedharan channel->combined_count--; 836068c9ec6SMichael Chan } else { 83776595193SPrashant Sreedharan if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) { 838c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 839c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 840c0c050c5SMichael Chan } 841068c9ec6SMichael Chan } 84276595193SPrashant Sreedharan } 843c0c050c5SMichael Chan 844c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 845c0c050c5SMichael Chan struct ethtool_channels *channel) 846c0c050c5SMichael Chan { 847c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 848d1e7925eSMichael Chan int req_tx_rings, req_rx_rings, tcs; 849068c9ec6SMichael Chan bool sh = false; 8505f449249SMichael Chan int tx_xdp = 0; 851d1e7925eSMichael Chan int rc = 0; 852c0c050c5SMichael Chan 853068c9ec6SMichael Chan if (channel->other_count) 854c0c050c5SMichael Chan return -EINVAL; 855c0c050c5SMichael Chan 856068c9ec6SMichael Chan if (!channel->combined_count && 857068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 858068c9ec6SMichael Chan return -EINVAL; 859068c9ec6SMichael Chan 860068c9ec6SMichael Chan if (channel->combined_count && 861068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 862068c9ec6SMichael Chan return -EINVAL; 863068c9ec6SMichael Chan 86476595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count || 86576595193SPrashant Sreedharan channel->tx_count)) 86676595193SPrashant Sreedharan return -EINVAL; 86776595193SPrashant Sreedharan 868068c9ec6SMichael Chan if (channel->combined_count) 869068c9ec6SMichael Chan sh = true; 870068c9ec6SMichael Chan 871c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 872c0c050c5SMichael Chan 873391be5c2SMichael Chan req_tx_rings = sh ? channel->combined_count : channel->tx_count; 874d1e7925eSMichael Chan req_rx_rings = sh ? channel->combined_count : channel->rx_count; 8755f449249SMichael Chan if (bp->tx_nr_rings_xdp) { 8765f449249SMichael Chan if (!sh) { 8775f449249SMichael Chan netdev_err(dev, "Only combined mode supported when XDP is enabled.\n"); 8785f449249SMichael Chan return -EINVAL; 8795f449249SMichael Chan } 8805f449249SMichael Chan tx_xdp = req_rx_rings; 8815f449249SMichael Chan } 88298fdbe73SMichael Chan rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp); 883d1e7925eSMichael Chan if (rc) { 884d1e7925eSMichael Chan netdev_warn(dev, "Unable to allocate the requested rings\n"); 885d1e7925eSMichael Chan return rc; 886391be5c2SMichael Chan } 887391be5c2SMichael Chan 888bd3191b5SMichael Chan if (bnxt_get_nr_rss_ctxs(bp, req_rx_rings) != 889bd3191b5SMichael Chan bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings) && 890bd3191b5SMichael Chan (dev->priv_flags & IFF_RXFH_CONFIGURED)) { 891bd3191b5SMichael Chan netdev_warn(dev, "RSS table size change required, RSS table entries must be default to proceed\n"); 892bd3191b5SMichael Chan return -EINVAL; 893bd3191b5SMichael Chan } 894bd3191b5SMichael Chan 895c0c050c5SMichael Chan if (netif_running(dev)) { 896c0c050c5SMichael Chan if (BNXT_PF(bp)) { 897c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 898c0c050c5SMichael Chan * before PF unload 899c0c050c5SMichael Chan */ 900c0c050c5SMichael Chan } 901c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 902c0c050c5SMichael Chan if (rc) { 903c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 904c0c050c5SMichael Chan rc); 905c0c050c5SMichael Chan return rc; 906c0c050c5SMichael Chan } 907c0c050c5SMichael Chan } 908c0c050c5SMichael Chan 909068c9ec6SMichael Chan if (sh) { 910068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 911d1e7925eSMichael Chan bp->rx_nr_rings = channel->combined_count; 912d1e7925eSMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 913068c9ec6SMichael Chan } else { 914068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 915c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 916c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 917068c9ec6SMichael Chan } 9185f449249SMichael Chan bp->tx_nr_rings_xdp = tx_xdp; 9195f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp; 920c0c050c5SMichael Chan if (tcs > 1) 9215f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp; 922068c9ec6SMichael Chan 923068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 924068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 925068c9ec6SMichael Chan 9262bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 9272bcfa6f6SMichael Chan netdev_update_features(dev); 928c0c050c5SMichael Chan if (netif_running(dev)) { 929c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 930c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 931c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 932c0c050c5SMichael Chan * to renable 933c0c050c5SMichael Chan */ 934c0c050c5SMichael Chan } 935d8c09f19SMichael Chan } else { 9361b3f0b75SMichael Chan rc = bnxt_reserve_rings(bp, true); 937c0c050c5SMichael Chan } 938c0c050c5SMichael Chan 939c0c050c5SMichael Chan return rc; 940c0c050c5SMichael Chan } 941c0c050c5SMichael Chan 942c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 943c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 944c0c050c5SMichael Chan u32 *rule_locs) 945c0c050c5SMichael Chan { 946c0c050c5SMichael Chan int i, j = 0; 947c0c050c5SMichael Chan 948c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 949c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 950c0c050c5SMichael Chan struct hlist_head *head; 951c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 952c0c050c5SMichael Chan 953c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 954c0c050c5SMichael Chan rcu_read_lock(); 955c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 956c0c050c5SMichael Chan if (j == cmd->rule_cnt) 957c0c050c5SMichael Chan break; 958c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 959c0c050c5SMichael Chan } 960c0c050c5SMichael Chan rcu_read_unlock(); 961c0c050c5SMichael Chan if (j == cmd->rule_cnt) 962c0c050c5SMichael Chan break; 963c0c050c5SMichael Chan } 964c0c050c5SMichael Chan cmd->rule_cnt = j; 965c0c050c5SMichael Chan return 0; 966c0c050c5SMichael Chan } 967c0c050c5SMichael Chan 968c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 969c0c050c5SMichael Chan { 970c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 971c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 972c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 973c0c050c5SMichael Chan struct flow_keys *fkeys; 974c0c050c5SMichael Chan int i, rc = -EINVAL; 975c0c050c5SMichael Chan 976b721cfafSstephen hemminger if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 977c0c050c5SMichael Chan return rc; 978c0c050c5SMichael Chan 979c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 980c0c050c5SMichael Chan struct hlist_head *head; 981c0c050c5SMichael Chan 982c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 983c0c050c5SMichael Chan rcu_read_lock(); 984c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 985c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 986c0c050c5SMichael Chan goto fltr_found; 987c0c050c5SMichael Chan } 988c0c050c5SMichael Chan rcu_read_unlock(); 989c0c050c5SMichael Chan } 990c0c050c5SMichael Chan return rc; 991c0c050c5SMichael Chan 992c0c050c5SMichael Chan fltr_found: 993c0c050c5SMichael Chan fkeys = &fltr->fkeys; 994dda0e746SMichael Chan if (fkeys->basic.n_proto == htons(ETH_P_IP)) { 995c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 996c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 997c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 998c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 999c0c050c5SMichael Chan else 1000c0c050c5SMichael Chan goto fltr_err; 1001c0c050c5SMichael Chan 1002c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 1003c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 1004c0c050c5SMichael Chan 1005c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 1006c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 1007c0c050c5SMichael Chan 1008c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 1009c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 1010c0c050c5SMichael Chan 1011c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 1012c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 1013dda0e746SMichael Chan } else { 1014dda0e746SMichael Chan int i; 1015dda0e746SMichael Chan 1016dda0e746SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 1017dda0e746SMichael Chan fs->flow_type = TCP_V6_FLOW; 1018dda0e746SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 1019dda0e746SMichael Chan fs->flow_type = UDP_V6_FLOW; 1020dda0e746SMichael Chan else 1021dda0e746SMichael Chan goto fltr_err; 1022dda0e746SMichael Chan 1023dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] = 1024dda0e746SMichael Chan fkeys->addrs.v6addrs.src; 1025dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] = 1026dda0e746SMichael Chan fkeys->addrs.v6addrs.dst; 1027dda0e746SMichael Chan for (i = 0; i < 4; i++) { 1028dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0); 1029dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0); 1030dda0e746SMichael Chan } 1031dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src; 1032dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0); 1033dda0e746SMichael Chan 1034dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst; 1035dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0); 1036dda0e746SMichael Chan } 1037c0c050c5SMichael Chan 1038c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 1039c0c050c5SMichael Chan rc = 0; 1040c0c050c5SMichael Chan 1041c0c050c5SMichael Chan fltr_err: 1042c0c050c5SMichael Chan rcu_read_unlock(); 1043c0c050c5SMichael Chan 1044c0c050c5SMichael Chan return rc; 1045c0c050c5SMichael Chan } 1046a011952aSMichael Chan #endif 1047a011952aSMichael Chan 1048a011952aSMichael Chan static u64 get_ethtool_ipv4_rss(struct bnxt *bp) 1049a011952aSMichael Chan { 1050a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4) 1051a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 1052a011952aSMichael Chan return 0; 1053a011952aSMichael Chan } 1054a011952aSMichael Chan 1055a011952aSMichael Chan static u64 get_ethtool_ipv6_rss(struct bnxt *bp) 1056a011952aSMichael Chan { 1057a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6) 1058a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 1059a011952aSMichael Chan return 0; 1060a011952aSMichael Chan } 1061a011952aSMichael Chan 1062a011952aSMichael Chan static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1063a011952aSMichael Chan { 1064a011952aSMichael Chan cmd->data = 0; 1065a011952aSMichael Chan switch (cmd->flow_type) { 1066a011952aSMichael Chan case TCP_V4_FLOW: 1067a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) 1068a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1069a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1070a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1071a011952aSMichael Chan break; 1072a011952aSMichael Chan case UDP_V4_FLOW: 1073a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4) 1074a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1075a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1076a011952aSMichael Chan /* fall through */ 1077a011952aSMichael Chan case SCTP_V4_FLOW: 1078a011952aSMichael Chan case AH_ESP_V4_FLOW: 1079a011952aSMichael Chan case AH_V4_FLOW: 1080a011952aSMichael Chan case ESP_V4_FLOW: 1081a011952aSMichael Chan case IPV4_FLOW: 1082a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 1083a011952aSMichael Chan break; 1084a011952aSMichael Chan 1085a011952aSMichael Chan case TCP_V6_FLOW: 1086a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) 1087a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1088a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1089a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1090a011952aSMichael Chan break; 1091a011952aSMichael Chan case UDP_V6_FLOW: 1092a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6) 1093a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 1094a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 1095a011952aSMichael Chan /* fall through */ 1096a011952aSMichael Chan case SCTP_V6_FLOW: 1097a011952aSMichael Chan case AH_ESP_V6_FLOW: 1098a011952aSMichael Chan case AH_V6_FLOW: 1099a011952aSMichael Chan case ESP_V6_FLOW: 1100a011952aSMichael Chan case IPV6_FLOW: 1101a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 1102a011952aSMichael Chan break; 1103a011952aSMichael Chan } 1104a011952aSMichael Chan return 0; 1105a011952aSMichael Chan } 1106a011952aSMichael Chan 1107a011952aSMichael Chan #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3) 1108a011952aSMichael Chan #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST) 1109a011952aSMichael Chan 1110a011952aSMichael Chan static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 1111a011952aSMichael Chan { 1112a011952aSMichael Chan u32 rss_hash_cfg = bp->rss_hash_cfg; 1113a011952aSMichael Chan int tuple, rc = 0; 1114a011952aSMichael Chan 1115a011952aSMichael Chan if (cmd->data == RXH_4TUPLE) 1116a011952aSMichael Chan tuple = 4; 1117a011952aSMichael Chan else if (cmd->data == RXH_2TUPLE) 1118a011952aSMichael Chan tuple = 2; 1119a011952aSMichael Chan else if (!cmd->data) 1120a011952aSMichael Chan tuple = 0; 1121a011952aSMichael Chan else 1122a011952aSMichael Chan return -EINVAL; 1123a011952aSMichael Chan 1124a011952aSMichael Chan if (cmd->flow_type == TCP_V4_FLOW) { 1125a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1126a011952aSMichael Chan if (tuple == 4) 1127a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 1128a011952aSMichael Chan } else if (cmd->flow_type == UDP_V4_FLOW) { 1129a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1130a011952aSMichael Chan return -EINVAL; 1131a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1132a011952aSMichael Chan if (tuple == 4) 1133a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 1134a011952aSMichael Chan } else if (cmd->flow_type == TCP_V6_FLOW) { 1135a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1136a011952aSMichael Chan if (tuple == 4) 1137a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 1138a011952aSMichael Chan } else if (cmd->flow_type == UDP_V6_FLOW) { 1139a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 1140a011952aSMichael Chan return -EINVAL; 1141a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1142a011952aSMichael Chan if (tuple == 4) 1143a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 1144a011952aSMichael Chan } else if (tuple == 4) { 1145a011952aSMichael Chan return -EINVAL; 1146a011952aSMichael Chan } 1147a011952aSMichael Chan 1148a011952aSMichael Chan switch (cmd->flow_type) { 1149a011952aSMichael Chan case TCP_V4_FLOW: 1150a011952aSMichael Chan case UDP_V4_FLOW: 1151a011952aSMichael Chan case SCTP_V4_FLOW: 1152a011952aSMichael Chan case AH_ESP_V4_FLOW: 1153a011952aSMichael Chan case AH_V4_FLOW: 1154a011952aSMichael Chan case ESP_V4_FLOW: 1155a011952aSMichael Chan case IPV4_FLOW: 1156a011952aSMichael Chan if (tuple == 2) 1157a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1158a011952aSMichael Chan else if (!tuple) 1159a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1160a011952aSMichael Chan break; 1161a011952aSMichael Chan 1162a011952aSMichael Chan case TCP_V6_FLOW: 1163a011952aSMichael Chan case UDP_V6_FLOW: 1164a011952aSMichael Chan case SCTP_V6_FLOW: 1165a011952aSMichael Chan case AH_ESP_V6_FLOW: 1166a011952aSMichael Chan case AH_V6_FLOW: 1167a011952aSMichael Chan case ESP_V6_FLOW: 1168a011952aSMichael Chan case IPV6_FLOW: 1169a011952aSMichael Chan if (tuple == 2) 1170a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1171a011952aSMichael Chan else if (!tuple) 1172a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1173a011952aSMichael Chan break; 1174a011952aSMichael Chan } 1175a011952aSMichael Chan 1176a011952aSMichael Chan if (bp->rss_hash_cfg == rss_hash_cfg) 1177a011952aSMichael Chan return 0; 1178a011952aSMichael Chan 1179a011952aSMichael Chan bp->rss_hash_cfg = rss_hash_cfg; 1180a011952aSMichael Chan if (netif_running(bp->dev)) { 1181a011952aSMichael Chan bnxt_close_nic(bp, false, false); 1182a011952aSMichael Chan rc = bnxt_open_nic(bp, false, false); 1183a011952aSMichael Chan } 1184a011952aSMichael Chan return rc; 1185a011952aSMichael Chan } 1186c0c050c5SMichael Chan 1187c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 1188c0c050c5SMichael Chan u32 *rule_locs) 1189c0c050c5SMichael Chan { 1190c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1191c0c050c5SMichael Chan int rc = 0; 1192c0c050c5SMichael Chan 1193c0c050c5SMichael Chan switch (cmd->cmd) { 1194a011952aSMichael Chan #ifdef CONFIG_RFS_ACCEL 1195c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 1196c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 1197c0c050c5SMichael Chan break; 1198c0c050c5SMichael Chan 1199c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 1200c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 1201c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 1202c0c050c5SMichael Chan break; 1203c0c050c5SMichael Chan 1204c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 1205c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 1206c0c050c5SMichael Chan break; 1207c0c050c5SMichael Chan 1208c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 1209c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 1210c0c050c5SMichael Chan break; 1211a011952aSMichael Chan #endif 1212a011952aSMichael Chan 1213a011952aSMichael Chan case ETHTOOL_GRXFH: 1214a011952aSMichael Chan rc = bnxt_grxfh(bp, cmd); 1215a011952aSMichael Chan break; 1216c0c050c5SMichael Chan 1217c0c050c5SMichael Chan default: 1218c0c050c5SMichael Chan rc = -EOPNOTSUPP; 1219c0c050c5SMichael Chan break; 1220c0c050c5SMichael Chan } 1221c0c050c5SMichael Chan 1222c0c050c5SMichael Chan return rc; 1223c0c050c5SMichael Chan } 1224a011952aSMichael Chan 1225a011952aSMichael Chan static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) 1226a011952aSMichael Chan { 1227a011952aSMichael Chan struct bnxt *bp = netdev_priv(dev); 1228a011952aSMichael Chan int rc; 1229a011952aSMichael Chan 1230a011952aSMichael Chan switch (cmd->cmd) { 1231a011952aSMichael Chan case ETHTOOL_SRXFH: 1232a011952aSMichael Chan rc = bnxt_srxfh(bp, cmd); 1233a011952aSMichael Chan break; 1234a011952aSMichael Chan 1235a011952aSMichael Chan default: 1236a011952aSMichael Chan rc = -EOPNOTSUPP; 1237a011952aSMichael Chan break; 1238a011952aSMichael Chan } 1239a011952aSMichael Chan return rc; 1240a011952aSMichael Chan } 1241c0c050c5SMichael Chan 1242b73c1d08SMichael Chan u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 1243c0c050c5SMichael Chan { 1244b73c1d08SMichael Chan struct bnxt *bp = netdev_priv(dev); 1245b73c1d08SMichael Chan 1246b73c1d08SMichael Chan if (bp->flags & BNXT_FLAG_CHIP_P5) 1247b73c1d08SMichael Chan return ALIGN(bp->rx_nr_rings, BNXT_RSS_TABLE_ENTRIES_P5); 1248c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 1249c0c050c5SMichael Chan } 1250c0c050c5SMichael Chan 1251c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 1252c0c050c5SMichael Chan { 1253c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 1254c0c050c5SMichael Chan } 1255c0c050c5SMichael Chan 1256c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 1257c0c050c5SMichael Chan u8 *hfunc) 1258c0c050c5SMichael Chan { 1259c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 12607991cb9cSMichael Chan struct bnxt_vnic_info *vnic; 1261adc38ac6SMichael Chan u32 i, tbl_size; 1262c0c050c5SMichael Chan 1263c0c050c5SMichael Chan if (hfunc) 1264c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 1265c0c050c5SMichael Chan 12667991cb9cSMichael Chan if (!bp->vnic_info) 12677991cb9cSMichael Chan return 0; 12687991cb9cSMichael Chan 12697991cb9cSMichael Chan vnic = &bp->vnic_info[0]; 1270adc38ac6SMichael Chan if (indir && bp->rss_indir_tbl) { 1271adc38ac6SMichael Chan tbl_size = bnxt_get_rxfh_indir_size(dev); 1272adc38ac6SMichael Chan for (i = 0; i < tbl_size; i++) 1273adc38ac6SMichael Chan indir[i] = bp->rss_indir_tbl[i]; 12747991cb9cSMichael Chan } 1275c0c050c5SMichael Chan 12767991cb9cSMichael Chan if (key && vnic->rss_hash_key) 1277c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 1278c0c050c5SMichael Chan 1279c0c050c5SMichael Chan return 0; 1280c0c050c5SMichael Chan } 1281c0c050c5SMichael Chan 1282bd3191b5SMichael Chan static int bnxt_set_rxfh(struct net_device *dev, const u32 *indir, 1283bd3191b5SMichael Chan const u8 *key, const u8 hfunc) 1284bd3191b5SMichael Chan { 1285bd3191b5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1286bd3191b5SMichael Chan int rc = 0; 1287bd3191b5SMichael Chan 1288bd3191b5SMichael Chan if (hfunc && hfunc != ETH_RSS_HASH_TOP) 1289bd3191b5SMichael Chan return -EOPNOTSUPP; 1290bd3191b5SMichael Chan 1291bd3191b5SMichael Chan if (key) 1292bd3191b5SMichael Chan return -EOPNOTSUPP; 1293bd3191b5SMichael Chan 1294bd3191b5SMichael Chan if (indir) { 1295bd3191b5SMichael Chan u32 i, pad, tbl_size = bnxt_get_rxfh_indir_size(dev); 1296bd3191b5SMichael Chan 1297bd3191b5SMichael Chan for (i = 0; i < tbl_size; i++) 1298bd3191b5SMichael Chan bp->rss_indir_tbl[i] = indir[i]; 1299bd3191b5SMichael Chan pad = bp->rss_indir_tbl_entries - tbl_size; 1300bd3191b5SMichael Chan if (pad) 1301bd3191b5SMichael Chan memset(&bp->rss_indir_tbl[i], 0, pad * sizeof(u16)); 1302bd3191b5SMichael Chan } 1303bd3191b5SMichael Chan 1304bd3191b5SMichael Chan if (netif_running(bp->dev)) { 1305bd3191b5SMichael Chan bnxt_close_nic(bp, false, false); 1306bd3191b5SMichael Chan rc = bnxt_open_nic(bp, false, false); 1307bd3191b5SMichael Chan } 1308bd3191b5SMichael Chan return rc; 1309bd3191b5SMichael Chan } 1310bd3191b5SMichael Chan 1311c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 1312c0c050c5SMichael Chan struct ethtool_drvinfo *info) 1313c0c050c5SMichael Chan { 1314c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1315c0c050c5SMichael Chan 1316c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 1317431aa1ebSMichael Chan strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); 1318c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 13195c8227d0SMichael Chan info->n_stats = bnxt_get_num_stats(bp); 1320eb513658SMichael Chan info->testinfo_len = bp->num_tests; 1321c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 1322c0c050c5SMichael Chan info->eedump_len = 0; 1323c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 1324c0c050c5SMichael Chan info->regdump_len = 0; 1325c0c050c5SMichael Chan } 1326c0c050c5SMichael Chan 1327b5d600b0SVasundhara Volam static int bnxt_get_regs_len(struct net_device *dev) 1328b5d600b0SVasundhara Volam { 1329b5d600b0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 1330b5d600b0SVasundhara Volam int reg_len; 1331b5d600b0SVasundhara Volam 1332b5d600b0SVasundhara Volam reg_len = BNXT_PXP_REG_LEN; 1333b5d600b0SVasundhara Volam 1334b5d600b0SVasundhara Volam if (bp->fw_cap & BNXT_FW_CAP_PCIE_STATS_SUPPORTED) 1335b5d600b0SVasundhara Volam reg_len += sizeof(struct pcie_ctx_hw_stats); 1336b5d600b0SVasundhara Volam 1337b5d600b0SVasundhara Volam return reg_len; 1338b5d600b0SVasundhara Volam } 1339b5d600b0SVasundhara Volam 1340b5d600b0SVasundhara Volam static void bnxt_get_regs(struct net_device *dev, struct ethtool_regs *regs, 1341b5d600b0SVasundhara Volam void *_p) 1342b5d600b0SVasundhara Volam { 1343b5d600b0SVasundhara Volam struct pcie_ctx_hw_stats *hw_pcie_stats; 1344b5d600b0SVasundhara Volam struct hwrm_pcie_qstats_input req = {0}; 1345b5d600b0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 1346b5d600b0SVasundhara Volam dma_addr_t hw_pcie_stats_addr; 1347b5d600b0SVasundhara Volam int rc; 1348b5d600b0SVasundhara Volam 1349b5d600b0SVasundhara Volam regs->version = 0; 1350b5d600b0SVasundhara Volam bnxt_dbg_hwrm_rd_reg(bp, 0, BNXT_PXP_REG_LEN / 4, _p); 1351b5d600b0SVasundhara Volam 1352b5d600b0SVasundhara Volam if (!(bp->fw_cap & BNXT_FW_CAP_PCIE_STATS_SUPPORTED)) 1353b5d600b0SVasundhara Volam return; 1354b5d600b0SVasundhara Volam 1355b5d600b0SVasundhara Volam hw_pcie_stats = dma_alloc_coherent(&bp->pdev->dev, 1356b5d600b0SVasundhara Volam sizeof(*hw_pcie_stats), 1357b5d600b0SVasundhara Volam &hw_pcie_stats_addr, GFP_KERNEL); 1358b5d600b0SVasundhara Volam if (!hw_pcie_stats) 1359b5d600b0SVasundhara Volam return; 1360b5d600b0SVasundhara Volam 1361b5d600b0SVasundhara Volam regs->version = 1; 1362b5d600b0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PCIE_QSTATS, -1, -1); 1363b5d600b0SVasundhara Volam req.pcie_stat_size = cpu_to_le16(sizeof(*hw_pcie_stats)); 1364b5d600b0SVasundhara Volam req.pcie_stat_host_addr = cpu_to_le64(hw_pcie_stats_addr); 1365b5d600b0SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 1366b5d600b0SVasundhara Volam rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1367b5d600b0SVasundhara Volam if (!rc) { 1368b5d600b0SVasundhara Volam __le64 *src = (__le64 *)hw_pcie_stats; 1369b5d600b0SVasundhara Volam u64 *dst = (u64 *)(_p + BNXT_PXP_REG_LEN); 1370b5d600b0SVasundhara Volam int i; 1371b5d600b0SVasundhara Volam 1372b5d600b0SVasundhara Volam for (i = 0; i < sizeof(*hw_pcie_stats) / sizeof(__le64); i++) 1373b5d600b0SVasundhara Volam dst[i] = le64_to_cpu(src[i]); 1374b5d600b0SVasundhara Volam } 1375b5d600b0SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 1376b5d600b0SVasundhara Volam dma_free_coherent(&bp->pdev->dev, sizeof(*hw_pcie_stats), hw_pcie_stats, 1377b5d600b0SVasundhara Volam hw_pcie_stats_addr); 1378b5d600b0SVasundhara Volam } 1379b5d600b0SVasundhara Volam 13808e202366SMichael Chan static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 13818e202366SMichael Chan { 13828e202366SMichael Chan struct bnxt *bp = netdev_priv(dev); 13838e202366SMichael Chan 13848e202366SMichael Chan wol->supported = 0; 13858e202366SMichael Chan wol->wolopts = 0; 13868e202366SMichael Chan memset(&wol->sopass, 0, sizeof(wol->sopass)); 13878e202366SMichael Chan if (bp->flags & BNXT_FLAG_WOL_CAP) { 13888e202366SMichael Chan wol->supported = WAKE_MAGIC; 13898e202366SMichael Chan if (bp->wol) 13908e202366SMichael Chan wol->wolopts = WAKE_MAGIC; 13918e202366SMichael Chan } 13928e202366SMichael Chan } 13938e202366SMichael Chan 13945282db6cSMichael Chan static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 13955282db6cSMichael Chan { 13965282db6cSMichael Chan struct bnxt *bp = netdev_priv(dev); 13975282db6cSMichael Chan 13985282db6cSMichael Chan if (wol->wolopts & ~WAKE_MAGIC) 13995282db6cSMichael Chan return -EINVAL; 14005282db6cSMichael Chan 14015282db6cSMichael Chan if (wol->wolopts & WAKE_MAGIC) { 14025282db6cSMichael Chan if (!(bp->flags & BNXT_FLAG_WOL_CAP)) 14035282db6cSMichael Chan return -EINVAL; 14045282db6cSMichael Chan if (!bp->wol) { 14055282db6cSMichael Chan if (bnxt_hwrm_alloc_wol_fltr(bp)) 14065282db6cSMichael Chan return -EBUSY; 14075282db6cSMichael Chan bp->wol = 1; 14085282db6cSMichael Chan } 14095282db6cSMichael Chan } else { 14105282db6cSMichael Chan if (bp->wol) { 14115282db6cSMichael Chan if (bnxt_hwrm_free_wol_fltr(bp)) 14125282db6cSMichael Chan return -EBUSY; 14135282db6cSMichael Chan bp->wol = 0; 14145282db6cSMichael Chan } 14155282db6cSMichael Chan } 14165282db6cSMichael Chan return 0; 14175282db6cSMichael Chan } 14185282db6cSMichael Chan 1419170ce013SMichael Chan u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause) 1420c0c050c5SMichael Chan { 1421c0c050c5SMichael Chan u32 speed_mask = 0; 1422c0c050c5SMichael Chan 1423c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 1424c0c050c5SMichael Chan /* set the advertised speeds */ 1425c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 1426c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 1427c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 1428c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 1429c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 1430c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 1431c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 1432c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 1433c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 14341c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 143527c4d578SMichael Chan 143627c4d578SMichael Chan if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH) 143727c4d578SMichael Chan speed_mask |= ADVERTISED_Pause; 143827c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_TX) 143927c4d578SMichael Chan speed_mask |= ADVERTISED_Asym_Pause; 144027c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_RX) 144127c4d578SMichael Chan speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 144227c4d578SMichael Chan 1443c0c050c5SMichael Chan return speed_mask; 1444c0c050c5SMichael Chan } 1445c0c050c5SMichael Chan 144600c04a92SMichael Chan #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\ 144700c04a92SMichael Chan { \ 144800c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \ 144900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 145000c04a92SMichael Chan 100baseT_Full); \ 145100c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \ 145200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 145300c04a92SMichael Chan 1000baseT_Full); \ 145400c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \ 145500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 145600c04a92SMichael Chan 10000baseT_Full); \ 145700c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \ 145800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 145900c04a92SMichael Chan 25000baseCR_Full); \ 146000c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \ 146100c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 146200c04a92SMichael Chan 40000baseCR4_Full);\ 146300c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \ 146400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 146500c04a92SMichael Chan 50000baseCR2_Full);\ 146638a21b34SDeepak Khungar if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \ 146738a21b34SDeepak Khungar ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 146838a21b34SDeepak Khungar 100000baseCR4_Full);\ 146900c04a92SMichael Chan if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \ 147000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 147100c04a92SMichael Chan Pause); \ 147200c04a92SMichael Chan if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \ 147300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode( \ 147400c04a92SMichael Chan lk_ksettings, name, Asym_Pause);\ 147500c04a92SMichael Chan } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \ 147600c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 147700c04a92SMichael Chan Asym_Pause); \ 147800c04a92SMichael Chan } \ 147900c04a92SMichael Chan } 148000c04a92SMichael Chan 148100c04a92SMichael Chan #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \ 148200c04a92SMichael Chan { \ 148300c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 148400c04a92SMichael Chan 100baseT_Full) || \ 148500c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 148600c04a92SMichael Chan 100baseT_Half)) \ 148700c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \ 148800c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 148900c04a92SMichael Chan 1000baseT_Full) || \ 149000c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 149100c04a92SMichael Chan 1000baseT_Half)) \ 149200c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \ 149300c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 149400c04a92SMichael Chan 10000baseT_Full)) \ 149500c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \ 149600c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 149700c04a92SMichael Chan 25000baseCR_Full)) \ 149800c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \ 149900c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 150000c04a92SMichael Chan 40000baseCR4_Full)) \ 150100c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \ 150200c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 150300c04a92SMichael Chan 50000baseCR2_Full)) \ 150400c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \ 150538a21b34SDeepak Khungar if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 150638a21b34SDeepak Khungar 100000baseCR4_Full)) \ 150738a21b34SDeepak Khungar (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \ 150800c04a92SMichael Chan } 150900c04a92SMichael Chan 151000c04a92SMichael Chan static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info, 151100c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 151227c4d578SMichael Chan { 151368515a18SMichael Chan u16 fw_speeds = link_info->advertising; 151427c4d578SMichael Chan u8 fw_pause = 0; 151527c4d578SMichael Chan 151627c4d578SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 151727c4d578SMichael Chan fw_pause = link_info->auto_pause_setting; 151827c4d578SMichael Chan 151900c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising); 152027c4d578SMichael Chan } 152127c4d578SMichael Chan 152200c04a92SMichael Chan static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info, 152300c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 15243277360eSMichael Chan { 15253277360eSMichael Chan u16 fw_speeds = link_info->lp_auto_link_speeds; 15263277360eSMichael Chan u8 fw_pause = 0; 15273277360eSMichael Chan 15283277360eSMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 15293277360eSMichael Chan fw_pause = link_info->lp_pause; 15303277360eSMichael Chan 153100c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, 153200c04a92SMichael Chan lp_advertising); 15333277360eSMichael Chan } 15343277360eSMichael Chan 153500c04a92SMichael Chan static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info, 153600c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 15374b32caccSMichael Chan { 15384b32caccSMichael Chan u16 fw_speeds = link_info->support_speeds; 15394b32caccSMichael Chan 154000c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported); 15414b32caccSMichael Chan 154200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause); 154300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 154400c04a92SMichael Chan Asym_Pause); 154593ed8117SMichael Chan 154600c04a92SMichael Chan if (link_info->support_auto_speeds) 154700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 154800c04a92SMichael Chan Autoneg); 154993ed8117SMichael Chan } 155093ed8117SMichael Chan 1551c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 1552c0c050c5SMichael Chan { 1553c0c050c5SMichael Chan switch (fw_link_speed) { 1554c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 1555c0c050c5SMichael Chan return SPEED_100; 1556c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 1557c0c050c5SMichael Chan return SPEED_1000; 1558c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 1559c0c050c5SMichael Chan return SPEED_2500; 1560c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 1561c0c050c5SMichael Chan return SPEED_10000; 1562c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 1563c0c050c5SMichael Chan return SPEED_20000; 1564c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 1565c0c050c5SMichael Chan return SPEED_25000; 1566c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 1567c0c050c5SMichael Chan return SPEED_40000; 1568c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 1569c0c050c5SMichael Chan return SPEED_50000; 157038a21b34SDeepak Khungar case BNXT_LINK_SPEED_100GB: 157138a21b34SDeepak Khungar return SPEED_100000; 1572c0c050c5SMichael Chan default: 1573c0c050c5SMichael Chan return SPEED_UNKNOWN; 1574c0c050c5SMichael Chan } 1575c0c050c5SMichael Chan } 1576c0c050c5SMichael Chan 157700c04a92SMichael Chan static int bnxt_get_link_ksettings(struct net_device *dev, 157800c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 1579c0c050c5SMichael Chan { 1580c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1581c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 158200c04a92SMichael Chan struct ethtool_link_settings *base = &lk_ksettings->base; 158300c04a92SMichael Chan u32 ethtool_speed; 1584c0c050c5SMichael Chan 158500c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported); 1586e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 158700c04a92SMichael Chan bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings); 1588c0c050c5SMichael Chan 158900c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising); 1590b763499eSMichael Chan if (link_info->autoneg) { 159100c04a92SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings); 159200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, 159300c04a92SMichael Chan advertising, Autoneg); 159400c04a92SMichael Chan base->autoneg = AUTONEG_ENABLE; 159500c04a92SMichael Chan base->duplex = DUPLEX_UNKNOWN; 159683d8f5e9SMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) { 159783d8f5e9SMichael Chan bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings); 159883d8f5e9SMichael Chan if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 159900c04a92SMichael Chan base->duplex = DUPLEX_FULL; 160029c262feSMichael Chan else 160100c04a92SMichael Chan base->duplex = DUPLEX_HALF; 160283d8f5e9SMichael Chan } 160383d8f5e9SMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 1604c0c050c5SMichael Chan } else { 160500c04a92SMichael Chan base->autoneg = AUTONEG_DISABLE; 160629c262feSMichael Chan ethtool_speed = 160729c262feSMichael Chan bnxt_fw_to_ethtool_speed(link_info->req_link_speed); 160800c04a92SMichael Chan base->duplex = DUPLEX_HALF; 160929c262feSMichael Chan if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL) 161000c04a92SMichael Chan base->duplex = DUPLEX_FULL; 1611c0c050c5SMichael Chan } 161200c04a92SMichael Chan base->speed = ethtool_speed; 1613c0c050c5SMichael Chan 161400c04a92SMichael Chan base->port = PORT_NONE; 1615c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 161600c04a92SMichael Chan base->port = PORT_TP; 161700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 161800c04a92SMichael Chan TP); 161900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 162000c04a92SMichael Chan TP); 1621c0c050c5SMichael Chan } else { 162200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 162300c04a92SMichael Chan FIBRE); 162400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 162500c04a92SMichael Chan FIBRE); 1626c0c050c5SMichael Chan 1627c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 162800c04a92SMichael Chan base->port = PORT_DA; 1629c0c050c5SMichael Chan else if (link_info->media_type == 1630c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 163100c04a92SMichael Chan base->port = PORT_FIBRE; 1632c0c050c5SMichael Chan } 163300c04a92SMichael Chan base->phy_address = link_info->phy_addr; 1634e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1635c0c050c5SMichael Chan 1636c0c050c5SMichael Chan return 0; 1637c0c050c5SMichael Chan } 1638c0c050c5SMichael Chan 163938a21b34SDeepak Khungar static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed) 1640c0c050c5SMichael Chan { 16419d9cee08SMichael Chan struct bnxt *bp = netdev_priv(dev); 16429d9cee08SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 16439d9cee08SMichael Chan u16 support_spds = link_info->support_speeds; 16449d9cee08SMichael Chan u32 fw_speed = 0; 16459d9cee08SMichael Chan 1646c0c050c5SMichael Chan switch (ethtool_speed) { 1647c0c050c5SMichael Chan case SPEED_100: 16489d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_100MB) 16499d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 16509d9cee08SMichael Chan break; 1651c0c050c5SMichael Chan case SPEED_1000: 16529d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_1GB) 16539d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 16549d9cee08SMichael Chan break; 1655c0c050c5SMichael Chan case SPEED_2500: 16569d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB) 16579d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 16589d9cee08SMichael Chan break; 1659c0c050c5SMichael Chan case SPEED_10000: 16609d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_10GB) 16619d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 16629d9cee08SMichael Chan break; 1663c0c050c5SMichael Chan case SPEED_20000: 16649d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_20GB) 16659d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 16669d9cee08SMichael Chan break; 1667c0c050c5SMichael Chan case SPEED_25000: 16689d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_25GB) 16699d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 16709d9cee08SMichael Chan break; 1671c0c050c5SMichael Chan case SPEED_40000: 16729d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_40GB) 16739d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 16749d9cee08SMichael Chan break; 1675c0c050c5SMichael Chan case SPEED_50000: 16769d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_50GB) 16779d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 16789d9cee08SMichael Chan break; 167938a21b34SDeepak Khungar case SPEED_100000: 168038a21b34SDeepak Khungar if (support_spds & BNXT_LINK_SPEED_MSK_100GB) 168138a21b34SDeepak Khungar fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB; 168238a21b34SDeepak Khungar break; 1683c0c050c5SMichael Chan default: 1684c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 1685c0c050c5SMichael Chan break; 1686c0c050c5SMichael Chan } 16879d9cee08SMichael Chan return fw_speed; 1688c0c050c5SMichael Chan } 1689c0c050c5SMichael Chan 1690939f7f0cSMichael Chan u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 1691c0c050c5SMichael Chan { 1692c0c050c5SMichael Chan u16 fw_speed_mask = 0; 1693c0c050c5SMichael Chan 1694c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 1695c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 1696c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 1697c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 1698c0c050c5SMichael Chan } 1699c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 1700c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 1701c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 1702c0c050c5SMichael Chan } 1703c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 1704c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 1705c0c050c5SMichael Chan 17061c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 17071c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 17081c49c421SMichael Chan 1709c0c050c5SMichael Chan return fw_speed_mask; 1710c0c050c5SMichael Chan } 1711c0c050c5SMichael Chan 171200c04a92SMichael Chan static int bnxt_set_link_ksettings(struct net_device *dev, 171300c04a92SMichael Chan const struct ethtool_link_ksettings *lk_ksettings) 1714c0c050c5SMichael Chan { 1715c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1716c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 171700c04a92SMichael Chan const struct ethtool_link_settings *base = &lk_ksettings->base; 1718c0c050c5SMichael Chan bool set_pause = false; 171968515a18SMichael Chan u16 fw_advertising = 0; 172068515a18SMichael Chan u32 speed; 172100c04a92SMichael Chan int rc = 0; 1722c0c050c5SMichael Chan 1723c7e457f4SMichael Chan if (!BNXT_PHY_CFG_ABLE(bp)) 172400c04a92SMichael Chan return -EOPNOTSUPP; 1725c0c050c5SMichael Chan 1726e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 172700c04a92SMichael Chan if (base->autoneg == AUTONEG_ENABLE) { 172800c04a92SMichael Chan BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings, 172900c04a92SMichael Chan advertising); 1730c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 1731c0c050c5SMichael Chan if (!fw_advertising) 173293ed8117SMichael Chan link_info->advertising = link_info->support_auto_speeds; 1733c0c050c5SMichael Chan else 1734c0c050c5SMichael Chan link_info->advertising = fw_advertising; 1735c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 1736c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 1737c0c050c5SMichael Chan */ 1738c0c050c5SMichael Chan set_pause = true; 1739c0c050c5SMichael Chan } else { 17409d9cee08SMichael Chan u16 fw_speed; 174103efbec0SMichael Chan u8 phy_type = link_info->phy_type; 17429d9cee08SMichael Chan 174303efbec0SMichael Chan if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET || 174403efbec0SMichael Chan phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE || 174503efbec0SMichael Chan link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 174603efbec0SMichael Chan netdev_err(dev, "10GBase-T devices must autoneg\n"); 174703efbec0SMichael Chan rc = -EINVAL; 174803efbec0SMichael Chan goto set_setting_exit; 174903efbec0SMichael Chan } 175000c04a92SMichael Chan if (base->duplex == DUPLEX_HALF) { 1751c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 1752c0c050c5SMichael Chan rc = -EINVAL; 1753c0c050c5SMichael Chan goto set_setting_exit; 1754c0c050c5SMichael Chan } 175500c04a92SMichael Chan speed = base->speed; 17569d9cee08SMichael Chan fw_speed = bnxt_get_fw_speed(dev, speed); 17579d9cee08SMichael Chan if (!fw_speed) { 17589d9cee08SMichael Chan rc = -EINVAL; 17599d9cee08SMichael Chan goto set_setting_exit; 17609d9cee08SMichael Chan } 17619d9cee08SMichael Chan link_info->req_link_speed = fw_speed; 1762c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 1763b763499eSMichael Chan link_info->autoneg = 0; 1764c0c050c5SMichael Chan link_info->advertising = 0; 1765c0c050c5SMichael Chan } 1766c0c050c5SMichael Chan 1767c0c050c5SMichael Chan if (netif_running(dev)) 1768939f7f0cSMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause, false); 1769c0c050c5SMichael Chan 1770c0c050c5SMichael Chan set_setting_exit: 1771e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1772c0c050c5SMichael Chan return rc; 1773c0c050c5SMichael Chan } 1774c0c050c5SMichael Chan 1775c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 1776c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1777c0c050c5SMichael Chan { 1778c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1779c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1780c0c050c5SMichael Chan 1781c0c050c5SMichael Chan if (BNXT_VF(bp)) 1782c0c050c5SMichael Chan return; 1783b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 17843c02d1bbSMichael Chan epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX); 17853c02d1bbSMichael Chan epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX); 1786c0c050c5SMichael Chan } 1787c0c050c5SMichael Chan 1788c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 1789c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1790c0c050c5SMichael Chan { 1791c0c050c5SMichael Chan int rc = 0; 1792c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1793c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1794c0c050c5SMichael Chan 1795c7e457f4SMichael Chan if (!BNXT_PHY_CFG_ABLE(bp)) 179675362a3fSMichael Chan return -EOPNOTSUPP; 1797c0c050c5SMichael Chan 1798c0c050c5SMichael Chan if (epause->autoneg) { 1799b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 1800b763499eSMichael Chan return -EINVAL; 1801b763499eSMichael Chan 1802c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 1803c9ee9516SMichael Chan if (bp->hwrm_spec_code >= 0x10201) 1804c9ee9516SMichael Chan link_info->req_flow_ctrl = 1805c9ee9516SMichael Chan PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; 1806c0c050c5SMichael Chan } else { 1807c0c050c5SMichael Chan /* when transition from auto pause to force pause, 1808c0c050c5SMichael Chan * force a link change 1809c0c050c5SMichael Chan */ 1810c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 1811c0c050c5SMichael Chan link_info->force_link_chng = true; 1812c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 1813c9ee9516SMichael Chan link_info->req_flow_ctrl = 0; 1814c0c050c5SMichael Chan } 1815c0c050c5SMichael Chan if (epause->rx_pause) 1816c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 1817c0c050c5SMichael Chan 1818c0c050c5SMichael Chan if (epause->tx_pause) 1819c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 1820c0c050c5SMichael Chan 1821163e9ef6SVasundhara Volam if (netif_running(dev)) { 1822163e9ef6SVasundhara Volam mutex_lock(&bp->link_lock); 1823c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 1824163e9ef6SVasundhara Volam mutex_unlock(&bp->link_lock); 1825163e9ef6SVasundhara Volam } 1826c0c050c5SMichael Chan return rc; 1827c0c050c5SMichael Chan } 1828c0c050c5SMichael Chan 1829c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 1830c0c050c5SMichael Chan { 1831c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1832c0c050c5SMichael Chan 1833c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 1834c0c050c5SMichael Chan return bp->link_info.link_up; 1835c0c050c5SMichael Chan } 1836c0c050c5SMichael Chan 1837b3b0ddd0SMichael Chan static void bnxt_print_admin_err(struct bnxt *bp) 1838b3b0ddd0SMichael Chan { 1839b3b0ddd0SMichael Chan netdev_info(bp->dev, "PF does not have admin privileges to flash or reset the device\n"); 1840b3b0ddd0SMichael Chan } 1841b3b0ddd0SMichael Chan 18425ac67d8bSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 18435ac67d8bSRob Swindell u16 ext, u16 *index, u32 *item_length, 18445ac67d8bSRob Swindell u32 *data_length); 18455ac67d8bSRob Swindell 1846c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 1847c0c050c5SMichael Chan u16 dir_type, 1848c0c050c5SMichael Chan u16 dir_ordinal, 1849c0c050c5SMichael Chan u16 dir_ext, 1850c0c050c5SMichael Chan u16 dir_attr, 1851c0c050c5SMichael Chan const u8 *data, 1852c0c050c5SMichael Chan size_t data_len) 1853c0c050c5SMichael Chan { 1854c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1855c0c050c5SMichael Chan int rc; 1856c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 1857c0c050c5SMichael Chan dma_addr_t dma_handle; 1858c0c050c5SMichael Chan u8 *kmem; 1859c0c050c5SMichael Chan 1860c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 1861c0c050c5SMichael Chan 1862c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 1863c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 1864c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 1865c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 1866c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 1867c0c050c5SMichael Chan 1868c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 1869c0c050c5SMichael Chan GFP_KERNEL); 1870c0c050c5SMichael Chan if (!kmem) { 1871c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1872c0c050c5SMichael Chan (unsigned)data_len); 1873c0c050c5SMichael Chan return -ENOMEM; 1874c0c050c5SMichael Chan } 1875c0c050c5SMichael Chan memcpy(kmem, data, data_len); 1876c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 1877c0c050c5SMichael Chan 1878c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 1879c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 1880c0c050c5SMichael Chan 1881d4f1420dSMichael Chan if (rc == -EACCES) 1882b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 1883c0c050c5SMichael Chan return rc; 1884c0c050c5SMichael Chan } 1885c0c050c5SMichael Chan 188695fec034SEdwin Peer static int bnxt_hwrm_firmware_reset(struct net_device *dev, u8 proc_type, 188795fec034SEdwin Peer u8 self_reset, u8 flags) 1888d2d6318cSRob Swindell { 1889d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 18907c675421SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 18917c675421SVasundhara Volam int rc; 1892d2d6318cSRob Swindell 1893d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 1894d2d6318cSRob Swindell 189595fec034SEdwin Peer req.embedded_proc_type = proc_type; 189695fec034SEdwin Peer req.selfrst_status = self_reset; 189795fec034SEdwin Peer req.flags = flags; 189895fec034SEdwin Peer 18998cec0940SEdwin Peer if (proc_type == FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP) { 19008cec0940SEdwin Peer rc = hwrm_send_message_silent(bp, &req, sizeof(req), 19018cec0940SEdwin Peer HWRM_CMD_TIMEOUT); 19028cec0940SEdwin Peer } else { 190395fec034SEdwin Peer rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 190495fec034SEdwin Peer if (rc == -EACCES) 190595fec034SEdwin Peer bnxt_print_admin_err(bp); 19068cec0940SEdwin Peer } 190795fec034SEdwin Peer return rc; 190895fec034SEdwin Peer } 190995fec034SEdwin Peer 191094f17e89SEdwin Peer static int bnxt_firmware_reset(struct net_device *dev, 191194f17e89SEdwin Peer enum bnxt_nvm_directory_type dir_type) 191295fec034SEdwin Peer { 191395fec034SEdwin Peer u8 self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTNONE; 191495fec034SEdwin Peer u8 proc_type, flags = 0; 191595fec034SEdwin Peer 1916d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 1917d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 1918d2d6318cSRob Swindell switch (dir_type) { 1919d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 1920d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 1921d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 192295fec034SEdwin Peer proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 1923d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 192495fec034SEdwin Peer self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1925d2d6318cSRob Swindell break; 1926d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 1927d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 192895fec034SEdwin Peer proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 192908141e0bSRob Swindell /* Self-reset APE upon next PCIe reset: */ 193095fec034SEdwin Peer self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1931d2d6318cSRob Swindell break; 1932d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 1933d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 193495fec034SEdwin Peer proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 1935d2d6318cSRob Swindell break; 1936d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 1937d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 193895fec034SEdwin Peer proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 1939d2d6318cSRob Swindell break; 1940d2d6318cSRob Swindell default: 1941d2d6318cSRob Swindell return -EINVAL; 1942d2d6318cSRob Swindell } 1943d2d6318cSRob Swindell 194495fec034SEdwin Peer return bnxt_hwrm_firmware_reset(dev, proc_type, self_reset, flags); 1945d2d6318cSRob Swindell } 1946d2d6318cSRob Swindell 194794f17e89SEdwin Peer static int bnxt_firmware_reset_chip(struct net_device *dev) 194894f17e89SEdwin Peer { 194994f17e89SEdwin Peer struct bnxt *bp = netdev_priv(dev); 195094f17e89SEdwin Peer u8 flags = 0; 195194f17e89SEdwin Peer 195294f17e89SEdwin Peer if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET) 195394f17e89SEdwin Peer flags = FW_RESET_REQ_FLAGS_RESET_GRACEFUL; 195494f17e89SEdwin Peer 195594f17e89SEdwin Peer return bnxt_hwrm_firmware_reset(dev, 195694f17e89SEdwin Peer FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP, 195794f17e89SEdwin Peer FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP, 195894f17e89SEdwin Peer flags); 195994f17e89SEdwin Peer } 196094f17e89SEdwin Peer 196194f17e89SEdwin Peer static int bnxt_firmware_reset_ap(struct net_device *dev) 196294f17e89SEdwin Peer { 196394f17e89SEdwin Peer return bnxt_hwrm_firmware_reset(dev, FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP, 196494f17e89SEdwin Peer FW_RESET_REQ_SELFRST_STATUS_SELFRSTNONE, 196594f17e89SEdwin Peer 0); 196694f17e89SEdwin Peer } 196794f17e89SEdwin Peer 1968c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 1969c0c050c5SMichael Chan u16 dir_type, 1970c0c050c5SMichael Chan const u8 *fw_data, 1971c0c050c5SMichael Chan size_t fw_size) 1972c0c050c5SMichael Chan { 1973c0c050c5SMichael Chan int rc = 0; 1974c0c050c5SMichael Chan u16 code_type; 1975c0c050c5SMichael Chan u32 stored_crc; 1976c0c050c5SMichael Chan u32 calculated_crc; 1977c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 1978c0c050c5SMichael Chan 1979c0c050c5SMichael Chan switch (dir_type) { 1980c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1981c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1982c0c050c5SMichael Chan code_type = CODE_BOOT; 1983c0c050c5SMichael Chan break; 198493e0b4feSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 198593e0b4feSRob Swindell code_type = CODE_CHIMP_PATCH; 198693e0b4feSRob Swindell break; 19872731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 19882731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 19892731d70fSRob Swindell break; 199093e0b4feSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 199193e0b4feSRob Swindell code_type = CODE_APE_PATCH; 199293e0b4feSRob Swindell break; 199393e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_FW: 199493e0b4feSRob Swindell code_type = CODE_KONG_FW; 199593e0b4feSRob Swindell break; 199693e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 199793e0b4feSRob Swindell code_type = CODE_KONG_PATCH; 199893e0b4feSRob Swindell break; 199993e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 200093e0b4feSRob Swindell code_type = CODE_BONO_FW; 200193e0b4feSRob Swindell break; 200293e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 200393e0b4feSRob Swindell code_type = CODE_BONO_PATCH; 200493e0b4feSRob Swindell break; 2005c0c050c5SMichael Chan default: 2006c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 2007c0c050c5SMichael Chan dir_type); 2008c0c050c5SMichael Chan return -EINVAL; 2009c0c050c5SMichael Chan } 2010c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 2011c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 2012c0c050c5SMichael Chan (unsigned int)fw_size); 2013c0c050c5SMichael Chan return -EINVAL; 2014c0c050c5SMichael Chan } 2015c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 2016c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 2017c0c050c5SMichael Chan le32_to_cpu(header->signature)); 2018c0c050c5SMichael Chan return -EINVAL; 2019c0c050c5SMichael Chan } 2020c0c050c5SMichael Chan if (header->code_type != code_type) { 2021c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 2022c0c050c5SMichael Chan code_type, header->code_type); 2023c0c050c5SMichael Chan return -EINVAL; 2024c0c050c5SMichael Chan } 2025c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 2026c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 2027c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 2028c0c050c5SMichael Chan return -EINVAL; 2029c0c050c5SMichael Chan } 2030c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 2031c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 2032c0c050c5SMichael Chan sizeof(stored_crc))); 2033c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 2034c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 2035c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 2036c0c050c5SMichael Chan (unsigned long)stored_crc, 2037c0c050c5SMichael Chan (unsigned long)calculated_crc); 2038c0c050c5SMichael Chan return -EINVAL; 2039c0c050c5SMichael Chan } 2040c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 2041c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 2042d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 2043d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 2044d2d6318cSRob Swindell 2045c0c050c5SMichael Chan return rc; 2046c0c050c5SMichael Chan } 2047c0c050c5SMichael Chan 20485ac67d8bSRob Swindell static int bnxt_flash_microcode(struct net_device *dev, 20495ac67d8bSRob Swindell u16 dir_type, 20505ac67d8bSRob Swindell const u8 *fw_data, 20515ac67d8bSRob Swindell size_t fw_size) 20525ac67d8bSRob Swindell { 20535ac67d8bSRob Swindell struct bnxt_ucode_trailer *trailer; 20545ac67d8bSRob Swindell u32 calculated_crc; 20555ac67d8bSRob Swindell u32 stored_crc; 20565ac67d8bSRob Swindell int rc = 0; 20575ac67d8bSRob Swindell 20585ac67d8bSRob Swindell if (fw_size < sizeof(struct bnxt_ucode_trailer)) { 20595ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode file size: %u\n", 20605ac67d8bSRob Swindell (unsigned int)fw_size); 20615ac67d8bSRob Swindell return -EINVAL; 20625ac67d8bSRob Swindell } 20635ac67d8bSRob Swindell trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size - 20645ac67d8bSRob Swindell sizeof(*trailer))); 20655ac67d8bSRob Swindell if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) { 20665ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer signature: %08X\n", 20675ac67d8bSRob Swindell le32_to_cpu(trailer->sig)); 20685ac67d8bSRob Swindell return -EINVAL; 20695ac67d8bSRob Swindell } 20705ac67d8bSRob Swindell if (le16_to_cpu(trailer->dir_type) != dir_type) { 20715ac67d8bSRob Swindell netdev_err(dev, "Expected microcode type: %d, read: %d\n", 20725ac67d8bSRob Swindell dir_type, le16_to_cpu(trailer->dir_type)); 20735ac67d8bSRob Swindell return -EINVAL; 20745ac67d8bSRob Swindell } 20755ac67d8bSRob Swindell if (le16_to_cpu(trailer->trailer_length) < 20765ac67d8bSRob Swindell sizeof(struct bnxt_ucode_trailer)) { 20775ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer length: %d\n", 20785ac67d8bSRob Swindell le16_to_cpu(trailer->trailer_length)); 20795ac67d8bSRob Swindell return -EINVAL; 20805ac67d8bSRob Swindell } 20815ac67d8bSRob Swindell 20825ac67d8bSRob Swindell /* Confirm the CRC32 checksum of the file: */ 20835ac67d8bSRob Swindell stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 20845ac67d8bSRob Swindell sizeof(stored_crc))); 20855ac67d8bSRob Swindell calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 20865ac67d8bSRob Swindell if (calculated_crc != stored_crc) { 20875ac67d8bSRob Swindell netdev_err(dev, 20885ac67d8bSRob Swindell "CRC32 (%08lX) does not match calculated: %08lX\n", 20895ac67d8bSRob Swindell (unsigned long)stored_crc, 20905ac67d8bSRob Swindell (unsigned long)calculated_crc); 20915ac67d8bSRob Swindell return -EINVAL; 20925ac67d8bSRob Swindell } 20935ac67d8bSRob Swindell rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 20945ac67d8bSRob Swindell 0, 0, fw_data, fw_size); 20955ac67d8bSRob Swindell 20965ac67d8bSRob Swindell return rc; 20975ac67d8bSRob Swindell } 20985ac67d8bSRob Swindell 2099c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 2100c0c050c5SMichael Chan { 2101c0c050c5SMichael Chan switch (dir_type) { 2102c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 2103c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 2104c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 2105c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 2106c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 2107c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 2108c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 210993e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 211093e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 2111c0c050c5SMichael Chan return true; 2112c0c050c5SMichael Chan } 2113c0c050c5SMichael Chan 2114c0c050c5SMichael Chan return false; 2115c0c050c5SMichael Chan } 2116c0c050c5SMichael Chan 21175ac67d8bSRob Swindell static bool bnxt_dir_type_is_other_exec_format(u16 dir_type) 2118c0c050c5SMichael Chan { 2119c0c050c5SMichael Chan switch (dir_type) { 2120c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 2121c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 2122c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 2123c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 2124c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 2125c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 2126c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 2127c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 2128c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 2129c0c050c5SMichael Chan return true; 2130c0c050c5SMichael Chan } 2131c0c050c5SMichael Chan 2132c0c050c5SMichael Chan return false; 2133c0c050c5SMichael Chan } 2134c0c050c5SMichael Chan 2135c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 2136c0c050c5SMichael Chan { 2137c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 21385ac67d8bSRob Swindell bnxt_dir_type_is_other_exec_format(dir_type); 2139c0c050c5SMichael Chan } 2140c0c050c5SMichael Chan 2141c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 2142c0c050c5SMichael Chan u16 dir_type, 2143c0c050c5SMichael Chan const char *filename) 2144c0c050c5SMichael Chan { 2145c0c050c5SMichael Chan const struct firmware *fw; 2146c0c050c5SMichael Chan int rc; 2147c0c050c5SMichael Chan 2148c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 2149c0c050c5SMichael Chan if (rc != 0) { 2150c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 2151c0c050c5SMichael Chan rc, filename); 2152c0c050c5SMichael Chan return rc; 2153c0c050c5SMichael Chan } 2154ba425800SJason Yan if (bnxt_dir_type_is_ape_bin_format(dir_type)) 2155c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 2156ba425800SJason Yan else if (bnxt_dir_type_is_other_exec_format(dir_type)) 21575ac67d8bSRob Swindell rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size); 2158c0c050c5SMichael Chan else 2159c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 2160c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 2161c0c050c5SMichael Chan release_firmware(fw); 2162c0c050c5SMichael Chan return rc; 2163c0c050c5SMichael Chan } 2164c0c050c5SMichael Chan 2165d168f328SVasundhara Volam int bnxt_flash_package_from_file(struct net_device *dev, const char *filename, 2166d168f328SVasundhara Volam u32 install_type) 2167c0c050c5SMichael Chan { 21685ac67d8bSRob Swindell struct bnxt *bp = netdev_priv(dev); 21695ac67d8bSRob Swindell struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr; 21705ac67d8bSRob Swindell struct hwrm_nvm_install_update_input install = {0}; 21715ac67d8bSRob Swindell const struct firmware *fw; 21725ac67d8bSRob Swindell u32 item_len; 217322630e28SEdwin Peer int rc = 0; 21745ac67d8bSRob Swindell u16 index; 21755ac67d8bSRob Swindell 21765ac67d8bSRob Swindell bnxt_hwrm_fw_set_time(bp); 21775ac67d8bSRob Swindell 217895ec1f47SVasundhara Volam rc = bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE, 21795ac67d8bSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 218095ec1f47SVasundhara Volam &index, &item_len, NULL); 218195ec1f47SVasundhara Volam if (rc) { 21825ac67d8bSRob Swindell netdev_err(dev, "PKG update area not created in nvram\n"); 218395ec1f47SVasundhara Volam return rc; 21845ac67d8bSRob Swindell } 21855ac67d8bSRob Swindell 21865ac67d8bSRob Swindell rc = request_firmware(&fw, filename, &dev->dev); 21875ac67d8bSRob Swindell if (rc != 0) { 21885ac67d8bSRob Swindell netdev_err(dev, "PKG error %d requesting file: %s\n", 21895ac67d8bSRob Swindell rc, filename); 21905ac67d8bSRob Swindell return rc; 21915ac67d8bSRob Swindell } 21925ac67d8bSRob Swindell 21935ac67d8bSRob Swindell if (fw->size > item_len) { 21949a005c38SJonathan Lemon netdev_err(dev, "PKG insufficient update area in nvram: %lu\n", 21955ac67d8bSRob Swindell (unsigned long)fw->size); 21965ac67d8bSRob Swindell rc = -EFBIG; 21975ac67d8bSRob Swindell } else { 21985ac67d8bSRob Swindell dma_addr_t dma_handle; 21995ac67d8bSRob Swindell u8 *kmem; 22005ac67d8bSRob Swindell struct hwrm_nvm_modify_input modify = {0}; 22015ac67d8bSRob Swindell 22025ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1); 22035ac67d8bSRob Swindell 22045ac67d8bSRob Swindell modify.dir_idx = cpu_to_le16(index); 22055ac67d8bSRob Swindell modify.len = cpu_to_le32(fw->size); 22065ac67d8bSRob Swindell 22075ac67d8bSRob Swindell kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size, 22085ac67d8bSRob Swindell &dma_handle, GFP_KERNEL); 22095ac67d8bSRob Swindell if (!kmem) { 22105ac67d8bSRob Swindell netdev_err(dev, 22115ac67d8bSRob Swindell "dma_alloc_coherent failure, length = %u\n", 22125ac67d8bSRob Swindell (unsigned int)fw->size); 22135ac67d8bSRob Swindell rc = -ENOMEM; 22145ac67d8bSRob Swindell } else { 22155ac67d8bSRob Swindell memcpy(kmem, fw->data, fw->size); 22165ac67d8bSRob Swindell modify.host_src_addr = cpu_to_le64(dma_handle); 22175ac67d8bSRob Swindell 221822630e28SEdwin Peer rc = hwrm_send_message(bp, &modify, sizeof(modify), 22195ac67d8bSRob Swindell FLASH_PACKAGE_TIMEOUT); 22205ac67d8bSRob Swindell dma_free_coherent(&bp->pdev->dev, fw->size, kmem, 22215ac67d8bSRob Swindell dma_handle); 22225ac67d8bSRob Swindell } 22235ac67d8bSRob Swindell } 22245ac67d8bSRob Swindell release_firmware(fw); 222522630e28SEdwin Peer if (rc) 22267c675421SVasundhara Volam goto err_exit; 22275ac67d8bSRob Swindell 22285ac67d8bSRob Swindell if ((install_type & 0xffff) == 0) 22295ac67d8bSRob Swindell install_type >>= 16; 22305ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1); 22315ac67d8bSRob Swindell install.install_type = cpu_to_le32(install_type); 22325ac67d8bSRob Swindell 2233cb4d1d62SKshitij Soni mutex_lock(&bp->hwrm_cmd_lock); 223422630e28SEdwin Peer rc = _hwrm_send_message(bp, &install, sizeof(install), 22355ac67d8bSRob Swindell INSTALL_PACKAGE_TIMEOUT); 223622630e28SEdwin Peer if (rc) { 2237cb4d1d62SKshitij Soni u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err; 2238cb4d1d62SKshitij Soni 2239dd2ebf34SVasundhara Volam if (resp->error_code && error_code == 2240dd2ebf34SVasundhara Volam NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) { 2241cb4d1d62SKshitij Soni install.flags |= cpu_to_le16( 2242cb4d1d62SKshitij Soni NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG); 224322630e28SEdwin Peer rc = _hwrm_send_message(bp, &install, sizeof(install), 2244cb4d1d62SKshitij Soni INSTALL_PACKAGE_TIMEOUT); 2245dd2ebf34SVasundhara Volam } 224622630e28SEdwin Peer if (rc) 2247cb4d1d62SKshitij Soni goto flash_pkg_exit; 2248cb4d1d62SKshitij Soni } 22495ac67d8bSRob Swindell 22505ac67d8bSRob Swindell if (resp->result) { 22515ac67d8bSRob Swindell netdev_err(dev, "PKG install error = %d, problem_item = %d\n", 22525ac67d8bSRob Swindell (s8)resp->result, (int)resp->problem_item); 2253cb4d1d62SKshitij Soni rc = -ENOPKG; 22545ac67d8bSRob Swindell } 2255cb4d1d62SKshitij Soni flash_pkg_exit: 2256cb4d1d62SKshitij Soni mutex_unlock(&bp->hwrm_cmd_lock); 22577c675421SVasundhara Volam err_exit: 225822630e28SEdwin Peer if (rc == -EACCES) 2259b3b0ddd0SMichael Chan bnxt_print_admin_err(bp); 2260cb4d1d62SKshitij Soni return rc; 2261c0c050c5SMichael Chan } 2262c0c050c5SMichael Chan 2263c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 2264c0c050c5SMichael Chan struct ethtool_flash *flash) 2265c0c050c5SMichael Chan { 2266c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 2267c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 2268c0c050c5SMichael Chan return -EINVAL; 2269c0c050c5SMichael Chan } 2270c0c050c5SMichael Chan 22715ac67d8bSRob Swindell if (flash->region == ETHTOOL_FLASH_ALL_REGIONS || 22725ac67d8bSRob Swindell flash->region > 0xffff) 22735ac67d8bSRob Swindell return bnxt_flash_package_from_file(dev, flash->data, 22745ac67d8bSRob Swindell flash->region); 2275c0c050c5SMichael Chan 2276c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 2277c0c050c5SMichael Chan } 2278c0c050c5SMichael Chan 2279c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 2280c0c050c5SMichael Chan { 2281c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2282c0c050c5SMichael Chan int rc; 2283c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 2284c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 2285c0c050c5SMichael Chan 2286c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 2287c0c050c5SMichael Chan 2288c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2289c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2290c0c050c5SMichael Chan if (!rc) { 2291c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 2292c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 2293c0c050c5SMichael Chan } 2294c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2295c0c050c5SMichael Chan return rc; 2296c0c050c5SMichael Chan } 2297c0c050c5SMichael Chan 2298c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 2299c0c050c5SMichael Chan { 23004cebbacaSMichael Chan struct bnxt *bp = netdev_priv(dev); 23014cebbacaSMichael Chan 23024cebbacaSMichael Chan if (BNXT_VF(bp)) 23034cebbacaSMichael Chan return 0; 23044cebbacaSMichael Chan 2305c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 2306c0c050c5SMichael Chan * passed via the ethtool command-line utility. 2307c0c050c5SMichael Chan */ 2308c0c050c5SMichael Chan return -1; 2309c0c050c5SMichael Chan } 2310c0c050c5SMichael Chan 2311c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 2312c0c050c5SMichael Chan { 2313c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2314c0c050c5SMichael Chan int rc; 2315c0c050c5SMichael Chan u32 dir_entries; 2316c0c050c5SMichael Chan u32 entry_length; 2317c0c050c5SMichael Chan u8 *buf; 2318c0c050c5SMichael Chan size_t buflen; 2319c0c050c5SMichael Chan dma_addr_t dma_handle; 2320c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 2321c0c050c5SMichael Chan 2322c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 2323c0c050c5SMichael Chan if (rc != 0) 2324c0c050c5SMichael Chan return rc; 2325c0c050c5SMichael Chan 2326c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 2327c0c050c5SMichael Chan if (len < 2) 2328c0c050c5SMichael Chan return -EINVAL; 2329c0c050c5SMichael Chan 2330c0c050c5SMichael Chan *data++ = dir_entries; 2331c0c050c5SMichael Chan *data++ = entry_length; 2332c0c050c5SMichael Chan len -= 2; 2333c0c050c5SMichael Chan memset(data, 0xff, len); 2334c0c050c5SMichael Chan 2335c0c050c5SMichael Chan buflen = dir_entries * entry_length; 2336c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 2337c0c050c5SMichael Chan GFP_KERNEL); 2338c0c050c5SMichael Chan if (!buf) { 2339c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2340c0c050c5SMichael Chan (unsigned)buflen); 2341c0c050c5SMichael Chan return -ENOMEM; 2342c0c050c5SMichael Chan } 2343c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 2344c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2345c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2346c0c050c5SMichael Chan if (rc == 0) 2347c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 2348c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 2349c0c050c5SMichael Chan return rc; 2350c0c050c5SMichael Chan } 2351c0c050c5SMichael Chan 2352c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 2353c0c050c5SMichael Chan u32 length, u8 *data) 2354c0c050c5SMichael Chan { 2355c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2356c0c050c5SMichael Chan int rc; 2357c0c050c5SMichael Chan u8 *buf; 2358c0c050c5SMichael Chan dma_addr_t dma_handle; 2359c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 2360c0c050c5SMichael Chan 2361e0ad8fc5SMichael Chan if (!length) 2362e0ad8fc5SMichael Chan return -EINVAL; 2363e0ad8fc5SMichael Chan 2364c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 2365c0c050c5SMichael Chan GFP_KERNEL); 2366c0c050c5SMichael Chan if (!buf) { 2367c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2368c0c050c5SMichael Chan (unsigned)length); 2369c0c050c5SMichael Chan return -ENOMEM; 2370c0c050c5SMichael Chan } 2371c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 2372c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2373c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2374c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 2375c0c050c5SMichael Chan req.len = cpu_to_le32(length); 2376c0c050c5SMichael Chan 2377c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2378c0c050c5SMichael Chan if (rc == 0) 2379c0c050c5SMichael Chan memcpy(data, buf, length); 2380c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 2381c0c050c5SMichael Chan return rc; 2382c0c050c5SMichael Chan } 2383c0c050c5SMichael Chan 23843ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 23853ebf6f0aSRob Swindell u16 ext, u16 *index, u32 *item_length, 23863ebf6f0aSRob Swindell u32 *data_length) 23873ebf6f0aSRob Swindell { 23883ebf6f0aSRob Swindell struct bnxt *bp = netdev_priv(dev); 23893ebf6f0aSRob Swindell int rc; 23903ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_input req = {0}; 23913ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr; 23923ebf6f0aSRob Swindell 23933ebf6f0aSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1); 23943ebf6f0aSRob Swindell req.enables = 0; 23953ebf6f0aSRob Swindell req.dir_idx = 0; 23963ebf6f0aSRob Swindell req.dir_type = cpu_to_le16(type); 23973ebf6f0aSRob Swindell req.dir_ordinal = cpu_to_le16(ordinal); 23983ebf6f0aSRob Swindell req.dir_ext = cpu_to_le16(ext); 23993ebf6f0aSRob Swindell req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ; 2400cc72f3b1SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2401cc72f3b1SMichael Chan rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 24023ebf6f0aSRob Swindell if (rc == 0) { 24033ebf6f0aSRob Swindell if (index) 24043ebf6f0aSRob Swindell *index = le16_to_cpu(output->dir_idx); 24053ebf6f0aSRob Swindell if (item_length) 24063ebf6f0aSRob Swindell *item_length = le32_to_cpu(output->dir_item_length); 24073ebf6f0aSRob Swindell if (data_length) 24083ebf6f0aSRob Swindell *data_length = le32_to_cpu(output->dir_data_length); 24093ebf6f0aSRob Swindell } 2410cc72f3b1SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 24113ebf6f0aSRob Swindell return rc; 24123ebf6f0aSRob Swindell } 24133ebf6f0aSRob Swindell 24143ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen) 24153ebf6f0aSRob Swindell { 24163ebf6f0aSRob Swindell char *retval = NULL; 24173ebf6f0aSRob Swindell char *p; 24183ebf6f0aSRob Swindell char *value; 24193ebf6f0aSRob Swindell int field = 0; 24203ebf6f0aSRob Swindell 24213ebf6f0aSRob Swindell if (datalen < 1) 24223ebf6f0aSRob Swindell return NULL; 24233ebf6f0aSRob Swindell /* null-terminate the log data (removing last '\n'): */ 24243ebf6f0aSRob Swindell data[datalen - 1] = 0; 24253ebf6f0aSRob Swindell for (p = data; *p != 0; p++) { 24263ebf6f0aSRob Swindell field = 0; 24273ebf6f0aSRob Swindell retval = NULL; 24283ebf6f0aSRob Swindell while (*p != 0 && *p != '\n') { 24293ebf6f0aSRob Swindell value = p; 24303ebf6f0aSRob Swindell while (*p != 0 && *p != '\t' && *p != '\n') 24313ebf6f0aSRob Swindell p++; 24323ebf6f0aSRob Swindell if (field == desired_field) 24333ebf6f0aSRob Swindell retval = value; 24343ebf6f0aSRob Swindell if (*p != '\t') 24353ebf6f0aSRob Swindell break; 24363ebf6f0aSRob Swindell *p = 0; 24373ebf6f0aSRob Swindell field++; 24383ebf6f0aSRob Swindell p++; 24393ebf6f0aSRob Swindell } 24403ebf6f0aSRob Swindell if (*p == 0) 24413ebf6f0aSRob Swindell break; 24423ebf6f0aSRob Swindell *p = 0; 24433ebf6f0aSRob Swindell } 24443ebf6f0aSRob Swindell return retval; 24453ebf6f0aSRob Swindell } 24463ebf6f0aSRob Swindell 2447a60faa60SVasundhara Volam static void bnxt_get_pkgver(struct net_device *dev) 24483ebf6f0aSRob Swindell { 2449a60faa60SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 24503ebf6f0aSRob Swindell u16 index = 0; 2451a60faa60SVasundhara Volam char *pkgver; 2452a60faa60SVasundhara Volam u32 pkglen; 2453a60faa60SVasundhara Volam u8 *pkgbuf; 2454a60faa60SVasundhara Volam int len; 24553ebf6f0aSRob Swindell 24563ebf6f0aSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG, 24573ebf6f0aSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 2458a60faa60SVasundhara Volam &index, NULL, &pkglen) != 0) 2459a60faa60SVasundhara Volam return; 24603ebf6f0aSRob Swindell 2461a60faa60SVasundhara Volam pkgbuf = kzalloc(pkglen, GFP_KERNEL); 2462a60faa60SVasundhara Volam if (!pkgbuf) { 2463a60faa60SVasundhara Volam dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n", 2464a60faa60SVasundhara Volam pkglen); 2465a60faa60SVasundhara Volam return; 2466a60faa60SVasundhara Volam } 24673ebf6f0aSRob Swindell 2468a60faa60SVasundhara Volam if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf)) 2469a60faa60SVasundhara Volam goto err; 2470a60faa60SVasundhara Volam 2471a60faa60SVasundhara Volam pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf, 2472a60faa60SVasundhara Volam pkglen); 2473a60faa60SVasundhara Volam if (pkgver && *pkgver != 0 && isdigit(*pkgver)) { 2474a60faa60SVasundhara Volam len = strlen(bp->fw_ver_str); 2475a60faa60SVasundhara Volam snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1, 2476a60faa60SVasundhara Volam "/pkg %s", pkgver); 2477a60faa60SVasundhara Volam } 2478a60faa60SVasundhara Volam err: 2479a60faa60SVasundhara Volam kfree(pkgbuf); 24803ebf6f0aSRob Swindell } 24813ebf6f0aSRob Swindell 2482c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 2483c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2484c0c050c5SMichael Chan u8 *data) 2485c0c050c5SMichael Chan { 2486c0c050c5SMichael Chan u32 index; 2487c0c050c5SMichael Chan u32 offset; 2488c0c050c5SMichael Chan 2489c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 2490c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 2491c0c050c5SMichael Chan 2492c0c050c5SMichael Chan index = eeprom->offset >> 24; 2493c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 2494c0c050c5SMichael Chan 2495c0c050c5SMichael Chan if (index == 0) { 2496c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 2497c0c050c5SMichael Chan return -EINVAL; 2498c0c050c5SMichael Chan } 2499c0c050c5SMichael Chan 2500c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 2501c0c050c5SMichael Chan } 2502c0c050c5SMichael Chan 2503c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 2504c0c050c5SMichael Chan { 2505c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2506c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 2507c0c050c5SMichael Chan 2508c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 2509c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2510c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2511c0c050c5SMichael Chan } 2512c0c050c5SMichael Chan 2513c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 2514c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2515c0c050c5SMichael Chan u8 *data) 2516c0c050c5SMichael Chan { 2517c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2518c0c050c5SMichael Chan u8 index, dir_op; 2519c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 2520c0c050c5SMichael Chan 2521c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 2522c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 2523c0c050c5SMichael Chan return -EINVAL; 2524c0c050c5SMichael Chan } 2525c0c050c5SMichael Chan 2526c0c050c5SMichael Chan type = eeprom->magic >> 16; 2527c0c050c5SMichael Chan 2528c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 2529c0c050c5SMichael Chan index = eeprom->magic & 0xff; 2530c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 2531c0c050c5SMichael Chan if (index == 0) 2532c0c050c5SMichael Chan return -EINVAL; 2533c0c050c5SMichael Chan switch (dir_op) { 2534c0c050c5SMichael Chan case 0x0e: /* erase */ 2535c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 2536c0c050c5SMichael Chan return -EINVAL; 2537c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 2538c0c050c5SMichael Chan default: 2539c0c050c5SMichael Chan return -EINVAL; 2540c0c050c5SMichael Chan } 2541c0c050c5SMichael Chan } 2542c0c050c5SMichael Chan 2543c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 2544ba425800SJason Yan if (bnxt_dir_type_is_executable(type)) 25455ac67d8bSRob Swindell return -EOPNOTSUPP; 2546c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 2547c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 2548c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 2549c0c050c5SMichael Chan 2550c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 2551c0c050c5SMichael Chan eeprom->len); 2552c0c050c5SMichael Chan } 2553c0c050c5SMichael Chan 255472b34f04SMichael Chan static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata) 255572b34f04SMichael Chan { 255672b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 255772b34f04SMichael Chan struct ethtool_eee *eee = &bp->eee; 255872b34f04SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 255972b34f04SMichael Chan u32 advertising = 256072b34f04SMichael Chan _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); 256172b34f04SMichael Chan int rc = 0; 256272b34f04SMichael Chan 2563c7e457f4SMichael Chan if (!BNXT_PHY_CFG_ABLE(bp)) 256475362a3fSMichael Chan return -EOPNOTSUPP; 256572b34f04SMichael Chan 256672b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 256772b34f04SMichael Chan return -EOPNOTSUPP; 256872b34f04SMichael Chan 256972b34f04SMichael Chan if (!edata->eee_enabled) 257072b34f04SMichael Chan goto eee_ok; 257172b34f04SMichael Chan 257272b34f04SMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { 257372b34f04SMichael Chan netdev_warn(dev, "EEE requires autoneg\n"); 257472b34f04SMichael Chan return -EINVAL; 257572b34f04SMichael Chan } 257672b34f04SMichael Chan if (edata->tx_lpi_enabled) { 257772b34f04SMichael Chan if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi || 257872b34f04SMichael Chan edata->tx_lpi_timer < bp->lpi_tmr_lo)) { 257972b34f04SMichael Chan netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n", 258072b34f04SMichael Chan bp->lpi_tmr_lo, bp->lpi_tmr_hi); 258172b34f04SMichael Chan return -EINVAL; 258272b34f04SMichael Chan } else if (!bp->lpi_tmr_hi) { 258372b34f04SMichael Chan edata->tx_lpi_timer = eee->tx_lpi_timer; 258472b34f04SMichael Chan } 258572b34f04SMichael Chan } 258672b34f04SMichael Chan if (!edata->advertised) { 258772b34f04SMichael Chan edata->advertised = advertising & eee->supported; 258872b34f04SMichael Chan } else if (edata->advertised & ~advertising) { 258972b34f04SMichael Chan netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", 259072b34f04SMichael Chan edata->advertised, advertising); 259172b34f04SMichael Chan return -EINVAL; 259272b34f04SMichael Chan } 259372b34f04SMichael Chan 259472b34f04SMichael Chan eee->advertised = edata->advertised; 259572b34f04SMichael Chan eee->tx_lpi_enabled = edata->tx_lpi_enabled; 259672b34f04SMichael Chan eee->tx_lpi_timer = edata->tx_lpi_timer; 259772b34f04SMichael Chan eee_ok: 259872b34f04SMichael Chan eee->eee_enabled = edata->eee_enabled; 259972b34f04SMichael Chan 260072b34f04SMichael Chan if (netif_running(dev)) 260172b34f04SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, false, true); 260272b34f04SMichael Chan 260372b34f04SMichael Chan return rc; 260472b34f04SMichael Chan } 260572b34f04SMichael Chan 260672b34f04SMichael Chan static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata) 260772b34f04SMichael Chan { 260872b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 260972b34f04SMichael Chan 261072b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 261172b34f04SMichael Chan return -EOPNOTSUPP; 261272b34f04SMichael Chan 261372b34f04SMichael Chan *edata = bp->eee; 261472b34f04SMichael Chan if (!bp->eee.eee_enabled) { 261572b34f04SMichael Chan /* Preserve tx_lpi_timer so that the last value will be used 261672b34f04SMichael Chan * by default when it is re-enabled. 261772b34f04SMichael Chan */ 261872b34f04SMichael Chan edata->advertised = 0; 261972b34f04SMichael Chan edata->tx_lpi_enabled = 0; 262072b34f04SMichael Chan } 262172b34f04SMichael Chan 262272b34f04SMichael Chan if (!bp->eee.eee_active) 262372b34f04SMichael Chan edata->lp_advertised = 0; 262472b34f04SMichael Chan 262572b34f04SMichael Chan return 0; 262672b34f04SMichael Chan } 262772b34f04SMichael Chan 262842ee18feSAjit Khaparde static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr, 262942ee18feSAjit Khaparde u16 page_number, u16 start_addr, 263042ee18feSAjit Khaparde u16 data_length, u8 *buf) 263142ee18feSAjit Khaparde { 263242ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_input req = {0}; 263342ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr; 263442ee18feSAjit Khaparde int rc, byte_offset = 0; 263542ee18feSAjit Khaparde 263642ee18feSAjit Khaparde bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1); 263742ee18feSAjit Khaparde req.i2c_slave_addr = i2c_addr; 263842ee18feSAjit Khaparde req.page_number = cpu_to_le16(page_number); 263942ee18feSAjit Khaparde req.port_id = cpu_to_le16(bp->pf.port_id); 264042ee18feSAjit Khaparde do { 264142ee18feSAjit Khaparde u16 xfer_size; 264242ee18feSAjit Khaparde 264342ee18feSAjit Khaparde xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE); 264442ee18feSAjit Khaparde data_length -= xfer_size; 264542ee18feSAjit Khaparde req.page_offset = cpu_to_le16(start_addr + byte_offset); 264642ee18feSAjit Khaparde req.data_length = xfer_size; 264742ee18feSAjit Khaparde req.enables = cpu_to_le32(start_addr + byte_offset ? 264842ee18feSAjit Khaparde PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0); 264942ee18feSAjit Khaparde mutex_lock(&bp->hwrm_cmd_lock); 265042ee18feSAjit Khaparde rc = _hwrm_send_message(bp, &req, sizeof(req), 265142ee18feSAjit Khaparde HWRM_CMD_TIMEOUT); 265242ee18feSAjit Khaparde if (!rc) 265342ee18feSAjit Khaparde memcpy(buf + byte_offset, output->data, xfer_size); 265442ee18feSAjit Khaparde mutex_unlock(&bp->hwrm_cmd_lock); 265542ee18feSAjit Khaparde byte_offset += xfer_size; 265642ee18feSAjit Khaparde } while (!rc && data_length > 0); 265742ee18feSAjit Khaparde 265842ee18feSAjit Khaparde return rc; 265942ee18feSAjit Khaparde } 266042ee18feSAjit Khaparde 266142ee18feSAjit Khaparde static int bnxt_get_module_info(struct net_device *dev, 266242ee18feSAjit Khaparde struct ethtool_modinfo *modinfo) 266342ee18feSAjit Khaparde { 26647328a23cSVasundhara Volam u8 data[SFF_DIAG_SUPPORT_OFFSET + 1]; 266542ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 266642ee18feSAjit Khaparde int rc; 266742ee18feSAjit Khaparde 266842ee18feSAjit Khaparde /* No point in going further if phy status indicates 266942ee18feSAjit Khaparde * module is not inserted or if it is powered down or 267042ee18feSAjit Khaparde * if it is of type 10GBase-T 267142ee18feSAjit Khaparde */ 267242ee18feSAjit Khaparde if (bp->link_info.module_status > 267342ee18feSAjit Khaparde PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG) 267442ee18feSAjit Khaparde return -EOPNOTSUPP; 267542ee18feSAjit Khaparde 267642ee18feSAjit Khaparde /* This feature is not supported in older firmware versions */ 267742ee18feSAjit Khaparde if (bp->hwrm_spec_code < 0x10202) 267842ee18feSAjit Khaparde return -EOPNOTSUPP; 267942ee18feSAjit Khaparde 26807328a23cSVasundhara Volam rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0, 26817328a23cSVasundhara Volam SFF_DIAG_SUPPORT_OFFSET + 1, 26827328a23cSVasundhara Volam data); 268342ee18feSAjit Khaparde if (!rc) { 26847328a23cSVasundhara Volam u8 module_id = data[0]; 26857328a23cSVasundhara Volam u8 diag_supported = data[SFF_DIAG_SUPPORT_OFFSET]; 268642ee18feSAjit Khaparde 268742ee18feSAjit Khaparde switch (module_id) { 268842ee18feSAjit Khaparde case SFF_MODULE_ID_SFP: 268942ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8472; 269042ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 26917328a23cSVasundhara Volam if (!diag_supported) 26927328a23cSVasundhara Volam modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 269342ee18feSAjit Khaparde break; 269442ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP: 269542ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP_PLUS: 269642ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8436; 269742ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 269842ee18feSAjit Khaparde break; 269942ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP28: 270042ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8636; 270142ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 270242ee18feSAjit Khaparde break; 270342ee18feSAjit Khaparde default: 270442ee18feSAjit Khaparde rc = -EOPNOTSUPP; 270542ee18feSAjit Khaparde break; 270642ee18feSAjit Khaparde } 270742ee18feSAjit Khaparde } 270842ee18feSAjit Khaparde return rc; 270942ee18feSAjit Khaparde } 271042ee18feSAjit Khaparde 271142ee18feSAjit Khaparde static int bnxt_get_module_eeprom(struct net_device *dev, 271242ee18feSAjit Khaparde struct ethtool_eeprom *eeprom, 271342ee18feSAjit Khaparde u8 *data) 271442ee18feSAjit Khaparde { 271542ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 271642ee18feSAjit Khaparde u16 start = eeprom->offset, length = eeprom->len; 2717f3ea3119SColin Ian King int rc = 0; 271842ee18feSAjit Khaparde 271942ee18feSAjit Khaparde memset(data, 0, eeprom->len); 272042ee18feSAjit Khaparde 272142ee18feSAjit Khaparde /* Read A0 portion of the EEPROM */ 272242ee18feSAjit Khaparde if (start < ETH_MODULE_SFF_8436_LEN) { 272342ee18feSAjit Khaparde if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN) 272442ee18feSAjit Khaparde length = ETH_MODULE_SFF_8436_LEN - start; 272542ee18feSAjit Khaparde rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 272642ee18feSAjit Khaparde start, length, data); 272742ee18feSAjit Khaparde if (rc) 272842ee18feSAjit Khaparde return rc; 272942ee18feSAjit Khaparde start += length; 273042ee18feSAjit Khaparde data += length; 273142ee18feSAjit Khaparde length = eeprom->len - length; 273242ee18feSAjit Khaparde } 273342ee18feSAjit Khaparde 273442ee18feSAjit Khaparde /* Read A2 portion of the EEPROM */ 273542ee18feSAjit Khaparde if (length) { 273642ee18feSAjit Khaparde start -= ETH_MODULE_SFF_8436_LEN; 2737dea521a2SChristophe JAILLET rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1, 2738dea521a2SChristophe JAILLET start, length, data); 273942ee18feSAjit Khaparde } 274042ee18feSAjit Khaparde return rc; 274142ee18feSAjit Khaparde } 274242ee18feSAjit Khaparde 2743ae8e98a6SDeepak Khungar static int bnxt_nway_reset(struct net_device *dev) 2744ae8e98a6SDeepak Khungar { 2745ae8e98a6SDeepak Khungar int rc = 0; 2746ae8e98a6SDeepak Khungar 2747ae8e98a6SDeepak Khungar struct bnxt *bp = netdev_priv(dev); 2748ae8e98a6SDeepak Khungar struct bnxt_link_info *link_info = &bp->link_info; 2749ae8e98a6SDeepak Khungar 2750c7e457f4SMichael Chan if (!BNXT_PHY_CFG_ABLE(bp)) 2751ae8e98a6SDeepak Khungar return -EOPNOTSUPP; 2752ae8e98a6SDeepak Khungar 2753ae8e98a6SDeepak Khungar if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 2754ae8e98a6SDeepak Khungar return -EINVAL; 2755ae8e98a6SDeepak Khungar 2756ae8e98a6SDeepak Khungar if (netif_running(dev)) 2757ae8e98a6SDeepak Khungar rc = bnxt_hwrm_set_link_setting(bp, true, false); 2758ae8e98a6SDeepak Khungar 2759ae8e98a6SDeepak Khungar return rc; 2760ae8e98a6SDeepak Khungar } 2761ae8e98a6SDeepak Khungar 27625ad2cbeeSMichael Chan static int bnxt_set_phys_id(struct net_device *dev, 27635ad2cbeeSMichael Chan enum ethtool_phys_id_state state) 27645ad2cbeeSMichael Chan { 27655ad2cbeeSMichael Chan struct hwrm_port_led_cfg_input req = {0}; 27665ad2cbeeSMichael Chan struct bnxt *bp = netdev_priv(dev); 27675ad2cbeeSMichael Chan struct bnxt_pf_info *pf = &bp->pf; 27685ad2cbeeSMichael Chan struct bnxt_led_cfg *led_cfg; 27695ad2cbeeSMichael Chan u8 led_state; 27705ad2cbeeSMichael Chan __le16 duration; 27719f90445cSVasundhara Volam int i; 27725ad2cbeeSMichael Chan 27735ad2cbeeSMichael Chan if (!bp->num_leds || BNXT_VF(bp)) 27745ad2cbeeSMichael Chan return -EOPNOTSUPP; 27755ad2cbeeSMichael Chan 27765ad2cbeeSMichael Chan if (state == ETHTOOL_ID_ACTIVE) { 27775ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT; 27785ad2cbeeSMichael Chan duration = cpu_to_le16(500); 27795ad2cbeeSMichael Chan } else if (state == ETHTOOL_ID_INACTIVE) { 27805ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT; 27815ad2cbeeSMichael Chan duration = cpu_to_le16(0); 27825ad2cbeeSMichael Chan } else { 27835ad2cbeeSMichael Chan return -EINVAL; 27845ad2cbeeSMichael Chan } 27855ad2cbeeSMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1); 27865ad2cbeeSMichael Chan req.port_id = cpu_to_le16(pf->port_id); 27875ad2cbeeSMichael Chan req.num_leds = bp->num_leds; 27885ad2cbeeSMichael Chan led_cfg = (struct bnxt_led_cfg *)&req.led0_id; 27895ad2cbeeSMichael Chan for (i = 0; i < bp->num_leds; i++, led_cfg++) { 27905ad2cbeeSMichael Chan req.enables |= BNXT_LED_DFLT_ENABLES(i); 27915ad2cbeeSMichael Chan led_cfg->led_id = bp->leds[i].led_id; 27925ad2cbeeSMichael Chan led_cfg->led_state = led_state; 27935ad2cbeeSMichael Chan led_cfg->led_blink_on = duration; 27945ad2cbeeSMichael Chan led_cfg->led_blink_off = duration; 27955ad2cbeeSMichael Chan led_cfg->led_group_id = bp->leds[i].led_group_id; 27965ad2cbeeSMichael Chan } 27979f90445cSVasundhara Volam return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 27985ad2cbeeSMichael Chan } 27995ad2cbeeSMichael Chan 280067fea463SMichael Chan static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring) 280167fea463SMichael Chan { 280267fea463SMichael Chan struct hwrm_selftest_irq_input req = {0}; 280367fea463SMichael Chan 280467fea463SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1); 280567fea463SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 280667fea463SMichael Chan } 280767fea463SMichael Chan 280867fea463SMichael Chan static int bnxt_test_irq(struct bnxt *bp) 280967fea463SMichael Chan { 281067fea463SMichael Chan int i; 281167fea463SMichael Chan 281267fea463SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 281367fea463SMichael Chan u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id; 281467fea463SMichael Chan int rc; 281567fea463SMichael Chan 281667fea463SMichael Chan rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring); 281767fea463SMichael Chan if (rc) 281867fea463SMichael Chan return rc; 281967fea463SMichael Chan } 282067fea463SMichael Chan return 0; 282167fea463SMichael Chan } 282267fea463SMichael Chan 2823f7dc1ea6SMichael Chan static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable) 2824f7dc1ea6SMichael Chan { 2825f7dc1ea6SMichael Chan struct hwrm_port_mac_cfg_input req = {0}; 2826f7dc1ea6SMichael Chan 2827f7dc1ea6SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1); 2828f7dc1ea6SMichael Chan 2829f7dc1ea6SMichael Chan req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK); 2830f7dc1ea6SMichael Chan if (enable) 2831f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL; 2832f7dc1ea6SMichael Chan else 2833f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE; 2834f7dc1ea6SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2835f7dc1ea6SMichael Chan } 2836f7dc1ea6SMichael Chan 283756d37462SVasundhara Volam static int bnxt_query_force_speeds(struct bnxt *bp, u16 *force_speeds) 283856d37462SVasundhara Volam { 283956d37462SVasundhara Volam struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; 284056d37462SVasundhara Volam struct hwrm_port_phy_qcaps_input req = {0}; 284156d37462SVasundhara Volam int rc; 284256d37462SVasundhara Volam 284356d37462SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); 284456d37462SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 284556d37462SVasundhara Volam rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 284656d37462SVasundhara Volam if (!rc) 284756d37462SVasundhara Volam *force_speeds = le16_to_cpu(resp->supported_speeds_force_mode); 284856d37462SVasundhara Volam 284956d37462SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 285056d37462SVasundhara Volam return rc; 285156d37462SVasundhara Volam } 285256d37462SVasundhara Volam 285391725d89SMichael Chan static int bnxt_disable_an_for_lpbk(struct bnxt *bp, 285491725d89SMichael Chan struct hwrm_port_phy_cfg_input *req) 285591725d89SMichael Chan { 285691725d89SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 285756d37462SVasundhara Volam u16 fw_advertising; 285891725d89SMichael Chan u16 fw_speed; 285991725d89SMichael Chan int rc; 286091725d89SMichael Chan 28618a60efd1SMichael Chan if (!link_info->autoneg || 28628a60efd1SMichael Chan (bp->test_info->flags & BNXT_TEST_FL_AN_PHY_LPBK)) 286391725d89SMichael Chan return 0; 286491725d89SMichael Chan 286556d37462SVasundhara Volam rc = bnxt_query_force_speeds(bp, &fw_advertising); 286656d37462SVasundhara Volam if (rc) 286756d37462SVasundhara Volam return rc; 286856d37462SVasundhara Volam 286991725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB; 287083d8f5e9SMichael Chan if (bp->link_info.link_up) 287191725d89SMichael Chan fw_speed = bp->link_info.link_speed; 287291725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB) 287391725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB; 287491725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB) 287591725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB; 287691725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB) 287791725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB; 287891725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB) 287991725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB; 288091725d89SMichael Chan 288191725d89SMichael Chan req->force_link_speed = cpu_to_le16(fw_speed); 288291725d89SMichael Chan req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE | 288391725d89SMichael Chan PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); 288491725d89SMichael Chan rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT); 288591725d89SMichael Chan req->flags = 0; 288691725d89SMichael Chan req->force_link_speed = cpu_to_le16(0); 288791725d89SMichael Chan return rc; 288891725d89SMichael Chan } 288991725d89SMichael Chan 289055fd0cf3SMichael Chan static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable, bool ext) 289191725d89SMichael Chan { 289291725d89SMichael Chan struct hwrm_port_phy_cfg_input req = {0}; 289391725d89SMichael Chan 289491725d89SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); 289591725d89SMichael Chan 289691725d89SMichael Chan if (enable) { 289791725d89SMichael Chan bnxt_disable_an_for_lpbk(bp, &req); 289855fd0cf3SMichael Chan if (ext) 289955fd0cf3SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_EXTERNAL; 290055fd0cf3SMichael Chan else 290191725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL; 290291725d89SMichael Chan } else { 290391725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE; 290491725d89SMichael Chan } 290591725d89SMichael Chan req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK); 290691725d89SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 290791725d89SMichael Chan } 290891725d89SMichael Chan 2909e44758b7SMichael Chan static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2910f7dc1ea6SMichael Chan u32 raw_cons, int pkt_size) 2911f7dc1ea6SMichael Chan { 2912e44758b7SMichael Chan struct bnxt_napi *bnapi = cpr->bnapi; 2913e44758b7SMichael Chan struct bnxt_rx_ring_info *rxr; 2914f7dc1ea6SMichael Chan struct bnxt_sw_rx_bd *rx_buf; 2915f7dc1ea6SMichael Chan struct rx_cmp *rxcmp; 2916f7dc1ea6SMichael Chan u16 cp_cons, cons; 2917f7dc1ea6SMichael Chan u8 *data; 2918f7dc1ea6SMichael Chan u32 len; 2919f7dc1ea6SMichael Chan int i; 2920f7dc1ea6SMichael Chan 2921e44758b7SMichael Chan rxr = bnapi->rx_ring; 2922f7dc1ea6SMichael Chan cp_cons = RING_CMP(raw_cons); 2923f7dc1ea6SMichael Chan rxcmp = (struct rx_cmp *) 2924f7dc1ea6SMichael Chan &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; 2925f7dc1ea6SMichael Chan cons = rxcmp->rx_cmp_opaque; 2926f7dc1ea6SMichael Chan rx_buf = &rxr->rx_buf_ring[cons]; 2927f7dc1ea6SMichael Chan data = rx_buf->data_ptr; 2928f7dc1ea6SMichael Chan len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT; 2929f7dc1ea6SMichael Chan if (len != pkt_size) 2930f7dc1ea6SMichael Chan return -EIO; 2931f7dc1ea6SMichael Chan i = ETH_ALEN; 2932f7dc1ea6SMichael Chan if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr)) 2933f7dc1ea6SMichael Chan return -EIO; 2934f7dc1ea6SMichael Chan i += ETH_ALEN; 2935f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) { 2936f7dc1ea6SMichael Chan if (data[i] != (u8)(i & 0xff)) 2937f7dc1ea6SMichael Chan return -EIO; 2938f7dc1ea6SMichael Chan } 2939f7dc1ea6SMichael Chan return 0; 2940f7dc1ea6SMichael Chan } 2941f7dc1ea6SMichael Chan 2942e44758b7SMichael Chan static int bnxt_poll_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2943e44758b7SMichael Chan int pkt_size) 2944f7dc1ea6SMichael Chan { 2945f7dc1ea6SMichael Chan struct tx_cmp *txcmp; 2946f7dc1ea6SMichael Chan int rc = -EIO; 2947f7dc1ea6SMichael Chan u32 raw_cons; 2948f7dc1ea6SMichael Chan u32 cons; 2949f7dc1ea6SMichael Chan int i; 2950f7dc1ea6SMichael Chan 2951f7dc1ea6SMichael Chan raw_cons = cpr->cp_raw_cons; 2952f7dc1ea6SMichael Chan for (i = 0; i < 200; i++) { 2953f7dc1ea6SMichael Chan cons = RING_CMP(raw_cons); 2954f7dc1ea6SMichael Chan txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; 2955f7dc1ea6SMichael Chan 2956f7dc1ea6SMichael Chan if (!TX_CMP_VALID(txcmp, raw_cons)) { 2957f7dc1ea6SMichael Chan udelay(5); 2958f7dc1ea6SMichael Chan continue; 2959f7dc1ea6SMichael Chan } 2960f7dc1ea6SMichael Chan 2961f7dc1ea6SMichael Chan /* The valid test of the entry must be done first before 2962f7dc1ea6SMichael Chan * reading any further. 2963f7dc1ea6SMichael Chan */ 2964f7dc1ea6SMichael Chan dma_rmb(); 2965f7dc1ea6SMichael Chan if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) { 2966e44758b7SMichael Chan rc = bnxt_rx_loopback(bp, cpr, raw_cons, pkt_size); 2967f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2968f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2969f7dc1ea6SMichael Chan break; 2970f7dc1ea6SMichael Chan } 2971f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2972f7dc1ea6SMichael Chan } 2973f7dc1ea6SMichael Chan cpr->cp_raw_cons = raw_cons; 2974f7dc1ea6SMichael Chan return rc; 2975f7dc1ea6SMichael Chan } 2976f7dc1ea6SMichael Chan 2977f7dc1ea6SMichael Chan static int bnxt_run_loopback(struct bnxt *bp) 2978f7dc1ea6SMichael Chan { 2979f7dc1ea6SMichael Chan struct bnxt_tx_ring_info *txr = &bp->tx_ring[0]; 298084404d5fSMichael Chan struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0]; 2981e44758b7SMichael Chan struct bnxt_cp_ring_info *cpr; 2982f7dc1ea6SMichael Chan int pkt_size, i = 0; 2983f7dc1ea6SMichael Chan struct sk_buff *skb; 2984f7dc1ea6SMichael Chan dma_addr_t map; 2985f7dc1ea6SMichael Chan u8 *data; 2986f7dc1ea6SMichael Chan int rc; 2987f7dc1ea6SMichael Chan 298884404d5fSMichael Chan cpr = &rxr->bnapi->cp_ring; 298984404d5fSMichael Chan if (bp->flags & BNXT_FLAG_CHIP_P5) 299084404d5fSMichael Chan cpr = cpr->cp_ring_arr[BNXT_RX_HDL]; 2991f7dc1ea6SMichael Chan pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh); 2992f7dc1ea6SMichael Chan skb = netdev_alloc_skb(bp->dev, pkt_size); 2993f7dc1ea6SMichael Chan if (!skb) 2994f7dc1ea6SMichael Chan return -ENOMEM; 2995f7dc1ea6SMichael Chan data = skb_put(skb, pkt_size); 2996f7dc1ea6SMichael Chan eth_broadcast_addr(data); 2997f7dc1ea6SMichael Chan i += ETH_ALEN; 2998f7dc1ea6SMichael Chan ether_addr_copy(&data[i], bp->dev->dev_addr); 2999f7dc1ea6SMichael Chan i += ETH_ALEN; 3000f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) 3001f7dc1ea6SMichael Chan data[i] = (u8)(i & 0xff); 3002f7dc1ea6SMichael Chan 3003f7dc1ea6SMichael Chan map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size, 3004f7dc1ea6SMichael Chan PCI_DMA_TODEVICE); 3005f7dc1ea6SMichael Chan if (dma_mapping_error(&bp->pdev->dev, map)) { 3006f7dc1ea6SMichael Chan dev_kfree_skb(skb); 3007f7dc1ea6SMichael Chan return -EIO; 3008f7dc1ea6SMichael Chan } 3009c1ba92a8SMichael Chan bnxt_xmit_bd(bp, txr, map, pkt_size); 3010f7dc1ea6SMichael Chan 3011f7dc1ea6SMichael Chan /* Sync BD data before updating doorbell */ 3012f7dc1ea6SMichael Chan wmb(); 3013f7dc1ea6SMichael Chan 3014697197e5SMichael Chan bnxt_db_write(bp, &txr->tx_db, txr->tx_prod); 3015e44758b7SMichael Chan rc = bnxt_poll_loopback(bp, cpr, pkt_size); 3016f7dc1ea6SMichael Chan 3017f7dc1ea6SMichael Chan dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE); 3018f7dc1ea6SMichael Chan dev_kfree_skb(skb); 3019f7dc1ea6SMichael Chan return rc; 3020f7dc1ea6SMichael Chan } 3021f7dc1ea6SMichael Chan 3022eb513658SMichael Chan static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results) 3023eb513658SMichael Chan { 3024eb513658SMichael Chan struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr; 3025eb513658SMichael Chan struct hwrm_selftest_exec_input req = {0}; 3026eb513658SMichael Chan int rc; 3027eb513658SMichael Chan 3028eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1); 3029eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 3030eb513658SMichael Chan resp->test_success = 0; 3031eb513658SMichael Chan req.flags = test_mask; 3032eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout); 3033eb513658SMichael Chan *test_results = resp->test_success; 3034eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 3035eb513658SMichael Chan return rc; 3036eb513658SMichael Chan } 3037eb513658SMichael Chan 303855fd0cf3SMichael Chan #define BNXT_DRV_TESTS 4 3039f7dc1ea6SMichael Chan #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS) 304091725d89SMichael Chan #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1) 304155fd0cf3SMichael Chan #define BNXT_EXTLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2) 304255fd0cf3SMichael Chan #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 3) 3043eb513658SMichael Chan 3044eb513658SMichael Chan static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest, 3045eb513658SMichael Chan u64 *buf) 3046eb513658SMichael Chan { 3047eb513658SMichael Chan struct bnxt *bp = netdev_priv(dev); 304855fd0cf3SMichael Chan bool do_ext_lpbk = false; 3049eb513658SMichael Chan bool offline = false; 3050eb513658SMichael Chan u8 test_results = 0; 3051eb513658SMichael Chan u8 test_mask = 0; 3052d27e2ca1SMichael Chan int rc = 0, i; 3053eb513658SMichael Chan 3054eb513658SMichael Chan if (!bp->num_tests || !BNXT_SINGLE_PF(bp)) 3055eb513658SMichael Chan return; 3056eb513658SMichael Chan memset(buf, 0, sizeof(u64) * bp->num_tests); 3057eb513658SMichael Chan if (!netif_running(dev)) { 3058eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3059eb513658SMichael Chan return; 3060eb513658SMichael Chan } 3061eb513658SMichael Chan 306255fd0cf3SMichael Chan if ((etest->flags & ETH_TEST_FL_EXTERNAL_LB) && 306355fd0cf3SMichael Chan (bp->test_info->flags & BNXT_TEST_FL_EXT_LPBK)) 306455fd0cf3SMichael Chan do_ext_lpbk = true; 306555fd0cf3SMichael Chan 3066eb513658SMichael Chan if (etest->flags & ETH_TEST_FL_OFFLINE) { 3067eb513658SMichael Chan if (bp->pf.active_vfs) { 3068eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3069eb513658SMichael Chan netdev_warn(dev, "Offline tests cannot be run with active VFs\n"); 3070eb513658SMichael Chan return; 3071eb513658SMichael Chan } 3072eb513658SMichael Chan offline = true; 3073eb513658SMichael Chan } 3074eb513658SMichael Chan 3075eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 3076eb513658SMichael Chan u8 bit_val = 1 << i; 3077eb513658SMichael Chan 3078eb513658SMichael Chan if (!(bp->test_info->offline_mask & bit_val)) 3079eb513658SMichael Chan test_mask |= bit_val; 3080eb513658SMichael Chan else if (offline) 3081eb513658SMichael Chan test_mask |= bit_val; 3082eb513658SMichael Chan } 3083eb513658SMichael Chan if (!offline) { 3084eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 3085eb513658SMichael Chan } else { 3086eb513658SMichael Chan rc = bnxt_close_nic(bp, false, false); 3087eb513658SMichael Chan if (rc) 3088eb513658SMichael Chan return; 3089eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 3090f7dc1ea6SMichael Chan 3091f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 1; 3092f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, true); 3093f7dc1ea6SMichael Chan msleep(250); 3094f7dc1ea6SMichael Chan rc = bnxt_half_open_nic(bp); 3095f7dc1ea6SMichael Chan if (rc) { 3096f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 3097f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3098f7dc1ea6SMichael Chan return; 3099f7dc1ea6SMichael Chan } 3100f7dc1ea6SMichael Chan if (bnxt_run_loopback(bp)) 3101f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3102f7dc1ea6SMichael Chan else 3103f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 0; 3104f7dc1ea6SMichael Chan 3105f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 310655fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, false); 310791725d89SMichael Chan msleep(1000); 310891725d89SMichael Chan if (bnxt_run_loopback(bp)) { 310991725d89SMichael Chan buf[BNXT_PHYLPBK_TEST_IDX] = 1; 311091725d89SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 311191725d89SMichael Chan } 311255fd0cf3SMichael Chan if (do_ext_lpbk) { 311355fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; 311455fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, true); 311555fd0cf3SMichael Chan msleep(1000); 311655fd0cf3SMichael Chan if (bnxt_run_loopback(bp)) { 311755fd0cf3SMichael Chan buf[BNXT_EXTLPBK_TEST_IDX] = 1; 311855fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 311955fd0cf3SMichael Chan } 312055fd0cf3SMichael Chan } 312155fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, false, false); 312291725d89SMichael Chan bnxt_half_close_nic(bp); 3123d27e2ca1SMichael Chan rc = bnxt_open_nic(bp, false, true); 3124eb513658SMichael Chan } 3125d27e2ca1SMichael Chan if (rc || bnxt_test_irq(bp)) { 312667fea463SMichael Chan buf[BNXT_IRQ_TEST_IDX] = 1; 312767fea463SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 312867fea463SMichael Chan } 3129eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 3130eb513658SMichael Chan u8 bit_val = 1 << i; 3131eb513658SMichael Chan 3132eb513658SMichael Chan if ((test_mask & bit_val) && !(test_results & bit_val)) { 3133eb513658SMichael Chan buf[i] = 1; 3134eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 3135eb513658SMichael Chan } 3136eb513658SMichael Chan } 3137eb513658SMichael Chan } 3138eb513658SMichael Chan 313949f7972fSVasundhara Volam static int bnxt_reset(struct net_device *dev, u32 *flags) 314049f7972fSVasundhara Volam { 314149f7972fSVasundhara Volam struct bnxt *bp = netdev_priv(dev); 31428cec0940SEdwin Peer bool reload = false; 31437a13240eSEdwin Peer u32 req = *flags; 31447a13240eSEdwin Peer 31457a13240eSEdwin Peer if (!req) 31467a13240eSEdwin Peer return -EINVAL; 314749f7972fSVasundhara Volam 314849f7972fSVasundhara Volam if (!BNXT_PF(bp)) { 314949f7972fSVasundhara Volam netdev_err(dev, "Reset is not supported from a VF\n"); 315049f7972fSVasundhara Volam return -EOPNOTSUPP; 315149f7972fSVasundhara Volam } 315249f7972fSVasundhara Volam 31530a3f4e4fSVasundhara Volam if (pci_vfs_assigned(bp->pdev) && 31540a3f4e4fSVasundhara Volam !(bp->fw_cap & BNXT_FW_CAP_HOT_RESET)) { 315549f7972fSVasundhara Volam netdev_err(dev, 315649f7972fSVasundhara Volam "Reset not allowed when VFs are assigned to VMs\n"); 315749f7972fSVasundhara Volam return -EBUSY; 315849f7972fSVasundhara Volam } 315949f7972fSVasundhara Volam 31607a13240eSEdwin Peer if ((req & BNXT_FW_RESET_CHIP) == BNXT_FW_RESET_CHIP) { 316149f7972fSVasundhara Volam /* This feature is not supported in older firmware versions */ 31627a13240eSEdwin Peer if (bp->hwrm_spec_code >= 0x10803) { 31637a13240eSEdwin Peer if (!bnxt_firmware_reset_chip(dev)) { 31647a13240eSEdwin Peer netdev_info(dev, "Firmware reset request successful.\n"); 31650a3f4e4fSVasundhara Volam if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET)) 31668cec0940SEdwin Peer reload = true; 31677a13240eSEdwin Peer *flags &= ~BNXT_FW_RESET_CHIP; 31682373d8d6SScott Branden } 31697a13240eSEdwin Peer } else if (req == BNXT_FW_RESET_CHIP) { 31707a13240eSEdwin Peer return -EOPNOTSUPP; /* only request, fail hard */ 31717a13240eSEdwin Peer } 31727a13240eSEdwin Peer } 31737a13240eSEdwin Peer 31747a13240eSEdwin Peer if (req & BNXT_FW_RESET_AP) { 31756502ad59SScott Branden /* This feature is not supported in older firmware versions */ 31767a13240eSEdwin Peer if (bp->hwrm_spec_code >= 0x10803) { 31777a13240eSEdwin Peer if (!bnxt_firmware_reset_ap(dev)) { 31787a13240eSEdwin Peer netdev_info(dev, "Reset application processor successful.\n"); 31798cec0940SEdwin Peer reload = true; 31807a13240eSEdwin Peer *flags &= ~BNXT_FW_RESET_AP; 31812373d8d6SScott Branden } 31827a13240eSEdwin Peer } else if (req == BNXT_FW_RESET_AP) { 31837a13240eSEdwin Peer return -EOPNOTSUPP; /* only request, fail hard */ 31847a13240eSEdwin Peer } 318549f7972fSVasundhara Volam } 318649f7972fSVasundhara Volam 31878cec0940SEdwin Peer if (reload) 31888cec0940SEdwin Peer netdev_info(dev, "Reload driver to complete reset\n"); 31898cec0940SEdwin Peer 31907a13240eSEdwin Peer return 0; 319149f7972fSVasundhara Volam } 319249f7972fSVasundhara Volam 31936c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg, int msg_len, 31946c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info *info) 31956c5657d0SVasundhara Volam { 31966c5657d0SVasundhara Volam struct hwrm_dbg_cmn_output *cmn_resp = bp->hwrm_cmd_resp_addr; 31976c5657d0SVasundhara Volam struct hwrm_dbg_cmn_input *cmn_req = msg; 31986c5657d0SVasundhara Volam __le16 *seq_ptr = msg + info->seq_off; 31996c5657d0SVasundhara Volam u16 seq = 0, len, segs_off; 32006c5657d0SVasundhara Volam void *resp = cmn_resp; 32016c5657d0SVasundhara Volam dma_addr_t dma_handle; 32026c5657d0SVasundhara Volam int rc, off = 0; 32036c5657d0SVasundhara Volam void *dma_buf; 32046c5657d0SVasundhara Volam 32056c5657d0SVasundhara Volam dma_buf = dma_alloc_coherent(&bp->pdev->dev, info->dma_len, &dma_handle, 32066c5657d0SVasundhara Volam GFP_KERNEL); 32076c5657d0SVasundhara Volam if (!dma_buf) 32086c5657d0SVasundhara Volam return -ENOMEM; 32096c5657d0SVasundhara Volam 32106c5657d0SVasundhara Volam segs_off = offsetof(struct hwrm_dbg_coredump_list_output, 32116c5657d0SVasundhara Volam total_segments); 32126c5657d0SVasundhara Volam cmn_req->host_dest_addr = cpu_to_le64(dma_handle); 32136c5657d0SVasundhara Volam cmn_req->host_buf_len = cpu_to_le32(info->dma_len); 32146c5657d0SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 32156c5657d0SVasundhara Volam while (1) { 32166c5657d0SVasundhara Volam *seq_ptr = cpu_to_le16(seq); 32175b306bdeSVasundhara Volam rc = _hwrm_send_message(bp, msg, msg_len, 32185b306bdeSVasundhara Volam HWRM_COREDUMP_TIMEOUT); 32196c5657d0SVasundhara Volam if (rc) 32206c5657d0SVasundhara Volam break; 32216c5657d0SVasundhara Volam 32226c5657d0SVasundhara Volam len = le16_to_cpu(*((__le16 *)(resp + info->data_len_off))); 32236c5657d0SVasundhara Volam if (!seq && 32246c5657d0SVasundhara Volam cmn_req->req_type == cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) { 32256c5657d0SVasundhara Volam info->segs = le16_to_cpu(*((__le16 *)(resp + 32266c5657d0SVasundhara Volam segs_off))); 32276c5657d0SVasundhara Volam if (!info->segs) { 32286c5657d0SVasundhara Volam rc = -EIO; 32296c5657d0SVasundhara Volam break; 32306c5657d0SVasundhara Volam } 32316c5657d0SVasundhara Volam 32326c5657d0SVasundhara Volam info->dest_buf_size = info->segs * 32336c5657d0SVasundhara Volam sizeof(struct coredump_segment_record); 32346c5657d0SVasundhara Volam info->dest_buf = kmalloc(info->dest_buf_size, 32356c5657d0SVasundhara Volam GFP_KERNEL); 32366c5657d0SVasundhara Volam if (!info->dest_buf) { 32376c5657d0SVasundhara Volam rc = -ENOMEM; 32386c5657d0SVasundhara Volam break; 32396c5657d0SVasundhara Volam } 32406c5657d0SVasundhara Volam } 32416c5657d0SVasundhara Volam 3242c74751f4SVasundhara Volam if (info->dest_buf) { 3243c74751f4SVasundhara Volam if ((info->seg_start + off + len) <= 3244c74751f4SVasundhara Volam BNXT_COREDUMP_BUF_LEN(info->buf_len)) { 32456c5657d0SVasundhara Volam memcpy(info->dest_buf + off, dma_buf, len); 3246c74751f4SVasundhara Volam } else { 3247c74751f4SVasundhara Volam rc = -ENOBUFS; 3248c74751f4SVasundhara Volam break; 3249c74751f4SVasundhara Volam } 3250c74751f4SVasundhara Volam } 32516c5657d0SVasundhara Volam 32526c5657d0SVasundhara Volam if (cmn_req->req_type == 32536c5657d0SVasundhara Volam cpu_to_le16(HWRM_DBG_COREDUMP_RETRIEVE)) 32546c5657d0SVasundhara Volam info->dest_buf_size += len; 32556c5657d0SVasundhara Volam 32566c5657d0SVasundhara Volam if (!(cmn_resp->flags & HWRM_DBG_CMN_FLAGS_MORE)) 32576c5657d0SVasundhara Volam break; 32586c5657d0SVasundhara Volam 32596c5657d0SVasundhara Volam seq++; 32606c5657d0SVasundhara Volam off += len; 32616c5657d0SVasundhara Volam } 32626c5657d0SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 32636c5657d0SVasundhara Volam dma_free_coherent(&bp->pdev->dev, info->dma_len, dma_buf, dma_handle); 32646c5657d0SVasundhara Volam return rc; 32656c5657d0SVasundhara Volam } 32666c5657d0SVasundhara Volam 32676c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_list(struct bnxt *bp, 32686c5657d0SVasundhara Volam struct bnxt_coredump *coredump) 32696c5657d0SVasundhara Volam { 32706c5657d0SVasundhara Volam struct hwrm_dbg_coredump_list_input req = {0}; 32716c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 32726c5657d0SVasundhara Volam int rc; 32736c5657d0SVasundhara Volam 32746c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_LIST, -1, -1); 32756c5657d0SVasundhara Volam 32766c5657d0SVasundhara Volam info.dma_len = COREDUMP_LIST_BUF_LEN; 32776c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_list_input, seq_no); 32786c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_list_output, 32796c5657d0SVasundhara Volam data_len); 32806c5657d0SVasundhara Volam 32816c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 32826c5657d0SVasundhara Volam if (!rc) { 32836c5657d0SVasundhara Volam coredump->data = info.dest_buf; 32846c5657d0SVasundhara Volam coredump->data_size = info.dest_buf_size; 32856c5657d0SVasundhara Volam coredump->total_segs = info.segs; 32866c5657d0SVasundhara Volam } 32876c5657d0SVasundhara Volam return rc; 32886c5657d0SVasundhara Volam } 32896c5657d0SVasundhara Volam 32906c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_initiate(struct bnxt *bp, u16 component_id, 32916c5657d0SVasundhara Volam u16 segment_id) 32926c5657d0SVasundhara Volam { 32936c5657d0SVasundhara Volam struct hwrm_dbg_coredump_initiate_input req = {0}; 32946c5657d0SVasundhara Volam 32956c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_INITIATE, -1, -1); 32966c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 32976c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 32986c5657d0SVasundhara Volam 329957a8730bSVasundhara Volam return hwrm_send_message(bp, &req, sizeof(req), HWRM_COREDUMP_TIMEOUT); 33006c5657d0SVasundhara Volam } 33016c5657d0SVasundhara Volam 33026c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_retrieve(struct bnxt *bp, u16 component_id, 33036c5657d0SVasundhara Volam u16 segment_id, u32 *seg_len, 3304c74751f4SVasundhara Volam void *buf, u32 buf_len, u32 offset) 33056c5657d0SVasundhara Volam { 33066c5657d0SVasundhara Volam struct hwrm_dbg_coredump_retrieve_input req = {0}; 33076c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 33086c5657d0SVasundhara Volam int rc; 33096c5657d0SVasundhara Volam 33106c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_RETRIEVE, -1, -1); 33116c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 33126c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 33136c5657d0SVasundhara Volam 33146c5657d0SVasundhara Volam info.dma_len = COREDUMP_RETRIEVE_BUF_LEN; 33156c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_retrieve_input, 33166c5657d0SVasundhara Volam seq_no); 33176c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_retrieve_output, 33186c5657d0SVasundhara Volam data_len); 3319c74751f4SVasundhara Volam if (buf) { 33206c5657d0SVasundhara Volam info.dest_buf = buf + offset; 3321c74751f4SVasundhara Volam info.buf_len = buf_len; 3322c74751f4SVasundhara Volam info.seg_start = offset; 3323c74751f4SVasundhara Volam } 33246c5657d0SVasundhara Volam 33256c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 33266c5657d0SVasundhara Volam if (!rc) 33276c5657d0SVasundhara Volam *seg_len = info.dest_buf_size; 33286c5657d0SVasundhara Volam 33296c5657d0SVasundhara Volam return rc; 33306c5657d0SVasundhara Volam } 33316c5657d0SVasundhara Volam 33326c5657d0SVasundhara Volam static void 33336c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(struct bnxt *bp, 33346c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr *seg_hdr, 33356c5657d0SVasundhara Volam struct coredump_segment_record *seg_rec, u32 seg_len, 33366c5657d0SVasundhara Volam int status, u32 duration, u32 instance) 33376c5657d0SVasundhara Volam { 33386c5657d0SVasundhara Volam memset(seg_hdr, 0, sizeof(*seg_hdr)); 33398605212aSVasundhara Volam memcpy(seg_hdr->signature, "sEgM", 4); 33406c5657d0SVasundhara Volam if (seg_rec) { 33416c5657d0SVasundhara Volam seg_hdr->component_id = (__force __le32)seg_rec->component_id; 33426c5657d0SVasundhara Volam seg_hdr->segment_id = (__force __le32)seg_rec->segment_id; 33436c5657d0SVasundhara Volam seg_hdr->low_version = seg_rec->version_low; 33446c5657d0SVasundhara Volam seg_hdr->high_version = seg_rec->version_hi; 33456c5657d0SVasundhara Volam } else { 33466c5657d0SVasundhara Volam /* For hwrm_ver_get response Component id = 2 33476c5657d0SVasundhara Volam * and Segment id = 0 33486c5657d0SVasundhara Volam */ 33496c5657d0SVasundhara Volam seg_hdr->component_id = cpu_to_le32(2); 33506c5657d0SVasundhara Volam seg_hdr->segment_id = 0; 33516c5657d0SVasundhara Volam } 33526c5657d0SVasundhara Volam seg_hdr->function_id = cpu_to_le16(bp->pdev->devfn); 33536c5657d0SVasundhara Volam seg_hdr->length = cpu_to_le32(seg_len); 33546c5657d0SVasundhara Volam seg_hdr->status = cpu_to_le32(status); 33556c5657d0SVasundhara Volam seg_hdr->duration = cpu_to_le32(duration); 33566c5657d0SVasundhara Volam seg_hdr->data_offset = cpu_to_le32(sizeof(*seg_hdr)); 33576c5657d0SVasundhara Volam seg_hdr->instance = cpu_to_le32(instance); 33586c5657d0SVasundhara Volam } 33596c5657d0SVasundhara Volam 33606c5657d0SVasundhara Volam static void 33616c5657d0SVasundhara Volam bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record, 33626c5657d0SVasundhara Volam time64_t start, s16 start_utc, u16 total_segs, 33636c5657d0SVasundhara Volam int status) 33646c5657d0SVasundhara Volam { 33656c5657d0SVasundhara Volam time64_t end = ktime_get_real_seconds(); 33666c5657d0SVasundhara Volam u32 os_ver_major = 0, os_ver_minor = 0; 33676c5657d0SVasundhara Volam struct tm tm; 33686c5657d0SVasundhara Volam 33696c5657d0SVasundhara Volam time64_to_tm(start, 0, &tm); 33706c5657d0SVasundhara Volam memset(record, 0, sizeof(*record)); 33718605212aSVasundhara Volam memcpy(record->signature, "cOrE", 4); 33726c5657d0SVasundhara Volam record->flags = 0; 33736c5657d0SVasundhara Volam record->low_version = 0; 33746c5657d0SVasundhara Volam record->high_version = 1; 33756c5657d0SVasundhara Volam record->asic_state = 0; 33763d46eee5SArnd Bergmann strlcpy(record->system_name, utsname()->nodename, 33773d46eee5SArnd Bergmann sizeof(record->system_name)); 33788dc5ae2dSVasundhara Volam record->year = cpu_to_le16(tm.tm_year + 1900); 33798dc5ae2dSVasundhara Volam record->month = cpu_to_le16(tm.tm_mon + 1); 33806c5657d0SVasundhara Volam record->day = cpu_to_le16(tm.tm_mday); 33816c5657d0SVasundhara Volam record->hour = cpu_to_le16(tm.tm_hour); 33826c5657d0SVasundhara Volam record->minute = cpu_to_le16(tm.tm_min); 33836c5657d0SVasundhara Volam record->second = cpu_to_le16(tm.tm_sec); 33846c5657d0SVasundhara Volam record->utc_bias = cpu_to_le16(start_utc); 33856c5657d0SVasundhara Volam strcpy(record->commandline, "ethtool -w"); 33866c5657d0SVasundhara Volam record->total_segments = cpu_to_le32(total_segs); 33876c5657d0SVasundhara Volam 33886c5657d0SVasundhara Volam sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor); 33896c5657d0SVasundhara Volam record->os_ver_major = cpu_to_le32(os_ver_major); 33906c5657d0SVasundhara Volam record->os_ver_minor = cpu_to_le32(os_ver_minor); 33916c5657d0SVasundhara Volam 33928605212aSVasundhara Volam strlcpy(record->os_name, utsname()->sysname, 32); 33936c5657d0SVasundhara Volam time64_to_tm(end, 0, &tm); 33946c5657d0SVasundhara Volam record->end_year = cpu_to_le16(tm.tm_year + 1900); 33956c5657d0SVasundhara Volam record->end_month = cpu_to_le16(tm.tm_mon + 1); 33966c5657d0SVasundhara Volam record->end_day = cpu_to_le16(tm.tm_mday); 33976c5657d0SVasundhara Volam record->end_hour = cpu_to_le16(tm.tm_hour); 33986c5657d0SVasundhara Volam record->end_minute = cpu_to_le16(tm.tm_min); 33996c5657d0SVasundhara Volam record->end_second = cpu_to_le16(tm.tm_sec); 34006c5657d0SVasundhara Volam record->end_utc_bias = cpu_to_le16(sys_tz.tz_minuteswest * 60); 34016c5657d0SVasundhara Volam record->asic_id1 = cpu_to_le32(bp->chip_num << 16 | 34026c5657d0SVasundhara Volam bp->ver_resp.chip_rev << 8 | 34036c5657d0SVasundhara Volam bp->ver_resp.chip_metal); 34046c5657d0SVasundhara Volam record->asic_id2 = 0; 34056c5657d0SVasundhara Volam record->coredump_status = cpu_to_le32(status); 34066c5657d0SVasundhara Volam record->ioctl_low_version = 0; 34076c5657d0SVasundhara Volam record->ioctl_high_version = 0; 34086c5657d0SVasundhara Volam } 34096c5657d0SVasundhara Volam 34106c5657d0SVasundhara Volam static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len) 34116c5657d0SVasundhara Volam { 34126c5657d0SVasundhara Volam u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output); 3413c74751f4SVasundhara Volam u32 offset = 0, seg_hdr_len, seg_record_len, buf_len = 0; 34146c5657d0SVasundhara Volam struct coredump_segment_record *seg_record = NULL; 34156c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr seg_hdr; 34166c5657d0SVasundhara Volam struct bnxt_coredump coredump = {NULL}; 34176c5657d0SVasundhara Volam time64_t start_time; 34186c5657d0SVasundhara Volam u16 start_utc; 34196c5657d0SVasundhara Volam int rc = 0, i; 34206c5657d0SVasundhara Volam 3421c74751f4SVasundhara Volam if (buf) 3422c74751f4SVasundhara Volam buf_len = *dump_len; 3423c74751f4SVasundhara Volam 34246c5657d0SVasundhara Volam start_time = ktime_get_real_seconds(); 34256c5657d0SVasundhara Volam start_utc = sys_tz.tz_minuteswest * 60; 34266c5657d0SVasundhara Volam seg_hdr_len = sizeof(seg_hdr); 34276c5657d0SVasundhara Volam 34286c5657d0SVasundhara Volam /* First segment should be hwrm_ver_get response */ 34296c5657d0SVasundhara Volam *dump_len = seg_hdr_len + ver_get_resp_len; 34306c5657d0SVasundhara Volam if (buf) { 34316c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, NULL, ver_get_resp_len, 34326c5657d0SVasundhara Volam 0, 0, 0); 34336c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 34346c5657d0SVasundhara Volam offset += seg_hdr_len; 34356c5657d0SVasundhara Volam memcpy(buf + offset, &bp->ver_resp, ver_get_resp_len); 34366c5657d0SVasundhara Volam offset += ver_get_resp_len; 34376c5657d0SVasundhara Volam } 34386c5657d0SVasundhara Volam 34396c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_list(bp, &coredump); 34406c5657d0SVasundhara Volam if (rc) { 34416c5657d0SVasundhara Volam netdev_err(bp->dev, "Failed to get coredump segment list\n"); 34426c5657d0SVasundhara Volam goto err; 34436c5657d0SVasundhara Volam } 34446c5657d0SVasundhara Volam 34456c5657d0SVasundhara Volam *dump_len += seg_hdr_len * coredump.total_segs; 34466c5657d0SVasundhara Volam 34476c5657d0SVasundhara Volam seg_record = (struct coredump_segment_record *)coredump.data; 34486c5657d0SVasundhara Volam seg_record_len = sizeof(*seg_record); 34496c5657d0SVasundhara Volam 34506c5657d0SVasundhara Volam for (i = 0; i < coredump.total_segs; i++) { 34516c5657d0SVasundhara Volam u16 comp_id = le16_to_cpu(seg_record->component_id); 34526c5657d0SVasundhara Volam u16 seg_id = le16_to_cpu(seg_record->segment_id); 34536c5657d0SVasundhara Volam u32 duration = 0, seg_len = 0; 34546c5657d0SVasundhara Volam unsigned long start, end; 34556c5657d0SVasundhara Volam 3456c74751f4SVasundhara Volam if (buf && ((offset + seg_hdr_len) > 3457c74751f4SVasundhara Volam BNXT_COREDUMP_BUF_LEN(buf_len))) { 3458c74751f4SVasundhara Volam rc = -ENOBUFS; 3459c74751f4SVasundhara Volam goto err; 3460c74751f4SVasundhara Volam } 3461c74751f4SVasundhara Volam 34626c5657d0SVasundhara Volam start = jiffies; 34636c5657d0SVasundhara Volam 34646c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_initiate(bp, comp_id, seg_id); 34656c5657d0SVasundhara Volam if (rc) { 34666c5657d0SVasundhara Volam netdev_err(bp->dev, 34676c5657d0SVasundhara Volam "Failed to initiate coredump for seg = %d\n", 34686c5657d0SVasundhara Volam seg_record->segment_id); 34696c5657d0SVasundhara Volam goto next_seg; 34706c5657d0SVasundhara Volam } 34716c5657d0SVasundhara Volam 34726c5657d0SVasundhara Volam /* Write segment data into the buffer */ 34736c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_retrieve(bp, comp_id, seg_id, 3474c74751f4SVasundhara Volam &seg_len, buf, buf_len, 34756c5657d0SVasundhara Volam offset + seg_hdr_len); 3476c74751f4SVasundhara Volam if (rc && rc == -ENOBUFS) 3477c74751f4SVasundhara Volam goto err; 3478c74751f4SVasundhara Volam else if (rc) 34796c5657d0SVasundhara Volam netdev_err(bp->dev, 34806c5657d0SVasundhara Volam "Failed to retrieve coredump for seg = %d\n", 34816c5657d0SVasundhara Volam seg_record->segment_id); 34826c5657d0SVasundhara Volam 34836c5657d0SVasundhara Volam next_seg: 34846c5657d0SVasundhara Volam end = jiffies; 34856c5657d0SVasundhara Volam duration = jiffies_to_msecs(end - start); 34866c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, seg_record, seg_len, 34876c5657d0SVasundhara Volam rc, duration, 0); 34886c5657d0SVasundhara Volam 34896c5657d0SVasundhara Volam if (buf) { 34906c5657d0SVasundhara Volam /* Write segment header into the buffer */ 34916c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 34926c5657d0SVasundhara Volam offset += seg_hdr_len + seg_len; 34936c5657d0SVasundhara Volam } 34946c5657d0SVasundhara Volam 34956c5657d0SVasundhara Volam *dump_len += seg_len; 34966c5657d0SVasundhara Volam seg_record = 34976c5657d0SVasundhara Volam (struct coredump_segment_record *)((u8 *)seg_record + 34986c5657d0SVasundhara Volam seg_record_len); 34996c5657d0SVasundhara Volam } 35006c5657d0SVasundhara Volam 35016c5657d0SVasundhara Volam err: 35021bbf3aedSArnd Bergmann if (buf) 35031bbf3aedSArnd Bergmann bnxt_fill_coredump_record(bp, buf + offset, start_time, 35046c5657d0SVasundhara Volam start_utc, coredump.total_segs + 1, 35056c5657d0SVasundhara Volam rc); 35066c5657d0SVasundhara Volam kfree(coredump.data); 35071bbf3aedSArnd Bergmann *dump_len += sizeof(struct bnxt_coredump_record); 3508c74751f4SVasundhara Volam if (rc == -ENOBUFS) 35099a005c38SJonathan Lemon netdev_err(bp->dev, "Firmware returned large coredump buffer\n"); 35106c5657d0SVasundhara Volam return rc; 35116c5657d0SVasundhara Volam } 35126c5657d0SVasundhara Volam 35130b0eacf3SVasundhara Volam static int bnxt_set_dump(struct net_device *dev, struct ethtool_dump *dump) 35140b0eacf3SVasundhara Volam { 35150b0eacf3SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 35160b0eacf3SVasundhara Volam 35170b0eacf3SVasundhara Volam if (dump->flag > BNXT_DUMP_CRASH) { 35180b0eacf3SVasundhara Volam netdev_info(dev, "Supports only Live(0) and Crash(1) dumps.\n"); 35190b0eacf3SVasundhara Volam return -EINVAL; 35200b0eacf3SVasundhara Volam } 35210b0eacf3SVasundhara Volam 35220b0eacf3SVasundhara Volam if (!IS_ENABLED(CONFIG_TEE_BNXT_FW) && dump->flag == BNXT_DUMP_CRASH) { 35230b0eacf3SVasundhara Volam netdev_info(dev, "Cannot collect crash dump as TEE_BNXT_FW config option is not enabled.\n"); 35240b0eacf3SVasundhara Volam return -EOPNOTSUPP; 35250b0eacf3SVasundhara Volam } 35260b0eacf3SVasundhara Volam 35270b0eacf3SVasundhara Volam bp->dump_flag = dump->flag; 35280b0eacf3SVasundhara Volam return 0; 35290b0eacf3SVasundhara Volam } 35300b0eacf3SVasundhara Volam 35316c5657d0SVasundhara Volam static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump) 35326c5657d0SVasundhara Volam { 35336c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 35346c5657d0SVasundhara Volam 35356c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 35366c5657d0SVasundhara Volam return -EOPNOTSUPP; 35376c5657d0SVasundhara Volam 35386c5657d0SVasundhara Volam dump->version = bp->ver_resp.hwrm_fw_maj_8b << 24 | 35396c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_min_8b << 16 | 35406c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_bld_8b << 8 | 35416c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_rsvd_8b; 35426c5657d0SVasundhara Volam 35430b0eacf3SVasundhara Volam dump->flag = bp->dump_flag; 35440b0eacf3SVasundhara Volam if (bp->dump_flag == BNXT_DUMP_CRASH) 35450b0eacf3SVasundhara Volam dump->len = BNXT_CRASH_DUMP_LEN; 35460b0eacf3SVasundhara Volam else 35470b0eacf3SVasundhara Volam bnxt_get_coredump(bp, NULL, &dump->len); 35480b0eacf3SVasundhara Volam return 0; 35496c5657d0SVasundhara Volam } 35506c5657d0SVasundhara Volam 35516c5657d0SVasundhara Volam static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump, 35526c5657d0SVasundhara Volam void *buf) 35536c5657d0SVasundhara Volam { 35546c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 35556c5657d0SVasundhara Volam 35566c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 35576c5657d0SVasundhara Volam return -EOPNOTSUPP; 35586c5657d0SVasundhara Volam 35596c5657d0SVasundhara Volam memset(buf, 0, dump->len); 35606c5657d0SVasundhara Volam 35610b0eacf3SVasundhara Volam dump->flag = bp->dump_flag; 35620b0eacf3SVasundhara Volam if (dump->flag == BNXT_DUMP_CRASH) { 35630b0eacf3SVasundhara Volam #ifdef CONFIG_TEE_BNXT_FW 35640b0eacf3SVasundhara Volam return tee_bnxt_copy_coredump(buf, 0, dump->len); 35650b0eacf3SVasundhara Volam #endif 35660b0eacf3SVasundhara Volam } else { 35676c5657d0SVasundhara Volam return bnxt_get_coredump(bp, buf, &dump->len); 35686c5657d0SVasundhara Volam } 35696c5657d0SVasundhara Volam 35700b0eacf3SVasundhara Volam return 0; 35710b0eacf3SVasundhara Volam } 35720b0eacf3SVasundhara Volam 3573eb513658SMichael Chan void bnxt_ethtool_init(struct bnxt *bp) 3574eb513658SMichael Chan { 3575eb513658SMichael Chan struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr; 3576eb513658SMichael Chan struct hwrm_selftest_qlist_input req = {0}; 3577eb513658SMichael Chan struct bnxt_test_info *test_info; 3578431aa1ebSMichael Chan struct net_device *dev = bp->dev; 3579eb513658SMichael Chan int i, rc; 3580eb513658SMichael Chan 3581691aa620SVasundhara Volam if (!(bp->fw_cap & BNXT_FW_CAP_PKG_VER)) 3582a60faa60SVasundhara Volam bnxt_get_pkgver(dev); 3583431aa1ebSMichael Chan 3584ba642ab7SMichael Chan bp->num_tests = 0; 3585eb513658SMichael Chan if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp)) 3586eb513658SMichael Chan return; 3587eb513658SMichael Chan 3588eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1); 3589eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 3590eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 3591eb513658SMichael Chan if (rc) 3592eb513658SMichael Chan goto ethtool_init_exit; 3593eb513658SMichael Chan 3594ba642ab7SMichael Chan test_info = bp->test_info; 3595ba642ab7SMichael Chan if (!test_info) 3596eb513658SMichael Chan test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL); 3597eb513658SMichael Chan if (!test_info) 3598eb513658SMichael Chan goto ethtool_init_exit; 3599eb513658SMichael Chan 3600eb513658SMichael Chan bp->test_info = test_info; 3601eb513658SMichael Chan bp->num_tests = resp->num_tests + BNXT_DRV_TESTS; 3602eb513658SMichael Chan if (bp->num_tests > BNXT_MAX_TEST) 3603eb513658SMichael Chan bp->num_tests = BNXT_MAX_TEST; 3604eb513658SMichael Chan 3605eb513658SMichael Chan test_info->offline_mask = resp->offline_tests; 3606eb513658SMichael Chan test_info->timeout = le16_to_cpu(resp->test_timeout); 3607eb513658SMichael Chan if (!test_info->timeout) 3608eb513658SMichael Chan test_info->timeout = HWRM_CMD_TIMEOUT; 3609eb513658SMichael Chan for (i = 0; i < bp->num_tests; i++) { 3610eb513658SMichael Chan char *str = test_info->string[i]; 3611eb513658SMichael Chan char *fw_str = resp->test0_name + i * 32; 3612eb513658SMichael Chan 3613f7dc1ea6SMichael Chan if (i == BNXT_MACLPBK_TEST_IDX) { 3614f7dc1ea6SMichael Chan strcpy(str, "Mac loopback test (offline)"); 361591725d89SMichael Chan } else if (i == BNXT_PHYLPBK_TEST_IDX) { 361691725d89SMichael Chan strcpy(str, "Phy loopback test (offline)"); 361755fd0cf3SMichael Chan } else if (i == BNXT_EXTLPBK_TEST_IDX) { 361855fd0cf3SMichael Chan strcpy(str, "Ext loopback test (offline)"); 361967fea463SMichael Chan } else if (i == BNXT_IRQ_TEST_IDX) { 362067fea463SMichael Chan strcpy(str, "Interrupt_test (offline)"); 3621f7dc1ea6SMichael Chan } else { 3622eb513658SMichael Chan strlcpy(str, fw_str, ETH_GSTRING_LEN); 3623eb513658SMichael Chan strncat(str, " test", ETH_GSTRING_LEN - strlen(str)); 3624eb513658SMichael Chan if (test_info->offline_mask & (1 << i)) 3625eb513658SMichael Chan strncat(str, " (offline)", 3626eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3627eb513658SMichael Chan else 3628eb513658SMichael Chan strncat(str, " (online)", 3629eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3630eb513658SMichael Chan } 3631f7dc1ea6SMichael Chan } 3632eb513658SMichael Chan 3633eb513658SMichael Chan ethtool_init_exit: 3634eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 3635eb513658SMichael Chan } 3636eb513658SMichael Chan 3637eb513658SMichael Chan void bnxt_ethtool_free(struct bnxt *bp) 3638eb513658SMichael Chan { 3639eb513658SMichael Chan kfree(bp->test_info); 3640eb513658SMichael Chan bp->test_info = NULL; 3641eb513658SMichael Chan } 3642eb513658SMichael Chan 3643c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 3644f704d243SJakub Kicinski .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 3645f704d243SJakub Kicinski ETHTOOL_COALESCE_MAX_FRAMES | 3646f704d243SJakub Kicinski ETHTOOL_COALESCE_USECS_IRQ | 3647f704d243SJakub Kicinski ETHTOOL_COALESCE_MAX_FRAMES_IRQ | 3648f704d243SJakub Kicinski ETHTOOL_COALESCE_STATS_BLOCK_USECS | 3649f704d243SJakub Kicinski ETHTOOL_COALESCE_USE_ADAPTIVE_RX, 365000c04a92SMichael Chan .get_link_ksettings = bnxt_get_link_ksettings, 365100c04a92SMichael Chan .set_link_ksettings = bnxt_set_link_ksettings, 3652c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 3653c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 3654c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 3655b5d600b0SVasundhara Volam .get_regs_len = bnxt_get_regs_len, 3656b5d600b0SVasundhara Volam .get_regs = bnxt_get_regs, 36578e202366SMichael Chan .get_wol = bnxt_get_wol, 36585282db6cSMichael Chan .set_wol = bnxt_set_wol, 3659c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 3660c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 3661c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 3662c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 3663c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 3664c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 3665c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 3666c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 3667c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 3668c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 3669c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 3670c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 3671a011952aSMichael Chan .set_rxnfc = bnxt_set_rxnfc, 3672c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 3673c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 3674c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 3675bd3191b5SMichael Chan .set_rxfh = bnxt_set_rxfh, 3676c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 3677c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 3678c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 3679c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 3680c0c050c5SMichael Chan .get_link = bnxt_get_link, 368172b34f04SMichael Chan .get_eee = bnxt_get_eee, 368272b34f04SMichael Chan .set_eee = bnxt_set_eee, 368342ee18feSAjit Khaparde .get_module_info = bnxt_get_module_info, 368442ee18feSAjit Khaparde .get_module_eeprom = bnxt_get_module_eeprom, 36855ad2cbeeSMichael Chan .nway_reset = bnxt_nway_reset, 36865ad2cbeeSMichael Chan .set_phys_id = bnxt_set_phys_id, 3687eb513658SMichael Chan .self_test = bnxt_self_test, 368849f7972fSVasundhara Volam .reset = bnxt_reset, 36890b0eacf3SVasundhara Volam .set_dump = bnxt_set_dump, 36906c5657d0SVasundhara Volam .get_dump_flag = bnxt_get_dump_flag, 36916c5657d0SVasundhara Volam .get_dump_data = bnxt_get_dump_data, 3692c0c050c5SMichael Chan }; 3693