Merge branch 'stable/for-jens-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / drivers / net / ethernet / intel / fm10k / fm10k_dcbnl.c
1 /* Intel(R) Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2016 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
19 */
20
21 #include "fm10k.h"
22
23 /**
24 * fm10k_dcbnl_ieee_getets - get the ETS configuration for the device
25 * @dev: netdev interface for the device
26 * @ets: ETS structure to push configuration to
27 **/
28 static int fm10k_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets)
29 {
30 int i;
31
32 /* we support 8 TCs in all modes */
33 ets->ets_cap = IEEE_8021QAZ_MAX_TCS;
34 ets->cbs = 0;
35
36 /* we only support strict priority and cannot do traffic shaping */
37 memset(ets->tc_tx_bw, 0, sizeof(ets->tc_tx_bw));
38 memset(ets->tc_rx_bw, 0, sizeof(ets->tc_rx_bw));
39 memset(ets->tc_tsa, IEEE_8021QAZ_TSA_STRICT, sizeof(ets->tc_tsa));
40
41 /* populate the prio map based on the netdev */
42 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
43 ets->prio_tc[i] = netdev_get_prio_tc_map(dev, i);
44
45 return 0;
46 }
47
48 /**
49 * fm10k_dcbnl_ieee_setets - set the ETS configuration for the device
50 * @dev: netdev interface for the device
51 * @ets: ETS structure to pull configuration from
52 **/
53 static int fm10k_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
54 {
55 u8 num_tc = 0;
56 int i, err;
57
58 /* verify type and determine num_tcs needed */
59 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
60 if (ets->tc_tx_bw[i] || ets->tc_rx_bw[i])
61 return -EINVAL;
62 if (ets->tc_tsa[i] != IEEE_8021QAZ_TSA_STRICT)
63 return -EINVAL;
64 if (ets->prio_tc[i] > num_tc)
65 num_tc = ets->prio_tc[i];
66 }
67
68 /* if requested TC is greater than 0 then num_tcs is max + 1 */
69 if (num_tc)
70 num_tc++;
71
72 if (num_tc > IEEE_8021QAZ_MAX_TCS)
73 return -EINVAL;
74
75 /* update TC hardware mapping if necessary */
76 if (num_tc != netdev_get_num_tc(dev)) {
77 err = fm10k_setup_tc(dev, num_tc);
78 if (err)
79 return err;
80 }
81
82 /* update priority mapping */
83 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
84 netdev_set_prio_tc_map(dev, i, ets->prio_tc[i]);
85
86 return 0;
87 }
88
89 /**
90 * fm10k_dcbnl_ieee_getpfc - get the PFC configuration for the device
91 * @dev: netdev interface for the device
92 * @pfc: PFC structure to push configuration to
93 **/
94 static int fm10k_dcbnl_ieee_getpfc(struct net_device *dev, struct ieee_pfc *pfc)
95 {
96 struct fm10k_intfc *interface = netdev_priv(dev);
97
98 /* record flow control max count and state of TCs */
99 pfc->pfc_cap = IEEE_8021QAZ_MAX_TCS;
100 pfc->pfc_en = interface->pfc_en;
101
102 return 0;
103 }
104
105 /**
106 * fm10k_dcbnl_ieee_setpfc - set the PFC configuration for the device
107 * @dev: netdev interface for the device
108 * @pfc: PFC structure to pull configuration from
109 **/
110 static int fm10k_dcbnl_ieee_setpfc(struct net_device *dev, struct ieee_pfc *pfc)
111 {
112 struct fm10k_intfc *interface = netdev_priv(dev);
113
114 /* record PFC configuration to interface */
115 interface->pfc_en = pfc->pfc_en;
116
117 /* if we are running update the drop_en state for all queues */
118 if (netif_running(dev))
119 fm10k_update_rx_drop_en(interface);
120
121 return 0;
122 }
123
124 /**
125 * fm10k_dcbnl_ieee_getdcbx - get the DCBX configuration for the device
126 * @dev: netdev interface for the device
127 *
128 * Returns that we support only IEEE DCB for this interface
129 **/
130 static u8 fm10k_dcbnl_getdcbx(struct net_device __always_unused *dev)
131 {
132 return DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
133 }
134
135 /**
136 * fm10k_dcbnl_ieee_setdcbx - get the DCBX configuration for the device
137 * @dev: netdev interface for the device
138 * @mode: new mode for this device
139 *
140 * Returns error on attempt to enable anything but IEEE DCB for this interface
141 **/
142 static u8 fm10k_dcbnl_setdcbx(struct net_device __always_unused *dev, u8 mode)
143 {
144 return (mode != (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE)) ? 1 : 0;
145 }
146
147 static const struct dcbnl_rtnl_ops fm10k_dcbnl_ops = {
148 .ieee_getets = fm10k_dcbnl_ieee_getets,
149 .ieee_setets = fm10k_dcbnl_ieee_setets,
150 .ieee_getpfc = fm10k_dcbnl_ieee_getpfc,
151 .ieee_setpfc = fm10k_dcbnl_ieee_setpfc,
152
153 .getdcbx = fm10k_dcbnl_getdcbx,
154 .setdcbx = fm10k_dcbnl_setdcbx,
155 };
156
157 /**
158 * fm10k_dcbnl_set_ops - Configures dcbnl ops pointer for netdev
159 * @dev: netdev interface for the device
160 *
161 * Enables PF for DCB by assigning DCBNL ops pointer.
162 **/
163 void fm10k_dcbnl_set_ops(struct net_device *dev)
164 {
165 struct fm10k_intfc *interface = netdev_priv(dev);
166 struct fm10k_hw *hw = &interface->hw;
167
168 if (hw->mac.type == fm10k_mac_pf)
169 dev->dcbnl_ops = &fm10k_dcbnl_ops;
170 }
This page took 0.035273 seconds and 6 git commands to generate.