forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/net/ethernet/netronome/nfp/nfp_net.h
....@@ -1,35 +1,5 @@
1
-/*
2
- * Copyright (C) 2015-2017 Netronome Systems, Inc.
3
- *
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.
8
- *
9
- * The BSD 2-Clause License:
10
- *
11
- * Redistribution and use in source and binary forms, with or
12
- * without modification, are permitted provided that the following
13
- * conditions are met:
14
- *
15
- * 1. Redistributions of source code must retain the above
16
- * copyright notice, this list of conditions and the following
17
- * disclaimer.
18
- *
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.
23
- *
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
31
- * SOFTWARE.
32
- */
1
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2
+/* Copyright (C) 2015-2018 Netronome Systems, Inc. */
333
344 /*
355 * nfp_net.h
....@@ -42,11 +12,14 @@
4212 #ifndef _NFP_NET_H_
4313 #define _NFP_NET_H_
4414
15
+#include <linux/atomic.h>
4516 #include <linux/interrupt.h>
4617 #include <linux/list.h>
4718 #include <linux/netdevice.h>
4819 #include <linux/pci.h>
4920 #include <linux/io-64-nonatomic-hi-lo.h>
21
+#include <linux/semaphore.h>
22
+#include <linux/workqueue.h>
5023 #include <net/xdp.h>
5124
5225 #include "nfp_net_ctrl.h"
....@@ -93,7 +66,7 @@
9366 #define NFP_NET_MAX_DMA_BITS 40
9467
9568 /* Default size for MTU and freelist buffer sizes */
96
-#define NFP_NET_DEFAULT_MTU 1500
69
+#define NFP_NET_DEFAULT_MTU 1500U
9770
9871 /* Maximum number of bytes prepended to a packet */
9972 #define NFP_NET_MAX_PREPEND 64
....@@ -188,6 +161,7 @@
188161 __le16 data_len; /* Length of frame + meta data */
189162 } __packed;
190163 __le32 vals[4];
164
+ __le64 vals8[2];
191165 };
192166 };
193167
....@@ -267,7 +241,7 @@
267241 #define PCIE_DESC_RX_I_TCP_CSUM_OK cpu_to_le16(BIT(11))
268242 #define PCIE_DESC_RX_I_UDP_CSUM cpu_to_le16(BIT(10))
269243 #define PCIE_DESC_RX_I_UDP_CSUM_OK cpu_to_le16(BIT(9))
270
-#define PCIE_DESC_RX_BPF cpu_to_le16(BIT(8))
244
+#define PCIE_DESC_RX_DECRYPTED cpu_to_le16(BIT(8))
271245 #define PCIE_DESC_RX_EOP cpu_to_le16(BIT(7))
272246 #define PCIE_DESC_RX_IP4_CSUM cpu_to_le16(BIT(6))
273247 #define PCIE_DESC_RX_IP4_CSUM_OK cpu_to_le16(BIT(5))
....@@ -394,6 +368,7 @@
394368 * @hw_csum_rx_inner_ok: Counter of packets where the inner HW checksum was OK
395369 * @hw_csum_rx_complete: Counter of packets with CHECKSUM_COMPLETE reported
396370 * @hw_csum_rx_error: Counter of packets with bad checksums
371
+ * @hw_tls_rx: Number of packets with TLS decrypted by hardware
397372 * @tx_sync: Seqlock for atomic updates of TX stats
398373 * @tx_pkts: Number of Transmitted packets
399374 * @tx_bytes: Number of Transmitted bytes
....@@ -401,6 +376,11 @@
401376 * @hw_csum_tx_inner: Counter of inner TX checksum offload requests
402377 * @tx_gather: Counter of packets with Gather DMA
403378 * @tx_lso: Counter of LSO packets sent
379
+ * @hw_tls_tx: Counter of TLS packets sent with crypto offloaded to HW
380
+ * @tls_tx_fallback: Counter of TLS packets sent which had to be encrypted
381
+ * by the fallback path because packets came out of order
382
+ * @tls_tx_no_fallback: Counter of TLS packets not sent because the fallback
383
+ * path could not encrypt them
404384 * @tx_errors: How many TX errors were encountered
405385 * @tx_busy: How often was TX busy (no space)?
406386 * @rx_replace_buf_alloc_fail: Counter of RX buffer allocation failures
....@@ -421,7 +401,7 @@
421401 struct {
422402 struct tasklet_struct tasklet;
423403 struct sk_buff_head queue;
424
- struct spinlock lock;
404
+ spinlock_t lock;
425405 };
426406 };
427407
....@@ -437,21 +417,29 @@
437417 u64 hw_csum_rx_ok;
438418 u64 hw_csum_rx_inner_ok;
439419 u64 hw_csum_rx_complete;
420
+ u64 hw_tls_rx;
421
+
422
+ u64 hw_csum_rx_error;
423
+ u64 rx_replace_buf_alloc_fail;
440424
441425 struct nfp_net_tx_ring *xdp_ring;
442426
443427 struct u64_stats_sync tx_sync;
444428 u64 tx_pkts;
445429 u64 tx_bytes;
446
- u64 hw_csum_tx;
430
+
431
+ u64 ____cacheline_aligned_in_smp hw_csum_tx;
447432 u64 hw_csum_tx_inner;
448433 u64 tx_gather;
449434 u64 tx_lso;
435
+ u64 hw_tls_tx;
450436
451
- u64 hw_csum_rx_error;
452
- u64 rx_replace_buf_alloc_fail;
437
+ u64 tls_tx_fallback;
438
+ u64 tls_tx_no_fallback;
453439 u64 tx_errors;
454440 u64 tx_busy;
441
+
442
+ /* Cold data follows */
455443
456444 u32 irq_vector;
457445 irq_handler_t handler;
....@@ -487,6 +475,7 @@
487475 * @netdev: Backpointer to net_device structure
488476 * @is_vf: Is the driver attached to a VF?
489477 * @chained_metadata_format: Firemware will use new metadata format
478
+ * @ktls_tx: Is kTLS TX enabled?
490479 * @rx_dma_dir: Mapping direction for RX buffers
491480 * @rx_dma_off: Offset at which DMA packets (for XDP headroom)
492481 * @rx_offset: Offset in the RX buffers where packet data starts
....@@ -511,6 +500,7 @@
511500
512501 u8 is_vf:1;
513502 u8 chained_metadata_format:1;
503
+ u8 ktls_tx:1;
514504
515505 u8 rx_dma_dir;
516506 u8 rx_offset;
....@@ -567,24 +557,42 @@
567557 * @exn_name: Name for Exception interrupt
568558 * @shared_handler: Handler for shared interrupts
569559 * @shared_name: Name for shared interrupt
570
- * @me_freq_mhz: ME clock_freq (MHz)
571
- * @reconfig_lock: Protects HW reconfiguration request regs/machinery
560
+ * @reconfig_lock: Protects @reconfig_posted, @reconfig_timer_active,
561
+ * @reconfig_sync_present and HW reconfiguration request
562
+ * regs/machinery from async requests (sync must take
563
+ * @bar_lock)
572564 * @reconfig_posted: Pending reconfig bits coming from async sources
573565 * @reconfig_timer_active: Timer for reading reconfiguration results is pending
574566 * @reconfig_sync_present: Some thread is performing synchronous reconfig
575567 * @reconfig_timer: Timer for async reading of reconfig results
568
+ * @reconfig_in_progress_update: Update FW is processing now (debug only)
569
+ * @bar_lock: vNIC config BAR access lock, protects: update,
570
+ * mailbox area, crypto TLV
576571 * @link_up: Is the link up?
577572 * @link_status_lock: Protects @link_* and ensures atomicity with BAR reading
578573 * @rx_coalesce_usecs: RX interrupt moderation usecs delay parameter
579574 * @rx_coalesce_max_frames: RX interrupt moderation frame count parameter
580575 * @tx_coalesce_usecs: TX interrupt moderation usecs delay parameter
581576 * @tx_coalesce_max_frames: TX interrupt moderation frame count parameter
582
- * @vxlan_ports: VXLAN ports for RX inner csum offload communicated to HW
583
- * @vxlan_usecnt: IPv4/IPv6 VXLAN port use counts
584577 * @qcp_cfg: Pointer to QCP queue used for configuration notification
585578 * @tx_bar: Pointer to mapped TX queues
586579 * @rx_bar: Pointer to mapped FL/RX queues
587580 * @tlv_caps: Parsed TLV capabilities
581
+ * @ktls_tx_conn_cnt: Number of offloaded kTLS TX connections
582
+ * @ktls_rx_conn_cnt: Number of offloaded kTLS RX connections
583
+ * @ktls_conn_id_gen: Trivial generator for kTLS connection ids (for TX)
584
+ * @ktls_no_space: Counter of firmware rejecting kTLS connection due to
585
+ * lack of space
586
+ * @ktls_rx_resync_req: Counter of TLS RX resync requested
587
+ * @ktls_rx_resync_ign: Counter of TLS RX resync requests ignored
588
+ * @ktls_rx_resync_sent: Counter of TLS RX resync completed
589
+ * @mbox_cmsg: Common Control Message via vNIC mailbox state
590
+ * @mbox_cmsg.queue: CCM mbox queue of pending messages
591
+ * @mbox_cmsg.wq: CCM mbox wait queue of waiting processes
592
+ * @mbox_cmsg.workq: CCM mbox work queue for @wait_work and @runq_work
593
+ * @mbox_cmsg.wait_work: CCM mbox posted msg reconfig wait work
594
+ * @mbox_cmsg.runq_work: CCM mbox posted msg queue runner work
595
+ * @mbox_cmsg.tag: CCM mbox message tag allocator
588596 * @debugfs_dir: Device directory in debugfs
589597 * @vnic_list: Entry on device vNIC list
590598 * @pdev: Backpointer to PCI device
....@@ -631,8 +639,6 @@
631639 irq_handler_t shared_handler;
632640 char shared_name[IFNAMSIZ + 8];
633641
634
- u32 me_freq_mhz;
635
-
636642 bool link_up;
637643 spinlock_t link_status_lock;
638644
....@@ -641,14 +647,14 @@
641647 bool reconfig_timer_active;
642648 bool reconfig_sync_present;
643649 struct timer_list reconfig_timer;
650
+ u32 reconfig_in_progress_update;
651
+
652
+ struct semaphore bar_lock;
644653
645654 u32 rx_coalesce_usecs;
646655 u32 rx_coalesce_max_frames;
647656 u32 tx_coalesce_usecs;
648657 u32 tx_coalesce_max_frames;
649
-
650
- __be16 vxlan_ports[NFP_NET_N_VXLAN_PORTS];
651
- u8 vxlan_usecnt[NFP_NET_N_VXLAN_PORTS];
652658
653659 u8 __iomem *qcp_cfg;
654660
....@@ -656,6 +662,25 @@
656662 u8 __iomem *rx_bar;
657663
658664 struct nfp_net_tlv_caps tlv_caps;
665
+
666
+ unsigned int ktls_tx_conn_cnt;
667
+ unsigned int ktls_rx_conn_cnt;
668
+
669
+ atomic64_t ktls_conn_id_gen;
670
+
671
+ atomic_t ktls_no_space;
672
+ atomic_t ktls_rx_resync_req;
673
+ atomic_t ktls_rx_resync_ign;
674
+ atomic_t ktls_rx_resync_sent;
675
+
676
+ struct {
677
+ struct sk_buff_head queue;
678
+ wait_queue_head_t wq;
679
+ struct workqueue_struct *workq;
680
+ struct work_struct wait_work;
681
+ struct work_struct runq_work;
682
+ u16 tag;
683
+ } mbox_cmsg;
659684
660685 struct dentry *debugfs_dir;
661686
....@@ -866,6 +891,21 @@
866891 spin_unlock_bh(&nn->r_vecs[0].lock);
867892 }
868893
894
+static inline void nn_ctrl_bar_lock(struct nfp_net *nn)
895
+{
896
+ down(&nn->bar_lock);
897
+}
898
+
899
+static inline bool nn_ctrl_bar_trylock(struct nfp_net *nn)
900
+{
901
+ return !down_trylock(&nn->bar_lock);
902
+}
903
+
904
+static inline void nn_ctrl_bar_unlock(struct nfp_net *nn)
905
+{
906
+ up(&nn->bar_lock);
907
+}
908
+
869909 /* Globals */
870910 extern const char nfp_driver_version[];
871911
....@@ -881,7 +921,7 @@
881921 void __iomem *ctrl_bar);
882922
883923 struct nfp_net *
884
-nfp_net_alloc(struct pci_dev *pdev, bool needs_netdev,
924
+nfp_net_alloc(struct pci_dev *pdev, void __iomem *ctrl_bar, bool needs_netdev,
885925 unsigned int max_tx_rings, unsigned int max_rx_rings);
886926 void nfp_net_free(struct nfp_net *nn);
887927
....@@ -893,11 +933,17 @@
893933
894934 void nfp_net_set_ethtool_ops(struct net_device *netdev);
895935 void nfp_net_info(struct nfp_net *nn);
936
+int __nfp_net_reconfig(struct nfp_net *nn, u32 update);
896937 int nfp_net_reconfig(struct nfp_net *nn, u32 update);
897938 unsigned int nfp_net_rss_key_sz(struct nfp_net *nn);
898939 void nfp_net_rss_write_itbl(struct nfp_net *nn);
899940 void nfp_net_rss_write_key(struct nfp_net *nn);
900941 void nfp_net_coalesce_write_cfg(struct nfp_net *nn);
942
+int nfp_net_mbox_lock(struct nfp_net *nn, unsigned int data_size);
943
+int nfp_net_mbox_reconfig(struct nfp_net *nn, u32 mbox_cmd);
944
+int nfp_net_mbox_reconfig_and_unlock(struct nfp_net *nn, u32 mbox_cmd);
945
+void nfp_net_mbox_reconfig_post(struct nfp_net *nn, u32 update);
946
+int nfp_net_mbox_reconfig_wait_posted(struct nfp_net *nn);
901947
902948 unsigned int
903949 nfp_net_irqs_alloc(struct pci_dev *pdev, struct msix_entry *irq_entries,