1c0c050c5SMichael Chan /* Broadcom NetXtreme-C/E network driver. 2c0c050c5SMichael Chan * 311f15ed3SMichael Chan * Copyright (c) 2014-2016 Broadcom Corporation 4c0c050c5SMichael Chan * 5c0c050c5SMichael Chan * This program is free software; you can redistribute it and/or modify 6c0c050c5SMichael Chan * it under the terms of the GNU General Public License as published by 7c0c050c5SMichael Chan * the Free Software Foundation. 8c0c050c5SMichael Chan */ 9c0c050c5SMichael Chan 103ebf6f0aSRob Swindell #include <linux/ctype.h> 118ddc9aaaSMichael Chan #include <linux/stringify.h> 12c0c050c5SMichael Chan #include <linux/ethtool.h> 13c0c050c5SMichael Chan #include <linux/interrupt.h> 14c0c050c5SMichael Chan #include <linux/pci.h> 15c0c050c5SMichael Chan #include <linux/etherdevice.h> 16c0c050c5SMichael Chan #include <linux/crc32.h> 17c0c050c5SMichael Chan #include <linux/firmware.h> 18c0c050c5SMichael Chan #include "bnxt_hsi.h" 19c0c050c5SMichael Chan #include "bnxt.h" 20c0c050c5SMichael Chan #include "bnxt_ethtool.h" 21c0c050c5SMichael Chan #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */ 22c0c050c5SMichael Chan #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */ 23c0c050c5SMichael Chan #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100) 24c0c050c5SMichael Chan 253ebf6f0aSRob Swindell static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen); 263ebf6f0aSRob Swindell 27c0c050c5SMichael Chan static u32 bnxt_get_msglevel(struct net_device *dev) 28c0c050c5SMichael Chan { 29c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 30c0c050c5SMichael Chan 31c0c050c5SMichael Chan return bp->msg_enable; 32c0c050c5SMichael Chan } 33c0c050c5SMichael Chan 34c0c050c5SMichael Chan static void bnxt_set_msglevel(struct net_device *dev, u32 value) 35c0c050c5SMichael Chan { 36c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 37c0c050c5SMichael Chan 38c0c050c5SMichael Chan bp->msg_enable = value; 39c0c050c5SMichael Chan } 40c0c050c5SMichael Chan 41c0c050c5SMichael Chan static int bnxt_get_coalesce(struct net_device *dev, 42c0c050c5SMichael Chan struct ethtool_coalesce *coal) 43c0c050c5SMichael Chan { 44c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 45c0c050c5SMichael Chan 46c0c050c5SMichael Chan memset(coal, 0, sizeof(*coal)); 47c0c050c5SMichael Chan 48dfb5b894SMichael Chan coal->rx_coalesce_usecs = bp->rx_coal_ticks; 49dfb5b894SMichael Chan /* 2 completion records per rx packet */ 50dfb5b894SMichael Chan coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2; 51dfb5b894SMichael Chan coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq; 52dfb5b894SMichael Chan coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2; 53c0c050c5SMichael Chan 54dfc9c94aSMichael Chan coal->tx_coalesce_usecs = bp->tx_coal_ticks; 55dfc9c94aSMichael Chan coal->tx_max_coalesced_frames = bp->tx_coal_bufs; 56dfc9c94aSMichael Chan coal->tx_coalesce_usecs_irq = bp->tx_coal_ticks_irq; 57dfc9c94aSMichael Chan coal->tx_max_coalesced_frames_irq = bp->tx_coal_bufs_irq; 58dfc9c94aSMichael Chan 59c0c050c5SMichael Chan return 0; 60c0c050c5SMichael Chan } 61c0c050c5SMichael Chan 62c0c050c5SMichael Chan static int bnxt_set_coalesce(struct net_device *dev, 63c0c050c5SMichael Chan struct ethtool_coalesce *coal) 64c0c050c5SMichael Chan { 65c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 66c0c050c5SMichael Chan int rc = 0; 67c0c050c5SMichael Chan 68dfb5b894SMichael Chan bp->rx_coal_ticks = coal->rx_coalesce_usecs; 69dfb5b894SMichael Chan /* 2 completion records per rx packet */ 70dfb5b894SMichael Chan bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2; 71dfb5b894SMichael Chan bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq; 72dfb5b894SMichael Chan bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2; 73c0c050c5SMichael Chan 74dfc9c94aSMichael Chan bp->tx_coal_ticks = coal->tx_coalesce_usecs; 75dfc9c94aSMichael Chan bp->tx_coal_bufs = coal->tx_max_coalesced_frames; 76dfc9c94aSMichael Chan bp->tx_coal_ticks_irq = coal->tx_coalesce_usecs_irq; 77dfc9c94aSMichael Chan bp->tx_coal_bufs_irq = coal->tx_max_coalesced_frames_irq; 78dfc9c94aSMichael Chan 79c0c050c5SMichael Chan if (netif_running(dev)) 80c0c050c5SMichael Chan rc = bnxt_hwrm_set_coal(bp); 81c0c050c5SMichael Chan 82c0c050c5SMichael Chan return rc; 83c0c050c5SMichael Chan } 84c0c050c5SMichael Chan 85c0c050c5SMichael Chan #define BNXT_NUM_STATS 21 86c0c050c5SMichael Chan 878ddc9aaaSMichael Chan #define BNXT_RX_STATS_OFFSET(counter) \ 888ddc9aaaSMichael Chan (offsetof(struct rx_port_stats, counter) / 8) 898ddc9aaaSMichael Chan 908ddc9aaaSMichael Chan #define BNXT_RX_STATS_ENTRY(counter) \ 918ddc9aaaSMichael Chan { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) } 928ddc9aaaSMichael Chan 938ddc9aaaSMichael Chan #define BNXT_TX_STATS_OFFSET(counter) \ 948ddc9aaaSMichael Chan ((offsetof(struct tx_port_stats, counter) + \ 958ddc9aaaSMichael Chan sizeof(struct rx_port_stats) + 512) / 8) 968ddc9aaaSMichael Chan 978ddc9aaaSMichael Chan #define BNXT_TX_STATS_ENTRY(counter) \ 988ddc9aaaSMichael Chan { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) } 998ddc9aaaSMichael Chan 1008ddc9aaaSMichael Chan static const struct { 1018ddc9aaaSMichael Chan long offset; 1028ddc9aaaSMichael Chan char string[ETH_GSTRING_LEN]; 1038ddc9aaaSMichael Chan } bnxt_port_stats_arr[] = { 1048ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_64b_frames), 1058ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_65b_127b_frames), 1068ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_128b_255b_frames), 1078ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_256b_511b_frames), 1088ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames), 1098ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_1024b_1518_frames), 1108ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_vlan_frames), 1118ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames), 1128ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames), 1138ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames), 1148ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames), 1158ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_total_frames), 1168ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ucast_frames), 1178ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mcast_frames), 1188ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bcast_frames), 1198ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_fcs_err_frames), 1208ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ctrl_frames), 1218ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pause_frames), 1228ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_pfc_frames), 1238ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_align_err_frames), 1248ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_ovrsz_frames), 1258ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_jbr_frames), 1268ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_mtu_err_frames), 1278ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_tagged_frames), 1288ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_double_tagged_frames), 1298ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_good_frames), 1308ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_undrsz_frames), 1318ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_events), 1328ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration), 1338ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_bytes), 1348ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_bytes), 1358ddc9aaaSMichael Chan BNXT_RX_STATS_ENTRY(rx_runt_frames), 1368ddc9aaaSMichael Chan 1378ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_64b_frames), 1388ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_65b_127b_frames), 1398ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_128b_255b_frames), 1408ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_256b_511b_frames), 1418ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames), 1428ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_1024b_1518_frames), 1438ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_vlan_frames), 1448ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_1519b_2047_frames), 1458ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames), 1468ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames), 1478ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames), 1488ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_good_frames), 1498ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_frames), 1508ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_ucast_frames), 1518ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_mcast_frames), 1528ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bcast_frames), 1538ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pause_frames), 1548ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_pfc_frames), 1558ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_jabber_frames), 1568ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fcs_err_frames), 1578ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_err), 1588ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_fifo_underruns), 1598ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_events), 1608ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration), 1618ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_total_collisions), 1628ddc9aaaSMichael Chan BNXT_TX_STATS_ENTRY(tx_bytes), 1638ddc9aaaSMichael Chan }; 1648ddc9aaaSMichael Chan 1658ddc9aaaSMichael Chan #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr) 1668ddc9aaaSMichael Chan 167c0c050c5SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 168c0c050c5SMichael Chan { 169c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 170c0c050c5SMichael Chan 171c0c050c5SMichael Chan switch (sset) { 1728ddc9aaaSMichael Chan case ETH_SS_STATS: { 1738ddc9aaaSMichael Chan int num_stats = BNXT_NUM_STATS * bp->cp_nr_rings; 1748ddc9aaaSMichael Chan 1758ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) 1768ddc9aaaSMichael Chan num_stats += BNXT_NUM_PORT_STATS; 1778ddc9aaaSMichael Chan 1788ddc9aaaSMichael Chan return num_stats; 1798ddc9aaaSMichael Chan } 180c0c050c5SMichael Chan default: 181c0c050c5SMichael Chan return -EOPNOTSUPP; 182c0c050c5SMichael Chan } 183c0c050c5SMichael Chan } 184c0c050c5SMichael Chan 185c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 186c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 187c0c050c5SMichael Chan { 188c0c050c5SMichael Chan u32 i, j = 0; 189c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 190c0c050c5SMichael Chan u32 buf_size = sizeof(struct ctx_hw_stats) * bp->cp_nr_rings; 191c0c050c5SMichael Chan u32 stat_fields = sizeof(struct ctx_hw_stats) / 8; 192c0c050c5SMichael Chan 193c0c050c5SMichael Chan memset(buf, 0, buf_size); 194c0c050c5SMichael Chan 195c0c050c5SMichael Chan if (!bp->bnapi) 196c0c050c5SMichael Chan return; 197c0c050c5SMichael Chan 198c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 199c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 200c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 201c0c050c5SMichael Chan __le64 *hw_stats = (__le64 *)cpr->hw_stats; 202c0c050c5SMichael Chan int k; 203c0c050c5SMichael Chan 204c0c050c5SMichael Chan for (k = 0; k < stat_fields; j++, k++) 205c0c050c5SMichael Chan buf[j] = le64_to_cpu(hw_stats[k]); 206c0c050c5SMichael Chan buf[j++] = cpr->rx_l4_csum_errors; 207c0c050c5SMichael Chan } 2088ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 2098ddc9aaaSMichael Chan __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats; 2108ddc9aaaSMichael Chan 2118ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) { 2128ddc9aaaSMichael Chan buf[j] = le64_to_cpu(*(port_stats + 2138ddc9aaaSMichael Chan bnxt_port_stats_arr[i].offset)); 2148ddc9aaaSMichael Chan } 2158ddc9aaaSMichael Chan } 216c0c050c5SMichael Chan } 217c0c050c5SMichael Chan 218c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 219c0c050c5SMichael Chan { 220c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 221c0c050c5SMichael Chan u32 i; 222c0c050c5SMichael Chan 223c0c050c5SMichael Chan switch (stringset) { 224c0c050c5SMichael Chan /* The number of strings must match BNXT_NUM_STATS defined above. */ 225c0c050c5SMichael Chan case ETH_SS_STATS: 226c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 227c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_ucast_packets", i); 228c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 229c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_mcast_packets", i); 230c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 231c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_bcast_packets", i); 232c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 233c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_discards", i); 234c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 235c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_drops", i); 236c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 237c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_ucast_bytes", i); 238c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 239c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_mcast_bytes", i); 240c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 241c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_bcast_bytes", i); 242c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 243c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_ucast_packets", i); 244c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 245c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_mcast_packets", i); 246c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 247c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_bcast_packets", i); 248c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 249c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_discards", i); 250c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 251c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_drops", i); 252c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 253c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_ucast_bytes", i); 254c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 255c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_mcast_bytes", i); 256c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 257c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_bcast_bytes", i); 258c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 259c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_packets", i); 260c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 261c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_bytes", i); 262c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 263c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_events", i); 264c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 265c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_aborts", i); 266c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 267c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_l4_csum_errors", i); 268c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 269c0c050c5SMichael Chan } 2708ddc9aaaSMichael Chan if (bp->flags & BNXT_FLAG_PORT_STATS) { 2718ddc9aaaSMichael Chan for (i = 0; i < BNXT_NUM_PORT_STATS; i++) { 2728ddc9aaaSMichael Chan strcpy(buf, bnxt_port_stats_arr[i].string); 2738ddc9aaaSMichael Chan buf += ETH_GSTRING_LEN; 2748ddc9aaaSMichael Chan } 2758ddc9aaaSMichael Chan } 276c0c050c5SMichael Chan break; 277c0c050c5SMichael Chan default: 278c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 279c0c050c5SMichael Chan stringset); 280c0c050c5SMichael Chan break; 281c0c050c5SMichael Chan } 282c0c050c5SMichael Chan } 283c0c050c5SMichael Chan 284c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 285c0c050c5SMichael Chan struct ethtool_ringparam *ering) 286c0c050c5SMichael Chan { 287c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 288c0c050c5SMichael Chan 289c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 290c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 291c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 292c0c050c5SMichael Chan 293c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 294c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 295c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 296c0c050c5SMichael Chan } 297c0c050c5SMichael Chan 298c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 299c0c050c5SMichael Chan struct ethtool_ringparam *ering) 300c0c050c5SMichael Chan { 301c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 302c0c050c5SMichael Chan 303c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 304c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 305c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 306c0c050c5SMichael Chan return -EINVAL; 307c0c050c5SMichael Chan 308c0c050c5SMichael Chan if (netif_running(dev)) 309c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 310c0c050c5SMichael Chan 311c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 312c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 313c0c050c5SMichael Chan bnxt_set_ring_params(bp); 314c0c050c5SMichael Chan 315c0c050c5SMichael Chan if (netif_running(dev)) 316c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 317c0c050c5SMichael Chan 318c0c050c5SMichael Chan return 0; 319c0c050c5SMichael Chan } 320c0c050c5SMichael Chan 321c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 322c0c050c5SMichael Chan struct ethtool_channels *channel) 323c0c050c5SMichael Chan { 324c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 325c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 326c0c050c5SMichael Chan 3276e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 328068c9ec6SMichael Chan channel->max_combined = max_rx_rings; 329068c9ec6SMichael Chan 330068c9ec6SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false); 331c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 332c0c050c5SMichael Chan if (tcs > 1) 333c0c050c5SMichael Chan max_tx_rings /= tcs; 334c0c050c5SMichael Chan 335c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 336c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 337c0c050c5SMichael Chan channel->max_other = 0; 338068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 339068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 340068c9ec6SMichael Chan } else { 341c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 342c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 343c0c050c5SMichael Chan } 344068c9ec6SMichael Chan } 345c0c050c5SMichael Chan 346c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 347c0c050c5SMichael Chan struct ethtool_channels *channel) 348c0c050c5SMichael Chan { 349c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 350c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 351c0c050c5SMichael Chan u32 rc = 0; 352068c9ec6SMichael Chan bool sh = false; 353c0c050c5SMichael Chan 354068c9ec6SMichael Chan if (channel->other_count) 355c0c050c5SMichael Chan return -EINVAL; 356c0c050c5SMichael Chan 357068c9ec6SMichael Chan if (!channel->combined_count && 358068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 359068c9ec6SMichael Chan return -EINVAL; 360068c9ec6SMichael Chan 361068c9ec6SMichael Chan if (channel->combined_count && 362068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 363068c9ec6SMichael Chan return -EINVAL; 364068c9ec6SMichael Chan 365068c9ec6SMichael Chan if (channel->combined_count) 366068c9ec6SMichael Chan sh = true; 367068c9ec6SMichael Chan 368068c9ec6SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh); 369068c9ec6SMichael Chan 370c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 371c0c050c5SMichael Chan if (tcs > 1) 372c0c050c5SMichael Chan max_tx_rings /= tcs; 373c0c050c5SMichael Chan 374068c9ec6SMichael Chan if (sh && (channel->combined_count > max_rx_rings || 375068c9ec6SMichael Chan channel->combined_count > max_tx_rings)) 376068c9ec6SMichael Chan return -ENOMEM; 377068c9ec6SMichael Chan 378068c9ec6SMichael Chan if (!sh && (channel->rx_count > max_rx_rings || 379068c9ec6SMichael Chan channel->tx_count > max_tx_rings)) 380068c9ec6SMichael Chan return -ENOMEM; 381c0c050c5SMichael Chan 382c0c050c5SMichael Chan if (netif_running(dev)) { 383c0c050c5SMichael Chan if (BNXT_PF(bp)) { 384c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 385c0c050c5SMichael Chan * before PF unload 386c0c050c5SMichael Chan */ 387c0c050c5SMichael Chan } 388c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 389c0c050c5SMichael Chan if (rc) { 390c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 391c0c050c5SMichael Chan rc); 392c0c050c5SMichael Chan return rc; 393c0c050c5SMichael Chan } 394c0c050c5SMichael Chan } 395c0c050c5SMichael Chan 396068c9ec6SMichael Chan if (sh) { 397068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 398068c9ec6SMichael Chan bp->rx_nr_rings = channel->combined_count; 399068c9ec6SMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 400068c9ec6SMichael Chan } else { 401068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 402c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 403c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 404068c9ec6SMichael Chan } 405068c9ec6SMichael Chan 406c0c050c5SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc; 407c0c050c5SMichael Chan if (tcs > 1) 408c0c050c5SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs; 409068c9ec6SMichael Chan 410068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 411068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 412068c9ec6SMichael Chan 413c0c050c5SMichael Chan bp->num_stat_ctxs = bp->cp_nr_rings; 414c0c050c5SMichael Chan 4152bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 4162bcfa6f6SMichael Chan netdev_update_features(dev); 417c0c050c5SMichael Chan if (netif_running(dev)) { 418c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 419c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 420c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 421c0c050c5SMichael Chan * to renable 422c0c050c5SMichael Chan */ 423c0c050c5SMichael Chan } 424c0c050c5SMichael Chan } 425c0c050c5SMichael Chan 426c0c050c5SMichael Chan return rc; 427c0c050c5SMichael Chan } 428c0c050c5SMichael Chan 429c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 430c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 431c0c050c5SMichael Chan u32 *rule_locs) 432c0c050c5SMichael Chan { 433c0c050c5SMichael Chan int i, j = 0; 434c0c050c5SMichael Chan 435c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 436c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 437c0c050c5SMichael Chan struct hlist_head *head; 438c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 439c0c050c5SMichael Chan 440c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 441c0c050c5SMichael Chan rcu_read_lock(); 442c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 443c0c050c5SMichael Chan if (j == cmd->rule_cnt) 444c0c050c5SMichael Chan break; 445c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 446c0c050c5SMichael Chan } 447c0c050c5SMichael Chan rcu_read_unlock(); 448c0c050c5SMichael Chan if (j == cmd->rule_cnt) 449c0c050c5SMichael Chan break; 450c0c050c5SMichael Chan } 451c0c050c5SMichael Chan cmd->rule_cnt = j; 452c0c050c5SMichael Chan return 0; 453c0c050c5SMichael Chan } 454c0c050c5SMichael Chan 455c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 456c0c050c5SMichael Chan { 457c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 458c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 459c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 460c0c050c5SMichael Chan struct flow_keys *fkeys; 461c0c050c5SMichael Chan int i, rc = -EINVAL; 462c0c050c5SMichael Chan 463c0c050c5SMichael Chan if (fs->location < 0 || fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 464c0c050c5SMichael Chan return rc; 465c0c050c5SMichael Chan 466c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 467c0c050c5SMichael Chan struct hlist_head *head; 468c0c050c5SMichael Chan 469c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 470c0c050c5SMichael Chan rcu_read_lock(); 471c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 472c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 473c0c050c5SMichael Chan goto fltr_found; 474c0c050c5SMichael Chan } 475c0c050c5SMichael Chan rcu_read_unlock(); 476c0c050c5SMichael Chan } 477c0c050c5SMichael Chan return rc; 478c0c050c5SMichael Chan 479c0c050c5SMichael Chan fltr_found: 480c0c050c5SMichael Chan fkeys = &fltr->fkeys; 481c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 482c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 483c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 484c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 485c0c050c5SMichael Chan else 486c0c050c5SMichael Chan goto fltr_err; 487c0c050c5SMichael Chan 488c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 489c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 490c0c050c5SMichael Chan 491c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 492c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 493c0c050c5SMichael Chan 494c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 495c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 496c0c050c5SMichael Chan 497c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 498c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 499c0c050c5SMichael Chan 500c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 501c0c050c5SMichael Chan rc = 0; 502c0c050c5SMichael Chan 503c0c050c5SMichael Chan fltr_err: 504c0c050c5SMichael Chan rcu_read_unlock(); 505c0c050c5SMichael Chan 506c0c050c5SMichael Chan return rc; 507c0c050c5SMichael Chan } 508c0c050c5SMichael Chan 509c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 510c0c050c5SMichael Chan u32 *rule_locs) 511c0c050c5SMichael Chan { 512c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 513c0c050c5SMichael Chan int rc = 0; 514c0c050c5SMichael Chan 515c0c050c5SMichael Chan switch (cmd->cmd) { 516c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 517c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 518c0c050c5SMichael Chan break; 519c0c050c5SMichael Chan 520c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 521c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 522c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 523c0c050c5SMichael Chan break; 524c0c050c5SMichael Chan 525c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 526c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 527c0c050c5SMichael Chan break; 528c0c050c5SMichael Chan 529c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 530c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 531c0c050c5SMichael Chan break; 532c0c050c5SMichael Chan 533c0c050c5SMichael Chan default: 534c0c050c5SMichael Chan rc = -EOPNOTSUPP; 535c0c050c5SMichael Chan break; 536c0c050c5SMichael Chan } 537c0c050c5SMichael Chan 538c0c050c5SMichael Chan return rc; 539c0c050c5SMichael Chan } 540c0c050c5SMichael Chan #endif 541c0c050c5SMichael Chan 542c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 543c0c050c5SMichael Chan { 544c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 545c0c050c5SMichael Chan } 546c0c050c5SMichael Chan 547c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 548c0c050c5SMichael Chan { 549c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 550c0c050c5SMichael Chan } 551c0c050c5SMichael Chan 552c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 553c0c050c5SMichael Chan u8 *hfunc) 554c0c050c5SMichael Chan { 555c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 556c0c050c5SMichael Chan struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; 557c0c050c5SMichael Chan int i = 0; 558c0c050c5SMichael Chan 559c0c050c5SMichael Chan if (hfunc) 560c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 561c0c050c5SMichael Chan 562c0c050c5SMichael Chan if (indir) 563c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 564c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 565c0c050c5SMichael Chan 566c0c050c5SMichael Chan if (key) 567c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 568c0c050c5SMichael Chan 569c0c050c5SMichael Chan return 0; 570c0c050c5SMichael Chan } 571c0c050c5SMichael Chan 572c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 573c0c050c5SMichael Chan struct ethtool_drvinfo *info) 574c0c050c5SMichael Chan { 575c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 5763ebf6f0aSRob Swindell char *pkglog; 5773ebf6f0aSRob Swindell char *pkgver = NULL; 578c0c050c5SMichael Chan 5793ebf6f0aSRob Swindell pkglog = kmalloc(BNX_PKG_LOG_MAX_LENGTH, GFP_KERNEL); 5803ebf6f0aSRob Swindell if (pkglog) 5813ebf6f0aSRob Swindell pkgver = bnxt_get_pkgver(dev, pkglog, BNX_PKG_LOG_MAX_LENGTH); 582c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 583c0c050c5SMichael Chan strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 5843ebf6f0aSRob Swindell if (pkgver && *pkgver != 0 && isdigit(*pkgver)) 5853ebf6f0aSRob Swindell snprintf(info->fw_version, sizeof(info->fw_version) - 1, 5863ebf6f0aSRob Swindell "%s pkg %s", bp->fw_ver_str, pkgver); 5873ebf6f0aSRob Swindell else 5883ebf6f0aSRob Swindell strlcpy(info->fw_version, bp->fw_ver_str, 5893ebf6f0aSRob Swindell sizeof(info->fw_version)); 590c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 591c0c050c5SMichael Chan info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings; 592c0c050c5SMichael Chan info->testinfo_len = BNXT_NUM_TESTS(bp); 593c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 594c0c050c5SMichael Chan info->eedump_len = 0; 595c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 596c0c050c5SMichael Chan info->regdump_len = 0; 5973ebf6f0aSRob Swindell kfree(pkglog); 598c0c050c5SMichael Chan } 599c0c050c5SMichael Chan 600170ce013SMichael Chan u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause) 601c0c050c5SMichael Chan { 602c0c050c5SMichael Chan u32 speed_mask = 0; 603c0c050c5SMichael Chan 604c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 605c0c050c5SMichael Chan /* set the advertised speeds */ 606c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 607c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 608c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 609c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 610c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 611c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 612c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 613c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 614c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 6151c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 61627c4d578SMichael Chan 61727c4d578SMichael Chan if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH) 61827c4d578SMichael Chan speed_mask |= ADVERTISED_Pause; 61927c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_TX) 62027c4d578SMichael Chan speed_mask |= ADVERTISED_Asym_Pause; 62127c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_RX) 62227c4d578SMichael Chan speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 62327c4d578SMichael Chan 624c0c050c5SMichael Chan return speed_mask; 625c0c050c5SMichael Chan } 626c0c050c5SMichael Chan 62727c4d578SMichael Chan static u32 bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info) 62827c4d578SMichael Chan { 62927c4d578SMichael Chan u16 fw_speeds = link_info->auto_link_speeds; 63027c4d578SMichael Chan u8 fw_pause = 0; 63127c4d578SMichael Chan 63227c4d578SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 63327c4d578SMichael Chan fw_pause = link_info->auto_pause_setting; 63427c4d578SMichael Chan 63527c4d578SMichael Chan return _bnxt_fw_to_ethtool_adv_spds(fw_speeds, fw_pause); 63627c4d578SMichael Chan } 63727c4d578SMichael Chan 6383277360eSMichael Chan static u32 bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info) 6393277360eSMichael Chan { 6403277360eSMichael Chan u16 fw_speeds = link_info->lp_auto_link_speeds; 6413277360eSMichael Chan u8 fw_pause = 0; 6423277360eSMichael Chan 6433277360eSMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 6443277360eSMichael Chan fw_pause = link_info->lp_pause; 6453277360eSMichael Chan 6463277360eSMichael Chan return _bnxt_fw_to_ethtool_adv_spds(fw_speeds, fw_pause); 6473277360eSMichael Chan } 6483277360eSMichael Chan 6494b32caccSMichael Chan static u32 bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info) 6504b32caccSMichael Chan { 6514b32caccSMichael Chan u16 fw_speeds = link_info->support_speeds; 6524b32caccSMichael Chan u32 supported; 6534b32caccSMichael Chan 6544b32caccSMichael Chan supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); 6554b32caccSMichael Chan return supported | SUPPORTED_Pause | SUPPORTED_Asym_Pause; 6564b32caccSMichael Chan } 6574b32caccSMichael Chan 658c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 659c0c050c5SMichael Chan { 660c0c050c5SMichael Chan switch (fw_link_speed) { 661c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 662c0c050c5SMichael Chan return SPEED_100; 663c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 664c0c050c5SMichael Chan return SPEED_1000; 665c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 666c0c050c5SMichael Chan return SPEED_2500; 667c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 668c0c050c5SMichael Chan return SPEED_10000; 669c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 670c0c050c5SMichael Chan return SPEED_20000; 671c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 672c0c050c5SMichael Chan return SPEED_25000; 673c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 674c0c050c5SMichael Chan return SPEED_40000; 675c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 676c0c050c5SMichael Chan return SPEED_50000; 677c0c050c5SMichael Chan default: 678c0c050c5SMichael Chan return SPEED_UNKNOWN; 679c0c050c5SMichael Chan } 680c0c050c5SMichael Chan } 681c0c050c5SMichael Chan 682c0c050c5SMichael Chan static int bnxt_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 683c0c050c5SMichael Chan { 684c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 685c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 686c0c050c5SMichael Chan u16 ethtool_speed; 687c0c050c5SMichael Chan 688c0c050c5SMichael Chan cmd->supported = bnxt_fw_to_ethtool_support_spds(link_info); 689c0c050c5SMichael Chan 690c0c050c5SMichael Chan if (link_info->auto_link_speeds) 691c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Autoneg; 692c0c050c5SMichael Chan 693b763499eSMichael Chan if (link_info->autoneg) { 694c0c050c5SMichael Chan cmd->advertising = 695c0c050c5SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info); 696c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Autoneg; 697c0c050c5SMichael Chan cmd->autoneg = AUTONEG_ENABLE; 6983277360eSMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) 6993277360eSMichael Chan cmd->lp_advertising = 7003277360eSMichael Chan bnxt_fw_to_ethtool_lp_adv(link_info); 70129c262feSMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 70229c262feSMichael Chan if (!netif_carrier_ok(dev)) 70329c262feSMichael Chan cmd->duplex = DUPLEX_UNKNOWN; 70429c262feSMichael Chan else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 70529c262feSMichael Chan cmd->duplex = DUPLEX_FULL; 70629c262feSMichael Chan else 70729c262feSMichael Chan cmd->duplex = DUPLEX_HALF; 708c0c050c5SMichael Chan } else { 709c0c050c5SMichael Chan cmd->autoneg = AUTONEG_DISABLE; 710c0c050c5SMichael Chan cmd->advertising = 0; 71129c262feSMichael Chan ethtool_speed = 71229c262feSMichael Chan bnxt_fw_to_ethtool_speed(link_info->req_link_speed); 71329c262feSMichael Chan cmd->duplex = DUPLEX_HALF; 71429c262feSMichael Chan if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL) 71529c262feSMichael Chan cmd->duplex = DUPLEX_FULL; 716c0c050c5SMichael Chan } 71729c262feSMichael Chan ethtool_cmd_speed_set(cmd, ethtool_speed); 718c0c050c5SMichael Chan 719c0c050c5SMichael Chan cmd->port = PORT_NONE; 720c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 721c0c050c5SMichael Chan cmd->port = PORT_TP; 722c0c050c5SMichael Chan cmd->supported |= SUPPORTED_TP; 723c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_TP; 724c0c050c5SMichael Chan } else { 725c0c050c5SMichael Chan cmd->supported |= SUPPORTED_FIBRE; 726c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_FIBRE; 727c0c050c5SMichael Chan 728c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 729c0c050c5SMichael Chan cmd->port = PORT_DA; 730c0c050c5SMichael Chan else if (link_info->media_type == 731c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 732c0c050c5SMichael Chan cmd->port = PORT_FIBRE; 733c0c050c5SMichael Chan } 734c0c050c5SMichael Chan 735c0c050c5SMichael Chan if (link_info->transceiver == 73611f15ed3SMichael Chan PORT_PHY_QCFG_RESP_XCVR_PKG_TYPE_XCVR_INTERNAL) 737c0c050c5SMichael Chan cmd->transceiver = XCVR_INTERNAL; 738c0c050c5SMichael Chan else 739c0c050c5SMichael Chan cmd->transceiver = XCVR_EXTERNAL; 740c0c050c5SMichael Chan cmd->phy_address = link_info->phy_addr; 741c0c050c5SMichael Chan 742c0c050c5SMichael Chan return 0; 743c0c050c5SMichael Chan } 744c0c050c5SMichael Chan 745c0c050c5SMichael Chan static u32 bnxt_get_fw_speed(struct net_device *dev, u16 ethtool_speed) 746c0c050c5SMichael Chan { 7479d9cee08SMichael Chan struct bnxt *bp = netdev_priv(dev); 7489d9cee08SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 7499d9cee08SMichael Chan u16 support_spds = link_info->support_speeds; 7509d9cee08SMichael Chan u32 fw_speed = 0; 7519d9cee08SMichael Chan 752c0c050c5SMichael Chan switch (ethtool_speed) { 753c0c050c5SMichael Chan case SPEED_100: 7549d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_100MB) 7559d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 7569d9cee08SMichael Chan break; 757c0c050c5SMichael Chan case SPEED_1000: 7589d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_1GB) 7599d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 7609d9cee08SMichael Chan break; 761c0c050c5SMichael Chan case SPEED_2500: 7629d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB) 7639d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 7649d9cee08SMichael Chan break; 765c0c050c5SMichael Chan case SPEED_10000: 7669d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_10GB) 7679d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 7689d9cee08SMichael Chan break; 769c0c050c5SMichael Chan case SPEED_20000: 7709d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_20GB) 7719d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 7729d9cee08SMichael Chan break; 773c0c050c5SMichael Chan case SPEED_25000: 7749d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_25GB) 7759d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 7769d9cee08SMichael Chan break; 777c0c050c5SMichael Chan case SPEED_40000: 7789d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_40GB) 7799d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 7809d9cee08SMichael Chan break; 781c0c050c5SMichael Chan case SPEED_50000: 7829d9cee08SMichael Chan if (support_spds & BNXT_LINK_SPEED_MSK_50GB) 7839d9cee08SMichael Chan fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 7849d9cee08SMichael Chan break; 785c0c050c5SMichael Chan default: 786c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 787c0c050c5SMichael Chan break; 788c0c050c5SMichael Chan } 7899d9cee08SMichael Chan return fw_speed; 790c0c050c5SMichael Chan } 791c0c050c5SMichael Chan 792939f7f0cSMichael Chan u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 793c0c050c5SMichael Chan { 794c0c050c5SMichael Chan u16 fw_speed_mask = 0; 795c0c050c5SMichael Chan 796c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 797c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 798c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 799c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 800c0c050c5SMichael Chan } 801c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 802c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 803c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 804c0c050c5SMichael Chan } 805c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 806c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 807c0c050c5SMichael Chan 8081c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 8091c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 8101c49c421SMichael Chan 811c0c050c5SMichael Chan return fw_speed_mask; 812c0c050c5SMichael Chan } 813c0c050c5SMichael Chan 814c0c050c5SMichael Chan static int bnxt_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 815c0c050c5SMichael Chan { 816c0c050c5SMichael Chan int rc = 0; 817c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 818c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 819c0c050c5SMichael Chan u32 speed, fw_advertising = 0; 820c0c050c5SMichael Chan bool set_pause = false; 821c0c050c5SMichael Chan 822c0c050c5SMichael Chan if (BNXT_VF(bp)) 823c0c050c5SMichael Chan return rc; 824c0c050c5SMichael Chan 825c0c050c5SMichael Chan if (cmd->autoneg == AUTONEG_ENABLE) { 826f1a082a6SMichael Chan u32 supported_spds = bnxt_fw_to_ethtool_support_spds(link_info); 827f1a082a6SMichael Chan 828f1a082a6SMichael Chan if (cmd->advertising & ~(supported_spds | ADVERTISED_Autoneg | 829f1a082a6SMichael Chan ADVERTISED_TP | ADVERTISED_FIBRE)) { 830c0c050c5SMichael Chan netdev_err(dev, "Unsupported advertising mask (adv: 0x%x)\n", 831c0c050c5SMichael Chan cmd->advertising); 832c0c050c5SMichael Chan rc = -EINVAL; 833c0c050c5SMichael Chan goto set_setting_exit; 834c0c050c5SMichael Chan } 835c0c050c5SMichael Chan fw_advertising = bnxt_get_fw_auto_link_speeds(cmd->advertising); 836c0c050c5SMichael Chan if (fw_advertising & ~link_info->support_speeds) { 837c0c050c5SMichael Chan netdev_err(dev, "Advertising parameters are not supported! (adv: 0x%x)\n", 838c0c050c5SMichael Chan cmd->advertising); 839c0c050c5SMichael Chan rc = -EINVAL; 840c0c050c5SMichael Chan goto set_setting_exit; 841c0c050c5SMichael Chan } 842c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 843c0c050c5SMichael Chan if (!fw_advertising) 844c0c050c5SMichael Chan link_info->advertising = link_info->support_speeds; 845c0c050c5SMichael Chan else 846c0c050c5SMichael Chan link_info->advertising = fw_advertising; 847c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 848c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 849c0c050c5SMichael Chan */ 850c0c050c5SMichael Chan set_pause = true; 851c0c050c5SMichael Chan } else { 8529d9cee08SMichael Chan u16 fw_speed; 8539d9cee08SMichael Chan 854c0c050c5SMichael Chan /* TODO: currently don't support half duplex */ 855c0c050c5SMichael Chan if (cmd->duplex == DUPLEX_HALF) { 856c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 857c0c050c5SMichael Chan rc = -EINVAL; 858c0c050c5SMichael Chan goto set_setting_exit; 859c0c050c5SMichael Chan } 860c0c050c5SMichael Chan /* If received a request for an unknown duplex, assume full*/ 861c0c050c5SMichael Chan if (cmd->duplex == DUPLEX_UNKNOWN) 862c0c050c5SMichael Chan cmd->duplex = DUPLEX_FULL; 863c0c050c5SMichael Chan speed = ethtool_cmd_speed(cmd); 8649d9cee08SMichael Chan fw_speed = bnxt_get_fw_speed(dev, speed); 8659d9cee08SMichael Chan if (!fw_speed) { 8669d9cee08SMichael Chan rc = -EINVAL; 8679d9cee08SMichael Chan goto set_setting_exit; 8689d9cee08SMichael Chan } 8699d9cee08SMichael Chan link_info->req_link_speed = fw_speed; 870c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 871b763499eSMichael Chan link_info->autoneg = 0; 872c0c050c5SMichael Chan link_info->advertising = 0; 873c0c050c5SMichael Chan } 874c0c050c5SMichael Chan 875c0c050c5SMichael Chan if (netif_running(dev)) 876939f7f0cSMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause, false); 877c0c050c5SMichael Chan 878c0c050c5SMichael Chan set_setting_exit: 879c0c050c5SMichael Chan return rc; 880c0c050c5SMichael Chan } 881c0c050c5SMichael Chan 882c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 883c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 884c0c050c5SMichael Chan { 885c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 886c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 887c0c050c5SMichael Chan 888c0c050c5SMichael Chan if (BNXT_VF(bp)) 889c0c050c5SMichael Chan return; 890b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 8913c02d1bbSMichael Chan epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX); 8923c02d1bbSMichael Chan epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX); 893c0c050c5SMichael Chan } 894c0c050c5SMichael Chan 895c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 896c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 897c0c050c5SMichael Chan { 898c0c050c5SMichael Chan int rc = 0; 899c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 900c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 901c0c050c5SMichael Chan 902c0c050c5SMichael Chan if (BNXT_VF(bp)) 903c0c050c5SMichael Chan return rc; 904c0c050c5SMichael Chan 905c0c050c5SMichael Chan if (epause->autoneg) { 906b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 907b763499eSMichael Chan return -EINVAL; 908b763499eSMichael Chan 909c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 910c9ee9516SMichael Chan if (bp->hwrm_spec_code >= 0x10201) 911c9ee9516SMichael Chan link_info->req_flow_ctrl = 912c9ee9516SMichael Chan PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; 913c0c050c5SMichael Chan } else { 914c0c050c5SMichael Chan /* when transition from auto pause to force pause, 915c0c050c5SMichael Chan * force a link change 916c0c050c5SMichael Chan */ 917c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 918c0c050c5SMichael Chan link_info->force_link_chng = true; 919c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 920c9ee9516SMichael Chan link_info->req_flow_ctrl = 0; 921c0c050c5SMichael Chan } 922c0c050c5SMichael Chan if (epause->rx_pause) 923c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 924c0c050c5SMichael Chan 925c0c050c5SMichael Chan if (epause->tx_pause) 926c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 927c0c050c5SMichael Chan 928c0c050c5SMichael Chan if (netif_running(dev)) 929c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 930c0c050c5SMichael Chan return rc; 931c0c050c5SMichael Chan } 932c0c050c5SMichael Chan 933c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 934c0c050c5SMichael Chan { 935c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 936c0c050c5SMichael Chan 937c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 938c0c050c5SMichael Chan return bp->link_info.link_up; 939c0c050c5SMichael Chan } 940c0c050c5SMichael Chan 941c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 942c0c050c5SMichael Chan u16 dir_type, 943c0c050c5SMichael Chan u16 dir_ordinal, 944c0c050c5SMichael Chan u16 dir_ext, 945c0c050c5SMichael Chan u16 dir_attr, 946c0c050c5SMichael Chan const u8 *data, 947c0c050c5SMichael Chan size_t data_len) 948c0c050c5SMichael Chan { 949c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 950c0c050c5SMichael Chan int rc; 951c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 952c0c050c5SMichael Chan dma_addr_t dma_handle; 953c0c050c5SMichael Chan u8 *kmem; 954c0c050c5SMichael Chan 955c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 956c0c050c5SMichael Chan 957c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 958c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 959c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 960c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 961c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 962c0c050c5SMichael Chan 963c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 964c0c050c5SMichael Chan GFP_KERNEL); 965c0c050c5SMichael Chan if (!kmem) { 966c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 967c0c050c5SMichael Chan (unsigned)data_len); 968c0c050c5SMichael Chan return -ENOMEM; 969c0c050c5SMichael Chan } 970c0c050c5SMichael Chan memcpy(kmem, data, data_len); 971c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 972c0c050c5SMichael Chan 973c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 974c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 975c0c050c5SMichael Chan 976c0c050c5SMichael Chan return rc; 977c0c050c5SMichael Chan } 978c0c050c5SMichael Chan 979d2d6318cSRob Swindell static int bnxt_firmware_reset(struct net_device *dev, 980d2d6318cSRob Swindell u16 dir_type) 981d2d6318cSRob Swindell { 982d2d6318cSRob Swindell struct bnxt *bp = netdev_priv(dev); 983d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 984d2d6318cSRob Swindell 985d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 986d2d6318cSRob Swindell 987d2d6318cSRob Swindell /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */ 988d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 989d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 990d2d6318cSRob Swindell switch (dir_type) { 991d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 992d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 993d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 994d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 995d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 996d2d6318cSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 997d2d6318cSRob Swindell break; 998d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 999d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 1000d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 1001d2d6318cSRob Swindell break; 1002d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 1003d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 1004d2d6318cSRob Swindell req.embedded_proc_type = 1005d2d6318cSRob Swindell FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 1006d2d6318cSRob Swindell break; 1007d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 1008d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 1009d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 1010d2d6318cSRob Swindell break; 1011d2d6318cSRob Swindell default: 1012d2d6318cSRob Swindell return -EINVAL; 1013d2d6318cSRob Swindell } 1014d2d6318cSRob Swindell 1015d2d6318cSRob Swindell return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1016d2d6318cSRob Swindell } 1017d2d6318cSRob Swindell 1018c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 1019c0c050c5SMichael Chan u16 dir_type, 1020c0c050c5SMichael Chan const u8 *fw_data, 1021c0c050c5SMichael Chan size_t fw_size) 1022c0c050c5SMichael Chan { 1023c0c050c5SMichael Chan int rc = 0; 1024c0c050c5SMichael Chan u16 code_type; 1025c0c050c5SMichael Chan u32 stored_crc; 1026c0c050c5SMichael Chan u32 calculated_crc; 1027c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 1028c0c050c5SMichael Chan 1029c0c050c5SMichael Chan switch (dir_type) { 1030c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1031c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1032c0c050c5SMichael Chan code_type = CODE_BOOT; 1033c0c050c5SMichael Chan break; 10342731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 10352731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 10362731d70fSRob Swindell break; 1037c0c050c5SMichael Chan default: 1038c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 1039c0c050c5SMichael Chan dir_type); 1040c0c050c5SMichael Chan return -EINVAL; 1041c0c050c5SMichael Chan } 1042c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 1043c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 1044c0c050c5SMichael Chan (unsigned int)fw_size); 1045c0c050c5SMichael Chan return -EINVAL; 1046c0c050c5SMichael Chan } 1047c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 1048c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 1049c0c050c5SMichael Chan le32_to_cpu(header->signature)); 1050c0c050c5SMichael Chan return -EINVAL; 1051c0c050c5SMichael Chan } 1052c0c050c5SMichael Chan if (header->code_type != code_type) { 1053c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 1054c0c050c5SMichael Chan code_type, header->code_type); 1055c0c050c5SMichael Chan return -EINVAL; 1056c0c050c5SMichael Chan } 1057c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 1058c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 1059c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 1060c0c050c5SMichael Chan return -EINVAL; 1061c0c050c5SMichael Chan } 1062c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 1063c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 1064c0c050c5SMichael Chan sizeof(stored_crc))); 1065c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 1066c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 1067c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 1068c0c050c5SMichael Chan (unsigned long)stored_crc, 1069c0c050c5SMichael Chan (unsigned long)calculated_crc); 1070c0c050c5SMichael Chan return -EINVAL; 1071c0c050c5SMichael Chan } 1072c0c050c5SMichael Chan /* TODO: Validate digital signature (RSA-encrypted SHA-256 hash) here */ 1073c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1074c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 1075d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 1076d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 1077d2d6318cSRob Swindell 1078c0c050c5SMichael Chan return rc; 1079c0c050c5SMichael Chan } 1080c0c050c5SMichael Chan 1081c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 1082c0c050c5SMichael Chan { 1083c0c050c5SMichael Chan switch (dir_type) { 1084c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 1085c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 1086c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 1087c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 1088c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 1089c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 1090c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 1091c0c050c5SMichael Chan return true; 1092c0c050c5SMichael Chan } 1093c0c050c5SMichael Chan 1094c0c050c5SMichael Chan return false; 1095c0c050c5SMichael Chan } 1096c0c050c5SMichael Chan 1097c0c050c5SMichael Chan static bool bnxt_dir_type_is_unprotected_exec_format(u16 dir_type) 1098c0c050c5SMichael Chan { 1099c0c050c5SMichael Chan switch (dir_type) { 1100c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 1101c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 1102c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 1103c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 1104c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 1105c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 1106c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 1107c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 1108c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 1109c0c050c5SMichael Chan return true; 1110c0c050c5SMichael Chan } 1111c0c050c5SMichael Chan 1112c0c050c5SMichael Chan return false; 1113c0c050c5SMichael Chan } 1114c0c050c5SMichael Chan 1115c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 1116c0c050c5SMichael Chan { 1117c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 1118c0c050c5SMichael Chan bnxt_dir_type_is_unprotected_exec_format(dir_type); 1119c0c050c5SMichael Chan } 1120c0c050c5SMichael Chan 1121c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 1122c0c050c5SMichael Chan u16 dir_type, 1123c0c050c5SMichael Chan const char *filename) 1124c0c050c5SMichael Chan { 1125c0c050c5SMichael Chan const struct firmware *fw; 1126c0c050c5SMichael Chan int rc; 1127c0c050c5SMichael Chan 1128c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(dir_type) == false) 1129c0c050c5SMichael Chan return -EINVAL; 1130c0c050c5SMichael Chan 1131c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 1132c0c050c5SMichael Chan if (rc != 0) { 1133c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 1134c0c050c5SMichael Chan rc, filename); 1135c0c050c5SMichael Chan return rc; 1136c0c050c5SMichael Chan } 1137c0c050c5SMichael Chan if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) 1138c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 1139c0c050c5SMichael Chan else 1140c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1141c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 1142c0c050c5SMichael Chan release_firmware(fw); 1143c0c050c5SMichael Chan return rc; 1144c0c050c5SMichael Chan } 1145c0c050c5SMichael Chan 1146c0c050c5SMichael Chan static int bnxt_flash_package_from_file(struct net_device *dev, 1147c0c050c5SMichael Chan char *filename) 1148c0c050c5SMichael Chan { 1149c0c050c5SMichael Chan netdev_err(dev, "packages are not yet supported\n"); 1150c0c050c5SMichael Chan return -EINVAL; 1151c0c050c5SMichael Chan } 1152c0c050c5SMichael Chan 1153c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 1154c0c050c5SMichael Chan struct ethtool_flash *flash) 1155c0c050c5SMichael Chan { 1156c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 1157c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 1158c0c050c5SMichael Chan return -EINVAL; 1159c0c050c5SMichael Chan } 1160c0c050c5SMichael Chan 1161c0c050c5SMichael Chan if (flash->region == ETHTOOL_FLASH_ALL_REGIONS) 1162c0c050c5SMichael Chan return bnxt_flash_package_from_file(dev, flash->data); 1163c0c050c5SMichael Chan 1164c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 1165c0c050c5SMichael Chan } 1166c0c050c5SMichael Chan 1167c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 1168c0c050c5SMichael Chan { 1169c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1170c0c050c5SMichael Chan int rc; 1171c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 1172c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 1173c0c050c5SMichael Chan 1174c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 1175c0c050c5SMichael Chan 1176c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 1177c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1178c0c050c5SMichael Chan if (!rc) { 1179c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 1180c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 1181c0c050c5SMichael Chan } 1182c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 1183c0c050c5SMichael Chan return rc; 1184c0c050c5SMichael Chan } 1185c0c050c5SMichael Chan 1186c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 1187c0c050c5SMichael Chan { 1188c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 1189c0c050c5SMichael Chan * passed via the ethtool command-line utility. 1190c0c050c5SMichael Chan */ 1191c0c050c5SMichael Chan return -1; 1192c0c050c5SMichael Chan } 1193c0c050c5SMichael Chan 1194c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 1195c0c050c5SMichael Chan { 1196c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1197c0c050c5SMichael Chan int rc; 1198c0c050c5SMichael Chan u32 dir_entries; 1199c0c050c5SMichael Chan u32 entry_length; 1200c0c050c5SMichael Chan u8 *buf; 1201c0c050c5SMichael Chan size_t buflen; 1202c0c050c5SMichael Chan dma_addr_t dma_handle; 1203c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 1204c0c050c5SMichael Chan 1205c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 1206c0c050c5SMichael Chan if (rc != 0) 1207c0c050c5SMichael Chan return rc; 1208c0c050c5SMichael Chan 1209c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 1210c0c050c5SMichael Chan if (len < 2) 1211c0c050c5SMichael Chan return -EINVAL; 1212c0c050c5SMichael Chan 1213c0c050c5SMichael Chan *data++ = dir_entries; 1214c0c050c5SMichael Chan *data++ = entry_length; 1215c0c050c5SMichael Chan len -= 2; 1216c0c050c5SMichael Chan memset(data, 0xff, len); 1217c0c050c5SMichael Chan 1218c0c050c5SMichael Chan buflen = dir_entries * entry_length; 1219c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 1220c0c050c5SMichael Chan GFP_KERNEL); 1221c0c050c5SMichael Chan if (!buf) { 1222c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1223c0c050c5SMichael Chan (unsigned)buflen); 1224c0c050c5SMichael Chan return -ENOMEM; 1225c0c050c5SMichael Chan } 1226c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 1227c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 1228c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1229c0c050c5SMichael Chan if (rc == 0) 1230c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 1231c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 1232c0c050c5SMichael Chan return rc; 1233c0c050c5SMichael Chan } 1234c0c050c5SMichael Chan 1235c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 1236c0c050c5SMichael Chan u32 length, u8 *data) 1237c0c050c5SMichael Chan { 1238c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1239c0c050c5SMichael Chan int rc; 1240c0c050c5SMichael Chan u8 *buf; 1241c0c050c5SMichael Chan dma_addr_t dma_handle; 1242c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 1243c0c050c5SMichael Chan 1244c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 1245c0c050c5SMichael Chan GFP_KERNEL); 1246c0c050c5SMichael Chan if (!buf) { 1247c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1248c0c050c5SMichael Chan (unsigned)length); 1249c0c050c5SMichael Chan return -ENOMEM; 1250c0c050c5SMichael Chan } 1251c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 1252c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 1253c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 1254c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 1255c0c050c5SMichael Chan req.len = cpu_to_le32(length); 1256c0c050c5SMichael Chan 1257c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1258c0c050c5SMichael Chan if (rc == 0) 1259c0c050c5SMichael Chan memcpy(data, buf, length); 1260c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 1261c0c050c5SMichael Chan return rc; 1262c0c050c5SMichael Chan } 1263c0c050c5SMichael Chan 12643ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 12653ebf6f0aSRob Swindell u16 ext, u16 *index, u32 *item_length, 12663ebf6f0aSRob Swindell u32 *data_length) 12673ebf6f0aSRob Swindell { 12683ebf6f0aSRob Swindell struct bnxt *bp = netdev_priv(dev); 12693ebf6f0aSRob Swindell int rc; 12703ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_input req = {0}; 12713ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr; 12723ebf6f0aSRob Swindell 12733ebf6f0aSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1); 12743ebf6f0aSRob Swindell req.enables = 0; 12753ebf6f0aSRob Swindell req.dir_idx = 0; 12763ebf6f0aSRob Swindell req.dir_type = cpu_to_le16(type); 12773ebf6f0aSRob Swindell req.dir_ordinal = cpu_to_le16(ordinal); 12783ebf6f0aSRob Swindell req.dir_ext = cpu_to_le16(ext); 12793ebf6f0aSRob Swindell req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ; 128090e20921SMichael Chan rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 12813ebf6f0aSRob Swindell if (rc == 0) { 12823ebf6f0aSRob Swindell if (index) 12833ebf6f0aSRob Swindell *index = le16_to_cpu(output->dir_idx); 12843ebf6f0aSRob Swindell if (item_length) 12853ebf6f0aSRob Swindell *item_length = le32_to_cpu(output->dir_item_length); 12863ebf6f0aSRob Swindell if (data_length) 12873ebf6f0aSRob Swindell *data_length = le32_to_cpu(output->dir_data_length); 12883ebf6f0aSRob Swindell } 12893ebf6f0aSRob Swindell return rc; 12903ebf6f0aSRob Swindell } 12913ebf6f0aSRob Swindell 12923ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen) 12933ebf6f0aSRob Swindell { 12943ebf6f0aSRob Swindell char *retval = NULL; 12953ebf6f0aSRob Swindell char *p; 12963ebf6f0aSRob Swindell char *value; 12973ebf6f0aSRob Swindell int field = 0; 12983ebf6f0aSRob Swindell 12993ebf6f0aSRob Swindell if (datalen < 1) 13003ebf6f0aSRob Swindell return NULL; 13013ebf6f0aSRob Swindell /* null-terminate the log data (removing last '\n'): */ 13023ebf6f0aSRob Swindell data[datalen - 1] = 0; 13033ebf6f0aSRob Swindell for (p = data; *p != 0; p++) { 13043ebf6f0aSRob Swindell field = 0; 13053ebf6f0aSRob Swindell retval = NULL; 13063ebf6f0aSRob Swindell while (*p != 0 && *p != '\n') { 13073ebf6f0aSRob Swindell value = p; 13083ebf6f0aSRob Swindell while (*p != 0 && *p != '\t' && *p != '\n') 13093ebf6f0aSRob Swindell p++; 13103ebf6f0aSRob Swindell if (field == desired_field) 13113ebf6f0aSRob Swindell retval = value; 13123ebf6f0aSRob Swindell if (*p != '\t') 13133ebf6f0aSRob Swindell break; 13143ebf6f0aSRob Swindell *p = 0; 13153ebf6f0aSRob Swindell field++; 13163ebf6f0aSRob Swindell p++; 13173ebf6f0aSRob Swindell } 13183ebf6f0aSRob Swindell if (*p == 0) 13193ebf6f0aSRob Swindell break; 13203ebf6f0aSRob Swindell *p = 0; 13213ebf6f0aSRob Swindell } 13223ebf6f0aSRob Swindell return retval; 13233ebf6f0aSRob Swindell } 13243ebf6f0aSRob Swindell 13253ebf6f0aSRob Swindell static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen) 13263ebf6f0aSRob Swindell { 13273ebf6f0aSRob Swindell u16 index = 0; 13283ebf6f0aSRob Swindell u32 datalen; 13293ebf6f0aSRob Swindell 13303ebf6f0aSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG, 13313ebf6f0aSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 13323ebf6f0aSRob Swindell &index, NULL, &datalen) != 0) 13333ebf6f0aSRob Swindell return NULL; 13343ebf6f0aSRob Swindell 13353ebf6f0aSRob Swindell memset(buf, 0, buflen); 13363ebf6f0aSRob Swindell if (bnxt_get_nvram_item(dev, index, 0, datalen, buf) != 0) 13373ebf6f0aSRob Swindell return NULL; 13383ebf6f0aSRob Swindell 13393ebf6f0aSRob Swindell return bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, buf, 13403ebf6f0aSRob Swindell datalen); 13413ebf6f0aSRob Swindell } 13423ebf6f0aSRob Swindell 1343c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 1344c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 1345c0c050c5SMichael Chan u8 *data) 1346c0c050c5SMichael Chan { 1347c0c050c5SMichael Chan u32 index; 1348c0c050c5SMichael Chan u32 offset; 1349c0c050c5SMichael Chan 1350c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 1351c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 1352c0c050c5SMichael Chan 1353c0c050c5SMichael Chan index = eeprom->offset >> 24; 1354c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 1355c0c050c5SMichael Chan 1356c0c050c5SMichael Chan if (index == 0) { 1357c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 1358c0c050c5SMichael Chan return -EINVAL; 1359c0c050c5SMichael Chan } 1360c0c050c5SMichael Chan 1361c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 1362c0c050c5SMichael Chan } 1363c0c050c5SMichael Chan 1364c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 1365c0c050c5SMichael Chan { 1366c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1367c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 1368c0c050c5SMichael Chan 1369c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 1370c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 1371c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1372c0c050c5SMichael Chan } 1373c0c050c5SMichael Chan 1374c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 1375c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 1376c0c050c5SMichael Chan u8 *data) 1377c0c050c5SMichael Chan { 1378c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1379c0c050c5SMichael Chan u8 index, dir_op; 1380c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 1381c0c050c5SMichael Chan 1382c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 1383c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 1384c0c050c5SMichael Chan return -EINVAL; 1385c0c050c5SMichael Chan } 1386c0c050c5SMichael Chan 1387c0c050c5SMichael Chan type = eeprom->magic >> 16; 1388c0c050c5SMichael Chan 1389c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 1390c0c050c5SMichael Chan index = eeprom->magic & 0xff; 1391c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 1392c0c050c5SMichael Chan if (index == 0) 1393c0c050c5SMichael Chan return -EINVAL; 1394c0c050c5SMichael Chan switch (dir_op) { 1395c0c050c5SMichael Chan case 0x0e: /* erase */ 1396c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 1397c0c050c5SMichael Chan return -EINVAL; 1398c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 1399c0c050c5SMichael Chan default: 1400c0c050c5SMichael Chan return -EINVAL; 1401c0c050c5SMichael Chan } 1402c0c050c5SMichael Chan } 1403c0c050c5SMichael Chan 1404c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 1405c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(type) == true) 1406c0c050c5SMichael Chan return -EINVAL; 1407c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 1408c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 1409c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 1410c0c050c5SMichael Chan 1411c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 1412c0c050c5SMichael Chan eeprom->len); 1413c0c050c5SMichael Chan } 1414c0c050c5SMichael Chan 141572b34f04SMichael Chan static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata) 141672b34f04SMichael Chan { 141772b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 141872b34f04SMichael Chan struct ethtool_eee *eee = &bp->eee; 141972b34f04SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 142072b34f04SMichael Chan u32 advertising = 142172b34f04SMichael Chan _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); 142272b34f04SMichael Chan int rc = 0; 142372b34f04SMichael Chan 142472b34f04SMichael Chan if (BNXT_VF(bp)) 142572b34f04SMichael Chan return 0; 142672b34f04SMichael Chan 142772b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 142872b34f04SMichael Chan return -EOPNOTSUPP; 142972b34f04SMichael Chan 143072b34f04SMichael Chan if (!edata->eee_enabled) 143172b34f04SMichael Chan goto eee_ok; 143272b34f04SMichael Chan 143372b34f04SMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { 143472b34f04SMichael Chan netdev_warn(dev, "EEE requires autoneg\n"); 143572b34f04SMichael Chan return -EINVAL; 143672b34f04SMichael Chan } 143772b34f04SMichael Chan if (edata->tx_lpi_enabled) { 143872b34f04SMichael Chan if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi || 143972b34f04SMichael Chan edata->tx_lpi_timer < bp->lpi_tmr_lo)) { 144072b34f04SMichael Chan netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n", 144172b34f04SMichael Chan bp->lpi_tmr_lo, bp->lpi_tmr_hi); 144272b34f04SMichael Chan return -EINVAL; 144372b34f04SMichael Chan } else if (!bp->lpi_tmr_hi) { 144472b34f04SMichael Chan edata->tx_lpi_timer = eee->tx_lpi_timer; 144572b34f04SMichael Chan } 144672b34f04SMichael Chan } 144772b34f04SMichael Chan if (!edata->advertised) { 144872b34f04SMichael Chan edata->advertised = advertising & eee->supported; 144972b34f04SMichael Chan } else if (edata->advertised & ~advertising) { 145072b34f04SMichael Chan netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", 145172b34f04SMichael Chan edata->advertised, advertising); 145272b34f04SMichael Chan return -EINVAL; 145372b34f04SMichael Chan } 145472b34f04SMichael Chan 145572b34f04SMichael Chan eee->advertised = edata->advertised; 145672b34f04SMichael Chan eee->tx_lpi_enabled = edata->tx_lpi_enabled; 145772b34f04SMichael Chan eee->tx_lpi_timer = edata->tx_lpi_timer; 145872b34f04SMichael Chan eee_ok: 145972b34f04SMichael Chan eee->eee_enabled = edata->eee_enabled; 146072b34f04SMichael Chan 146172b34f04SMichael Chan if (netif_running(dev)) 146272b34f04SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, false, true); 146372b34f04SMichael Chan 146472b34f04SMichael Chan return rc; 146572b34f04SMichael Chan } 146672b34f04SMichael Chan 146772b34f04SMichael Chan static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata) 146872b34f04SMichael Chan { 146972b34f04SMichael Chan struct bnxt *bp = netdev_priv(dev); 147072b34f04SMichael Chan 147172b34f04SMichael Chan if (!(bp->flags & BNXT_FLAG_EEE_CAP)) 147272b34f04SMichael Chan return -EOPNOTSUPP; 147372b34f04SMichael Chan 147472b34f04SMichael Chan *edata = bp->eee; 147572b34f04SMichael Chan if (!bp->eee.eee_enabled) { 147672b34f04SMichael Chan /* Preserve tx_lpi_timer so that the last value will be used 147772b34f04SMichael Chan * by default when it is re-enabled. 147872b34f04SMichael Chan */ 147972b34f04SMichael Chan edata->advertised = 0; 148072b34f04SMichael Chan edata->tx_lpi_enabled = 0; 148172b34f04SMichael Chan } 148272b34f04SMichael Chan 148372b34f04SMichael Chan if (!bp->eee.eee_active) 148472b34f04SMichael Chan edata->lp_advertised = 0; 148572b34f04SMichael Chan 148672b34f04SMichael Chan return 0; 148772b34f04SMichael Chan } 148872b34f04SMichael Chan 1489c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 1490c0c050c5SMichael Chan .get_settings = bnxt_get_settings, 1491c0c050c5SMichael Chan .set_settings = bnxt_set_settings, 1492c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 1493c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 1494c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 1495c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 1496c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 1497c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 1498c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 1499c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 1500c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 1501c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 1502c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 1503c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 1504c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 1505c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 1506c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 1507c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 1508c0c050c5SMichael Chan #endif 1509c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 1510c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 1511c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 1512c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 1513c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 1514c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 1515c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 1516c0c050c5SMichael Chan .get_link = bnxt_get_link, 151772b34f04SMichael Chan .get_eee = bnxt_get_eee, 151872b34f04SMichael Chan .set_eee = bnxt_set_eee, 1519c0c050c5SMichael Chan }; 1520