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