net/mlx5e: Allocate DMA coherent memory on reader NUMA node
[linux-2.6-block.git] / drivers / net / ethernet / mellanox / mlx5 / core / en.h
CommitLineData
f62b8bb8
AV
1/*
2 * Copyright (c) 2015, Mellanox Technologies. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/if_vlan.h>
34#include <linux/etherdevice.h>
35#include <linux/mlx5/driver.h>
36#include <linux/mlx5/qp.h>
37#include <linux/mlx5/cq.h>
d18a9470 38#include <linux/mlx5/vport.h>
f62b8bb8
AV
39#include "wq.h"
40#include "transobj.h"
41#include "mlx5_core.h"
42
43#define MLX5E_MAX_NUM_TC 8
44
45#define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE 0x7
46#define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE 0xa
47#define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE 0xd
48
49#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE 0x7
50#define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE 0xa
51#define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE 0xd
52
53#define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ (16 * 1024)
54#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC 0x10
55#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS 0x20
56#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC 0x10
57#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS 0x20
58#define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES 0x80
59#define MLX5E_PARAMS_DEFAULT_RX_HASH_LOG_TBL_SZ 0x7
f62b8bb8
AV
60
61#define MLX5E_TX_CQ_POLL_BUDGET 128
62#define MLX5E_UPDATE_STATS_INTERVAL 200 /* msecs */
63
64static const char vport_strings[][ETH_GSTRING_LEN] = {
65 /* vport statistics */
66 "rx_packets",
67 "rx_bytes",
68 "tx_packets",
69 "tx_bytes",
70 "rx_error_packets",
71 "rx_error_bytes",
72 "tx_error_packets",
73 "tx_error_bytes",
74 "rx_unicast_packets",
75 "rx_unicast_bytes",
76 "tx_unicast_packets",
77 "tx_unicast_bytes",
78 "rx_multicast_packets",
79 "rx_multicast_bytes",
80 "tx_multicast_packets",
81 "tx_multicast_bytes",
82 "rx_broadcast_packets",
83 "rx_broadcast_bytes",
84 "tx_broadcast_packets",
85 "tx_broadcast_bytes",
86
87 /* SW counters */
88 "tso_packets",
89 "tso_bytes",
90 "lro_packets",
91 "lro_bytes",
92 "rx_csum_good",
93 "rx_csum_none",
94 "tx_csum_offload",
95 "tx_queue_stopped",
96 "tx_queue_wake",
97 "tx_queue_dropped",
98 "rx_wqe_err",
99};
100
101struct mlx5e_vport_stats {
102 /* HW counters */
103 u64 rx_packets;
104 u64 rx_bytes;
105 u64 tx_packets;
106 u64 tx_bytes;
107 u64 rx_error_packets;
108 u64 rx_error_bytes;
109 u64 tx_error_packets;
110 u64 tx_error_bytes;
111 u64 rx_unicast_packets;
112 u64 rx_unicast_bytes;
113 u64 tx_unicast_packets;
114 u64 tx_unicast_bytes;
115 u64 rx_multicast_packets;
116 u64 rx_multicast_bytes;
117 u64 tx_multicast_packets;
118 u64 tx_multicast_bytes;
119 u64 rx_broadcast_packets;
120 u64 rx_broadcast_bytes;
121 u64 tx_broadcast_packets;
122 u64 tx_broadcast_bytes;
123
124 /* SW counters */
125 u64 tso_packets;
126 u64 tso_bytes;
127 u64 lro_packets;
128 u64 lro_bytes;
129 u64 rx_csum_good;
130 u64 rx_csum_none;
131 u64 tx_csum_offload;
132 u64 tx_queue_stopped;
133 u64 tx_queue_wake;
134 u64 tx_queue_dropped;
135 u64 rx_wqe_err;
136
137#define NUM_VPORT_COUNTERS 31
138};
139
140static const char rq_stats_strings[][ETH_GSTRING_LEN] = {
141 "packets",
142 "csum_none",
143 "lro_packets",
144 "lro_bytes",
145 "wqe_err"
146};
147
148struct mlx5e_rq_stats {
149 u64 packets;
150 u64 csum_none;
151 u64 lro_packets;
152 u64 lro_bytes;
153 u64 wqe_err;
154#define NUM_RQ_STATS 5
155};
156
157static const char sq_stats_strings[][ETH_GSTRING_LEN] = {
158 "packets",
159 "tso_packets",
160 "tso_bytes",
161 "csum_offload_none",
162 "stopped",
163 "wake",
164 "dropped",
165 "nop"
166};
167
168struct mlx5e_sq_stats {
169 u64 packets;
170 u64 tso_packets;
171 u64 tso_bytes;
172 u64 csum_offload_none;
173 u64 stopped;
174 u64 wake;
175 u64 dropped;
176 u64 nop;
177#define NUM_SQ_STATS 8
178};
179
180struct mlx5e_stats {
181 struct mlx5e_vport_stats vport;
182};
183
184struct mlx5e_params {
185 u8 log_sq_size;
186 u8 log_rq_size;
187 u16 num_channels;
188 u8 default_vlan_prio;
189 u8 num_tc;
190 u16 rx_cq_moderation_usec;
191 u16 rx_cq_moderation_pkts;
192 u16 tx_cq_moderation_usec;
193 u16 tx_cq_moderation_pkts;
194 u16 min_rx_wqes;
195 u16 rx_hash_log_tbl_sz;
196 bool lro_en;
197 u32 lro_wqe_sz;
2be6967c 198 u8 rss_hfunc;
f62b8bb8
AV
199};
200
201enum {
202 MLX5E_RQ_STATE_POST_WQES_ENABLE,
203};
204
205enum cq_flags {
206 MLX5E_CQ_HAS_CQES = 1,
207};
208
209struct mlx5e_cq {
210 /* data path - accessed per cqe */
211 struct mlx5_cqwq wq;
f62b8bb8
AV
212 unsigned long flags;
213
214 /* data path - accessed per napi poll */
215 struct napi_struct *napi;
216 struct mlx5_core_cq mcq;
217 struct mlx5e_channel *channel;
218
219 /* control */
220 struct mlx5_wq_ctrl wq_ctrl;
221} ____cacheline_aligned_in_smp;
222
223struct mlx5e_rq {
224 /* data path */
225 struct mlx5_wq_ll wq;
226 u32 wqe_sz;
227 struct sk_buff **skb;
228
229 struct device *pdev;
230 struct net_device *netdev;
231 struct mlx5e_rq_stats stats;
232 struct mlx5e_cq cq;
233
234 unsigned long state;
235 int ix;
236
237 /* control */
238 struct mlx5_wq_ctrl wq_ctrl;
239 u32 rqn;
240 struct mlx5e_channel *channel;
241} ____cacheline_aligned_in_smp;
242
243struct mlx5e_tx_skb_cb {
244 u32 num_bytes;
245 u8 num_wqebbs;
246 u8 num_dma;
247};
248
249#define MLX5E_TX_SKB_CB(__skb) ((struct mlx5e_tx_skb_cb *)__skb->cb)
250
251struct mlx5e_sq_dma {
252 dma_addr_t addr;
253 u32 size;
254};
255
256enum {
257 MLX5E_SQ_STATE_WAKE_TXQ_ENABLE,
258};
259
260struct mlx5e_sq {
261 /* data path */
262
263 /* dirtied @completion */
264 u16 cc;
265 u32 dma_fifo_cc;
266
267 /* dirtied @xmit */
268 u16 pc ____cacheline_aligned_in_smp;
269 u32 dma_fifo_pc;
270 u32 bf_offset;
271 struct mlx5e_sq_stats stats;
272
273 struct mlx5e_cq cq;
274
275 /* pointers to per packet info: write@xmit, read@completion */
276 struct sk_buff **skb;
277 struct mlx5e_sq_dma *dma_fifo;
278
279 /* read only */
280 struct mlx5_wq_cyc wq;
281 u32 dma_fifo_mask;
282 void __iomem *uar_map;
283 struct netdev_queue *txq;
284 u32 sqn;
285 u32 bf_buf_size;
12be4b21
SM
286 u16 max_inline;
287 u16 edge;
f62b8bb8
AV
288 struct device *pdev;
289 __be32 mkey_be;
290 unsigned long state;
291
292 /* control path */
293 struct mlx5_wq_ctrl wq_ctrl;
294 struct mlx5_uar uar;
295 struct mlx5e_channel *channel;
296 int tc;
297} ____cacheline_aligned_in_smp;
298
299static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
300{
301 return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
302 (sq->cc == sq->pc));
303}
304
305enum channel_flags {
306 MLX5E_CHANNEL_NAPI_SCHED = 1,
307};
308
309struct mlx5e_channel {
310 /* data path */
311 struct mlx5e_rq rq;
312 struct mlx5e_sq sq[MLX5E_MAX_NUM_TC];
313 struct napi_struct napi;
314 struct device *pdev;
315 struct net_device *netdev;
316 __be32 mkey_be;
317 u8 num_tc;
318 unsigned long flags;
03289b88 319 int tc_to_txq_map[MLX5E_MAX_NUM_TC];
f62b8bb8
AV
320
321 /* control */
322 struct mlx5e_priv *priv;
323 int ix;
324 int cpu;
325};
326
327enum mlx5e_traffic_types {
328 MLX5E_TT_IPV4_TCP = 0,
329 MLX5E_TT_IPV6_TCP = 1,
330 MLX5E_TT_IPV4_UDP = 2,
331 MLX5E_TT_IPV6_UDP = 3,
332 MLX5E_TT_IPV4 = 4,
333 MLX5E_TT_IPV6 = 5,
334 MLX5E_TT_ANY = 6,
335 MLX5E_NUM_TT = 7,
336};
337
338enum {
339 MLX5E_RQT_SPREADING = 0,
340 MLX5E_RQT_DEFAULT_RQ = 1,
341 MLX5E_NUM_RQT = 2,
342};
343
344struct mlx5e_eth_addr_info {
345 u8 addr[ETH_ALEN + 2];
346 u32 tt_vec;
347 u32 ft_ix[MLX5E_NUM_TT]; /* flow table index per traffic type */
348};
349
350#define MLX5E_ETH_ADDR_HASH_SIZE (1 << BITS_PER_BYTE)
351
352struct mlx5e_eth_addr_db {
353 struct hlist_head netdev_uc[MLX5E_ETH_ADDR_HASH_SIZE];
354 struct hlist_head netdev_mc[MLX5E_ETH_ADDR_HASH_SIZE];
355 struct mlx5e_eth_addr_info broadcast;
356 struct mlx5e_eth_addr_info allmulti;
357 struct mlx5e_eth_addr_info promisc;
358 bool broadcast_enabled;
359 bool allmulti_enabled;
360 bool promisc_enabled;
361};
362
363enum {
364 MLX5E_STATE_ASYNC_EVENTS_ENABLE,
365 MLX5E_STATE_OPENED,
366};
367
368struct mlx5e_vlan_db {
369 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
370 u32 active_vlans_ft_ix[VLAN_N_VID];
371 u32 untagged_rule_ft_ix;
372 u32 any_vlan_rule_ft_ix;
373 bool filter_disabled;
374};
375
376struct mlx5e_flow_table {
377 void *vlan;
378 void *main;
379};
380
381struct mlx5e_priv {
382 /* priv data path fields - start */
f62b8bb8
AV
383 int num_tc;
384 int default_vlan_prio;
03289b88 385 struct mlx5e_sq **txq_to_sq_map;
f62b8bb8
AV
386 /* priv data path fields - end */
387
388 unsigned long state;
389 struct mutex state_lock; /* Protects Interface state */
390 struct mlx5_uar cq_uar;
391 u32 pdn;
3191e05f 392 u32 tdn;
f62b8bb8
AV
393 struct mlx5_core_mr mr;
394
395 struct mlx5e_channel **channel;
396 u32 tisn[MLX5E_MAX_NUM_TC];
397 u32 rqtn;
398 u32 tirn[MLX5E_NUM_TT];
399
400 struct mlx5e_flow_table ft;
401 struct mlx5e_eth_addr_db eth_addr;
402 struct mlx5e_vlan_db vlan;
403
404 struct mlx5e_params params;
405 spinlock_t async_events_spinlock; /* sync hw events */
406 struct work_struct update_carrier_work;
407 struct work_struct set_rx_mode_work;
408 struct delayed_work update_stats_work;
409
410 struct mlx5_core_dev *mdev;
411 struct net_device *netdev;
412 struct mlx5e_stats stats;
413};
414
415#define MLX5E_NET_IP_ALIGN 2
416
417struct mlx5e_tx_wqe {
418 struct mlx5_wqe_ctrl_seg ctrl;
419 struct mlx5_wqe_eth_seg eth;
420};
421
422struct mlx5e_rx_wqe {
423 struct mlx5_wqe_srq_next_seg next;
424 struct mlx5_wqe_data_seg data;
425};
426
427enum mlx5e_link_mode {
428 MLX5E_1000BASE_CX_SGMII = 0,
429 MLX5E_1000BASE_KX = 1,
430 MLX5E_10GBASE_CX4 = 2,
431 MLX5E_10GBASE_KX4 = 3,
432 MLX5E_10GBASE_KR = 4,
433 MLX5E_20GBASE_KR2 = 5,
434 MLX5E_40GBASE_CR4 = 6,
435 MLX5E_40GBASE_KR4 = 7,
436 MLX5E_56GBASE_R4 = 8,
437 MLX5E_10GBASE_CR = 12,
438 MLX5E_10GBASE_SR = 13,
439 MLX5E_10GBASE_ER = 14,
440 MLX5E_40GBASE_SR4 = 15,
441 MLX5E_40GBASE_LR4 = 16,
442 MLX5E_100GBASE_CR4 = 20,
443 MLX5E_100GBASE_SR4 = 21,
444 MLX5E_100GBASE_KR4 = 22,
445 MLX5E_100GBASE_LR4 = 23,
446 MLX5E_100BASE_TX = 24,
447 MLX5E_100BASE_T = 25,
448 MLX5E_10GBASE_T = 26,
449 MLX5E_25GBASE_CR = 27,
450 MLX5E_25GBASE_KR = 28,
451 MLX5E_25GBASE_SR = 29,
452 MLX5E_50GBASE_CR2 = 30,
453 MLX5E_50GBASE_KR2 = 31,
454 MLX5E_LINK_MODES_NUMBER,
455};
456
457#define MLX5E_PROT_MASK(link_mode) (1 << link_mode)
458
12be4b21 459void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
f62b8bb8
AV
460u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
461 void *accel_priv, select_queue_fallback_t fallback);
462netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
f62b8bb8
AV
463
464void mlx5e_completion_event(struct mlx5_core_cq *mcq);
465void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
466int mlx5e_napi_poll(struct napi_struct *napi, int budget);
467bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq);
468bool mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
469bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
470struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
471
472void mlx5e_update_stats(struct mlx5e_priv *priv);
473
474int mlx5e_open_flow_table(struct mlx5e_priv *priv);
475void mlx5e_close_flow_table(struct mlx5e_priv *priv);
476void mlx5e_init_eth_addr(struct mlx5e_priv *priv);
477void mlx5e_set_rx_mode_core(struct mlx5e_priv *priv);
478void mlx5e_set_rx_mode_work(struct work_struct *work);
479
480int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
481 u16 vid);
482int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
483 u16 vid);
484void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
485void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
486int mlx5e_add_all_vlan_rules(struct mlx5e_priv *priv);
487void mlx5e_del_all_vlan_rules(struct mlx5e_priv *priv);
488
489int mlx5e_open_locked(struct net_device *netdev);
490int mlx5e_close_locked(struct net_device *netdev);
491int mlx5e_update_priv_params(struct mlx5e_priv *priv,
492 struct mlx5e_params *new_params);
493
494static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
495 struct mlx5e_tx_wqe *wqe)
496{
497 /* ensure wqe is visible to device before updating doorbell record */
498 dma_wmb();
499
500 *sq->wq.db = cpu_to_be32(sq->pc);
501
502 /* ensure doorbell record is visible to device before ringing the
503 * doorbell
504 */
505 wmb();
506
507 mlx5_write64((__be32 *)&wqe->ctrl,
508 sq->uar_map + MLX5_BF_OFFSET + sq->bf_offset,
509 NULL);
510
511 sq->bf_offset ^= sq->bf_buf_size;
512}
513
514static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
515{
516 struct mlx5_core_cq *mcq;
517
518 mcq = &cq->mcq;
519 mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, NULL, cq->wq.cc);
520}
521
522extern const struct ethtool_ops mlx5e_ethtool_ops;