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 103ebf6f0aSRob Swindell #include <linux/ctype.h> 11c0c050c5SMichael Chan #include <linux/ethtool.h> 12c0c050c5SMichael Chan #include <linux/interrupt.h> 13c0c050c5SMichael Chan #include <linux/pci.h> 14c0c050c5SMichael Chan #include <linux/etherdevice.h> 15c0c050c5SMichael Chan #include <linux/crc32.h> 16c0c050c5SMichael Chan #include <linux/firmware.h> 17c0c050c5SMichael Chan #include "bnxt_hsi.h" 18c0c050c5SMichael Chan #include "bnxt.h" 19c0c050c5SMichael Chan #include "bnxt_ethtool.h" 20c0c050c5SMichael Chan #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */ 21c0c050c5SMichael Chan #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */ 22c0c050c5SMichael Chan #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100) 23c0c050c5SMichael Chan 243ebf6f0aSRob Swindell static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen); 253ebf6f0aSRob Swindell 26c0c050c5SMichael Chan static u32 bnxt_get_msglevel(struct net_device *dev) 27c0c050c5SMichael Chan { 28c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 29c0c050c5SMichael Chan 30c0c050c5SMichael Chan return bp->msg_enable; 31c0c050c5SMichael Chan } 32c0c050c5SMichael Chan 33c0c050c5SMichael Chan static void bnxt_set_msglevel(struct net_device *dev, u32 value) 34c0c050c5SMichael Chan { 35c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 36c0c050c5SMichael Chan 37c0c050c5SMichael Chan bp->msg_enable = value; 38c0c050c5SMichael Chan } 39c0c050c5SMichael Chan 40c0c050c5SMichael Chan static int bnxt_get_coalesce(struct net_device *dev, 41c0c050c5SMichael Chan struct ethtool_coalesce *coal) 42c0c050c5SMichael Chan { 43c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 44c0c050c5SMichael Chan 45c0c050c5SMichael Chan memset(coal, 0, sizeof(*coal)); 46c0c050c5SMichael Chan 47dfb5b894SMichael Chan coal->rx_coalesce_usecs = bp->rx_coal_ticks; 48dfb5b894SMichael Chan /* 2 completion records per rx packet */ 49dfb5b894SMichael Chan coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2; 50dfb5b894SMichael Chan coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq; 51dfb5b894SMichael Chan coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2; 52c0c050c5SMichael Chan 53dfc9c94aSMichael Chan coal->tx_coalesce_usecs = bp->tx_coal_ticks; 54dfc9c94aSMichael Chan coal->tx_max_coalesced_frames = bp->tx_coal_bufs; 55dfc9c94aSMichael Chan coal->tx_coalesce_usecs_irq = bp->tx_coal_ticks_irq; 56dfc9c94aSMichael Chan coal->tx_max_coalesced_frames_irq = bp->tx_coal_bufs_irq; 57dfc9c94aSMichael Chan 58c0c050c5SMichael Chan return 0; 59c0c050c5SMichael Chan } 60c0c050c5SMichael Chan 61c0c050c5SMichael Chan static int bnxt_set_coalesce(struct net_device *dev, 62c0c050c5SMichael Chan struct ethtool_coalesce *coal) 63c0c050c5SMichael Chan { 64c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 65c0c050c5SMichael Chan int rc = 0; 66c0c050c5SMichael Chan 67dfb5b894SMichael Chan bp->rx_coal_ticks = coal->rx_coalesce_usecs; 68dfb5b894SMichael Chan /* 2 completion records per rx packet */ 69dfb5b894SMichael Chan bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2; 70dfb5b894SMichael Chan bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq; 71dfb5b894SMichael Chan bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2; 72c0c050c5SMichael Chan 73dfc9c94aSMichael Chan bp->tx_coal_ticks = coal->tx_coalesce_usecs; 74dfc9c94aSMichael Chan bp->tx_coal_bufs = coal->tx_max_coalesced_frames; 75dfc9c94aSMichael Chan bp->tx_coal_ticks_irq = coal->tx_coalesce_usecs_irq; 76dfc9c94aSMichael Chan bp->tx_coal_bufs_irq = coal->tx_max_coalesced_frames_irq; 77dfc9c94aSMichael Chan 78c0c050c5SMichael Chan if (netif_running(dev)) 79c0c050c5SMichael Chan rc = bnxt_hwrm_set_coal(bp); 80c0c050c5SMichael Chan 81c0c050c5SMichael Chan return rc; 82c0c050c5SMichael Chan } 83c0c050c5SMichael Chan 84c0c050c5SMichael Chan #define BNXT_NUM_STATS 21 85c0c050c5SMichael Chan 86c0c050c5SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset) 87c0c050c5SMichael Chan { 88c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 89c0c050c5SMichael Chan 90c0c050c5SMichael Chan switch (sset) { 91c0c050c5SMichael Chan case ETH_SS_STATS: 92c0c050c5SMichael Chan return BNXT_NUM_STATS * bp->cp_nr_rings; 93c0c050c5SMichael Chan default: 94c0c050c5SMichael Chan return -EOPNOTSUPP; 95c0c050c5SMichael Chan } 96c0c050c5SMichael Chan } 97c0c050c5SMichael Chan 98c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev, 99c0c050c5SMichael Chan struct ethtool_stats *stats, u64 *buf) 100c0c050c5SMichael Chan { 101c0c050c5SMichael Chan u32 i, j = 0; 102c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 103c0c050c5SMichael Chan u32 buf_size = sizeof(struct ctx_hw_stats) * bp->cp_nr_rings; 104c0c050c5SMichael Chan u32 stat_fields = sizeof(struct ctx_hw_stats) / 8; 105c0c050c5SMichael Chan 106c0c050c5SMichael Chan memset(buf, 0, buf_size); 107c0c050c5SMichael Chan 108c0c050c5SMichael Chan if (!bp->bnapi) 109c0c050c5SMichael Chan return; 110c0c050c5SMichael Chan 111c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 112c0c050c5SMichael Chan struct bnxt_napi *bnapi = bp->bnapi[i]; 113c0c050c5SMichael Chan struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; 114c0c050c5SMichael Chan __le64 *hw_stats = (__le64 *)cpr->hw_stats; 115c0c050c5SMichael Chan int k; 116c0c050c5SMichael Chan 117c0c050c5SMichael Chan for (k = 0; k < stat_fields; j++, k++) 118c0c050c5SMichael Chan buf[j] = le64_to_cpu(hw_stats[k]); 119c0c050c5SMichael Chan buf[j++] = cpr->rx_l4_csum_errors; 120c0c050c5SMichael Chan } 121c0c050c5SMichael Chan } 122c0c050c5SMichael Chan 123c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 124c0c050c5SMichael Chan { 125c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 126c0c050c5SMichael Chan u32 i; 127c0c050c5SMichael Chan 128c0c050c5SMichael Chan switch (stringset) { 129c0c050c5SMichael Chan /* The number of strings must match BNXT_NUM_STATS defined above. */ 130c0c050c5SMichael Chan case ETH_SS_STATS: 131c0c050c5SMichael Chan for (i = 0; i < bp->cp_nr_rings; i++) { 132c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_ucast_packets", i); 133c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 134c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_mcast_packets", i); 135c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 136c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_bcast_packets", i); 137c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 138c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_discards", i); 139c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 140c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_drops", i); 141c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 142c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_ucast_bytes", i); 143c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 144c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_mcast_bytes", i); 145c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 146c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_bcast_bytes", i); 147c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 148c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_ucast_packets", i); 149c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 150c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_mcast_packets", i); 151c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 152c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_bcast_packets", i); 153c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 154c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_discards", i); 155c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 156c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_drops", i); 157c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 158c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_ucast_bytes", i); 159c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 160c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_mcast_bytes", i); 161c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 162c0c050c5SMichael Chan sprintf(buf, "[%d]: tx_bcast_bytes", i); 163c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 164c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_packets", i); 165c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 166c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_bytes", i); 167c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 168c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_events", i); 169c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 170c0c050c5SMichael Chan sprintf(buf, "[%d]: tpa_aborts", i); 171c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 172c0c050c5SMichael Chan sprintf(buf, "[%d]: rx_l4_csum_errors", i); 173c0c050c5SMichael Chan buf += ETH_GSTRING_LEN; 174c0c050c5SMichael Chan } 175c0c050c5SMichael Chan break; 176c0c050c5SMichael Chan default: 177c0c050c5SMichael Chan netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", 178c0c050c5SMichael Chan stringset); 179c0c050c5SMichael Chan break; 180c0c050c5SMichael Chan } 181c0c050c5SMichael Chan } 182c0c050c5SMichael Chan 183c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev, 184c0c050c5SMichael Chan struct ethtool_ringparam *ering) 185c0c050c5SMichael Chan { 186c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 187c0c050c5SMichael Chan 188c0c050c5SMichael Chan ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; 189c0c050c5SMichael Chan ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; 190c0c050c5SMichael Chan ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; 191c0c050c5SMichael Chan 192c0c050c5SMichael Chan ering->rx_pending = bp->rx_ring_size; 193c0c050c5SMichael Chan ering->rx_jumbo_pending = bp->rx_agg_ring_size; 194c0c050c5SMichael Chan ering->tx_pending = bp->tx_ring_size; 195c0c050c5SMichael Chan } 196c0c050c5SMichael Chan 197c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev, 198c0c050c5SMichael Chan struct ethtool_ringparam *ering) 199c0c050c5SMichael Chan { 200c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 201c0c050c5SMichael Chan 202c0c050c5SMichael Chan if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || 203c0c050c5SMichael Chan (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || 204c0c050c5SMichael Chan (ering->tx_pending <= MAX_SKB_FRAGS)) 205c0c050c5SMichael Chan return -EINVAL; 206c0c050c5SMichael Chan 207c0c050c5SMichael Chan if (netif_running(dev)) 208c0c050c5SMichael Chan bnxt_close_nic(bp, false, false); 209c0c050c5SMichael Chan 210c0c050c5SMichael Chan bp->rx_ring_size = ering->rx_pending; 211c0c050c5SMichael Chan bp->tx_ring_size = ering->tx_pending; 212c0c050c5SMichael Chan bnxt_set_ring_params(bp); 213c0c050c5SMichael Chan 214c0c050c5SMichael Chan if (netif_running(dev)) 215c0c050c5SMichael Chan return bnxt_open_nic(bp, false, false); 216c0c050c5SMichael Chan 217c0c050c5SMichael Chan return 0; 218c0c050c5SMichael Chan } 219c0c050c5SMichael Chan 220c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev, 221c0c050c5SMichael Chan struct ethtool_channels *channel) 222c0c050c5SMichael Chan { 223c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 224c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 225c0c050c5SMichael Chan 2266e6c5a57SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); 227068c9ec6SMichael Chan channel->max_combined = max_rx_rings; 228068c9ec6SMichael Chan 229068c9ec6SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false); 230c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 231c0c050c5SMichael Chan if (tcs > 1) 232c0c050c5SMichael Chan max_tx_rings /= tcs; 233c0c050c5SMichael Chan 234c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 235c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 236c0c050c5SMichael Chan channel->max_other = 0; 237068c9ec6SMichael Chan if (bp->flags & BNXT_FLAG_SHARED_RINGS) { 238068c9ec6SMichael Chan channel->combined_count = bp->rx_nr_rings; 239068c9ec6SMichael Chan } else { 240c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 241c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 242c0c050c5SMichael Chan } 243068c9ec6SMichael Chan } 244c0c050c5SMichael Chan 245c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 246c0c050c5SMichael Chan struct ethtool_channels *channel) 247c0c050c5SMichael Chan { 248c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 249c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 250c0c050c5SMichael Chan u32 rc = 0; 251068c9ec6SMichael Chan bool sh = false; 252c0c050c5SMichael Chan 253068c9ec6SMichael Chan if (channel->other_count) 254c0c050c5SMichael Chan return -EINVAL; 255c0c050c5SMichael Chan 256068c9ec6SMichael Chan if (!channel->combined_count && 257068c9ec6SMichael Chan (!channel->rx_count || !channel->tx_count)) 258068c9ec6SMichael Chan return -EINVAL; 259068c9ec6SMichael Chan 260068c9ec6SMichael Chan if (channel->combined_count && 261068c9ec6SMichael Chan (channel->rx_count || channel->tx_count)) 262068c9ec6SMichael Chan return -EINVAL; 263068c9ec6SMichael Chan 264068c9ec6SMichael Chan if (channel->combined_count) 265068c9ec6SMichael Chan sh = true; 266068c9ec6SMichael Chan 267068c9ec6SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh); 268068c9ec6SMichael Chan 269c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 270c0c050c5SMichael Chan if (tcs > 1) 271c0c050c5SMichael Chan max_tx_rings /= tcs; 272c0c050c5SMichael Chan 273068c9ec6SMichael Chan if (sh && (channel->combined_count > max_rx_rings || 274068c9ec6SMichael Chan channel->combined_count > max_tx_rings)) 275068c9ec6SMichael Chan return -ENOMEM; 276068c9ec6SMichael Chan 277068c9ec6SMichael Chan if (!sh && (channel->rx_count > max_rx_rings || 278068c9ec6SMichael Chan channel->tx_count > max_tx_rings)) 279068c9ec6SMichael Chan return -ENOMEM; 280c0c050c5SMichael Chan 281c0c050c5SMichael Chan if (netif_running(dev)) { 282c0c050c5SMichael Chan if (BNXT_PF(bp)) { 283c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 284c0c050c5SMichael Chan * before PF unload 285c0c050c5SMichael Chan */ 286c0c050c5SMichael Chan } 287c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 288c0c050c5SMichael Chan if (rc) { 289c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 290c0c050c5SMichael Chan rc); 291c0c050c5SMichael Chan return rc; 292c0c050c5SMichael Chan } 293c0c050c5SMichael Chan } 294c0c050c5SMichael Chan 295068c9ec6SMichael Chan if (sh) { 296068c9ec6SMichael Chan bp->flags |= BNXT_FLAG_SHARED_RINGS; 297068c9ec6SMichael Chan bp->rx_nr_rings = channel->combined_count; 298068c9ec6SMichael Chan bp->tx_nr_rings_per_tc = channel->combined_count; 299068c9ec6SMichael Chan } else { 300068c9ec6SMichael Chan bp->flags &= ~BNXT_FLAG_SHARED_RINGS; 301c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 302c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 303068c9ec6SMichael Chan } 304068c9ec6SMichael Chan 305c0c050c5SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc; 306c0c050c5SMichael Chan if (tcs > 1) 307c0c050c5SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs; 308068c9ec6SMichael Chan 309068c9ec6SMichael Chan bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : 310068c9ec6SMichael Chan bp->tx_nr_rings + bp->rx_nr_rings; 311068c9ec6SMichael Chan 312c0c050c5SMichael Chan bp->num_stat_ctxs = bp->cp_nr_rings; 313c0c050c5SMichael Chan 3142bcfa6f6SMichael Chan /* After changing number of rx channels, update NTUPLE feature. */ 3152bcfa6f6SMichael Chan netdev_update_features(dev); 316c0c050c5SMichael Chan if (netif_running(dev)) { 317c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 318c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 319c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 320c0c050c5SMichael Chan * to renable 321c0c050c5SMichael Chan */ 322c0c050c5SMichael Chan } 323c0c050c5SMichael Chan } 324c0c050c5SMichael Chan 325c0c050c5SMichael Chan return rc; 326c0c050c5SMichael Chan } 327c0c050c5SMichael Chan 328c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 329c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 330c0c050c5SMichael Chan u32 *rule_locs) 331c0c050c5SMichael Chan { 332c0c050c5SMichael Chan int i, j = 0; 333c0c050c5SMichael Chan 334c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 335c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 336c0c050c5SMichael Chan struct hlist_head *head; 337c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 338c0c050c5SMichael Chan 339c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 340c0c050c5SMichael Chan rcu_read_lock(); 341c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 342c0c050c5SMichael Chan if (j == cmd->rule_cnt) 343c0c050c5SMichael Chan break; 344c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 345c0c050c5SMichael Chan } 346c0c050c5SMichael Chan rcu_read_unlock(); 347c0c050c5SMichael Chan if (j == cmd->rule_cnt) 348c0c050c5SMichael Chan break; 349c0c050c5SMichael Chan } 350c0c050c5SMichael Chan cmd->rule_cnt = j; 351c0c050c5SMichael Chan return 0; 352c0c050c5SMichael Chan } 353c0c050c5SMichael Chan 354c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 355c0c050c5SMichael Chan { 356c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 357c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 358c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 359c0c050c5SMichael Chan struct flow_keys *fkeys; 360c0c050c5SMichael Chan int i, rc = -EINVAL; 361c0c050c5SMichael Chan 362c0c050c5SMichael Chan if (fs->location < 0 || fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 363c0c050c5SMichael Chan return rc; 364c0c050c5SMichael Chan 365c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 366c0c050c5SMichael Chan struct hlist_head *head; 367c0c050c5SMichael Chan 368c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 369c0c050c5SMichael Chan rcu_read_lock(); 370c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 371c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 372c0c050c5SMichael Chan goto fltr_found; 373c0c050c5SMichael Chan } 374c0c050c5SMichael Chan rcu_read_unlock(); 375c0c050c5SMichael Chan } 376c0c050c5SMichael Chan return rc; 377c0c050c5SMichael Chan 378c0c050c5SMichael Chan fltr_found: 379c0c050c5SMichael Chan fkeys = &fltr->fkeys; 380c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 381c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 382c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 383c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 384c0c050c5SMichael Chan else 385c0c050c5SMichael Chan goto fltr_err; 386c0c050c5SMichael Chan 387c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 388c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 389c0c050c5SMichael Chan 390c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 391c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 392c0c050c5SMichael Chan 393c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 394c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 395c0c050c5SMichael Chan 396c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 397c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 398c0c050c5SMichael Chan 399c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 400c0c050c5SMichael Chan rc = 0; 401c0c050c5SMichael Chan 402c0c050c5SMichael Chan fltr_err: 403c0c050c5SMichael Chan rcu_read_unlock(); 404c0c050c5SMichael Chan 405c0c050c5SMichael Chan return rc; 406c0c050c5SMichael Chan } 407c0c050c5SMichael Chan 408c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 409c0c050c5SMichael Chan u32 *rule_locs) 410c0c050c5SMichael Chan { 411c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 412c0c050c5SMichael Chan int rc = 0; 413c0c050c5SMichael Chan 414c0c050c5SMichael Chan switch (cmd->cmd) { 415c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 416c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 417c0c050c5SMichael Chan break; 418c0c050c5SMichael Chan 419c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 420c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 421c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 422c0c050c5SMichael Chan break; 423c0c050c5SMichael Chan 424c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 425c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 426c0c050c5SMichael Chan break; 427c0c050c5SMichael Chan 428c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 429c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 430c0c050c5SMichael Chan break; 431c0c050c5SMichael Chan 432c0c050c5SMichael Chan default: 433c0c050c5SMichael Chan rc = -EOPNOTSUPP; 434c0c050c5SMichael Chan break; 435c0c050c5SMichael Chan } 436c0c050c5SMichael Chan 437c0c050c5SMichael Chan return rc; 438c0c050c5SMichael Chan } 439c0c050c5SMichael Chan #endif 440c0c050c5SMichael Chan 441c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 442c0c050c5SMichael Chan { 443c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 444c0c050c5SMichael Chan } 445c0c050c5SMichael Chan 446c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 447c0c050c5SMichael Chan { 448c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 449c0c050c5SMichael Chan } 450c0c050c5SMichael Chan 451c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 452c0c050c5SMichael Chan u8 *hfunc) 453c0c050c5SMichael Chan { 454c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 455c0c050c5SMichael Chan struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; 456c0c050c5SMichael Chan int i = 0; 457c0c050c5SMichael Chan 458c0c050c5SMichael Chan if (hfunc) 459c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 460c0c050c5SMichael Chan 461c0c050c5SMichael Chan if (indir) 462c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 463c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 464c0c050c5SMichael Chan 465c0c050c5SMichael Chan if (key) 466c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 467c0c050c5SMichael Chan 468c0c050c5SMichael Chan return 0; 469c0c050c5SMichael Chan } 470c0c050c5SMichael Chan 471c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 472c0c050c5SMichael Chan struct ethtool_drvinfo *info) 473c0c050c5SMichael Chan { 474c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 4753ebf6f0aSRob Swindell char *pkglog; 4763ebf6f0aSRob Swindell char *pkgver = NULL; 477c0c050c5SMichael Chan 4783ebf6f0aSRob Swindell pkglog = kmalloc(BNX_PKG_LOG_MAX_LENGTH, GFP_KERNEL); 4793ebf6f0aSRob Swindell if (pkglog) 4803ebf6f0aSRob Swindell pkgver = bnxt_get_pkgver(dev, pkglog, BNX_PKG_LOG_MAX_LENGTH); 481c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 482c0c050c5SMichael Chan strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 4833ebf6f0aSRob Swindell if (pkgver && *pkgver != 0 && isdigit(*pkgver)) 4843ebf6f0aSRob Swindell snprintf(info->fw_version, sizeof(info->fw_version) - 1, 4853ebf6f0aSRob Swindell "%s pkg %s", bp->fw_ver_str, pkgver); 4863ebf6f0aSRob Swindell else 4873ebf6f0aSRob Swindell strlcpy(info->fw_version, bp->fw_ver_str, 4883ebf6f0aSRob Swindell sizeof(info->fw_version)); 489c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 490c0c050c5SMichael Chan info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings; 491c0c050c5SMichael Chan info->testinfo_len = BNXT_NUM_TESTS(bp); 492c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 493c0c050c5SMichael Chan info->eedump_len = 0; 494c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 495c0c050c5SMichael Chan info->regdump_len = 0; 4963ebf6f0aSRob Swindell kfree(pkglog); 497c0c050c5SMichael Chan } 498c0c050c5SMichael Chan 49927c4d578SMichael Chan static u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause) 500c0c050c5SMichael Chan { 501c0c050c5SMichael Chan u32 speed_mask = 0; 502c0c050c5SMichael Chan 503c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 504c0c050c5SMichael Chan /* set the advertised speeds */ 505c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 506c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 507c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 508c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 509c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 510c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 511c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 512c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 513c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 5141c49c421SMichael Chan speed_mask |= ADVERTISED_40000baseCR4_Full; 51527c4d578SMichael Chan 51627c4d578SMichael Chan if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH) 51727c4d578SMichael Chan speed_mask |= ADVERTISED_Pause; 51827c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_TX) 51927c4d578SMichael Chan speed_mask |= ADVERTISED_Asym_Pause; 52027c4d578SMichael Chan else if (fw_pause & BNXT_LINK_PAUSE_RX) 52127c4d578SMichael Chan speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; 52227c4d578SMichael Chan 523c0c050c5SMichael Chan return speed_mask; 524c0c050c5SMichael Chan } 525c0c050c5SMichael Chan 52627c4d578SMichael Chan static u32 bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info) 52727c4d578SMichael Chan { 52827c4d578SMichael Chan u16 fw_speeds = link_info->auto_link_speeds; 52927c4d578SMichael Chan u8 fw_pause = 0; 53027c4d578SMichael Chan 53127c4d578SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 53227c4d578SMichael Chan fw_pause = link_info->auto_pause_setting; 53327c4d578SMichael Chan 53427c4d578SMichael Chan return _bnxt_fw_to_ethtool_adv_spds(fw_speeds, fw_pause); 53527c4d578SMichael Chan } 53627c4d578SMichael Chan 5373277360eSMichael Chan static u32 bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info) 5383277360eSMichael Chan { 5393277360eSMichael Chan u16 fw_speeds = link_info->lp_auto_link_speeds; 5403277360eSMichael Chan u8 fw_pause = 0; 5413277360eSMichael Chan 5423277360eSMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 5433277360eSMichael Chan fw_pause = link_info->lp_pause; 5443277360eSMichael Chan 5453277360eSMichael Chan return _bnxt_fw_to_ethtool_adv_spds(fw_speeds, fw_pause); 5463277360eSMichael Chan } 5473277360eSMichael Chan 5484b32caccSMichael Chan static u32 bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info) 5494b32caccSMichael Chan { 5504b32caccSMichael Chan u16 fw_speeds = link_info->support_speeds; 5514b32caccSMichael Chan u32 supported; 5524b32caccSMichael Chan 5534b32caccSMichael Chan supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); 5544b32caccSMichael Chan return supported | SUPPORTED_Pause | SUPPORTED_Asym_Pause; 5554b32caccSMichael Chan } 5564b32caccSMichael Chan 557c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 558c0c050c5SMichael Chan { 559c0c050c5SMichael Chan switch (fw_link_speed) { 560c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 561c0c050c5SMichael Chan return SPEED_100; 562c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 563c0c050c5SMichael Chan return SPEED_1000; 564c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 565c0c050c5SMichael Chan return SPEED_2500; 566c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 567c0c050c5SMichael Chan return SPEED_10000; 568c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 569c0c050c5SMichael Chan return SPEED_20000; 570c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 571c0c050c5SMichael Chan return SPEED_25000; 572c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 573c0c050c5SMichael Chan return SPEED_40000; 574c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 575c0c050c5SMichael Chan return SPEED_50000; 576c0c050c5SMichael Chan default: 577c0c050c5SMichael Chan return SPEED_UNKNOWN; 578c0c050c5SMichael Chan } 579c0c050c5SMichael Chan } 580c0c050c5SMichael Chan 581c0c050c5SMichael Chan static int bnxt_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 582c0c050c5SMichael Chan { 583c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 584c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 585c0c050c5SMichael Chan u16 ethtool_speed; 586c0c050c5SMichael Chan 587c0c050c5SMichael Chan cmd->supported = bnxt_fw_to_ethtool_support_spds(link_info); 588c0c050c5SMichael Chan 589c0c050c5SMichael Chan if (link_info->auto_link_speeds) 590c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Autoneg; 591c0c050c5SMichael Chan 592b763499eSMichael Chan if (link_info->autoneg) { 593c0c050c5SMichael Chan cmd->advertising = 594c0c050c5SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info); 595c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Autoneg; 596c0c050c5SMichael Chan cmd->autoneg = AUTONEG_ENABLE; 5973277360eSMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) 5983277360eSMichael Chan cmd->lp_advertising = 5993277360eSMichael Chan bnxt_fw_to_ethtool_lp_adv(link_info); 600c0c050c5SMichael Chan } else { 601c0c050c5SMichael Chan cmd->autoneg = AUTONEG_DISABLE; 602c0c050c5SMichael Chan cmd->advertising = 0; 603c0c050c5SMichael Chan } 604c0c050c5SMichael Chan 605c0c050c5SMichael Chan cmd->port = PORT_NONE; 606c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 607c0c050c5SMichael Chan cmd->port = PORT_TP; 608c0c050c5SMichael Chan cmd->supported |= SUPPORTED_TP; 609c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_TP; 610c0c050c5SMichael Chan } else { 611c0c050c5SMichael Chan cmd->supported |= SUPPORTED_FIBRE; 612c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_FIBRE; 613c0c050c5SMichael Chan 614c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 615c0c050c5SMichael Chan cmd->port = PORT_DA; 616c0c050c5SMichael Chan else if (link_info->media_type == 617c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 618c0c050c5SMichael Chan cmd->port = PORT_FIBRE; 619c0c050c5SMichael Chan } 620c0c050c5SMichael Chan 621c0c050c5SMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) { 622c0c050c5SMichael Chan if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 623c0c050c5SMichael Chan cmd->duplex = DUPLEX_FULL; 624c0c050c5SMichael Chan } else { 625c0c050c5SMichael Chan cmd->duplex = DUPLEX_UNKNOWN; 626c0c050c5SMichael Chan } 627c0c050c5SMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 628c0c050c5SMichael Chan ethtool_cmd_speed_set(cmd, ethtool_speed); 629c0c050c5SMichael Chan if (link_info->transceiver == 630c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_TRANSCEIVER_TYPE_XCVR_INTERNAL) 631c0c050c5SMichael Chan cmd->transceiver = XCVR_INTERNAL; 632c0c050c5SMichael Chan else 633c0c050c5SMichael Chan cmd->transceiver = XCVR_EXTERNAL; 634c0c050c5SMichael Chan cmd->phy_address = link_info->phy_addr; 635c0c050c5SMichael Chan 636c0c050c5SMichael Chan return 0; 637c0c050c5SMichael Chan } 638c0c050c5SMichael Chan 639c0c050c5SMichael Chan static u32 bnxt_get_fw_speed(struct net_device *dev, u16 ethtool_speed) 640c0c050c5SMichael Chan { 641c0c050c5SMichael Chan switch (ethtool_speed) { 642c0c050c5SMichael Chan case SPEED_100: 643c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 644c0c050c5SMichael Chan case SPEED_1000: 645c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 646c0c050c5SMichael Chan case SPEED_2500: 647c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 648c0c050c5SMichael Chan case SPEED_10000: 649c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 650c0c050c5SMichael Chan case SPEED_20000: 651c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 652c0c050c5SMichael Chan case SPEED_25000: 653c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 654c0c050c5SMichael Chan case SPEED_40000: 655c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 656c0c050c5SMichael Chan case SPEED_50000: 657c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 658c0c050c5SMichael Chan default: 659c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 660c0c050c5SMichael Chan break; 661c0c050c5SMichael Chan } 662c0c050c5SMichael Chan return 0; 663c0c050c5SMichael Chan } 664c0c050c5SMichael Chan 665c0c050c5SMichael Chan static u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 666c0c050c5SMichael Chan { 667c0c050c5SMichael Chan u16 fw_speed_mask = 0; 668c0c050c5SMichael Chan 669c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 670c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 671c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 672c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 673c0c050c5SMichael Chan } 674c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 675c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 676c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 677c0c050c5SMichael Chan } 678c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 679c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 680c0c050c5SMichael Chan 6811c49c421SMichael Chan if (advertising & ADVERTISED_40000baseCR4_Full) 6821c49c421SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; 6831c49c421SMichael Chan 684c0c050c5SMichael Chan return fw_speed_mask; 685c0c050c5SMichael Chan } 686c0c050c5SMichael Chan 687c0c050c5SMichael Chan static int bnxt_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 688c0c050c5SMichael Chan { 689c0c050c5SMichael Chan int rc = 0; 690c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 691c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 692c0c050c5SMichael Chan u32 speed, fw_advertising = 0; 693c0c050c5SMichael Chan bool set_pause = false; 694c0c050c5SMichael Chan 695c0c050c5SMichael Chan if (BNXT_VF(bp)) 696c0c050c5SMichael Chan return rc; 697c0c050c5SMichael Chan 698c0c050c5SMichael Chan if (cmd->autoneg == AUTONEG_ENABLE) { 699*f1a082a6SMichael Chan u32 supported_spds = bnxt_fw_to_ethtool_support_spds(link_info); 700*f1a082a6SMichael Chan 701*f1a082a6SMichael Chan if (cmd->advertising & ~(supported_spds | ADVERTISED_Autoneg | 702*f1a082a6SMichael Chan ADVERTISED_TP | ADVERTISED_FIBRE)) { 703c0c050c5SMichael Chan netdev_err(dev, "Unsupported advertising mask (adv: 0x%x)\n", 704c0c050c5SMichael Chan cmd->advertising); 705c0c050c5SMichael Chan rc = -EINVAL; 706c0c050c5SMichael Chan goto set_setting_exit; 707c0c050c5SMichael Chan } 708c0c050c5SMichael Chan fw_advertising = bnxt_get_fw_auto_link_speeds(cmd->advertising); 709c0c050c5SMichael Chan if (fw_advertising & ~link_info->support_speeds) { 710c0c050c5SMichael Chan netdev_err(dev, "Advertising parameters are not supported! (adv: 0x%x)\n", 711c0c050c5SMichael Chan cmd->advertising); 712c0c050c5SMichael Chan rc = -EINVAL; 713c0c050c5SMichael Chan goto set_setting_exit; 714c0c050c5SMichael Chan } 715c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 716c0c050c5SMichael Chan if (!fw_advertising) 717c0c050c5SMichael Chan link_info->advertising = link_info->support_speeds; 718c0c050c5SMichael Chan else 719c0c050c5SMichael Chan link_info->advertising = fw_advertising; 720c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 721c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 722c0c050c5SMichael Chan */ 723c0c050c5SMichael Chan set_pause = true; 724c0c050c5SMichael Chan } else { 725c0c050c5SMichael Chan /* TODO: currently don't support half duplex */ 726c0c050c5SMichael Chan if (cmd->duplex == DUPLEX_HALF) { 727c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 728c0c050c5SMichael Chan rc = -EINVAL; 729c0c050c5SMichael Chan goto set_setting_exit; 730c0c050c5SMichael Chan } 731c0c050c5SMichael Chan /* If received a request for an unknown duplex, assume full*/ 732c0c050c5SMichael Chan if (cmd->duplex == DUPLEX_UNKNOWN) 733c0c050c5SMichael Chan cmd->duplex = DUPLEX_FULL; 734c0c050c5SMichael Chan speed = ethtool_cmd_speed(cmd); 735c0c050c5SMichael Chan link_info->req_link_speed = bnxt_get_fw_speed(dev, speed); 736c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 737b763499eSMichael Chan link_info->autoneg = 0; 738c0c050c5SMichael Chan link_info->advertising = 0; 739c0c050c5SMichael Chan } 740c0c050c5SMichael Chan 741c0c050c5SMichael Chan if (netif_running(dev)) 742c0c050c5SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause); 743c0c050c5SMichael Chan 744c0c050c5SMichael Chan set_setting_exit: 745c0c050c5SMichael Chan return rc; 746c0c050c5SMichael Chan } 747c0c050c5SMichael Chan 748c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 749c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 750c0c050c5SMichael Chan { 751c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 752c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 753c0c050c5SMichael Chan 754c0c050c5SMichael Chan if (BNXT_VF(bp)) 755c0c050c5SMichael Chan return; 756b763499eSMichael Chan epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); 7573277360eSMichael Chan epause->rx_pause = 7583277360eSMichael Chan ((link_info->auto_pause_setting & BNXT_LINK_PAUSE_RX) != 0); 7593277360eSMichael Chan epause->tx_pause = 7603277360eSMichael Chan ((link_info->auto_pause_setting & BNXT_LINK_PAUSE_TX) != 0); 761c0c050c5SMichael Chan } 762c0c050c5SMichael Chan 763c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 764c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 765c0c050c5SMichael Chan { 766c0c050c5SMichael Chan int rc = 0; 767c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 768c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 769c0c050c5SMichael Chan 770c0c050c5SMichael Chan if (BNXT_VF(bp)) 771c0c050c5SMichael Chan return rc; 772c0c050c5SMichael Chan 773c0c050c5SMichael Chan if (epause->autoneg) { 774b763499eSMichael Chan if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) 775b763499eSMichael Chan return -EINVAL; 776b763499eSMichael Chan 777c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 778c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_BOTH; 779c0c050c5SMichael Chan } else { 780c0c050c5SMichael Chan /* when transition from auto pause to force pause, 781c0c050c5SMichael Chan * force a link change 782c0c050c5SMichael Chan */ 783c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 784c0c050c5SMichael Chan link_info->force_link_chng = true; 785c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 786c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_BOTH; 787c0c050c5SMichael Chan } 788c0c050c5SMichael Chan if (epause->rx_pause) 789c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 790c0c050c5SMichael Chan else 791c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_RX; 792c0c050c5SMichael Chan 793c0c050c5SMichael Chan if (epause->tx_pause) 794c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 795c0c050c5SMichael Chan else 796c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_TX; 797c0c050c5SMichael Chan 798c0c050c5SMichael Chan if (netif_running(dev)) 799c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 800c0c050c5SMichael Chan return rc; 801c0c050c5SMichael Chan } 802c0c050c5SMichael Chan 803c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 804c0c050c5SMichael Chan { 805c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 806c0c050c5SMichael Chan 807c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 808c0c050c5SMichael Chan return bp->link_info.link_up; 809c0c050c5SMichael Chan } 810c0c050c5SMichael Chan 811c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 812c0c050c5SMichael Chan u16 dir_type, 813c0c050c5SMichael Chan u16 dir_ordinal, 814c0c050c5SMichael Chan u16 dir_ext, 815c0c050c5SMichael Chan u16 dir_attr, 816c0c050c5SMichael Chan const u8 *data, 817c0c050c5SMichael Chan size_t data_len) 818c0c050c5SMichael Chan { 819c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 820c0c050c5SMichael Chan int rc; 821c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 822c0c050c5SMichael Chan dma_addr_t dma_handle; 823c0c050c5SMichael Chan u8 *kmem; 824c0c050c5SMichael Chan 825c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 826c0c050c5SMichael Chan 827c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 828c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 829c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 830c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 831c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 832c0c050c5SMichael Chan 833c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 834c0c050c5SMichael Chan GFP_KERNEL); 835c0c050c5SMichael Chan if (!kmem) { 836c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 837c0c050c5SMichael Chan (unsigned)data_len); 838c0c050c5SMichael Chan return -ENOMEM; 839c0c050c5SMichael Chan } 840c0c050c5SMichael Chan memcpy(kmem, data, data_len); 841c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 842c0c050c5SMichael Chan 843c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 844c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 845c0c050c5SMichael Chan 846c0c050c5SMichael Chan return rc; 847c0c050c5SMichael Chan } 848c0c050c5SMichael Chan 849d2d6318cSRob Swindell static int bnxt_firmware_reset(struct net_device *dev, 850d2d6318cSRob Swindell u16 dir_type) 851d2d6318cSRob Swindell { 852d2d6318cSRob Swindell struct bnxt *bp = netdev_priv(dev); 853d2d6318cSRob Swindell struct hwrm_fw_reset_input req = {0}; 854d2d6318cSRob Swindell 855d2d6318cSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 856d2d6318cSRob Swindell 857d2d6318cSRob Swindell /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */ 858d2d6318cSRob Swindell /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ 859d2d6318cSRob Swindell /* (e.g. when firmware isn't already running) */ 860d2d6318cSRob Swindell switch (dir_type) { 861d2d6318cSRob Swindell case BNX_DIR_TYPE_CHIMP_PATCH: 862d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE: 863d2d6318cSRob Swindell case BNX_DIR_TYPE_BOOTCODE_2: 864d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; 865d2d6318cSRob Swindell /* Self-reset ChiMP upon next PCIe reset: */ 866d2d6318cSRob Swindell req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; 867d2d6318cSRob Swindell break; 868d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_FW: 869d2d6318cSRob Swindell case BNX_DIR_TYPE_APE_PATCH: 870d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; 871d2d6318cSRob Swindell break; 872d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_FW: 873d2d6318cSRob Swindell case BNX_DIR_TYPE_KONG_PATCH: 874d2d6318cSRob Swindell req.embedded_proc_type = 875d2d6318cSRob Swindell FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; 876d2d6318cSRob Swindell break; 877d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_FW: 878d2d6318cSRob Swindell case BNX_DIR_TYPE_BONO_PATCH: 879d2d6318cSRob Swindell req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; 880d2d6318cSRob Swindell break; 881d2d6318cSRob Swindell default: 882d2d6318cSRob Swindell return -EINVAL; 883d2d6318cSRob Swindell } 884d2d6318cSRob Swindell 885d2d6318cSRob Swindell return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 886d2d6318cSRob Swindell } 887d2d6318cSRob Swindell 888c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 889c0c050c5SMichael Chan u16 dir_type, 890c0c050c5SMichael Chan const u8 *fw_data, 891c0c050c5SMichael Chan size_t fw_size) 892c0c050c5SMichael Chan { 893c0c050c5SMichael Chan int rc = 0; 894c0c050c5SMichael Chan u16 code_type; 895c0c050c5SMichael Chan u32 stored_crc; 896c0c050c5SMichael Chan u32 calculated_crc; 897c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 898c0c050c5SMichael Chan 899c0c050c5SMichael Chan switch (dir_type) { 900c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 901c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 902c0c050c5SMichael Chan code_type = CODE_BOOT; 903c0c050c5SMichael Chan break; 9042731d70fSRob Swindell case BNX_DIR_TYPE_APE_FW: 9052731d70fSRob Swindell code_type = CODE_MCTP_PASSTHRU; 9062731d70fSRob Swindell break; 907c0c050c5SMichael Chan default: 908c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 909c0c050c5SMichael Chan dir_type); 910c0c050c5SMichael Chan return -EINVAL; 911c0c050c5SMichael Chan } 912c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 913c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 914c0c050c5SMichael Chan (unsigned int)fw_size); 915c0c050c5SMichael Chan return -EINVAL; 916c0c050c5SMichael Chan } 917c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 918c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 919c0c050c5SMichael Chan le32_to_cpu(header->signature)); 920c0c050c5SMichael Chan return -EINVAL; 921c0c050c5SMichael Chan } 922c0c050c5SMichael Chan if (header->code_type != code_type) { 923c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 924c0c050c5SMichael Chan code_type, header->code_type); 925c0c050c5SMichael Chan return -EINVAL; 926c0c050c5SMichael Chan } 927c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 928c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 929c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 930c0c050c5SMichael Chan return -EINVAL; 931c0c050c5SMichael Chan } 932c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 933c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 934c0c050c5SMichael Chan sizeof(stored_crc))); 935c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 936c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 937c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 938c0c050c5SMichael Chan (unsigned long)stored_crc, 939c0c050c5SMichael Chan (unsigned long)calculated_crc); 940c0c050c5SMichael Chan return -EINVAL; 941c0c050c5SMichael Chan } 942c0c050c5SMichael Chan /* TODO: Validate digital signature (RSA-encrypted SHA-256 hash) here */ 943c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 944c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 945d2d6318cSRob Swindell if (rc == 0) /* Firmware update successful */ 946d2d6318cSRob Swindell rc = bnxt_firmware_reset(dev, dir_type); 947d2d6318cSRob Swindell 948c0c050c5SMichael Chan return rc; 949c0c050c5SMichael Chan } 950c0c050c5SMichael Chan 951c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 952c0c050c5SMichael Chan { 953c0c050c5SMichael Chan switch (dir_type) { 954c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 955c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 956c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 957c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 958c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 959c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 960c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 961c0c050c5SMichael Chan return true; 962c0c050c5SMichael Chan } 963c0c050c5SMichael Chan 964c0c050c5SMichael Chan return false; 965c0c050c5SMichael Chan } 966c0c050c5SMichael Chan 967c0c050c5SMichael Chan static bool bnxt_dir_type_is_unprotected_exec_format(u16 dir_type) 968c0c050c5SMichael Chan { 969c0c050c5SMichael Chan switch (dir_type) { 970c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 971c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 972c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 973c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 974c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 975c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 976c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 977c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 978c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 979c0c050c5SMichael Chan return true; 980c0c050c5SMichael Chan } 981c0c050c5SMichael Chan 982c0c050c5SMichael Chan return false; 983c0c050c5SMichael Chan } 984c0c050c5SMichael Chan 985c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 986c0c050c5SMichael Chan { 987c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 988c0c050c5SMichael Chan bnxt_dir_type_is_unprotected_exec_format(dir_type); 989c0c050c5SMichael Chan } 990c0c050c5SMichael Chan 991c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 992c0c050c5SMichael Chan u16 dir_type, 993c0c050c5SMichael Chan const char *filename) 994c0c050c5SMichael Chan { 995c0c050c5SMichael Chan const struct firmware *fw; 996c0c050c5SMichael Chan int rc; 997c0c050c5SMichael Chan 998c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(dir_type) == false) 999c0c050c5SMichael Chan return -EINVAL; 1000c0c050c5SMichael Chan 1001c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 1002c0c050c5SMichael Chan if (rc != 0) { 1003c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 1004c0c050c5SMichael Chan rc, filename); 1005c0c050c5SMichael Chan return rc; 1006c0c050c5SMichael Chan } 1007c0c050c5SMichael Chan if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) 1008c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 1009c0c050c5SMichael Chan else 1010c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 1011c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 1012c0c050c5SMichael Chan release_firmware(fw); 1013c0c050c5SMichael Chan return rc; 1014c0c050c5SMichael Chan } 1015c0c050c5SMichael Chan 1016c0c050c5SMichael Chan static int bnxt_flash_package_from_file(struct net_device *dev, 1017c0c050c5SMichael Chan char *filename) 1018c0c050c5SMichael Chan { 1019c0c050c5SMichael Chan netdev_err(dev, "packages are not yet supported\n"); 1020c0c050c5SMichael Chan return -EINVAL; 1021c0c050c5SMichael Chan } 1022c0c050c5SMichael Chan 1023c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 1024c0c050c5SMichael Chan struct ethtool_flash *flash) 1025c0c050c5SMichael Chan { 1026c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 1027c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 1028c0c050c5SMichael Chan return -EINVAL; 1029c0c050c5SMichael Chan } 1030c0c050c5SMichael Chan 1031c0c050c5SMichael Chan if (flash->region == ETHTOOL_FLASH_ALL_REGIONS) 1032c0c050c5SMichael Chan return bnxt_flash_package_from_file(dev, flash->data); 1033c0c050c5SMichael Chan 1034c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 1035c0c050c5SMichael Chan } 1036c0c050c5SMichael Chan 1037c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 1038c0c050c5SMichael Chan { 1039c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1040c0c050c5SMichael Chan int rc; 1041c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 1042c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 1043c0c050c5SMichael Chan 1044c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 1045c0c050c5SMichael Chan 1046c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 1047c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1048c0c050c5SMichael Chan if (!rc) { 1049c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 1050c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 1051c0c050c5SMichael Chan } 1052c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 1053c0c050c5SMichael Chan return rc; 1054c0c050c5SMichael Chan } 1055c0c050c5SMichael Chan 1056c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 1057c0c050c5SMichael Chan { 1058c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 1059c0c050c5SMichael Chan * passed via the ethtool command-line utility. 1060c0c050c5SMichael Chan */ 1061c0c050c5SMichael Chan return -1; 1062c0c050c5SMichael Chan } 1063c0c050c5SMichael Chan 1064c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 1065c0c050c5SMichael Chan { 1066c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1067c0c050c5SMichael Chan int rc; 1068c0c050c5SMichael Chan u32 dir_entries; 1069c0c050c5SMichael Chan u32 entry_length; 1070c0c050c5SMichael Chan u8 *buf; 1071c0c050c5SMichael Chan size_t buflen; 1072c0c050c5SMichael Chan dma_addr_t dma_handle; 1073c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 1074c0c050c5SMichael Chan 1075c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 1076c0c050c5SMichael Chan if (rc != 0) 1077c0c050c5SMichael Chan return rc; 1078c0c050c5SMichael Chan 1079c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 1080c0c050c5SMichael Chan if (len < 2) 1081c0c050c5SMichael Chan return -EINVAL; 1082c0c050c5SMichael Chan 1083c0c050c5SMichael Chan *data++ = dir_entries; 1084c0c050c5SMichael Chan *data++ = entry_length; 1085c0c050c5SMichael Chan len -= 2; 1086c0c050c5SMichael Chan memset(data, 0xff, len); 1087c0c050c5SMichael Chan 1088c0c050c5SMichael Chan buflen = dir_entries * entry_length; 1089c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 1090c0c050c5SMichael Chan GFP_KERNEL); 1091c0c050c5SMichael Chan if (!buf) { 1092c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1093c0c050c5SMichael Chan (unsigned)buflen); 1094c0c050c5SMichael Chan return -ENOMEM; 1095c0c050c5SMichael Chan } 1096c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 1097c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 1098c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1099c0c050c5SMichael Chan if (rc == 0) 1100c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 1101c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 1102c0c050c5SMichael Chan return rc; 1103c0c050c5SMichael Chan } 1104c0c050c5SMichael Chan 1105c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 1106c0c050c5SMichael Chan u32 length, u8 *data) 1107c0c050c5SMichael Chan { 1108c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1109c0c050c5SMichael Chan int rc; 1110c0c050c5SMichael Chan u8 *buf; 1111c0c050c5SMichael Chan dma_addr_t dma_handle; 1112c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 1113c0c050c5SMichael Chan 1114c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 1115c0c050c5SMichael Chan GFP_KERNEL); 1116c0c050c5SMichael Chan if (!buf) { 1117c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1118c0c050c5SMichael Chan (unsigned)length); 1119c0c050c5SMichael Chan return -ENOMEM; 1120c0c050c5SMichael Chan } 1121c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 1122c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 1123c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 1124c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 1125c0c050c5SMichael Chan req.len = cpu_to_le32(length); 1126c0c050c5SMichael Chan 1127c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1128c0c050c5SMichael Chan if (rc == 0) 1129c0c050c5SMichael Chan memcpy(data, buf, length); 1130c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 1131c0c050c5SMichael Chan return rc; 1132c0c050c5SMichael Chan } 1133c0c050c5SMichael Chan 11343ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 11353ebf6f0aSRob Swindell u16 ext, u16 *index, u32 *item_length, 11363ebf6f0aSRob Swindell u32 *data_length) 11373ebf6f0aSRob Swindell { 11383ebf6f0aSRob Swindell struct bnxt *bp = netdev_priv(dev); 11393ebf6f0aSRob Swindell int rc; 11403ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_input req = {0}; 11413ebf6f0aSRob Swindell struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr; 11423ebf6f0aSRob Swindell 11433ebf6f0aSRob Swindell bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1); 11443ebf6f0aSRob Swindell req.enables = 0; 11453ebf6f0aSRob Swindell req.dir_idx = 0; 11463ebf6f0aSRob Swindell req.dir_type = cpu_to_le16(type); 11473ebf6f0aSRob Swindell req.dir_ordinal = cpu_to_le16(ordinal); 11483ebf6f0aSRob Swindell req.dir_ext = cpu_to_le16(ext); 11493ebf6f0aSRob Swindell req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ; 115090e20921SMichael Chan rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 11513ebf6f0aSRob Swindell if (rc == 0) { 11523ebf6f0aSRob Swindell if (index) 11533ebf6f0aSRob Swindell *index = le16_to_cpu(output->dir_idx); 11543ebf6f0aSRob Swindell if (item_length) 11553ebf6f0aSRob Swindell *item_length = le32_to_cpu(output->dir_item_length); 11563ebf6f0aSRob Swindell if (data_length) 11573ebf6f0aSRob Swindell *data_length = le32_to_cpu(output->dir_data_length); 11583ebf6f0aSRob Swindell } 11593ebf6f0aSRob Swindell return rc; 11603ebf6f0aSRob Swindell } 11613ebf6f0aSRob Swindell 11623ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen) 11633ebf6f0aSRob Swindell { 11643ebf6f0aSRob Swindell char *retval = NULL; 11653ebf6f0aSRob Swindell char *p; 11663ebf6f0aSRob Swindell char *value; 11673ebf6f0aSRob Swindell int field = 0; 11683ebf6f0aSRob Swindell 11693ebf6f0aSRob Swindell if (datalen < 1) 11703ebf6f0aSRob Swindell return NULL; 11713ebf6f0aSRob Swindell /* null-terminate the log data (removing last '\n'): */ 11723ebf6f0aSRob Swindell data[datalen - 1] = 0; 11733ebf6f0aSRob Swindell for (p = data; *p != 0; p++) { 11743ebf6f0aSRob Swindell field = 0; 11753ebf6f0aSRob Swindell retval = NULL; 11763ebf6f0aSRob Swindell while (*p != 0 && *p != '\n') { 11773ebf6f0aSRob Swindell value = p; 11783ebf6f0aSRob Swindell while (*p != 0 && *p != '\t' && *p != '\n') 11793ebf6f0aSRob Swindell p++; 11803ebf6f0aSRob Swindell if (field == desired_field) 11813ebf6f0aSRob Swindell retval = value; 11823ebf6f0aSRob Swindell if (*p != '\t') 11833ebf6f0aSRob Swindell break; 11843ebf6f0aSRob Swindell *p = 0; 11853ebf6f0aSRob Swindell field++; 11863ebf6f0aSRob Swindell p++; 11873ebf6f0aSRob Swindell } 11883ebf6f0aSRob Swindell if (*p == 0) 11893ebf6f0aSRob Swindell break; 11903ebf6f0aSRob Swindell *p = 0; 11913ebf6f0aSRob Swindell } 11923ebf6f0aSRob Swindell return retval; 11933ebf6f0aSRob Swindell } 11943ebf6f0aSRob Swindell 11953ebf6f0aSRob Swindell static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen) 11963ebf6f0aSRob Swindell { 11973ebf6f0aSRob Swindell u16 index = 0; 11983ebf6f0aSRob Swindell u32 datalen; 11993ebf6f0aSRob Swindell 12003ebf6f0aSRob Swindell if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG, 12013ebf6f0aSRob Swindell BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, 12023ebf6f0aSRob Swindell &index, NULL, &datalen) != 0) 12033ebf6f0aSRob Swindell return NULL; 12043ebf6f0aSRob Swindell 12053ebf6f0aSRob Swindell memset(buf, 0, buflen); 12063ebf6f0aSRob Swindell if (bnxt_get_nvram_item(dev, index, 0, datalen, buf) != 0) 12073ebf6f0aSRob Swindell return NULL; 12083ebf6f0aSRob Swindell 12093ebf6f0aSRob Swindell return bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, buf, 12103ebf6f0aSRob Swindell datalen); 12113ebf6f0aSRob Swindell } 12123ebf6f0aSRob Swindell 1213c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 1214c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 1215c0c050c5SMichael Chan u8 *data) 1216c0c050c5SMichael Chan { 1217c0c050c5SMichael Chan u32 index; 1218c0c050c5SMichael Chan u32 offset; 1219c0c050c5SMichael Chan 1220c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 1221c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 1222c0c050c5SMichael Chan 1223c0c050c5SMichael Chan index = eeprom->offset >> 24; 1224c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 1225c0c050c5SMichael Chan 1226c0c050c5SMichael Chan if (index == 0) { 1227c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 1228c0c050c5SMichael Chan return -EINVAL; 1229c0c050c5SMichael Chan } 1230c0c050c5SMichael Chan 1231c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 1232c0c050c5SMichael Chan } 1233c0c050c5SMichael Chan 1234c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 1235c0c050c5SMichael Chan { 1236c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1237c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 1238c0c050c5SMichael Chan 1239c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 1240c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 1241c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1242c0c050c5SMichael Chan } 1243c0c050c5SMichael Chan 1244c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 1245c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 1246c0c050c5SMichael Chan u8 *data) 1247c0c050c5SMichael Chan { 1248c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1249c0c050c5SMichael Chan u8 index, dir_op; 1250c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 1251c0c050c5SMichael Chan 1252c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 1253c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 1254c0c050c5SMichael Chan return -EINVAL; 1255c0c050c5SMichael Chan } 1256c0c050c5SMichael Chan 1257c0c050c5SMichael Chan type = eeprom->magic >> 16; 1258c0c050c5SMichael Chan 1259c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 1260c0c050c5SMichael Chan index = eeprom->magic & 0xff; 1261c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 1262c0c050c5SMichael Chan if (index == 0) 1263c0c050c5SMichael Chan return -EINVAL; 1264c0c050c5SMichael Chan switch (dir_op) { 1265c0c050c5SMichael Chan case 0x0e: /* erase */ 1266c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 1267c0c050c5SMichael Chan return -EINVAL; 1268c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 1269c0c050c5SMichael Chan default: 1270c0c050c5SMichael Chan return -EINVAL; 1271c0c050c5SMichael Chan } 1272c0c050c5SMichael Chan } 1273c0c050c5SMichael Chan 1274c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 1275c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(type) == true) 1276c0c050c5SMichael Chan return -EINVAL; 1277c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 1278c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 1279c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 1280c0c050c5SMichael Chan 1281c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 1282c0c050c5SMichael Chan eeprom->len); 1283c0c050c5SMichael Chan } 1284c0c050c5SMichael Chan 1285c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 1286c0c050c5SMichael Chan .get_settings = bnxt_get_settings, 1287c0c050c5SMichael Chan .set_settings = bnxt_set_settings, 1288c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 1289c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 1290c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 1291c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 1292c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 1293c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 1294c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 1295c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 1296c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 1297c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 1298c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 1299c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 1300c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 1301c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 1302c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 1303c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 1304c0c050c5SMichael Chan #endif 1305c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 1306c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 1307c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 1308c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 1309c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 1310c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 1311c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 1312c0c050c5SMichael Chan .get_link = bnxt_get_link, 1313c0c050c5SMichael Chan }; 1314