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