net/cxgbe: grab available ports after firmware reset
[dpdk.git] / drivers / net / cxgbe / cxgbe_main.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2014-2017 Chelsio Communications.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Chelsio Communications nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <sys/queue.h>
35 #include <stdio.h>
36 #include <errno.h>
37 #include <stdint.h>
38 #include <string.h>
39 #include <unistd.h>
40 #include <stdarg.h>
41 #include <inttypes.h>
42 #include <netinet/in.h>
43
44 #include <rte_byteorder.h>
45 #include <rte_common.h>
46 #include <rte_cycles.h>
47 #include <rte_interrupts.h>
48 #include <rte_log.h>
49 #include <rte_debug.h>
50 #include <rte_pci.h>
51 #include <rte_atomic.h>
52 #include <rte_branch_prediction.h>
53 #include <rte_memory.h>
54 #include <rte_memzone.h>
55 #include <rte_tailq.h>
56 #include <rte_eal.h>
57 #include <rte_alarm.h>
58 #include <rte_ether.h>
59 #include <rte_ethdev.h>
60 #include <rte_ethdev_pci.h>
61 #include <rte_atomic.h>
62 #include <rte_malloc.h>
63 #include <rte_random.h>
64 #include <rte_dev.h>
65
66 #include "common.h"
67 #include "t4_regs.h"
68 #include "t4_msg.h"
69 #include "cxgbe.h"
70
71 /*
72  * Response queue handler for the FW event queue.
73  */
74 static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
75                           __rte_unused const struct pkt_gl *gl)
76 {
77         u8 opcode = ((const struct rss_header *)rsp)->opcode;
78
79         rsp++;                                          /* skip RSS header */
80
81         /*
82          * FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
83          */
84         if (unlikely(opcode == CPL_FW4_MSG &&
85                      ((const struct cpl_fw4_msg *)rsp)->type ==
86                       FW_TYPE_RSSCPL)) {
87                 rsp++;
88                 opcode = ((const struct rss_header *)rsp)->opcode;
89                 rsp++;
90                 if (opcode != CPL_SGE_EGR_UPDATE) {
91                         dev_err(q->adapter, "unexpected FW4/CPL %#x on FW event queue\n",
92                                 opcode);
93                         goto out;
94                 }
95         }
96
97         if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
98                 /* do nothing */
99         } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
100                 const struct cpl_fw6_msg *msg = (const void *)rsp;
101
102                 t4_handle_fw_rpl(q->adapter, msg->data);
103         } else {
104                 dev_err(adapter, "unexpected CPL %#x on FW event queue\n",
105                         opcode);
106         }
107 out:
108         return 0;
109 }
110
111 int setup_sge_fwevtq(struct adapter *adapter)
112 {
113         struct sge *s = &adapter->sge;
114         int err = 0;
115         int msi_idx = 0;
116
117         err = t4_sge_alloc_rxq(adapter, &s->fw_evtq, true, adapter->eth_dev,
118                                msi_idx, NULL, fwevtq_handler, -1, NULL, 0,
119                                rte_socket_id());
120         return err;
121 }
122
123 static int closest_timer(const struct sge *s, int time)
124 {
125         unsigned int i, match = 0;
126         int delta, min_delta = INT_MAX;
127
128         for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
129                 delta = time - s->timer_val[i];
130                 if (delta < 0)
131                         delta = -delta;
132                 if (delta < min_delta) {
133                         min_delta = delta;
134                         match = i;
135                 }
136         }
137         return match;
138 }
139
140 static int closest_thres(const struct sge *s, int thres)
141 {
142         unsigned int i, match = 0;
143         int delta, min_delta = INT_MAX;
144
145         for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
146                 delta = thres - s->counter_val[i];
147                 if (delta < 0)
148                         delta = -delta;
149                 if (delta < min_delta) {
150                         min_delta = delta;
151                         match = i;
152                 }
153         }
154         return match;
155 }
156
157 /**
158  * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
159  * @q: the Rx queue
160  * @us: the hold-off time in us, or 0 to disable timer
161  * @cnt: the hold-off packet count, or 0 to disable counter
162  *
163  * Sets an Rx queue's interrupt hold-off time and packet count.  At least
164  * one of the two needs to be enabled for the queue to generate interrupts.
165  */
166 int cxgb4_set_rspq_intr_params(struct sge_rspq *q, unsigned int us,
167                                unsigned int cnt)
168 {
169         struct adapter *adap = q->adapter;
170         unsigned int timer_val;
171
172         if (cnt) {
173                 int err;
174                 u32 v, new_idx;
175
176                 new_idx = closest_thres(&adap->sge, cnt);
177                 if (q->desc && q->pktcnt_idx != new_idx) {
178                         /* the queue has already been created, update it */
179                         v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
180                             V_FW_PARAMS_PARAM_X(
181                             FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
182                             V_FW_PARAMS_PARAM_YZ(q->cntxt_id);
183                         err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
184                                             &v, &new_idx);
185                         if (err)
186                                 return err;
187                 }
188                 q->pktcnt_idx = new_idx;
189         }
190
191         timer_val = (us == 0) ? X_TIMERREG_RESTART_COUNTER :
192                                 closest_timer(&adap->sge, us);
193
194         if ((us | cnt) == 0)
195                 q->intr_params = V_QINTR_TIMER_IDX(X_TIMERREG_UPDATE_CIDX);
196         else
197                 q->intr_params = V_QINTR_TIMER_IDX(timer_val) |
198                                  V_QINTR_CNT_EN(cnt > 0);
199         return 0;
200 }
201
202 static inline bool is_x_1g_port(const struct link_config *lc)
203 {
204         return (lc->supported & FW_PORT_CAP_SPEED_1G) != 0;
205 }
206
207 static inline bool is_x_10g_port(const struct link_config *lc)
208 {
209         return ((lc->supported & FW_PORT_CAP_SPEED_10G) != 0 ||
210                 (lc->supported & FW_PORT_CAP_SPEED_40G) != 0 ||
211                 (lc->supported & FW_PORT_CAP_SPEED_100G) != 0);
212 }
213
214 inline void init_rspq(struct adapter *adap, struct sge_rspq *q,
215                       unsigned int us, unsigned int cnt,
216                       unsigned int size, unsigned int iqe_size)
217 {
218         q->adapter = adap;
219         cxgb4_set_rspq_intr_params(q, us, cnt);
220         q->iqe_len = iqe_size;
221         q->size = size;
222 }
223
224 int cfg_queue_count(struct rte_eth_dev *eth_dev)
225 {
226         struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
227         struct adapter *adap = pi->adapter;
228         struct sge *s = &adap->sge;
229         unsigned int max_queues = s->max_ethqsets / adap->params.nports;
230
231         if ((eth_dev->data->nb_rx_queues < 1) ||
232             (eth_dev->data->nb_tx_queues < 1))
233                 return -EINVAL;
234
235         if ((eth_dev->data->nb_rx_queues > max_queues) ||
236             (eth_dev->data->nb_tx_queues > max_queues))
237                 return -EINVAL;
238
239         if (eth_dev->data->nb_rx_queues > pi->rss_size)
240                 return -EINVAL;
241
242         /* We must configure RSS, since config has changed*/
243         pi->flags &= ~PORT_RSS_DONE;
244
245         pi->n_rx_qsets = eth_dev->data->nb_rx_queues;
246         pi->n_tx_qsets = eth_dev->data->nb_tx_queues;
247
248         return 0;
249 }
250
251 void cfg_queues(struct rte_eth_dev *eth_dev)
252 {
253         struct rte_config *config = rte_eal_get_configuration();
254         struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
255         struct adapter *adap = pi->adapter;
256         struct sge *s = &adap->sge;
257         unsigned int i, nb_ports = 0, qidx = 0;
258         unsigned int q_per_port = 0;
259
260         if (!(adap->flags & CFG_QUEUES)) {
261                 for_each_port(adap, i) {
262                         struct port_info *tpi = adap2pinfo(adap, i);
263
264                         nb_ports += (is_x_10g_port(&tpi->link_cfg)) ||
265                                      is_x_1g_port(&tpi->link_cfg) ? 1 : 0;
266                 }
267
268                 /*
269                  * We default up to # of cores queues per 1G/10G port.
270                  */
271                 if (nb_ports)
272                         q_per_port = (MAX_ETH_QSETS -
273                                      (adap->params.nports - nb_ports)) /
274                                      nb_ports;
275
276                 if (q_per_port > config->lcore_count)
277                         q_per_port = config->lcore_count;
278
279                 for_each_port(adap, i) {
280                         struct port_info *pi = adap2pinfo(adap, i);
281
282                         pi->first_qset = qidx;
283
284                         /* Initially n_rx_qsets == n_tx_qsets */
285                         pi->n_rx_qsets = (is_x_10g_port(&pi->link_cfg) ||
286                                           is_x_1g_port(&pi->link_cfg)) ?
287                                           q_per_port : 1;
288                         pi->n_tx_qsets = pi->n_rx_qsets;
289
290                         if (pi->n_rx_qsets > pi->rss_size)
291                                 pi->n_rx_qsets = pi->rss_size;
292
293                         qidx += pi->n_rx_qsets;
294                 }
295
296                 s->max_ethqsets = qidx;
297
298                 for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
299                         struct sge_eth_rxq *r = &s->ethrxq[i];
300
301                         init_rspq(adap, &r->rspq, 0, 0, 1024, 64);
302                         r->usembufs = 1;
303                         r->fl.size = (r->usembufs ? 1024 : 72);
304                 }
305
306                 for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
307                         s->ethtxq[i].q.size = 1024;
308
309                 init_rspq(adap, &adap->sge.fw_evtq, 0, 0, 1024, 64);
310                 adap->flags |= CFG_QUEUES;
311         }
312 }
313
314 void cxgbe_stats_get(struct port_info *pi, struct port_stats *stats)
315 {
316         t4_get_port_stats_offset(pi->adapter, pi->tx_chan, stats,
317                                  &pi->stats_base);
318 }
319
320 void cxgbe_stats_reset(struct port_info *pi)
321 {
322         t4_clr_port_stats(pi->adapter, pi->tx_chan);
323 }
324
325 static void setup_memwin(struct adapter *adap)
326 {
327         u32 mem_win0_base;
328
329         /* For T5, only relative offset inside the PCIe BAR is passed */
330         mem_win0_base = MEMWIN0_BASE;
331
332         /*
333          * Set up memory window for accessing adapter memory ranges.  (Read
334          * back MA register to ensure that changes propagate before we attempt
335          * to use the new values.)
336          */
337         t4_write_reg(adap,
338                      PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN,
339                                          MEMWIN_NIC),
340                      mem_win0_base | V_BIR(0) |
341                      V_WINDOW(ilog2(MEMWIN0_APERTURE) - X_WINDOW_SHIFT));
342         t4_read_reg(adap,
343                     PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN,
344                                         MEMWIN_NIC));
345 }
346
347 static int init_rss(struct adapter *adap)
348 {
349         unsigned int i;
350         int err;
351
352         err = t4_init_rss_mode(adap, adap->mbox);
353         if (err)
354                 return err;
355
356         for_each_port(adap, i) {
357                 struct port_info *pi = adap2pinfo(adap, i);
358
359                 pi->rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0);
360                 if (!pi->rss)
361                         return -ENOMEM;
362         }
363         return 0;
364 }
365
366 static void print_port_info(struct adapter *adap)
367 {
368         int i;
369         char buf[80];
370         struct rte_pci_addr *loc = &adap->pdev->addr;
371
372         for_each_port(adap, i) {
373                 const struct port_info *pi = &adap->port[i];
374                 char *bufp = buf;
375
376                 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100M)
377                         bufp += sprintf(bufp, "100/");
378                 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_1G)
379                         bufp += sprintf(bufp, "1000/");
380                 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G)
381                         bufp += sprintf(bufp, "10G/");
382                 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G)
383                         bufp += sprintf(bufp, "40G/");
384                 if (bufp != buf)
385                         --bufp;
386                 sprintf(bufp, "BASE-%s",
387                         t4_get_port_type_description(
388                                         (enum fw_port_type)pi->port_type));
389
390                 dev_info(adap,
391                          " " PCI_PRI_FMT " Chelsio rev %d %s %s\n",
392                          loc->domain, loc->bus, loc->devid, loc->function,
393                          CHELSIO_CHIP_RELEASE(adap->params.chip), buf,
394                          (adap->flags & USING_MSIX) ? " MSI-X" :
395                          (adap->flags & USING_MSI) ? " MSI" : "");
396         }
397 }
398
399 /*
400  * Tweak configuration based on system architecture, etc.  Most of these have
401  * defaults assigned to them by Firmware Configuration Files (if we're using
402  * them) but need to be explicitly set if we're using hard-coded
403  * initialization. So these are essentially common tweaks/settings for
404  * Configuration Files and hard-coded initialization ...
405  */
406 static int adap_init0_tweaks(struct adapter *adapter)
407 {
408         u8 rx_dma_offset;
409
410         /*
411          * Fix up various Host-Dependent Parameters like Page Size, Cache
412          * Line Size, etc.  The firmware default is for a 4KB Page Size and
413          * 64B Cache Line Size ...
414          */
415         t4_fixup_host_params_compat(adapter, CXGBE_PAGE_SIZE, L1_CACHE_BYTES,
416                                     T5_LAST_REV);
417
418         /*
419          * Keep the chip default offset to deliver Ingress packets into our
420          * DMA buffers to zero
421          */
422         rx_dma_offset = 0;
423         t4_set_reg_field(adapter, A_SGE_CONTROL, V_PKTSHIFT(M_PKTSHIFT),
424                          V_PKTSHIFT(rx_dma_offset));
425
426         t4_set_reg_field(adapter, A_SGE_FLM_CFG,
427                          V_CREDITCNT(M_CREDITCNT) | M_CREDITCNTPACKING,
428                          V_CREDITCNT(3) | V_CREDITCNTPACKING(1));
429
430         t4_set_reg_field(adapter, A_SGE_CONTROL2, V_IDMAARBROUNDROBIN(1U),
431                          V_IDMAARBROUNDROBIN(1U));
432
433         /*
434          * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
435          * adds the pseudo header itself.
436          */
437         t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG,
438                                F_CSUM_HAS_PSEUDO_HDR, 0);
439
440         return 0;
441 }
442
443 /*
444  * Attempt to initialize the adapter via a Firmware Configuration File.
445  */
446 static int adap_init0_config(struct adapter *adapter, int reset)
447 {
448         struct fw_caps_config_cmd caps_cmd;
449         unsigned long mtype = 0, maddr = 0;
450         u32 finiver, finicsum, cfcsum;
451         int ret;
452         int config_issued = 0;
453         int cfg_addr;
454         char config_name[20];
455
456         /*
457          * Reset device if necessary.
458          */
459         if (reset) {
460                 ret = t4_fw_reset(adapter, adapter->mbox,
461                                   F_PIORSTMODE | F_PIORST);
462                 if (ret < 0) {
463                         dev_warn(adapter, "Firmware reset failed, error %d\n",
464                                  -ret);
465                         goto bye;
466                 }
467         }
468
469         cfg_addr = t4_flash_cfg_addr(adapter);
470         if (cfg_addr < 0) {
471                 ret = cfg_addr;
472                 dev_warn(adapter, "Finding address for firmware config file in flash failed, error %d\n",
473                          -ret);
474                 goto bye;
475         }
476
477         strcpy(config_name, "On Flash");
478         mtype = FW_MEMTYPE_CF_FLASH;
479         maddr = cfg_addr;
480
481         /*
482          * Issue a Capability Configuration command to the firmware to get it
483          * to parse the Configuration File.  We don't use t4_fw_config_file()
484          * because we want the ability to modify various features after we've
485          * processed the configuration file ...
486          */
487         memset(&caps_cmd, 0, sizeof(caps_cmd));
488         caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
489                                            F_FW_CMD_REQUEST | F_FW_CMD_READ);
490         caps_cmd.cfvalid_to_len16 =
491                 cpu_to_be32(F_FW_CAPS_CONFIG_CMD_CFVALID |
492                             V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
493                             V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(maddr >> 16) |
494                             FW_LEN16(caps_cmd));
495         ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
496                          &caps_cmd);
497         /*
498          * If the CAPS_CONFIG failed with an ENOENT (for a Firmware
499          * Configuration File in FLASH), our last gasp effort is to use the
500          * Firmware Configuration File which is embedded in the firmware.  A
501          * very few early versions of the firmware didn't have one embedded
502          * but we can ignore those.
503          */
504         if (ret == -ENOENT) {
505                 dev_info(adapter, "%s: Going for embedded config in firmware..\n",
506                          __func__);
507
508                 memset(&caps_cmd, 0, sizeof(caps_cmd));
509                 caps_cmd.op_to_write =
510                         cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
511                                     F_FW_CMD_REQUEST | F_FW_CMD_READ);
512                 caps_cmd.cfvalid_to_len16 = cpu_to_be32(FW_LEN16(caps_cmd));
513                 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
514                                  sizeof(caps_cmd), &caps_cmd);
515                 strcpy(config_name, "Firmware Default");
516         }
517
518         config_issued = 1;
519         if (ret < 0)
520                 goto bye;
521
522         finiver = be32_to_cpu(caps_cmd.finiver);
523         finicsum = be32_to_cpu(caps_cmd.finicsum);
524         cfcsum = be32_to_cpu(caps_cmd.cfcsum);
525         if (finicsum != cfcsum)
526                 dev_warn(adapter, "Configuration File checksum mismatch: [fini] csum=%#x, computed csum=%#x\n",
527                          finicsum, cfcsum);
528
529         /*
530          * If we're a pure NIC driver then disable all offloading facilities.
531          * This will allow the firmware to optimize aspects of the hardware
532          * configuration which will result in improved performance.
533          */
534         caps_cmd.niccaps &= cpu_to_be16(~(FW_CAPS_CONFIG_NIC_HASHFILTER |
535                                           FW_CAPS_CONFIG_NIC_ETHOFLD));
536         caps_cmd.toecaps = 0;
537         caps_cmd.iscsicaps = 0;
538         caps_cmd.rdmacaps = 0;
539         caps_cmd.fcoecaps = 0;
540
541         /*
542          * And now tell the firmware to use the configuration we just loaded.
543          */
544         caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
545                                            F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
546         caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
547         ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
548                          NULL);
549         if (ret < 0) {
550                 dev_warn(adapter, "Unable to finalize Firmware Capabilities %d\n",
551                          -ret);
552                 goto bye;
553         }
554
555         /*
556          * Tweak configuration based on system architecture, etc.
557          */
558         ret = adap_init0_tweaks(adapter);
559         if (ret < 0) {
560                 dev_warn(adapter, "Unable to do init0-tweaks %d\n", -ret);
561                 goto bye;
562         }
563
564         /*
565          * And finally tell the firmware to initialize itself using the
566          * parameters from the Configuration File.
567          */
568         ret = t4_fw_initialize(adapter, adapter->mbox);
569         if (ret < 0) {
570                 dev_warn(adapter, "Initializing Firmware failed, error %d\n",
571                          -ret);
572                 goto bye;
573         }
574
575         /*
576          * Return successfully and note that we're operating with parameters
577          * not supplied by the driver, rather than from hard-wired
578          * initialization constants burried in the driver.
579          */
580         dev_info(adapter,
581                  "Successfully configured using Firmware Configuration File \"%s\", version %#x, computed checksum %#x\n",
582                  config_name, finiver, cfcsum);
583
584         return 0;
585
586         /*
587          * Something bad happened.  Return the error ...  (If the "error"
588          * is that there's no Configuration File on the adapter we don't
589          * want to issue a warning since this is fairly common.)
590          */
591 bye:
592         if (config_issued && ret != -ENOENT)
593                 dev_warn(adapter, "\"%s\" configuration file error %d\n",
594                          config_name, -ret);
595
596         dev_debug(adapter, "%s: returning ret = %d ..\n", __func__, ret);
597         return ret;
598 }
599
600 static int adap_init0(struct adapter *adap)
601 {
602         int ret = 0;
603         u32 v, port_vec;
604         enum dev_state state;
605         u32 params[7], val[7];
606         int reset = 1;
607         int mbox = adap->mbox;
608
609         /*
610          * Contact FW, advertising Master capability.
611          */
612         ret = t4_fw_hello(adap, adap->mbox, adap->mbox, MASTER_MAY, &state);
613         if (ret < 0) {
614                 dev_err(adap, "%s: could not connect to FW, error %d\n",
615                         __func__, -ret);
616                 goto bye;
617         }
618
619         CXGBE_DEBUG_MBOX(adap, "%s: adap->mbox = %d; ret = %d\n", __func__,
620                          adap->mbox, ret);
621
622         if (ret == mbox)
623                 adap->flags |= MASTER_PF;
624
625         if (state == DEV_STATE_INIT) {
626                 /*
627                  * Force halt and reset FW because a previous instance may have
628                  * exited abnormally without properly shutting down
629                  */
630                 ret = t4_fw_halt(adap, adap->mbox, reset);
631                 if (ret < 0) {
632                         dev_err(adap, "Failed to halt. Exit.\n");
633                         goto bye;
634                 }
635
636                 ret = t4_fw_restart(adap, adap->mbox, reset);
637                 if (ret < 0) {
638                         dev_err(adap, "Failed to restart. Exit.\n");
639                         goto bye;
640                 }
641                 state = (enum dev_state)((unsigned)state & ~DEV_STATE_INIT);
642         }
643
644         t4_get_fw_version(adap, &adap->params.fw_vers);
645         t4_get_tp_version(adap, &adap->params.tp_vers);
646
647         dev_info(adap, "fw: %u.%u.%u.%u, TP: %u.%u.%u.%u\n",
648                  G_FW_HDR_FW_VER_MAJOR(adap->params.fw_vers),
649                  G_FW_HDR_FW_VER_MINOR(adap->params.fw_vers),
650                  G_FW_HDR_FW_VER_MICRO(adap->params.fw_vers),
651                  G_FW_HDR_FW_VER_BUILD(adap->params.fw_vers),
652                  G_FW_HDR_FW_VER_MAJOR(adap->params.tp_vers),
653                  G_FW_HDR_FW_VER_MINOR(adap->params.tp_vers),
654                  G_FW_HDR_FW_VER_MICRO(adap->params.tp_vers),
655                  G_FW_HDR_FW_VER_BUILD(adap->params.tp_vers));
656
657         ret = t4_get_core_clock(adap, &adap->params.vpd);
658         if (ret < 0) {
659                 dev_err(adap, "%s: could not get core clock, error %d\n",
660                         __func__, -ret);
661                 goto bye;
662         }
663
664         /*
665          * If the firmware is initialized already (and we're not forcing a
666          * master initialization), note that we're living with existing
667          * adapter parameters.  Otherwise, it's time to try initializing the
668          * adapter ...
669          */
670         if (state == DEV_STATE_INIT) {
671                 dev_info(adap, "Coming up as %s: Adapter already initialized\n",
672                          adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
673         } else {
674                 dev_info(adap, "Coming up as MASTER: Initializing adapter\n");
675
676                 ret = adap_init0_config(adap, reset);
677                 if (ret == -ENOENT) {
678                         dev_err(adap,
679                                 "No Configuration File present on adapter. Using hard-wired configuration parameters.\n");
680                         goto bye;
681                 }
682         }
683         if (ret < 0) {
684                 dev_err(adap, "could not initialize adapter, error %d\n", -ret);
685                 goto bye;
686         }
687
688         /* Find out what ports are available to us. */
689         v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
690             V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_PORTVEC);
691         ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
692         if (ret < 0) {
693                 dev_err(adap, "%s: failure in t4_query_params; error = %d\n",
694                         __func__, ret);
695                 goto bye;
696         }
697
698         adap->params.nports = hweight32(port_vec);
699         adap->params.portvec = port_vec;
700
701         dev_debug(adap, "%s: adap->params.nports = %u\n", __func__,
702                   adap->params.nports);
703
704         /*
705          * Give the SGE code a chance to pull in anything that it needs ...
706          * Note that this must be called after we retrieve our VPD parameters
707          * in order to know how to convert core ticks to seconds, etc.
708          */
709         ret = t4_sge_init(adap);
710         if (ret < 0) {
711                 dev_err(adap, "t4_sge_init failed with error %d\n",
712                         -ret);
713                 goto bye;
714         }
715
716         /*
717          * Grab some of our basic fundamental operating parameters.
718          */
719 #define FW_PARAM_DEV(param) \
720         (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
721          V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
722
723 #define FW_PARAM_PFVF(param) \
724         (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
725          V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param) |  \
726          V_FW_PARAMS_PARAM_Y(0) | \
727          V_FW_PARAMS_PARAM_Z(0))
728
729         /* If we're running on newer firmware, let it know that we're
730          * prepared to deal with encapsulated CPL messages.  Older
731          * firmware won't understand this and we'll just get
732          * unencapsulated messages ...
733          */
734         params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
735         val[0] = 1;
736         (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
737
738         /*
739          * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
740          * capability.  Earlier versions of the firmware didn't have the
741          * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
742          * permission to use ULPTX MEMWRITE DSGL.
743          */
744         if (is_t4(adap->params.chip)) {
745                 adap->params.ulptx_memwrite_dsgl = false;
746         } else {
747                 params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
748                 ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
749                                       1, params, val);
750                 adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
751         }
752
753         /*
754          * The MTU/MSS Table is initialized by now, so load their values.  If
755          * we're initializing the adapter, then we'll make any modifications
756          * we want to the MTU/MSS Table and also initialize the congestion
757          * parameters.
758          */
759         t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
760         if (state != DEV_STATE_INIT) {
761                 int i;
762
763                 /*
764                  * The default MTU Table contains values 1492 and 1500.
765                  * However, for TCP, it's better to have two values which are
766                  * a multiple of 8 +/- 4 bytes apart near this popular MTU.
767                  * This allows us to have a TCP Data Payload which is a
768                  * multiple of 8 regardless of what combination of TCP Options
769                  * are in use (always a multiple of 4 bytes) which is
770                  * important for performance reasons.  For instance, if no
771                  * options are in use, then we have a 20-byte IP header and a
772                  * 20-byte TCP header.  In this case, a 1500-byte MSS would
773                  * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
774                  * which is not a multiple of 8.  So using an MSS of 1488 in
775                  * this case results in a TCP Data Payload of 1448 bytes which
776                  * is a multiple of 8.  On the other hand, if 12-byte TCP Time
777                  * Stamps have been negotiated, then an MTU of 1500 bytes
778                  * results in a TCP Data Payload of 1448 bytes which, as
779                  * above, is a multiple of 8 bytes ...
780                  */
781                 for (i = 0; i < NMTUS; i++)
782                         if (adap->params.mtus[i] == 1492) {
783                                 adap->params.mtus[i] = 1488;
784                                 break;
785                         }
786
787                 t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
788                              adap->params.b_wnd);
789         }
790         t4_init_sge_params(adap);
791         t4_init_tp_params(adap);
792
793         adap->params.drv_memwin = MEMWIN_NIC;
794         adap->flags |= FW_OK;
795         dev_debug(adap, "%s: returning zero..\n", __func__);
796         return 0;
797
798         /*
799          * Something bad happened.  If a command timed out or failed with EIO
800          * FW does not operate within its spec or something catastrophic
801          * happened to HW/FW, stop issuing commands.
802          */
803 bye:
804         if (ret != -ETIMEDOUT && ret != -EIO)
805                 t4_fw_bye(adap, adap->mbox);
806         return ret;
807 }
808
809 /**
810  * t4_os_portmod_changed - handle port module changes
811  * @adap: the adapter associated with the module change
812  * @port_id: the port index whose module status has changed
813  *
814  * This is the OS-dependent handler for port module changes.  It is
815  * invoked when a port module is removed or inserted for any OS-specific
816  * processing.
817  */
818 void t4_os_portmod_changed(const struct adapter *adap, int port_id)
819 {
820         static const char * const mod_str[] = {
821                 NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
822         };
823
824         const struct port_info *pi = &adap->port[port_id];
825
826         if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
827                 dev_info(adap, "Port%d: port module unplugged\n", pi->port_id);
828         else if (pi->mod_type < ARRAY_SIZE(mod_str))
829                 dev_info(adap, "Port%d: %s port module inserted\n", pi->port_id,
830                          mod_str[pi->mod_type]);
831         else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
832                 dev_info(adap, "Port%d: unsupported optical port module inserted\n",
833                          pi->port_id);
834         else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
835                 dev_info(adap, "Port%d: unknown port module inserted, forcing TWINAX\n",
836                          pi->port_id);
837         else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
838                 dev_info(adap, "Port%d: transceiver module error\n",
839                          pi->port_id);
840         else
841                 dev_info(adap, "Port%d: unknown module type %d inserted\n",
842                          pi->port_id, pi->mod_type);
843 }
844
845 /**
846  * link_start - enable a port
847  * @dev: the port to enable
848  *
849  * Performs the MAC and PHY actions needed to enable a port.
850  */
851 int link_start(struct port_info *pi)
852 {
853         struct adapter *adapter = pi->adapter;
854         int ret;
855         unsigned int mtu;
856
857         mtu = pi->eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
858               (ETHER_HDR_LEN + ETHER_CRC_LEN);
859
860         /*
861          * We do not set address filters and promiscuity here, the stack does
862          * that step explicitly.
863          */
864         ret = t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu, -1, -1,
865                             -1, 1, true);
866         if (ret == 0) {
867                 ret = t4_change_mac(adapter, adapter->mbox, pi->viid,
868                                     pi->xact_addr_filt,
869                                     (u8 *)&pi->eth_dev->data->mac_addrs[0],
870                                     true, true);
871                 if (ret >= 0) {
872                         pi->xact_addr_filt = ret;
873                         ret = 0;
874                 }
875         }
876         if (ret == 0)
877                 ret = t4_link_l1cfg(adapter, adapter->mbox, pi->tx_chan,
878                                     &pi->link_cfg);
879         if (ret == 0) {
880                 /*
881                  * Enabling a Virtual Interface can result in an interrupt
882                  * during the processing of the VI Enable command and, in some
883                  * paths, result in an attempt to issue another command in the
884                  * interrupt context.  Thus, we disable interrupts during the
885                  * course of the VI Enable command ...
886                  */
887                 ret = t4_enable_vi_params(adapter, adapter->mbox, pi->viid,
888                                           true, true, false);
889         }
890         return ret;
891 }
892
893 /**
894  * cxgb4_write_rss - write the RSS table for a given port
895  * @pi: the port
896  * @queues: array of queue indices for RSS
897  *
898  * Sets up the portion of the HW RSS table for the port's VI to distribute
899  * packets to the Rx queues in @queues.
900  */
901 int cxgb4_write_rss(const struct port_info *pi, const u16 *queues)
902 {
903         u16 *rss;
904         int i, err;
905         struct adapter *adapter = pi->adapter;
906         const struct sge_eth_rxq *rxq;
907
908         /*  Should never be called before setting up sge eth rx queues */
909         BUG_ON(!(adapter->flags & FULL_INIT_DONE));
910
911         rxq = &adapter->sge.ethrxq[pi->first_qset];
912         rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0);
913         if (!rss)
914                 return -ENOMEM;
915
916         /* map the queue indices to queue ids */
917         for (i = 0; i < pi->rss_size; i++, queues++)
918                 rss[i] = rxq[*queues].rspq.abs_id;
919
920         err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
921                                   pi->rss_size, rss, pi->rss_size);
922         /*
923          * If Tunnel All Lookup isn't specified in the global RSS
924          * Configuration, then we need to specify a default Ingress
925          * Queue for any ingress packets which aren't hashed.  We'll
926          * use our first ingress queue ...
927          */
928         if (!err)
929                 err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
930                                        F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN |
931                                        F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
932                                        F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
933                                        F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN |
934                                        F_FW_RSS_VI_CONFIG_CMD_UDPEN,
935                                        rss[0]);
936         rte_free(rss);
937         return err;
938 }
939
940 /**
941  * setup_rss - configure RSS
942  * @adapter: the adapter
943  *
944  * Sets up RSS to distribute packets to multiple receive queues.  We
945  * configure the RSS CPU lookup table to distribute to the number of HW
946  * receive queues, and the response queue lookup table to narrow that
947  * down to the response queues actually configured for each port.
948  * We always configure the RSS mapping for all ports since the mapping
949  * table has plenty of entries.
950  */
951 int setup_rss(struct port_info *pi)
952 {
953         int j, err;
954         struct adapter *adapter = pi->adapter;
955
956         dev_debug(adapter, "%s:  pi->rss_size = %u; pi->n_rx_qsets = %u\n",
957                   __func__, pi->rss_size, pi->n_rx_qsets);
958
959         if (!(pi->flags & PORT_RSS_DONE)) {
960                 if (adapter->flags & FULL_INIT_DONE) {
961                         /* Fill default values with equal distribution */
962                         for (j = 0; j < pi->rss_size; j++)
963                                 pi->rss[j] = j % pi->n_rx_qsets;
964
965                         err = cxgb4_write_rss(pi, pi->rss);
966                         if (err)
967                                 return err;
968                         pi->flags |= PORT_RSS_DONE;
969                 }
970         }
971         return 0;
972 }
973
974 /*
975  * Enable NAPI scheduling and interrupt generation for all Rx queues.
976  */
977 static void enable_rx(struct adapter *adap)
978 {
979         struct sge *s = &adap->sge;
980         struct sge_rspq *q = &s->fw_evtq;
981         int i, j;
982
983         /* 0-increment GTS to start the timer and enable interrupts */
984         t4_write_reg(adap, MYPF_REG(A_SGE_PF_GTS),
985                      V_SEINTARM(q->intr_params) |
986                      V_INGRESSQID(q->cntxt_id));
987
988         for_each_port(adap, i) {
989                 const struct port_info *pi = &adap->port[i];
990                 struct rte_eth_dev *eth_dev = pi->eth_dev;
991
992                 for (j = 0; j < eth_dev->data->nb_rx_queues; j++) {
993                         q = eth_dev->data->rx_queues[j];
994
995                         /*
996                          * 0-increment GTS to start the timer and enable
997                          * interrupts
998                          */
999                         t4_write_reg(adap, MYPF_REG(A_SGE_PF_GTS),
1000                                      V_SEINTARM(q->intr_params) |
1001                                      V_INGRESSQID(q->cntxt_id));
1002                 }
1003         }
1004 }
1005
1006 /**
1007  * cxgb_up - enable the adapter
1008  * @adap: adapter being enabled
1009  *
1010  * Called when the first port is enabled, this function performs the
1011  * actions necessary to make an adapter operational, such as completing
1012  * the initialization of HW modules, and enabling interrupts.
1013  */
1014 int cxgbe_up(struct adapter *adap)
1015 {
1016         enable_rx(adap);
1017         t4_sge_tx_monitor_start(adap);
1018         t4_intr_enable(adap);
1019         adap->flags |= FULL_INIT_DONE;
1020
1021         /* TODO: deadman watchdog ?? */
1022         return 0;
1023 }
1024
1025 /*
1026  * Close the port
1027  */
1028 int cxgbe_down(struct port_info *pi)
1029 {
1030         struct adapter *adapter = pi->adapter;
1031         int err = 0;
1032
1033         err = t4_enable_vi(adapter, adapter->mbox, pi->viid, false, false);
1034         if (err) {
1035                 dev_err(adapter, "%s: disable_vi failed: %d\n", __func__, err);
1036                 return err;
1037         }
1038
1039         t4_reset_link_config(adapter, pi->port_id);
1040         return 0;
1041 }
1042
1043 /*
1044  * Release resources when all the ports have been stopped.
1045  */
1046 void cxgbe_close(struct adapter *adapter)
1047 {
1048         struct port_info *pi;
1049         int i;
1050
1051         if (adapter->flags & FULL_INIT_DONE) {
1052                 t4_intr_disable(adapter);
1053                 t4_sge_tx_monitor_stop(adapter);
1054                 t4_free_sge_resources(adapter);
1055                 for_each_port(adapter, i) {
1056                         pi = adap2pinfo(adapter, i);
1057                         if (pi->viid != 0)
1058                                 t4_free_vi(adapter, adapter->mbox,
1059                                            adapter->pf, 0, pi->viid);
1060                         rte_free(pi->eth_dev->data->mac_addrs);
1061                 }
1062                 adapter->flags &= ~FULL_INIT_DONE;
1063         }
1064
1065         if (adapter->flags & FW_OK)
1066                 t4_fw_bye(adapter, adapter->mbox);
1067 }
1068
1069 int cxgbe_probe(struct adapter *adapter)
1070 {
1071         struct port_info *pi;
1072         int chip;
1073         int func, i;
1074         int err = 0;
1075         u32 whoami;
1076
1077         whoami = t4_read_reg(adapter, A_PL_WHOAMI);
1078         chip = t4_get_chip_type(adapter,
1079                         CHELSIO_PCI_ID_VER(adapter->pdev->id.device_id));
1080         if (chip < 0)
1081                 return chip;
1082
1083         func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
1084                G_SOURCEPF(whoami) : G_T6_SOURCEPF(whoami);
1085
1086         adapter->mbox = func;
1087         adapter->pf = func;
1088
1089         t4_os_lock_init(&adapter->mbox_lock);
1090         TAILQ_INIT(&adapter->mbox_list);
1091
1092         err = t4_prep_adapter(adapter);
1093         if (err)
1094                 return err;
1095
1096         setup_memwin(adapter);
1097         err = adap_init0(adapter);
1098         if (err) {
1099                 dev_err(adapter, "%s: Adapter initialization failed, error %d\n",
1100                         __func__, err);
1101                 goto out_free;
1102         }
1103
1104         if (!is_t4(adapter->params.chip)) {
1105                 /*
1106                  * The userspace doorbell BAR is split evenly into doorbell
1107                  * regions, each associated with an egress queue.  If this
1108                  * per-queue region is large enough (at least UDBS_SEG_SIZE)
1109                  * then it can be used to submit a tx work request with an
1110                  * implied doorbell.  Enable write combining on the BAR if
1111                  * there is room for such work requests.
1112                  */
1113                 int s_qpp, qpp, num_seg;
1114
1115                 s_qpp = (S_QUEUESPERPAGEPF0 +
1116                         (S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) *
1117                         adapter->pf);
1118                 qpp = 1 << ((t4_read_reg(adapter,
1119                                 A_SGE_EGRESS_QUEUES_PER_PAGE_PF) >> s_qpp)
1120                                 & M_QUEUESPERPAGEPF0);
1121                 num_seg = CXGBE_PAGE_SIZE / UDBS_SEG_SIZE;
1122                 if (qpp > num_seg)
1123                         dev_warn(adapter, "Incorrect SGE EGRESS QUEUES_PER_PAGE configuration, continuing in debug mode\n");
1124
1125                 adapter->bar2 = (void *)adapter->pdev->mem_resource[2].addr;
1126                 if (!adapter->bar2) {
1127                         dev_err(adapter, "cannot map device bar2 region\n");
1128                         err = -ENOMEM;
1129                         goto out_free;
1130                 }
1131                 t4_write_reg(adapter, A_SGE_STAT_CFG, V_STATSOURCE_T5(7) |
1132                              V_STATMODE(0));
1133         }
1134
1135         for_each_port(adapter, i) {
1136                 char name[RTE_ETH_NAME_MAX_LEN];
1137                 struct rte_eth_dev_data *data = NULL;
1138                 const unsigned int numa_node = rte_socket_id();
1139
1140                 pi = &adapter->port[i];
1141                 pi->adapter = adapter;
1142                 pi->xact_addr_filt = -1;
1143                 pi->port_id = i;
1144
1145                 snprintf(name, sizeof(name), "cxgbe%d",
1146                          adapter->eth_dev->data->port_id + i);
1147
1148                 if (i == 0) {
1149                         /* First port is already allocated by DPDK */
1150                         pi->eth_dev = adapter->eth_dev;
1151                         goto allocate_mac;
1152                 }
1153
1154                 /*
1155                  * now do all data allocation - for eth_dev structure,
1156                  * and internal (private) data for the remaining ports
1157                  */
1158
1159                 /* reserve an ethdev entry */
1160                 pi->eth_dev = rte_eth_dev_allocate(name);
1161                 if (!pi->eth_dev)
1162                         goto out_free;
1163
1164                 data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
1165                 if (!data)
1166                         goto out_free;
1167
1168                 data->port_id = adapter->eth_dev->data->port_id + i;
1169
1170                 pi->eth_dev->data = data;
1171
1172 allocate_mac:
1173                 pi->eth_dev->device = &adapter->pdev->device;
1174                 pi->eth_dev->data->dev_private = pi;
1175                 pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops;
1176                 pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst;
1177                 pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst;
1178
1179                 rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev);
1180
1181                 pi->eth_dev->data->mac_addrs = rte_zmalloc(name,
1182                                                            ETHER_ADDR_LEN, 0);
1183                 if (!pi->eth_dev->data->mac_addrs) {
1184                         dev_err(adapter, "%s: Mem allocation failed for storing mac addr, aborting\n",
1185                                 __func__);
1186                         err = -1;
1187                         goto out_free;
1188                 }
1189         }
1190
1191         if (adapter->flags & FW_OK) {
1192                 err = t4_port_init(adapter, adapter->mbox, adapter->pf, 0);
1193                 if (err) {
1194                         dev_err(adapter, "%s: t4_port_init failed with err %d\n",
1195                                 __func__, err);
1196                         goto out_free;
1197                 }
1198         }
1199
1200         cfg_queues(adapter->eth_dev);
1201
1202         print_port_info(adapter);
1203
1204         err = init_rss(adapter);
1205         if (err)
1206                 goto out_free;
1207
1208         return 0;
1209
1210 out_free:
1211         for_each_port(adapter, i) {
1212                 pi = adap2pinfo(adapter, i);
1213                 if (pi->viid != 0)
1214                         t4_free_vi(adapter, adapter->mbox, adapter->pf,
1215                                    0, pi->viid);
1216                 /* Skip first port since it'll be de-allocated by DPDK */
1217                 if (i == 0)
1218                         continue;
1219                 if (pi->eth_dev->data)
1220                         rte_free(pi->eth_dev->data);
1221         }
1222
1223         if (adapter->flags & FW_OK)
1224                 t4_fw_bye(adapter, adapter->mbox);
1225         return -err;
1226 }