1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <linux/if_vlan.h>
36
37#include <linux/mlx4/device.h>
38#include <linux/mlx4/cmd.h>
39
40#include "en_port.h"
41#include "mlx4_en.h"
42
43
44int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port,
45 u64 mac, u64 clear, u8 mode)
46{
47 return mlx4_cmd(dev, (mac | (clear << 63)), port, mode,
48 MLX4_CMD_SET_MCAST_FLTR, MLX4_CMD_TIME_CLASS_B);
49}
50
51int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, u8 port, struct vlan_group *grp)
52{
53 struct mlx4_cmd_mailbox *mailbox;
54 struct mlx4_set_vlan_fltr_mbox *filter;
55 int i;
56 int j;
57 int index = 0;
58 u32 entry;
59 int err = 0;
60
61 mailbox = mlx4_alloc_cmd_mailbox(dev);
62 if (IS_ERR(mailbox))
63 return PTR_ERR(mailbox);
64
65 filter = mailbox->buf;
66 if (grp) {
67 memset(filter, 0, sizeof *filter);
68 for (i = VLAN_FLTR_SIZE - 1; i >= 0; i--) {
69 entry = 0;
70 for (j = 0; j < 32; j++)
71 if (vlan_group_get_device(grp, index++))
72 entry |= 1 << j;
73 filter->entry[i] = cpu_to_be32(entry);
74 }
75 } else {
76
77 memset(filter, 0, sizeof(*filter));
78 }
79 err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_SET_VLAN_FLTR,
80 MLX4_CMD_TIME_CLASS_B);
81 mlx4_free_cmd_mailbox(dev, mailbox);
82 return err;
83}
84
85
86int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu,
87 u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx)
88{
89 struct mlx4_cmd_mailbox *mailbox;
90 struct mlx4_set_port_general_context *context;
91 int err;
92 u32 in_mod;
93
94 mailbox = mlx4_alloc_cmd_mailbox(dev);
95 if (IS_ERR(mailbox))
96 return PTR_ERR(mailbox);
97 context = mailbox->buf;
98 memset(context, 0, sizeof *context);
99
100 context->flags = SET_PORT_GEN_ALL_VALID;
101 context->mtu = cpu_to_be16(mtu);
102 context->pptx = (pptx * (!pfctx)) << 7;
103 context->pfctx = pfctx;
104 context->pprx = (pprx * (!pfcrx)) << 7;
105 context->pfcrx = pfcrx;
106
107 in_mod = MLX4_SET_PORT_GENERAL << 8 | port;
108 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
109 MLX4_CMD_TIME_CLASS_B);
110
111 mlx4_free_cmd_mailbox(dev, mailbox);
112 return err;
113}
114
115int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn,
116 u8 promisc)
117{
118 struct mlx4_cmd_mailbox *mailbox;
119 struct mlx4_set_port_rqp_calc_context *context;
120 int err;
121 u32 in_mod;
122
123 mailbox = mlx4_alloc_cmd_mailbox(dev);
124 if (IS_ERR(mailbox))
125 return PTR_ERR(mailbox);
126 context = mailbox->buf;
127 memset(context, 0, sizeof *context);
128
129 context->base_qpn = cpu_to_be32(base_qpn);
130 context->promisc = cpu_to_be32(promisc << SET_PORT_PROMISC_EN_SHIFT | base_qpn);
131 context->mcast = cpu_to_be32(1 << SET_PORT_PROMISC_MODE_SHIFT | base_qpn);
132 context->intra_no_vlan = 0;
133 context->no_vlan = MLX4_NO_VLAN_IDX;
134 context->intra_vlan_miss = 0;
135 context->vlan_miss = MLX4_VLAN_MISS_IDX;
136
137 in_mod = MLX4_SET_PORT_RQP_CALC << 8 | port;
138 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
139 MLX4_CMD_TIME_CLASS_B);
140
141 mlx4_free_cmd_mailbox(dev, mailbox);
142 return err;
143}
144
145int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port)
146{
147 struct mlx4_en_query_port_context *qport_context;
148 struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
149 struct mlx4_en_port_state *state = &priv->port_state;
150 struct mlx4_cmd_mailbox *mailbox;
151 int err;
152
153 mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
154 if (IS_ERR(mailbox))
155 return PTR_ERR(mailbox);
156 memset(mailbox->buf, 0, sizeof(*qport_context));
157 err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, port, 0,
158 MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B);
159 if (err)
160 goto out;
161 qport_context = mailbox->buf;
162
163
164
165 state->link_state = !!(qport_context->link_up & MLX4_EN_LINK_UP_MASK);
166 if ((qport_context->link_speed & MLX4_EN_SPEED_MASK) ==
167 MLX4_EN_1G_SPEED)
168 state->link_speed = 1000;
169 else
170 state->link_speed = 10000;
171 state->transciver = qport_context->transceiver;
172
173out:
174 mlx4_free_cmd_mailbox(mdev->dev, mailbox);
175 return err;
176}
177
178int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset)
179{
180 struct mlx4_en_stat_out_mbox *mlx4_en_stats;
181 struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
182 struct net_device_stats *stats = &priv->stats;
183 struct mlx4_cmd_mailbox *mailbox;
184 u64 in_mod = reset << 8 | port;
185 int err;
186 int i;
187
188 mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
189 if (IS_ERR(mailbox))
190 return PTR_ERR(mailbox);
191 memset(mailbox->buf, 0, sizeof(*mlx4_en_stats));
192 err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0,
193 MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B);
194 if (err)
195 goto out;
196
197 mlx4_en_stats = mailbox->buf;
198
199 spin_lock_bh(&priv->stats_lock);
200
201 stats->rx_packets = 0;
202 stats->rx_bytes = 0;
203 for (i = 0; i < priv->rx_ring_num; i++) {
204 stats->rx_packets += priv->rx_ring[i].packets;
205 stats->rx_bytes += priv->rx_ring[i].bytes;
206 }
207 stats->tx_packets = 0;
208 stats->tx_bytes = 0;
209 for (i = 0; i <= priv->tx_ring_num; i++) {
210 stats->tx_packets += priv->tx_ring[i].packets;
211 stats->tx_bytes += priv->tx_ring[i].bytes;
212 }
213
214 stats->rx_errors = be64_to_cpu(mlx4_en_stats->PCS) +
215 be32_to_cpu(mlx4_en_stats->RdropLength) +
216 be32_to_cpu(mlx4_en_stats->RJBBR) +
217 be32_to_cpu(mlx4_en_stats->RCRC) +
218 be32_to_cpu(mlx4_en_stats->RRUNT);
219 stats->tx_errors = be32_to_cpu(mlx4_en_stats->TDROP);
220 stats->multicast = be64_to_cpu(mlx4_en_stats->MCAST_prio_0) +
221 be64_to_cpu(mlx4_en_stats->MCAST_prio_1) +
222 be64_to_cpu(mlx4_en_stats->MCAST_prio_2) +
223 be64_to_cpu(mlx4_en_stats->MCAST_prio_3) +
224 be64_to_cpu(mlx4_en_stats->MCAST_prio_4) +
225 be64_to_cpu(mlx4_en_stats->MCAST_prio_5) +
226 be64_to_cpu(mlx4_en_stats->MCAST_prio_6) +
227 be64_to_cpu(mlx4_en_stats->MCAST_prio_7) +
228 be64_to_cpu(mlx4_en_stats->MCAST_novlan);
229 stats->collisions = 0;
230 stats->rx_length_errors = be32_to_cpu(mlx4_en_stats->RdropLength);
231 stats->rx_over_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
232 stats->rx_crc_errors = be32_to_cpu(mlx4_en_stats->RCRC);
233 stats->rx_frame_errors = 0;
234 stats->rx_fifo_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
235 stats->rx_missed_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
236 stats->tx_aborted_errors = 0;
237 stats->tx_carrier_errors = 0;
238 stats->tx_fifo_errors = 0;
239 stats->tx_heartbeat_errors = 0;
240 stats->tx_window_errors = 0;
241
242 priv->pkstats.broadcast =
243 be64_to_cpu(mlx4_en_stats->RBCAST_prio_0) +
244 be64_to_cpu(mlx4_en_stats->RBCAST_prio_1) +
245 be64_to_cpu(mlx4_en_stats->RBCAST_prio_2) +
246 be64_to_cpu(mlx4_en_stats->RBCAST_prio_3) +
247 be64_to_cpu(mlx4_en_stats->RBCAST_prio_4) +
248 be64_to_cpu(mlx4_en_stats->RBCAST_prio_5) +
249 be64_to_cpu(mlx4_en_stats->RBCAST_prio_6) +
250 be64_to_cpu(mlx4_en_stats->RBCAST_prio_7) +
251 be64_to_cpu(mlx4_en_stats->RBCAST_novlan);
252 priv->pkstats.rx_prio[0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_0);
253 priv->pkstats.rx_prio[1] = be64_to_cpu(mlx4_en_stats->RTOT_prio_1);
254 priv->pkstats.rx_prio[2] = be64_to_cpu(mlx4_en_stats->RTOT_prio_2);
255 priv->pkstats.rx_prio[3] = be64_to_cpu(mlx4_en_stats->RTOT_prio_3);
256 priv->pkstats.rx_prio[4] = be64_to_cpu(mlx4_en_stats->RTOT_prio_4);
257 priv->pkstats.rx_prio[5] = be64_to_cpu(mlx4_en_stats->RTOT_prio_5);
258 priv->pkstats.rx_prio[6] = be64_to_cpu(mlx4_en_stats->RTOT_prio_6);
259 priv->pkstats.rx_prio[7] = be64_to_cpu(mlx4_en_stats->RTOT_prio_7);
260 priv->pkstats.tx_prio[0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_0);
261 priv->pkstats.tx_prio[1] = be64_to_cpu(mlx4_en_stats->TTOT_prio_1);
262 priv->pkstats.tx_prio[2] = be64_to_cpu(mlx4_en_stats->TTOT_prio_2);
263 priv->pkstats.tx_prio[3] = be64_to_cpu(mlx4_en_stats->TTOT_prio_3);
264 priv->pkstats.tx_prio[4] = be64_to_cpu(mlx4_en_stats->TTOT_prio_4);
265 priv->pkstats.tx_prio[5] = be64_to_cpu(mlx4_en_stats->TTOT_prio_5);
266 priv->pkstats.tx_prio[6] = be64_to_cpu(mlx4_en_stats->TTOT_prio_6);
267 priv->pkstats.tx_prio[7] = be64_to_cpu(mlx4_en_stats->TTOT_prio_7);
268 spin_unlock_bh(&priv->stats_lock);
269
270out:
271 mlx4_free_cmd_mailbox(mdev->dev, mailbox);
272 return err;
273}
274
275