net/mlx5e: Have a single RSS Toeplitz hash key
[deliverable/linux.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 */
88a85f99 63#define MLX5E_SQ_BF_BUDGET 16
f62b8bb8
AV
64
65static const char vport_strings[][ETH_GSTRING_LEN] = {
66 /* vport statistics */
67 "rx_packets",
68 "rx_bytes",
69 "tx_packets",
70 "tx_bytes",
71 "rx_error_packets",
72 "rx_error_bytes",
73 "tx_error_packets",
74 "tx_error_bytes",
75 "rx_unicast_packets",
76 "rx_unicast_bytes",
77 "tx_unicast_packets",
78 "tx_unicast_bytes",
79 "rx_multicast_packets",
80 "rx_multicast_bytes",
81 "tx_multicast_packets",
82 "tx_multicast_bytes",
83 "rx_broadcast_packets",
84 "rx_broadcast_bytes",
85 "tx_broadcast_packets",
86 "tx_broadcast_bytes",
87
88 /* SW counters */
89 "tso_packets",
90 "tso_bytes",
91 "lro_packets",
92 "lro_bytes",
93 "rx_csum_good",
94 "rx_csum_none",
95 "tx_csum_offload",
96 "tx_queue_stopped",
97 "tx_queue_wake",
98 "tx_queue_dropped",
99 "rx_wqe_err",
100};
101
102struct mlx5e_vport_stats {
103 /* HW counters */
104 u64 rx_packets;
105 u64 rx_bytes;
106 u64 tx_packets;
107 u64 tx_bytes;
108 u64 rx_error_packets;
109 u64 rx_error_bytes;
110 u64 tx_error_packets;
111 u64 tx_error_bytes;
112 u64 rx_unicast_packets;
113 u64 rx_unicast_bytes;
114 u64 tx_unicast_packets;
115 u64 tx_unicast_bytes;
116 u64 rx_multicast_packets;
117 u64 rx_multicast_bytes;
118 u64 tx_multicast_packets;
119 u64 tx_multicast_bytes;
120 u64 rx_broadcast_packets;
121 u64 rx_broadcast_bytes;
122 u64 tx_broadcast_packets;
123 u64 tx_broadcast_bytes;
124
125 /* SW counters */
126 u64 tso_packets;
127 u64 tso_bytes;
128 u64 lro_packets;
129 u64 lro_bytes;
130 u64 rx_csum_good;
131 u64 rx_csum_none;
132 u64 tx_csum_offload;
133 u64 tx_queue_stopped;
134 u64 tx_queue_wake;
135 u64 tx_queue_dropped;
136 u64 rx_wqe_err;
137
138#define NUM_VPORT_COUNTERS 31
139};
140
efea389d
GP
141static const char pport_strings[][ETH_GSTRING_LEN] = {
142 /* IEEE802.3 counters */
143 "frames_tx",
144 "frames_rx",
145 "check_seq_err",
146 "alignment_err",
147 "octets_tx",
148 "octets_received",
149 "multicast_xmitted",
150 "broadcast_xmitted",
151 "multicast_rx",
152 "broadcast_rx",
153 "in_range_len_errors",
154 "out_of_range_len",
155 "too_long_errors",
156 "symbol_err",
157 "mac_control_tx",
158 "mac_control_rx",
159 "unsupported_op_rx",
160 "pause_ctrl_rx",
161 "pause_ctrl_tx",
162
163 /* RFC2863 counters */
164 "in_octets",
165 "in_ucast_pkts",
166 "in_discards",
167 "in_errors",
168 "in_unknown_protos",
169 "out_octets",
170 "out_ucast_pkts",
171 "out_discards",
172 "out_errors",
173 "in_multicast_pkts",
174 "in_broadcast_pkts",
175 "out_multicast_pkts",
176 "out_broadcast_pkts",
177
178 /* RFC2819 counters */
179 "drop_events",
180 "octets",
181 "pkts",
182 "broadcast_pkts",
183 "multicast_pkts",
184 "crc_align_errors",
185 "undersize_pkts",
186 "oversize_pkts",
187 "fragments",
188 "jabbers",
189 "collisions",
190 "p64octets",
191 "p65to127octets",
192 "p128to255octets",
193 "p256to511octets",
194 "p512to1023octets",
195 "p1024to1518octets",
196 "p1519to2047octets",
197 "p2048to4095octets",
198 "p4096to8191octets",
199 "p8192to10239octets",
200};
201
202#define NUM_IEEE_802_3_COUNTERS 19
203#define NUM_RFC_2863_COUNTERS 13
204#define NUM_RFC_2819_COUNTERS 21
205#define NUM_PPORT_COUNTERS (NUM_IEEE_802_3_COUNTERS + \
206 NUM_RFC_2863_COUNTERS + \
207 NUM_RFC_2819_COUNTERS)
208
209struct mlx5e_pport_stats {
210 __be64 IEEE_802_3_counters[NUM_IEEE_802_3_COUNTERS];
211 __be64 RFC_2863_counters[NUM_RFC_2863_COUNTERS];
212 __be64 RFC_2819_counters[NUM_RFC_2819_COUNTERS];
213};
214
f62b8bb8
AV
215static const char rq_stats_strings[][ETH_GSTRING_LEN] = {
216 "packets",
217 "csum_none",
218 "lro_packets",
219 "lro_bytes",
220 "wqe_err"
221};
222
223struct mlx5e_rq_stats {
224 u64 packets;
225 u64 csum_none;
226 u64 lro_packets;
227 u64 lro_bytes;
228 u64 wqe_err;
229#define NUM_RQ_STATS 5
230};
231
232static const char sq_stats_strings[][ETH_GSTRING_LEN] = {
233 "packets",
234 "tso_packets",
235 "tso_bytes",
236 "csum_offload_none",
237 "stopped",
238 "wake",
239 "dropped",
240 "nop"
241};
242
243struct mlx5e_sq_stats {
244 u64 packets;
245 u64 tso_packets;
246 u64 tso_bytes;
247 u64 csum_offload_none;
248 u64 stopped;
249 u64 wake;
250 u64 dropped;
251 u64 nop;
252#define NUM_SQ_STATS 8
253};
254
255struct mlx5e_stats {
256 struct mlx5e_vport_stats vport;
efea389d 257 struct mlx5e_pport_stats pport;
f62b8bb8
AV
258};
259
260struct mlx5e_params {
261 u8 log_sq_size;
262 u8 log_rq_size;
263 u16 num_channels;
264 u8 default_vlan_prio;
265 u8 num_tc;
266 u16 rx_cq_moderation_usec;
267 u16 rx_cq_moderation_pkts;
268 u16 tx_cq_moderation_usec;
269 u16 tx_cq_moderation_pkts;
270 u16 min_rx_wqes;
271 u16 rx_hash_log_tbl_sz;
272 bool lro_en;
273 u32 lro_wqe_sz;
2be6967c 274 u8 rss_hfunc;
58d52291 275 u16 tx_max_inline;
57afead5 276 u8 toeplitz_hash_key[40];
f62b8bb8
AV
277};
278
279enum {
280 MLX5E_RQ_STATE_POST_WQES_ENABLE,
281};
282
283enum cq_flags {
284 MLX5E_CQ_HAS_CQES = 1,
285};
286
287struct mlx5e_cq {
288 /* data path - accessed per cqe */
289 struct mlx5_cqwq wq;
f62b8bb8
AV
290 unsigned long flags;
291
292 /* data path - accessed per napi poll */
293 struct napi_struct *napi;
294 struct mlx5_core_cq mcq;
295 struct mlx5e_channel *channel;
50cfa25a 296 struct mlx5e_priv *priv;
f62b8bb8
AV
297
298 /* control */
299 struct mlx5_wq_ctrl wq_ctrl;
300} ____cacheline_aligned_in_smp;
301
302struct mlx5e_rq {
303 /* data path */
304 struct mlx5_wq_ll wq;
305 u32 wqe_sz;
306 struct sk_buff **skb;
307
308 struct device *pdev;
309 struct net_device *netdev;
310 struct mlx5e_rq_stats stats;
311 struct mlx5e_cq cq;
312
313 unsigned long state;
314 int ix;
315
316 /* control */
317 struct mlx5_wq_ctrl wq_ctrl;
318 u32 rqn;
319 struct mlx5e_channel *channel;
50cfa25a 320 struct mlx5e_priv *priv;
f62b8bb8
AV
321} ____cacheline_aligned_in_smp;
322
323struct mlx5e_tx_skb_cb {
324 u32 num_bytes;
325 u8 num_wqebbs;
326 u8 num_dma;
327};
328
329#define MLX5E_TX_SKB_CB(__skb) ((struct mlx5e_tx_skb_cb *)__skb->cb)
330
331struct mlx5e_sq_dma {
332 dma_addr_t addr;
333 u32 size;
334};
335
336enum {
337 MLX5E_SQ_STATE_WAKE_TXQ_ENABLE,
338};
339
340struct mlx5e_sq {
341 /* data path */
342
343 /* dirtied @completion */
344 u16 cc;
345 u32 dma_fifo_cc;
346
347 /* dirtied @xmit */
348 u16 pc ____cacheline_aligned_in_smp;
349 u32 dma_fifo_pc;
88a85f99
AS
350 u16 bf_offset;
351 u16 prev_cc;
352 u8 bf_budget;
f62b8bb8
AV
353 struct mlx5e_sq_stats stats;
354
355 struct mlx5e_cq cq;
356
357 /* pointers to per packet info: write@xmit, read@completion */
358 struct sk_buff **skb;
359 struct mlx5e_sq_dma *dma_fifo;
360
361 /* read only */
362 struct mlx5_wq_cyc wq;
363 u32 dma_fifo_mask;
364 void __iomem *uar_map;
88a85f99 365 void __iomem *uar_bf_map;
f62b8bb8
AV
366 struct netdev_queue *txq;
367 u32 sqn;
88a85f99 368 u16 bf_buf_size;
12be4b21
SM
369 u16 max_inline;
370 u16 edge;
f62b8bb8
AV
371 struct device *pdev;
372 __be32 mkey_be;
373 unsigned long state;
374
375 /* control path */
376 struct mlx5_wq_ctrl wq_ctrl;
377 struct mlx5_uar uar;
378 struct mlx5e_channel *channel;
379 int tc;
380} ____cacheline_aligned_in_smp;
381
382static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
383{
384 return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
385 (sq->cc == sq->pc));
386}
387
388enum channel_flags {
389 MLX5E_CHANNEL_NAPI_SCHED = 1,
390};
391
392struct mlx5e_channel {
393 /* data path */
394 struct mlx5e_rq rq;
395 struct mlx5e_sq sq[MLX5E_MAX_NUM_TC];
396 struct napi_struct napi;
397 struct device *pdev;
398 struct net_device *netdev;
399 __be32 mkey_be;
400 u8 num_tc;
401 unsigned long flags;
03289b88 402 int tc_to_txq_map[MLX5E_MAX_NUM_TC];
f62b8bb8
AV
403
404 /* control */
405 struct mlx5e_priv *priv;
406 int ix;
407 int cpu;
408};
409
410enum mlx5e_traffic_types {
5a6f8aef
AS
411 MLX5E_TT_IPV4_TCP,
412 MLX5E_TT_IPV6_TCP,
413 MLX5E_TT_IPV4_UDP,
414 MLX5E_TT_IPV6_UDP,
a741749f
AS
415 MLX5E_TT_IPV4_IPSEC_AH,
416 MLX5E_TT_IPV6_IPSEC_AH,
417 MLX5E_TT_IPV4_IPSEC_ESP,
418 MLX5E_TT_IPV6_IPSEC_ESP,
5a6f8aef
AS
419 MLX5E_TT_IPV4,
420 MLX5E_TT_IPV6,
421 MLX5E_TT_ANY,
422 MLX5E_NUM_TT,
f62b8bb8
AV
423};
424
4cbeaff5
AS
425enum mlx5e_rqt_ix {
426 MLX5E_INDIRECTION_RQT,
427 MLX5E_SINGLE_RQ_RQT,
428 MLX5E_NUM_RQT,
f62b8bb8
AV
429};
430
431struct mlx5e_eth_addr_info {
432 u8 addr[ETH_ALEN + 2];
433 u32 tt_vec;
434 u32 ft_ix[MLX5E_NUM_TT]; /* flow table index per traffic type */
435};
436
437#define MLX5E_ETH_ADDR_HASH_SIZE (1 << BITS_PER_BYTE)
438
439struct mlx5e_eth_addr_db {
440 struct hlist_head netdev_uc[MLX5E_ETH_ADDR_HASH_SIZE];
441 struct hlist_head netdev_mc[MLX5E_ETH_ADDR_HASH_SIZE];
442 struct mlx5e_eth_addr_info broadcast;
443 struct mlx5e_eth_addr_info allmulti;
444 struct mlx5e_eth_addr_info promisc;
445 bool broadcast_enabled;
446 bool allmulti_enabled;
447 bool promisc_enabled;
448};
449
450enum {
451 MLX5E_STATE_ASYNC_EVENTS_ENABLE,
452 MLX5E_STATE_OPENED,
9b37b07f 453 MLX5E_STATE_DESTROYING,
f62b8bb8
AV
454};
455
456struct mlx5e_vlan_db {
f62b8bb8
AV
457 u32 active_vlans_ft_ix[VLAN_N_VID];
458 u32 untagged_rule_ft_ix;
459 u32 any_vlan_rule_ft_ix;
460 bool filter_disabled;
461};
462
463struct mlx5e_flow_table {
464 void *vlan;
465 void *main;
466};
467
468struct mlx5e_priv {
469 /* priv data path fields - start */
f62b8bb8 470 int default_vlan_prio;
03289b88 471 struct mlx5e_sq **txq_to_sq_map;
f62b8bb8
AV
472 /* priv data path fields - end */
473
474 unsigned long state;
475 struct mutex state_lock; /* Protects Interface state */
476 struct mlx5_uar cq_uar;
477 u32 pdn;
3191e05f 478 u32 tdn;
f62b8bb8 479 struct mlx5_core_mr mr;
50cfa25a 480 struct mlx5e_rq drop_rq;
f62b8bb8
AV
481
482 struct mlx5e_channel **channel;
483 u32 tisn[MLX5E_MAX_NUM_TC];
4cbeaff5 484 u32 rqtn[MLX5E_NUM_RQT];
f62b8bb8
AV
485 u32 tirn[MLX5E_NUM_TT];
486
487 struct mlx5e_flow_table ft;
488 struct mlx5e_eth_addr_db eth_addr;
489 struct mlx5e_vlan_db vlan;
490
491 struct mlx5e_params params;
492 spinlock_t async_events_spinlock; /* sync hw events */
493 struct work_struct update_carrier_work;
494 struct work_struct set_rx_mode_work;
495 struct delayed_work update_stats_work;
496
497 struct mlx5_core_dev *mdev;
498 struct net_device *netdev;
499 struct mlx5e_stats stats;
500};
501
502#define MLX5E_NET_IP_ALIGN 2
503
504struct mlx5e_tx_wqe {
505 struct mlx5_wqe_ctrl_seg ctrl;
506 struct mlx5_wqe_eth_seg eth;
507};
508
509struct mlx5e_rx_wqe {
510 struct mlx5_wqe_srq_next_seg next;
511 struct mlx5_wqe_data_seg data;
512};
513
514enum mlx5e_link_mode {
515 MLX5E_1000BASE_CX_SGMII = 0,
516 MLX5E_1000BASE_KX = 1,
517 MLX5E_10GBASE_CX4 = 2,
518 MLX5E_10GBASE_KX4 = 3,
519 MLX5E_10GBASE_KR = 4,
520 MLX5E_20GBASE_KR2 = 5,
521 MLX5E_40GBASE_CR4 = 6,
522 MLX5E_40GBASE_KR4 = 7,
523 MLX5E_56GBASE_R4 = 8,
524 MLX5E_10GBASE_CR = 12,
525 MLX5E_10GBASE_SR = 13,
526 MLX5E_10GBASE_ER = 14,
527 MLX5E_40GBASE_SR4 = 15,
528 MLX5E_40GBASE_LR4 = 16,
529 MLX5E_100GBASE_CR4 = 20,
530 MLX5E_100GBASE_SR4 = 21,
531 MLX5E_100GBASE_KR4 = 22,
532 MLX5E_100GBASE_LR4 = 23,
533 MLX5E_100BASE_TX = 24,
534 MLX5E_100BASE_T = 25,
535 MLX5E_10GBASE_T = 26,
536 MLX5E_25GBASE_CR = 27,
537 MLX5E_25GBASE_KR = 28,
538 MLX5E_25GBASE_SR = 29,
539 MLX5E_50GBASE_CR2 = 30,
540 MLX5E_50GBASE_KR2 = 31,
541 MLX5E_LINK_MODES_NUMBER,
542};
543
544#define MLX5E_PROT_MASK(link_mode) (1 << link_mode)
545
12be4b21 546void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
f62b8bb8
AV
547u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
548 void *accel_priv, select_queue_fallback_t fallback);
549netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
f62b8bb8
AV
550
551void mlx5e_completion_event(struct mlx5_core_cq *mcq);
552void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
553int mlx5e_napi_poll(struct napi_struct *napi, int budget);
554bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq);
555bool mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
556bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
557struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
558
559void mlx5e_update_stats(struct mlx5e_priv *priv);
560
40ab6a6e
AS
561int mlx5e_create_flow_tables(struct mlx5e_priv *priv);
562void mlx5e_destroy_flow_tables(struct mlx5e_priv *priv);
f62b8bb8 563void mlx5e_init_eth_addr(struct mlx5e_priv *priv);
f62b8bb8
AV
564void mlx5e_set_rx_mode_work(struct work_struct *work);
565
566int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
567 u16 vid);
568int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
569 u16 vid);
570void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
571void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
f62b8bb8
AV
572
573int mlx5e_open_locked(struct net_device *netdev);
574int mlx5e_close_locked(struct net_device *netdev);
f62b8bb8
AV
575
576static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
88a85f99 577 struct mlx5e_tx_wqe *wqe, int bf_sz)
f62b8bb8 578{
88a85f99
AS
579 u16 ofst = MLX5_BF_OFFSET + sq->bf_offset;
580
f62b8bb8
AV
581 /* ensure wqe is visible to device before updating doorbell record */
582 dma_wmb();
583
584 *sq->wq.db = cpu_to_be32(sq->pc);
585
586 /* ensure doorbell record is visible to device before ringing the
587 * doorbell
588 */
589 wmb();
590
88a85f99
AS
591 if (bf_sz) {
592 __iowrite64_copy(sq->uar_bf_map + ofst, &wqe->ctrl, bf_sz);
593
594 /* flush the write-combining mapped buffer */
595 wmb();
596
597 } else {
598 mlx5_write64((__be32 *)&wqe->ctrl, sq->uar_map + ofst, NULL);
599 }
f62b8bb8
AV
600
601 sq->bf_offset ^= sq->bf_buf_size;
602}
603
604static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
605{
606 struct mlx5_core_cq *mcq;
607
608 mcq = &cq->mcq;
609 mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, NULL, cq->wq.cc);
610}
611
612extern const struct ethtool_ops mlx5e_ethtool_ops;
58d52291 613u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
This page took 0.070374 seconds and 5 git commands to generate.