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 214c0c050c5SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings); 215c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 216c0c050c5SMichael Chan if (tcs > 1) 217c0c050c5SMichael Chan max_tx_rings /= tcs; 218c0c050c5SMichael Chan 219c0c050c5SMichael Chan channel->max_rx = max_rx_rings; 220c0c050c5SMichael Chan channel->max_tx = max_tx_rings; 221c0c050c5SMichael Chan channel->max_other = 0; 222c0c050c5SMichael Chan channel->max_combined = 0; 223c0c050c5SMichael Chan channel->rx_count = bp->rx_nr_rings; 224c0c050c5SMichael Chan channel->tx_count = bp->tx_nr_rings_per_tc; 225c0c050c5SMichael Chan } 226c0c050c5SMichael Chan 227c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev, 228c0c050c5SMichael Chan struct ethtool_channels *channel) 229c0c050c5SMichael Chan { 230c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 231c0c050c5SMichael Chan int max_rx_rings, max_tx_rings, tcs; 232c0c050c5SMichael Chan u32 rc = 0; 233c0c050c5SMichael Chan 234c0c050c5SMichael Chan if (channel->other_count || channel->combined_count || 235c0c050c5SMichael Chan !channel->rx_count || !channel->tx_count) 236c0c050c5SMichael Chan return -EINVAL; 237c0c050c5SMichael Chan 238c0c050c5SMichael Chan bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings); 239c0c050c5SMichael Chan tcs = netdev_get_num_tc(dev); 240c0c050c5SMichael Chan if (tcs > 1) 241c0c050c5SMichael Chan max_tx_rings /= tcs; 242c0c050c5SMichael Chan 243c0c050c5SMichael Chan if (channel->rx_count > max_rx_rings || 244c0c050c5SMichael Chan channel->tx_count > max_tx_rings) 245c0c050c5SMichael Chan return -EINVAL; 246c0c050c5SMichael Chan 247c0c050c5SMichael Chan if (netif_running(dev)) { 248c0c050c5SMichael Chan if (BNXT_PF(bp)) { 249c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 250c0c050c5SMichael Chan * before PF unload 251c0c050c5SMichael Chan */ 252c0c050c5SMichael Chan } 253c0c050c5SMichael Chan rc = bnxt_close_nic(bp, true, false); 254c0c050c5SMichael Chan if (rc) { 255c0c050c5SMichael Chan netdev_err(bp->dev, "Set channel failure rc :%x\n", 256c0c050c5SMichael Chan rc); 257c0c050c5SMichael Chan return rc; 258c0c050c5SMichael Chan } 259c0c050c5SMichael Chan } 260c0c050c5SMichael Chan 261c0c050c5SMichael Chan bp->rx_nr_rings = channel->rx_count; 262c0c050c5SMichael Chan bp->tx_nr_rings_per_tc = channel->tx_count; 263c0c050c5SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc; 264c0c050c5SMichael Chan if (tcs > 1) 265c0c050c5SMichael Chan bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs; 266c0c050c5SMichael Chan bp->cp_nr_rings = max_t(int, bp->tx_nr_rings, bp->rx_nr_rings); 267c0c050c5SMichael Chan bp->num_stat_ctxs = bp->cp_nr_rings; 268c0c050c5SMichael Chan 269c0c050c5SMichael Chan if (netif_running(dev)) { 270c0c050c5SMichael Chan rc = bnxt_open_nic(bp, true, false); 271c0c050c5SMichael Chan if ((!rc) && BNXT_PF(bp)) { 272c0c050c5SMichael Chan /* TODO CHIMP_FW: Send message to all VF's 273c0c050c5SMichael Chan * to renable 274c0c050c5SMichael Chan */ 275c0c050c5SMichael Chan } 276c0c050c5SMichael Chan } 277c0c050c5SMichael Chan 278c0c050c5SMichael Chan return rc; 279c0c050c5SMichael Chan } 280c0c050c5SMichael Chan 281c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 282c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, 283c0c050c5SMichael Chan u32 *rule_locs) 284c0c050c5SMichael Chan { 285c0c050c5SMichael Chan int i, j = 0; 286c0c050c5SMichael Chan 287c0c050c5SMichael Chan cmd->data = bp->ntp_fltr_count; 288c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 289c0c050c5SMichael Chan struct hlist_head *head; 290c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 291c0c050c5SMichael Chan 292c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 293c0c050c5SMichael Chan rcu_read_lock(); 294c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 295c0c050c5SMichael Chan if (j == cmd->rule_cnt) 296c0c050c5SMichael Chan break; 297c0c050c5SMichael Chan rule_locs[j++] = fltr->sw_id; 298c0c050c5SMichael Chan } 299c0c050c5SMichael Chan rcu_read_unlock(); 300c0c050c5SMichael Chan if (j == cmd->rule_cnt) 301c0c050c5SMichael Chan break; 302c0c050c5SMichael Chan } 303c0c050c5SMichael Chan cmd->rule_cnt = j; 304c0c050c5SMichael Chan return 0; 305c0c050c5SMichael Chan } 306c0c050c5SMichael Chan 307c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) 308c0c050c5SMichael Chan { 309c0c050c5SMichael Chan struct ethtool_rx_flow_spec *fs = 310c0c050c5SMichael Chan (struct ethtool_rx_flow_spec *)&cmd->fs; 311c0c050c5SMichael Chan struct bnxt_ntuple_filter *fltr; 312c0c050c5SMichael Chan struct flow_keys *fkeys; 313c0c050c5SMichael Chan int i, rc = -EINVAL; 314c0c050c5SMichael Chan 315c0c050c5SMichael Chan if (fs->location < 0 || fs->location >= BNXT_NTP_FLTR_MAX_FLTR) 316c0c050c5SMichael Chan return rc; 317c0c050c5SMichael Chan 318c0c050c5SMichael Chan for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { 319c0c050c5SMichael Chan struct hlist_head *head; 320c0c050c5SMichael Chan 321c0c050c5SMichael Chan head = &bp->ntp_fltr_hash_tbl[i]; 322c0c050c5SMichael Chan rcu_read_lock(); 323c0c050c5SMichael Chan hlist_for_each_entry_rcu(fltr, head, hash) { 324c0c050c5SMichael Chan if (fltr->sw_id == fs->location) 325c0c050c5SMichael Chan goto fltr_found; 326c0c050c5SMichael Chan } 327c0c050c5SMichael Chan rcu_read_unlock(); 328c0c050c5SMichael Chan } 329c0c050c5SMichael Chan return rc; 330c0c050c5SMichael Chan 331c0c050c5SMichael Chan fltr_found: 332c0c050c5SMichael Chan fkeys = &fltr->fkeys; 333c0c050c5SMichael Chan if (fkeys->basic.ip_proto == IPPROTO_TCP) 334c0c050c5SMichael Chan fs->flow_type = TCP_V4_FLOW; 335c0c050c5SMichael Chan else if (fkeys->basic.ip_proto == IPPROTO_UDP) 336c0c050c5SMichael Chan fs->flow_type = UDP_V4_FLOW; 337c0c050c5SMichael Chan else 338c0c050c5SMichael Chan goto fltr_err; 339c0c050c5SMichael Chan 340c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; 341c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); 342c0c050c5SMichael Chan 343c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; 344c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); 345c0c050c5SMichael Chan 346c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; 347c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); 348c0c050c5SMichael Chan 349c0c050c5SMichael Chan fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; 350c0c050c5SMichael Chan fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); 351c0c050c5SMichael Chan 352c0c050c5SMichael Chan fs->ring_cookie = fltr->rxq; 353c0c050c5SMichael Chan rc = 0; 354c0c050c5SMichael Chan 355c0c050c5SMichael Chan fltr_err: 356c0c050c5SMichael Chan rcu_read_unlock(); 357c0c050c5SMichael Chan 358c0c050c5SMichael Chan return rc; 359c0c050c5SMichael Chan } 360c0c050c5SMichael Chan 361c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 362c0c050c5SMichael Chan u32 *rule_locs) 363c0c050c5SMichael Chan { 364c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 365c0c050c5SMichael Chan int rc = 0; 366c0c050c5SMichael Chan 367c0c050c5SMichael Chan switch (cmd->cmd) { 368c0c050c5SMichael Chan case ETHTOOL_GRXRINGS: 369c0c050c5SMichael Chan cmd->data = bp->rx_nr_rings; 370c0c050c5SMichael Chan break; 371c0c050c5SMichael Chan 372c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLCNT: 373c0c050c5SMichael Chan cmd->rule_cnt = bp->ntp_fltr_count; 374c0c050c5SMichael Chan cmd->data = BNXT_NTP_FLTR_MAX_FLTR; 375c0c050c5SMichael Chan break; 376c0c050c5SMichael Chan 377c0c050c5SMichael Chan case ETHTOOL_GRXCLSRLALL: 378c0c050c5SMichael Chan rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); 379c0c050c5SMichael Chan break; 380c0c050c5SMichael Chan 381c0c050c5SMichael Chan case ETHTOOL_GRXCLSRULE: 382c0c050c5SMichael Chan rc = bnxt_grxclsrule(bp, cmd); 383c0c050c5SMichael Chan break; 384c0c050c5SMichael Chan 385c0c050c5SMichael Chan default: 386c0c050c5SMichael Chan rc = -EOPNOTSUPP; 387c0c050c5SMichael Chan break; 388c0c050c5SMichael Chan } 389c0c050c5SMichael Chan 390c0c050c5SMichael Chan return rc; 391c0c050c5SMichael Chan } 392c0c050c5SMichael Chan #endif 393c0c050c5SMichael Chan 394c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) 395c0c050c5SMichael Chan { 396c0c050c5SMichael Chan return HW_HASH_INDEX_SIZE; 397c0c050c5SMichael Chan } 398c0c050c5SMichael Chan 399c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev) 400c0c050c5SMichael Chan { 401c0c050c5SMichael Chan return HW_HASH_KEY_SIZE; 402c0c050c5SMichael Chan } 403c0c050c5SMichael Chan 404c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, 405c0c050c5SMichael Chan u8 *hfunc) 406c0c050c5SMichael Chan { 407c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 408c0c050c5SMichael Chan struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; 409c0c050c5SMichael Chan int i = 0; 410c0c050c5SMichael Chan 411c0c050c5SMichael Chan if (hfunc) 412c0c050c5SMichael Chan *hfunc = ETH_RSS_HASH_TOP; 413c0c050c5SMichael Chan 414c0c050c5SMichael Chan if (indir) 415c0c050c5SMichael Chan for (i = 0; i < HW_HASH_INDEX_SIZE; i++) 416c0c050c5SMichael Chan indir[i] = le16_to_cpu(vnic->rss_table[i]); 417c0c050c5SMichael Chan 418c0c050c5SMichael Chan if (key) 419c0c050c5SMichael Chan memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); 420c0c050c5SMichael Chan 421c0c050c5SMichael Chan return 0; 422c0c050c5SMichael Chan } 423c0c050c5SMichael Chan 424c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev, 425c0c050c5SMichael Chan struct ethtool_drvinfo *info) 426c0c050c5SMichael Chan { 427c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 428c0c050c5SMichael Chan 429c0c050c5SMichael Chan strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); 430c0c050c5SMichael Chan strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); 431c0c050c5SMichael Chan strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); 432c0c050c5SMichael Chan strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); 433c0c050c5SMichael Chan info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings; 434c0c050c5SMichael Chan info->testinfo_len = BNXT_NUM_TESTS(bp); 435c0c050c5SMichael Chan /* TODO CHIMP_FW: eeprom dump details */ 436c0c050c5SMichael Chan info->eedump_len = 0; 437c0c050c5SMichael Chan /* TODO CHIMP FW: reg dump details */ 438c0c050c5SMichael Chan info->regdump_len = 0; 439c0c050c5SMichael Chan } 440c0c050c5SMichael Chan 441c0c050c5SMichael Chan static u32 bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info) 442c0c050c5SMichael Chan { 443c0c050c5SMichael Chan u16 fw_speeds = link_info->support_speeds; 444c0c050c5SMichael Chan u32 speed_mask = 0; 445c0c050c5SMichael Chan 446c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 447c0c050c5SMichael Chan speed_mask |= SUPPORTED_100baseT_Full; 448c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 449c0c050c5SMichael Chan speed_mask |= SUPPORTED_1000baseT_Full; 450c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 451c0c050c5SMichael Chan speed_mask |= SUPPORTED_2500baseX_Full; 452c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 453c0c050c5SMichael Chan speed_mask |= SUPPORTED_10000baseT_Full; 454c0c050c5SMichael Chan /* TODO: support 25GB, 50GB with different cable type */ 455c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_20GB) 456c0c050c5SMichael Chan speed_mask |= SUPPORTED_20000baseMLD2_Full | 457c0c050c5SMichael Chan SUPPORTED_20000baseKR2_Full; 458c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 459c0c050c5SMichael Chan speed_mask |= SUPPORTED_40000baseKR4_Full | 460c0c050c5SMichael Chan SUPPORTED_40000baseCR4_Full | 461c0c050c5SMichael Chan SUPPORTED_40000baseSR4_Full | 462c0c050c5SMichael Chan SUPPORTED_40000baseLR4_Full; 463c0c050c5SMichael Chan 464c0c050c5SMichael Chan return speed_mask; 465c0c050c5SMichael Chan } 466c0c050c5SMichael Chan 467c0c050c5SMichael Chan static u32 bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info) 468c0c050c5SMichael Chan { 469c0c050c5SMichael Chan u16 fw_speeds = link_info->auto_link_speeds; 470c0c050c5SMichael Chan u32 speed_mask = 0; 471c0c050c5SMichael Chan 472c0c050c5SMichael Chan /* TODO: support 25GB, 40GB, 50GB with different cable type */ 473c0c050c5SMichael Chan /* set the advertised speeds */ 474c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) 475c0c050c5SMichael Chan speed_mask |= ADVERTISED_100baseT_Full; 476c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) 477c0c050c5SMichael Chan speed_mask |= ADVERTISED_1000baseT_Full; 478c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) 479c0c050c5SMichael Chan speed_mask |= ADVERTISED_2500baseX_Full; 480c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) 481c0c050c5SMichael Chan speed_mask |= ADVERTISED_10000baseT_Full; 482c0c050c5SMichael Chan /* TODO: how to advertise 20, 25, 40, 50GB with different cable type ?*/ 483c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_20GB) 484c0c050c5SMichael Chan speed_mask |= ADVERTISED_20000baseMLD2_Full | 485c0c050c5SMichael Chan ADVERTISED_20000baseKR2_Full; 486c0c050c5SMichael Chan if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) 487c0c050c5SMichael Chan speed_mask |= ADVERTISED_40000baseKR4_Full | 488c0c050c5SMichael Chan ADVERTISED_40000baseCR4_Full | 489c0c050c5SMichael Chan ADVERTISED_40000baseSR4_Full | 490c0c050c5SMichael Chan ADVERTISED_40000baseLR4_Full; 491c0c050c5SMichael Chan return speed_mask; 492c0c050c5SMichael Chan } 493c0c050c5SMichael Chan 494c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) 495c0c050c5SMichael Chan { 496c0c050c5SMichael Chan switch (fw_link_speed) { 497c0c050c5SMichael Chan case BNXT_LINK_SPEED_100MB: 498c0c050c5SMichael Chan return SPEED_100; 499c0c050c5SMichael Chan case BNXT_LINK_SPEED_1GB: 500c0c050c5SMichael Chan return SPEED_1000; 501c0c050c5SMichael Chan case BNXT_LINK_SPEED_2_5GB: 502c0c050c5SMichael Chan return SPEED_2500; 503c0c050c5SMichael Chan case BNXT_LINK_SPEED_10GB: 504c0c050c5SMichael Chan return SPEED_10000; 505c0c050c5SMichael Chan case BNXT_LINK_SPEED_20GB: 506c0c050c5SMichael Chan return SPEED_20000; 507c0c050c5SMichael Chan case BNXT_LINK_SPEED_25GB: 508c0c050c5SMichael Chan return SPEED_25000; 509c0c050c5SMichael Chan case BNXT_LINK_SPEED_40GB: 510c0c050c5SMichael Chan return SPEED_40000; 511c0c050c5SMichael Chan case BNXT_LINK_SPEED_50GB: 512c0c050c5SMichael Chan return SPEED_50000; 513c0c050c5SMichael Chan default: 514c0c050c5SMichael Chan return SPEED_UNKNOWN; 515c0c050c5SMichael Chan } 516c0c050c5SMichael Chan } 517c0c050c5SMichael Chan 518c0c050c5SMichael Chan static int bnxt_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 519c0c050c5SMichael Chan { 520c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 521c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 522c0c050c5SMichael Chan u16 ethtool_speed; 523c0c050c5SMichael Chan 524c0c050c5SMichael Chan cmd->supported = bnxt_fw_to_ethtool_support_spds(link_info); 525c0c050c5SMichael Chan 526c0c050c5SMichael Chan if (link_info->auto_link_speeds) 527c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Autoneg; 528c0c050c5SMichael Chan 529c0c050c5SMichael Chan if (BNXT_AUTO_MODE(link_info->auto_mode)) { 530c0c050c5SMichael Chan cmd->advertising = 531c0c050c5SMichael Chan bnxt_fw_to_ethtool_advertised_spds(link_info); 532c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Autoneg; 533c0c050c5SMichael Chan cmd->autoneg = AUTONEG_ENABLE; 534c0c050c5SMichael Chan } else { 535c0c050c5SMichael Chan cmd->autoneg = AUTONEG_DISABLE; 536c0c050c5SMichael Chan cmd->advertising = 0; 537c0c050c5SMichael Chan } 538c0c050c5SMichael Chan if (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) { 539c0c050c5SMichael Chan if ((link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) == 540c0c050c5SMichael Chan BNXT_LINK_PAUSE_BOTH) { 541c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Pause; 542c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Pause; 543c0c050c5SMichael Chan } else { 544c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Asym_Pause; 545c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Asym_Pause; 546c0c050c5SMichael Chan if (link_info->auto_pause_setting & 547c0c050c5SMichael Chan BNXT_LINK_PAUSE_RX) 548c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_Pause; 549c0c050c5SMichael Chan } 550c0c050c5SMichael Chan } else if (link_info->force_pause_setting & BNXT_LINK_PAUSE_BOTH) { 551c0c050c5SMichael Chan if ((link_info->force_pause_setting & BNXT_LINK_PAUSE_BOTH) == 552c0c050c5SMichael Chan BNXT_LINK_PAUSE_BOTH) { 553c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Pause; 554c0c050c5SMichael Chan } else { 555c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Asym_Pause; 556c0c050c5SMichael Chan if (link_info->force_pause_setting & 557c0c050c5SMichael Chan BNXT_LINK_PAUSE_RX) 558c0c050c5SMichael Chan cmd->supported |= SUPPORTED_Pause; 559c0c050c5SMichael Chan } 560c0c050c5SMichael Chan } 561c0c050c5SMichael Chan 562c0c050c5SMichael Chan cmd->port = PORT_NONE; 563c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 564c0c050c5SMichael Chan cmd->port = PORT_TP; 565c0c050c5SMichael Chan cmd->supported |= SUPPORTED_TP; 566c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_TP; 567c0c050c5SMichael Chan } else { 568c0c050c5SMichael Chan cmd->supported |= SUPPORTED_FIBRE; 569c0c050c5SMichael Chan cmd->advertising |= ADVERTISED_FIBRE; 570c0c050c5SMichael Chan 571c0c050c5SMichael Chan if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) 572c0c050c5SMichael Chan cmd->port = PORT_DA; 573c0c050c5SMichael Chan else if (link_info->media_type == 574c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) 575c0c050c5SMichael Chan cmd->port = PORT_FIBRE; 576c0c050c5SMichael Chan } 577c0c050c5SMichael Chan 578c0c050c5SMichael Chan if (link_info->phy_link_status == BNXT_LINK_LINK) { 579c0c050c5SMichael Chan if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) 580c0c050c5SMichael Chan cmd->duplex = DUPLEX_FULL; 581c0c050c5SMichael Chan } else { 582c0c050c5SMichael Chan cmd->duplex = DUPLEX_UNKNOWN; 583c0c050c5SMichael Chan } 584c0c050c5SMichael Chan ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); 585c0c050c5SMichael Chan ethtool_cmd_speed_set(cmd, ethtool_speed); 586c0c050c5SMichael Chan if (link_info->transceiver == 587c0c050c5SMichael Chan PORT_PHY_QCFG_RESP_TRANSCEIVER_TYPE_XCVR_INTERNAL) 588c0c050c5SMichael Chan cmd->transceiver = XCVR_INTERNAL; 589c0c050c5SMichael Chan else 590c0c050c5SMichael Chan cmd->transceiver = XCVR_EXTERNAL; 591c0c050c5SMichael Chan cmd->phy_address = link_info->phy_addr; 592c0c050c5SMichael Chan 593c0c050c5SMichael Chan return 0; 594c0c050c5SMichael Chan } 595c0c050c5SMichael Chan 596c0c050c5SMichael Chan static u32 bnxt_get_fw_speed(struct net_device *dev, u16 ethtool_speed) 597c0c050c5SMichael Chan { 598c0c050c5SMichael Chan switch (ethtool_speed) { 599c0c050c5SMichael Chan case SPEED_100: 600c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; 601c0c050c5SMichael Chan case SPEED_1000: 602c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; 603c0c050c5SMichael Chan case SPEED_2500: 604c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; 605c0c050c5SMichael Chan case SPEED_10000: 606c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; 607c0c050c5SMichael Chan case SPEED_20000: 608c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; 609c0c050c5SMichael Chan case SPEED_25000: 610c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; 611c0c050c5SMichael Chan case SPEED_40000: 612c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; 613c0c050c5SMichael Chan case SPEED_50000: 614c0c050c5SMichael Chan return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; 615c0c050c5SMichael Chan default: 616c0c050c5SMichael Chan netdev_err(dev, "unsupported speed!\n"); 617c0c050c5SMichael Chan break; 618c0c050c5SMichael Chan } 619c0c050c5SMichael Chan return 0; 620c0c050c5SMichael Chan } 621c0c050c5SMichael Chan 622c0c050c5SMichael Chan static u16 bnxt_get_fw_auto_link_speeds(u32 advertising) 623c0c050c5SMichael Chan { 624c0c050c5SMichael Chan u16 fw_speed_mask = 0; 625c0c050c5SMichael Chan 626c0c050c5SMichael Chan /* only support autoneg at speed 100, 1000, and 10000 */ 627c0c050c5SMichael Chan if (advertising & (ADVERTISED_100baseT_Full | 628c0c050c5SMichael Chan ADVERTISED_100baseT_Half)) { 629c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; 630c0c050c5SMichael Chan } 631c0c050c5SMichael Chan if (advertising & (ADVERTISED_1000baseT_Full | 632c0c050c5SMichael Chan ADVERTISED_1000baseT_Half)) { 633c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; 634c0c050c5SMichael Chan } 635c0c050c5SMichael Chan if (advertising & ADVERTISED_10000baseT_Full) 636c0c050c5SMichael Chan fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; 637c0c050c5SMichael Chan 638c0c050c5SMichael Chan return fw_speed_mask; 639c0c050c5SMichael Chan } 640c0c050c5SMichael Chan 641c0c050c5SMichael Chan static int bnxt_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 642c0c050c5SMichael Chan { 643c0c050c5SMichael Chan int rc = 0; 644c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 645c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 646c0c050c5SMichael Chan u32 speed, fw_advertising = 0; 647c0c050c5SMichael Chan bool set_pause = false; 648c0c050c5SMichael Chan 649c0c050c5SMichael Chan if (BNXT_VF(bp)) 650c0c050c5SMichael Chan return rc; 651c0c050c5SMichael Chan 652c0c050c5SMichael Chan if (cmd->autoneg == AUTONEG_ENABLE) { 653c0c050c5SMichael Chan if (link_info->media_type != PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { 654c0c050c5SMichael Chan netdev_err(dev, "Media type doesn't support autoneg\n"); 655c0c050c5SMichael Chan rc = -EINVAL; 656c0c050c5SMichael Chan goto set_setting_exit; 657c0c050c5SMichael Chan } 658c0c050c5SMichael Chan if (cmd->advertising & ~(BNXT_ALL_COPPER_ETHTOOL_SPEED | 659c0c050c5SMichael Chan ADVERTISED_Autoneg | 660c0c050c5SMichael Chan ADVERTISED_TP | 661c0c050c5SMichael Chan ADVERTISED_Pause | 662c0c050c5SMichael Chan ADVERTISED_Asym_Pause)) { 663c0c050c5SMichael Chan netdev_err(dev, "Unsupported advertising mask (adv: 0x%x)\n", 664c0c050c5SMichael Chan cmd->advertising); 665c0c050c5SMichael Chan rc = -EINVAL; 666c0c050c5SMichael Chan goto set_setting_exit; 667c0c050c5SMichael Chan } 668c0c050c5SMichael Chan fw_advertising = bnxt_get_fw_auto_link_speeds(cmd->advertising); 669c0c050c5SMichael Chan if (fw_advertising & ~link_info->support_speeds) { 670c0c050c5SMichael Chan netdev_err(dev, "Advertising parameters are not supported! (adv: 0x%x)\n", 671c0c050c5SMichael Chan cmd->advertising); 672c0c050c5SMichael Chan rc = -EINVAL; 673c0c050c5SMichael Chan goto set_setting_exit; 674c0c050c5SMichael Chan } 675c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_SPEED; 676c0c050c5SMichael Chan if (!fw_advertising) 677c0c050c5SMichael Chan link_info->advertising = link_info->support_speeds; 678c0c050c5SMichael Chan else 679c0c050c5SMichael Chan link_info->advertising = fw_advertising; 680c0c050c5SMichael Chan /* any change to autoneg will cause link change, therefore the 681c0c050c5SMichael Chan * driver should put back the original pause setting in autoneg 682c0c050c5SMichael Chan */ 683c0c050c5SMichael Chan set_pause = true; 684c0c050c5SMichael Chan } else { 685c0c050c5SMichael Chan /* TODO: currently don't support half duplex */ 686c0c050c5SMichael Chan if (cmd->duplex == DUPLEX_HALF) { 687c0c050c5SMichael Chan netdev_err(dev, "HALF DUPLEX is not supported!\n"); 688c0c050c5SMichael Chan rc = -EINVAL; 689c0c050c5SMichael Chan goto set_setting_exit; 690c0c050c5SMichael Chan } 691c0c050c5SMichael Chan /* If received a request for an unknown duplex, assume full*/ 692c0c050c5SMichael Chan if (cmd->duplex == DUPLEX_UNKNOWN) 693c0c050c5SMichael Chan cmd->duplex = DUPLEX_FULL; 694c0c050c5SMichael Chan speed = ethtool_cmd_speed(cmd); 695c0c050c5SMichael Chan link_info->req_link_speed = bnxt_get_fw_speed(dev, speed); 696c0c050c5SMichael Chan link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; 697c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_SPEED; 698c0c050c5SMichael Chan link_info->advertising = 0; 699c0c050c5SMichael Chan } 700c0c050c5SMichael Chan 701c0c050c5SMichael Chan if (netif_running(dev)) 702c0c050c5SMichael Chan rc = bnxt_hwrm_set_link_setting(bp, set_pause); 703c0c050c5SMichael Chan 704c0c050c5SMichael Chan set_setting_exit: 705c0c050c5SMichael Chan return rc; 706c0c050c5SMichael Chan } 707c0c050c5SMichael Chan 708c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev, 709c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 710c0c050c5SMichael Chan { 711c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 712c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 713c0c050c5SMichael Chan 714c0c050c5SMichael Chan if (BNXT_VF(bp)) 715c0c050c5SMichael Chan return; 716c0c050c5SMichael Chan epause->autoneg = !!(link_info->auto_pause_setting & 717c0c050c5SMichael Chan BNXT_LINK_PAUSE_BOTH); 718c0c050c5SMichael Chan epause->rx_pause = ((link_info->pause & BNXT_LINK_PAUSE_RX) != 0); 719c0c050c5SMichael Chan epause->tx_pause = ((link_info->pause & BNXT_LINK_PAUSE_TX) != 0); 720c0c050c5SMichael Chan } 721c0c050c5SMichael Chan 722c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev, 723c0c050c5SMichael Chan struct ethtool_pauseparam *epause) 724c0c050c5SMichael Chan { 725c0c050c5SMichael Chan int rc = 0; 726c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 727c0c050c5SMichael Chan struct bnxt_link_info *link_info = &bp->link_info; 728c0c050c5SMichael Chan 729c0c050c5SMichael Chan if (BNXT_VF(bp)) 730c0c050c5SMichael Chan return rc; 731c0c050c5SMichael Chan 732c0c050c5SMichael Chan if (epause->autoneg) { 733c0c050c5SMichael Chan link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; 734c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_BOTH; 735c0c050c5SMichael Chan } else { 736c0c050c5SMichael Chan /* when transition from auto pause to force pause, 737c0c050c5SMichael Chan * force a link change 738c0c050c5SMichael Chan */ 739c0c050c5SMichael Chan if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) 740c0c050c5SMichael Chan link_info->force_link_chng = true; 741c0c050c5SMichael Chan link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; 742c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_BOTH; 743c0c050c5SMichael Chan } 744c0c050c5SMichael Chan if (epause->rx_pause) 745c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; 746c0c050c5SMichael Chan else 747c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_RX; 748c0c050c5SMichael Chan 749c0c050c5SMichael Chan if (epause->tx_pause) 750c0c050c5SMichael Chan link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; 751c0c050c5SMichael Chan else 752c0c050c5SMichael Chan link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_TX; 753c0c050c5SMichael Chan 754c0c050c5SMichael Chan if (netif_running(dev)) 755c0c050c5SMichael Chan rc = bnxt_hwrm_set_pause(bp); 756c0c050c5SMichael Chan return rc; 757c0c050c5SMichael Chan } 758c0c050c5SMichael Chan 759c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev) 760c0c050c5SMichael Chan { 761c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 762c0c050c5SMichael Chan 763c0c050c5SMichael Chan /* TODO: handle MF, VF, driver close case */ 764c0c050c5SMichael Chan return bp->link_info.link_up; 765c0c050c5SMichael Chan } 766c0c050c5SMichael Chan 767c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev, 768c0c050c5SMichael Chan u16 dir_type, 769c0c050c5SMichael Chan u16 dir_ordinal, 770c0c050c5SMichael Chan u16 dir_ext, 771c0c050c5SMichael Chan u16 dir_attr, 772c0c050c5SMichael Chan const u8 *data, 773c0c050c5SMichael Chan size_t data_len) 774c0c050c5SMichael Chan { 775c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 776c0c050c5SMichael Chan int rc; 777c0c050c5SMichael Chan struct hwrm_nvm_write_input req = {0}; 778c0c050c5SMichael Chan dma_addr_t dma_handle; 779c0c050c5SMichael Chan u8 *kmem; 780c0c050c5SMichael Chan 781c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); 782c0c050c5SMichael Chan 783c0c050c5SMichael Chan req.dir_type = cpu_to_le16(dir_type); 784c0c050c5SMichael Chan req.dir_ordinal = cpu_to_le16(dir_ordinal); 785c0c050c5SMichael Chan req.dir_ext = cpu_to_le16(dir_ext); 786c0c050c5SMichael Chan req.dir_attr = cpu_to_le16(dir_attr); 787c0c050c5SMichael Chan req.dir_data_length = cpu_to_le32(data_len); 788c0c050c5SMichael Chan 789c0c050c5SMichael Chan kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, 790c0c050c5SMichael Chan GFP_KERNEL); 791c0c050c5SMichael Chan if (!kmem) { 792c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 793c0c050c5SMichael Chan (unsigned)data_len); 794c0c050c5SMichael Chan return -ENOMEM; 795c0c050c5SMichael Chan } 796c0c050c5SMichael Chan memcpy(kmem, data, data_len); 797c0c050c5SMichael Chan req.host_src_addr = cpu_to_le64(dma_handle); 798c0c050c5SMichael Chan 799c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 800c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 801c0c050c5SMichael Chan 802c0c050c5SMichael Chan return rc; 803c0c050c5SMichael Chan } 804c0c050c5SMichael Chan 805c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev, 806c0c050c5SMichael Chan u16 dir_type, 807c0c050c5SMichael Chan const u8 *fw_data, 808c0c050c5SMichael Chan size_t fw_size) 809c0c050c5SMichael Chan { 810c0c050c5SMichael Chan int rc = 0; 811c0c050c5SMichael Chan u16 code_type; 812c0c050c5SMichael Chan u32 stored_crc; 813c0c050c5SMichael Chan u32 calculated_crc; 814c0c050c5SMichael Chan struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; 815c0c050c5SMichael Chan 816c0c050c5SMichael Chan switch (dir_type) { 817c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 818c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 819c0c050c5SMichael Chan code_type = CODE_BOOT; 820c0c050c5SMichael Chan break; 821c0c050c5SMichael Chan default: 822c0c050c5SMichael Chan netdev_err(dev, "Unsupported directory entry type: %u\n", 823c0c050c5SMichael Chan dir_type); 824c0c050c5SMichael Chan return -EINVAL; 825c0c050c5SMichael Chan } 826c0c050c5SMichael Chan if (fw_size < sizeof(struct bnxt_fw_header)) { 827c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware file size: %u\n", 828c0c050c5SMichael Chan (unsigned int)fw_size); 829c0c050c5SMichael Chan return -EINVAL; 830c0c050c5SMichael Chan } 831c0c050c5SMichael Chan if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { 832c0c050c5SMichael Chan netdev_err(dev, "Invalid firmware signature: %08X\n", 833c0c050c5SMichael Chan le32_to_cpu(header->signature)); 834c0c050c5SMichael Chan return -EINVAL; 835c0c050c5SMichael Chan } 836c0c050c5SMichael Chan if (header->code_type != code_type) { 837c0c050c5SMichael Chan netdev_err(dev, "Expected firmware type: %d, read: %d\n", 838c0c050c5SMichael Chan code_type, header->code_type); 839c0c050c5SMichael Chan return -EINVAL; 840c0c050c5SMichael Chan } 841c0c050c5SMichael Chan if (header->device != DEVICE_CUMULUS_FAMILY) { 842c0c050c5SMichael Chan netdev_err(dev, "Expected firmware device family %d, read: %d\n", 843c0c050c5SMichael Chan DEVICE_CUMULUS_FAMILY, header->device); 844c0c050c5SMichael Chan return -EINVAL; 845c0c050c5SMichael Chan } 846c0c050c5SMichael Chan /* Confirm the CRC32 checksum of the file: */ 847c0c050c5SMichael Chan stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - 848c0c050c5SMichael Chan sizeof(stored_crc))); 849c0c050c5SMichael Chan calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); 850c0c050c5SMichael Chan if (calculated_crc != stored_crc) { 851c0c050c5SMichael Chan netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", 852c0c050c5SMichael Chan (unsigned long)stored_crc, 853c0c050c5SMichael Chan (unsigned long)calculated_crc); 854c0c050c5SMichael Chan return -EINVAL; 855c0c050c5SMichael Chan } 856c0c050c5SMichael Chan /* TODO: Validate digital signature (RSA-encrypted SHA-256 hash) here */ 857c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 858c0c050c5SMichael Chan 0, 0, fw_data, fw_size); 859c0c050c5SMichael Chan if (rc == 0) { /* Firmware update successful */ 860c0c050c5SMichael Chan /* TODO: Notify processor it needs to reset itself 861c0c050c5SMichael Chan */ 862c0c050c5SMichael Chan } 863c0c050c5SMichael Chan return rc; 864c0c050c5SMichael Chan } 865c0c050c5SMichael Chan 866c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) 867c0c050c5SMichael Chan { 868c0c050c5SMichael Chan switch (dir_type) { 869c0c050c5SMichael Chan case BNX_DIR_TYPE_CHIMP_PATCH: 870c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE: 871c0c050c5SMichael Chan case BNX_DIR_TYPE_BOOTCODE_2: 872c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_FW: 873c0c050c5SMichael Chan case BNX_DIR_TYPE_APE_PATCH: 874c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_FW: 875c0c050c5SMichael Chan case BNX_DIR_TYPE_KONG_PATCH: 876c0c050c5SMichael Chan return true; 877c0c050c5SMichael Chan } 878c0c050c5SMichael Chan 879c0c050c5SMichael Chan return false; 880c0c050c5SMichael Chan } 881c0c050c5SMichael Chan 882c0c050c5SMichael Chan static bool bnxt_dir_type_is_unprotected_exec_format(u16 dir_type) 883c0c050c5SMichael Chan { 884c0c050c5SMichael Chan switch (dir_type) { 885c0c050c5SMichael Chan case BNX_DIR_TYPE_AVS: 886c0c050c5SMichael Chan case BNX_DIR_TYPE_EXP_ROM_MBA: 887c0c050c5SMichael Chan case BNX_DIR_TYPE_PCIE: 888c0c050c5SMichael Chan case BNX_DIR_TYPE_TSCF_UCODE: 889c0c050c5SMichael Chan case BNX_DIR_TYPE_EXT_PHY: 890c0c050c5SMichael Chan case BNX_DIR_TYPE_CCM: 891c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT: 892c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: 893c0c050c5SMichael Chan case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: 894c0c050c5SMichael Chan return true; 895c0c050c5SMichael Chan } 896c0c050c5SMichael Chan 897c0c050c5SMichael Chan return false; 898c0c050c5SMichael Chan } 899c0c050c5SMichael Chan 900c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type) 901c0c050c5SMichael Chan { 902c0c050c5SMichael Chan return bnxt_dir_type_is_ape_bin_format(dir_type) || 903c0c050c5SMichael Chan bnxt_dir_type_is_unprotected_exec_format(dir_type); 904c0c050c5SMichael Chan } 905c0c050c5SMichael Chan 906c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev, 907c0c050c5SMichael Chan u16 dir_type, 908c0c050c5SMichael Chan const char *filename) 909c0c050c5SMichael Chan { 910c0c050c5SMichael Chan const struct firmware *fw; 911c0c050c5SMichael Chan int rc; 912c0c050c5SMichael Chan 913c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(dir_type) == false) 914c0c050c5SMichael Chan return -EINVAL; 915c0c050c5SMichael Chan 916c0c050c5SMichael Chan rc = request_firmware(&fw, filename, &dev->dev); 917c0c050c5SMichael Chan if (rc != 0) { 918c0c050c5SMichael Chan netdev_err(dev, "Error %d requesting firmware file: %s\n", 919c0c050c5SMichael Chan rc, filename); 920c0c050c5SMichael Chan return rc; 921c0c050c5SMichael Chan } 922c0c050c5SMichael Chan if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) 923c0c050c5SMichael Chan rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); 924c0c050c5SMichael Chan else 925c0c050c5SMichael Chan rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, 926c0c050c5SMichael Chan 0, 0, fw->data, fw->size); 927c0c050c5SMichael Chan release_firmware(fw); 928c0c050c5SMichael Chan return rc; 929c0c050c5SMichael Chan } 930c0c050c5SMichael Chan 931c0c050c5SMichael Chan static int bnxt_flash_package_from_file(struct net_device *dev, 932c0c050c5SMichael Chan char *filename) 933c0c050c5SMichael Chan { 934c0c050c5SMichael Chan netdev_err(dev, "packages are not yet supported\n"); 935c0c050c5SMichael Chan return -EINVAL; 936c0c050c5SMichael Chan } 937c0c050c5SMichael Chan 938c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev, 939c0c050c5SMichael Chan struct ethtool_flash *flash) 940c0c050c5SMichael Chan { 941c0c050c5SMichael Chan if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { 942c0c050c5SMichael Chan netdev_err(dev, "flashdev not supported from a virtual function\n"); 943c0c050c5SMichael Chan return -EINVAL; 944c0c050c5SMichael Chan } 945c0c050c5SMichael Chan 946c0c050c5SMichael Chan if (flash->region == ETHTOOL_FLASH_ALL_REGIONS) 947c0c050c5SMichael Chan return bnxt_flash_package_from_file(dev, flash->data); 948c0c050c5SMichael Chan 949c0c050c5SMichael Chan return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); 950c0c050c5SMichael Chan } 951c0c050c5SMichael Chan 952c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) 953c0c050c5SMichael Chan { 954c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 955c0c050c5SMichael Chan int rc; 956c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_input req = {0}; 957c0c050c5SMichael Chan struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; 958c0c050c5SMichael Chan 959c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); 960c0c050c5SMichael Chan 961c0c050c5SMichael Chan mutex_lock(&bp->hwrm_cmd_lock); 962c0c050c5SMichael Chan rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 963c0c050c5SMichael Chan if (!rc) { 964c0c050c5SMichael Chan *entries = le32_to_cpu(output->entries); 965c0c050c5SMichael Chan *length = le32_to_cpu(output->entry_length); 966c0c050c5SMichael Chan } 967c0c050c5SMichael Chan mutex_unlock(&bp->hwrm_cmd_lock); 968c0c050c5SMichael Chan return rc; 969c0c050c5SMichael Chan } 970c0c050c5SMichael Chan 971c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev) 972c0c050c5SMichael Chan { 973c0c050c5SMichael Chan /* The -1 return value allows the entire 32-bit range of offsets to be 974c0c050c5SMichael Chan * passed via the ethtool command-line utility. 975c0c050c5SMichael Chan */ 976c0c050c5SMichael Chan return -1; 977c0c050c5SMichael Chan } 978c0c050c5SMichael Chan 979c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) 980c0c050c5SMichael Chan { 981c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 982c0c050c5SMichael Chan int rc; 983c0c050c5SMichael Chan u32 dir_entries; 984c0c050c5SMichael Chan u32 entry_length; 985c0c050c5SMichael Chan u8 *buf; 986c0c050c5SMichael Chan size_t buflen; 987c0c050c5SMichael Chan dma_addr_t dma_handle; 988c0c050c5SMichael Chan struct hwrm_nvm_get_dir_entries_input req = {0}; 989c0c050c5SMichael Chan 990c0c050c5SMichael Chan rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); 991c0c050c5SMichael Chan if (rc != 0) 992c0c050c5SMichael Chan return rc; 993c0c050c5SMichael Chan 994c0c050c5SMichael Chan /* Insert 2 bytes of directory info (count and size of entries) */ 995c0c050c5SMichael Chan if (len < 2) 996c0c050c5SMichael Chan return -EINVAL; 997c0c050c5SMichael Chan 998c0c050c5SMichael Chan *data++ = dir_entries; 999c0c050c5SMichael Chan *data++ = entry_length; 1000c0c050c5SMichael Chan len -= 2; 1001c0c050c5SMichael Chan memset(data, 0xff, len); 1002c0c050c5SMichael Chan 1003c0c050c5SMichael Chan buflen = dir_entries * entry_length; 1004c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, 1005c0c050c5SMichael Chan GFP_KERNEL); 1006c0c050c5SMichael Chan if (!buf) { 1007c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1008c0c050c5SMichael Chan (unsigned)buflen); 1009c0c050c5SMichael Chan return -ENOMEM; 1010c0c050c5SMichael Chan } 1011c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); 1012c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 1013c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1014c0c050c5SMichael Chan if (rc == 0) 1015c0c050c5SMichael Chan memcpy(data, buf, len > buflen ? buflen : len); 1016c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); 1017c0c050c5SMichael Chan return rc; 1018c0c050c5SMichael Chan } 1019c0c050c5SMichael Chan 1020c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, 1021c0c050c5SMichael Chan u32 length, u8 *data) 1022c0c050c5SMichael Chan { 1023c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1024c0c050c5SMichael Chan int rc; 1025c0c050c5SMichael Chan u8 *buf; 1026c0c050c5SMichael Chan dma_addr_t dma_handle; 1027c0c050c5SMichael Chan struct hwrm_nvm_read_input req = {0}; 1028c0c050c5SMichael Chan 1029c0c050c5SMichael Chan buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, 1030c0c050c5SMichael Chan GFP_KERNEL); 1031c0c050c5SMichael Chan if (!buf) { 1032c0c050c5SMichael Chan netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", 1033c0c050c5SMichael Chan (unsigned)length); 1034c0c050c5SMichael Chan return -ENOMEM; 1035c0c050c5SMichael Chan } 1036c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); 1037c0c050c5SMichael Chan req.host_dest_addr = cpu_to_le64(dma_handle); 1038c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 1039c0c050c5SMichael Chan req.offset = cpu_to_le32(offset); 1040c0c050c5SMichael Chan req.len = cpu_to_le32(length); 1041c0c050c5SMichael Chan 1042c0c050c5SMichael Chan rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1043c0c050c5SMichael Chan if (rc == 0) 1044c0c050c5SMichael Chan memcpy(data, buf, length); 1045c0c050c5SMichael Chan dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); 1046c0c050c5SMichael Chan return rc; 1047c0c050c5SMichael Chan } 1048c0c050c5SMichael Chan 1049c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev, 1050c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 1051c0c050c5SMichael Chan u8 *data) 1052c0c050c5SMichael Chan { 1053c0c050c5SMichael Chan u32 index; 1054c0c050c5SMichael Chan u32 offset; 1055c0c050c5SMichael Chan 1056c0c050c5SMichael Chan if (eeprom->offset == 0) /* special offset value to get directory */ 1057c0c050c5SMichael Chan return bnxt_get_nvram_directory(dev, eeprom->len, data); 1058c0c050c5SMichael Chan 1059c0c050c5SMichael Chan index = eeprom->offset >> 24; 1060c0c050c5SMichael Chan offset = eeprom->offset & 0xffffff; 1061c0c050c5SMichael Chan 1062c0c050c5SMichael Chan if (index == 0) { 1063c0c050c5SMichael Chan netdev_err(dev, "unsupported index value: %d\n", index); 1064c0c050c5SMichael Chan return -EINVAL; 1065c0c050c5SMichael Chan } 1066c0c050c5SMichael Chan 1067c0c050c5SMichael Chan return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); 1068c0c050c5SMichael Chan } 1069c0c050c5SMichael Chan 1070c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) 1071c0c050c5SMichael Chan { 1072c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1073c0c050c5SMichael Chan struct hwrm_nvm_erase_dir_entry_input req = {0}; 1074c0c050c5SMichael Chan 1075c0c050c5SMichael Chan bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); 1076c0c050c5SMichael Chan req.dir_idx = cpu_to_le16(index); 1077c0c050c5SMichael Chan return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1078c0c050c5SMichael Chan } 1079c0c050c5SMichael Chan 1080c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev, 1081c0c050c5SMichael Chan struct ethtool_eeprom *eeprom, 1082c0c050c5SMichael Chan u8 *data) 1083c0c050c5SMichael Chan { 1084c0c050c5SMichael Chan struct bnxt *bp = netdev_priv(dev); 1085c0c050c5SMichael Chan u8 index, dir_op; 1086c0c050c5SMichael Chan u16 type, ext, ordinal, attr; 1087c0c050c5SMichael Chan 1088c0c050c5SMichael Chan if (!BNXT_PF(bp)) { 1089c0c050c5SMichael Chan netdev_err(dev, "NVM write not supported from a virtual function\n"); 1090c0c050c5SMichael Chan return -EINVAL; 1091c0c050c5SMichael Chan } 1092c0c050c5SMichael Chan 1093c0c050c5SMichael Chan type = eeprom->magic >> 16; 1094c0c050c5SMichael Chan 1095c0c050c5SMichael Chan if (type == 0xffff) { /* special value for directory operations */ 1096c0c050c5SMichael Chan index = eeprom->magic & 0xff; 1097c0c050c5SMichael Chan dir_op = eeprom->magic >> 8; 1098c0c050c5SMichael Chan if (index == 0) 1099c0c050c5SMichael Chan return -EINVAL; 1100c0c050c5SMichael Chan switch (dir_op) { 1101c0c050c5SMichael Chan case 0x0e: /* erase */ 1102c0c050c5SMichael Chan if (eeprom->offset != ~eeprom->magic) 1103c0c050c5SMichael Chan return -EINVAL; 1104c0c050c5SMichael Chan return bnxt_erase_nvram_directory(dev, index - 1); 1105c0c050c5SMichael Chan default: 1106c0c050c5SMichael Chan return -EINVAL; 1107c0c050c5SMichael Chan } 1108c0c050c5SMichael Chan } 1109c0c050c5SMichael Chan 1110c0c050c5SMichael Chan /* Create or re-write an NVM item: */ 1111c0c050c5SMichael Chan if (bnxt_dir_type_is_executable(type) == true) 1112c0c050c5SMichael Chan return -EINVAL; 1113c0c050c5SMichael Chan ext = eeprom->magic & 0xffff; 1114c0c050c5SMichael Chan ordinal = eeprom->offset >> 16; 1115c0c050c5SMichael Chan attr = eeprom->offset & 0xffff; 1116c0c050c5SMichael Chan 1117c0c050c5SMichael Chan return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, 1118c0c050c5SMichael Chan eeprom->len); 1119c0c050c5SMichael Chan } 1120c0c050c5SMichael Chan 1121c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = { 1122c0c050c5SMichael Chan .get_settings = bnxt_get_settings, 1123c0c050c5SMichael Chan .set_settings = bnxt_set_settings, 1124c0c050c5SMichael Chan .get_pauseparam = bnxt_get_pauseparam, 1125c0c050c5SMichael Chan .set_pauseparam = bnxt_set_pauseparam, 1126c0c050c5SMichael Chan .get_drvinfo = bnxt_get_drvinfo, 1127c0c050c5SMichael Chan .get_coalesce = bnxt_get_coalesce, 1128c0c050c5SMichael Chan .set_coalesce = bnxt_set_coalesce, 1129c0c050c5SMichael Chan .get_msglevel = bnxt_get_msglevel, 1130c0c050c5SMichael Chan .set_msglevel = bnxt_set_msglevel, 1131c0c050c5SMichael Chan .get_sset_count = bnxt_get_sset_count, 1132c0c050c5SMichael Chan .get_strings = bnxt_get_strings, 1133c0c050c5SMichael Chan .get_ethtool_stats = bnxt_get_ethtool_stats, 1134c0c050c5SMichael Chan .set_ringparam = bnxt_set_ringparam, 1135c0c050c5SMichael Chan .get_ringparam = bnxt_get_ringparam, 1136c0c050c5SMichael Chan .get_channels = bnxt_get_channels, 1137c0c050c5SMichael Chan .set_channels = bnxt_set_channels, 1138c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL 1139c0c050c5SMichael Chan .get_rxnfc = bnxt_get_rxnfc, 1140c0c050c5SMichael Chan #endif 1141c0c050c5SMichael Chan .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, 1142c0c050c5SMichael Chan .get_rxfh_key_size = bnxt_get_rxfh_key_size, 1143c0c050c5SMichael Chan .get_rxfh = bnxt_get_rxfh, 1144c0c050c5SMichael Chan .flash_device = bnxt_flash_device, 1145c0c050c5SMichael Chan .get_eeprom_len = bnxt_get_eeprom_len, 1146c0c050c5SMichael Chan .get_eeprom = bnxt_get_eeprom, 1147c0c050c5SMichael Chan .set_eeprom = bnxt_set_eeprom, 1148c0c050c5SMichael Chan .get_link = bnxt_get_link, 1149c0c050c5SMichael Chan }; 1150