xref: /linux/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige.h (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
1 /* SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause */
2 
3 /* Header file for Gigabit Ethernet driver for Mellanox BlueField SoC
4  * - this file contains software data structures and any chip-specific
5  *   data structures (e.g. TX WQE format) that are memory resident.
6  *
7  * Copyright (C) 2020-2021 NVIDIA CORPORATION & AFFILIATES
8  */
9 
10 #ifndef __MLXBF_GIGE_H__
11 #define __MLXBF_GIGE_H__
12 
13 #include <linux/io-64-nonatomic-lo-hi.h>
14 #include <linux/irqreturn.h>
15 #include <linux/netdevice.h>
16 #include <linux/irq.h>
17 
18 /* The silicon design supports a maximum RX ring size of
19  * 32K entries. Based on current testing this maximum size
20  * is not required to be supported.  Instead the RX ring
21  * will be capped at a realistic value of 1024 entries.
22  */
23 #define MLXBF_GIGE_MIN_RXQ_SZ     32
24 #define MLXBF_GIGE_MAX_RXQ_SZ     1024
25 #define MLXBF_GIGE_DEFAULT_RXQ_SZ 128
26 
27 #define MLXBF_GIGE_MIN_TXQ_SZ     4
28 #define MLXBF_GIGE_MAX_TXQ_SZ     256
29 #define MLXBF_GIGE_DEFAULT_TXQ_SZ 128
30 
31 #define MLXBF_GIGE_DEFAULT_BUF_SZ 2048
32 
33 #define MLXBF_GIGE_DMA_PAGE_SZ    4096
34 #define MLXBF_GIGE_DMA_PAGE_SHIFT 12
35 
36 /* There are four individual MAC RX filters. Currently
37  * two of them are being used: one for the broadcast MAC
38  * (index 0) and one for local MAC (index 1)
39  */
40 #define MLXBF_GIGE_BCAST_MAC_FILTER_IDX 0
41 #define MLXBF_GIGE_LOCAL_MAC_FILTER_IDX 1
42 
43 /* Define for broadcast MAC literal */
44 #define BCAST_MAC_ADDR 0xFFFFFFFFFFFF
45 
46 /* There are three individual interrupts:
47  *   1) Errors, "OOB" interrupt line
48  *   2) Receive Packet, "OOB_LLU" interrupt line
49  *   3) LLU and PLU Events, "OOB_PLU" interrupt line
50  */
51 #define MLXBF_GIGE_ERROR_INTR_IDX       0
52 #define MLXBF_GIGE_RECEIVE_PKT_INTR_IDX 1
53 #define MLXBF_GIGE_LLU_PLU_INTR_IDX     2
54 
55 struct mlxbf_gige_stats {
56 	u64 hw_access_errors;
57 	u64 tx_invalid_checksums;
58 	u64 tx_small_frames;
59 	u64 tx_index_errors;
60 	u64 sw_config_errors;
61 	u64 sw_access_errors;
62 	u64 rx_truncate_errors;
63 	u64 rx_mac_errors;
64 	u64 rx_din_dropped_pkts;
65 	u64 tx_fifo_full;
66 	u64 rx_filter_passed_pkts;
67 	u64 rx_filter_discard_pkts;
68 };
69 
70 struct mlxbf_gige {
71 	void __iomem *base;
72 	void __iomem *llu_base;
73 	void __iomem *plu_base;
74 	struct device *dev;
75 	struct net_device *netdev;
76 	struct platform_device *pdev;
77 	void __iomem *mdio_io;
78 	struct mii_bus *mdiobus;
79 	spinlock_t lock;      /* for packet processing indices */
80 	u16 rx_q_entries;
81 	u16 tx_q_entries;
82 	u64 *tx_wqe_base;
83 	dma_addr_t tx_wqe_base_dma;
84 	u64 *tx_wqe_next;
85 	u64 *tx_cc;
86 	dma_addr_t tx_cc_dma;
87 	dma_addr_t *rx_wqe_base;
88 	dma_addr_t rx_wqe_base_dma;
89 	u64 *rx_cqe_base;
90 	dma_addr_t rx_cqe_base_dma;
91 	u16 tx_pi;
92 	u16 prev_tx_ci;
93 	u64 error_intr_count;
94 	u64 rx_intr_count;
95 	u64 llu_plu_intr_count;
96 	struct sk_buff *rx_skb[MLXBF_GIGE_MAX_RXQ_SZ];
97 	struct sk_buff *tx_skb[MLXBF_GIGE_MAX_TXQ_SZ];
98 	int error_irq;
99 	int rx_irq;
100 	int llu_plu_irq;
101 	int phy_irq;
102 	int hw_phy_irq;
103 	bool promisc_enabled;
104 	u8 valid_polarity;
105 	struct napi_struct napi;
106 	struct mlxbf_gige_stats stats;
107 };
108 
109 /* Rx Work Queue Element definitions */
110 #define MLXBF_GIGE_RX_WQE_SZ                   8
111 
112 /* Rx Completion Queue Element definitions */
113 #define MLXBF_GIGE_RX_CQE_SZ                   8
114 #define MLXBF_GIGE_RX_CQE_PKT_LEN_MASK         GENMASK(10, 0)
115 #define MLXBF_GIGE_RX_CQE_VALID_MASK           GENMASK(11, 11)
116 #define MLXBF_GIGE_RX_CQE_PKT_STATUS_MASK      GENMASK(15, 12)
117 #define MLXBF_GIGE_RX_CQE_PKT_STATUS_MAC_ERR   GENMASK(12, 12)
118 #define MLXBF_GIGE_RX_CQE_PKT_STATUS_TRUNCATED GENMASK(13, 13)
119 #define MLXBF_GIGE_RX_CQE_CHKSUM_MASK          GENMASK(31, 16)
120 
121 /* Tx Work Queue Element definitions */
122 #define MLXBF_GIGE_TX_WQE_SZ_QWORDS            2
123 #define MLXBF_GIGE_TX_WQE_SZ                   16
124 #define MLXBF_GIGE_TX_WQE_PKT_LEN_MASK         GENMASK(10, 0)
125 #define MLXBF_GIGE_TX_WQE_UPDATE_MASK          GENMASK(31, 31)
126 #define MLXBF_GIGE_TX_WQE_CHKSUM_LEN_MASK      GENMASK(42, 32)
127 #define MLXBF_GIGE_TX_WQE_CHKSUM_START_MASK    GENMASK(55, 48)
128 #define MLXBF_GIGE_TX_WQE_CHKSUM_OFFSET_MASK   GENMASK(63, 56)
129 
130 /* Macro to return packet length of specified TX WQE */
131 #define MLXBF_GIGE_TX_WQE_PKT_LEN(tx_wqe_addr) \
132 	(*((tx_wqe_addr) + 1) & MLXBF_GIGE_TX_WQE_PKT_LEN_MASK)
133 
134 /* Tx Completion Count */
135 #define MLXBF_GIGE_TX_CC_SZ                    8
136 
137 /* List of resources in ACPI table */
138 enum mlxbf_gige_res {
139 	MLXBF_GIGE_RES_MAC,
140 	MLXBF_GIGE_RES_MDIO9,
141 	MLXBF_GIGE_RES_GPIO0,
142 	MLXBF_GIGE_RES_LLU,
143 	MLXBF_GIGE_RES_PLU
144 };
145 
146 /* Version of register data returned by mlxbf_gige_get_regs() */
147 #define MLXBF_GIGE_REGS_VERSION 1
148 
149 int mlxbf_gige_mdio_probe(struct platform_device *pdev,
150 			  struct mlxbf_gige *priv);
151 void mlxbf_gige_mdio_remove(struct mlxbf_gige *priv);
152 irqreturn_t mlxbf_gige_mdio_handle_phy_interrupt(int irq, void *dev_id);
153 void mlxbf_gige_mdio_enable_phy_int(struct mlxbf_gige *priv);
154 
155 void mlxbf_gige_set_mac_rx_filter(struct mlxbf_gige *priv,
156 				  unsigned int index, u64 dmac);
157 void mlxbf_gige_get_mac_rx_filter(struct mlxbf_gige *priv,
158 				  unsigned int index, u64 *dmac);
159 void mlxbf_gige_enable_promisc(struct mlxbf_gige *priv);
160 void mlxbf_gige_disable_promisc(struct mlxbf_gige *priv);
161 int mlxbf_gige_rx_init(struct mlxbf_gige *priv);
162 void mlxbf_gige_rx_deinit(struct mlxbf_gige *priv);
163 int mlxbf_gige_tx_init(struct mlxbf_gige *priv);
164 void mlxbf_gige_tx_deinit(struct mlxbf_gige *priv);
165 bool mlxbf_gige_handle_tx_complete(struct mlxbf_gige *priv);
166 netdev_tx_t mlxbf_gige_start_xmit(struct sk_buff *skb,
167 				  struct net_device *netdev);
168 struct sk_buff *mlxbf_gige_alloc_skb(struct mlxbf_gige *priv,
169 				     unsigned int map_len,
170 				     dma_addr_t *buf_dma,
171 				     enum dma_data_direction dir);
172 int mlxbf_gige_request_irqs(struct mlxbf_gige *priv);
173 void mlxbf_gige_free_irqs(struct mlxbf_gige *priv);
174 int mlxbf_gige_poll(struct napi_struct *napi, int budget);
175 extern const struct ethtool_ops mlxbf_gige_ethtool_ops;
176 void mlxbf_gige_update_tx_wqe_next(struct mlxbf_gige *priv);
177 
178 #endif /* !defined(__MLXBF_GIGE_H__) */
179