36a540b514be334a5bb3b3e983f7ecef2b24b6a9
[linux-2.6-block.git] / drivers / net / ethernet / netronome / nfp / nfp_port.h
1 /*
2  * Copyright (C) 2017 Netronome Systems, Inc.
3  *
4  * This software is dual licensed under the GNU General License Version 2,
5  * June 1991 as shown in the file COPYING in the top-level directory of this
6  * source tree or the BSD 2-Clause License provided below.  You have the
7  * option to license this software under the complete terms of either license.
8  *
9  * The BSD 2-Clause License:
10  *
11  *     Redistribution and use in source and binary forms, with or
12  *     without modification, are permitted provided that the following
13  *     conditions are met:
14  *
15  *      1. Redistributions of source code must retain the above
16  *         copyright notice, this list of conditions and the following
17  *         disclaimer.
18  *
19  *      2. Redistributions in binary form must reproduce the above
20  *         copyright notice, this list of conditions and the following
21  *         disclaimer in the documentation and/or other materials
22  *         provided with the distribution.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31  * SOFTWARE.
32  */
33
34 #ifndef _NFP_PORT_H_
35 #define _NFP_PORT_H_
36
37 #include <net/devlink.h>
38
39 struct net_device;
40 struct nfp_app;
41 struct nfp_port;
42
43 /**
44  * enum nfp_port_type - type of port NFP can switch traffic to
45  * @NFP_PORT_INVALID:   port is invalid, %NFP_PORT_PHYS_PORT transitions to this
46  *                      state when port disappears because of FW fault or config
47  *                      change
48  * @NFP_PORT_PHYS_PORT: external NIC port
49  */
50 enum nfp_port_type {
51         NFP_PORT_INVALID,
52         NFP_PORT_PHYS_PORT,
53 };
54
55 /**
56  * enum nfp_port_flags - port flags (can be type-specific)
57  * @NFP_PORT_CHANGED:   port state has changed since last eth table refresh;
58  *                      for NFP_PORT_PHYS_PORT, never set otherwise; must hold
59  *                      rtnl_lock to clear
60  */
61 enum nfp_port_flags {
62         NFP_PORT_CHANGED = 0,
63 };
64
65 /**
66  * struct nfp_port - structure representing NFP port
67  * @netdev:     backpointer to associated netdev
68  * @type:       what port type does the entity represent
69  * @flags:      port flags
70  * @app:        backpointer to the app structure
71  * @dl_port:    devlink port structure
72  * @eth_id:     for %NFP_PORT_PHYS_PORT port ID in NFP enumeration scheme
73  * @eth_port:   for %NFP_PORT_PHYS_PORT translated ETH Table port entry
74  * @port_list:  entry on pf's list of ports
75  */
76 struct nfp_port {
77         struct net_device *netdev;
78         enum nfp_port_type type;
79
80         unsigned long flags;
81
82         struct nfp_app *app;
83
84         struct devlink_port dl_port;
85
86         unsigned int eth_id;
87         struct nfp_eth_table_port *eth_port;
88
89         struct list_head port_list;
90 };
91
92 struct nfp_port *nfp_port_from_netdev(struct net_device *netdev);
93 struct nfp_eth_table_port *__nfp_port_get_eth_port(struct nfp_port *port);
94 struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port);
95
96 int
97 nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len);
98
99 struct nfp_port *
100 nfp_port_alloc(struct nfp_app *app, enum nfp_port_type type,
101                struct net_device *netdev);
102 void nfp_port_free(struct nfp_port *port);
103
104 int nfp_net_refresh_eth_port(struct nfp_port *port);
105 void nfp_net_refresh_port_table(struct nfp_port *port);
106
107 int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port);
108 void nfp_devlink_port_unregister(struct nfp_port *port);
109
110 #endif