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 14083eb5c5cSMichael Chan #define BNXT_NUM_STATS 22 141c0c050c5SMichael Chan 1428ddc9aaaSMichael Chan #define BNXT_RX_STATS_ENTRY(counter) \ 1438ddc9aaaSMichael Chan { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) } 1448ddc9aaaSMichael Chan 1458ddc9aaaSMichael Chan #define BNXT_TX_STATS_ENTRY(counter) \ 1468ddc9aaaSMichael Chan { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) } 1478ddc9aaaSMichael Chan 14800db3cbaSVasundhara Volam #define BNXT_RX_STATS_EXT_ENTRY(counter) \ 14900db3cbaSVasundhara Volam { BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) } 15000db3cbaSVasundhara Volam 15136e53349SMichael Chan #define BNXT_TX_STATS_EXT_ENTRY(counter) \ 15236e53349SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter), __stringify(counter) } 15336e53349SMichael Chan 15436e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRY(n) \ 15536e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_duration_us), \ 15636e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_transitions) 15736e53349SMichael Chan 15836e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRY(n) \ 15936e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_duration_us), \ 16036e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_transitions) 16136e53349SMichael Chan 16236e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRIES \ 16336e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(0), \ 16436e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(1), \ 16536e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(2), \ 16636e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(3), \ 16736e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(4), \ 16836e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(5), \ 16936e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(6), \ 17036e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRY(7) 17136e53349SMichael Chan 17236e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRIES \ 17336e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(0), \ 17436e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(1), \ 17536e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(2), \ 17636e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(3), \ 17736e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(4), \ 17836e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(5), \ 17936e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(6), \ 18036e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRY(7) 18136e53349SMichael Chan 18236e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRY(n) \ 18336e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_bytes_cos##n), \ 18436e53349SMichael Chan BNXT_RX_STATS_EXT_ENTRY(rx_packets_cos##n) 18536e53349SMichael Chan 18636e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRY(n) \ 18736e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_bytes_cos##n), \ 18836e53349SMichael Chan BNXT_TX_STATS_EXT_ENTRY(tx_packets_cos##n) 18936e53349SMichael Chan 19036e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRIES \ 19136e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(0), \ 19236e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(1), \ 19336e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(2), \ 19436e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(3), \ 19536e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(4), \ 19636e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(5), \ 19736e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(6), \ 19836e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRY(7) \ 19936e53349SMichael Chan 20036e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRIES \ 20136e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(0), \ 20236e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(1), \ 20336e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(2), \ 20436e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(3), \ 20536e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(4), \ 20636e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(5), \ 20736e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(6), \ 20836e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRY(7) \ 20936e53349SMichael Chan 210e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRY(counter, n) \ 211e37fed79SMichael Chan { BNXT_RX_STATS_EXT_OFFSET(counter##_cos0), \ 212e37fed79SMichael Chan __stringify(counter##_pri##n) } 213e37fed79SMichael Chan 214e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRY(counter, n) \ 215e37fed79SMichael Chan { BNXT_TX_STATS_EXT_OFFSET(counter##_cos0), \ 216e37fed79SMichael Chan __stringify(counter##_pri##n) } 217e37fed79SMichael Chan 218e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRIES(counter) \ 219e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 0), \ 220e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 1), \ 221e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 2), \ 222e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 3), \ 223e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 4), \ 224e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 5), \ 225e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 6), \ 226e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRY(counter, 7) 227e37fed79SMichael Chan 228e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRIES(counter) \ 229e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 0), \ 230e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 1), \ 231e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 2), \ 232e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 3), \ 233e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 4), \ 234e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 5), \ 235e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 6), \ 236e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRY(counter, 7) 237e37fed79SMichael Chan 23820c1d28eSVasundhara Volam enum { 23920c1d28eSVasundhara Volam RX_TOTAL_DISCARDS, 24020c1d28eSVasundhara Volam TX_TOTAL_DISCARDS, 24120c1d28eSVasundhara Volam }; 24220c1d28eSVasundhara Volam 24320c1d28eSVasundhara Volam static struct { 24420c1d28eSVasundhara Volam u64 counter; 24520c1d28eSVasundhara Volam char string[ETH_GSTRING_LEN]; 24620c1d28eSVasundhara Volam } bnxt_sw_func_stats[] = { 24720c1d28eSVasundhara Volam {0, "rx_total_discard_pkts"}, 24820c1d28eSVasundhara Volam {0, "tx_total_discard_pkts"}, 24920c1d28eSVasundhara Volam }; 25020c1d28eSVasundhara Volam 2518ddc9aaaSMichael Chan static const struct { 2528ddc9aaaSMichael Chan long offset; 2538ddc9aaaSMichael Chan char string[ETH_GSTRING_LEN]; 2548ddc9aaaSMichael Chan } bnxt_port_stats_arr[] = { 2558ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_64b_frames), 2568ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_65b_127b_frames), 2578ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_128b_255b_frames), 2588ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_256b_511b_frames), 2598ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames), 2606fc92c33SMichael Chan BNXT_RX_STATS_ENTRY(rx_1024b_1518b_frames), 2618ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_vlan_frames), 2628ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames), 2638ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames), 2648ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames), 2658ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames), 2668ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_total_frames), 2678ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ucast_frames), 2688ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mcast_frames), 2698ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bcast_frames), 2708ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_fcs_err_frames), 2718ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ctrl_frames), 2728ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pause_frames), 2738ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_frames), 2748ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_align_err_frames), 2758ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ovrsz_frames), 2768ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_jbr_frames), 2778ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mtu_err_frames), 2788ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_tagged_frames), 2798ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_double_tagged_frames), 2808ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_frames), 281c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0), 282c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1), 283c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2), 284c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3), 285c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4), 286c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5), 287c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6), 288c77192f2SMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7), 2898ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_undrsz_frames), 2908ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_events), 2918ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration), 2928ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bytes), 2938ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_bytes), 2948ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_frames), 295699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_discard), 296699efed0SVasundhara Volam BNXT_RX_STATS_ENTRY(rx_stat_err), 2978ddc9aaaSMichael Chan 2988ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_64b_frames), 2998ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_65b_127b_frames), 3008ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_128b_255b_frames), 3018ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_256b_511b_frames), 3028ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames), 3036fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1024b_1518b_frames), 3048ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_vlan_frames), 3056fc92c33SMichael Chan BNXT_TX_STATS_ENTRY(tx_1519b_2047b_frames), 3068ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames), 3078ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames), 3088ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames), 3098ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_frames), 3108ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_frames), 3118ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_ucast_frames), 3128ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_mcast_frames), 3138ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bcast_frames), 3148ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pause_frames), 3158ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_frames), 3168ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_jabber_frames), 3178ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fcs_err_frames), 3188ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_err), 3198ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fifo_underruns), 320c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0), 321c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1), 322c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2), 323c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3), 324c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4), 325c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5), 326c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6), 327c77192f2SMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7), 3288ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_events), 3298ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration), 3308ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_collisions), 3318ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bytes), 332699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_xthol_frames), 333699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_discard), 334699efed0SVasundhara Volam BNXT_TX_STATS_ENTRY(tx_stat_error), 3358ddc9aaaSMichael Chan }; 3368ddc9aaaSMichael Chan 33700db3cbaSVasundhara Volam static const struct { 33800db3cbaSVasundhara Volam long offset; 33900db3cbaSVasundhara Volam char string[ETH_GSTRING_LEN]; 34000db3cbaSVasundhara Volam } bnxt_port_stats_ext_arr[] = { 34100db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(link_down_events), 34200db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events), 34300db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_pause_events), 34400db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events), 34500db3cbaSVasundhara Volam BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events), 34636e53349SMichael Chan BNXT_RX_STATS_EXT_COS_ENTRIES, 34736e53349SMichael Chan BNXT_RX_STATS_EXT_PFC_ENTRIES, 34836e53349SMichael Chan }; 34936e53349SMichael Chan 35036e53349SMichael Chan static const struct { 35136e53349SMichael Chan long offset; 35236e53349SMichael Chan char string[ETH_GSTRING_LEN]; 35336e53349SMichael Chan } bnxt_tx_port_stats_ext_arr[] = { 35436e53349SMichael Chan BNXT_TX_STATS_EXT_COS_ENTRIES, 35536e53349SMichael Chan BNXT_TX_STATS_EXT_PFC_ENTRIES, 35600db3cbaSVasundhara Volam }; 35700db3cbaSVasundhara Volam 358e37fed79SMichael Chan static const struct { 359e37fed79SMichael Chan long base_off; 360e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 361e37fed79SMichael Chan } bnxt_rx_bytes_pri_arr[] = { 362e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_bytes), 363e37fed79SMichael Chan }; 364e37fed79SMichael Chan 365e37fed79SMichael Chan static const struct { 366e37fed79SMichael Chan long base_off; 367e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 368e37fed79SMichael Chan } bnxt_rx_pkts_pri_arr[] = { 369e37fed79SMichael Chan BNXT_RX_STATS_PRI_ENTRIES(rx_packets), 370e37fed79SMichael Chan }; 371e37fed79SMichael Chan 372e37fed79SMichael Chan static const struct { 373e37fed79SMichael Chan long base_off; 374e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 375e37fed79SMichael Chan } bnxt_tx_bytes_pri_arr[] = { 376e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_bytes), 377e37fed79SMichael Chan }; 378e37fed79SMichael Chan 379e37fed79SMichael Chan static const struct { 380e37fed79SMichael Chan long base_off; 381e37fed79SMichael Chan char string[ETH_GSTRING_LEN]; 382e37fed79SMichael Chan } bnxt_tx_pkts_pri_arr[] = { 383e37fed79SMichael Chan BNXT_TX_STATS_PRI_ENTRIES(tx_packets), 384e37fed79SMichael Chan }; 385e37fed79SMichael Chan 38620c1d28eSVasundhara Volam #define BNXT_NUM_SW_FUNC_STATS ARRAY_SIZE(bnxt_sw_func_stats) 3878ddc9aaaSMichael Chan #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr) 388e37fed79SMichael Chan #define BNXT_NUM_STATS_PRI \ 389e37fed79SMichael Chan (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \ 390e37fed79SMichael Chan ARRAY_SIZE(bnxt_rx_pkts_pri_arr) + \ 391e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_bytes_pri_arr) + \ 392e37fed79SMichael Chan ARRAY_SIZE(bnxt_tx_pkts_pri_arr)) 3938ddc9aaaSMichael Chan 3945c8227d0SMichael Chan static int bnxt_get_num_stats(struct bnxt *bp) 395c0c050c5SMichael Chan { 3968ddc9aaaSMichael Chan int num_stats = BNXT_NUM_STATS * bp->cp_nr_rings; 3978ddc9aaaSMichael Chan 39820c1d28eSVasundhara Volam num_stats += BNXT_NUM_SW_FUNC_STATS; 39920c1d28eSVasundhara Volam 4008ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) 4018ddc9aaaSMichael Chan num_stats += BNXT_NUM_PORT_STATS; 4028ddc9aaaSMichael Chan 403e37fed79SMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 40436e53349SMichael Chan num_stats += bp->fw_rx_stats_ext_size + 40536e53349SMichael Chan bp->fw_tx_stats_ext_size; 406e37fed79SMichael Chan if (bp->pri2cos_valid) 407e37fed79SMichael Chan num_stats += BNXT_NUM_STATS_PRI; 408e37fed79SMichael Chan } 40900db3cbaSVasundhara Volam 4108ddc9aaaSMichael Chan return num_stats; 4118ddc9aaaSMichael Chan } 4125c8227d0SMichael Chan 4135c8227d0SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 4145c8227d0SMichael Chan { 4155c8227d0SMichael Chan struct bnxt *bp = netdev_priv(dev); 4165c8227d0SMichael Chan 4175c8227d0SMichael Chan switch (sset) { 4185c8227d0SMichael Chan case ETH_SS_STATS: 4195c8227d0SMichael Chan return bnxt_get_num_stats(bp); 420eb513658SMichael Chan case ETH_SS_TEST: 421eb513658SMichael Chan if (!bp->num_tests) 422eb513658SMichael Chan return -EOPNOTSUPP; 423eb513658SMichael Chan return bp->num_tests; 424c0c050c5SMichael Chan default: 425c0c050c5SMichael Chan return -EOPNOTSUPP; 426c0c050c5SMichael Chan } 427c0c050c5SMichael Chan } 428c0c050c5SMichael Chan 429c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 430c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 431c0c050c5SMichael Chan { 432c0c050c5SMichael Chan u32 i, j = 0; 433c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 434c0c050c5SMichael Chan u32 stat_fields = sizeof(struct ctx_hw_stats) / 8; 435c0c050c5SMichael Chan 436c0c050c5SMichael Chan if (!bp->bnapi) 437c0c050c5SMichael Chan return; 438c0c050c5SMichael Chan 43920c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) 44020c1d28eSVasundhara Volam bnxt_sw_func_stats[i].counter = 0; 44120c1d28eSVasundhara Volam 442c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 443c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 444c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 445c0c050c5SMichael Chan __le64 *hw_stats = (__le64 *)cpr->hw_stats; 446c0c050c5SMichael Chan int k; 447c0c050c5SMichael Chan 448c0c050c5SMichael Chan for (k = 0; k < stat_fields; j++, k++) 449c0c050c5SMichael Chan buf[j] = le64_to_cpu(hw_stats[k]); 450c0c050c5SMichael Chan buf[j++] = cpr->rx_l4_csum_errors; 45183eb5c5cSMichael Chan buf[j++] = cpr->missed_irqs; 45220c1d28eSVasundhara Volam 45320c1d28eSVasundhara Volam bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter += 45420c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->rx_discard_pkts); 45520c1d28eSVasundhara Volam bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter += 45620c1d28eSVasundhara Volam le64_to_cpu(cpr->hw_stats->tx_discard_pkts); 457c0c050c5SMichael Chan } 45820c1d28eSVasundhara Volam 45920c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++) 46020c1d28eSVasundhara Volam buf[j] = bnxt_sw_func_stats[i].counter; 46120c1d28eSVasundhara Volam 4628ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 4638ddc9aaaSMichael Chan __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats; 4648ddc9aaaSMichael Chan 4658ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) { 4668ddc9aaaSMichael Chan buf[j] = le64_to_cpu(*(port_stats + 4678ddc9aaaSMichael Chan bnxt_port_stats_arr[i].offset)); 4688ddc9aaaSMichael Chan } 4698ddc9aaaSMichael Chan } 47000db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 47136e53349SMichael Chan __le64 *rx_port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext; 47236e53349SMichael Chan __le64 *tx_port_stats_ext = (__le64 *)bp->hw_tx_port_stats_ext; 47300db3cbaSVasundhara Volam 47436e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) { 47536e53349SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + 47600db3cbaSVasundhara Volam bnxt_port_stats_ext_arr[i].offset)); 47700db3cbaSVasundhara Volam } 47836e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++, j++) { 47936e53349SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + 48036e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].offset)); 48136e53349SMichael Chan } 482e37fed79SMichael Chan if (bp->pri2cos_valid) { 483e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 484e37fed79SMichael Chan long n = bnxt_rx_bytes_pri_arr[i].base_off + 485e37fed79SMichael Chan bp->pri2cos[i]; 486e37fed79SMichael Chan 487e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 488e37fed79SMichael Chan } 489e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 490e37fed79SMichael Chan long n = bnxt_rx_pkts_pri_arr[i].base_off + 491e37fed79SMichael Chan bp->pri2cos[i]; 492e37fed79SMichael Chan 493e37fed79SMichael Chan buf[j] = le64_to_cpu(*(rx_port_stats_ext + n)); 494e37fed79SMichael Chan } 495e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 496e37fed79SMichael Chan long n = bnxt_tx_bytes_pri_arr[i].base_off + 497e37fed79SMichael Chan bp->pri2cos[i]; 498e37fed79SMichael Chan 499e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 500e37fed79SMichael Chan } 501e37fed79SMichael Chan for (i = 0; i < 8; i++, j++) { 502e37fed79SMichael Chan long n = bnxt_tx_pkts_pri_arr[i].base_off + 503e37fed79SMichael Chan bp->pri2cos[i]; 504e37fed79SMichael Chan 505e37fed79SMichael Chan buf[j] = le64_to_cpu(*(tx_port_stats_ext + n)); 506e37fed79SMichael Chan } 507e37fed79SMichael Chan } 50800db3cbaSVasundhara Volam } 509c0c050c5SMichael Chan } 510c0c050c5SMichael Chan 511c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 512c0c050c5SMichael Chan { 513c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 514c0c050c5SMichael Chan u32 i; 515c0c050c5SMichael Chan 516c0c050c5SMichael Chan switch (stringset) { 517c0c050c5SMichael Chan /* The number of strings must match BNXT_NUM_STATS defined above. */ 518c0c050c5SMichael Chan case ETH_SS_STATS: 519c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 520c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_ucast_packets", i); 521c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 522c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_mcast_packets", i); 523c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 524c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_bcast_packets", i); 525c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 526c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_discards", i); 527c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 528c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_drops", i); 529c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 530c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_ucast_bytes", i); 531c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 532c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_mcast_bytes", i); 533c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 534c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_bcast_bytes", i); 535c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 536c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_ucast_packets", i); 537c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 538c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_mcast_packets", i); 539c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 540c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_bcast_packets", i); 541c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 542c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_discards", i); 543c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 544c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_drops", i); 545c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 546c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_ucast_bytes", i); 547c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 548c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_mcast_bytes", i); 549c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 550c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_bcast_bytes", i); 551c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 552c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_packets", i); 553c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 554c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_bytes", i); 555c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 556c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_events", i); 557c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 558c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_aborts", i); 559c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 560c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_l4_csum_errors", i); 561c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 56283eb5c5cSMichael Chan sprintf(buf, "[%d]: missed_irqs", i); 56383eb5c5cSMichael Chan buf += ETH_GSTRING_LEN; 564c0c050c5SMichael Chan } 56520c1d28eSVasundhara Volam for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) { 56620c1d28eSVasundhara Volam strcpy(buf, bnxt_sw_func_stats[i].string); 56720c1d28eSVasundhara Volam buf += ETH_GSTRING_LEN; 56820c1d28eSVasundhara Volam } 56920c1d28eSVasundhara Volam 5708ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 5718ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++) { 5728ddc9aaaSMichael Chan strcpy(buf, bnxt_port_stats_arr[i].string); 5738ddc9aaaSMichael Chan buf += ETH_GSTRING_LEN; 5748ddc9aaaSMichael Chan } 5758ddc9aaaSMichael Chan } 57600db3cbaSVasundhara Volam if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 57736e53349SMichael Chan for (i = 0; i < bp->fw_rx_stats_ext_size; i++) { 57800db3cbaSVasundhara Volam strcpy(buf, bnxt_port_stats_ext_arr[i].string); 57900db3cbaSVasundhara Volam buf += ETH_GSTRING_LEN; 58000db3cbaSVasundhara Volam } 58136e53349SMichael Chan for (i = 0; i < bp->fw_tx_stats_ext_size; i++) { 58236e53349SMichael Chan strcpy(buf, 58336e53349SMichael Chan bnxt_tx_port_stats_ext_arr[i].string); 58436e53349SMichael Chan buf += ETH_GSTRING_LEN; 58536e53349SMichael Chan } 586e37fed79SMichael Chan if (bp->pri2cos_valid) { 587e37fed79SMichael Chan for (i = 0; i < 8; i++) { 588e37fed79SMichael Chan strcpy(buf, 589e37fed79SMichael Chan bnxt_rx_bytes_pri_arr[i].string); 590e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 591e37fed79SMichael Chan } 592e37fed79SMichael Chan for (i = 0; i < 8; i++) { 593e37fed79SMichael Chan strcpy(buf, 594e37fed79SMichael Chan bnxt_rx_pkts_pri_arr[i].string); 595e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 596e37fed79SMichael Chan } 597e37fed79SMichael Chan for (i = 0; i < 8; i++) { 598e37fed79SMichael Chan strcpy(buf, 599e37fed79SMichael Chan bnxt_tx_bytes_pri_arr[i].string); 600e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 601e37fed79SMichael Chan } 602e37fed79SMichael Chan for (i = 0; i < 8; i++) { 603e37fed79SMichael Chan strcpy(buf, 604e37fed79SMichael Chan bnxt_tx_pkts_pri_arr[i].string); 605e37fed79SMichael Chan buf += ETH_GSTRING_LEN; 606e37fed79SMichael Chan } 607e37fed79SMichael Chan } 60800db3cbaSVasundhara Volam } 609c0c050c5SMichael Chan break; 610eb513658SMichael Chan case ETH_SS_TEST: 611eb513658SMichael Chan if (bp->num_tests) 612eb513658SMichael Chan memcpy(buf, bp->test_info->string, 613eb513658SMichael Chan bp->num_tests * ETH_GSTRING_LEN); 614eb513658SMichael Chan break; 615c0c050c5SMichael Chan default: 616c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 617c0c050c5SMichael Chan stringset); 618c0c050c5SMichael Chan break; 619c0c050c5SMichael Chan } 620c0c050c5SMichael Chan } 621c0c050c5SMichael Chan 622c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 623c0c050c5SMichael Chan struct ethtool_ringparam *ering) 624c0c050c5SMichael Chan { 625c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 626c0c050c5SMichael Chan 627c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 628c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 629c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 630c0c050c5SMichael Chan 631c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 632c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 633c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 634c0c050c5SMichael Chan } 635c0c050c5SMichael Chan 636c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 637c0c050c5SMichael Chan struct ethtool_ringparam *ering) 638c0c050c5SMichael Chan { 639c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 640c0c050c5SMichael Chan 641c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 642c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 643c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 644c0c050c5SMichael Chan return -EINVAL; 645c0c050c5SMichael Chan 646c0c050c5SMichael Chan if (netif_running(dev)) 647c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 648c0c050c5SMichael Chan 649c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 650c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 651c0c050c5SMichael Chan bnxt_set_ring_params(bp); 652c0c050c5SMichael Chan 653c0c050c5SMichael Chan if (netif_running(dev)) 654c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 655c0c050c5SMichael Chan 656c0c050c5SMichael Chan return 0; 657c0c050c5SMichael Chan } 658c0c050c5SMichael Chan 659c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 660c0c050c5SMichael Chan struct ethtool_channels *channel) 661c0c050c5SMichael Chan { 662c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 663db4723b3SMichael Chan struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 664c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 665db4723b3SMichael Chan int max_tx_sch_inputs; 666db4723b3SMichael Chan 667db4723b3SMichael Chan /* Get the most up-to-date max_tx_sch_inputs. */ 668f1ca94deSMichael Chan if (BNXT_NEW_RM(bp)) 669db4723b3SMichael Chan bnxt_hwrm_func_resc_qcaps(bp, false); 670db4723b3SMichael Chan max_tx_sch_inputs = hw_resc->max_tx_sch_inputs; 671c0c050c5SMichael Chan 6726e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 673db4723b3SMichael Chan if (max_tx_sch_inputs) 674db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 675a79a5276SMichael Chan channel->max_combined = min_t(int, max_rx_rings, max_tx_rings); 676068c9ec6SMichael Chan 67718d6e4e2SSatish Baddipadige if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) { 67818d6e4e2SSatish Baddipadige max_rx_rings = 0; 67918d6e4e2SSatish Baddipadige max_tx_rings = 0; 68018d6e4e2SSatish Baddipadige } 681db4723b3SMichael Chan if (max_tx_sch_inputs) 682db4723b3SMichael Chan max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs); 68318d6e4e2SSatish Baddipadige 684c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 685c0c050c5SMichael Chan if (tcs > 1) 686c0c050c5SMichael Chan max_tx_rings /= tcs; 687c0c050c5SMichael Chan 688c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 689c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 690c0c050c5SMichael Chan channel->max_other = 0; 691068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 692068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 69376595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp)) 69476595193SPrashant Sreedharan channel->combined_count--; 695068c9ec6SMichael Chan } else { 69676595193SPrashant Sreedharan if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) { 697c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 698c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 699c0c050c5SMichael Chan } 700068c9ec6SMichael Chan } 70176595193SPrashant Sreedharan } 702c0c050c5SMichael Chan 703c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 704c0c050c5SMichael Chan struct ethtool_channels *channel) 705c0c050c5SMichael Chan { 706c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 707d1e7925eSMichael Chan int req_tx_rings, req_rx_rings, tcs; 708068c9ec6SMichael Chan bool sh = false; 7095f449249SMichael Chan int tx_xdp = 0; 710d1e7925eSMichael Chan int rc = 0; 711c0c050c5SMichael Chan 712068c9ec6SMichael Chan if (channel->other_count) 713c0c050c5SMichael Chan return -EINVAL; 714c0c050c5SMichael Chan 715068c9ec6SMichael Chan if (!channel->combined_count && 716068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 717068c9ec6SMichael Chan return -EINVAL; 718068c9ec6SMichael Chan 719068c9ec6SMichael Chan if (channel->combined_count && 720068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 721068c9ec6SMichael Chan return -EINVAL; 722068c9ec6SMichael Chan 72376595193SPrashant Sreedharan if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count || 72476595193SPrashant Sreedharan channel->tx_count)) 72576595193SPrashant Sreedharan return -EINVAL; 72676595193SPrashant Sreedharan 727068c9ec6SMichael Chan if (channel->combined_count) 728068c9ec6SMichael Chan sh = true; 729068c9ec6SMichael Chan 730c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 731c0c050c5SMichael Chan 732391be5c2SMichael Chan req_tx_rings = sh ? channel->combined_count : channel->tx_count; 733d1e7925eSMichael Chan req_rx_rings = sh ? channel->combined_count : channel->rx_count; 7345f449249SMichael Chan if (bp->tx_nr_rings_xdp) { 7355f449249SMichael Chan if (!sh) { 7365f449249SMichael Chan netdev_err(dev, "Only combined mode supported when XDP is enabled.\n"); 7375f449249SMichael Chan return -EINVAL; 7385f449249SMichael Chan } 7395f449249SMichael Chan tx_xdp = req_rx_rings; 7405f449249SMichael Chan } 74198fdbe73SMichael Chan rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp); 742d1e7925eSMichael Chan if (rc) { 743d1e7925eSMichael Chan netdev_warn(dev, "Unable to allocate the requested rings\n"); 744d1e7925eSMichael Chan return rc; 745391be5c2SMichael Chan } 746391be5c2SMichael Chan 747c0c050c5SMichael Chan if (netif_running(dev)) { 748c0c050c5SMichael Chan if (BNXT_PF(bp)) { 749c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 750c0c050c5SMichael Chan * before PF unload 751c0c050c5SMichael Chan */ 752c0c050c5SMichael Chan } 753c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 754c0c050c5SMichael Chan if (rc) { 755c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 756c0c050c5SMichael Chan rc); 757c0c050c5SMichael Chan return rc; 758c0c050c5SMichael Chan } 759c0c050c5SMichael Chan } 760c0c050c5SMichael Chan 761068c9ec6SMichael Chan if (sh) { 762068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 763d1e7925eSMichael Chan bp->rx_nr_rings = channel->combined_count; 764d1e7925eSMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 765068c9ec6SMichael Chan } else { 766068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 767c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 768c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 769068c9ec6SMichael Chan } 7705f449249SMichael Chan bp->tx_nr_rings_xdp = tx_xdp; 7715f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp; 772c0c050c5SMichael Chan if (tcs > 1) 7735f449249SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp; 774068c9ec6SMichael Chan 775068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 776068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 777068c9ec6SMichael Chan 7782bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 7792bcfa6f6SMichael Chan netdev_update_features(dev); 780c0c050c5SMichael Chan if (netif_running(dev)) { 781c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 782c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 783c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 784c0c050c5SMichael Chan * to renable 785c0c050c5SMichael Chan */ 786c0c050c5SMichael Chan } 787d8c09f19SMichael Chan } else { 788d8c09f19SMichael Chan rc = bnxt_reserve_rings(bp); 789c0c050c5SMichael Chan } 790c0c050c5SMichael Chan 791c0c050c5SMichael Chan return rc; 792c0c050c5SMichael Chan } 793c0c050c5SMichael Chan 794c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 795c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 796c0c050c5SMichael Chan u32 *rule_locs) 797c0c050c5SMichael Chan { 798c0c050c5SMichael Chan int i, j = 0; 799c0c050c5SMichael Chan 800c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 801c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 802c0c050c5SMichael Chan struct hlist_head *head; 803c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 804c0c050c5SMichael Chan 805c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 806c0c050c5SMichael Chan rcu_read_lock(); 807c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 808c0c050c5SMichael Chan if (j == cmd->rule_cnt) 809c0c050c5SMichael Chan break; 810c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 811c0c050c5SMichael Chan } 812c0c050c5SMichael Chan rcu_read_unlock(); 813c0c050c5SMichael Chan if (j == cmd->rule_cnt) 814c0c050c5SMichael Chan break; 815c0c050c5SMichael Chan } 816c0c050c5SMichael Chan cmd->rule_cnt = j; 817c0c050c5SMichael Chan return 0; 818c0c050c5SMichael Chan } 819c0c050c5SMichael Chan 820c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 821c0c050c5SMichael Chan { 822c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 823c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 824c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 825c0c050c5SMichael Chan struct flow_keys *fkeys; 826c0c050c5SMichael Chan int i, rc = -EINVAL; 827c0c050c5SMichael Chan 828b721cfafSstephen hemminger if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 829c0c050c5SMichael Chan return rc; 830c0c050c5SMichael Chan 831c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 832c0c050c5SMichael Chan struct hlist_head *head; 833c0c050c5SMichael Chan 834c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 835c0c050c5SMichael Chan rcu_read_lock(); 836c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 837c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 838c0c050c5SMichael Chan goto fltr_found; 839c0c050c5SMichael Chan } 840c0c050c5SMichael Chan rcu_read_unlock(); 841c0c050c5SMichael Chan } 842c0c050c5SMichael Chan return rc; 843c0c050c5SMichael Chan 844c0c050c5SMichael Chan fltr_found: 845c0c050c5SMichael Chan fkeys = &fltr->fkeys; 846dda0e746SMichael Chan if (fkeys->basic.n_proto == htons(ETH_P_IP)) { 847c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 848c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 849c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 850c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 851c0c050c5SMichael Chan else 852c0c050c5SMichael Chan goto fltr_err; 853c0c050c5SMichael Chan 854c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 855c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 856c0c050c5SMichael Chan 857c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 858c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 859c0c050c5SMichael Chan 860c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 861c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 862c0c050c5SMichael Chan 863c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 864c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 865dda0e746SMichael Chan } else { 866dda0e746SMichael Chan int i; 867dda0e746SMichael Chan 868dda0e746SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 869dda0e746SMichael Chan fs->flow_type = TCP_V6_FLOW; 870dda0e746SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 871dda0e746SMichael Chan fs->flow_type = UDP_V6_FLOW; 872dda0e746SMichael Chan else 873dda0e746SMichael Chan goto fltr_err; 874dda0e746SMichael Chan 875dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] = 876dda0e746SMichael Chan fkeys->addrs.v6addrs.src; 877dda0e746SMichael Chan *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] = 878dda0e746SMichael Chan fkeys->addrs.v6addrs.dst; 879dda0e746SMichael Chan for (i = 0; i < 4; i++) { 880dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0); 881dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0); 882dda0e746SMichael Chan } 883dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src; 884dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0); 885dda0e746SMichael Chan 886dda0e746SMichael Chan fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst; 887dda0e746SMichael Chan fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0); 888dda0e746SMichael Chan } 889c0c050c5SMichael Chan 890c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 891c0c050c5SMichael Chan rc = 0; 892c0c050c5SMichael Chan 893c0c050c5SMichael Chan fltr_err: 894c0c050c5SMichael Chan rcu_read_unlock(); 895c0c050c5SMichael Chan 896c0c050c5SMichael Chan return rc; 897c0c050c5SMichael Chan } 898a011952aSMichael Chan #endif 899a011952aSMichael Chan 900a011952aSMichael Chan static u64 get_ethtool_ipv4_rss(struct bnxt *bp) 901a011952aSMichael Chan { 902a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4) 903a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 904a011952aSMichael Chan return 0; 905a011952aSMichael Chan } 906a011952aSMichael Chan 907a011952aSMichael Chan static u64 get_ethtool_ipv6_rss(struct bnxt *bp) 908a011952aSMichael Chan { 909a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6) 910a011952aSMichael Chan return RXH_IP_SRC | RXH_IP_DST; 911a011952aSMichael Chan return 0; 912a011952aSMichael Chan } 913a011952aSMichael Chan 914a011952aSMichael Chan static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 915a011952aSMichael Chan { 916a011952aSMichael Chan cmd->data = 0; 917a011952aSMichael Chan switch (cmd->flow_type) { 918a011952aSMichael Chan case TCP_V4_FLOW: 919a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4) 920a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 921a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 922a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 923a011952aSMichael Chan break; 924a011952aSMichael Chan case UDP_V4_FLOW: 925a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4) 926a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 927a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 928a011952aSMichael Chan /* fall through */ 929a011952aSMichael Chan case SCTP_V4_FLOW: 930a011952aSMichael Chan case AH_ESP_V4_FLOW: 931a011952aSMichael Chan case AH_V4_FLOW: 932a011952aSMichael Chan case ESP_V4_FLOW: 933a011952aSMichael Chan case IPV4_FLOW: 934a011952aSMichael Chan cmd->data |= get_ethtool_ipv4_rss(bp); 935a011952aSMichael Chan break; 936a011952aSMichael Chan 937a011952aSMichael Chan case TCP_V6_FLOW: 938a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6) 939a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 940a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 941a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 942a011952aSMichael Chan break; 943a011952aSMichael Chan case UDP_V6_FLOW: 944a011952aSMichael Chan if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6) 945a011952aSMichael Chan cmd->data |= RXH_IP_SRC | RXH_IP_DST | 946a011952aSMichael Chan RXH_L4_B_0_1 | RXH_L4_B_2_3; 947a011952aSMichael Chan /* fall through */ 948a011952aSMichael Chan case SCTP_V6_FLOW: 949a011952aSMichael Chan case AH_ESP_V6_FLOW: 950a011952aSMichael Chan case AH_V6_FLOW: 951a011952aSMichael Chan case ESP_V6_FLOW: 952a011952aSMichael Chan case IPV6_FLOW: 953a011952aSMichael Chan cmd->data |= get_ethtool_ipv6_rss(bp); 954a011952aSMichael Chan break; 955a011952aSMichael Chan } 956a011952aSMichael Chan return 0; 957a011952aSMichael Chan } 958a011952aSMichael Chan 959a011952aSMichael Chan #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3) 960a011952aSMichael Chan #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST) 961a011952aSMichael Chan 962a011952aSMichael Chan static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd) 963a011952aSMichael Chan { 964a011952aSMichael Chan u32 rss_hash_cfg = bp->rss_hash_cfg; 965a011952aSMichael Chan int tuple, rc = 0; 966a011952aSMichael Chan 967a011952aSMichael Chan if (cmd->data == RXH_4TUPLE) 968a011952aSMichael Chan tuple = 4; 969a011952aSMichael Chan else if (cmd->data == RXH_2TUPLE) 970a011952aSMichael Chan tuple = 2; 971a011952aSMichael Chan else if (!cmd->data) 972a011952aSMichael Chan tuple = 0; 973a011952aSMichael Chan else 974a011952aSMichael Chan return -EINVAL; 975a011952aSMichael Chan 976a011952aSMichael Chan if (cmd->flow_type == TCP_V4_FLOW) { 977a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 978a011952aSMichael Chan if (tuple == 4) 979a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4; 980a011952aSMichael Chan } else if (cmd->flow_type == UDP_V4_FLOW) { 981a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 982a011952aSMichael Chan return -EINVAL; 983a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 984a011952aSMichael Chan if (tuple == 4) 985a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4; 986a011952aSMichael Chan } else if (cmd->flow_type == TCP_V6_FLOW) { 987a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 988a011952aSMichael Chan if (tuple == 4) 989a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 990a011952aSMichael Chan } else if (cmd->flow_type == UDP_V6_FLOW) { 991a011952aSMichael Chan if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP)) 992a011952aSMichael Chan return -EINVAL; 993a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 994a011952aSMichael Chan if (tuple == 4) 995a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 996a011952aSMichael Chan } else if (tuple == 4) { 997a011952aSMichael Chan return -EINVAL; 998a011952aSMichael Chan } 999a011952aSMichael Chan 1000a011952aSMichael Chan switch (cmd->flow_type) { 1001a011952aSMichael Chan case TCP_V4_FLOW: 1002a011952aSMichael Chan case UDP_V4_FLOW: 1003a011952aSMichael Chan case SCTP_V4_FLOW: 1004a011952aSMichael Chan case AH_ESP_V4_FLOW: 1005a011952aSMichael Chan case AH_V4_FLOW: 1006a011952aSMichael Chan case ESP_V4_FLOW: 1007a011952aSMichael Chan case IPV4_FLOW: 1008a011952aSMichael Chan if (tuple == 2) 1009a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1010a011952aSMichael Chan else if (!tuple) 1011a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4; 1012a011952aSMichael Chan break; 1013a011952aSMichael Chan 1014a011952aSMichael Chan case TCP_V6_FLOW: 1015a011952aSMichael Chan case UDP_V6_FLOW: 1016a011952aSMichael Chan case SCTP_V6_FLOW: 1017a011952aSMichael Chan case AH_ESP_V6_FLOW: 1018a011952aSMichael Chan case AH_V6_FLOW: 1019a011952aSMichael Chan case ESP_V6_FLOW: 1020a011952aSMichael Chan case IPV6_FLOW: 1021a011952aSMichael Chan if (tuple == 2) 1022a011952aSMichael Chan rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1023a011952aSMichael Chan else if (!tuple) 1024a011952aSMichael Chan rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6; 1025a011952aSMichael Chan break; 1026a011952aSMichael Chan } 1027a011952aSMichael Chan 1028a011952aSMichael Chan if (bp->rss_hash_cfg == rss_hash_cfg) 1029a011952aSMichael Chan return 0; 1030a011952aSMichael Chan 1031a011952aSMichael Chan bp->rss_hash_cfg = rss_hash_cfg; 1032a011952aSMichael Chan if (netif_running(bp->dev)) { 1033a011952aSMichael Chan bnxt_close_nic(bp, false, false); 1034a011952aSMichael Chan rc = bnxt_open_nic(bp, false, false); 1035a011952aSMichael Chan } 1036a011952aSMichael Chan return rc; 1037a011952aSMichael Chan } 1038c0c050c5SMichael Chan 1039c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 1040c0c050c5SMichael Chan u32 *rule_locs) 1041c0c050c5SMichael Chan { 1042c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1043c0c050c5SMichael Chan int rc = 0; 1044c0c050c5SMichael Chan 1045c0c050c5SMichael Chan switch (cmd->cmd) { 1046a011952aSMichael Chan #ifdef CONFIG_RFS_ACCEL 1047c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 1048c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 1049c0c050c5SMichael Chan break; 1050c0c050c5SMichael Chan 1051c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 1052c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 1053c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 1054c0c050c5SMichael Chan break; 1055c0c050c5SMichael Chan 1056c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 1057c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 1058c0c050c5SMichael Chan break; 1059c0c050c5SMichael Chan 1060c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 1061c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 1062c0c050c5SMichael Chan break; 1063a011952aSMichael Chan #endif 1064a011952aSMichael Chan 1065a011952aSMichael Chan case ETHTOOL_GRXFH: 1066a011952aSMichael Chan rc = bnxt_grxfh(bp, cmd); 1067a011952aSMichael Chan break; 1068c0c050c5SMichael Chan 1069c0c050c5SMichael Chan default: 1070c0c050c5SMichael Chan rc = -EOPNOTSUPP; 1071c0c050c5SMichael Chan break; 1072c0c050c5SMichael Chan } 1073c0c050c5SMichael Chan 1074c0c050c5SMichael Chan return rc; 1075c0c050c5SMichael Chan } 1076a011952aSMichael Chan 1077a011952aSMichael Chan static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) 1078a011952aSMichael Chan { 1079a011952aSMichael Chan struct bnxt *bp = netdev_priv(dev); 1080a011952aSMichael Chan int rc; 1081a011952aSMichael Chan 1082a011952aSMichael Chan switch (cmd->cmd) { 1083a011952aSMichael Chan case ETHTOOL_SRXFH: 1084a011952aSMichael Chan rc = bnxt_srxfh(bp, cmd); 1085a011952aSMichael Chan break; 1086a011952aSMichael Chan 1087a011952aSMichael Chan default: 1088a011952aSMichael Chan rc = -EOPNOTSUPP; 1089a011952aSMichael Chan break; 1090a011952aSMichael Chan } 1091a011952aSMichael Chan return rc; 1092a011952aSMichael Chan } 1093c0c050c5SMichael Chan 1094c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 1095c0c050c5SMichael Chan { 1096c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 1097c0c050c5SMichael Chan } 1098c0c050c5SMichael Chan 1099c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 1100c0c050c5SMichael Chan { 1101c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 1102c0c050c5SMichael Chan } 1103c0c050c5SMichael Chan 1104c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 1105c0c050c5SMichael Chan u8 *hfunc) 1106c0c050c5SMichael Chan { 1107c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 11087991cb9cSMichael Chan struct bnxt_vnic_info *vnic; 1109c0c050c5SMichael Chan int i = 0; 1110c0c050c5SMichael Chan 1111c0c050c5SMichael Chan if (hfunc) 1112c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 1113c0c050c5SMichael Chan 11147991cb9cSMichael Chan if (!bp->vnic_info) 11157991cb9cSMichael Chan return 0; 11167991cb9cSMichael Chan 11177991cb9cSMichael Chan vnic = &bp->vnic_info[0]; 11187991cb9cSMichael Chan if (indir && vnic->rss_table) { 1119c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 1120c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 11217991cb9cSMichael Chan } 1122c0c050c5SMichael Chan 11237991cb9cSMichael Chan if (key && vnic->rss_hash_key) 1124c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 1125c0c050c5SMichael Chan 1126c0c050c5SMichael Chan return 0; 1127c0c050c5SMichael Chan } 1128c0c050c5SMichael Chan 1129c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 1130c0c050c5SMichael Chan struct ethtool_drvinfo *info) 1131c0c050c5SMichael Chan { 1132c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1133c0c050c5SMichael Chan 1134c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 1135c0c050c5SMichael Chan strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 1136431aa1ebSMichael Chan strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); 1137c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 11385c8227d0SMichael Chan info->n_stats = bnxt_get_num_stats(bp); 1139eb513658SMichael Chan info->testinfo_len = bp->num_tests; 1140c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 1141c0c050c5SMichael Chan info->eedump_len = 0; 1142c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 1143c0c050c5SMichael Chan info->regdump_len = 0; 1144c0c050c5SMichael Chan } 1145c0c050c5SMichael Chan 11468e202366SMichael Chan static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 11478e202366SMichael Chan { 11488e202366SMichael Chan struct bnxt *bp = netdev_priv(dev); 11498e202366SMichael Chan 11508e202366SMichael Chan wol->supported = 0; 11518e202366SMichael Chan wol->wolopts = 0; 11528e202366SMichael Chan memset(&wol->sopass, 0, sizeof(wol->sopass)); 11538e202366SMichael Chan if (bp->flags & BNXT_FLAG_WOL_CAP) { 11548e202366SMichael Chan wol->supported = WAKE_MAGIC; 11558e202366SMichael Chan if (bp->wol) 11568e202366SMichael Chan wol->wolopts = WAKE_MAGIC; 11578e202366SMichael Chan } 11588e202366SMichael Chan } 11598e202366SMichael Chan 11605282db6cSMichael Chan static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 11615282db6cSMichael Chan { 11625282db6cSMichael Chan struct bnxt *bp = netdev_priv(dev); 11635282db6cSMichael Chan 11645282db6cSMichael Chan if (wol->wolopts & ~WAKE_MAGIC) 11655282db6cSMichael Chan return -EINVAL; 11665282db6cSMichael Chan 11675282db6cSMichael Chan if (wol->wolopts & WAKE_MAGIC) { 11685282db6cSMichael Chan if (!(bp->flags & BNXT_FLAG_WOL_CAP)) 11695282db6cSMichael Chan return -EINVAL; 11705282db6cSMichael Chan if (!bp->wol) { 11715282db6cSMichael Chan if (bnxt_hwrm_alloc_wol_fltr(bp)) 11725282db6cSMichael Chan return -EBUSY; 11735282db6cSMichael Chan bp->wol = 1; 11745282db6cSMichael Chan } 11755282db6cSMichael Chan } else { 11765282db6cSMichael Chan if (bp->wol) { 11775282db6cSMichael Chan if (bnxt_hwrm_free_wol_fltr(bp)) 11785282db6cSMichael Chan return -EBUSY; 11795282db6cSMichael Chan bp->wol = 0; 11805282db6cSMichael Chan } 11815282db6cSMichael Chan } 11825282db6cSMichael Chan return 0; 11835282db6cSMichael Chan } 11845282db6cSMichael Chan 1185170ce013SMichael Chan u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause) 1186c0c050c5SMichael Chan { 1187c0c050c5SMichael Chan u32 speed_mask = 0; 1188c0c050c5SMichael Chan 1189c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 1190c0c050c5SMichael Chan /* set the advertised speeds */ 1191c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 1192c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 1193c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 1194c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 1195c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 1196c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 1197c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 1198c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 1199c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 12001c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 120127c4d578SMichael Chan 120227c4d578SMichael Chan if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH) 120327c4d578SMichael Chan speed_mask |= ADVERTISED_Pause; 120427c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_TX) 120527c4d578SMichael Chan speed_mask |= ADVERTISED_Asym_Pause; 120627c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_RX) 120727c4d578SMichael Chan speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 120827c4d578SMichael Chan 1209c0c050c5SMichael Chan return speed_mask; 1210c0c050c5SMichael Chan } 1211c0c050c5SMichael Chan 121200c04a92SMichael Chan #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\ 121300c04a92SMichael Chan { \ 121400c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \ 121500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 121600c04a92SMichael Chan 100baseT_Full); \ 121700c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \ 121800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 121900c04a92SMichael Chan 1000baseT_Full); \ 122000c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \ 122100c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 122200c04a92SMichael Chan 10000baseT_Full); \ 122300c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \ 122400c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 122500c04a92SMichael Chan 25000baseCR_Full); \ 122600c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \ 122700c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 122800c04a92SMichael Chan 40000baseCR4_Full);\ 122900c04a92SMichael Chan if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \ 123000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 123100c04a92SMichael Chan 50000baseCR2_Full);\ 123238a21b34SDeepak Khungar if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \ 123338a21b34SDeepak Khungar ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 123438a21b34SDeepak Khungar 100000baseCR4_Full);\ 123500c04a92SMichael Chan if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \ 123600c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 123700c04a92SMichael Chan Pause); \ 123800c04a92SMichael Chan if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \ 123900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode( \ 124000c04a92SMichael Chan lk_ksettings, name, Asym_Pause);\ 124100c04a92SMichael Chan } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \ 124200c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 124300c04a92SMichael Chan Asym_Pause); \ 124400c04a92SMichael Chan } \ 124500c04a92SMichael Chan } 124600c04a92SMichael Chan 124700c04a92SMichael Chan #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \ 124800c04a92SMichael Chan { \ 124900c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 125000c04a92SMichael Chan 100baseT_Full) || \ 125100c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 125200c04a92SMichael Chan 100baseT_Half)) \ 125300c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \ 125400c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 125500c04a92SMichael Chan 1000baseT_Full) || \ 125600c04a92SMichael Chan ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 125700c04a92SMichael Chan 1000baseT_Half)) \ 125800c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \ 125900c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 126000c04a92SMichael Chan 10000baseT_Full)) \ 126100c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \ 126200c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 126300c04a92SMichael Chan 25000baseCR_Full)) \ 126400c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \ 126500c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 126600c04a92SMichael Chan 40000baseCR4_Full)) \ 126700c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \ 126800c04a92SMichael Chan if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 126900c04a92SMichael Chan 50000baseCR2_Full)) \ 127000c04a92SMichael Chan (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \ 127138a21b34SDeepak Khungar if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \ 127238a21b34SDeepak Khungar 100000baseCR4_Full)) \ 127338a21b34SDeepak Khungar (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \ 127400c04a92SMichael Chan } 127500c04a92SMichael Chan 127600c04a92SMichael Chan static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info, 127700c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 127827c4d578SMichael Chan { 127968515a18SMichael Chan u16 fw_speeds = link_info->advertising; 128027c4d578SMichael Chan u8 fw_pause = 0; 128127c4d578SMichael Chan 128227c4d578SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 128327c4d578SMichael Chan fw_pause = link_info->auto_pause_setting; 128427c4d578SMichael Chan 128500c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising); 128627c4d578SMichael Chan } 128727c4d578SMichael Chan 128800c04a92SMichael Chan static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info, 128900c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 12903277360eSMichael Chan { 12913277360eSMichael Chan u16 fw_speeds = link_info->lp_auto_link_speeds; 12923277360eSMichael Chan u8 fw_pause = 0; 12933277360eSMichael Chan 12943277360eSMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 12953277360eSMichael Chan fw_pause = link_info->lp_pause; 12963277360eSMichael Chan 129700c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, 129800c04a92SMichael Chan lp_advertising); 12993277360eSMichael Chan } 13003277360eSMichael Chan 130100c04a92SMichael Chan static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info, 130200c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 13034b32caccSMichael Chan { 13044b32caccSMichael Chan u16 fw_speeds = link_info->support_speeds; 13054b32caccSMichael Chan 130600c04a92SMichael Chan BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported); 13074b32caccSMichael Chan 130800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause); 130900c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 131000c04a92SMichael Chan Asym_Pause); 131193ed8117SMichael Chan 131200c04a92SMichael Chan if (link_info->support_auto_speeds) 131300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 131400c04a92SMichael Chan Autoneg); 131593ed8117SMichael Chan } 131693ed8117SMichael Chan 1317c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 1318c0c050c5SMichael Chan { 1319c0c050c5SMichael Chan switch (fw_link_speed) { 1320c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 1321c0c050c5SMichael Chan return SPEED_100; 1322c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 1323c0c050c5SMichael Chan return SPEED_1000; 1324c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 1325c0c050c5SMichael Chan return SPEED_2500; 1326c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 1327c0c050c5SMichael Chan return SPEED_10000; 1328c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 1329c0c050c5SMichael Chan return SPEED_20000; 1330c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 1331c0c050c5SMichael Chan return SPEED_25000; 1332c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 1333c0c050c5SMichael Chan return SPEED_40000; 1334c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 1335c0c050c5SMichael Chan return SPEED_50000; 133638a21b34SDeepak Khungar case BNXT_LINK_SPEED_100GB: 133738a21b34SDeepak Khungar return SPEED_100000; 1338c0c050c5SMichael Chan default: 1339c0c050c5SMichael Chan return SPEED_UNKNOWN; 1340c0c050c5SMichael Chan } 1341c0c050c5SMichael Chan } 1342c0c050c5SMichael Chan 134300c04a92SMichael Chan static int bnxt_get_link_ksettings(struct net_device *dev, 134400c04a92SMichael Chan struct ethtool_link_ksettings *lk_ksettings) 1345c0c050c5SMichael Chan { 1346c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1347c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 134800c04a92SMichael Chan struct ethtool_link_settings *base = &lk_ksettings->base; 134900c04a92SMichael Chan u32 ethtool_speed; 1350c0c050c5SMichael Chan 135100c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported); 1352e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 135300c04a92SMichael Chan bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings); 1354c0c050c5SMichael Chan 135500c04a92SMichael Chan ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising); 1356b763499eSMichael Chan if (link_info->autoneg) { 135700c04a92SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings); 135800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, 135900c04a92SMichael Chan advertising, Autoneg); 136000c04a92SMichael Chan base->autoneg = AUTONEG_ENABLE; 13613277360eSMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) 136200c04a92SMichael Chan bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings); 136329c262feSMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 136429c262feSMichael Chan if (!netif_carrier_ok(dev)) 136500c04a92SMichael Chan base->duplex = DUPLEX_UNKNOWN; 136629c262feSMichael Chan else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 136700c04a92SMichael Chan base->duplex = DUPLEX_FULL; 136829c262feSMichael Chan else 136900c04a92SMichael Chan base->duplex = DUPLEX_HALF; 1370c0c050c5SMichael Chan } else { 137100c04a92SMichael Chan base->autoneg = AUTONEG_DISABLE; 137229c262feSMichael Chan ethtool_speed = 137329c262feSMichael Chan bnxt_fw_to_ethtool_speed(link_info->req_link_speed); 137400c04a92SMichael Chan base->duplex = DUPLEX_HALF; 137529c262feSMichael Chan if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL) 137600c04a92SMichael Chan base->duplex = DUPLEX_FULL; 1377c0c050c5SMichael Chan } 137800c04a92SMichael Chan base->speed = ethtool_speed; 1379c0c050c5SMichael Chan 138000c04a92SMichael Chan base->port = PORT_NONE; 1381c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 138200c04a92SMichael Chan base->port = PORT_TP; 138300c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 138400c04a92SMichael Chan TP); 138500c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 138600c04a92SMichael Chan TP); 1387c0c050c5SMichael Chan } else { 138800c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, 138900c04a92SMichael Chan FIBRE); 139000c04a92SMichael Chan ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, 139100c04a92SMichael Chan FIBRE); 1392c0c050c5SMichael Chan 1393c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 139400c04a92SMichael Chan base->port = PORT_DA; 1395c0c050c5SMichael Chan else if (link_info->media_type == 1396c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 139700c04a92SMichael Chan base->port = PORT_FIBRE; 1398c0c050c5SMichael Chan } 139900c04a92SMichael Chan base->phy_address = link_info->phy_addr; 1400e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1401c0c050c5SMichael Chan 1402c0c050c5SMichael Chan return 0; 1403c0c050c5SMichael Chan } 1404c0c050c5SMichael Chan 140538a21b34SDeepak Khungar static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed) 1406c0c050c5SMichael Chan { 14079d9cee08SMichael Chan struct bnxt *bp = netdev_priv(dev); 14089d9cee08SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 14099d9cee08SMichael Chan u16 support_spds = link_info->support_speeds; 14109d9cee08SMichael Chan u32 fw_speed = 0; 14119d9cee08SMichael Chan 1412c0c050c5SMichael Chan switch (ethtool_speed) { 1413c0c050c5SMichael Chan case SPEED_100: 14149d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_100MB) 14159d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 14169d9cee08SMichael Chan break; 1417c0c050c5SMichael Chan case SPEED_1000: 14189d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_1GB) 14199d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 14209d9cee08SMichael Chan break; 1421c0c050c5SMichael Chan case SPEED_2500: 14229d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB) 14239d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 14249d9cee08SMichael Chan break; 1425c0c050c5SMichael Chan case SPEED_10000: 14269d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_10GB) 14279d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 14289d9cee08SMichael Chan break; 1429c0c050c5SMichael Chan case SPEED_20000: 14309d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_20GB) 14319d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 14329d9cee08SMichael Chan break; 1433c0c050c5SMichael Chan case SPEED_25000: 14349d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_25GB) 14359d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 14369d9cee08SMichael Chan break; 1437c0c050c5SMichael Chan case SPEED_40000: 14389d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_40GB) 14399d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 14409d9cee08SMichael Chan break; 1441c0c050c5SMichael Chan case SPEED_50000: 14429d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_50GB) 14439d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 14449d9cee08SMichael Chan break; 144538a21b34SDeepak Khungar case SPEED_100000: 144638a21b34SDeepak Khungar if (support_spds & BNXT_LINK_SPEED_MSK_100GB) 144738a21b34SDeepak Khungar fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB; 144838a21b34SDeepak Khungar break; 1449c0c050c5SMichael Chan default: 1450c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 1451c0c050c5SMichael Chan break; 1452c0c050c5SMichael Chan } 14539d9cee08SMichael Chan return fw_speed; 1454c0c050c5SMichael Chan } 1455c0c050c5SMichael Chan 1456939f7f0cSMichael Chan u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 1457c0c050c5SMichael Chan { 1458c0c050c5SMichael Chan u16 fw_speed_mask = 0; 1459c0c050c5SMichael Chan 1460c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 1461c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 1462c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 1463c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 1464c0c050c5SMichael Chan } 1465c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 1466c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 1467c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 1468c0c050c5SMichael Chan } 1469c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 1470c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 1471c0c050c5SMichael Chan 14721c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 14731c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 14741c49c421SMichael Chan 1475c0c050c5SMichael Chan return fw_speed_mask; 1476c0c050c5SMichael Chan } 1477c0c050c5SMichael Chan 147800c04a92SMichael Chan static int bnxt_set_link_ksettings(struct net_device *dev, 147900c04a92SMichael Chan const struct ethtool_link_ksettings *lk_ksettings) 1480c0c050c5SMichael Chan { 1481c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1482c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 148300c04a92SMichael Chan const struct ethtool_link_settings *base = &lk_ksettings->base; 1484c0c050c5SMichael Chan bool set_pause = false; 148568515a18SMichael Chan u16 fw_advertising = 0; 148668515a18SMichael Chan u32 speed; 148700c04a92SMichael Chan int rc = 0; 1488c0c050c5SMichael Chan 1489567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 149000c04a92SMichael Chan return -EOPNOTSUPP; 1491c0c050c5SMichael Chan 1492e2dc9b6eSMichael Chan mutex_lock(&bp->link_lock); 149300c04a92SMichael Chan if (base->autoneg == AUTONEG_ENABLE) { 149400c04a92SMichael Chan BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings, 149500c04a92SMichael Chan advertising); 1496c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 1497c0c050c5SMichael Chan if (!fw_advertising) 149893ed8117SMichael Chan link_info->advertising = link_info->support_auto_speeds; 1499c0c050c5SMichael Chan else 1500c0c050c5SMichael Chan link_info->advertising = fw_advertising; 1501c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 1502c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 1503c0c050c5SMichael Chan */ 1504c0c050c5SMichael Chan set_pause = true; 1505c0c050c5SMichael Chan } else { 15069d9cee08SMichael Chan u16 fw_speed; 150703efbec0SMichael Chan u8 phy_type = link_info->phy_type; 15089d9cee08SMichael Chan 150903efbec0SMichael Chan if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET || 151003efbec0SMichael Chan phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE || 151103efbec0SMichael Chan link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 151203efbec0SMichael Chan netdev_err(dev, "10GBase-T devices must autoneg\n"); 151303efbec0SMichael Chan rc = -EINVAL; 151403efbec0SMichael Chan goto set_setting_exit; 151503efbec0SMichael Chan } 151600c04a92SMichael Chan if (base->duplex == DUPLEX_HALF) { 1517c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 1518c0c050c5SMichael Chan rc = -EINVAL; 1519c0c050c5SMichael Chan goto set_setting_exit; 1520c0c050c5SMichael Chan } 152100c04a92SMichael Chan speed = base->speed; 15229d9cee08SMichael Chan fw_speed = bnxt_get_fw_speed(dev, speed); 15239d9cee08SMichael Chan if (!fw_speed) { 15249d9cee08SMichael Chan rc = -EINVAL; 15259d9cee08SMichael Chan goto set_setting_exit; 15269d9cee08SMichael Chan } 15279d9cee08SMichael Chan link_info->req_link_speed = fw_speed; 1528c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 1529b763499eSMichael Chan link_info->autoneg = 0; 1530c0c050c5SMichael Chan link_info->advertising = 0; 1531c0c050c5SMichael Chan } 1532c0c050c5SMichael Chan 1533c0c050c5SMichael Chan if (netif_running(dev)) 1534939f7f0cSMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause, false); 1535c0c050c5SMichael Chan 1536c0c050c5SMichael Chan set_setting_exit: 1537e2dc9b6eSMichael Chan mutex_unlock(&bp->link_lock); 1538c0c050c5SMichael Chan return rc; 1539c0c050c5SMichael Chan } 1540c0c050c5SMichael Chan 1541c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 1542c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1543c0c050c5SMichael Chan { 1544c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1545c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1546c0c050c5SMichael Chan 1547c0c050c5SMichael Chan if (BNXT_VF(bp)) 1548c0c050c5SMichael Chan return; 1549b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 15503c02d1bbSMichael Chan epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX); 15513c02d1bbSMichael Chan epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX); 1552c0c050c5SMichael Chan } 1553c0c050c5SMichael Chan 1554c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 1555c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 1556c0c050c5SMichael Chan { 1557c0c050c5SMichael Chan int rc = 0; 1558c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1559c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 1560c0c050c5SMichael Chan 1561567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 156275362a3fSMichael Chan return -EOPNOTSUPP; 1563c0c050c5SMichael Chan 1564c0c050c5SMichael Chan if (epause->autoneg) { 1565b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 1566b763499eSMichael Chan return -EINVAL; 1567b763499eSMichael Chan 1568c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 1569c9ee9516SMichael Chan if (bp->hwrm_spec_code >= 0x10201) 1570c9ee9516SMichael Chan link_info->req_flow_ctrl = 1571c9ee9516SMichael Chan PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; 1572c0c050c5SMichael Chan } else { 1573c0c050c5SMichael Chan /* when transition from auto pause to force pause, 1574c0c050c5SMichael Chan * force a link change 1575c0c050c5SMichael Chan */ 1576c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 1577c0c050c5SMichael Chan link_info->force_link_chng = true; 1578c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 1579c9ee9516SMichael Chan link_info->req_flow_ctrl = 0; 1580c0c050c5SMichael Chan } 1581c0c050c5SMichael Chan if (epause->rx_pause) 1582c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 1583c0c050c5SMichael Chan 1584c0c050c5SMichael Chan if (epause->tx_pause) 1585c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 1586c0c050c5SMichael Chan 1587c0c050c5SMichael Chan if (netif_running(dev)) 1588c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 1589c0c050c5SMichael Chan return rc; 1590c0c050c5SMichael Chan } 1591c0c050c5SMichael Chan 1592c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 1593c0c050c5SMichael Chan { 1594c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1595c0c050c5SMichael Chan 1596c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 1597c0c050c5SMichael Chan return bp->link_info.link_up; 1598c0c050c5SMichael Chan } 1599c0c050c5SMichael Chan 16005ac67d8bSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 16015ac67d8bSRob Swindell u16 ext, u16 *index, u32 *item_length, 16025ac67d8bSRob Swindell u32 *data_length); 16035ac67d8bSRob Swindell 1604c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 1605c0c050c5SMichael Chan u16 dir_type, 1606c0c050c5SMichael Chan u16 dir_ordinal, 1607c0c050c5SMichael Chan u16 dir_ext, 1608c0c050c5SMichael Chan u16 dir_attr, 1609c0c050c5SMichael Chan const u8 *data, 1610c0c050c5SMichael Chan size_t data_len) 1611c0c050c5SMichael Chan { 1612c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1613c0c050c5SMichael Chan int rc; 1614c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 1615c0c050c5SMichael Chan dma_addr_t dma_handle; 1616c0c050c5SMichael Chan u8 *kmem; 1617c0c050c5SMichael Chan 1618c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 1619c0c050c5SMichael Chan 1620c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 1621c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 1622c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 1623c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 1624c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 1625c0c050c5SMichael Chan 1626c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 1627c0c050c5SMichael Chan GFP_KERNEL); 1628c0c050c5SMichael Chan if (!kmem) { 1629c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1630c0c050c5SMichael Chan (unsigned)data_len); 1631c0c050c5SMichael Chan return -ENOMEM; 1632c0c050c5SMichael Chan } 1633c0c050c5SMichael Chan memcpy(kmem, data, data_len); 1634c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 1635c0c050c5SMichael Chan 1636c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 1637c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 1638c0c050c5SMichael Chan 16397c675421SVasundhara Volam if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 16407c675421SVasundhara Volam netdev_info(dev, 16417c675421SVasundhara Volam "PF does not have admin privileges to flash the device\n"); 16427c675421SVasundhara Volam rc = -EACCES; 16437c675421SVasundhara Volam } else if (rc) { 16447c675421SVasundhara Volam rc = -EIO; 16457c675421SVasundhara Volam } 1646c0c050c5SMichael Chan return rc; 1647c0c050c5SMichael Chan } 1648c0c050c5SMichael Chan 1649d2d6318cSRob Swindell static int bnxt_firmware_reset(struct net_device *dev, 1650d2d6318cSRob Swindell u16 dir_type) 1651d2d6318cSRob Swindell { 1652d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 16537c675421SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 16547c675421SVasundhara Volam int rc; 1655d2d6318cSRob Swindell 1656d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 1657d2d6318cSRob Swindell 1658d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 1659d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 1660d2d6318cSRob Swindell switch (dir_type) { 1661d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 1662d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 1663d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 1664d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 1665d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 1666d2d6318cSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1667d2d6318cSRob Swindell break; 1668d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 1669d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 1670d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 167108141e0bSRob Swindell /* Self-reset APE upon next PCIe reset: */ 167208141e0bSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 1673d2d6318cSRob Swindell break; 1674d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 1675d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 1676d2d6318cSRob Swindell req.embedded_proc_type = 1677d2d6318cSRob Swindell FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 1678d2d6318cSRob Swindell break; 1679d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 1680d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1681d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 1682d2d6318cSRob Swindell break; 168349f7972fSVasundhara Volam case BNXT_FW_RESET_CHIP: 168449f7972fSVasundhara Volam req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP; 168549f7972fSVasundhara Volam req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP; 168649f7972fSVasundhara Volam break; 16876502ad59SScott Branden case BNXT_FW_RESET_AP: 16886502ad59SScott Branden req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP; 16896502ad59SScott Branden break; 1690d2d6318cSRob Swindell default: 1691d2d6318cSRob Swindell return -EINVAL; 1692d2d6318cSRob Swindell } 1693d2d6318cSRob Swindell 16947c675421SVasundhara Volam rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 16957c675421SVasundhara Volam if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 16967c675421SVasundhara Volam netdev_info(dev, 16977c675421SVasundhara Volam "PF does not have admin privileges to reset the device\n"); 16987c675421SVasundhara Volam rc = -EACCES; 16997c675421SVasundhara Volam } else if (rc) { 17007c675421SVasundhara Volam rc = -EIO; 17017c675421SVasundhara Volam } 17027c675421SVasundhara Volam return rc; 1703d2d6318cSRob Swindell } 1704d2d6318cSRob Swindell 1705c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 1706c0c050c5SMichael Chan u16 dir_type, 1707c0c050c5SMichael Chan const u8 *fw_data, 1708c0c050c5SMichael Chan size_t fw_size) 1709c0c050c5SMichael Chan { 1710c0c050c5SMichael Chan int rc = 0; 1711c0c050c5SMichael Chan u16 code_type; 1712c0c050c5SMichael Chan u32 stored_crc; 1713c0c050c5SMichael Chan u32 calculated_crc; 1714c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 1715c0c050c5SMichael Chan 1716c0c050c5SMichael Chan switch (dir_type) { 1717c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1718c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1719c0c050c5SMichael Chan code_type = CODE_BOOT; 1720c0c050c5SMichael Chan break; 172193e0b4feSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 172293e0b4feSRob Swindell code_type = CODE_CHIMP_PATCH; 172393e0b4feSRob Swindell break; 17242731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 17252731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 17262731d70fSRob Swindell break; 172793e0b4feSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 172893e0b4feSRob Swindell code_type = CODE_APE_PATCH; 172993e0b4feSRob Swindell break; 173093e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_FW: 173193e0b4feSRob Swindell code_type = CODE_KONG_FW; 173293e0b4feSRob Swindell break; 173393e0b4feSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 173493e0b4feSRob Swindell code_type = CODE_KONG_PATCH; 173593e0b4feSRob Swindell break; 173693e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 173793e0b4feSRob Swindell code_type = CODE_BONO_FW; 173893e0b4feSRob Swindell break; 173993e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 174093e0b4feSRob Swindell code_type = CODE_BONO_PATCH; 174193e0b4feSRob Swindell break; 1742c0c050c5SMichael Chan default: 1743c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 1744c0c050c5SMichael Chan dir_type); 1745c0c050c5SMichael Chan return -EINVAL; 1746c0c050c5SMichael Chan } 1747c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 1748c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 1749c0c050c5SMichael Chan (unsigned int)fw_size); 1750c0c050c5SMichael Chan return -EINVAL; 1751c0c050c5SMichael Chan } 1752c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 1753c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 1754c0c050c5SMichael Chan le32_to_cpu(header->signature)); 1755c0c050c5SMichael Chan return -EINVAL; 1756c0c050c5SMichael Chan } 1757c0c050c5SMichael Chan if (header->code_type != code_type) { 1758c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 1759c0c050c5SMichael Chan code_type, header->code_type); 1760c0c050c5SMichael Chan return -EINVAL; 1761c0c050c5SMichael Chan } 1762c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 1763c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 1764c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 1765c0c050c5SMichael Chan return -EINVAL; 1766c0c050c5SMichael Chan } 1767c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 1768c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 1769c0c050c5SMichael Chan sizeof(stored_crc))); 1770c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 1771c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 1772c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 1773c0c050c5SMichael Chan (unsigned long)stored_crc, 1774c0c050c5SMichael Chan (unsigned long)calculated_crc); 1775c0c050c5SMichael Chan return -EINVAL; 1776c0c050c5SMichael Chan } 1777c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1778c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 1779d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 1780d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 1781d2d6318cSRob Swindell 1782c0c050c5SMichael Chan return rc; 1783c0c050c5SMichael Chan } 1784c0c050c5SMichael Chan 17855ac67d8bSRob Swindell static int bnxt_flash_microcode(struct net_device *dev, 17865ac67d8bSRob Swindell u16 dir_type, 17875ac67d8bSRob Swindell const u8 *fw_data, 17885ac67d8bSRob Swindell size_t fw_size) 17895ac67d8bSRob Swindell { 17905ac67d8bSRob Swindell struct bnxt_ucode_trailer *trailer; 17915ac67d8bSRob Swindell u32 calculated_crc; 17925ac67d8bSRob Swindell u32 stored_crc; 17935ac67d8bSRob Swindell int rc = 0; 17945ac67d8bSRob Swindell 17955ac67d8bSRob Swindell if (fw_size < sizeof(struct bnxt_ucode_trailer)) { 17965ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode file size: %u\n", 17975ac67d8bSRob Swindell (unsigned int)fw_size); 17985ac67d8bSRob Swindell return -EINVAL; 17995ac67d8bSRob Swindell } 18005ac67d8bSRob Swindell trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size - 18015ac67d8bSRob Swindell sizeof(*trailer))); 18025ac67d8bSRob Swindell if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) { 18035ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer signature: %08X\n", 18045ac67d8bSRob Swindell le32_to_cpu(trailer->sig)); 18055ac67d8bSRob Swindell return -EINVAL; 18065ac67d8bSRob Swindell } 18075ac67d8bSRob Swindell if (le16_to_cpu(trailer->dir_type) != dir_type) { 18085ac67d8bSRob Swindell netdev_err(dev, "Expected microcode type: %d, read: %d\n", 18095ac67d8bSRob Swindell dir_type, le16_to_cpu(trailer->dir_type)); 18105ac67d8bSRob Swindell return -EINVAL; 18115ac67d8bSRob Swindell } 18125ac67d8bSRob Swindell if (le16_to_cpu(trailer->trailer_length) < 18135ac67d8bSRob Swindell sizeof(struct bnxt_ucode_trailer)) { 18145ac67d8bSRob Swindell netdev_err(dev, "Invalid microcode trailer length: %d\n", 18155ac67d8bSRob Swindell le16_to_cpu(trailer->trailer_length)); 18165ac67d8bSRob Swindell return -EINVAL; 18175ac67d8bSRob Swindell } 18185ac67d8bSRob Swindell 18195ac67d8bSRob Swindell /* Confirm the CRC32 checksum of the file: */ 18205ac67d8bSRob Swindell stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 18215ac67d8bSRob Swindell sizeof(stored_crc))); 18225ac67d8bSRob Swindell calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 18235ac67d8bSRob Swindell if (calculated_crc != stored_crc) { 18245ac67d8bSRob Swindell netdev_err(dev, 18255ac67d8bSRob Swindell "CRC32 (%08lX) does not match calculated: %08lX\n", 18265ac67d8bSRob Swindell (unsigned long)stored_crc, 18275ac67d8bSRob Swindell (unsigned long)calculated_crc); 18285ac67d8bSRob Swindell return -EINVAL; 18295ac67d8bSRob Swindell } 18305ac67d8bSRob Swindell rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 18315ac67d8bSRob Swindell 0, 0, fw_data, fw_size); 18325ac67d8bSRob Swindell 18335ac67d8bSRob Swindell return rc; 18345ac67d8bSRob Swindell } 18355ac67d8bSRob Swindell 1836c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 1837c0c050c5SMichael Chan { 1838c0c050c5SMichael Chan switch (dir_type) { 1839c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 1840c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1841c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1842c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 1843c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 1844c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 1845c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 184693e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_FW: 184793e0b4feSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1848c0c050c5SMichael Chan return true; 1849c0c050c5SMichael Chan } 1850c0c050c5SMichael Chan 1851c0c050c5SMichael Chan return false; 1852c0c050c5SMichael Chan } 1853c0c050c5SMichael Chan 18545ac67d8bSRob Swindell static bool bnxt_dir_type_is_other_exec_format(u16 dir_type) 1855c0c050c5SMichael Chan { 1856c0c050c5SMichael Chan switch (dir_type) { 1857c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 1858c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 1859c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 1860c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 1861c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 1862c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 1863c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 1864c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 1865c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 1866c0c050c5SMichael Chan return true; 1867c0c050c5SMichael Chan } 1868c0c050c5SMichael Chan 1869c0c050c5SMichael Chan return false; 1870c0c050c5SMichael Chan } 1871c0c050c5SMichael Chan 1872c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 1873c0c050c5SMichael Chan { 1874c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 18755ac67d8bSRob Swindell bnxt_dir_type_is_other_exec_format(dir_type); 1876c0c050c5SMichael Chan } 1877c0c050c5SMichael Chan 1878c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 1879c0c050c5SMichael Chan u16 dir_type, 1880c0c050c5SMichael Chan const char *filename) 1881c0c050c5SMichael Chan { 1882c0c050c5SMichael Chan const struct firmware *fw; 1883c0c050c5SMichael Chan int rc; 1884c0c050c5SMichael Chan 1885c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 1886c0c050c5SMichael Chan if (rc != 0) { 1887c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 1888c0c050c5SMichael Chan rc, filename); 1889c0c050c5SMichael Chan return rc; 1890c0c050c5SMichael Chan } 1891c0c050c5SMichael Chan if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) 1892c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 18935ac67d8bSRob Swindell else if (bnxt_dir_type_is_other_exec_format(dir_type) == true) 18945ac67d8bSRob Swindell rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size); 1895c0c050c5SMichael Chan else 1896c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1897c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 1898c0c050c5SMichael Chan release_firmware(fw); 1899c0c050c5SMichael Chan return rc; 1900c0c050c5SMichael Chan } 1901c0c050c5SMichael Chan 1902c0c050c5SMichael Chan static int bnxt_flash_package_from_file(struct net_device *dev, 19035ac67d8bSRob Swindell char *filename, u32 install_type) 1904c0c050c5SMichael Chan { 19055ac67d8bSRob Swindell struct bnxt *bp = netdev_priv(dev); 19065ac67d8bSRob Swindell struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr; 19075ac67d8bSRob Swindell struct hwrm_nvm_install_update_input install = {0}; 19085ac67d8bSRob Swindell const struct firmware *fw; 19097c675421SVasundhara Volam int rc, hwrm_err = 0; 19105ac67d8bSRob Swindell u32 item_len; 19115ac67d8bSRob Swindell u16 index; 19125ac67d8bSRob Swindell 19135ac67d8bSRob Swindell bnxt_hwrm_fw_set_time(bp); 19145ac67d8bSRob Swindell 19155ac67d8bSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE, 19165ac67d8bSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 19175ac67d8bSRob Swindell &index, &item_len, NULL) != 0) { 19185ac67d8bSRob Swindell netdev_err(dev, "PKG update area not created in nvram\n"); 19195ac67d8bSRob Swindell return -ENOBUFS; 19205ac67d8bSRob Swindell } 19215ac67d8bSRob Swindell 19225ac67d8bSRob Swindell rc = request_firmware(&fw, filename, &dev->dev); 19235ac67d8bSRob Swindell if (rc != 0) { 19245ac67d8bSRob Swindell netdev_err(dev, "PKG error %d requesting file: %s\n", 19255ac67d8bSRob Swindell rc, filename); 19265ac67d8bSRob Swindell return rc; 19275ac67d8bSRob Swindell } 19285ac67d8bSRob Swindell 19295ac67d8bSRob Swindell if (fw->size > item_len) { 19305ac67d8bSRob Swindell netdev_err(dev, "PKG insufficient update area in nvram: %lu", 19315ac67d8bSRob Swindell (unsigned long)fw->size); 19325ac67d8bSRob Swindell rc = -EFBIG; 19335ac67d8bSRob Swindell } else { 19345ac67d8bSRob Swindell dma_addr_t dma_handle; 19355ac67d8bSRob Swindell u8 *kmem; 19365ac67d8bSRob Swindell struct hwrm_nvm_modify_input modify = {0}; 19375ac67d8bSRob Swindell 19385ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1); 19395ac67d8bSRob Swindell 19405ac67d8bSRob Swindell modify.dir_idx = cpu_to_le16(index); 19415ac67d8bSRob Swindell modify.len = cpu_to_le32(fw->size); 19425ac67d8bSRob Swindell 19435ac67d8bSRob Swindell kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size, 19445ac67d8bSRob Swindell &dma_handle, GFP_KERNEL); 19455ac67d8bSRob Swindell if (!kmem) { 19465ac67d8bSRob Swindell netdev_err(dev, 19475ac67d8bSRob Swindell "dma_alloc_coherent failure, length = %u\n", 19485ac67d8bSRob Swindell (unsigned int)fw->size); 19495ac67d8bSRob Swindell rc = -ENOMEM; 19505ac67d8bSRob Swindell } else { 19515ac67d8bSRob Swindell memcpy(kmem, fw->data, fw->size); 19525ac67d8bSRob Swindell modify.host_src_addr = cpu_to_le64(dma_handle); 19535ac67d8bSRob Swindell 19547c675421SVasundhara Volam hwrm_err = hwrm_send_message(bp, &modify, 19557c675421SVasundhara Volam sizeof(modify), 19565ac67d8bSRob Swindell FLASH_PACKAGE_TIMEOUT); 19575ac67d8bSRob Swindell dma_free_coherent(&bp->pdev->dev, fw->size, kmem, 19585ac67d8bSRob Swindell dma_handle); 19595ac67d8bSRob Swindell } 19605ac67d8bSRob Swindell } 19615ac67d8bSRob Swindell release_firmware(fw); 19627c675421SVasundhara Volam if (rc || hwrm_err) 19637c675421SVasundhara Volam goto err_exit; 19645ac67d8bSRob Swindell 19655ac67d8bSRob Swindell if ((install_type & 0xffff) == 0) 19665ac67d8bSRob Swindell install_type >>= 16; 19675ac67d8bSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1); 19685ac67d8bSRob Swindell install.install_type = cpu_to_le32(install_type); 19695ac67d8bSRob Swindell 1970cb4d1d62SKshitij Soni mutex_lock(&bp->hwrm_cmd_lock); 19717c675421SVasundhara Volam hwrm_err = _hwrm_send_message(bp, &install, sizeof(install), 19725ac67d8bSRob Swindell INSTALL_PACKAGE_TIMEOUT); 19737c675421SVasundhara Volam if (hwrm_err) 1974cb4d1d62SKshitij Soni goto flash_pkg_exit; 1975cb4d1d62SKshitij Soni 1976cb4d1d62SKshitij Soni if (resp->error_code) { 1977cb4d1d62SKshitij Soni u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err; 1978cb4d1d62SKshitij Soni 1979cb4d1d62SKshitij Soni if (error_code == NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) { 1980cb4d1d62SKshitij Soni install.flags |= cpu_to_le16( 1981cb4d1d62SKshitij Soni NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG); 19827c675421SVasundhara Volam hwrm_err = _hwrm_send_message(bp, &install, 19837c675421SVasundhara Volam sizeof(install), 1984cb4d1d62SKshitij Soni INSTALL_PACKAGE_TIMEOUT); 19857c675421SVasundhara Volam if (hwrm_err) 1986cb4d1d62SKshitij Soni goto flash_pkg_exit; 1987cb4d1d62SKshitij Soni } 1988cb4d1d62SKshitij Soni } 19895ac67d8bSRob Swindell 19905ac67d8bSRob Swindell if (resp->result) { 19915ac67d8bSRob Swindell netdev_err(dev, "PKG install error = %d, problem_item = %d\n", 19925ac67d8bSRob Swindell (s8)resp->result, (int)resp->problem_item); 1993cb4d1d62SKshitij Soni rc = -ENOPKG; 19945ac67d8bSRob Swindell } 1995cb4d1d62SKshitij Soni flash_pkg_exit: 1996cb4d1d62SKshitij Soni mutex_unlock(&bp->hwrm_cmd_lock); 19977c675421SVasundhara Volam err_exit: 19987c675421SVasundhara Volam if (hwrm_err == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 19997c675421SVasundhara Volam netdev_info(dev, 20007c675421SVasundhara Volam "PF does not have admin privileges to flash the device\n"); 20017c675421SVasundhara Volam rc = -EACCES; 20027c675421SVasundhara Volam } else if (hwrm_err) { 20037c675421SVasundhara Volam rc = -EOPNOTSUPP; 20047c675421SVasundhara Volam } 2005cb4d1d62SKshitij Soni return rc; 2006c0c050c5SMichael Chan } 2007c0c050c5SMichael Chan 2008c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 2009c0c050c5SMichael Chan struct ethtool_flash *flash) 2010c0c050c5SMichael Chan { 2011c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 2012c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 2013c0c050c5SMichael Chan return -EINVAL; 2014c0c050c5SMichael Chan } 2015c0c050c5SMichael Chan 20165ac67d8bSRob Swindell if (flash->region == ETHTOOL_FLASH_ALL_REGIONS || 20175ac67d8bSRob Swindell flash->region > 0xffff) 20185ac67d8bSRob Swindell return bnxt_flash_package_from_file(dev, flash->data, 20195ac67d8bSRob Swindell flash->region); 2020c0c050c5SMichael Chan 2021c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 2022c0c050c5SMichael Chan } 2023c0c050c5SMichael Chan 2024c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 2025c0c050c5SMichael Chan { 2026c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2027c0c050c5SMichael Chan int rc; 2028c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 2029c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 2030c0c050c5SMichael Chan 2031c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 2032c0c050c5SMichael Chan 2033c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2034c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2035c0c050c5SMichael Chan if (!rc) { 2036c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 2037c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 2038c0c050c5SMichael Chan } 2039c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2040c0c050c5SMichael Chan return rc; 2041c0c050c5SMichael Chan } 2042c0c050c5SMichael Chan 2043c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 2044c0c050c5SMichael Chan { 20454cebbacaSMichael Chan struct bnxt *bp = netdev_priv(dev); 20464cebbacaSMichael Chan 20474cebbacaSMichael Chan if (BNXT_VF(bp)) 20484cebbacaSMichael Chan return 0; 20494cebbacaSMichael Chan 2050c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 2051c0c050c5SMichael Chan * passed via the ethtool command-line utility. 2052c0c050c5SMichael Chan */ 2053c0c050c5SMichael Chan return -1; 2054c0c050c5SMichael Chan } 2055c0c050c5SMichael Chan 2056c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 2057c0c050c5SMichael Chan { 2058c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2059c0c050c5SMichael Chan int rc; 2060c0c050c5SMichael Chan u32 dir_entries; 2061c0c050c5SMichael Chan u32 entry_length; 2062c0c050c5SMichael Chan u8 *buf; 2063c0c050c5SMichael Chan size_t buflen; 2064c0c050c5SMichael Chan dma_addr_t dma_handle; 2065c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 2066c0c050c5SMichael Chan 2067c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 2068c0c050c5SMichael Chan if (rc != 0) 2069c0c050c5SMichael Chan return rc; 2070c0c050c5SMichael Chan 2071c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 2072c0c050c5SMichael Chan if (len < 2) 2073c0c050c5SMichael Chan return -EINVAL; 2074c0c050c5SMichael Chan 2075c0c050c5SMichael Chan *data++ = dir_entries; 2076c0c050c5SMichael Chan *data++ = entry_length; 2077c0c050c5SMichael Chan len -= 2; 2078c0c050c5SMichael Chan memset(data, 0xff, len); 2079c0c050c5SMichael Chan 2080c0c050c5SMichael Chan buflen = dir_entries * entry_length; 2081c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 2082c0c050c5SMichael Chan GFP_KERNEL); 2083c0c050c5SMichael Chan if (!buf) { 2084c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2085c0c050c5SMichael Chan (unsigned)buflen); 2086c0c050c5SMichael Chan return -ENOMEM; 2087c0c050c5SMichael Chan } 2088c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 2089c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2090c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2091c0c050c5SMichael Chan if (rc == 0) 2092c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 2093c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 2094c0c050c5SMichael Chan return rc; 2095c0c050c5SMichael Chan } 2096c0c050c5SMichael Chan 2097c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 2098c0c050c5SMichael Chan u32 length, u8 *data) 2099c0c050c5SMichael Chan { 2100c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2101c0c050c5SMichael Chan int rc; 2102c0c050c5SMichael Chan u8 *buf; 2103c0c050c5SMichael Chan dma_addr_t dma_handle; 2104c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 2105c0c050c5SMichael Chan 2106e0ad8fc5SMichael Chan if (!length) 2107e0ad8fc5SMichael Chan return -EINVAL; 2108e0ad8fc5SMichael Chan 2109c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 2110c0c050c5SMichael Chan GFP_KERNEL); 2111c0c050c5SMichael Chan if (!buf) { 2112c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 2113c0c050c5SMichael Chan (unsigned)length); 2114c0c050c5SMichael Chan return -ENOMEM; 2115c0c050c5SMichael Chan } 2116c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 2117c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 2118c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2119c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 2120c0c050c5SMichael Chan req.len = cpu_to_le32(length); 2121c0c050c5SMichael Chan 2122c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2123c0c050c5SMichael Chan if (rc == 0) 2124c0c050c5SMichael Chan memcpy(data, buf, length); 2125c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 2126c0c050c5SMichael Chan return rc; 2127c0c050c5SMichael Chan } 2128c0c050c5SMichael Chan 21293ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 21303ebf6f0aSRob Swindell u16 ext, u16 *index, u32 *item_length, 21313ebf6f0aSRob Swindell u32 *data_length) 21323ebf6f0aSRob Swindell { 21333ebf6f0aSRob Swindell struct bnxt *bp = netdev_priv(dev); 21343ebf6f0aSRob Swindell int rc; 21353ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_input req = {0}; 21363ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr; 21373ebf6f0aSRob Swindell 21383ebf6f0aSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1); 21393ebf6f0aSRob Swindell req.enables = 0; 21403ebf6f0aSRob Swindell req.dir_idx = 0; 21413ebf6f0aSRob Swindell req.dir_type = cpu_to_le16(type); 21423ebf6f0aSRob Swindell req.dir_ordinal = cpu_to_le16(ordinal); 21433ebf6f0aSRob Swindell req.dir_ext = cpu_to_le16(ext); 21443ebf6f0aSRob Swindell req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ; 2145cc72f3b1SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2146cc72f3b1SMichael Chan rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 21473ebf6f0aSRob Swindell if (rc == 0) { 21483ebf6f0aSRob Swindell if (index) 21493ebf6f0aSRob Swindell *index = le16_to_cpu(output->dir_idx); 21503ebf6f0aSRob Swindell if (item_length) 21513ebf6f0aSRob Swindell *item_length = le32_to_cpu(output->dir_item_length); 21523ebf6f0aSRob Swindell if (data_length) 21533ebf6f0aSRob Swindell *data_length = le32_to_cpu(output->dir_data_length); 21543ebf6f0aSRob Swindell } 2155cc72f3b1SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 21563ebf6f0aSRob Swindell return rc; 21573ebf6f0aSRob Swindell } 21583ebf6f0aSRob Swindell 21593ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen) 21603ebf6f0aSRob Swindell { 21613ebf6f0aSRob Swindell char *retval = NULL; 21623ebf6f0aSRob Swindell char *p; 21633ebf6f0aSRob Swindell char *value; 21643ebf6f0aSRob Swindell int field = 0; 21653ebf6f0aSRob Swindell 21663ebf6f0aSRob Swindell if (datalen < 1) 21673ebf6f0aSRob Swindell return NULL; 21683ebf6f0aSRob Swindell /* null-terminate the log data (removing last '\n'): */ 21693ebf6f0aSRob Swindell data[datalen - 1] = 0; 21703ebf6f0aSRob Swindell for (p = data; *p != 0; p++) { 21713ebf6f0aSRob Swindell field = 0; 21723ebf6f0aSRob Swindell retval = NULL; 21733ebf6f0aSRob Swindell while (*p != 0 && *p != '\n') { 21743ebf6f0aSRob Swindell value = p; 21753ebf6f0aSRob Swindell while (*p != 0 && *p != '\t' && *p != '\n') 21763ebf6f0aSRob Swindell p++; 21773ebf6f0aSRob Swindell if (field == desired_field) 21783ebf6f0aSRob Swindell retval = value; 21793ebf6f0aSRob Swindell if (*p != '\t') 21803ebf6f0aSRob Swindell break; 21813ebf6f0aSRob Swindell *p = 0; 21823ebf6f0aSRob Swindell field++; 21833ebf6f0aSRob Swindell p++; 21843ebf6f0aSRob Swindell } 21853ebf6f0aSRob Swindell if (*p == 0) 21863ebf6f0aSRob Swindell break; 21873ebf6f0aSRob Swindell *p = 0; 21883ebf6f0aSRob Swindell } 21893ebf6f0aSRob Swindell return retval; 21903ebf6f0aSRob Swindell } 21913ebf6f0aSRob Swindell 2192a60faa60SVasundhara Volam static void bnxt_get_pkgver(struct net_device *dev) 21933ebf6f0aSRob Swindell { 2194a60faa60SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 21953ebf6f0aSRob Swindell u16 index = 0; 2196a60faa60SVasundhara Volam char *pkgver; 2197a60faa60SVasundhara Volam u32 pkglen; 2198a60faa60SVasundhara Volam u8 *pkgbuf; 2199a60faa60SVasundhara Volam int len; 22003ebf6f0aSRob Swindell 22013ebf6f0aSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG, 22023ebf6f0aSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 2203a60faa60SVasundhara Volam &index, NULL, &pkglen) != 0) 2204a60faa60SVasundhara Volam return; 22053ebf6f0aSRob Swindell 2206a60faa60SVasundhara Volam pkgbuf = kzalloc(pkglen, GFP_KERNEL); 2207a60faa60SVasundhara Volam if (!pkgbuf) { 2208a60faa60SVasundhara Volam dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n", 2209a60faa60SVasundhara Volam pkglen); 2210a60faa60SVasundhara Volam return; 2211a60faa60SVasundhara Volam } 22123ebf6f0aSRob Swindell 2213a60faa60SVasundhara Volam if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf)) 2214a60faa60SVasundhara Volam goto err; 2215a60faa60SVasundhara Volam 2216a60faa60SVasundhara Volam pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf, 2217a60faa60SVasundhara Volam pkglen); 2218a60faa60SVasundhara Volam if (pkgver && *pkgver != 0 && isdigit(*pkgver)) { 2219a60faa60SVasundhara Volam len = strlen(bp->fw_ver_str); 2220a60faa60SVasundhara Volam snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1, 2221a60faa60SVasundhara Volam "/pkg %s", pkgver); 2222a60faa60SVasundhara Volam } 2223a60faa60SVasundhara Volam err: 2224a60faa60SVasundhara Volam kfree(pkgbuf); 22253ebf6f0aSRob Swindell } 22263ebf6f0aSRob Swindell 2227c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 2228c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2229c0c050c5SMichael Chan u8 *data) 2230c0c050c5SMichael Chan { 2231c0c050c5SMichael Chan u32 index; 2232c0c050c5SMichael Chan u32 offset; 2233c0c050c5SMichael Chan 2234c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 2235c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 2236c0c050c5SMichael Chan 2237c0c050c5SMichael Chan index = eeprom->offset >> 24; 2238c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 2239c0c050c5SMichael Chan 2240c0c050c5SMichael Chan if (index == 0) { 2241c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 2242c0c050c5SMichael Chan return -EINVAL; 2243c0c050c5SMichael Chan } 2244c0c050c5SMichael Chan 2245c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 2246c0c050c5SMichael Chan } 2247c0c050c5SMichael Chan 2248c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 2249c0c050c5SMichael Chan { 2250c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2251c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 2252c0c050c5SMichael Chan 2253c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 2254c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 2255c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2256c0c050c5SMichael Chan } 2257c0c050c5SMichael Chan 2258c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 2259c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 2260c0c050c5SMichael Chan u8 *data) 2261c0c050c5SMichael Chan { 2262c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 2263c0c050c5SMichael Chan u8 index, dir_op; 2264c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 2265c0c050c5SMichael Chan 2266c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 2267c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 2268c0c050c5SMichael Chan return -EINVAL; 2269c0c050c5SMichael Chan } 2270c0c050c5SMichael Chan 2271c0c050c5SMichael Chan type = eeprom->magic >> 16; 2272c0c050c5SMichael Chan 2273c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 2274c0c050c5SMichael Chan index = eeprom->magic & 0xff; 2275c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 2276c0c050c5SMichael Chan if (index == 0) 2277c0c050c5SMichael Chan return -EINVAL; 2278c0c050c5SMichael Chan switch (dir_op) { 2279c0c050c5SMichael Chan case 0x0e: /* erase */ 2280c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 2281c0c050c5SMichael Chan return -EINVAL; 2282c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 2283c0c050c5SMichael Chan default: 2284c0c050c5SMichael Chan return -EINVAL; 2285c0c050c5SMichael Chan } 2286c0c050c5SMichael Chan } 2287c0c050c5SMichael Chan 2288c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 2289c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(type) == true) 22905ac67d8bSRob Swindell return -EOPNOTSUPP; 2291c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 2292c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 2293c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 2294c0c050c5SMichael Chan 2295c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 2296c0c050c5SMichael Chan eeprom->len); 2297c0c050c5SMichael Chan } 2298c0c050c5SMichael Chan 229972b34f04SMichael Chan static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata) 230072b34f04SMichael Chan { 230172b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 230272b34f04SMichael Chan struct ethtool_eee *eee = &bp->eee; 230372b34f04SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 230472b34f04SMichael Chan u32 advertising = 230572b34f04SMichael Chan _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); 230672b34f04SMichael Chan int rc = 0; 230772b34f04SMichael Chan 2308567b2abeSSatish Baddipadige if (!BNXT_SINGLE_PF(bp)) 230975362a3fSMichael Chan return -EOPNOTSUPP; 231072b34f04SMichael Chan 231172b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 231272b34f04SMichael Chan return -EOPNOTSUPP; 231372b34f04SMichael Chan 231472b34f04SMichael Chan if (!edata->eee_enabled) 231572b34f04SMichael Chan goto eee_ok; 231672b34f04SMichael Chan 231772b34f04SMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { 231872b34f04SMichael Chan netdev_warn(dev, "EEE requires autoneg\n"); 231972b34f04SMichael Chan return -EINVAL; 232072b34f04SMichael Chan } 232172b34f04SMichael Chan if (edata->tx_lpi_enabled) { 232272b34f04SMichael Chan if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi || 232372b34f04SMichael Chan edata->tx_lpi_timer < bp->lpi_tmr_lo)) { 232472b34f04SMichael Chan netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n", 232572b34f04SMichael Chan bp->lpi_tmr_lo, bp->lpi_tmr_hi); 232672b34f04SMichael Chan return -EINVAL; 232772b34f04SMichael Chan } else if (!bp->lpi_tmr_hi) { 232872b34f04SMichael Chan edata->tx_lpi_timer = eee->tx_lpi_timer; 232972b34f04SMichael Chan } 233072b34f04SMichael Chan } 233172b34f04SMichael Chan if (!edata->advertised) { 233272b34f04SMichael Chan edata->advertised = advertising & eee->supported; 233372b34f04SMichael Chan } else if (edata->advertised & ~advertising) { 233472b34f04SMichael Chan netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", 233572b34f04SMichael Chan edata->advertised, advertising); 233672b34f04SMichael Chan return -EINVAL; 233772b34f04SMichael Chan } 233872b34f04SMichael Chan 233972b34f04SMichael Chan eee->advertised = edata->advertised; 234072b34f04SMichael Chan eee->tx_lpi_enabled = edata->tx_lpi_enabled; 234172b34f04SMichael Chan eee->tx_lpi_timer = edata->tx_lpi_timer; 234272b34f04SMichael Chan eee_ok: 234372b34f04SMichael Chan eee->eee_enabled = edata->eee_enabled; 234472b34f04SMichael Chan 234572b34f04SMichael Chan if (netif_running(dev)) 234672b34f04SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, false, true); 234772b34f04SMichael Chan 234872b34f04SMichael Chan return rc; 234972b34f04SMichael Chan } 235072b34f04SMichael Chan 235172b34f04SMichael Chan static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata) 235272b34f04SMichael Chan { 235372b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 235472b34f04SMichael Chan 235572b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 235672b34f04SMichael Chan return -EOPNOTSUPP; 235772b34f04SMichael Chan 235872b34f04SMichael Chan *edata = bp->eee; 235972b34f04SMichael Chan if (!bp->eee.eee_enabled) { 236072b34f04SMichael Chan /* Preserve tx_lpi_timer so that the last value will be used 236172b34f04SMichael Chan * by default when it is re-enabled. 236272b34f04SMichael Chan */ 236372b34f04SMichael Chan edata->advertised = 0; 236472b34f04SMichael Chan edata->tx_lpi_enabled = 0; 236572b34f04SMichael Chan } 236672b34f04SMichael Chan 236772b34f04SMichael Chan if (!bp->eee.eee_active) 236872b34f04SMichael Chan edata->lp_advertised = 0; 236972b34f04SMichael Chan 237072b34f04SMichael Chan return 0; 237172b34f04SMichael Chan } 237272b34f04SMichael Chan 237342ee18feSAjit Khaparde static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr, 237442ee18feSAjit Khaparde u16 page_number, u16 start_addr, 237542ee18feSAjit Khaparde u16 data_length, u8 *buf) 237642ee18feSAjit Khaparde { 237742ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_input req = {0}; 237842ee18feSAjit Khaparde struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr; 237942ee18feSAjit Khaparde int rc, byte_offset = 0; 238042ee18feSAjit Khaparde 238142ee18feSAjit Khaparde bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1); 238242ee18feSAjit Khaparde req.i2c_slave_addr = i2c_addr; 238342ee18feSAjit Khaparde req.page_number = cpu_to_le16(page_number); 238442ee18feSAjit Khaparde req.port_id = cpu_to_le16(bp->pf.port_id); 238542ee18feSAjit Khaparde do { 238642ee18feSAjit Khaparde u16 xfer_size; 238742ee18feSAjit Khaparde 238842ee18feSAjit Khaparde xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE); 238942ee18feSAjit Khaparde data_length -= xfer_size; 239042ee18feSAjit Khaparde req.page_offset = cpu_to_le16(start_addr + byte_offset); 239142ee18feSAjit Khaparde req.data_length = xfer_size; 239242ee18feSAjit Khaparde req.enables = cpu_to_le32(start_addr + byte_offset ? 239342ee18feSAjit Khaparde PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0); 239442ee18feSAjit Khaparde mutex_lock(&bp->hwrm_cmd_lock); 239542ee18feSAjit Khaparde rc = _hwrm_send_message(bp, &req, sizeof(req), 239642ee18feSAjit Khaparde HWRM_CMD_TIMEOUT); 239742ee18feSAjit Khaparde if (!rc) 239842ee18feSAjit Khaparde memcpy(buf + byte_offset, output->data, xfer_size); 239942ee18feSAjit Khaparde mutex_unlock(&bp->hwrm_cmd_lock); 240042ee18feSAjit Khaparde byte_offset += xfer_size; 240142ee18feSAjit Khaparde } while (!rc && data_length > 0); 240242ee18feSAjit Khaparde 240342ee18feSAjit Khaparde return rc; 240442ee18feSAjit Khaparde } 240542ee18feSAjit Khaparde 240642ee18feSAjit Khaparde static int bnxt_get_module_info(struct net_device *dev, 240742ee18feSAjit Khaparde struct ethtool_modinfo *modinfo) 240842ee18feSAjit Khaparde { 24097328a23cSVasundhara Volam u8 data[SFF_DIAG_SUPPORT_OFFSET + 1]; 241042ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 241142ee18feSAjit Khaparde int rc; 241242ee18feSAjit Khaparde 241342ee18feSAjit Khaparde /* No point in going further if phy status indicates 241442ee18feSAjit Khaparde * module is not inserted or if it is powered down or 241542ee18feSAjit Khaparde * if it is of type 10GBase-T 241642ee18feSAjit Khaparde */ 241742ee18feSAjit Khaparde if (bp->link_info.module_status > 241842ee18feSAjit Khaparde PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG) 241942ee18feSAjit Khaparde return -EOPNOTSUPP; 242042ee18feSAjit Khaparde 242142ee18feSAjit Khaparde /* This feature is not supported in older firmware versions */ 242242ee18feSAjit Khaparde if (bp->hwrm_spec_code < 0x10202) 242342ee18feSAjit Khaparde return -EOPNOTSUPP; 242442ee18feSAjit Khaparde 24257328a23cSVasundhara Volam rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0, 24267328a23cSVasundhara Volam SFF_DIAG_SUPPORT_OFFSET + 1, 24277328a23cSVasundhara Volam data); 242842ee18feSAjit Khaparde if (!rc) { 24297328a23cSVasundhara Volam u8 module_id = data[0]; 24307328a23cSVasundhara Volam u8 diag_supported = data[SFF_DIAG_SUPPORT_OFFSET]; 243142ee18feSAjit Khaparde 243242ee18feSAjit Khaparde switch (module_id) { 243342ee18feSAjit Khaparde case SFF_MODULE_ID_SFP: 243442ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8472; 243542ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 24367328a23cSVasundhara Volam if (!diag_supported) 24377328a23cSVasundhara Volam modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 243842ee18feSAjit Khaparde break; 243942ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP: 244042ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP_PLUS: 244142ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8436; 244242ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 244342ee18feSAjit Khaparde break; 244442ee18feSAjit Khaparde case SFF_MODULE_ID_QSFP28: 244542ee18feSAjit Khaparde modinfo->type = ETH_MODULE_SFF_8636; 244642ee18feSAjit Khaparde modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; 244742ee18feSAjit Khaparde break; 244842ee18feSAjit Khaparde default: 244942ee18feSAjit Khaparde rc = -EOPNOTSUPP; 245042ee18feSAjit Khaparde break; 245142ee18feSAjit Khaparde } 245242ee18feSAjit Khaparde } 245342ee18feSAjit Khaparde return rc; 245442ee18feSAjit Khaparde } 245542ee18feSAjit Khaparde 245642ee18feSAjit Khaparde static int bnxt_get_module_eeprom(struct net_device *dev, 245742ee18feSAjit Khaparde struct ethtool_eeprom *eeprom, 245842ee18feSAjit Khaparde u8 *data) 245942ee18feSAjit Khaparde { 246042ee18feSAjit Khaparde struct bnxt *bp = netdev_priv(dev); 246142ee18feSAjit Khaparde u16 start = eeprom->offset, length = eeprom->len; 2462f3ea3119SColin Ian King int rc = 0; 246342ee18feSAjit Khaparde 246442ee18feSAjit Khaparde memset(data, 0, eeprom->len); 246542ee18feSAjit Khaparde 246642ee18feSAjit Khaparde /* Read A0 portion of the EEPROM */ 246742ee18feSAjit Khaparde if (start < ETH_MODULE_SFF_8436_LEN) { 246842ee18feSAjit Khaparde if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN) 246942ee18feSAjit Khaparde length = ETH_MODULE_SFF_8436_LEN - start; 247042ee18feSAjit Khaparde rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 247142ee18feSAjit Khaparde start, length, data); 247242ee18feSAjit Khaparde if (rc) 247342ee18feSAjit Khaparde return rc; 247442ee18feSAjit Khaparde start += length; 247542ee18feSAjit Khaparde data += length; 247642ee18feSAjit Khaparde length = eeprom->len - length; 247742ee18feSAjit Khaparde } 247842ee18feSAjit Khaparde 247942ee18feSAjit Khaparde /* Read A2 portion of the EEPROM */ 248042ee18feSAjit Khaparde if (length) { 248142ee18feSAjit Khaparde start -= ETH_MODULE_SFF_8436_LEN; 2482dea521a2SChristophe JAILLET rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1, 2483dea521a2SChristophe JAILLET start, length, data); 248442ee18feSAjit Khaparde } 248542ee18feSAjit Khaparde return rc; 248642ee18feSAjit Khaparde } 248742ee18feSAjit Khaparde 2488ae8e98a6SDeepak Khungar static int bnxt_nway_reset(struct net_device *dev) 2489ae8e98a6SDeepak Khungar { 2490ae8e98a6SDeepak Khungar int rc = 0; 2491ae8e98a6SDeepak Khungar 2492ae8e98a6SDeepak Khungar struct bnxt *bp = netdev_priv(dev); 2493ae8e98a6SDeepak Khungar struct bnxt_link_info *link_info = &bp->link_info; 2494ae8e98a6SDeepak Khungar 2495ae8e98a6SDeepak Khungar if (!BNXT_SINGLE_PF(bp)) 2496ae8e98a6SDeepak Khungar return -EOPNOTSUPP; 2497ae8e98a6SDeepak Khungar 2498ae8e98a6SDeepak Khungar if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 2499ae8e98a6SDeepak Khungar return -EINVAL; 2500ae8e98a6SDeepak Khungar 2501ae8e98a6SDeepak Khungar if (netif_running(dev)) 2502ae8e98a6SDeepak Khungar rc = bnxt_hwrm_set_link_setting(bp, true, false); 2503ae8e98a6SDeepak Khungar 2504ae8e98a6SDeepak Khungar return rc; 2505ae8e98a6SDeepak Khungar } 2506ae8e98a6SDeepak Khungar 25075ad2cbeeSMichael Chan static int bnxt_set_phys_id(struct net_device *dev, 25085ad2cbeeSMichael Chan enum ethtool_phys_id_state state) 25095ad2cbeeSMichael Chan { 25105ad2cbeeSMichael Chan struct hwrm_port_led_cfg_input req = {0}; 25115ad2cbeeSMichael Chan struct bnxt *bp = netdev_priv(dev); 25125ad2cbeeSMichael Chan struct bnxt_pf_info *pf = &bp->pf; 25135ad2cbeeSMichael Chan struct bnxt_led_cfg *led_cfg; 25145ad2cbeeSMichael Chan u8 led_state; 25155ad2cbeeSMichael Chan __le16 duration; 25165ad2cbeeSMichael Chan int i, rc; 25175ad2cbeeSMichael Chan 25185ad2cbeeSMichael Chan if (!bp->num_leds || BNXT_VF(bp)) 25195ad2cbeeSMichael Chan return -EOPNOTSUPP; 25205ad2cbeeSMichael Chan 25215ad2cbeeSMichael Chan if (state == ETHTOOL_ID_ACTIVE) { 25225ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT; 25235ad2cbeeSMichael Chan duration = cpu_to_le16(500); 25245ad2cbeeSMichael Chan } else if (state == ETHTOOL_ID_INACTIVE) { 25255ad2cbeeSMichael Chan led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT; 25265ad2cbeeSMichael Chan duration = cpu_to_le16(0); 25275ad2cbeeSMichael Chan } else { 25285ad2cbeeSMichael Chan return -EINVAL; 25295ad2cbeeSMichael Chan } 25305ad2cbeeSMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1); 25315ad2cbeeSMichael Chan req.port_id = cpu_to_le16(pf->port_id); 25325ad2cbeeSMichael Chan req.num_leds = bp->num_leds; 25335ad2cbeeSMichael Chan led_cfg = (struct bnxt_led_cfg *)&req.led0_id; 25345ad2cbeeSMichael Chan for (i = 0; i < bp->num_leds; i++, led_cfg++) { 25355ad2cbeeSMichael Chan req.enables |= BNXT_LED_DFLT_ENABLES(i); 25365ad2cbeeSMichael Chan led_cfg->led_id = bp->leds[i].led_id; 25375ad2cbeeSMichael Chan led_cfg->led_state = led_state; 25385ad2cbeeSMichael Chan led_cfg->led_blink_on = duration; 25395ad2cbeeSMichael Chan led_cfg->led_blink_off = duration; 25405ad2cbeeSMichael Chan led_cfg->led_group_id = bp->leds[i].led_group_id; 25415ad2cbeeSMichael Chan } 25425ad2cbeeSMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 25435ad2cbeeSMichael Chan if (rc) 25445ad2cbeeSMichael Chan rc = -EIO; 25455ad2cbeeSMichael Chan return rc; 25465ad2cbeeSMichael Chan } 25475ad2cbeeSMichael Chan 254867fea463SMichael Chan static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring) 254967fea463SMichael Chan { 255067fea463SMichael Chan struct hwrm_selftest_irq_input req = {0}; 255167fea463SMichael Chan 255267fea463SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1); 255367fea463SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 255467fea463SMichael Chan } 255567fea463SMichael Chan 255667fea463SMichael Chan static int bnxt_test_irq(struct bnxt *bp) 255767fea463SMichael Chan { 255867fea463SMichael Chan int i; 255967fea463SMichael Chan 256067fea463SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 256167fea463SMichael Chan u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id; 256267fea463SMichael Chan int rc; 256367fea463SMichael Chan 256467fea463SMichael Chan rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring); 256567fea463SMichael Chan if (rc) 256667fea463SMichael Chan return rc; 256767fea463SMichael Chan } 256867fea463SMichael Chan return 0; 256967fea463SMichael Chan } 257067fea463SMichael Chan 2571f7dc1ea6SMichael Chan static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable) 2572f7dc1ea6SMichael Chan { 2573f7dc1ea6SMichael Chan struct hwrm_port_mac_cfg_input req = {0}; 2574f7dc1ea6SMichael Chan 2575f7dc1ea6SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1); 2576f7dc1ea6SMichael Chan 2577f7dc1ea6SMichael Chan req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK); 2578f7dc1ea6SMichael Chan if (enable) 2579f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL; 2580f7dc1ea6SMichael Chan else 2581f7dc1ea6SMichael Chan req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE; 2582f7dc1ea6SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2583f7dc1ea6SMichael Chan } 2584f7dc1ea6SMichael Chan 258591725d89SMichael Chan static int bnxt_disable_an_for_lpbk(struct bnxt *bp, 258691725d89SMichael Chan struct hwrm_port_phy_cfg_input *req) 258791725d89SMichael Chan { 258891725d89SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 258991725d89SMichael Chan u16 fw_advertising = link_info->advertising; 259091725d89SMichael Chan u16 fw_speed; 259191725d89SMichael Chan int rc; 259291725d89SMichael Chan 259391725d89SMichael Chan if (!link_info->autoneg) 259491725d89SMichael Chan return 0; 259591725d89SMichael Chan 259691725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB; 259791725d89SMichael Chan if (netif_carrier_ok(bp->dev)) 259891725d89SMichael Chan fw_speed = bp->link_info.link_speed; 259991725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB) 260091725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB; 260191725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB) 260291725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB; 260391725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB) 260491725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB; 260591725d89SMichael Chan else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB) 260691725d89SMichael Chan fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB; 260791725d89SMichael Chan 260891725d89SMichael Chan req->force_link_speed = cpu_to_le16(fw_speed); 260991725d89SMichael Chan req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE | 261091725d89SMichael Chan PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); 261191725d89SMichael Chan rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT); 261291725d89SMichael Chan req->flags = 0; 261391725d89SMichael Chan req->force_link_speed = cpu_to_le16(0); 261491725d89SMichael Chan return rc; 261591725d89SMichael Chan } 261691725d89SMichael Chan 261755fd0cf3SMichael Chan static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable, bool ext) 261891725d89SMichael Chan { 261991725d89SMichael Chan struct hwrm_port_phy_cfg_input req = {0}; 262091725d89SMichael Chan 262191725d89SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); 262291725d89SMichael Chan 262391725d89SMichael Chan if (enable) { 262491725d89SMichael Chan bnxt_disable_an_for_lpbk(bp, &req); 262555fd0cf3SMichael Chan if (ext) 262655fd0cf3SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_EXTERNAL; 262755fd0cf3SMichael Chan else 262891725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL; 262991725d89SMichael Chan } else { 263091725d89SMichael Chan req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE; 263191725d89SMichael Chan } 263291725d89SMichael Chan req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK); 263391725d89SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 263491725d89SMichael Chan } 263591725d89SMichael Chan 2636e44758b7SMichael Chan static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2637f7dc1ea6SMichael Chan u32 raw_cons, int pkt_size) 2638f7dc1ea6SMichael Chan { 2639e44758b7SMichael Chan struct bnxt_napi *bnapi = cpr->bnapi; 2640e44758b7SMichael Chan struct bnxt_rx_ring_info *rxr; 2641f7dc1ea6SMichael Chan struct bnxt_sw_rx_bd *rx_buf; 2642f7dc1ea6SMichael Chan struct rx_cmp *rxcmp; 2643f7dc1ea6SMichael Chan u16 cp_cons, cons; 2644f7dc1ea6SMichael Chan u8 *data; 2645f7dc1ea6SMichael Chan u32 len; 2646f7dc1ea6SMichael Chan int i; 2647f7dc1ea6SMichael Chan 2648e44758b7SMichael Chan rxr = bnapi->rx_ring; 2649f7dc1ea6SMichael Chan cp_cons = RING_CMP(raw_cons); 2650f7dc1ea6SMichael Chan rxcmp = (struct rx_cmp *) 2651f7dc1ea6SMichael Chan &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; 2652f7dc1ea6SMichael Chan cons = rxcmp->rx_cmp_opaque; 2653f7dc1ea6SMichael Chan rx_buf = &rxr->rx_buf_ring[cons]; 2654f7dc1ea6SMichael Chan data = rx_buf->data_ptr; 2655f7dc1ea6SMichael Chan len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT; 2656f7dc1ea6SMichael Chan if (len != pkt_size) 2657f7dc1ea6SMichael Chan return -EIO; 2658f7dc1ea6SMichael Chan i = ETH_ALEN; 2659f7dc1ea6SMichael Chan if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr)) 2660f7dc1ea6SMichael Chan return -EIO; 2661f7dc1ea6SMichael Chan i += ETH_ALEN; 2662f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) { 2663f7dc1ea6SMichael Chan if (data[i] != (u8)(i & 0xff)) 2664f7dc1ea6SMichael Chan return -EIO; 2665f7dc1ea6SMichael Chan } 2666f7dc1ea6SMichael Chan return 0; 2667f7dc1ea6SMichael Chan } 2668f7dc1ea6SMichael Chan 2669e44758b7SMichael Chan static int bnxt_poll_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, 2670e44758b7SMichael Chan int pkt_size) 2671f7dc1ea6SMichael Chan { 2672f7dc1ea6SMichael Chan struct tx_cmp *txcmp; 2673f7dc1ea6SMichael Chan int rc = -EIO; 2674f7dc1ea6SMichael Chan u32 raw_cons; 2675f7dc1ea6SMichael Chan u32 cons; 2676f7dc1ea6SMichael Chan int i; 2677f7dc1ea6SMichael Chan 2678f7dc1ea6SMichael Chan raw_cons = cpr->cp_raw_cons; 2679f7dc1ea6SMichael Chan for (i = 0; i < 200; i++) { 2680f7dc1ea6SMichael Chan cons = RING_CMP(raw_cons); 2681f7dc1ea6SMichael Chan txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; 2682f7dc1ea6SMichael Chan 2683f7dc1ea6SMichael Chan if (!TX_CMP_VALID(txcmp, raw_cons)) { 2684f7dc1ea6SMichael Chan udelay(5); 2685f7dc1ea6SMichael Chan continue; 2686f7dc1ea6SMichael Chan } 2687f7dc1ea6SMichael Chan 2688f7dc1ea6SMichael Chan /* The valid test of the entry must be done first before 2689f7dc1ea6SMichael Chan * reading any further. 2690f7dc1ea6SMichael Chan */ 2691f7dc1ea6SMichael Chan dma_rmb(); 2692f7dc1ea6SMichael Chan if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) { 2693e44758b7SMichael Chan rc = bnxt_rx_loopback(bp, cpr, raw_cons, pkt_size); 2694f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2695f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2696f7dc1ea6SMichael Chan break; 2697f7dc1ea6SMichael Chan } 2698f7dc1ea6SMichael Chan raw_cons = NEXT_RAW_CMP(raw_cons); 2699f7dc1ea6SMichael Chan } 2700f7dc1ea6SMichael Chan cpr->cp_raw_cons = raw_cons; 2701f7dc1ea6SMichael Chan return rc; 2702f7dc1ea6SMichael Chan } 2703f7dc1ea6SMichael Chan 2704f7dc1ea6SMichael Chan static int bnxt_run_loopback(struct bnxt *bp) 2705f7dc1ea6SMichael Chan { 2706f7dc1ea6SMichael Chan struct bnxt_tx_ring_info *txr = &bp->tx_ring[0]; 2707e44758b7SMichael Chan struct bnxt_cp_ring_info *cpr; 2708f7dc1ea6SMichael Chan int pkt_size, i = 0; 2709f7dc1ea6SMichael Chan struct sk_buff *skb; 2710f7dc1ea6SMichael Chan dma_addr_t map; 2711f7dc1ea6SMichael Chan u8 *data; 2712f7dc1ea6SMichael Chan int rc; 2713f7dc1ea6SMichael Chan 2714e44758b7SMichael Chan cpr = &txr->bnapi->cp_ring; 2715f7dc1ea6SMichael Chan pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh); 2716f7dc1ea6SMichael Chan skb = netdev_alloc_skb(bp->dev, pkt_size); 2717f7dc1ea6SMichael Chan if (!skb) 2718f7dc1ea6SMichael Chan return -ENOMEM; 2719f7dc1ea6SMichael Chan data = skb_put(skb, pkt_size); 2720f7dc1ea6SMichael Chan eth_broadcast_addr(data); 2721f7dc1ea6SMichael Chan i += ETH_ALEN; 2722f7dc1ea6SMichael Chan ether_addr_copy(&data[i], bp->dev->dev_addr); 2723f7dc1ea6SMichael Chan i += ETH_ALEN; 2724f7dc1ea6SMichael Chan for ( ; i < pkt_size; i++) 2725f7dc1ea6SMichael Chan data[i] = (u8)(i & 0xff); 2726f7dc1ea6SMichael Chan 2727f7dc1ea6SMichael Chan map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size, 2728f7dc1ea6SMichael Chan PCI_DMA_TODEVICE); 2729f7dc1ea6SMichael Chan if (dma_mapping_error(&bp->pdev->dev, map)) { 2730f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2731f7dc1ea6SMichael Chan return -EIO; 2732f7dc1ea6SMichael Chan } 2733f7dc1ea6SMichael Chan bnxt_xmit_xdp(bp, txr, map, pkt_size, 0); 2734f7dc1ea6SMichael Chan 2735f7dc1ea6SMichael Chan /* Sync BD data before updating doorbell */ 2736f7dc1ea6SMichael Chan wmb(); 2737f7dc1ea6SMichael Chan 2738697197e5SMichael Chan bnxt_db_write(bp, &txr->tx_db, txr->tx_prod); 2739e44758b7SMichael Chan rc = bnxt_poll_loopback(bp, cpr, pkt_size); 2740f7dc1ea6SMichael Chan 2741f7dc1ea6SMichael Chan dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE); 2742f7dc1ea6SMichael Chan dev_kfree_skb(skb); 2743f7dc1ea6SMichael Chan return rc; 2744f7dc1ea6SMichael Chan } 2745f7dc1ea6SMichael Chan 2746eb513658SMichael Chan static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results) 2747eb513658SMichael Chan { 2748eb513658SMichael Chan struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr; 2749eb513658SMichael Chan struct hwrm_selftest_exec_input req = {0}; 2750eb513658SMichael Chan int rc; 2751eb513658SMichael Chan 2752eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1); 2753eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 2754eb513658SMichael Chan resp->test_success = 0; 2755eb513658SMichael Chan req.flags = test_mask; 2756eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout); 2757eb513658SMichael Chan *test_results = resp->test_success; 2758eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 2759eb513658SMichael Chan return rc; 2760eb513658SMichael Chan } 2761eb513658SMichael Chan 276255fd0cf3SMichael Chan #define BNXT_DRV_TESTS 4 2763f7dc1ea6SMichael Chan #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS) 276491725d89SMichael Chan #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1) 276555fd0cf3SMichael Chan #define BNXT_EXTLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2) 276655fd0cf3SMichael Chan #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 3) 2767eb513658SMichael Chan 2768eb513658SMichael Chan static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest, 2769eb513658SMichael Chan u64 *buf) 2770eb513658SMichael Chan { 2771eb513658SMichael Chan struct bnxt *bp = netdev_priv(dev); 277255fd0cf3SMichael Chan bool do_ext_lpbk = false; 2773eb513658SMichael Chan bool offline = false; 2774eb513658SMichael Chan u8 test_results = 0; 2775eb513658SMichael Chan u8 test_mask = 0; 2776eb513658SMichael Chan int rc, i; 2777eb513658SMichael Chan 2778eb513658SMichael Chan if (!bp->num_tests || !BNXT_SINGLE_PF(bp)) 2779eb513658SMichael Chan return; 2780eb513658SMichael Chan memset(buf, 0, sizeof(u64) * bp->num_tests); 2781eb513658SMichael Chan if (!netif_running(dev)) { 2782eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2783eb513658SMichael Chan return; 2784eb513658SMichael Chan } 2785eb513658SMichael Chan 278655fd0cf3SMichael Chan if ((etest->flags & ETH_TEST_FL_EXTERNAL_LB) && 278755fd0cf3SMichael Chan (bp->test_info->flags & BNXT_TEST_FL_EXT_LPBK)) 278855fd0cf3SMichael Chan do_ext_lpbk = true; 278955fd0cf3SMichael Chan 2790eb513658SMichael Chan if (etest->flags & ETH_TEST_FL_OFFLINE) { 2791eb513658SMichael Chan if (bp->pf.active_vfs) { 2792eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2793eb513658SMichael Chan netdev_warn(dev, "Offline tests cannot be run with active VFs\n"); 2794eb513658SMichael Chan return; 2795eb513658SMichael Chan } 2796eb513658SMichael Chan offline = true; 2797eb513658SMichael Chan } 2798eb513658SMichael Chan 2799eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 2800eb513658SMichael Chan u8 bit_val = 1 << i; 2801eb513658SMichael Chan 2802eb513658SMichael Chan if (!(bp->test_info->offline_mask & bit_val)) 2803eb513658SMichael Chan test_mask |= bit_val; 2804eb513658SMichael Chan else if (offline) 2805eb513658SMichael Chan test_mask |= bit_val; 2806eb513658SMichael Chan } 2807eb513658SMichael Chan if (!offline) { 2808eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 2809eb513658SMichael Chan } else { 2810eb513658SMichael Chan rc = bnxt_close_nic(bp, false, false); 2811eb513658SMichael Chan if (rc) 2812eb513658SMichael Chan return; 2813eb513658SMichael Chan bnxt_run_fw_tests(bp, test_mask, &test_results); 2814f7dc1ea6SMichael Chan 2815f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 1; 2816f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, true); 2817f7dc1ea6SMichael Chan msleep(250); 2818f7dc1ea6SMichael Chan rc = bnxt_half_open_nic(bp); 2819f7dc1ea6SMichael Chan if (rc) { 2820f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 2821f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2822f7dc1ea6SMichael Chan return; 2823f7dc1ea6SMichael Chan } 2824f7dc1ea6SMichael Chan if (bnxt_run_loopback(bp)) 2825f7dc1ea6SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2826f7dc1ea6SMichael Chan else 2827f7dc1ea6SMichael Chan buf[BNXT_MACLPBK_TEST_IDX] = 0; 2828f7dc1ea6SMichael Chan 2829f7dc1ea6SMichael Chan bnxt_hwrm_mac_loopback(bp, false); 283055fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, false); 283191725d89SMichael Chan msleep(1000); 283291725d89SMichael Chan if (bnxt_run_loopback(bp)) { 283391725d89SMichael Chan buf[BNXT_PHYLPBK_TEST_IDX] = 1; 283491725d89SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 283591725d89SMichael Chan } 283655fd0cf3SMichael Chan if (do_ext_lpbk) { 283755fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; 283855fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, true, true); 283955fd0cf3SMichael Chan msleep(1000); 284055fd0cf3SMichael Chan if (bnxt_run_loopback(bp)) { 284155fd0cf3SMichael Chan buf[BNXT_EXTLPBK_TEST_IDX] = 1; 284255fd0cf3SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 284355fd0cf3SMichael Chan } 284455fd0cf3SMichael Chan } 284555fd0cf3SMichael Chan bnxt_hwrm_phy_loopback(bp, false, false); 284691725d89SMichael Chan bnxt_half_close_nic(bp); 2847eb513658SMichael Chan bnxt_open_nic(bp, false, true); 2848eb513658SMichael Chan } 284967fea463SMichael Chan if (bnxt_test_irq(bp)) { 285067fea463SMichael Chan buf[BNXT_IRQ_TEST_IDX] = 1; 285167fea463SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 285267fea463SMichael Chan } 2853eb513658SMichael Chan for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) { 2854eb513658SMichael Chan u8 bit_val = 1 << i; 2855eb513658SMichael Chan 2856eb513658SMichael Chan if ((test_mask & bit_val) && !(test_results & bit_val)) { 2857eb513658SMichael Chan buf[i] = 1; 2858eb513658SMichael Chan etest->flags |= ETH_TEST_FL_FAILED; 2859eb513658SMichael Chan } 2860eb513658SMichael Chan } 2861eb513658SMichael Chan } 2862eb513658SMichael Chan 286349f7972fSVasundhara Volam static int bnxt_reset(struct net_device *dev, u32 *flags) 286449f7972fSVasundhara Volam { 286549f7972fSVasundhara Volam struct bnxt *bp = netdev_priv(dev); 286649f7972fSVasundhara Volam int rc = 0; 286749f7972fSVasundhara Volam 286849f7972fSVasundhara Volam if (!BNXT_PF(bp)) { 286949f7972fSVasundhara Volam netdev_err(dev, "Reset is not supported from a VF\n"); 287049f7972fSVasundhara Volam return -EOPNOTSUPP; 287149f7972fSVasundhara Volam } 287249f7972fSVasundhara Volam 287349f7972fSVasundhara Volam if (pci_vfs_assigned(bp->pdev)) { 287449f7972fSVasundhara Volam netdev_err(dev, 287549f7972fSVasundhara Volam "Reset not allowed when VFs are assigned to VMs\n"); 287649f7972fSVasundhara Volam return -EBUSY; 287749f7972fSVasundhara Volam } 287849f7972fSVasundhara Volam 287949f7972fSVasundhara Volam if (*flags == ETH_RESET_ALL) { 288049f7972fSVasundhara Volam /* This feature is not supported in older firmware versions */ 288149f7972fSVasundhara Volam if (bp->hwrm_spec_code < 0x10803) 288249f7972fSVasundhara Volam return -EOPNOTSUPP; 288349f7972fSVasundhara Volam 288449f7972fSVasundhara Volam rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_CHIP); 28852373d8d6SScott Branden if (!rc) { 288649f7972fSVasundhara Volam netdev_info(dev, "Reset request successful. Reload driver to complete reset\n"); 28872373d8d6SScott Branden *flags = 0; 28882373d8d6SScott Branden } 28896502ad59SScott Branden } else if (*flags == ETH_RESET_AP) { 28906502ad59SScott Branden /* This feature is not supported in older firmware versions */ 28916502ad59SScott Branden if (bp->hwrm_spec_code < 0x10803) 28926502ad59SScott Branden return -EOPNOTSUPP; 28936502ad59SScott Branden 28946502ad59SScott Branden rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_AP); 28952373d8d6SScott Branden if (!rc) { 28966502ad59SScott Branden netdev_info(dev, "Reset Application Processor request successful.\n"); 28972373d8d6SScott Branden *flags = 0; 28982373d8d6SScott Branden } 289949f7972fSVasundhara Volam } else { 290049f7972fSVasundhara Volam rc = -EINVAL; 290149f7972fSVasundhara Volam } 290249f7972fSVasundhara Volam 290349f7972fSVasundhara Volam return rc; 290449f7972fSVasundhara Volam } 290549f7972fSVasundhara Volam 29066c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg, int msg_len, 29076c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info *info) 29086c5657d0SVasundhara Volam { 29096c5657d0SVasundhara Volam struct hwrm_dbg_cmn_output *cmn_resp = bp->hwrm_cmd_resp_addr; 29106c5657d0SVasundhara Volam struct hwrm_dbg_cmn_input *cmn_req = msg; 29116c5657d0SVasundhara Volam __le16 *seq_ptr = msg + info->seq_off; 29126c5657d0SVasundhara Volam u16 seq = 0, len, segs_off; 29136c5657d0SVasundhara Volam void *resp = cmn_resp; 29146c5657d0SVasundhara Volam dma_addr_t dma_handle; 29156c5657d0SVasundhara Volam int rc, off = 0; 29166c5657d0SVasundhara Volam void *dma_buf; 29176c5657d0SVasundhara Volam 29186c5657d0SVasundhara Volam dma_buf = dma_alloc_coherent(&bp->pdev->dev, info->dma_len, &dma_handle, 29196c5657d0SVasundhara Volam GFP_KERNEL); 29206c5657d0SVasundhara Volam if (!dma_buf) 29216c5657d0SVasundhara Volam return -ENOMEM; 29226c5657d0SVasundhara Volam 29236c5657d0SVasundhara Volam segs_off = offsetof(struct hwrm_dbg_coredump_list_output, 29246c5657d0SVasundhara Volam total_segments); 29256c5657d0SVasundhara Volam cmn_req->host_dest_addr = cpu_to_le64(dma_handle); 29266c5657d0SVasundhara Volam cmn_req->host_buf_len = cpu_to_le32(info->dma_len); 29276c5657d0SVasundhara Volam mutex_lock(&bp->hwrm_cmd_lock); 29286c5657d0SVasundhara Volam while (1) { 29296c5657d0SVasundhara Volam *seq_ptr = cpu_to_le16(seq); 29306c5657d0SVasundhara Volam rc = _hwrm_send_message(bp, msg, msg_len, HWRM_CMD_TIMEOUT); 29316c5657d0SVasundhara Volam if (rc) 29326c5657d0SVasundhara Volam break; 29336c5657d0SVasundhara Volam 29346c5657d0SVasundhara Volam len = le16_to_cpu(*((__le16 *)(resp + info->data_len_off))); 29356c5657d0SVasundhara Volam if (!seq && 29366c5657d0SVasundhara Volam cmn_req->req_type == cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) { 29376c5657d0SVasundhara Volam info->segs = le16_to_cpu(*((__le16 *)(resp + 29386c5657d0SVasundhara Volam segs_off))); 29396c5657d0SVasundhara Volam if (!info->segs) { 29406c5657d0SVasundhara Volam rc = -EIO; 29416c5657d0SVasundhara Volam break; 29426c5657d0SVasundhara Volam } 29436c5657d0SVasundhara Volam 29446c5657d0SVasundhara Volam info->dest_buf_size = info->segs * 29456c5657d0SVasundhara Volam sizeof(struct coredump_segment_record); 29466c5657d0SVasundhara Volam info->dest_buf = kmalloc(info->dest_buf_size, 29476c5657d0SVasundhara Volam GFP_KERNEL); 29486c5657d0SVasundhara Volam if (!info->dest_buf) { 29496c5657d0SVasundhara Volam rc = -ENOMEM; 29506c5657d0SVasundhara Volam break; 29516c5657d0SVasundhara Volam } 29526c5657d0SVasundhara Volam } 29536c5657d0SVasundhara Volam 29546c5657d0SVasundhara Volam if (info->dest_buf) 29556c5657d0SVasundhara Volam memcpy(info->dest_buf + off, dma_buf, len); 29566c5657d0SVasundhara Volam 29576c5657d0SVasundhara Volam if (cmn_req->req_type == 29586c5657d0SVasundhara Volam cpu_to_le16(HWRM_DBG_COREDUMP_RETRIEVE)) 29596c5657d0SVasundhara Volam info->dest_buf_size += len; 29606c5657d0SVasundhara Volam 29616c5657d0SVasundhara Volam if (!(cmn_resp->flags & HWRM_DBG_CMN_FLAGS_MORE)) 29626c5657d0SVasundhara Volam break; 29636c5657d0SVasundhara Volam 29646c5657d0SVasundhara Volam seq++; 29656c5657d0SVasundhara Volam off += len; 29666c5657d0SVasundhara Volam } 29676c5657d0SVasundhara Volam mutex_unlock(&bp->hwrm_cmd_lock); 29686c5657d0SVasundhara Volam dma_free_coherent(&bp->pdev->dev, info->dma_len, dma_buf, dma_handle); 29696c5657d0SVasundhara Volam return rc; 29706c5657d0SVasundhara Volam } 29716c5657d0SVasundhara Volam 29726c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_list(struct bnxt *bp, 29736c5657d0SVasundhara Volam struct bnxt_coredump *coredump) 29746c5657d0SVasundhara Volam { 29756c5657d0SVasundhara Volam struct hwrm_dbg_coredump_list_input req = {0}; 29766c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 29776c5657d0SVasundhara Volam int rc; 29786c5657d0SVasundhara Volam 29796c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_LIST, -1, -1); 29806c5657d0SVasundhara Volam 29816c5657d0SVasundhara Volam info.dma_len = COREDUMP_LIST_BUF_LEN; 29826c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_list_input, seq_no); 29836c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_list_output, 29846c5657d0SVasundhara Volam data_len); 29856c5657d0SVasundhara Volam 29866c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 29876c5657d0SVasundhara Volam if (!rc) { 29886c5657d0SVasundhara Volam coredump->data = info.dest_buf; 29896c5657d0SVasundhara Volam coredump->data_size = info.dest_buf_size; 29906c5657d0SVasundhara Volam coredump->total_segs = info.segs; 29916c5657d0SVasundhara Volam } 29926c5657d0SVasundhara Volam return rc; 29936c5657d0SVasundhara Volam } 29946c5657d0SVasundhara Volam 29956c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_initiate(struct bnxt *bp, u16 component_id, 29966c5657d0SVasundhara Volam u16 segment_id) 29976c5657d0SVasundhara Volam { 29986c5657d0SVasundhara Volam struct hwrm_dbg_coredump_initiate_input req = {0}; 29996c5657d0SVasundhara Volam 30006c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_INITIATE, -1, -1); 30016c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 30026c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 30036c5657d0SVasundhara Volam 30046c5657d0SVasundhara Volam return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 30056c5657d0SVasundhara Volam } 30066c5657d0SVasundhara Volam 30076c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_retrieve(struct bnxt *bp, u16 component_id, 30086c5657d0SVasundhara Volam u16 segment_id, u32 *seg_len, 30096c5657d0SVasundhara Volam void *buf, u32 offset) 30106c5657d0SVasundhara Volam { 30116c5657d0SVasundhara Volam struct hwrm_dbg_coredump_retrieve_input req = {0}; 30126c5657d0SVasundhara Volam struct bnxt_hwrm_dbg_dma_info info = {NULL}; 30136c5657d0SVasundhara Volam int rc; 30146c5657d0SVasundhara Volam 30156c5657d0SVasundhara Volam bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_RETRIEVE, -1, -1); 30166c5657d0SVasundhara Volam req.component_id = cpu_to_le16(component_id); 30176c5657d0SVasundhara Volam req.segment_id = cpu_to_le16(segment_id); 30186c5657d0SVasundhara Volam 30196c5657d0SVasundhara Volam info.dma_len = COREDUMP_RETRIEVE_BUF_LEN; 30206c5657d0SVasundhara Volam info.seq_off = offsetof(struct hwrm_dbg_coredump_retrieve_input, 30216c5657d0SVasundhara Volam seq_no); 30226c5657d0SVasundhara Volam info.data_len_off = offsetof(struct hwrm_dbg_coredump_retrieve_output, 30236c5657d0SVasundhara Volam data_len); 30246c5657d0SVasundhara Volam if (buf) 30256c5657d0SVasundhara Volam info.dest_buf = buf + offset; 30266c5657d0SVasundhara Volam 30276c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info); 30286c5657d0SVasundhara Volam if (!rc) 30296c5657d0SVasundhara Volam *seg_len = info.dest_buf_size; 30306c5657d0SVasundhara Volam 30316c5657d0SVasundhara Volam return rc; 30326c5657d0SVasundhara Volam } 30336c5657d0SVasundhara Volam 30346c5657d0SVasundhara Volam static void 30356c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(struct bnxt *bp, 30366c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr *seg_hdr, 30376c5657d0SVasundhara Volam struct coredump_segment_record *seg_rec, u32 seg_len, 30386c5657d0SVasundhara Volam int status, u32 duration, u32 instance) 30396c5657d0SVasundhara Volam { 30406c5657d0SVasundhara Volam memset(seg_hdr, 0, sizeof(*seg_hdr)); 30418605212aSVasundhara Volam memcpy(seg_hdr->signature, "sEgM", 4); 30426c5657d0SVasundhara Volam if (seg_rec) { 30436c5657d0SVasundhara Volam seg_hdr->component_id = (__force __le32)seg_rec->component_id; 30446c5657d0SVasundhara Volam seg_hdr->segment_id = (__force __le32)seg_rec->segment_id; 30456c5657d0SVasundhara Volam seg_hdr->low_version = seg_rec->version_low; 30466c5657d0SVasundhara Volam seg_hdr->high_version = seg_rec->version_hi; 30476c5657d0SVasundhara Volam } else { 30486c5657d0SVasundhara Volam /* For hwrm_ver_get response Component id = 2 30496c5657d0SVasundhara Volam * and Segment id = 0 30506c5657d0SVasundhara Volam */ 30516c5657d0SVasundhara Volam seg_hdr->component_id = cpu_to_le32(2); 30526c5657d0SVasundhara Volam seg_hdr->segment_id = 0; 30536c5657d0SVasundhara Volam } 30546c5657d0SVasundhara Volam seg_hdr->function_id = cpu_to_le16(bp->pdev->devfn); 30556c5657d0SVasundhara Volam seg_hdr->length = cpu_to_le32(seg_len); 30566c5657d0SVasundhara Volam seg_hdr->status = cpu_to_le32(status); 30576c5657d0SVasundhara Volam seg_hdr->duration = cpu_to_le32(duration); 30586c5657d0SVasundhara Volam seg_hdr->data_offset = cpu_to_le32(sizeof(*seg_hdr)); 30596c5657d0SVasundhara Volam seg_hdr->instance = cpu_to_le32(instance); 30606c5657d0SVasundhara Volam } 30616c5657d0SVasundhara Volam 30626c5657d0SVasundhara Volam static void 30636c5657d0SVasundhara Volam bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record, 30646c5657d0SVasundhara Volam time64_t start, s16 start_utc, u16 total_segs, 30656c5657d0SVasundhara Volam int status) 30666c5657d0SVasundhara Volam { 30676c5657d0SVasundhara Volam time64_t end = ktime_get_real_seconds(); 30686c5657d0SVasundhara Volam u32 os_ver_major = 0, os_ver_minor = 0; 30696c5657d0SVasundhara Volam struct tm tm; 30706c5657d0SVasundhara Volam 30716c5657d0SVasundhara Volam time64_to_tm(start, 0, &tm); 30726c5657d0SVasundhara Volam memset(record, 0, sizeof(*record)); 30738605212aSVasundhara Volam memcpy(record->signature, "cOrE", 4); 30746c5657d0SVasundhara Volam record->flags = 0; 30756c5657d0SVasundhara Volam record->low_version = 0; 30766c5657d0SVasundhara Volam record->high_version = 1; 30776c5657d0SVasundhara Volam record->asic_state = 0; 30783d46eee5SArnd Bergmann strlcpy(record->system_name, utsname()->nodename, 30793d46eee5SArnd Bergmann sizeof(record->system_name)); 30808dc5ae2dSVasundhara Volam record->year = cpu_to_le16(tm.tm_year + 1900); 30818dc5ae2dSVasundhara Volam record->month = cpu_to_le16(tm.tm_mon + 1); 30826c5657d0SVasundhara Volam record->day = cpu_to_le16(tm.tm_mday); 30836c5657d0SVasundhara Volam record->hour = cpu_to_le16(tm.tm_hour); 30846c5657d0SVasundhara Volam record->minute = cpu_to_le16(tm.tm_min); 30856c5657d0SVasundhara Volam record->second = cpu_to_le16(tm.tm_sec); 30866c5657d0SVasundhara Volam record->utc_bias = cpu_to_le16(start_utc); 30876c5657d0SVasundhara Volam strcpy(record->commandline, "ethtool -w"); 30886c5657d0SVasundhara Volam record->total_segments = cpu_to_le32(total_segs); 30896c5657d0SVasundhara Volam 30906c5657d0SVasundhara Volam sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor); 30916c5657d0SVasundhara Volam record->os_ver_major = cpu_to_le32(os_ver_major); 30926c5657d0SVasundhara Volam record->os_ver_minor = cpu_to_le32(os_ver_minor); 30936c5657d0SVasundhara Volam 30948605212aSVasundhara Volam strlcpy(record->os_name, utsname()->sysname, 32); 30956c5657d0SVasundhara Volam time64_to_tm(end, 0, &tm); 30966c5657d0SVasundhara Volam record->end_year = cpu_to_le16(tm.tm_year + 1900); 30976c5657d0SVasundhara Volam record->end_month = cpu_to_le16(tm.tm_mon + 1); 30986c5657d0SVasundhara Volam record->end_day = cpu_to_le16(tm.tm_mday); 30996c5657d0SVasundhara Volam record->end_hour = cpu_to_le16(tm.tm_hour); 31006c5657d0SVasundhara Volam record->end_minute = cpu_to_le16(tm.tm_min); 31016c5657d0SVasundhara Volam record->end_second = cpu_to_le16(tm.tm_sec); 31026c5657d0SVasundhara Volam record->end_utc_bias = cpu_to_le16(sys_tz.tz_minuteswest * 60); 31036c5657d0SVasundhara Volam record->asic_id1 = cpu_to_le32(bp->chip_num << 16 | 31046c5657d0SVasundhara Volam bp->ver_resp.chip_rev << 8 | 31056c5657d0SVasundhara Volam bp->ver_resp.chip_metal); 31066c5657d0SVasundhara Volam record->asic_id2 = 0; 31076c5657d0SVasundhara Volam record->coredump_status = cpu_to_le32(status); 31086c5657d0SVasundhara Volam record->ioctl_low_version = 0; 31096c5657d0SVasundhara Volam record->ioctl_high_version = 0; 31106c5657d0SVasundhara Volam } 31116c5657d0SVasundhara Volam 31126c5657d0SVasundhara Volam static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len) 31136c5657d0SVasundhara Volam { 31146c5657d0SVasundhara Volam u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output); 31156c5657d0SVasundhara Volam struct coredump_segment_record *seg_record = NULL; 31166c5657d0SVasundhara Volam u32 offset = 0, seg_hdr_len, seg_record_len; 31176c5657d0SVasundhara Volam struct bnxt_coredump_segment_hdr seg_hdr; 31186c5657d0SVasundhara Volam struct bnxt_coredump coredump = {NULL}; 31196c5657d0SVasundhara Volam time64_t start_time; 31206c5657d0SVasundhara Volam u16 start_utc; 31216c5657d0SVasundhara Volam int rc = 0, i; 31226c5657d0SVasundhara Volam 31236c5657d0SVasundhara Volam start_time = ktime_get_real_seconds(); 31246c5657d0SVasundhara Volam start_utc = sys_tz.tz_minuteswest * 60; 31256c5657d0SVasundhara Volam seg_hdr_len = sizeof(seg_hdr); 31266c5657d0SVasundhara Volam 31276c5657d0SVasundhara Volam /* First segment should be hwrm_ver_get response */ 31286c5657d0SVasundhara Volam *dump_len = seg_hdr_len + ver_get_resp_len; 31296c5657d0SVasundhara Volam if (buf) { 31306c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, NULL, ver_get_resp_len, 31316c5657d0SVasundhara Volam 0, 0, 0); 31326c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 31336c5657d0SVasundhara Volam offset += seg_hdr_len; 31346c5657d0SVasundhara Volam memcpy(buf + offset, &bp->ver_resp, ver_get_resp_len); 31356c5657d0SVasundhara Volam offset += ver_get_resp_len; 31366c5657d0SVasundhara Volam } 31376c5657d0SVasundhara Volam 31386c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_list(bp, &coredump); 31396c5657d0SVasundhara Volam if (rc) { 31406c5657d0SVasundhara Volam netdev_err(bp->dev, "Failed to get coredump segment list\n"); 31416c5657d0SVasundhara Volam goto err; 31426c5657d0SVasundhara Volam } 31436c5657d0SVasundhara Volam 31446c5657d0SVasundhara Volam *dump_len += seg_hdr_len * coredump.total_segs; 31456c5657d0SVasundhara Volam 31466c5657d0SVasundhara Volam seg_record = (struct coredump_segment_record *)coredump.data; 31476c5657d0SVasundhara Volam seg_record_len = sizeof(*seg_record); 31486c5657d0SVasundhara Volam 31496c5657d0SVasundhara Volam for (i = 0; i < coredump.total_segs; i++) { 31506c5657d0SVasundhara Volam u16 comp_id = le16_to_cpu(seg_record->component_id); 31516c5657d0SVasundhara Volam u16 seg_id = le16_to_cpu(seg_record->segment_id); 31526c5657d0SVasundhara Volam u32 duration = 0, seg_len = 0; 31536c5657d0SVasundhara Volam unsigned long start, end; 31546c5657d0SVasundhara Volam 31556c5657d0SVasundhara Volam start = jiffies; 31566c5657d0SVasundhara Volam 31576c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_initiate(bp, comp_id, seg_id); 31586c5657d0SVasundhara Volam if (rc) { 31596c5657d0SVasundhara Volam netdev_err(bp->dev, 31606c5657d0SVasundhara Volam "Failed to initiate coredump for seg = %d\n", 31616c5657d0SVasundhara Volam seg_record->segment_id); 31626c5657d0SVasundhara Volam goto next_seg; 31636c5657d0SVasundhara Volam } 31646c5657d0SVasundhara Volam 31656c5657d0SVasundhara Volam /* Write segment data into the buffer */ 31666c5657d0SVasundhara Volam rc = bnxt_hwrm_dbg_coredump_retrieve(bp, comp_id, seg_id, 31676c5657d0SVasundhara Volam &seg_len, buf, 31686c5657d0SVasundhara Volam offset + seg_hdr_len); 31696c5657d0SVasundhara Volam if (rc) 31706c5657d0SVasundhara Volam netdev_err(bp->dev, 31716c5657d0SVasundhara Volam "Failed to retrieve coredump for seg = %d\n", 31726c5657d0SVasundhara Volam seg_record->segment_id); 31736c5657d0SVasundhara Volam 31746c5657d0SVasundhara Volam next_seg: 31756c5657d0SVasundhara Volam end = jiffies; 31766c5657d0SVasundhara Volam duration = jiffies_to_msecs(end - start); 31776c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, seg_record, seg_len, 31786c5657d0SVasundhara Volam rc, duration, 0); 31796c5657d0SVasundhara Volam 31806c5657d0SVasundhara Volam if (buf) { 31816c5657d0SVasundhara Volam /* Write segment header into the buffer */ 31826c5657d0SVasundhara Volam memcpy(buf + offset, &seg_hdr, seg_hdr_len); 31836c5657d0SVasundhara Volam offset += seg_hdr_len + seg_len; 31846c5657d0SVasundhara Volam } 31856c5657d0SVasundhara Volam 31866c5657d0SVasundhara Volam *dump_len += seg_len; 31876c5657d0SVasundhara Volam seg_record = 31886c5657d0SVasundhara Volam (struct coredump_segment_record *)((u8 *)seg_record + 31896c5657d0SVasundhara Volam seg_record_len); 31906c5657d0SVasundhara Volam } 31916c5657d0SVasundhara Volam 31926c5657d0SVasundhara Volam err: 31931bbf3aedSArnd Bergmann if (buf) 31941bbf3aedSArnd Bergmann bnxt_fill_coredump_record(bp, buf + offset, start_time, 31956c5657d0SVasundhara Volam start_utc, coredump.total_segs + 1, 31966c5657d0SVasundhara Volam rc); 31976c5657d0SVasundhara Volam kfree(coredump.data); 31981bbf3aedSArnd Bergmann *dump_len += sizeof(struct bnxt_coredump_record); 31996c5657d0SVasundhara Volam 32006c5657d0SVasundhara Volam return rc; 32016c5657d0SVasundhara Volam } 32026c5657d0SVasundhara Volam 32036c5657d0SVasundhara Volam static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump) 32046c5657d0SVasundhara Volam { 32056c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 32066c5657d0SVasundhara Volam 32076c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 32086c5657d0SVasundhara Volam return -EOPNOTSUPP; 32096c5657d0SVasundhara Volam 32106c5657d0SVasundhara Volam dump->version = bp->ver_resp.hwrm_fw_maj_8b << 24 | 32116c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_min_8b << 16 | 32126c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_bld_8b << 8 | 32136c5657d0SVasundhara Volam bp->ver_resp.hwrm_fw_rsvd_8b; 32146c5657d0SVasundhara Volam 32156c5657d0SVasundhara Volam return bnxt_get_coredump(bp, NULL, &dump->len); 32166c5657d0SVasundhara Volam } 32176c5657d0SVasundhara Volam 32186c5657d0SVasundhara Volam static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump, 32196c5657d0SVasundhara Volam void *buf) 32206c5657d0SVasundhara Volam { 32216c5657d0SVasundhara Volam struct bnxt *bp = netdev_priv(dev); 32226c5657d0SVasundhara Volam 32236c5657d0SVasundhara Volam if (bp->hwrm_spec_code < 0x10801) 32246c5657d0SVasundhara Volam return -EOPNOTSUPP; 32256c5657d0SVasundhara Volam 32266c5657d0SVasundhara Volam memset(buf, 0, dump->len); 32276c5657d0SVasundhara Volam 32286c5657d0SVasundhara Volam return bnxt_get_coredump(bp, buf, &dump->len); 32296c5657d0SVasundhara Volam } 32306c5657d0SVasundhara Volam 3231eb513658SMichael Chan void bnxt_ethtool_init(struct bnxt *bp) 3232eb513658SMichael Chan { 3233eb513658SMichael Chan struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr; 3234eb513658SMichael Chan struct hwrm_selftest_qlist_input req = {0}; 3235eb513658SMichael Chan struct bnxt_test_info *test_info; 3236431aa1ebSMichael Chan struct net_device *dev = bp->dev; 3237eb513658SMichael Chan int i, rc; 3238eb513658SMichael Chan 3239a60faa60SVasundhara Volam bnxt_get_pkgver(dev); 3240431aa1ebSMichael Chan 3241eb513658SMichael Chan if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp)) 3242eb513658SMichael Chan return; 3243eb513658SMichael Chan 3244eb513658SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1); 3245eb513658SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 3246eb513658SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 3247eb513658SMichael Chan if (rc) 3248eb513658SMichael Chan goto ethtool_init_exit; 3249eb513658SMichael Chan 3250eb513658SMichael Chan test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL); 3251eb513658SMichael Chan if (!test_info) 3252eb513658SMichael Chan goto ethtool_init_exit; 3253eb513658SMichael Chan 3254eb513658SMichael Chan bp->test_info = test_info; 3255eb513658SMichael Chan bp->num_tests = resp->num_tests + BNXT_DRV_TESTS; 3256eb513658SMichael Chan if (bp->num_tests > BNXT_MAX_TEST) 3257eb513658SMichael Chan bp->num_tests = BNXT_MAX_TEST; 3258eb513658SMichael Chan 3259eb513658SMichael Chan test_info->offline_mask = resp->offline_tests; 3260eb513658SMichael Chan test_info->timeout = le16_to_cpu(resp->test_timeout); 3261eb513658SMichael Chan if (!test_info->timeout) 3262eb513658SMichael Chan test_info->timeout = HWRM_CMD_TIMEOUT; 3263eb513658SMichael Chan for (i = 0; i < bp->num_tests; i++) { 3264eb513658SMichael Chan char *str = test_info->string[i]; 3265eb513658SMichael Chan char *fw_str = resp->test0_name + i * 32; 3266eb513658SMichael Chan 3267f7dc1ea6SMichael Chan if (i == BNXT_MACLPBK_TEST_IDX) { 3268f7dc1ea6SMichael Chan strcpy(str, "Mac loopback test (offline)"); 326991725d89SMichael Chan } else if (i == BNXT_PHYLPBK_TEST_IDX) { 327091725d89SMichael Chan strcpy(str, "Phy loopback test (offline)"); 327155fd0cf3SMichael Chan } else if (i == BNXT_EXTLPBK_TEST_IDX) { 327255fd0cf3SMichael Chan strcpy(str, "Ext loopback test (offline)"); 327367fea463SMichael Chan } else if (i == BNXT_IRQ_TEST_IDX) { 327467fea463SMichael Chan strcpy(str, "Interrupt_test (offline)"); 3275f7dc1ea6SMichael Chan } else { 3276eb513658SMichael Chan strlcpy(str, fw_str, ETH_GSTRING_LEN); 3277eb513658SMichael Chan strncat(str, " test", ETH_GSTRING_LEN - strlen(str)); 3278eb513658SMichael Chan if (test_info->offline_mask & (1 << i)) 3279eb513658SMichael Chan strncat(str, " (offline)", 3280eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3281eb513658SMichael Chan else 3282eb513658SMichael Chan strncat(str, " (online)", 3283eb513658SMichael Chan ETH_GSTRING_LEN - strlen(str)); 3284eb513658SMichael Chan } 3285f7dc1ea6SMichael Chan } 3286eb513658SMichael Chan 3287eb513658SMichael Chan ethtool_init_exit: 3288eb513658SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 3289eb513658SMichael Chan } 3290eb513658SMichael Chan 3291eb513658SMichael Chan void bnxt_ethtool_free(struct bnxt *bp) 3292eb513658SMichael Chan { 3293eb513658SMichael Chan kfree(bp->test_info); 3294eb513658SMichael Chan bp->test_info = NULL; 3295eb513658SMichael Chan } 3296eb513658SMichael Chan 3297c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 329800c04a92SMichael Chan .get_link_ksettings = bnxt_get_link_ksettings, 329900c04a92SMichael Chan .set_link_ksettings = bnxt_set_link_ksettings, 3300c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 3301c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 3302c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 33038e202366SMichael Chan .get_wol = bnxt_get_wol, 33045282db6cSMichael Chan .set_wol = bnxt_set_wol, 3305c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 3306c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 3307c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 3308c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 3309c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 3310c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 3311c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 3312c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 3313c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 3314c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 3315c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 3316c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 3317a011952aSMichael Chan .set_rxnfc = bnxt_set_rxnfc, 3318c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 3319c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 3320c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 3321c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 3322c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 3323c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 3324c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 3325c0c050c5SMichael Chan .get_link = bnxt_get_link, 332672b34f04SMichael Chan .get_eee = bnxt_get_eee, 332772b34f04SMichael Chan .set_eee = bnxt_set_eee, 332842ee18feSAjit Khaparde .get_module_info = bnxt_get_module_info, 332942ee18feSAjit Khaparde .get_module_eeprom = bnxt_get_module_eeprom, 33305ad2cbeeSMichael Chan .nway_reset = bnxt_nway_reset, 33315ad2cbeeSMichael Chan .set_phys_id = bnxt_set_phys_id, 3332eb513658SMichael Chan .self_test = bnxt_self_test, 333349f7972fSVasundhara Volam .reset = bnxt_reset, 33346c5657d0SVasundhara Volam .get_dump_flag = bnxt_get_dump_flag, 33356c5657d0SVasundhara Volam .get_dump_data = bnxt_get_dump_data, 3336c0c050c5SMichael Chan }; 3337