]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/ethernet/netronome/nfp/nfp_port.c
2 * Copyright (C) 2017 Netronome Systems, Inc.
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.
9 * The BSD 2-Clause License:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
34 #include <linux/lockdep.h>
36 #include "nfpcore/nfp_nsp.h"
42 struct nfp_port
*nfp_port_from_netdev(struct net_device
*netdev
)
46 if (WARN_ON(!nfp_netdev_is_nfp_net(netdev
)))
48 nn
= netdev_priv(netdev
);
54 nfp_port_from_id(struct nfp_pf
*pf
, enum nfp_port_type type
, unsigned int id
)
56 struct nfp_port
*port
;
58 lockdep_assert_held(&pf
->lock
);
60 if (type
!= NFP_PORT_PHYS_PORT
)
63 list_for_each_entry(port
, &pf
->ports
, port_list
)
64 if (port
->eth_id
== id
)
70 struct nfp_eth_table_port
*__nfp_port_get_eth_port(struct nfp_port
*port
)
74 if (port
->type
!= NFP_PORT_PHYS_PORT
)
77 return port
->eth_port
;
80 struct nfp_eth_table_port
*nfp_port_get_eth_port(struct nfp_port
*port
)
82 if (!__nfp_port_get_eth_port(port
))
85 if (test_bit(NFP_PORT_CHANGED
, &port
->flags
))
86 if (nfp_net_refresh_eth_port(port
))
89 return __nfp_port_get_eth_port(port
);
93 nfp_port_get_phys_port_name(struct net_device
*netdev
, char *name
, size_t len
)
95 struct nfp_eth_table_port
*eth_port
;
96 struct nfp_port
*port
;
99 port
= nfp_port_from_netdev(netdev
);
100 eth_port
= __nfp_port_get_eth_port(port
);
104 if (!eth_port
->is_split
)
105 n
= snprintf(name
, len
, "p%d", eth_port
->label_port
);
107 n
= snprintf(name
, len
, "p%ds%d", eth_port
->label_port
,
108 eth_port
->label_subport
);
116 nfp_port_alloc(struct nfp_app
*app
, enum nfp_port_type type
,
117 struct net_device
*netdev
)
119 struct nfp_port
*port
;
121 port
= kzalloc(sizeof(*port
), GFP_KERNEL
);
123 return ERR_PTR(-ENOMEM
);
125 port
->netdev
= netdev
;
129 list_add_tail(&port
->port_list
, &app
->pf
->ports
);
134 void nfp_port_free(struct nfp_port
*port
)
138 list_del(&port
->port_list
);