New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / net / sfc / sfc.c
1 /*-
2  *   BSD LICENSE
3  *
4  * Copyright (c) 2016-2017 Solarflare Communications Inc.
5  * All rights reserved.
6  *
7  * This software was jointly developed between OKTET Labs (under contract
8  * for Solarflare) and Solarflare Communications, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  *    this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  *    this list of conditions and the following disclaimer in the documentation
17  *    and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 /* sysconf() */
33 #include <unistd.h>
34
35 #include <rte_errno.h>
36
37 #include "efx.h"
38
39 #include "sfc.h"
40 #include "sfc_log.h"
41 #include "sfc_ev.h"
42 #include "sfc_rx.h"
43 #include "sfc_tx.h"
44
45
46 int
47 sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id,
48               size_t len, int socket_id, efsys_mem_t *esmp)
49 {
50         const struct rte_memzone *mz;
51
52         sfc_log_init(sa, "name=%s id=%u len=%lu socket_id=%d",
53                      name, id, len, socket_id);
54
55         mz = rte_eth_dma_zone_reserve(sa->eth_dev, name, id, len,
56                                       sysconf(_SC_PAGESIZE), socket_id);
57         if (mz == NULL) {
58                 sfc_err(sa, "cannot reserve DMA zone for %s:%u %#x@%d: %s",
59                         name, (unsigned int)id, (unsigned int)len, socket_id,
60                         rte_strerror(rte_errno));
61                 return ENOMEM;
62         }
63
64         esmp->esm_addr = mz->iova;
65         if (esmp->esm_addr == RTE_BAD_IOVA) {
66                 (void)rte_memzone_free(mz);
67                 return EFAULT;
68         }
69
70         esmp->esm_mz = mz;
71         esmp->esm_base = mz->addr;
72
73         return 0;
74 }
75
76 void
77 sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp)
78 {
79         int rc;
80
81         sfc_log_init(sa, "name=%s", esmp->esm_mz->name);
82
83         rc = rte_memzone_free(esmp->esm_mz);
84         if (rc != 0)
85                 sfc_err(sa, "rte_memzone_free(() failed: %d", rc);
86
87         memset(esmp, 0, sizeof(*esmp));
88 }
89
90 static uint32_t
91 sfc_phy_cap_from_link_speeds(uint32_t speeds)
92 {
93         uint32_t phy_caps = 0;
94
95         if (~speeds & ETH_LINK_SPEED_FIXED) {
96                 phy_caps |= (1 << EFX_PHY_CAP_AN);
97                 /*
98                  * If no speeds are specified in the mask, any supported
99                  * may be negotiated
100                  */
101                 if (speeds == ETH_LINK_SPEED_AUTONEG)
102                         phy_caps |=
103                                 (1 << EFX_PHY_CAP_1000FDX) |
104                                 (1 << EFX_PHY_CAP_10000FDX) |
105                                 (1 << EFX_PHY_CAP_40000FDX);
106         }
107         if (speeds & ETH_LINK_SPEED_1G)
108                 phy_caps |= (1 << EFX_PHY_CAP_1000FDX);
109         if (speeds & ETH_LINK_SPEED_10G)
110                 phy_caps |= (1 << EFX_PHY_CAP_10000FDX);
111         if (speeds & ETH_LINK_SPEED_40G)
112                 phy_caps |= (1 << EFX_PHY_CAP_40000FDX);
113
114         return phy_caps;
115 }
116
117 /*
118  * Check requested device level configuration.
119  * Receive and transmit configuration is checked in corresponding
120  * modules.
121  */
122 static int
123 sfc_check_conf(struct sfc_adapter *sa)
124 {
125         const struct rte_eth_conf *conf = &sa->eth_dev->data->dev_conf;
126         int rc = 0;
127
128         sa->port.phy_adv_cap =
129                 sfc_phy_cap_from_link_speeds(conf->link_speeds) &
130                 sa->port.phy_adv_cap_mask;
131         if ((sa->port.phy_adv_cap & ~(1 << EFX_PHY_CAP_AN)) == 0) {
132                 sfc_err(sa, "No link speeds from mask %#x are supported",
133                         conf->link_speeds);
134                 rc = EINVAL;
135         }
136
137         if (conf->lpbk_mode != 0) {
138                 sfc_err(sa, "Loopback not supported");
139                 rc = EINVAL;
140         }
141
142         if (conf->dcb_capability_en != 0) {
143                 sfc_err(sa, "Priority-based flow control not supported");
144                 rc = EINVAL;
145         }
146
147         if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
148                 sfc_err(sa, "Flow Director not supported");
149                 rc = EINVAL;
150         }
151
152         if ((conf->intr_conf.lsc != 0) &&
153             (sa->intr.type != EFX_INTR_LINE) &&
154             (sa->intr.type != EFX_INTR_MESSAGE)) {
155                 sfc_err(sa, "Link status change interrupt not supported");
156                 rc = EINVAL;
157         }
158
159         if (conf->intr_conf.rxq != 0) {
160                 sfc_err(sa, "Receive queue interrupt not supported");
161                 rc = EINVAL;
162         }
163
164         return rc;
165 }
166
167 /*
168  * Find out maximum number of receive and transmit queues which could be
169  * advertised.
170  *
171  * NIC is kept initialized on success to allow other modules acquire
172  * defaults and capabilities.
173  */
174 static int
175 sfc_estimate_resource_limits(struct sfc_adapter *sa)
176 {
177         const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
178         efx_drv_limits_t limits;
179         int rc;
180         uint32_t evq_allocated;
181         uint32_t rxq_allocated;
182         uint32_t txq_allocated;
183
184         memset(&limits, 0, sizeof(limits));
185
186         /* Request at least one Rx and Tx queue */
187         limits.edl_min_rxq_count = 1;
188         limits.edl_min_txq_count = 1;
189         /* Management event queue plus event queue for each Tx and Rx queue */
190         limits.edl_min_evq_count =
191                 1 + limits.edl_min_rxq_count + limits.edl_min_txq_count;
192
193         /* Divide by number of functions to guarantee that all functions
194          * will get promised resources
195          */
196         /* FIXME Divide by number of functions (not 2) below */
197         limits.edl_max_evq_count = encp->enc_evq_limit / 2;
198         SFC_ASSERT(limits.edl_max_evq_count >= limits.edl_min_rxq_count);
199
200         /* Split equally between receive and transmit */
201         limits.edl_max_rxq_count =
202                 MIN(encp->enc_rxq_limit, (limits.edl_max_evq_count - 1) / 2);
203         SFC_ASSERT(limits.edl_max_rxq_count >= limits.edl_min_rxq_count);
204
205         limits.edl_max_txq_count =
206                 MIN(encp->enc_txq_limit,
207                     limits.edl_max_evq_count - 1 - limits.edl_max_rxq_count);
208
209         if (sa->tso)
210                 limits.edl_max_txq_count =
211                         MIN(limits.edl_max_txq_count,
212                             encp->enc_fw_assisted_tso_v2_n_contexts /
213                             encp->enc_hw_pf_count);
214
215         SFC_ASSERT(limits.edl_max_txq_count >= limits.edl_min_rxq_count);
216
217         /* Configure the minimum required resources needed for the
218          * driver to operate, and the maximum desired resources that the
219          * driver is capable of using.
220          */
221         efx_nic_set_drv_limits(sa->nic, &limits);
222
223         sfc_log_init(sa, "init nic");
224         rc = efx_nic_init(sa->nic);
225         if (rc != 0)
226                 goto fail_nic_init;
227
228         /* Find resource dimensions assigned by firmware to this function */
229         rc = efx_nic_get_vi_pool(sa->nic, &evq_allocated, &rxq_allocated,
230                                  &txq_allocated);
231         if (rc != 0)
232                 goto fail_get_vi_pool;
233
234         /* It still may allocate more than maximum, ensure limit */
235         evq_allocated = MIN(evq_allocated, limits.edl_max_evq_count);
236         rxq_allocated = MIN(rxq_allocated, limits.edl_max_rxq_count);
237         txq_allocated = MIN(txq_allocated, limits.edl_max_txq_count);
238
239         /* Subtract management EVQ not used for traffic */
240         SFC_ASSERT(evq_allocated > 0);
241         evq_allocated--;
242
243         /* Right now we use separate EVQ for Rx and Tx */
244         sa->rxq_max = MIN(rxq_allocated, evq_allocated / 2);
245         sa->txq_max = MIN(txq_allocated, evq_allocated - sa->rxq_max);
246
247         /* Keep NIC initialized */
248         return 0;
249
250 fail_get_vi_pool:
251 fail_nic_init:
252         efx_nic_fini(sa->nic);
253         return rc;
254 }
255
256 static int
257 sfc_set_drv_limits(struct sfc_adapter *sa)
258 {
259         const struct rte_eth_dev_data *data = sa->eth_dev->data;
260         efx_drv_limits_t lim;
261
262         memset(&lim, 0, sizeof(lim));
263
264         /* Limits are strict since take into account initial estimation */
265         lim.edl_min_evq_count = lim.edl_max_evq_count =
266                 1 + data->nb_rx_queues + data->nb_tx_queues;
267         lim.edl_min_rxq_count = lim.edl_max_rxq_count = data->nb_rx_queues;
268         lim.edl_min_txq_count = lim.edl_max_txq_count = data->nb_tx_queues;
269
270         return efx_nic_set_drv_limits(sa->nic, &lim);
271 }
272
273 int
274 sfc_start(struct sfc_adapter *sa)
275 {
276         int rc;
277
278         sfc_log_init(sa, "entry");
279
280         SFC_ASSERT(sfc_adapter_is_locked(sa));
281
282         switch (sa->state) {
283         case SFC_ADAPTER_CONFIGURED:
284                 break;
285         case SFC_ADAPTER_STARTED:
286                 sfc_info(sa, "already started");
287                 return 0;
288         default:
289                 rc = EINVAL;
290                 goto fail_bad_state;
291         }
292
293         sa->state = SFC_ADAPTER_STARTING;
294
295         sfc_log_init(sa, "set resource limits");
296         rc = sfc_set_drv_limits(sa);
297         if (rc != 0)
298                 goto fail_set_drv_limits;
299
300         sfc_log_init(sa, "init nic");
301         rc = efx_nic_init(sa->nic);
302         if (rc != 0)
303                 goto fail_nic_init;
304
305         rc = sfc_intr_start(sa);
306         if (rc != 0)
307                 goto fail_intr_start;
308
309         rc = sfc_ev_start(sa);
310         if (rc != 0)
311                 goto fail_ev_start;
312
313         rc = sfc_port_start(sa);
314         if (rc != 0)
315                 goto fail_port_start;
316
317         rc = sfc_rx_start(sa);
318         if (rc != 0)
319                 goto fail_rx_start;
320
321         rc = sfc_tx_start(sa);
322         if (rc != 0)
323                 goto fail_tx_start;
324
325         rc = sfc_flow_start(sa);
326         if (rc != 0)
327                 goto fail_flows_insert;
328
329         sa->state = SFC_ADAPTER_STARTED;
330         sfc_log_init(sa, "done");
331         return 0;
332
333 fail_flows_insert:
334         sfc_tx_stop(sa);
335
336 fail_tx_start:
337         sfc_rx_stop(sa);
338
339 fail_rx_start:
340         sfc_port_stop(sa);
341
342 fail_port_start:
343         sfc_ev_stop(sa);
344
345 fail_ev_start:
346         sfc_intr_stop(sa);
347
348 fail_intr_start:
349         efx_nic_fini(sa->nic);
350
351 fail_nic_init:
352 fail_set_drv_limits:
353         sa->state = SFC_ADAPTER_CONFIGURED;
354 fail_bad_state:
355         sfc_log_init(sa, "failed %d", rc);
356         return rc;
357 }
358
359 void
360 sfc_stop(struct sfc_adapter *sa)
361 {
362         sfc_log_init(sa, "entry");
363
364         SFC_ASSERT(sfc_adapter_is_locked(sa));
365
366         switch (sa->state) {
367         case SFC_ADAPTER_STARTED:
368                 break;
369         case SFC_ADAPTER_CONFIGURED:
370                 sfc_info(sa, "already stopped");
371                 return;
372         default:
373                 sfc_err(sa, "stop in unexpected state %u", sa->state);
374                 SFC_ASSERT(B_FALSE);
375                 return;
376         }
377
378         sa->state = SFC_ADAPTER_STOPPING;
379
380         sfc_flow_stop(sa);
381         sfc_tx_stop(sa);
382         sfc_rx_stop(sa);
383         sfc_port_stop(sa);
384         sfc_ev_stop(sa);
385         sfc_intr_stop(sa);
386         efx_nic_fini(sa->nic);
387
388         sa->state = SFC_ADAPTER_CONFIGURED;
389         sfc_log_init(sa, "done");
390 }
391
392 int
393 sfc_configure(struct sfc_adapter *sa)
394 {
395         int rc;
396
397         sfc_log_init(sa, "entry");
398
399         SFC_ASSERT(sfc_adapter_is_locked(sa));
400
401         SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED ||
402                    sa->state == SFC_ADAPTER_CONFIGURED);
403         sa->state = SFC_ADAPTER_CONFIGURING;
404
405         rc = sfc_check_conf(sa);
406         if (rc != 0)
407                 goto fail_check_conf;
408
409         rc = sfc_intr_configure(sa);
410         if (rc != 0)
411                 goto fail_intr_configure;
412
413         rc = sfc_port_configure(sa);
414         if (rc != 0)
415                 goto fail_port_configure;
416
417         rc = sfc_rx_configure(sa);
418         if (rc != 0)
419                 goto fail_rx_configure;
420
421         rc = sfc_tx_configure(sa);
422         if (rc != 0)
423                 goto fail_tx_configure;
424
425         sa->state = SFC_ADAPTER_CONFIGURED;
426         sfc_log_init(sa, "done");
427         return 0;
428
429 fail_tx_configure:
430         sfc_rx_close(sa);
431
432 fail_rx_configure:
433         sfc_port_close(sa);
434
435 fail_port_configure:
436         sfc_intr_close(sa);
437
438 fail_intr_configure:
439 fail_check_conf:
440         sa->state = SFC_ADAPTER_INITIALIZED;
441         sfc_log_init(sa, "failed %d", rc);
442         return rc;
443 }
444
445 void
446 sfc_close(struct sfc_adapter *sa)
447 {
448         sfc_log_init(sa, "entry");
449
450         SFC_ASSERT(sfc_adapter_is_locked(sa));
451
452         SFC_ASSERT(sa->state == SFC_ADAPTER_CONFIGURED);
453         sa->state = SFC_ADAPTER_CLOSING;
454
455         sfc_tx_close(sa);
456         sfc_rx_close(sa);
457         sfc_port_close(sa);
458         sfc_intr_close(sa);
459
460         sa->state = SFC_ADAPTER_INITIALIZED;
461         sfc_log_init(sa, "done");
462 }
463
464 static int
465 sfc_mem_bar_init(struct sfc_adapter *sa)
466 {
467         struct rte_eth_dev *eth_dev = sa->eth_dev;
468         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
469         efsys_bar_t *ebp = &sa->mem_bar;
470         unsigned int i;
471         struct rte_mem_resource *res;
472
473         for (i = 0; i < RTE_DIM(pci_dev->mem_resource); i++) {
474                 res = &pci_dev->mem_resource[i];
475                 if ((res->len != 0) && (res->phys_addr != 0)) {
476                         /* Found first memory BAR */
477                         SFC_BAR_LOCK_INIT(ebp, eth_dev->data->name);
478                         ebp->esb_rid = i;
479                         ebp->esb_dev = pci_dev;
480                         ebp->esb_base = res->addr;
481                         return 0;
482                 }
483         }
484
485         return EFAULT;
486 }
487
488 static void
489 sfc_mem_bar_fini(struct sfc_adapter *sa)
490 {
491         efsys_bar_t *ebp = &sa->mem_bar;
492
493         SFC_BAR_LOCK_DESTROY(ebp);
494         memset(ebp, 0, sizeof(*ebp));
495 }
496
497 #if EFSYS_OPT_RX_SCALE
498 /*
499  * A fixed RSS key which has a property of being symmetric
500  * (symmetrical flows are distributed to the same CPU)
501  * and also known to give a uniform distribution
502  * (a good distribution of traffic between different CPUs)
503  */
504 static const uint8_t default_rss_key[EFX_RSS_KEY_SIZE] = {
505         0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
506         0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
507         0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
508         0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
509         0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
510 };
511 #endif
512
513 #if EFSYS_OPT_RX_SCALE
514 static int
515 sfc_set_rss_defaults(struct sfc_adapter *sa)
516 {
517         int rc;
518
519         rc = efx_intr_init(sa->nic, sa->intr.type, NULL);
520         if (rc != 0)
521                 goto fail_intr_init;
522
523         rc = efx_ev_init(sa->nic);
524         if (rc != 0)
525                 goto fail_ev_init;
526
527         rc = efx_rx_init(sa->nic);
528         if (rc != 0)
529                 goto fail_rx_init;
530
531         rc = efx_rx_scale_default_support_get(sa->nic, &sa->rss_support);
532         if (rc != 0)
533                 goto fail_scale_support_get;
534
535         rc = efx_rx_hash_default_support_get(sa->nic, &sa->hash_support);
536         if (rc != 0)
537                 goto fail_hash_support_get;
538
539         efx_rx_fini(sa->nic);
540         efx_ev_fini(sa->nic);
541         efx_intr_fini(sa->nic);
542
543         sa->rss_hash_types = sfc_rte_to_efx_hash_type(SFC_RSS_OFFLOADS);
544
545         rte_memcpy(sa->rss_key, default_rss_key, sizeof(sa->rss_key));
546
547         return 0;
548
549 fail_hash_support_get:
550 fail_scale_support_get:
551 fail_rx_init:
552         efx_ev_fini(sa->nic);
553
554 fail_ev_init:
555         efx_intr_fini(sa->nic);
556
557 fail_intr_init:
558         return rc;
559 }
560 #else
561 static int
562 sfc_set_rss_defaults(__rte_unused struct sfc_adapter *sa)
563 {
564         return 0;
565 }
566 #endif
567
568 int
569 sfc_attach(struct sfc_adapter *sa)
570 {
571         const efx_nic_cfg_t *encp;
572         efx_nic_t *enp = sa->nic;
573         int rc;
574
575         sfc_log_init(sa, "entry");
576
577         SFC_ASSERT(sfc_adapter_is_locked(sa));
578
579         efx_mcdi_new_epoch(enp);
580
581         sfc_log_init(sa, "reset nic");
582         rc = efx_nic_reset(enp);
583         if (rc != 0)
584                 goto fail_nic_reset;
585
586         encp = efx_nic_cfg_get(sa->nic);
587
588         if (sa->dp_tx->features & SFC_DP_TX_FEAT_TSO) {
589                 sa->tso = encp->enc_fw_assisted_tso_v2_enabled;
590                 if (!sa->tso)
591                         sfc_warn(sa,
592                                  "TSO support isn't available on this adapter");
593         }
594
595         sfc_log_init(sa, "estimate resource limits");
596         rc = sfc_estimate_resource_limits(sa);
597         if (rc != 0)
598                 goto fail_estimate_rsrc_limits;
599
600         sa->txq_max_entries = encp->enc_txq_max_ndescs;
601         SFC_ASSERT(rte_is_power_of_2(sa->txq_max_entries));
602
603         rc = sfc_intr_attach(sa);
604         if (rc != 0)
605                 goto fail_intr_attach;
606
607         rc = sfc_ev_attach(sa);
608         if (rc != 0)
609                 goto fail_ev_attach;
610
611         rc = sfc_port_attach(sa);
612         if (rc != 0)
613                 goto fail_port_attach;
614
615         rc = sfc_set_rss_defaults(sa);
616         if (rc != 0)
617                 goto fail_set_rss_defaults;
618
619         rc = sfc_filter_attach(sa);
620         if (rc != 0)
621                 goto fail_filter_attach;
622
623         sfc_log_init(sa, "fini nic");
624         efx_nic_fini(enp);
625
626         sfc_flow_init(sa);
627
628         sa->state = SFC_ADAPTER_INITIALIZED;
629
630         sfc_log_init(sa, "done");
631         return 0;
632
633 fail_filter_attach:
634 fail_set_rss_defaults:
635         sfc_port_detach(sa);
636
637 fail_port_attach:
638         sfc_ev_detach(sa);
639
640 fail_ev_attach:
641         sfc_intr_detach(sa);
642
643 fail_intr_attach:
644         efx_nic_fini(sa->nic);
645
646 fail_estimate_rsrc_limits:
647 fail_nic_reset:
648
649         sfc_log_init(sa, "failed %d", rc);
650         return rc;
651 }
652
653 void
654 sfc_detach(struct sfc_adapter *sa)
655 {
656         sfc_log_init(sa, "entry");
657
658         SFC_ASSERT(sfc_adapter_is_locked(sa));
659
660         sfc_flow_fini(sa);
661
662         sfc_filter_detach(sa);
663         sfc_port_detach(sa);
664         sfc_ev_detach(sa);
665         sfc_intr_detach(sa);
666
667         sa->state = SFC_ADAPTER_UNINITIALIZED;
668 }
669
670 int
671 sfc_probe(struct sfc_adapter *sa)
672 {
673         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev);
674         efx_nic_t *enp;
675         int rc;
676
677         sfc_log_init(sa, "entry");
678
679         SFC_ASSERT(sfc_adapter_is_locked(sa));
680
681         sa->socket_id = rte_socket_id();
682
683         sfc_log_init(sa, "init mem bar");
684         rc = sfc_mem_bar_init(sa);
685         if (rc != 0)
686                 goto fail_mem_bar_init;
687
688         sfc_log_init(sa, "get family");
689         rc = efx_family(pci_dev->id.vendor_id, pci_dev->id.device_id,
690                         &sa->family);
691         if (rc != 0)
692                 goto fail_family;
693         sfc_log_init(sa, "family is %u", sa->family);
694
695         sfc_log_init(sa, "create nic");
696         rte_spinlock_init(&sa->nic_lock);
697         rc = efx_nic_create(sa->family, (efsys_identifier_t *)sa,
698                             &sa->mem_bar, &sa->nic_lock, &enp);
699         if (rc != 0)
700                 goto fail_nic_create;
701         sa->nic = enp;
702
703         rc = sfc_mcdi_init(sa);
704         if (rc != 0)
705                 goto fail_mcdi_init;
706
707         sfc_log_init(sa, "probe nic");
708         rc = efx_nic_probe(enp);
709         if (rc != 0)
710                 goto fail_nic_probe;
711
712         sfc_log_init(sa, "done");
713         return 0;
714
715 fail_nic_probe:
716         sfc_mcdi_fini(sa);
717
718 fail_mcdi_init:
719         sfc_log_init(sa, "destroy nic");
720         sa->nic = NULL;
721         efx_nic_destroy(enp);
722
723 fail_nic_create:
724 fail_family:
725         sfc_mem_bar_fini(sa);
726
727 fail_mem_bar_init:
728         sfc_log_init(sa, "failed %d", rc);
729         return rc;
730 }
731
732 void
733 sfc_unprobe(struct sfc_adapter *sa)
734 {
735         efx_nic_t *enp = sa->nic;
736
737         sfc_log_init(sa, "entry");
738
739         SFC_ASSERT(sfc_adapter_is_locked(sa));
740
741         sfc_log_init(sa, "unprobe nic");
742         efx_nic_unprobe(enp);
743
744         sfc_mcdi_fini(sa);
745
746         sfc_log_init(sa, "destroy nic");
747         sa->nic = NULL;
748         efx_nic_destroy(enp);
749
750         sfc_mem_bar_fini(sa);
751
752         sfc_flow_fini(sa);
753         sa->state = SFC_ADAPTER_UNINITIALIZED;
754 }