1c0c050c5SMichael Chan /* Broadcom NetXtreme-C/E network driver. 2c0c050c5SMichael Chan * 3c0c050c5SMichael Chan * Copyright (c) 2014-2015 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 10c0c050c5SMichael Chan #include <linux/ethtool.h> 11c0c050c5SMichael Chan #include <linux/interrupt.h> 12c0c050c5SMichael Chan #include <linux/pci.h> 13c0c050c5SMichael Chan #include <linux/etherdevice.h> 14c0c050c5SMichael Chan #include <linux/crc32.h> 15c0c050c5SMichael Chan #include <linux/firmware.h> 16c0c050c5SMichael Chan #include "bnxt_hsi.h" 17c0c050c5SMichael Chan #include "bnxt.h" 18c0c050c5SMichael Chan #include "bnxt_ethtool.h" 19c0c050c5SMichael Chan #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */ 20c0c050c5SMichael Chan #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */ 21c0c050c5SMichael Chan #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100) 22c0c050c5SMichael Chan 23c0c050c5SMichael Chan static u32 bnxt_get_msglevel(struct net_device *dev) 24c0c050c5SMichael Chan { 25c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 26c0c050c5SMichael Chan 27c0c050c5SMichael Chan return bp->msg_enable; 28c0c050c5SMichael Chan } 29c0c050c5SMichael Chan 30c0c050c5SMichael Chan static void bnxt_set_msglevel(struct net_device *dev, u32 value) 31c0c050c5SMichael Chan { 32c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 33c0c050c5SMichael Chan 34c0c050c5SMichael Chan bp->msg_enable = value; 35c0c050c5SMichael Chan } 36c0c050c5SMichael Chan 37c0c050c5SMichael Chan static int bnxt_get_coalesce(struct net_device *dev, 38c0c050c5SMichael Chan struct ethtool_coalesce *coal) 39c0c050c5SMichael Chan { 40c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 41c0c050c5SMichael Chan 42c0c050c5SMichael Chan memset(coal, 0, sizeof(*coal)); 43c0c050c5SMichael Chan 44dfb5b894SMichael Chan coal->rx_coalesce_usecs = bp->rx_coal_ticks; 45dfb5b894SMichael Chan /* 2 completion records per rx packet */ 46dfb5b894SMichael Chan coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2; 47dfb5b894SMichael Chan coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq; 48dfb5b894SMichael Chan coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2; 49c0c050c5SMichael Chan 50dfc9c94aSMichael Chan coal->tx_coalesce_usecs = bp->tx_coal_ticks; 51dfc9c94aSMichael Chan coal->tx_max_coalesced_frames = bp->tx_coal_bufs; 52dfc9c94aSMichael Chan coal->tx_coalesce_usecs_irq = bp->tx_coal_ticks_irq; 53dfc9c94aSMichael Chan coal->tx_max_coalesced_frames_irq = bp->tx_coal_bufs_irq; 54dfc9c94aSMichael Chan 55c0c050c5SMichael Chan return 0; 56c0c050c5SMichael Chan } 57c0c050c5SMichael Chan 58c0c050c5SMichael Chan static int bnxt_set_coalesce(struct net_device *dev, 59c0c050c5SMichael Chan struct ethtool_coalesce *coal) 60c0c050c5SMichael Chan { 61c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 62c0c050c5SMichael Chan int rc = 0; 63c0c050c5SMichael Chan 64dfb5b894SMichael Chan bp->rx_coal_ticks = coal->rx_coalesce_usecs; 65dfb5b894SMichael Chan /* 2 completion records per rx packet */ 66dfb5b894SMichael Chan bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2; 67dfb5b894SMichael Chan bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq; 68dfb5b894SMichael Chan bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2; 69c0c050c5SMichael Chan 70dfc9c94aSMichael Chan bp->tx_coal_ticks = coal->tx_coalesce_usecs; 71dfc9c94aSMichael Chan bp->tx_coal_bufs = coal->tx_max_coalesced_frames; 72dfc9c94aSMichael Chan bp->tx_coal_ticks_irq = coal->tx_coalesce_usecs_irq; 73dfc9c94aSMichael Chan bp->tx_coal_bufs_irq = coal->tx_max_coalesced_frames_irq; 74dfc9c94aSMichael Chan 75c0c050c5SMichael Chan if (netif_running(dev)) 76c0c050c5SMichael Chan rc = bnxt_hwrm_set_coal(bp); 77c0c050c5SMichael Chan 78c0c050c5SMichael Chan return rc; 79c0c050c5SMichael Chan } 80c0c050c5SMichael Chan 81c0c050c5SMichael Chan #define BNXT_NUM_STATS 21 82c0c050c5SMichael Chan 83c0c050c5SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 84c0c050c5SMichael Chan { 85c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 86c0c050c5SMichael Chan 87c0c050c5SMichael Chan switch (sset) { 88c0c050c5SMichael Chan case ETH_SS_STATS: 89c0c050c5SMichael Chan return BNXT_NUM_STATS * bp->cp_nr_rings; 90c0c050c5SMichael Chan default: 91c0c050c5SMichael Chan return -EOPNOTSUPP; 92c0c050c5SMichael Chan } 93c0c050c5SMichael Chan } 94c0c050c5SMichael Chan 95c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 96c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 97c0c050c5SMichael Chan { 98c0c050c5SMichael Chan u32 i, j = 0; 99c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 100c0c050c5SMichael Chan u32 buf_size = sizeof(struct ctx_hw_stats) * bp->cp_nr_rings; 101c0c050c5SMichael Chan u32 stat_fields = sizeof(struct ctx_hw_stats) / 8; 102c0c050c5SMichael Chan 103c0c050c5SMichael Chan memset(buf, 0, buf_size); 104c0c050c5SMichael Chan 105c0c050c5SMichael Chan if (!bp->bnapi) 106c0c050c5SMichael Chan return; 107c0c050c5SMichael Chan 108c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 109c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 110c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 111c0c050c5SMichael Chan __le64 *hw_stats = (__le64 *)cpr->hw_stats; 112c0c050c5SMichael Chan int k; 113c0c050c5SMichael Chan 114c0c050c5SMichael Chan for (k = 0; k < stat_fields; j++, k++) 115c0c050c5SMichael Chan buf[j] = le64_to_cpu(hw_stats[k]); 116c0c050c5SMichael Chan buf[j++] = cpr->rx_l4_csum_errors; 117c0c050c5SMichael Chan } 118c0c050c5SMichael Chan } 119c0c050c5SMichael Chan 120c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 121c0c050c5SMichael Chan { 122c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 123c0c050c5SMichael Chan u32 i; 124c0c050c5SMichael Chan 125c0c050c5SMichael Chan switch (stringset) { 126c0c050c5SMichael Chan /* The number of strings must match BNXT_NUM_STATS defined above. */ 127c0c050c5SMichael Chan case ETH_SS_STATS: 128c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 129c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_ucast_packets", i); 130c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 131c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_mcast_packets", i); 132c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 133c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_bcast_packets", i); 134c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 135c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_discards", i); 136c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 137c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_drops", i); 138c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 139c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_ucast_bytes", i); 140c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 141c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_mcast_bytes", i); 142c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 143c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_bcast_bytes", i); 144c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 145c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_ucast_packets", i); 146c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 147c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_mcast_packets", i); 148c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 149c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_bcast_packets", i); 150c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 151c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_discards", i); 152c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 153c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_drops", i); 154c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 155c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_ucast_bytes", i); 156c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 157c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_mcast_bytes", i); 158c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 159c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_bcast_bytes", i); 160c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 161c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_packets", i); 162c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 163c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_bytes", i); 164c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 165c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_events", i); 166c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 167c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_aborts", i); 168c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 169c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_l4_csum_errors", i); 170c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 171c0c050c5SMichael Chan } 172c0c050c5SMichael Chan break; 173c0c050c5SMichael Chan default: 174c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 175c0c050c5SMichael Chan stringset); 176c0c050c5SMichael Chan break; 177c0c050c5SMichael Chan } 178c0c050c5SMichael Chan } 179c0c050c5SMichael Chan 180c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 181c0c050c5SMichael Chan struct ethtool_ringparam *ering) 182c0c050c5SMichael Chan { 183c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 184c0c050c5SMichael Chan 185c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 186c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 187c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 188c0c050c5SMichael Chan 189c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 190c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 191c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 192c0c050c5SMichael Chan } 193c0c050c5SMichael Chan 194c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 195c0c050c5SMichael Chan struct ethtool_ringparam *ering) 196c0c050c5SMichael Chan { 197c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 198c0c050c5SMichael Chan 199c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 200c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 201c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 202c0c050c5SMichael Chan return -EINVAL; 203c0c050c5SMichael Chan 204c0c050c5SMichael Chan if (netif_running(dev)) 205c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 206c0c050c5SMichael Chan 207c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 208c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 209c0c050c5SMichael Chan bnxt_set_ring_params(bp); 210c0c050c5SMichael Chan 211c0c050c5SMichael Chan if (netif_running(dev)) 212c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 213c0c050c5SMichael Chan 214c0c050c5SMichael Chan return 0; 215c0c050c5SMichael Chan } 216c0c050c5SMichael Chan 217c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 218c0c050c5SMichael Chan struct ethtool_channels *channel) 219c0c050c5SMichael Chan { 220c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 221c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 222c0c050c5SMichael Chan 2236e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 224068c9ec6SMichael Chan channel->max_combined = max_rx_rings; 225068c9ec6SMichael Chan 226068c9ec6SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false); 227c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 228c0c050c5SMichael Chan if (tcs > 1) 229c0c050c5SMichael Chan max_tx_rings /= tcs; 230c0c050c5SMichael Chan 231c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 232c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 233c0c050c5SMichael Chan channel->max_other = 0; 234068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 235068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 236068c9ec6SMichael Chan } else { 237c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 238c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 239c0c050c5SMichael Chan } 240068c9ec6SMichael Chan } 241c0c050c5SMichael Chan 242c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 243c0c050c5SMichael Chan struct ethtool_channels *channel) 244c0c050c5SMichael Chan { 245c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 246c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 247c0c050c5SMichael Chan u32 rc = 0; 248068c9ec6SMichael Chan bool sh = false; 249c0c050c5SMichael Chan 250068c9ec6SMichael Chan if (channel->other_count) 251c0c050c5SMichael Chan return -EINVAL; 252c0c050c5SMichael Chan 253068c9ec6SMichael Chan if (!channel->combined_count && 254068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 255068c9ec6SMichael Chan return -EINVAL; 256068c9ec6SMichael Chan 257068c9ec6SMichael Chan if (channel->combined_count && 258068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 259068c9ec6SMichael Chan return -EINVAL; 260068c9ec6SMichael Chan 261068c9ec6SMichael Chan if (channel->combined_count) 262068c9ec6SMichael Chan sh = true; 263068c9ec6SMichael Chan 264068c9ec6SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh); 265068c9ec6SMichael Chan 266c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 267c0c050c5SMichael Chan if (tcs > 1) 268c0c050c5SMichael Chan max_tx_rings /= tcs; 269c0c050c5SMichael Chan 270068c9ec6SMichael Chan if (sh && (channel->combined_count > max_rx_rings || 271068c9ec6SMichael Chan channel->combined_count > max_tx_rings)) 272068c9ec6SMichael Chan return -ENOMEM; 273068c9ec6SMichael Chan 274068c9ec6SMichael Chan if (!sh && (channel->rx_count > max_rx_rings || 275068c9ec6SMichael Chan channel->tx_count > max_tx_rings)) 276068c9ec6SMichael Chan return -ENOMEM; 277c0c050c5SMichael Chan 278c0c050c5SMichael Chan if (netif_running(dev)) { 279c0c050c5SMichael Chan if (BNXT_PF(bp)) { 280c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 281c0c050c5SMichael Chan * before PF unload 282c0c050c5SMichael Chan */ 283c0c050c5SMichael Chan } 284c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 285c0c050c5SMichael Chan if (rc) { 286c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 287c0c050c5SMichael Chan rc); 288c0c050c5SMichael Chan return rc; 289c0c050c5SMichael Chan } 290c0c050c5SMichael Chan } 291c0c050c5SMichael Chan 292068c9ec6SMichael Chan if (sh) { 293068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 294068c9ec6SMichael Chan bp->rx_nr_rings = channel->combined_count; 295068c9ec6SMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 296068c9ec6SMichael Chan } else { 297068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 298c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 299c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 300068c9ec6SMichael Chan } 301068c9ec6SMichael Chan 302c0c050c5SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc; 303c0c050c5SMichael Chan if (tcs > 1) 304c0c050c5SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs; 305068c9ec6SMichael Chan 306068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 307068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 308068c9ec6SMichael Chan 309c0c050c5SMichael Chan bp->num_stat_ctxs = bp->cp_nr_rings; 310c0c050c5SMichael Chan 3112bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 3122bcfa6f6SMichael Chan netdev_update_features(dev); 313c0c050c5SMichael Chan if (netif_running(dev)) { 314c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 315c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 316c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 317c0c050c5SMichael Chan * to renable 318c0c050c5SMichael Chan */ 319c0c050c5SMichael Chan } 320c0c050c5SMichael Chan } 321c0c050c5SMichael Chan 322c0c050c5SMichael Chan return rc; 323c0c050c5SMichael Chan } 324c0c050c5SMichael Chan 325c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 326c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 327c0c050c5SMichael Chan u32 *rule_locs) 328c0c050c5SMichael Chan { 329c0c050c5SMichael Chan int i, j = 0; 330c0c050c5SMichael Chan 331c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 332c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 333c0c050c5SMichael Chan struct hlist_head *head; 334c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 335c0c050c5SMichael Chan 336c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 337c0c050c5SMichael Chan rcu_read_lock(); 338c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 339c0c050c5SMichael Chan if (j == cmd->rule_cnt) 340c0c050c5SMichael Chan break; 341c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 342c0c050c5SMichael Chan } 343c0c050c5SMichael Chan rcu_read_unlock(); 344c0c050c5SMichael Chan if (j == cmd->rule_cnt) 345c0c050c5SMichael Chan break; 346c0c050c5SMichael Chan } 347c0c050c5SMichael Chan cmd->rule_cnt = j; 348c0c050c5SMichael Chan return 0; 349c0c050c5SMichael Chan } 350c0c050c5SMichael Chan 351c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 352c0c050c5SMichael Chan { 353c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 354c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 355c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 356c0c050c5SMichael Chan struct flow_keys *fkeys; 357c0c050c5SMichael Chan int i, rc = -EINVAL; 358c0c050c5SMichael Chan 359c0c050c5SMichael Chan if (fs->location < 0 || fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 360c0c050c5SMichael Chan return rc; 361c0c050c5SMichael Chan 362c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 363c0c050c5SMichael Chan struct hlist_head *head; 364c0c050c5SMichael Chan 365c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 366c0c050c5SMichael Chan rcu_read_lock(); 367c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 368c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 369c0c050c5SMichael Chan goto fltr_found; 370c0c050c5SMichael Chan } 371c0c050c5SMichael Chan rcu_read_unlock(); 372c0c050c5SMichael Chan } 373c0c050c5SMichael Chan return rc; 374c0c050c5SMichael Chan 375c0c050c5SMichael Chan fltr_found: 376c0c050c5SMichael Chan fkeys = &fltr->fkeys; 377c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 378c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 379c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 380c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 381c0c050c5SMichael Chan else 382c0c050c5SMichael Chan goto fltr_err; 383c0c050c5SMichael Chan 384c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 385c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 386c0c050c5SMichael Chan 387c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 388c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 389c0c050c5SMichael Chan 390c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 391c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 392c0c050c5SMichael Chan 393c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 394c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 395c0c050c5SMichael Chan 396c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 397c0c050c5SMichael Chan rc = 0; 398c0c050c5SMichael Chan 399c0c050c5SMichael Chan fltr_err: 400c0c050c5SMichael Chan rcu_read_unlock(); 401c0c050c5SMichael Chan 402c0c050c5SMichael Chan return rc; 403c0c050c5SMichael Chan } 404c0c050c5SMichael Chan 405c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 406c0c050c5SMichael Chan u32 *rule_locs) 407c0c050c5SMichael Chan { 408c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 409c0c050c5SMichael Chan int rc = 0; 410c0c050c5SMichael Chan 411c0c050c5SMichael Chan switch (cmd->cmd) { 412c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 413c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 414c0c050c5SMichael Chan break; 415c0c050c5SMichael Chan 416c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 417c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 418c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 419c0c050c5SMichael Chan break; 420c0c050c5SMichael Chan 421c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 422c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 423c0c050c5SMichael Chan break; 424c0c050c5SMichael Chan 425c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 426c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 427c0c050c5SMichael Chan break; 428c0c050c5SMichael Chan 429c0c050c5SMichael Chan default: 430c0c050c5SMichael Chan rc = -EOPNOTSUPP; 431c0c050c5SMichael Chan break; 432c0c050c5SMichael Chan } 433c0c050c5SMichael Chan 434c0c050c5SMichael Chan return rc; 435c0c050c5SMichael Chan } 436c0c050c5SMichael Chan #endif 437c0c050c5SMichael Chan 438c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 439c0c050c5SMichael Chan { 440c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 441c0c050c5SMichael Chan } 442c0c050c5SMichael Chan 443c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 444c0c050c5SMichael Chan { 445c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 446c0c050c5SMichael Chan } 447c0c050c5SMichael Chan 448c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 449c0c050c5SMichael Chan u8 *hfunc) 450c0c050c5SMichael Chan { 451c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 452c0c050c5SMichael Chan struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; 453c0c050c5SMichael Chan int i = 0; 454c0c050c5SMichael Chan 455c0c050c5SMichael Chan if (hfunc) 456c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 457c0c050c5SMichael Chan 458c0c050c5SMichael Chan if (indir) 459c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 460c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 461c0c050c5SMichael Chan 462c0c050c5SMichael Chan if (key) 463c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 464c0c050c5SMichael Chan 465c0c050c5SMichael Chan return 0; 466c0c050c5SMichael Chan } 467c0c050c5SMichael Chan 468c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 469c0c050c5SMichael Chan struct ethtool_drvinfo *info) 470c0c050c5SMichael Chan { 471c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 472c0c050c5SMichael Chan 473c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 474c0c050c5SMichael Chan strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 475c0c050c5SMichael Chan strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); 476c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 477c0c050c5SMichael Chan info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings; 478c0c050c5SMichael Chan info->testinfo_len = BNXT_NUM_TESTS(bp); 479c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 480c0c050c5SMichael Chan info->eedump_len = 0; 481c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 482c0c050c5SMichael Chan info->regdump_len = 0; 483c0c050c5SMichael Chan } 484c0c050c5SMichael Chan 485c0c050c5SMichael Chan static u32 bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info) 486c0c050c5SMichael Chan { 487c0c050c5SMichael Chan u16 fw_speeds = link_info->support_speeds; 488c0c050c5SMichael Chan u32 speed_mask = 0; 489c0c050c5SMichael Chan 490c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 491c0c050c5SMichael Chan speed_mask |= SUPPORTED_100baseT_Full; 492c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 493c0c050c5SMichael Chan speed_mask |= SUPPORTED_1000baseT_Full; 494c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 495c0c050c5SMichael Chan speed_mask |= SUPPORTED_2500baseX_Full; 496c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 497c0c050c5SMichael Chan speed_mask |= SUPPORTED_10000baseT_Full; 498c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 4991c49c421SMichael Chan speed_mask |= SUPPORTED_40000baseCR4_Full; 500c0c050c5SMichael Chan 501c0c050c5SMichael Chan return speed_mask; 502c0c050c5SMichael Chan } 503c0c050c5SMichael Chan 504c0c050c5SMichael Chan static u32 bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info) 505c0c050c5SMichael Chan { 506c0c050c5SMichael Chan u16 fw_speeds = link_info->auto_link_speeds; 507c0c050c5SMichael Chan u32 speed_mask = 0; 508c0c050c5SMichael Chan 509c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 510c0c050c5SMichael Chan /* set the advertised speeds */ 511c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 512c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 513c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 514c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 515c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 516c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 517c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 518c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 519c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 5201c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 521c0c050c5SMichael Chan return speed_mask; 522c0c050c5SMichael Chan } 523c0c050c5SMichael Chan 524c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 525c0c050c5SMichael Chan { 526c0c050c5SMichael Chan switch (fw_link_speed) { 527c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 528c0c050c5SMichael Chan return SPEED_100; 529c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 530c0c050c5SMichael Chan return SPEED_1000; 531c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 532c0c050c5SMichael Chan return SPEED_2500; 533c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 534c0c050c5SMichael Chan return SPEED_10000; 535c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 536c0c050c5SMichael Chan return SPEED_20000; 537c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 538c0c050c5SMichael Chan return SPEED_25000; 539c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 540c0c050c5SMichael Chan return SPEED_40000; 541c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 542c0c050c5SMichael Chan return SPEED_50000; 543c0c050c5SMichael Chan default: 544c0c050c5SMichael Chan return SPEED_UNKNOWN; 545c0c050c5SMichael Chan } 546c0c050c5SMichael Chan } 547c0c050c5SMichael Chan 548c0c050c5SMichael Chan static int bnxt_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 549c0c050c5SMichael Chan { 550c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 551c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 552c0c050c5SMichael Chan u16 ethtool_speed; 553c0c050c5SMichael Chan 554c0c050c5SMichael Chan cmd->supported = bnxt_fw_to_ethtool_support_spds(link_info); 5550d8abf02SMichael Chan cmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; 556c0c050c5SMichael Chan 557c0c050c5SMichael Chan if (link_info->auto_link_speeds) 558c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Autoneg; 559c0c050c5SMichael Chan 560b763499eSMichael Chan if (link_info->autoneg) { 561c0c050c5SMichael Chan cmd->advertising = 562c0c050c5SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info); 563c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Autoneg; 564c0c050c5SMichael Chan cmd->autoneg = AUTONEG_ENABLE; 565c0c050c5SMichael Chan } else { 566c0c050c5SMichael Chan cmd->autoneg = AUTONEG_DISABLE; 567c0c050c5SMichael Chan cmd->advertising = 0; 568c0c050c5SMichael Chan } 5690d8abf02SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) { 570c0c050c5SMichael Chan if ((link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) == 571c0c050c5SMichael Chan BNXT_LINK_PAUSE_BOTH) { 572c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Pause; 573c0c050c5SMichael Chan } else { 574c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Asym_Pause; 575c0c050c5SMichael Chan if (link_info->auto_pause_setting & 576c0c050c5SMichael Chan BNXT_LINK_PAUSE_RX) 577c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Pause; 578c0c050c5SMichael Chan } 579c0c050c5SMichael Chan } 580c0c050c5SMichael Chan 581c0c050c5SMichael Chan cmd->port = PORT_NONE; 582c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 583c0c050c5SMichael Chan cmd->port = PORT_TP; 584c0c050c5SMichael Chan cmd->supported |= SUPPORTED_TP; 585c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_TP; 586c0c050c5SMichael Chan } else { 587c0c050c5SMichael Chan cmd->supported |= SUPPORTED_FIBRE; 588c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_FIBRE; 589c0c050c5SMichael Chan 590c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 591c0c050c5SMichael Chan cmd->port = PORT_DA; 592c0c050c5SMichael Chan else if (link_info->media_type == 593c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 594c0c050c5SMichael Chan cmd->port = PORT_FIBRE; 595c0c050c5SMichael Chan } 596c0c050c5SMichael Chan 597c0c050c5SMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) { 598c0c050c5SMichael Chan if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 599c0c050c5SMichael Chan cmd->duplex = DUPLEX_FULL; 600c0c050c5SMichael Chan } else { 601c0c050c5SMichael Chan cmd->duplex = DUPLEX_UNKNOWN; 602c0c050c5SMichael Chan } 603c0c050c5SMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 604c0c050c5SMichael Chan ethtool_cmd_speed_set(cmd, ethtool_speed); 605c0c050c5SMichael Chan if (link_info->transceiver == 606c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_TRANSCEIVER_TYPE_XCVR_INTERNAL) 607c0c050c5SMichael Chan cmd->transceiver = XCVR_INTERNAL; 608c0c050c5SMichael Chan else 609c0c050c5SMichael Chan cmd->transceiver = XCVR_EXTERNAL; 610c0c050c5SMichael Chan cmd->phy_address = link_info->phy_addr; 611c0c050c5SMichael Chan 612c0c050c5SMichael Chan return 0; 613c0c050c5SMichael Chan } 614c0c050c5SMichael Chan 615c0c050c5SMichael Chan static u32 bnxt_get_fw_speed(struct net_device *dev, u16 ethtool_speed) 616c0c050c5SMichael Chan { 617c0c050c5SMichael Chan switch (ethtool_speed) { 618c0c050c5SMichael Chan case SPEED_100: 619c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 620c0c050c5SMichael Chan case SPEED_1000: 621c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 622c0c050c5SMichael Chan case SPEED_2500: 623c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 624c0c050c5SMichael Chan case SPEED_10000: 625c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 626c0c050c5SMichael Chan case SPEED_20000: 627c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 628c0c050c5SMichael Chan case SPEED_25000: 629c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 630c0c050c5SMichael Chan case SPEED_40000: 631c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 632c0c050c5SMichael Chan case SPEED_50000: 633c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 634c0c050c5SMichael Chan default: 635c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 636c0c050c5SMichael Chan break; 637c0c050c5SMichael Chan } 638c0c050c5SMichael Chan return 0; 639c0c050c5SMichael Chan } 640c0c050c5SMichael Chan 641c0c050c5SMichael Chan static u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 642c0c050c5SMichael Chan { 643c0c050c5SMichael Chan u16 fw_speed_mask = 0; 644c0c050c5SMichael Chan 645c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 646c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 647c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 648c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 649c0c050c5SMichael Chan } 650c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 651c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 652c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 653c0c050c5SMichael Chan } 654c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 655c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 656c0c050c5SMichael Chan 6571c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 6581c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 6591c49c421SMichael Chan 660c0c050c5SMichael Chan return fw_speed_mask; 661c0c050c5SMichael Chan } 662c0c050c5SMichael Chan 663c0c050c5SMichael Chan static int bnxt_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 664c0c050c5SMichael Chan { 665c0c050c5SMichael Chan int rc = 0; 666c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 667c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 668c0c050c5SMichael Chan u32 speed, fw_advertising = 0; 669c0c050c5SMichael Chan bool set_pause = false; 670c0c050c5SMichael Chan 671c0c050c5SMichael Chan if (BNXT_VF(bp)) 672c0c050c5SMichael Chan return rc; 673c0c050c5SMichael Chan 674c0c050c5SMichael Chan if (cmd->autoneg == AUTONEG_ENABLE) { 675c0c050c5SMichael Chan if (link_info->media_type != PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 676c0c050c5SMichael Chan netdev_err(dev, "Media type doesn't support autoneg\n"); 677c0c050c5SMichael Chan rc = -EINVAL; 678c0c050c5SMichael Chan goto set_setting_exit; 679c0c050c5SMichael Chan } 680c0c050c5SMichael Chan if (cmd->advertising & ~(BNXT_ALL_COPPER_ETHTOOL_SPEED | 681c0c050c5SMichael Chan ADVERTISED_Autoneg | 682c0c050c5SMichael Chan ADVERTISED_TP | 683c0c050c5SMichael Chan ADVERTISED_Pause | 684c0c050c5SMichael Chan ADVERTISED_Asym_Pause)) { 685c0c050c5SMichael Chan netdev_err(dev, "Unsupported advertising mask (adv: 0x%x)\n", 686c0c050c5SMichael Chan cmd->advertising); 687c0c050c5SMichael Chan rc = -EINVAL; 688c0c050c5SMichael Chan goto set_setting_exit; 689c0c050c5SMichael Chan } 690c0c050c5SMichael Chan fw_advertising = bnxt_get_fw_auto_link_speeds(cmd->advertising); 691c0c050c5SMichael Chan if (fw_advertising & ~link_info->support_speeds) { 692c0c050c5SMichael Chan netdev_err(dev, "Advertising parameters are not supported! (adv: 0x%x)\n", 693c0c050c5SMichael Chan cmd->advertising); 694c0c050c5SMichael Chan rc = -EINVAL; 695c0c050c5SMichael Chan goto set_setting_exit; 696c0c050c5SMichael Chan } 697c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 698c0c050c5SMichael Chan if (!fw_advertising) 699c0c050c5SMichael Chan link_info->advertising = link_info->support_speeds; 700c0c050c5SMichael Chan else 701c0c050c5SMichael Chan link_info->advertising = fw_advertising; 702c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 703c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 704c0c050c5SMichael Chan */ 705c0c050c5SMichael Chan set_pause = true; 706c0c050c5SMichael Chan } else { 707c0c050c5SMichael Chan /* TODO: currently don't support half duplex */ 708c0c050c5SMichael Chan if (cmd->duplex == DUPLEX_HALF) { 709c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 710c0c050c5SMichael Chan rc = -EINVAL; 711c0c050c5SMichael Chan goto set_setting_exit; 712c0c050c5SMichael Chan } 713c0c050c5SMichael Chan /* If received a request for an unknown duplex, assume full*/ 714c0c050c5SMichael Chan if (cmd->duplex == DUPLEX_UNKNOWN) 715c0c050c5SMichael Chan cmd->duplex = DUPLEX_FULL; 716c0c050c5SMichael Chan speed = ethtool_cmd_speed(cmd); 717c0c050c5SMichael Chan link_info->req_link_speed = bnxt_get_fw_speed(dev, speed); 718c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 719b763499eSMichael Chan link_info->autoneg = 0; 720c0c050c5SMichael Chan link_info->advertising = 0; 721c0c050c5SMichael Chan } 722c0c050c5SMichael Chan 723c0c050c5SMichael Chan if (netif_running(dev)) 724c0c050c5SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause); 725c0c050c5SMichael Chan 726c0c050c5SMichael Chan set_setting_exit: 727c0c050c5SMichael Chan return rc; 728c0c050c5SMichael Chan } 729c0c050c5SMichael Chan 730c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 731c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 732c0c050c5SMichael Chan { 733c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 734c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 735c0c050c5SMichael Chan 736c0c050c5SMichael Chan if (BNXT_VF(bp)) 737c0c050c5SMichael Chan return; 738b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 739c0c050c5SMichael Chan epause->rx_pause = ((link_info->pause & BNXT_LINK_PAUSE_RX) != 0); 740c0c050c5SMichael Chan epause->tx_pause = ((link_info->pause & BNXT_LINK_PAUSE_TX) != 0); 741c0c050c5SMichael Chan } 742c0c050c5SMichael Chan 743c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 744c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 745c0c050c5SMichael Chan { 746c0c050c5SMichael Chan int rc = 0; 747c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 748c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 749c0c050c5SMichael Chan 750c0c050c5SMichael Chan if (BNXT_VF(bp)) 751c0c050c5SMichael Chan return rc; 752c0c050c5SMichael Chan 753c0c050c5SMichael Chan if (epause->autoneg) { 754b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 755b763499eSMichael Chan return -EINVAL; 756b763499eSMichael Chan 757c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 758c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_BOTH; 759c0c050c5SMichael Chan } else { 760c0c050c5SMichael Chan /* when transition from auto pause to force pause, 761c0c050c5SMichael Chan * force a link change 762c0c050c5SMichael Chan */ 763c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 764c0c050c5SMichael Chan link_info->force_link_chng = true; 765c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 766c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_BOTH; 767c0c050c5SMichael Chan } 768c0c050c5SMichael Chan if (epause->rx_pause) 769c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 770c0c050c5SMichael Chan else 771c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_RX; 772c0c050c5SMichael Chan 773c0c050c5SMichael Chan if (epause->tx_pause) 774c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 775c0c050c5SMichael Chan else 776c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_TX; 777c0c050c5SMichael Chan 778c0c050c5SMichael Chan if (netif_running(dev)) 779c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 780c0c050c5SMichael Chan return rc; 781c0c050c5SMichael Chan } 782c0c050c5SMichael Chan 783c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 784c0c050c5SMichael Chan { 785c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 786c0c050c5SMichael Chan 787c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 788c0c050c5SMichael Chan return bp->link_info.link_up; 789c0c050c5SMichael Chan } 790c0c050c5SMichael Chan 791c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 792c0c050c5SMichael Chan u16 dir_type, 793c0c050c5SMichael Chan u16 dir_ordinal, 794c0c050c5SMichael Chan u16 dir_ext, 795c0c050c5SMichael Chan u16 dir_attr, 796c0c050c5SMichael Chan const u8 *data, 797c0c050c5SMichael Chan size_t data_len) 798c0c050c5SMichael Chan { 799c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 800c0c050c5SMichael Chan int rc; 801c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 802c0c050c5SMichael Chan dma_addr_t dma_handle; 803c0c050c5SMichael Chan u8 *kmem; 804c0c050c5SMichael Chan 805c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 806c0c050c5SMichael Chan 807c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 808c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 809c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 810c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 811c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 812c0c050c5SMichael Chan 813c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 814c0c050c5SMichael Chan GFP_KERNEL); 815c0c050c5SMichael Chan if (!kmem) { 816c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 817c0c050c5SMichael Chan (unsigned)data_len); 818c0c050c5SMichael Chan return -ENOMEM; 819c0c050c5SMichael Chan } 820c0c050c5SMichael Chan memcpy(kmem, data, data_len); 821c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 822c0c050c5SMichael Chan 823c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 824c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 825c0c050c5SMichael Chan 826c0c050c5SMichael Chan return rc; 827c0c050c5SMichael Chan } 828c0c050c5SMichael Chan 829d2d6318cSRob Swindell static int bnxt_firmware_reset(struct net_device *dev, 830d2d6318cSRob Swindell u16 dir_type) 831d2d6318cSRob Swindell { 832d2d6318cSRob Swindell struct bnxt *bp = netdev_priv(dev); 833d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 834d2d6318cSRob Swindell 835d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 836d2d6318cSRob Swindell 837d2d6318cSRob Swindell /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */ 838d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 839d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 840d2d6318cSRob Swindell switch (dir_type) { 841d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 842d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 843d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 844d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 845d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 846d2d6318cSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 847d2d6318cSRob Swindell break; 848d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 849d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 850d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 851d2d6318cSRob Swindell break; 852d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 853d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 854d2d6318cSRob Swindell req.embedded_proc_type = 855d2d6318cSRob Swindell FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 856d2d6318cSRob Swindell break; 857d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 858d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 859d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 860d2d6318cSRob Swindell break; 861d2d6318cSRob Swindell default: 862d2d6318cSRob Swindell return -EINVAL; 863d2d6318cSRob Swindell } 864d2d6318cSRob Swindell 865d2d6318cSRob Swindell return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 866d2d6318cSRob Swindell } 867d2d6318cSRob Swindell 868c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 869c0c050c5SMichael Chan u16 dir_type, 870c0c050c5SMichael Chan const u8 *fw_data, 871c0c050c5SMichael Chan size_t fw_size) 872c0c050c5SMichael Chan { 873c0c050c5SMichael Chan int rc = 0; 874c0c050c5SMichael Chan u16 code_type; 875c0c050c5SMichael Chan u32 stored_crc; 876c0c050c5SMichael Chan u32 calculated_crc; 877c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 878c0c050c5SMichael Chan 879c0c050c5SMichael Chan switch (dir_type) { 880c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 881c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 882c0c050c5SMichael Chan code_type = CODE_BOOT; 883c0c050c5SMichael Chan break; 8842731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 8852731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 8862731d70fSRob Swindell break; 887c0c050c5SMichael Chan default: 888c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 889c0c050c5SMichael Chan dir_type); 890c0c050c5SMichael Chan return -EINVAL; 891c0c050c5SMichael Chan } 892c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 893c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 894c0c050c5SMichael Chan (unsigned int)fw_size); 895c0c050c5SMichael Chan return -EINVAL; 896c0c050c5SMichael Chan } 897c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 898c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 899c0c050c5SMichael Chan le32_to_cpu(header->signature)); 900c0c050c5SMichael Chan return -EINVAL; 901c0c050c5SMichael Chan } 902c0c050c5SMichael Chan if (header->code_type != code_type) { 903c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 904c0c050c5SMichael Chan code_type, header->code_type); 905c0c050c5SMichael Chan return -EINVAL; 906c0c050c5SMichael Chan } 907c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 908c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 909c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 910c0c050c5SMichael Chan return -EINVAL; 911c0c050c5SMichael Chan } 912c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 913c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 914c0c050c5SMichael Chan sizeof(stored_crc))); 915c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 916c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 917c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 918c0c050c5SMichael Chan (unsigned long)stored_crc, 919c0c050c5SMichael Chan (unsigned long)calculated_crc); 920c0c050c5SMichael Chan return -EINVAL; 921c0c050c5SMichael Chan } 922c0c050c5SMichael Chan /* TODO: Validate digital signature (RSA-encrypted SHA-256 hash) here */ 923c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 924c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 925d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 926d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 927d2d6318cSRob Swindell 928c0c050c5SMichael Chan return rc; 929c0c050c5SMichael Chan } 930c0c050c5SMichael Chan 931c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 932c0c050c5SMichael Chan { 933c0c050c5SMichael Chan switch (dir_type) { 934c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 935c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 936c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 937c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 938c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 939c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 940c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 941c0c050c5SMichael Chan return true; 942c0c050c5SMichael Chan } 943c0c050c5SMichael Chan 944c0c050c5SMichael Chan return false; 945c0c050c5SMichael Chan } 946c0c050c5SMichael Chan 947c0c050c5SMichael Chan static bool bnxt_dir_type_is_unprotected_exec_format(u16 dir_type) 948c0c050c5SMichael Chan { 949c0c050c5SMichael Chan switch (dir_type) { 950c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 951c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 952c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 953c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 954c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 955c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 956c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 957c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 958c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 959c0c050c5SMichael Chan return true; 960c0c050c5SMichael Chan } 961c0c050c5SMichael Chan 962c0c050c5SMichael Chan return false; 963c0c050c5SMichael Chan } 964c0c050c5SMichael Chan 965c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 966c0c050c5SMichael Chan { 967c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 968c0c050c5SMichael Chan bnxt_dir_type_is_unprotected_exec_format(dir_type); 969c0c050c5SMichael Chan } 970c0c050c5SMichael Chan 971c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 972c0c050c5SMichael Chan u16 dir_type, 973c0c050c5SMichael Chan const char *filename) 974c0c050c5SMichael Chan { 975c0c050c5SMichael Chan const struct firmware *fw; 976c0c050c5SMichael Chan int rc; 977c0c050c5SMichael Chan 978c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(dir_type) == false) 979c0c050c5SMichael Chan return -EINVAL; 980c0c050c5SMichael Chan 981c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 982c0c050c5SMichael Chan if (rc != 0) { 983c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 984c0c050c5SMichael Chan rc, filename); 985c0c050c5SMichael Chan return rc; 986c0c050c5SMichael Chan } 987c0c050c5SMichael Chan if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) 988c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 989c0c050c5SMichael Chan else 990c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 991c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 992c0c050c5SMichael Chan release_firmware(fw); 993c0c050c5SMichael Chan return rc; 994c0c050c5SMichael Chan } 995c0c050c5SMichael Chan 996c0c050c5SMichael Chan static int bnxt_flash_package_from_file(struct net_device *dev, 997c0c050c5SMichael Chan char *filename) 998c0c050c5SMichael Chan { 999c0c050c5SMichael Chan netdev_err(dev, "packages are not yet supported\n"); 1000c0c050c5SMichael Chan return -EINVAL; 1001c0c050c5SMichael Chan } 1002c0c050c5SMichael Chan 1003c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 1004c0c050c5SMichael Chan struct ethtool_flash *flash) 1005c0c050c5SMichael Chan { 1006c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 1007c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 1008c0c050c5SMichael Chan return -EINVAL; 1009c0c050c5SMichael Chan } 1010c0c050c5SMichael Chan 1011c0c050c5SMichael Chan if (flash->region == ETHTOOL_FLASH_ALL_REGIONS) 1012c0c050c5SMichael Chan return bnxt_flash_package_from_file(dev, flash->data); 1013c0c050c5SMichael Chan 1014c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 1015c0c050c5SMichael Chan } 1016c0c050c5SMichael Chan 1017c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 1018c0c050c5SMichael Chan { 1019c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1020c0c050c5SMichael Chan int rc; 1021c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 1022c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 1023c0c050c5SMichael Chan 1024c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 1025c0c050c5SMichael Chan 1026c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 1027c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1028c0c050c5SMichael Chan if (!rc) { 1029c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 1030c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 1031c0c050c5SMichael Chan } 1032c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 1033c0c050c5SMichael Chan return rc; 1034c0c050c5SMichael Chan } 1035c0c050c5SMichael Chan 1036c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 1037c0c050c5SMichael Chan { 1038c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 1039c0c050c5SMichael Chan * passed via the ethtool command-line utility. 1040c0c050c5SMichael Chan */ 1041c0c050c5SMichael Chan return -1; 1042c0c050c5SMichael Chan } 1043c0c050c5SMichael Chan 1044c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 1045c0c050c5SMichael Chan { 1046c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1047c0c050c5SMichael Chan int rc; 1048c0c050c5SMichael Chan u32 dir_entries; 1049c0c050c5SMichael Chan u32 entry_length; 1050c0c050c5SMichael Chan u8 *buf; 1051c0c050c5SMichael Chan size_t buflen; 1052c0c050c5SMichael Chan dma_addr_t dma_handle; 1053c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 1054c0c050c5SMichael Chan 1055c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 1056c0c050c5SMichael Chan if (rc != 0) 1057c0c050c5SMichael Chan return rc; 1058c0c050c5SMichael Chan 1059c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 1060c0c050c5SMichael Chan if (len < 2) 1061c0c050c5SMichael Chan return -EINVAL; 1062c0c050c5SMichael Chan 1063c0c050c5SMichael Chan *data++ = dir_entries; 1064c0c050c5SMichael Chan *data++ = entry_length; 1065c0c050c5SMichael Chan len -= 2; 1066c0c050c5SMichael Chan memset(data, 0xff, len); 1067c0c050c5SMichael Chan 1068c0c050c5SMichael Chan buflen = dir_entries * entry_length; 1069c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 1070c0c050c5SMichael Chan GFP_KERNEL); 1071c0c050c5SMichael Chan if (!buf) { 1072c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1073c0c050c5SMichael Chan (unsigned)buflen); 1074c0c050c5SMichael Chan return -ENOMEM; 1075c0c050c5SMichael Chan } 1076c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 1077c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 1078c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1079c0c050c5SMichael Chan if (rc == 0) 1080c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 1081c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 1082c0c050c5SMichael Chan return rc; 1083c0c050c5SMichael Chan } 1084c0c050c5SMichael Chan 1085c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 1086c0c050c5SMichael Chan u32 length, u8 *data) 1087c0c050c5SMichael Chan { 1088c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1089c0c050c5SMichael Chan int rc; 1090c0c050c5SMichael Chan u8 *buf; 1091c0c050c5SMichael Chan dma_addr_t dma_handle; 1092c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 1093c0c050c5SMichael Chan 1094c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 1095c0c050c5SMichael Chan GFP_KERNEL); 1096c0c050c5SMichael Chan if (!buf) { 1097c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1098c0c050c5SMichael Chan (unsigned)length); 1099c0c050c5SMichael Chan return -ENOMEM; 1100c0c050c5SMichael Chan } 1101c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 1102c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 1103c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 1104c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 1105c0c050c5SMichael Chan req.len = cpu_to_le32(length); 1106c0c050c5SMichael Chan 1107c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1108c0c050c5SMichael Chan if (rc == 0) 1109c0c050c5SMichael Chan memcpy(data, buf, length); 1110c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 1111c0c050c5SMichael Chan return rc; 1112c0c050c5SMichael Chan } 1113c0c050c5SMichael Chan 1114c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 1115c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 1116c0c050c5SMichael Chan u8 *data) 1117c0c050c5SMichael Chan { 1118c0c050c5SMichael Chan u32 index; 1119c0c050c5SMichael Chan u32 offset; 1120c0c050c5SMichael Chan 1121c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 1122c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 1123c0c050c5SMichael Chan 1124c0c050c5SMichael Chan index = eeprom->offset >> 24; 1125c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 1126c0c050c5SMichael Chan 1127c0c050c5SMichael Chan if (index == 0) { 1128c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 1129c0c050c5SMichael Chan return -EINVAL; 1130c0c050c5SMichael Chan } 1131c0c050c5SMichael Chan 1132c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 1133c0c050c5SMichael Chan } 1134c0c050c5SMichael Chan 1135c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 1136c0c050c5SMichael Chan { 1137c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1138c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 1139c0c050c5SMichael Chan 1140c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 1141c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 1142c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1143c0c050c5SMichael Chan } 1144c0c050c5SMichael Chan 1145c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 1146c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 1147c0c050c5SMichael Chan u8 *data) 1148c0c050c5SMichael Chan { 1149c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1150c0c050c5SMichael Chan u8 index, dir_op; 1151c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 1152c0c050c5SMichael Chan 1153c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 1154c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 1155c0c050c5SMichael Chan return -EINVAL; 1156c0c050c5SMichael Chan } 1157c0c050c5SMichael Chan 1158c0c050c5SMichael Chan type = eeprom->magic >> 16; 1159c0c050c5SMichael Chan 1160c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 1161c0c050c5SMichael Chan index = eeprom->magic & 0xff; 1162c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 1163c0c050c5SMichael Chan if (index == 0) 1164c0c050c5SMichael Chan return -EINVAL; 1165c0c050c5SMichael Chan switch (dir_op) { 1166c0c050c5SMichael Chan case 0x0e: /* erase */ 1167c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 1168c0c050c5SMichael Chan return -EINVAL; 1169c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 1170c0c050c5SMichael Chan default: 1171c0c050c5SMichael Chan return -EINVAL; 1172c0c050c5SMichael Chan } 1173c0c050c5SMichael Chan } 1174c0c050c5SMichael Chan 1175c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 1176c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(type) == true) 1177c0c050c5SMichael Chan return -EINVAL; 1178c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 1179c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 1180c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 1181c0c050c5SMichael Chan 1182c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 1183c0c050c5SMichael Chan eeprom->len); 1184c0c050c5SMichael Chan } 1185c0c050c5SMichael Chan 1186c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 1187c0c050c5SMichael Chan .get_settings = bnxt_get_settings, 1188c0c050c5SMichael Chan .set_settings = bnxt_set_settings, 1189c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 1190c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 1191c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 1192c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 1193c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 1194c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 1195c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 1196c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 1197c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 1198c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 1199c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 1200c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 1201c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 1202c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 1203c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 1204c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 1205c0c050c5SMichael Chan #endif 1206c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 1207c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 1208c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 1209c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 1210c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 1211c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 1212c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 1213c0c050c5SMichael Chan .get_link = bnxt_get_link, 1214c0c050c5SMichael Chan }; 1215