xref: /freebsd/sys/dev/irdma/icrdma_hw.c (revision 5b5f7d0e77a9eee73eb5d596f43aef4e1a3674d8)
1cdcd52d4SBartosz Sobczak /*-
2cdcd52d4SBartosz Sobczak  * SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
3cdcd52d4SBartosz Sobczak  *
4*5b5f7d0eSBartosz Sobczak  * Copyright (c) 2017 - 2023 Intel Corporation
5cdcd52d4SBartosz Sobczak  *
6cdcd52d4SBartosz Sobczak  * This software is available to you under a choice of one of two
7cdcd52d4SBartosz Sobczak  * licenses.  You may choose to be licensed under the terms of the GNU
8cdcd52d4SBartosz Sobczak  * General Public License (GPL) Version 2, available from the file
9cdcd52d4SBartosz Sobczak  * COPYING in the main directory of this source tree, or the
10cdcd52d4SBartosz Sobczak  * OpenFabrics.org BSD license below:
11cdcd52d4SBartosz Sobczak  *
12cdcd52d4SBartosz Sobczak  *   Redistribution and use in source and binary forms, with or
13cdcd52d4SBartosz Sobczak  *   without modification, are permitted provided that the following
14cdcd52d4SBartosz Sobczak  *   conditions are met:
15cdcd52d4SBartosz Sobczak  *
16cdcd52d4SBartosz Sobczak  *    - Redistributions of source code must retain the above
17cdcd52d4SBartosz Sobczak  *	copyright notice, this list of conditions and the following
18cdcd52d4SBartosz Sobczak  *	disclaimer.
19cdcd52d4SBartosz Sobczak  *
20cdcd52d4SBartosz Sobczak  *    - Redistributions in binary form must reproduce the above
21cdcd52d4SBartosz Sobczak  *	copyright notice, this list of conditions and the following
22cdcd52d4SBartosz Sobczak  *	disclaimer in the documentation and/or other materials
23cdcd52d4SBartosz Sobczak  *	provided with the distribution.
24cdcd52d4SBartosz Sobczak  *
25cdcd52d4SBartosz Sobczak  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26cdcd52d4SBartosz Sobczak  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27cdcd52d4SBartosz Sobczak  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28cdcd52d4SBartosz Sobczak  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29cdcd52d4SBartosz Sobczak  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30cdcd52d4SBartosz Sobczak  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31cdcd52d4SBartosz Sobczak  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32cdcd52d4SBartosz Sobczak  * SOFTWARE.
33cdcd52d4SBartosz Sobczak  */
34cdcd52d4SBartosz Sobczak 
35cdcd52d4SBartosz Sobczak #include "osdep.h"
36cdcd52d4SBartosz Sobczak #include "irdma_type.h"
37cdcd52d4SBartosz Sobczak #include "icrdma_hw.h"
38cdcd52d4SBartosz Sobczak 
39cdcd52d4SBartosz Sobczak void disable_prefetch(struct irdma_hw *hw);
40cdcd52d4SBartosz Sobczak 
41cdcd52d4SBartosz Sobczak void disable_tx_spad(struct irdma_hw *hw);
42cdcd52d4SBartosz Sobczak 
43cdcd52d4SBartosz Sobczak void rdpu_ackreqpmthresh(struct irdma_hw *hw);
44cdcd52d4SBartosz Sobczak 
45cdcd52d4SBartosz Sobczak static u32 icrdma_regs[IRDMA_MAX_REGS] = {
46cdcd52d4SBartosz Sobczak 	PFPE_CQPTAIL,
47cdcd52d4SBartosz Sobczak 	    PFPE_CQPDB,
48cdcd52d4SBartosz Sobczak 	    PFPE_CCQPSTATUS,
49cdcd52d4SBartosz Sobczak 	    PFPE_CCQPHIGH,
50cdcd52d4SBartosz Sobczak 	    PFPE_CCQPLOW,
51cdcd52d4SBartosz Sobczak 	    PFPE_CQARM,
52cdcd52d4SBartosz Sobczak 	    PFPE_CQACK,
53cdcd52d4SBartosz Sobczak 	    PFPE_AEQALLOC,
54cdcd52d4SBartosz Sobczak 	    PFPE_CQPERRCODES,
55cdcd52d4SBartosz Sobczak 	    PFPE_WQEALLOC,
56cdcd52d4SBartosz Sobczak 	    GLINT_DYN_CTL(0),
57cdcd52d4SBartosz Sobczak 	    ICRDMA_DB_ADDR_OFFSET,
58cdcd52d4SBartosz Sobczak 
59cdcd52d4SBartosz Sobczak 	    GLPCI_LBARCTRL,
60cdcd52d4SBartosz Sobczak 	    GLPE_CPUSTATUS0,
61cdcd52d4SBartosz Sobczak 	    GLPE_CPUSTATUS1,
62cdcd52d4SBartosz Sobczak 	    GLPE_CPUSTATUS2,
63cdcd52d4SBartosz Sobczak 	    PFINT_AEQCTL,
64cdcd52d4SBartosz Sobczak 	    GLINT_CEQCTL(0),
65cdcd52d4SBartosz Sobczak 	    VSIQF_PE_CTL1(0),
66cdcd52d4SBartosz Sobczak 	    PFHMC_PDINV,
67cdcd52d4SBartosz Sobczak 	    GLHMC_VFPDINV(0),
68cdcd52d4SBartosz Sobczak 	    GLPE_CRITERR,
69cdcd52d4SBartosz Sobczak 	    GLINT_RATE(0),
70cdcd52d4SBartosz Sobczak };
71cdcd52d4SBartosz Sobczak 
72cdcd52d4SBartosz Sobczak static u64 icrdma_masks[IRDMA_MAX_MASKS] = {
73777e472cSBartosz Sobczak 	ICRDMA_CCQPSTATUS_CCQP_DONE,
74777e472cSBartosz Sobczak 	    ICRDMA_CCQPSTATUS_CCQP_ERR,
75777e472cSBartosz Sobczak 	    ICRDMA_CQPSQ_STAG_PDID,
76777e472cSBartosz Sobczak 	    ICRDMA_CQPSQ_CQ_CEQID,
77777e472cSBartosz Sobczak 	    ICRDMA_CQPSQ_CQ_CQID,
78777e472cSBartosz Sobczak 	    ICRDMA_COMMIT_FPM_CQCNT,
79*5b5f7d0eSBartosz Sobczak 	    ICRDMA_CQPSQ_UPESD_HMCFNID,
80cdcd52d4SBartosz Sobczak };
81cdcd52d4SBartosz Sobczak 
82777e472cSBartosz Sobczak static u8 icrdma_shifts[IRDMA_MAX_SHIFTS] = {
83cdcd52d4SBartosz Sobczak 	ICRDMA_CCQPSTATUS_CCQP_DONE_S,
84cdcd52d4SBartosz Sobczak 	    ICRDMA_CCQPSTATUS_CCQP_ERR_S,
85cdcd52d4SBartosz Sobczak 	    ICRDMA_CQPSQ_STAG_PDID_S,
86cdcd52d4SBartosz Sobczak 	    ICRDMA_CQPSQ_CQ_CEQID_S,
87cdcd52d4SBartosz Sobczak 	    ICRDMA_CQPSQ_CQ_CQID_S,
88cdcd52d4SBartosz Sobczak 	    ICRDMA_COMMIT_FPM_CQCNT_S,
89*5b5f7d0eSBartosz Sobczak 	    ICRDMA_CQPSQ_UPESD_HMCFNID_S,
90cdcd52d4SBartosz Sobczak };
91cdcd52d4SBartosz Sobczak 
92cdcd52d4SBartosz Sobczak /**
93cdcd52d4SBartosz Sobczak  * icrdma_ena_irq - Enable interrupt
94cdcd52d4SBartosz Sobczak  * @dev: pointer to the device structure
95cdcd52d4SBartosz Sobczak  * @idx: vector index
96cdcd52d4SBartosz Sobczak  */
97cdcd52d4SBartosz Sobczak static void
icrdma_ena_irq(struct irdma_sc_dev * dev,u32 idx)98cdcd52d4SBartosz Sobczak icrdma_ena_irq(struct irdma_sc_dev *dev, u32 idx)
99cdcd52d4SBartosz Sobczak {
100cdcd52d4SBartosz Sobczak 	u32 val;
101cdcd52d4SBartosz Sobczak 	u32 interval = 0;
102cdcd52d4SBartosz Sobczak 
103cdcd52d4SBartosz Sobczak 	if (dev->ceq_itr && dev->aeq->msix_idx != idx)
104cdcd52d4SBartosz Sobczak 		interval = dev->ceq_itr >> 1;	/* 2 usec units */
105777e472cSBartosz Sobczak 	val = FIELD_PREP(IRDMA_GLINT_DYN_CTL_ITR_INDX, IRDMA_IDX_ITR0) |
106777e472cSBartosz Sobczak 	    FIELD_PREP(IRDMA_GLINT_DYN_CTL_INTERVAL, interval) |
107777e472cSBartosz Sobczak 	    FIELD_PREP(IRDMA_GLINT_DYN_CTL_INTENA, true) |
108777e472cSBartosz Sobczak 	    FIELD_PREP(IRDMA_GLINT_DYN_CTL_CLEARPBA, true);
109cdcd52d4SBartosz Sobczak 	writel(val, dev->hw_regs[IRDMA_GLINT_DYN_CTL] + idx);
110cdcd52d4SBartosz Sobczak }
111cdcd52d4SBartosz Sobczak 
112cdcd52d4SBartosz Sobczak /**
113cdcd52d4SBartosz Sobczak  * icrdma_disable_irq - Disable interrupt
114cdcd52d4SBartosz Sobczak  * @dev: pointer to the device structure
115cdcd52d4SBartosz Sobczak  * @idx: vector index
116cdcd52d4SBartosz Sobczak  */
117cdcd52d4SBartosz Sobczak static void
icrdma_disable_irq(struct irdma_sc_dev * dev,u32 idx)118cdcd52d4SBartosz Sobczak icrdma_disable_irq(struct irdma_sc_dev *dev, u32 idx)
119cdcd52d4SBartosz Sobczak {
120cdcd52d4SBartosz Sobczak 	writel(0, dev->hw_regs[IRDMA_GLINT_DYN_CTL] + idx);
121cdcd52d4SBartosz Sobczak }
122cdcd52d4SBartosz Sobczak 
123cdcd52d4SBartosz Sobczak /**
124cdcd52d4SBartosz Sobczak  * icrdma_cfg_ceq- Configure CEQ interrupt
125cdcd52d4SBartosz Sobczak  * @dev: pointer to the device structure
126cdcd52d4SBartosz Sobczak  * @ceq_id: Completion Event Queue ID
127cdcd52d4SBartosz Sobczak  * @idx: vector index
128cdcd52d4SBartosz Sobczak  * @enable: True to enable, False disables
129cdcd52d4SBartosz Sobczak  */
130cdcd52d4SBartosz Sobczak static void
icrdma_cfg_ceq(struct irdma_sc_dev * dev,u32 ceq_id,u32 idx,bool enable)131cdcd52d4SBartosz Sobczak icrdma_cfg_ceq(struct irdma_sc_dev *dev, u32 ceq_id, u32 idx,
132cdcd52d4SBartosz Sobczak 	       bool enable)
133cdcd52d4SBartosz Sobczak {
134cdcd52d4SBartosz Sobczak 	u32 reg_val;
135cdcd52d4SBartosz Sobczak 
136777e472cSBartosz Sobczak 	reg_val = enable ? IRDMA_GLINT_CEQCTL_CAUSE_ENA : 0;
137cdcd52d4SBartosz Sobczak 	reg_val |= (idx << IRDMA_GLINT_CEQCTL_MSIX_INDX_S) |
138777e472cSBartosz Sobczak 	    IRDMA_GLINT_CEQCTL_ITR_INDX;
139cdcd52d4SBartosz Sobczak 
140cdcd52d4SBartosz Sobczak 	writel(reg_val, dev->hw_regs[IRDMA_GLINT_CEQCTL] + ceq_id);
141cdcd52d4SBartosz Sobczak }
142cdcd52d4SBartosz Sobczak 
143cdcd52d4SBartosz Sobczak static const struct irdma_irq_ops icrdma_irq_ops = {
144cdcd52d4SBartosz Sobczak 	.irdma_cfg_aeq = irdma_cfg_aeq,
145cdcd52d4SBartosz Sobczak 	.irdma_cfg_ceq = icrdma_cfg_ceq,
146cdcd52d4SBartosz Sobczak 	.irdma_dis_irq = icrdma_disable_irq,
147cdcd52d4SBartosz Sobczak 	.irdma_en_irq = icrdma_ena_irq,
148cdcd52d4SBartosz Sobczak };
149cdcd52d4SBartosz Sobczak 
150cdcd52d4SBartosz Sobczak static const struct irdma_hw_stat_map icrdma_hw_stat_map[] = {
151cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RXVLANERR] = {0, 32, IRDMA_MAX_STATS_24},
152cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4RXOCTS] = {8, 0, IRDMA_MAX_STATS_48},
153cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4RXPKTS] = {16, 0, IRDMA_MAX_STATS_48},
154cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4RXDISCARD] = {24, 32, IRDMA_MAX_STATS_32},
155cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4RXTRUNC] = {24, 0, IRDMA_MAX_STATS_32},
156cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4RXFRAGS] = {32, 0, IRDMA_MAX_STATS_48},
157cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4RXMCOCTS] = {40, 0, IRDMA_MAX_STATS_48},
158cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4RXMCPKTS] = {48, 0, IRDMA_MAX_STATS_48},
159cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6RXOCTS] = {56, 0, IRDMA_MAX_STATS_48},
160cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6RXPKTS] = {64, 0, IRDMA_MAX_STATS_48},
161cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6RXDISCARD] = {72, 32, IRDMA_MAX_STATS_32},
162cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6RXTRUNC] = {72, 0, IRDMA_MAX_STATS_32},
163cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6RXFRAGS] = {80, 0, IRDMA_MAX_STATS_48},
164cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6RXMCOCTS] = {88, 0, IRDMA_MAX_STATS_48},
165cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6RXMCPKTS] = {96, 0, IRDMA_MAX_STATS_48},
166cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4TXOCTS] = {104, 0, IRDMA_MAX_STATS_48},
167cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4TXPKTS] = {112, 0, IRDMA_MAX_STATS_48},
168cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4TXFRAGS] = {120, 0, IRDMA_MAX_STATS_48},
169cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4TXMCOCTS] = {128, 0, IRDMA_MAX_STATS_48},
170cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4TXMCPKTS] = {136, 0, IRDMA_MAX_STATS_48},
171cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6TXOCTS] = {144, 0, IRDMA_MAX_STATS_48},
172cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6TXPKTS] = {152, 0, IRDMA_MAX_STATS_48},
173cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6TXFRAGS] = {160, 0, IRDMA_MAX_STATS_48},
174cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6TXMCOCTS] = {168, 0, IRDMA_MAX_STATS_48},
175cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6TXMCPKTS] = {176, 0, IRDMA_MAX_STATS_48},
176cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP4TXNOROUTE] = {184, 32, IRDMA_MAX_STATS_24},
177cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_IP6TXNOROUTE] = {184, 0, IRDMA_MAX_STATS_24},
178cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_TCPRXSEGS] = {192, 32, IRDMA_MAX_STATS_48},
179cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_TCPRXOPTERR] = {200, 32, IRDMA_MAX_STATS_24},
180cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_TCPRXPROTOERR] = {200, 0, IRDMA_MAX_STATS_24},
181cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_TCPTXSEG] = {208, 0, IRDMA_MAX_STATS_48},
182cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_TCPRTXSEG] = {216, 32, IRDMA_MAX_STATS_32},
183cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_UDPRXPKTS] = {224, 0, IRDMA_MAX_STATS_48},
184cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_UDPTXPKTS] = {232, 0, IRDMA_MAX_STATS_48},
185cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RDMARXWRS] = {240, 0, IRDMA_MAX_STATS_48},
186cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RDMARXRDS] = {248, 0, IRDMA_MAX_STATS_48},
187cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RDMARXSNDS] = {256, 0, IRDMA_MAX_STATS_48},
188cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RDMATXWRS] = {264, 0, IRDMA_MAX_STATS_48},
189cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RDMATXRDS] = {272, 0, IRDMA_MAX_STATS_48},
190cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RDMATXSNDS] = {280, 0, IRDMA_MAX_STATS_48},
191cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RDMAVBND] = {288, 0, IRDMA_MAX_STATS_48},
192cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RDMAVINV] = {296, 0, IRDMA_MAX_STATS_48},
193cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RXNPECNMARKEDPKTS] = {304, 0, IRDMA_MAX_STATS_48},
194cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RXRPCNPIGNORED] = {312, 32, IRDMA_MAX_STATS_16},
195cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_RXRPCNPHANDLED] = {312, 0, IRDMA_MAX_STATS_32},
196cdcd52d4SBartosz Sobczak 	[IRDMA_HW_STAT_INDEX_TXNPCNPSENT] = {320, 0, IRDMA_MAX_STATS_32},
197cdcd52d4SBartosz Sobczak };
198cdcd52d4SBartosz Sobczak 
199cdcd52d4SBartosz Sobczak void
icrdma_init_hw(struct irdma_sc_dev * dev)200cdcd52d4SBartosz Sobczak icrdma_init_hw(struct irdma_sc_dev *dev)
201cdcd52d4SBartosz Sobczak {
202cdcd52d4SBartosz Sobczak 	int i;
203cdcd52d4SBartosz Sobczak 	u8 IOMEM *hw_addr;
204cdcd52d4SBartosz Sobczak 
205cdcd52d4SBartosz Sobczak 	for (i = 0; i < IRDMA_MAX_REGS; ++i) {
206cdcd52d4SBartosz Sobczak 		hw_addr = dev->hw->hw_addr;
207cdcd52d4SBartosz Sobczak 
208cdcd52d4SBartosz Sobczak 		if (i == IRDMA_DB_ADDR_OFFSET)
209cdcd52d4SBartosz Sobczak 			hw_addr = NULL;
210cdcd52d4SBartosz Sobczak 
211cdcd52d4SBartosz Sobczak 		dev->hw_regs[i] = (u32 IOMEM *) (hw_addr + icrdma_regs[i]);
212cdcd52d4SBartosz Sobczak 	}
213cdcd52d4SBartosz Sobczak 
214cdcd52d4SBartosz Sobczak 	for (i = 0; i < IRDMA_MAX_SHIFTS; ++i)
215cdcd52d4SBartosz Sobczak 		dev->hw_shifts[i] = icrdma_shifts[i];
216cdcd52d4SBartosz Sobczak 
217cdcd52d4SBartosz Sobczak 	for (i = 0; i < IRDMA_MAX_MASKS; ++i)
218cdcd52d4SBartosz Sobczak 		dev->hw_masks[i] = icrdma_masks[i];
219cdcd52d4SBartosz Sobczak 
220cdcd52d4SBartosz Sobczak 	dev->wqe_alloc_db = dev->hw_regs[IRDMA_WQEALLOC];
221cdcd52d4SBartosz Sobczak 	dev->cq_arm_db = dev->hw_regs[IRDMA_CQARM];
222cdcd52d4SBartosz Sobczak 	dev->aeq_alloc_db = dev->hw_regs[IRDMA_AEQALLOC];
223cdcd52d4SBartosz Sobczak 	dev->cqp_db = dev->hw_regs[IRDMA_CQPDB];
224cdcd52d4SBartosz Sobczak 	dev->cq_ack_db = dev->hw_regs[IRDMA_CQACK];
225cdcd52d4SBartosz Sobczak 	dev->irq_ops = &icrdma_irq_ops;
226cdcd52d4SBartosz Sobczak 	dev->hw_stats_map = icrdma_hw_stat_map;
227777e472cSBartosz Sobczak 	dev->hw_attrs.page_size_cap = SZ_4K | SZ_2M | SZ_1G;
228cdcd52d4SBartosz Sobczak 	dev->hw_attrs.max_hw_ird = ICRDMA_MAX_IRD_SIZE;
229cdcd52d4SBartosz Sobczak 	dev->hw_attrs.max_hw_ord = ICRDMA_MAX_ORD_SIZE;
230cdcd52d4SBartosz Sobczak 	dev->hw_attrs.max_stat_inst = ICRDMA_MAX_STATS_COUNT;
231cdcd52d4SBartosz Sobczak 	dev->hw_attrs.max_stat_idx = IRDMA_HW_STAT_INDEX_MAX_GEN_2;
232*5b5f7d0eSBartosz Sobczak 	dev->hw_attrs.max_hw_device_pages = ICRDMA_MAX_PUSH_PAGE_COUNT;
233cdcd52d4SBartosz Sobczak 
234cdcd52d4SBartosz Sobczak 	dev->hw_attrs.uk_attrs.max_hw_wq_frags = ICRDMA_MAX_WQ_FRAGMENT_COUNT;
235cdcd52d4SBartosz Sobczak 	dev->hw_attrs.uk_attrs.max_hw_read_sges = ICRDMA_MAX_SGE_RD;
236777e472cSBartosz Sobczak 	dev->hw_attrs.uk_attrs.min_hw_wq_size = ICRDMA_MIN_WQ_SIZE;
237cdcd52d4SBartosz Sobczak 	dev->hw_attrs.uk_attrs.max_hw_sq_chunk = IRDMA_MAX_QUANTA_PER_WR;
238cdcd52d4SBartosz Sobczak 	disable_tx_spad(dev->hw);
239cdcd52d4SBartosz Sobczak 	disable_prefetch(dev->hw);
240cdcd52d4SBartosz Sobczak 	rdpu_ackreqpmthresh(dev->hw);
241cdcd52d4SBartosz Sobczak 	dev->hw_attrs.uk_attrs.feature_flags |= IRDMA_FEATURE_RELAX_RQ_ORDER;
242cdcd52d4SBartosz Sobczak 	dev->hw_attrs.uk_attrs.feature_flags |= IRDMA_FEATURE_RTS_AE |
243cdcd52d4SBartosz Sobczak 	    IRDMA_FEATURE_CQ_RESIZE;
244cdcd52d4SBartosz Sobczak }
245cdcd52d4SBartosz Sobczak 
246cdcd52d4SBartosz Sobczak void
irdma_init_config_check(struct irdma_config_check * cc,u8 traffic_class,u16 qs_handle)247cdcd52d4SBartosz Sobczak irdma_init_config_check(struct irdma_config_check *cc, u8 traffic_class, u16 qs_handle)
248cdcd52d4SBartosz Sobczak {
249cdcd52d4SBartosz Sobczak 	cc->config_ok = false;
250cdcd52d4SBartosz Sobczak 	cc->traffic_class = traffic_class;
251cdcd52d4SBartosz Sobczak 	cc->qs_handle = qs_handle;
252cdcd52d4SBartosz Sobczak 	cc->lfc_set = 0;
253cdcd52d4SBartosz Sobczak 	cc->pfc_set = 0;
254cdcd52d4SBartosz Sobczak }
255cdcd52d4SBartosz Sobczak 
256cdcd52d4SBartosz Sobczak static bool
irdma_is_lfc_set(struct irdma_config_check * cc,struct irdma_sc_vsi * vsi)257cdcd52d4SBartosz Sobczak irdma_is_lfc_set(struct irdma_config_check *cc, struct irdma_sc_vsi *vsi)
258cdcd52d4SBartosz Sobczak {
259cdcd52d4SBartosz Sobczak 	u32 lfc = 1;
260cdcd52d4SBartosz Sobczak 	u8 fn_id = vsi->dev->hmc_fn_id;
261cdcd52d4SBartosz Sobczak 
262cdcd52d4SBartosz Sobczak 	lfc &= (rd32(vsi->dev->hw,
263cdcd52d4SBartosz Sobczak 		     PRTMAC_HSEC_CTL_RX_PAUSE_ENABLE_0 + 4 * fn_id) >> 8);
264cdcd52d4SBartosz Sobczak 	lfc &= (rd32(vsi->dev->hw,
265cdcd52d4SBartosz Sobczak 		     PRTMAC_HSEC_CTL_TX_PAUSE_ENABLE_0 + 4 * fn_id) >> 8);
266cdcd52d4SBartosz Sobczak 	lfc &= rd32(vsi->dev->hw,
267cdcd52d4SBartosz Sobczak 		    PRTMAC_HSEC_CTL_RX_ENABLE_GPP_0 + 4 * vsi->dev->hmc_fn_id);
268cdcd52d4SBartosz Sobczak 
269cdcd52d4SBartosz Sobczak 	if (lfc)
270cdcd52d4SBartosz Sobczak 		return true;
271cdcd52d4SBartosz Sobczak 	return false;
272cdcd52d4SBartosz Sobczak }
273cdcd52d4SBartosz Sobczak 
274cdcd52d4SBartosz Sobczak static bool
irdma_check_tc_has_pfc(struct irdma_sc_vsi * vsi,u64 reg_offset,u16 traffic_class)275cdcd52d4SBartosz Sobczak irdma_check_tc_has_pfc(struct irdma_sc_vsi *vsi, u64 reg_offset, u16 traffic_class)
276cdcd52d4SBartosz Sobczak {
277cdcd52d4SBartosz Sobczak 	u32 value, pfc = 0;
278cdcd52d4SBartosz Sobczak 	u32 i;
279cdcd52d4SBartosz Sobczak 
280cdcd52d4SBartosz Sobczak 	value = rd32(vsi->dev->hw, reg_offset);
281cdcd52d4SBartosz Sobczak 	for (i = 0; i < 4; i++)
282cdcd52d4SBartosz Sobczak 		pfc |= (value >> (8 * i + traffic_class)) & 0x1;
283cdcd52d4SBartosz Sobczak 
284cdcd52d4SBartosz Sobczak 	if (pfc)
285cdcd52d4SBartosz Sobczak 		return true;
286cdcd52d4SBartosz Sobczak 	return false;
287cdcd52d4SBartosz Sobczak }
288cdcd52d4SBartosz Sobczak 
289cdcd52d4SBartosz Sobczak static bool
irdma_is_pfc_set(struct irdma_config_check * cc,struct irdma_sc_vsi * vsi)290cdcd52d4SBartosz Sobczak irdma_is_pfc_set(struct irdma_config_check *cc, struct irdma_sc_vsi *vsi)
291cdcd52d4SBartosz Sobczak {
292cdcd52d4SBartosz Sobczak 	u32 pause;
293cdcd52d4SBartosz Sobczak 	u8 fn_id = vsi->dev->hmc_fn_id;
294cdcd52d4SBartosz Sobczak 
295cdcd52d4SBartosz Sobczak 	pause = (rd32(vsi->dev->hw,
296cdcd52d4SBartosz Sobczak 		      PRTMAC_HSEC_CTL_RX_PAUSE_ENABLE_0 + 4 * fn_id) >>
297cdcd52d4SBartosz Sobczak 		 cc->traffic_class) & BIT(0);
298cdcd52d4SBartosz Sobczak 	pause &= (rd32(vsi->dev->hw,
299cdcd52d4SBartosz Sobczak 		       PRTMAC_HSEC_CTL_TX_PAUSE_ENABLE_0 + 4 * fn_id) >>
300cdcd52d4SBartosz Sobczak 		  cc->traffic_class) & BIT(0);
301cdcd52d4SBartosz Sobczak 
302cdcd52d4SBartosz Sobczak 	return irdma_check_tc_has_pfc(vsi, GLDCB_TC2PFC, cc->traffic_class) &&
303cdcd52d4SBartosz Sobczak 	    pause;
304cdcd52d4SBartosz Sobczak }
305cdcd52d4SBartosz Sobczak 
306cdcd52d4SBartosz Sobczak bool
irdma_is_config_ok(struct irdma_config_check * cc,struct irdma_sc_vsi * vsi)307cdcd52d4SBartosz Sobczak irdma_is_config_ok(struct irdma_config_check *cc, struct irdma_sc_vsi *vsi)
308cdcd52d4SBartosz Sobczak {
309cdcd52d4SBartosz Sobczak 	cc->lfc_set = irdma_is_lfc_set(cc, vsi);
310cdcd52d4SBartosz Sobczak 	cc->pfc_set = irdma_is_pfc_set(cc, vsi);
311cdcd52d4SBartosz Sobczak 
312cdcd52d4SBartosz Sobczak 	cc->config_ok = cc->lfc_set || cc->pfc_set;
313cdcd52d4SBartosz Sobczak 
314cdcd52d4SBartosz Sobczak 	return cc->config_ok;
315cdcd52d4SBartosz Sobczak }
316cdcd52d4SBartosz Sobczak 
317cdcd52d4SBartosz Sobczak #define IRDMA_RCV_WND_NO_FC	65536
318cdcd52d4SBartosz Sobczak #define IRDMA_RCV_WND_FC	65536
319cdcd52d4SBartosz Sobczak 
320cdcd52d4SBartosz Sobczak #define IRDMA_CWND_NO_FC	0x1
321cdcd52d4SBartosz Sobczak #define IRDMA_CWND_FC		0x18
322cdcd52d4SBartosz Sobczak 
323777e472cSBartosz Sobczak #define IRDMA_RTOMIN_NO_FC	0x5
324777e472cSBartosz Sobczak #define IRDMA_RTOMIN_FC		0x32
325777e472cSBartosz Sobczak 
326cdcd52d4SBartosz Sobczak #define IRDMA_ACKCREDS_NO_FC	0x02
327cdcd52d4SBartosz Sobczak #define IRDMA_ACKCREDS_FC	0x06
328cdcd52d4SBartosz Sobczak 
329cdcd52d4SBartosz Sobczak static void
irdma_check_flow_ctrl(struct irdma_sc_vsi * vsi,u8 user_prio,u8 traffic_class)330cdcd52d4SBartosz Sobczak irdma_check_flow_ctrl(struct irdma_sc_vsi *vsi, u8 user_prio, u8 traffic_class)
331cdcd52d4SBartosz Sobczak {
332cdcd52d4SBartosz Sobczak 	struct irdma_config_check *cfg_chk = &vsi->cfg_check[user_prio];
333cdcd52d4SBartosz Sobczak 
334cdcd52d4SBartosz Sobczak 	if (!irdma_is_config_ok(cfg_chk, vsi)) {
335cdcd52d4SBartosz Sobczak 		if (vsi->tc_print_warning[traffic_class]) {
336cdcd52d4SBartosz Sobczak 			irdma_pr_info("INFO: Flow control is disabled for this traffic class (%d) on this vsi.\n", traffic_class);
337cdcd52d4SBartosz Sobczak 			vsi->tc_print_warning[traffic_class] = false;
338cdcd52d4SBartosz Sobczak 		}
339cdcd52d4SBartosz Sobczak 	} else {
340cdcd52d4SBartosz Sobczak 		if (vsi->tc_print_warning[traffic_class]) {
341cdcd52d4SBartosz Sobczak 			irdma_pr_info("INFO: Flow control is enabled for this traffic class (%d) on this vsi.\n", traffic_class);
342cdcd52d4SBartosz Sobczak 			vsi->tc_print_warning[traffic_class] = false;
343cdcd52d4SBartosz Sobczak 		}
344cdcd52d4SBartosz Sobczak 	}
345cdcd52d4SBartosz Sobczak }
346cdcd52d4SBartosz Sobczak 
347cdcd52d4SBartosz Sobczak void
irdma_check_fc_for_tc_update(struct irdma_sc_vsi * vsi,struct irdma_l2params * l2params)348cdcd52d4SBartosz Sobczak irdma_check_fc_for_tc_update(struct irdma_sc_vsi *vsi,
349cdcd52d4SBartosz Sobczak 			     struct irdma_l2params *l2params)
350cdcd52d4SBartosz Sobczak {
351cdcd52d4SBartosz Sobczak 	u8 i;
352cdcd52d4SBartosz Sobczak 
353cdcd52d4SBartosz Sobczak 	for (i = 0; i < IRDMA_MAX_TRAFFIC_CLASS; i++)
354cdcd52d4SBartosz Sobczak 		vsi->tc_print_warning[i] = true;
355cdcd52d4SBartosz Sobczak 
356cdcd52d4SBartosz Sobczak 	for (i = 0; i < IRDMA_MAX_USER_PRIORITY; i++) {
357cdcd52d4SBartosz Sobczak 		struct irdma_config_check *cfg_chk = &vsi->cfg_check[i];
358cdcd52d4SBartosz Sobczak 		u8 tc = l2params->up2tc[i];
359cdcd52d4SBartosz Sobczak 
360cdcd52d4SBartosz Sobczak 		cfg_chk->traffic_class = tc;
361cdcd52d4SBartosz Sobczak 		cfg_chk->qs_handle = vsi->qos[i].qs_handle;
362cdcd52d4SBartosz Sobczak 		irdma_check_flow_ctrl(vsi, i, tc);
363cdcd52d4SBartosz Sobczak 	}
364cdcd52d4SBartosz Sobczak }
365cdcd52d4SBartosz Sobczak 
366cdcd52d4SBartosz Sobczak void
irdma_check_fc_for_qp(struct irdma_sc_vsi * vsi,struct irdma_sc_qp * sc_qp)367cdcd52d4SBartosz Sobczak irdma_check_fc_for_qp(struct irdma_sc_vsi *vsi, struct irdma_sc_qp *sc_qp)
368cdcd52d4SBartosz Sobczak {
369cdcd52d4SBartosz Sobczak 	u8 i;
370cdcd52d4SBartosz Sobczak 
371cdcd52d4SBartosz Sobczak 	for (i = 0; i < IRDMA_MAX_USER_PRIORITY; i++) {
372cdcd52d4SBartosz Sobczak 		struct irdma_config_check *cfg_chk = &vsi->cfg_check[i];
373cdcd52d4SBartosz Sobczak 
374cdcd52d4SBartosz Sobczak 		irdma_init_config_check(cfg_chk,
375cdcd52d4SBartosz Sobczak 					vsi->qos[i].traffic_class,
376cdcd52d4SBartosz Sobczak 					vsi->qos[i].qs_handle);
377cdcd52d4SBartosz Sobczak 		if (sc_qp->qs_handle == cfg_chk->qs_handle)
378cdcd52d4SBartosz Sobczak 			irdma_check_flow_ctrl(vsi, i, cfg_chk->traffic_class);
379cdcd52d4SBartosz Sobczak 	}
380cdcd52d4SBartosz Sobczak }
381cdcd52d4SBartosz Sobczak 
382cdcd52d4SBartosz Sobczak #define GLPE_WQMTXIDXADDR	0x50E000
383cdcd52d4SBartosz Sobczak #define GLPE_WQMTXIDXDATA	0x50E004
384cdcd52d4SBartosz Sobczak 
385cdcd52d4SBartosz Sobczak void
disable_prefetch(struct irdma_hw * hw)386cdcd52d4SBartosz Sobczak disable_prefetch(struct irdma_hw *hw)
387cdcd52d4SBartosz Sobczak {
388cdcd52d4SBartosz Sobczak 	u32 wqm_data;
389cdcd52d4SBartosz Sobczak 
390cdcd52d4SBartosz Sobczak 	wr32(hw, GLPE_WQMTXIDXADDR, 0x12);
391cdcd52d4SBartosz Sobczak 	irdma_mb();
392cdcd52d4SBartosz Sobczak 
393cdcd52d4SBartosz Sobczak 	wqm_data = rd32(hw, GLPE_WQMTXIDXDATA);
394cdcd52d4SBartosz Sobczak 	wqm_data &= ~(1);
395cdcd52d4SBartosz Sobczak 	wr32(hw, GLPE_WQMTXIDXDATA, wqm_data);
396cdcd52d4SBartosz Sobczak }
397cdcd52d4SBartosz Sobczak 
398cdcd52d4SBartosz Sobczak void
disable_tx_spad(struct irdma_hw * hw)399cdcd52d4SBartosz Sobczak disable_tx_spad(struct irdma_hw *hw)
400cdcd52d4SBartosz Sobczak {
401cdcd52d4SBartosz Sobczak 	u32 wqm_data;
402cdcd52d4SBartosz Sobczak 
403cdcd52d4SBartosz Sobczak 	wr32(hw, GLPE_WQMTXIDXADDR, 0x12);
404cdcd52d4SBartosz Sobczak 	irdma_mb();
405cdcd52d4SBartosz Sobczak 
406cdcd52d4SBartosz Sobczak 	wqm_data = rd32(hw, GLPE_WQMTXIDXDATA);
407cdcd52d4SBartosz Sobczak 	wqm_data &= ~(1 << 3);
408cdcd52d4SBartosz Sobczak 	wr32(hw, GLPE_WQMTXIDXDATA, wqm_data);
409cdcd52d4SBartosz Sobczak }
410cdcd52d4SBartosz Sobczak 
411cdcd52d4SBartosz Sobczak #define GL_RDPU_CNTRL		0x52054
412cdcd52d4SBartosz Sobczak void
rdpu_ackreqpmthresh(struct irdma_hw * hw)413cdcd52d4SBartosz Sobczak rdpu_ackreqpmthresh(struct irdma_hw *hw)
414cdcd52d4SBartosz Sobczak {
415cdcd52d4SBartosz Sobczak 	u32 val;
416cdcd52d4SBartosz Sobczak 
417cdcd52d4SBartosz Sobczak 	val = rd32(hw, GL_RDPU_CNTRL);
418cdcd52d4SBartosz Sobczak 	val &= ~(0x3f << 10);
419cdcd52d4SBartosz Sobczak 	val |= (3 << 10);
420cdcd52d4SBartosz Sobczak 	wr32(hw, GL_RDPU_CNTRL, val);
421cdcd52d4SBartosz Sobczak }
422