net/sfc: minimum port control sufficient to receive traffic
[dpdk.git] / drivers / net / sfc / sfc_port.c
1 /*-
2  * Copyright (c) 2016 Solarflare Communications Inc.
3  * All rights reserved.
4  *
5  * This software was jointly developed between OKTET Labs (under contract
6  * for Solarflare) and Solarflare Communications, Inc.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  *    this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  *    this list of conditions and the following disclaimer in the documentation
15  *    and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "efx.h"
31
32 #include "sfc.h"
33 #include "sfc_log.h"
34
35
36 int
37 sfc_port_start(struct sfc_adapter *sa)
38 {
39         struct sfc_port *port = &sa->port;
40         int rc;
41
42         sfc_log_init(sa, "entry");
43
44         sfc_log_init(sa, "init filters");
45         rc = efx_filter_init(sa->nic);
46         if (rc != 0)
47                 goto fail_filter_init;
48
49         sfc_log_init(sa, "init port");
50         rc = efx_port_init(sa->nic);
51         if (rc != 0)
52                 goto fail_port_init;
53
54         sfc_log_init(sa, "set MAC PDU %u", (unsigned int)port->pdu);
55         rc = efx_mac_pdu_set(sa->nic, port->pdu);
56         if (rc != 0)
57                 goto fail_mac_pdu_set;
58
59         sfc_log_init(sa, "set MAC address");
60         rc = efx_mac_addr_set(sa->nic,
61                               sa->eth_dev->data->mac_addrs[0].addr_bytes);
62         if (rc != 0)
63                 goto fail_mac_addr_set;
64
65         sfc_log_init(sa, "set MAC filters");
66         rc = efx_mac_filter_set(sa->nic, B_TRUE, B_TRUE, B_TRUE, B_TRUE);
67         if (rc != 0)
68                 goto fail_mac_filter_set;
69
70         sfc_log_init(sa, "disable MAC drain");
71         rc = efx_mac_drain(sa->nic, B_FALSE);
72         if (rc != 0)
73                 goto fail_mac_drain;
74
75         sfc_log_init(sa, "done");
76         return 0;
77
78 fail_mac_drain:
79 fail_mac_filter_set:
80 fail_mac_addr_set:
81 fail_mac_pdu_set:
82         efx_port_fini(sa->nic);
83
84 fail_port_init:
85         efx_filter_fini(sa->nic);
86
87 fail_filter_init:
88         sfc_log_init(sa, "failed %d", rc);
89         return rc;
90 }
91
92 void
93 sfc_port_stop(struct sfc_adapter *sa)
94 {
95         sfc_log_init(sa, "entry");
96
97         efx_mac_drain(sa->nic, B_TRUE);
98         efx_port_fini(sa->nic);
99         efx_filter_fini(sa->nic);
100
101         sfc_log_init(sa, "done");
102 }
103
104 int
105 sfc_port_init(struct sfc_adapter *sa)
106 {
107         const struct rte_eth_dev_data *dev_data = sa->eth_dev->data;
108         struct sfc_port *port = &sa->port;
109
110         sfc_log_init(sa, "entry");
111
112         /* Enable flow control by default */
113         port->flow_ctrl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
114         port->flow_ctrl_autoneg = B_TRUE;
115
116         if (dev_data->dev_conf.rxmode.jumbo_frame)
117                 port->pdu = dev_data->dev_conf.rxmode.max_rx_pkt_len;
118         else
119                 port->pdu = EFX_MAC_PDU(dev_data->mtu);
120
121         sfc_log_init(sa, "done");
122         return 0;
123 }
124
125 void
126 sfc_port_fini(struct sfc_adapter *sa)
127 {
128         sfc_log_init(sa, "entry");
129
130         sfc_log_init(sa, "done");
131 }