Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)  * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * licenses.  You may choose to be licensed under the terms of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * General Public License (GPL) Version 2, available from the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * COPYING in the main directory of this source tree, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * OpenIB.org BSD license below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *     Redistribution and use in source and binary forms, with or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *     without modification, are permitted provided that the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *     conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *      - Redistributions of source code must retain the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *	  copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *	  disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *      - Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *	  copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *	  disclaimer in the documentation and/or other materials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *	  provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/math64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <rdma/ib_verbs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include "iw_cxgb4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define DRV_VERSION "0.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) MODULE_AUTHOR("Steve Wise");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) MODULE_DESCRIPTION("Chelsio T4/T5 RDMA Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) MODULE_LICENSE("Dual BSD/GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) static int allow_db_fc_on_t5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) module_param(allow_db_fc_on_t5, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) MODULE_PARM_DESC(allow_db_fc_on_t5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 		 "Allow DB Flow Control on T5 (default = 0)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) static int allow_db_coalescing_on_t5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) module_param(allow_db_coalescing_on_t5, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) MODULE_PARM_DESC(allow_db_coalescing_on_t5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 		 "Allow DB Coalescing on T5 (default = 0)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) int c4iw_wr_log = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) module_param(c4iw_wr_log, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) MODULE_PARM_DESC(c4iw_wr_log, "Enables logging of work request timing data.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) static int c4iw_wr_log_size_order = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) module_param(c4iw_wr_log_size_order, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) MODULE_PARM_DESC(c4iw_wr_log_size_order,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 		 "Number of entries (log2) in the work request timing log.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static LIST_HEAD(uld_ctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) static DEFINE_MUTEX(dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static struct workqueue_struct *reg_workq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #define DB_FC_RESUME_SIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define DB_FC_RESUME_DELAY 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #define DB_FC_DRAIN_THRESH 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) static struct dentry *c4iw_debugfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) struct c4iw_debugfs_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	struct c4iw_dev *devp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	int bufsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	int pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) static ssize_t debugfs_read(struct file *file, char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 			    loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	struct c4iw_debugfs_data *d = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	return simple_read_from_buffer(buf, count, ppos, d->buf, d->pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) void c4iw_log_wr_stats(struct t4_wq *wq, struct t4_cqe *cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	struct wr_log_entry le;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	if (!wq->rdev->wr_log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	idx = (atomic_inc_return(&wq->rdev->wr_log_idx) - 1) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		(wq->rdev->wr_log_size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	le.poll_sge_ts = cxgb4_read_sge_timestamp(wq->rdev->lldi.ports[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	le.poll_host_time = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	le.valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	le.cqe_sge_ts = CQE_TS(cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	if (SQ_TYPE(cqe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		le.qid = wq->sq.qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		le.opcode = CQE_OPCODE(cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 		le.post_host_time = wq->sq.sw_sq[wq->sq.cidx].host_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 		le.post_sge_ts = wq->sq.sw_sq[wq->sq.cidx].sge_ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		le.wr_id = CQE_WRID_SQ_IDX(cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 		le.qid = wq->rq.qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 		le.opcode = FW_RI_RECEIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		le.post_host_time = wq->rq.sw_rq[wq->rq.cidx].host_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 		le.post_sge_ts = wq->rq.sw_rq[wq->rq.cidx].sge_ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 		le.wr_id = CQE_WRID_MSN(cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	wq->rdev->wr_log[idx] = le;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) static int wr_log_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	struct c4iw_dev *dev = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	ktime_t prev_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	struct wr_log_entry *lep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	int prev_time_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	int idx, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #define ts2ns(ts) div64_u64((ts) * dev->rdev.lldi.cclk_ps, 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	idx = atomic_read(&dev->rdev.wr_log_idx) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 		(dev->rdev.wr_log_size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	end = idx - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	if (end < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		end = dev->rdev.wr_log_size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	lep = &dev->rdev.wr_log[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	while (idx != end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 		if (lep->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 			if (!prev_time_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 				prev_time_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 				prev_time = lep->poll_host_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 			seq_printf(seq, "%04u: nsec %llu qid %u opcode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 				   "%u %s 0x%x host_wr_delta nsec %llu "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 				   "post_sge_ts 0x%llx cqe_sge_ts 0x%llx "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 				   "poll_sge_ts 0x%llx post_poll_delta_ns %llu "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 				   "cqe_poll_delta_ns %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 				   idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 				   ktime_to_ns(ktime_sub(lep->poll_host_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 							 prev_time)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 				   lep->qid, lep->opcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 				   lep->opcode == FW_RI_RECEIVE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 							"msn" : "wrid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 				   lep->wr_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 				   ktime_to_ns(ktime_sub(lep->poll_host_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 							 lep->post_host_time)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 				   lep->post_sge_ts, lep->cqe_sge_ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 				   lep->poll_sge_ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 				   ts2ns(lep->poll_sge_ts - lep->post_sge_ts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 				   ts2ns(lep->poll_sge_ts - lep->cqe_sge_ts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 			prev_time = lep->poll_host_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 		if (idx > (dev->rdev.wr_log_size - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 			idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		lep = &dev->rdev.wr_log[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) #undef ts2ns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) static int wr_log_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	return single_open(file, wr_log_show, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) static ssize_t wr_log_clear(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 			    size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	struct c4iw_dev *dev = ((struct seq_file *)file->private_data)->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	if (dev->rdev.wr_log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		for (i = 0; i < dev->rdev.wr_log_size; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 			dev->rdev.wr_log[i].valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) static const struct file_operations wr_log_debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	.open    = wr_log_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	.read    = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	.llseek  = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	.write   = wr_log_clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) static struct sockaddr_in zero_sin = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	.sin_family = AF_INET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) static struct sockaddr_in6 zero_sin6 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	.sin6_family = AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) static void set_ep_sin_addrs(struct c4iw_ep *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 			     struct sockaddr_in **lsin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 			     struct sockaddr_in **rsin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			     struct sockaddr_in **m_lsin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 			     struct sockaddr_in **m_rsin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	struct iw_cm_id *id = ep->com.cm_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	*m_lsin = (struct sockaddr_in *)&ep->com.local_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	*m_rsin = (struct sockaddr_in *)&ep->com.remote_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	if (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		*lsin = (struct sockaddr_in *)&id->local_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		*rsin = (struct sockaddr_in *)&id->remote_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		*lsin = &zero_sin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		*rsin = &zero_sin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) static void set_ep_sin6_addrs(struct c4iw_ep *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 			      struct sockaddr_in6 **lsin6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 			      struct sockaddr_in6 **rsin6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 			      struct sockaddr_in6 **m_lsin6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 			      struct sockaddr_in6 **m_rsin6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	struct iw_cm_id *id = ep->com.cm_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	*m_lsin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	*m_rsin6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	if (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		*lsin6 = (struct sockaddr_in6 *)&id->local_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		*rsin6 = (struct sockaddr_in6 *)&id->remote_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		*lsin6 = &zero_sin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		*rsin6 = &zero_sin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) static int dump_qp(unsigned long id, struct c4iw_qp *qp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		   struct c4iw_debugfs_data *qpd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	int space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	if (id != qp->wq.sq.qid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	space = qpd->bufsize - qpd->pos - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	if (space == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	if (qp->ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		struct c4iw_ep *ep = qp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		if (ep->com.local_addr.ss_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 			struct sockaddr_in *lsin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 			struct sockaddr_in *rsin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 			struct sockaddr_in *m_lsin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 			struct sockaddr_in *m_rsin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 			set_ep_sin_addrs(ep, &lsin, &rsin, &m_lsin, &m_rsin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 			cc = snprintf(qpd->buf + qpd->pos, space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 				      "rc qp sq id %u %s id %u state %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 				      "onchip %u ep tid %u state %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 				      "%pI4:%u/%u->%pI4:%u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 				      qp->wq.sq.qid, qp->srq ? "srq" : "rq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 				      qp->srq ? qp->srq->idx : qp->wq.rq.qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 				      (int)qp->attr.state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 				      qp->wq.sq.flags & T4_SQ_ONCHIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 				      ep->hwtid, (int)ep->com.state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 				      &lsin->sin_addr, ntohs(lsin->sin_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 				      ntohs(m_lsin->sin_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 				      &rsin->sin_addr, ntohs(rsin->sin_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 				      ntohs(m_rsin->sin_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 			struct sockaddr_in6 *lsin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 			struct sockaddr_in6 *rsin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 			struct sockaddr_in6 *m_lsin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 			struct sockaddr_in6 *m_rsin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 			set_ep_sin6_addrs(ep, &lsin6, &rsin6, &m_lsin6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 					  &m_rsin6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			cc = snprintf(qpd->buf + qpd->pos, space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 				      "rc qp sq id %u rq id %u state %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 				      "onchip %u ep tid %u state %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 				      "%pI6:%u/%u->%pI6:%u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 				      qp->wq.sq.qid, qp->wq.rq.qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 				      (int)qp->attr.state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 				      qp->wq.sq.flags & T4_SQ_ONCHIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 				      ep->hwtid, (int)ep->com.state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 				      &lsin6->sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 				      ntohs(lsin6->sin6_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 				      ntohs(m_lsin6->sin6_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 				      &rsin6->sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 				      ntohs(rsin6->sin6_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 				      ntohs(m_rsin6->sin6_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		cc = snprintf(qpd->buf + qpd->pos, space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 			     "qp sq id %u rq id %u state %u onchip %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 			      qp->wq.sq.qid, qp->wq.rq.qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 			      (int)qp->attr.state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			      qp->wq.sq.flags & T4_SQ_ONCHIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (cc < space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		qpd->pos += cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) static int qp_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	struct c4iw_debugfs_data *qpd = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	if (!qpd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		pr_info("%s null qpd?\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	vfree(qpd->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	kfree(qpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) static int qp_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	struct c4iw_qp *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	struct c4iw_debugfs_data *qpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	int count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	qpd = kmalloc(sizeof(*qpd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	if (!qpd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	qpd->devp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	qpd->pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	 * No need to lock; we drop the lock to call vmalloc so it's racy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	 * anyway.  Someone who cares should switch this over to seq_file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	xa_for_each(&qpd->devp->qps, index, qp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	qpd->bufsize = count * 180;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	qpd->buf = vmalloc(qpd->bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	if (!qpd->buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		kfree(qpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	xa_lock_irq(&qpd->devp->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	xa_for_each(&qpd->devp->qps, index, qp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		dump_qp(index, qp, qpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	xa_unlock_irq(&qpd->devp->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	qpd->buf[qpd->pos++] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	file->private_data = qpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) static const struct file_operations qp_debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	.open    = qp_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	.release = qp_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	.read    = debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	.llseek  = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) static int dump_stag(unsigned long id, struct c4iw_debugfs_data *stagd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	int space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	struct fw_ri_tpte tpte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	space = stagd->bufsize - stagd->pos - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	if (space == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	ret = cxgb4_read_tpte(stagd->devp->rdev.lldi.ports[0], (u32)id<<8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			      (__be32 *)&tpte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		dev_err(&stagd->devp->rdev.lldi.pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			"%s cxgb4_read_tpte err %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	cc = snprintf(stagd->buf + stagd->pos, space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		      "stag: idx 0x%x valid %d key 0x%x state %d pdid %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		      "perm 0x%x ps %d len 0x%llx va 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		      (u32)id<<8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		      FW_RI_TPTE_VALID_G(ntohl(tpte.valid_to_pdid)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		      FW_RI_TPTE_STAGKEY_G(ntohl(tpte.valid_to_pdid)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		      FW_RI_TPTE_STAGSTATE_G(ntohl(tpte.valid_to_pdid)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		      FW_RI_TPTE_PDID_G(ntohl(tpte.valid_to_pdid)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		      FW_RI_TPTE_PERM_G(ntohl(tpte.locread_to_qpid)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		      FW_RI_TPTE_PS_G(ntohl(tpte.locread_to_qpid)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		      ((u64)ntohl(tpte.len_hi) << 32) | ntohl(tpte.len_lo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		      ((u64)ntohl(tpte.va_hi) << 32) | ntohl(tpte.va_lo_fbo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	if (cc < space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		stagd->pos += cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) static int stag_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	struct c4iw_debugfs_data *stagd = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	if (!stagd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		pr_info("%s null stagd?\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	vfree(stagd->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	kfree(stagd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) static int stag_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	struct c4iw_debugfs_data *stagd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	void *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	int count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	stagd = kmalloc(sizeof(*stagd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	if (!stagd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	stagd->devp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	stagd->pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	xa_for_each(&stagd->devp->mrs, index, p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	stagd->bufsize = count * 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	stagd->buf = vmalloc(stagd->bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	if (!stagd->buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		goto err1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	xa_lock_irq(&stagd->devp->mrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	xa_for_each(&stagd->devp->mrs, index, p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		dump_stag(index, stagd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	xa_unlock_irq(&stagd->devp->mrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	stagd->buf[stagd->pos++] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	file->private_data = stagd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) err1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	kfree(stagd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) static const struct file_operations stag_debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	.open    = stag_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	.release = stag_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	.read    = debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	.llseek  = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) static char *db_state_str[] = {"NORMAL", "FLOW_CONTROL", "RECOVERY", "STOPPED"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) static int stats_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	struct c4iw_dev *dev = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	seq_printf(seq, "   Object: %10s %10s %10s %10s\n", "Total", "Current",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		   "Max", "Fail");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	seq_printf(seq, "     PDID: %10llu %10llu %10llu %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			dev->rdev.stats.pd.total, dev->rdev.stats.pd.cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 			dev->rdev.stats.pd.max, dev->rdev.stats.pd.fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	seq_printf(seq, "      QID: %10llu %10llu %10llu %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 			dev->rdev.stats.qid.total, dev->rdev.stats.qid.cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			dev->rdev.stats.qid.max, dev->rdev.stats.qid.fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	seq_printf(seq, "     SRQS: %10llu %10llu %10llu %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		   dev->rdev.stats.srqt.total, dev->rdev.stats.srqt.cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 			dev->rdev.stats.srqt.max, dev->rdev.stats.srqt.fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	seq_printf(seq, "   TPTMEM: %10llu %10llu %10llu %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			dev->rdev.stats.stag.total, dev->rdev.stats.stag.cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			dev->rdev.stats.stag.max, dev->rdev.stats.stag.fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	seq_printf(seq, "   PBLMEM: %10llu %10llu %10llu %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			dev->rdev.stats.pbl.total, dev->rdev.stats.pbl.cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			dev->rdev.stats.pbl.max, dev->rdev.stats.pbl.fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	seq_printf(seq, "   RQTMEM: %10llu %10llu %10llu %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			dev->rdev.stats.rqt.total, dev->rdev.stats.rqt.cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			dev->rdev.stats.rqt.max, dev->rdev.stats.rqt.fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	seq_printf(seq, "  OCQPMEM: %10llu %10llu %10llu %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			dev->rdev.stats.ocqp.total, dev->rdev.stats.ocqp.cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			dev->rdev.stats.ocqp.max, dev->rdev.stats.ocqp.fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	seq_printf(seq, "  DB FULL: %10llu\n", dev->rdev.stats.db_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	seq_printf(seq, " DB EMPTY: %10llu\n", dev->rdev.stats.db_empty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	seq_printf(seq, "  DB DROP: %10llu\n", dev->rdev.stats.db_drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	seq_printf(seq, " DB State: %s Transitions %llu FC Interruptions %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		   db_state_str[dev->db_state],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		   dev->rdev.stats.db_state_transitions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		   dev->rdev.stats.db_fc_interruptions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	seq_printf(seq, "TCAM_FULL: %10llu\n", dev->rdev.stats.tcam_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	seq_printf(seq, "ACT_OFLD_CONN_FAILS: %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		   dev->rdev.stats.act_ofld_conn_fails);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	seq_printf(seq, "PAS_OFLD_CONN_FAILS: %10llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		   dev->rdev.stats.pas_ofld_conn_fails);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	seq_printf(seq, "NEG_ADV_RCVD: %10llu\n", dev->rdev.stats.neg_adv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	seq_printf(seq, "AVAILABLE IRD: %10u\n", dev->avail_ird);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) static int stats_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	return single_open(file, stats_show, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) static ssize_t stats_clear(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	struct c4iw_dev *dev = ((struct seq_file *)file->private_data)->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	mutex_lock(&dev->rdev.stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	dev->rdev.stats.pd.max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	dev->rdev.stats.pd.fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	dev->rdev.stats.qid.max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	dev->rdev.stats.qid.fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	dev->rdev.stats.stag.max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	dev->rdev.stats.stag.fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	dev->rdev.stats.pbl.max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	dev->rdev.stats.pbl.fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	dev->rdev.stats.rqt.max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	dev->rdev.stats.rqt.fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	dev->rdev.stats.rqt.max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	dev->rdev.stats.rqt.fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	dev->rdev.stats.ocqp.max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	dev->rdev.stats.ocqp.fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	dev->rdev.stats.db_full = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	dev->rdev.stats.db_empty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	dev->rdev.stats.db_drop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	dev->rdev.stats.db_state_transitions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	dev->rdev.stats.tcam_full = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	dev->rdev.stats.act_ofld_conn_fails = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	dev->rdev.stats.pas_ofld_conn_fails = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	mutex_unlock(&dev->rdev.stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) static const struct file_operations stats_debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	.open    = stats_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	.read    = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	.llseek  = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	.write   = stats_clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) static int dump_ep(struct c4iw_ep *ep, struct c4iw_debugfs_data *epd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	int space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	space = epd->bufsize - epd->pos - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	if (space == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	if (ep->com.local_addr.ss_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		struct sockaddr_in *lsin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		struct sockaddr_in *rsin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		struct sockaddr_in *m_lsin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		struct sockaddr_in *m_rsin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		set_ep_sin_addrs(ep, &lsin, &rsin, &m_lsin, &m_rsin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		cc = snprintf(epd->buf + epd->pos, space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 			      "ep %p cm_id %p qp %p state %d flags 0x%lx "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 			      "history 0x%lx hwtid %d atid %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 			      "conn_na %u abort_na %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			      "%pI4:%d/%d <-> %pI4:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			      ep, ep->com.cm_id, ep->com.qp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 			      (int)ep->com.state, ep->com.flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 			      ep->com.history, ep->hwtid, ep->atid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 			      ep->stats.connect_neg_adv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 			      ep->stats.abort_neg_adv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 			      &lsin->sin_addr, ntohs(lsin->sin_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			      ntohs(m_lsin->sin_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 			      &rsin->sin_addr, ntohs(rsin->sin_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 			      ntohs(m_rsin->sin_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		struct sockaddr_in6 *lsin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		struct sockaddr_in6 *rsin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		struct sockaddr_in6 *m_lsin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		struct sockaddr_in6 *m_rsin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		set_ep_sin6_addrs(ep, &lsin6, &rsin6, &m_lsin6, &m_rsin6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		cc = snprintf(epd->buf + epd->pos, space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			      "ep %p cm_id %p qp %p state %d flags 0x%lx "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			      "history 0x%lx hwtid %d atid %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			      "conn_na %u abort_na %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 			      "%pI6:%d/%d <-> %pI6:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			      ep, ep->com.cm_id, ep->com.qp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			      (int)ep->com.state, ep->com.flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 			      ep->com.history, ep->hwtid, ep->atid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 			      ep->stats.connect_neg_adv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 			      ep->stats.abort_neg_adv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 			      &lsin6->sin6_addr, ntohs(lsin6->sin6_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			      ntohs(m_lsin6->sin6_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 			      &rsin6->sin6_addr, ntohs(rsin6->sin6_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 			      ntohs(m_rsin6->sin6_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	if (cc < space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		epd->pos += cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) int dump_listen_ep(struct c4iw_listen_ep *ep, struct c4iw_debugfs_data *epd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	int space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	space = epd->bufsize - epd->pos - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	if (space == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	if (ep->com.local_addr.ss_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		struct sockaddr_in *lsin = (struct sockaddr_in *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			&ep->com.cm_id->local_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		struct sockaddr_in *m_lsin = (struct sockaddr_in *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 			&ep->com.cm_id->m_local_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		cc = snprintf(epd->buf + epd->pos, space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			      "ep %p cm_id %p state %d flags 0x%lx stid %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 			      "backlog %d %pI4:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			      ep, ep->com.cm_id, (int)ep->com.state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 			      ep->com.flags, ep->stid, ep->backlog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			      &lsin->sin_addr, ntohs(lsin->sin_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 			      ntohs(m_lsin->sin_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		struct sockaddr_in6 *lsin6 = (struct sockaddr_in6 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 			&ep->com.cm_id->local_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		struct sockaddr_in6 *m_lsin6 = (struct sockaddr_in6 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 			&ep->com.cm_id->m_local_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		cc = snprintf(epd->buf + epd->pos, space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 			      "ep %p cm_id %p state %d flags 0x%lx stid %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 			      "backlog %d %pI6:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 			      ep, ep->com.cm_id, (int)ep->com.state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			      ep->com.flags, ep->stid, ep->backlog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 			      &lsin6->sin6_addr, ntohs(lsin6->sin6_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			      ntohs(m_lsin6->sin6_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	if (cc < space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		epd->pos += cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) static int ep_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	struct c4iw_debugfs_data *epd = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	if (!epd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		pr_info("%s null qpd?\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	vfree(epd->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	kfree(epd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) static int ep_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	struct c4iw_ep *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	struct c4iw_listen_ep *lep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	struct c4iw_debugfs_data *epd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	int count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	epd = kmalloc(sizeof(*epd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	if (!epd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	epd->devp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	epd->pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	xa_for_each(&epd->devp->hwtids, index, ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	xa_for_each(&epd->devp->atids, index, ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	xa_for_each(&epd->devp->stids, index, lep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	epd->bufsize = count * 240;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	epd->buf = vmalloc(epd->bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	if (!epd->buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		goto err1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	xa_lock_irq(&epd->devp->hwtids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	xa_for_each(&epd->devp->hwtids, index, ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		dump_ep(ep, epd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	xa_unlock_irq(&epd->devp->hwtids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	xa_lock_irq(&epd->devp->atids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	xa_for_each(&epd->devp->atids, index, ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		dump_ep(ep, epd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	xa_unlock_irq(&epd->devp->atids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	xa_lock_irq(&epd->devp->stids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	xa_for_each(&epd->devp->stids, index, lep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		dump_listen_ep(lep, epd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	xa_unlock_irq(&epd->devp->stids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	file->private_data = epd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) err1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	kfree(epd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) static const struct file_operations ep_debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	.open    = ep_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	.release = ep_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	.read    = debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) static void setup_debugfs(struct c4iw_dev *devp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	debugfs_create_file_size("qps", S_IWUSR, devp->debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 				 (void *)devp, &qp_debugfs_fops, 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	debugfs_create_file_size("stags", S_IWUSR, devp->debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				 (void *)devp, &stag_debugfs_fops, 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	debugfs_create_file_size("stats", S_IWUSR, devp->debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 				 (void *)devp, &stats_debugfs_fops, 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	debugfs_create_file_size("eps", S_IWUSR, devp->debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 				 (void *)devp, &ep_debugfs_fops, 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	if (c4iw_wr_log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		debugfs_create_file_size("wr_log", S_IWUSR, devp->debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 					 (void *)devp, &wr_log_debugfs_fops, 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			       struct c4iw_dev_ucontext *uctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	struct list_head *pos, *nxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	struct c4iw_qid_list *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	mutex_lock(&uctx->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	list_for_each_safe(pos, nxt, &uctx->qpids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		entry = list_entry(pos, struct c4iw_qid_list, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		list_del_init(&entry->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		if (!(entry->qid & rdev->qpmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			c4iw_put_resource(&rdev->resource.qid_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 					  entry->qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 			mutex_lock(&rdev->stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 			rdev->stats.qid.cur -= rdev->qpmask + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			mutex_unlock(&rdev->stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	list_for_each_safe(pos, nxt, &uctx->cqids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		entry = list_entry(pos, struct c4iw_qid_list, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		list_del_init(&entry->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	mutex_unlock(&uctx->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) void c4iw_init_dev_ucontext(struct c4iw_rdev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 			    struct c4iw_dev_ucontext *uctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	INIT_LIST_HEAD(&uctx->qpids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	INIT_LIST_HEAD(&uctx->cqids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	mutex_init(&uctx->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) /* Caller takes care of locking if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) static int c4iw_rdev_open(struct c4iw_rdev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	unsigned int factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	c4iw_init_dev_ucontext(rdev, &rdev->uctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	 * This implementation assumes udb_density == ucq_density!  Eventually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	 * we might need to support this but for now fail the open. Also the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	 * cqid and qpid range must match for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	if (rdev->lldi.udb_density != rdev->lldi.ucq_density) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		pr_err("%s: unsupported udb/ucq densities %u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		       pci_name(rdev->lldi.pdev), rdev->lldi.udb_density,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		       rdev->lldi.ucq_density);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	if (rdev->lldi.vr->qp.start != rdev->lldi.vr->cq.start ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	    rdev->lldi.vr->qp.size != rdev->lldi.vr->cq.size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		pr_err("%s: unsupported qp and cq id ranges qp start %u size %u cq start %u size %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		       pci_name(rdev->lldi.pdev), rdev->lldi.vr->qp.start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		       rdev->lldi.vr->qp.size, rdev->lldi.vr->cq.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		       rdev->lldi.vr->cq.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	/* This implementation requires a sge_host_page_size <= PAGE_SIZE. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	if (rdev->lldi.sge_host_page_size > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		pr_err("%s: unsupported sge host page size %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		       pci_name(rdev->lldi.pdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		       rdev->lldi.sge_host_page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	factor = PAGE_SIZE / rdev->lldi.sge_host_page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	rdev->qpmask = (rdev->lldi.udb_density * factor) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	rdev->cqmask = (rdev->lldi.ucq_density * factor) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	pr_debug("dev %s stag start 0x%0x size 0x%0x num stags %d pbl start 0x%0x size 0x%0x rq start 0x%0x size 0x%0x qp qid start %u size %u cq qid start %u size %u srq size %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		 pci_name(rdev->lldi.pdev), rdev->lldi.vr->stag.start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		 rdev->lldi.vr->stag.size, c4iw_num_stags(rdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		 rdev->lldi.vr->pbl.start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		 rdev->lldi.vr->pbl.size, rdev->lldi.vr->rq.start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		 rdev->lldi.vr->rq.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		 rdev->lldi.vr->qp.start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		 rdev->lldi.vr->qp.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		 rdev->lldi.vr->cq.start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		 rdev->lldi.vr->cq.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		 rdev->lldi.vr->srq.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	pr_debug("udb %pR db_reg %p gts_reg %p qpmask 0x%x cqmask 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		 &rdev->lldi.pdev->resource[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		 rdev->lldi.db_reg, rdev->lldi.gts_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		 rdev->qpmask, rdev->cqmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (c4iw_num_stags(rdev) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	rdev->stats.pd.total = T4_MAX_NUM_PD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	rdev->stats.stag.total = rdev->lldi.vr->stag.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	rdev->stats.pbl.total = rdev->lldi.vr->pbl.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	rdev->stats.rqt.total = rdev->lldi.vr->rq.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	rdev->stats.srqt.total = rdev->lldi.vr->srq.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	rdev->stats.ocqp.total = rdev->lldi.vr->ocq.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	rdev->stats.qid.total = rdev->lldi.vr->qp.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	err = c4iw_init_resource(rdev, c4iw_num_stags(rdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 				 T4_MAX_NUM_PD, rdev->lldi.vr->srq.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		pr_err("error %d initializing resources\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	err = c4iw_pblpool_create(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		pr_err("error %d initializing pbl pool\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		goto destroy_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	err = c4iw_rqtpool_create(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		pr_err("error %d initializing rqt pool\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		goto destroy_pblpool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	err = c4iw_ocqp_pool_create(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		pr_err("error %d initializing ocqp pool\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		goto destroy_rqtpool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	rdev->status_page = (struct t4_dev_status_page *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 			    __get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	if (!rdev->status_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		goto destroy_ocqp_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	rdev->status_page->qp_start = rdev->lldi.vr->qp.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	rdev->status_page->qp_size = rdev->lldi.vr->qp.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	rdev->status_page->cq_start = rdev->lldi.vr->cq.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	rdev->status_page->cq_size = rdev->lldi.vr->cq.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	rdev->status_page->write_cmpl_supported = rdev->lldi.write_cmpl_support;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	if (c4iw_wr_log) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		rdev->wr_log = kcalloc(1 << c4iw_wr_log_size_order,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 				       sizeof(*rdev->wr_log),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 				       GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		if (rdev->wr_log) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 			rdev->wr_log_size = 1 << c4iw_wr_log_size_order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			atomic_set(&rdev->wr_log_idx, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	rdev->free_workq = create_singlethread_workqueue("iw_cxgb4_free");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	if (!rdev->free_workq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		goto err_free_status_page_and_wr_log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	rdev->status_page->db_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	init_completion(&rdev->rqt_compl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	init_completion(&rdev->pbl_compl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	kref_init(&rdev->rqt_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	kref_init(&rdev->pbl_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) err_free_status_page_and_wr_log:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	if (c4iw_wr_log && rdev->wr_log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		kfree(rdev->wr_log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	free_page((unsigned long)rdev->status_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) destroy_ocqp_pool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	c4iw_ocqp_pool_destroy(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) destroy_rqtpool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	c4iw_rqtpool_destroy(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) destroy_pblpool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	c4iw_pblpool_destroy(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) destroy_resource:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	c4iw_destroy_resource(&rdev->resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) static void c4iw_rdev_close(struct c4iw_rdev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	kfree(rdev->wr_log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	c4iw_release_dev_ucontext(rdev, &rdev->uctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	free_page((unsigned long)rdev->status_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	c4iw_pblpool_destroy(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	c4iw_rqtpool_destroy(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	wait_for_completion(&rdev->pbl_compl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	wait_for_completion(&rdev->rqt_compl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	c4iw_ocqp_pool_destroy(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	destroy_workqueue(rdev->free_workq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	c4iw_destroy_resource(&rdev->resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) void c4iw_dealloc(struct uld_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	c4iw_rdev_close(&ctx->dev->rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	WARN_ON(!xa_empty(&ctx->dev->cqs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	WARN_ON(!xa_empty(&ctx->dev->qps));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	WARN_ON(!xa_empty(&ctx->dev->mrs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	wait_event(ctx->dev->wait, xa_empty(&ctx->dev->hwtids));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	WARN_ON(!xa_empty(&ctx->dev->stids));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	WARN_ON(!xa_empty(&ctx->dev->atids));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	if (ctx->dev->rdev.bar2_kva)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		iounmap(ctx->dev->rdev.bar2_kva);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	if (ctx->dev->rdev.oc_mw_kva)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		iounmap(ctx->dev->rdev.oc_mw_kva);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	ib_dealloc_device(&ctx->dev->ibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	ctx->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) static void c4iw_remove(struct uld_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	pr_debug("c4iw_dev %p\n", ctx->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	debugfs_remove_recursive(ctx->dev->debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	c4iw_unregister_device(ctx->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	c4iw_dealloc(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) static int rdma_supported(const struct cxgb4_lld_info *infop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	return infop->vr->stag.size > 0 && infop->vr->pbl.size > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	       infop->vr->rq.size > 0 && infop->vr->qp.size > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	       infop->vr->cq.size > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	struct c4iw_dev *devp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	if (!rdma_supported(infop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		pr_info("%s: RDMA not supported on this device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			pci_name(infop->pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		return ERR_PTR(-ENOSYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	if (!ocqp_supported(infop))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		pr_info("%s: On-Chip Queues not supported on this device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			pci_name(infop->pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	devp = ib_alloc_device(c4iw_dev, ibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	if (!devp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		pr_err("Cannot allocate ib device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	devp->rdev.lldi = *infop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	/* init various hw-queue params based on lld info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	pr_debug("Ing. padding boundary is %d, egrsstatuspagesize = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		 devp->rdev.lldi.sge_ingpadboundary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		 devp->rdev.lldi.sge_egrstatuspagesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	devp->rdev.hw_queue.t4_eq_status_entries =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		devp->rdev.lldi.sge_egrstatuspagesize / 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	devp->rdev.hw_queue.t4_max_eq_size = 65520;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	devp->rdev.hw_queue.t4_max_iq_size = 65520;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	devp->rdev.hw_queue.t4_max_rq_size = 8192 -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		devp->rdev.hw_queue.t4_eq_status_entries - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	devp->rdev.hw_queue.t4_max_sq_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		devp->rdev.hw_queue.t4_max_eq_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		devp->rdev.hw_queue.t4_eq_status_entries - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	devp->rdev.hw_queue.t4_max_qp_depth =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		devp->rdev.hw_queue.t4_max_rq_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	devp->rdev.hw_queue.t4_max_cq_depth =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		devp->rdev.hw_queue.t4_max_iq_size - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	devp->rdev.hw_queue.t4_stat_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		devp->rdev.lldi.sge_egrstatuspagesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	 * For T5/T6 devices, we map all of BAR2 with WC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	 * For T4 devices with onchip qp mem, we map only that part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	 * of BAR2 with WC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	devp->rdev.bar2_pa = pci_resource_start(devp->rdev.lldi.pdev, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	if (!is_t4(devp->rdev.lldi.adapter_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		devp->rdev.bar2_kva = ioremap_wc(devp->rdev.bar2_pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 			pci_resource_len(devp->rdev.lldi.pdev, 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		if (!devp->rdev.bar2_kva) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 			pr_err("Unable to ioremap BAR2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 			ib_dealloc_device(&devp->ibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 			return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	} else if (ocqp_supported(infop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		devp->rdev.oc_mw_pa =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 			pci_resource_start(devp->rdev.lldi.pdev, 2) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 			pci_resource_len(devp->rdev.lldi.pdev, 2) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 			roundup_pow_of_two(devp->rdev.lldi.vr->ocq.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		devp->rdev.oc_mw_kva = ioremap_wc(devp->rdev.oc_mw_pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			devp->rdev.lldi.vr->ocq.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		if (!devp->rdev.oc_mw_kva) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			pr_err("Unable to ioremap onchip mem\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			ib_dealloc_device(&devp->ibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	pr_debug("ocq memory: hw_start 0x%x size %u mw_pa 0x%lx mw_kva %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		 devp->rdev.lldi.vr->ocq.start, devp->rdev.lldi.vr->ocq.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		 devp->rdev.oc_mw_pa, devp->rdev.oc_mw_kva);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	ret = c4iw_rdev_open(&devp->rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		pr_err("Unable to open CXIO rdev err %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		ib_dealloc_device(&devp->ibdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	xa_init_flags(&devp->cqs, XA_FLAGS_LOCK_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	xa_init_flags(&devp->qps, XA_FLAGS_LOCK_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	xa_init_flags(&devp->mrs, XA_FLAGS_LOCK_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	xa_init_flags(&devp->hwtids, XA_FLAGS_LOCK_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	xa_init_flags(&devp->atids, XA_FLAGS_LOCK_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	xa_init_flags(&devp->stids, XA_FLAGS_LOCK_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	mutex_init(&devp->rdev.stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	mutex_init(&devp->db_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	INIT_LIST_HEAD(&devp->db_fc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	init_waitqueue_head(&devp->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	devp->avail_ird = devp->rdev.lldi.max_ird_adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	if (c4iw_debugfs_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		devp->debugfs_root = debugfs_create_dir(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 					pci_name(devp->rdev.lldi.pdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 					c4iw_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		setup_debugfs(devp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	return devp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) static void *c4iw_uld_add(const struct cxgb4_lld_info *infop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	struct uld_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	static int vers_printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	if (!vers_printed++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		pr_info("Chelsio T4/T5 RDMA Driver - version %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 			DRV_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	if (!ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 		ctx = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	ctx->lldi = *infop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	pr_debug("found device %s nchan %u nrxq %u ntxq %u nports %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		 pci_name(ctx->lldi.pdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		 ctx->lldi.nchan, ctx->lldi.nrxq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		 ctx->lldi.ntxq, ctx->lldi.nports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	mutex_lock(&dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	list_add_tail(&ctx->entry, &uld_ctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	mutex_unlock(&dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	for (i = 0; i < ctx->lldi.nrxq; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		pr_debug("rxqid[%u] %u\n", i, ctx->lldi.rxq_ids[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) static inline struct sk_buff *copy_gl_to_skb_pkt(const struct pkt_gl *gl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 						 const __be64 *rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 						 u32 pktshift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	 * Allocate space for cpl_pass_accept_req which will be synthesized by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	 * driver. Once the driver synthesizes the request the skb will go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	 * through the regular cpl_pass_accept_req processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	 * The math here assumes sizeof cpl_pass_accept_req >= sizeof
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	 * cpl_rx_pkt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	skb = alloc_skb(gl->tot_len + sizeof(struct cpl_pass_accept_req) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 			sizeof(struct rss_header) - pktshift, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	__skb_put(skb, gl->tot_len + sizeof(struct cpl_pass_accept_req) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		  sizeof(struct rss_header) - pktshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	 * This skb will contain:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	 *   rss_header from the rspq descriptor (1 flit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	 *   cpl_rx_pkt struct from the rspq descriptor (2 flits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	 *   space for the difference between the size of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	 *      rx_pkt and pass_accept_req cpl (1 flit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	 *   the packet data from the gl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	skb_copy_to_linear_data(skb, rsp, sizeof(struct cpl_pass_accept_req) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 				sizeof(struct rss_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	skb_copy_to_linear_data_offset(skb, sizeof(struct rss_header) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 				       sizeof(struct cpl_pass_accept_req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 				       gl->va + pktshift,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 				       gl->tot_len - pktshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) static inline int recv_rx_pkt(struct c4iw_dev *dev, const struct pkt_gl *gl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 			   const __be64 *rsp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	unsigned int opcode = *(u8 *)rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	if (opcode != CPL_RX_PKT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	skb = copy_gl_to_skb_pkt(gl , rsp, dev->rdev.lldi.sge_pktshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	if (c4iw_handlers[opcode] == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		pr_info("%s no handler opcode 0x%x...\n", __func__, opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	c4iw_handlers[opcode](dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) static int c4iw_uld_rx_handler(void *handle, const __be64 *rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 			const struct pkt_gl *gl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	struct uld_ctx *ctx = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	struct c4iw_dev *dev = ctx->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	u8 opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	if (gl == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		/* omit RSS and rsp_ctrl at end of descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		skb = alloc_skb(256, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 			goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 		__skb_put(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 		skb_copy_to_linear_data(skb, &rsp[1], len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	} else if (gl == CXGB4_MSG_AN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		const struct rsp_ctrl *rc = (void *)rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		u32 qid = be32_to_cpu(rc->pldbuflen_qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 		c4iw_ev_handler(dev, qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	} else if (unlikely(*(u8 *)rsp != *(u8 *)gl->va)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		if (recv_rx_pkt(dev, gl, rsp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		pr_info("%s: unexpected FL contents at %p, RSS %#llx, FL %#llx, len %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 			pci_name(ctx->lldi.pdev), gl->va,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 			be64_to_cpu(*rsp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 			be64_to_cpu(*(__force __be64 *)gl->va),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 			gl->tot_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		skb = cxgb4_pktgl_to_skb(gl, 128, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 		if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 			goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	opcode = *(u8 *)rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	if (c4iw_handlers[opcode]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		c4iw_handlers[opcode](dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		pr_info("%s no handler opcode 0x%x...\n", __func__, opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) static int c4iw_uld_state_change(void *handle, enum cxgb4_state new_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	struct uld_ctx *ctx = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	pr_debug("new_state %u\n", new_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	switch (new_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	case CXGB4_STATE_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		pr_info("%s: Up\n", pci_name(ctx->lldi.pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		if (!ctx->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 			ctx->dev = c4iw_alloc(&ctx->lldi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 			if (IS_ERR(ctx->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 				pr_err("%s: initialization failed: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 				       pci_name(ctx->lldi.pdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 				       PTR_ERR(ctx->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 				ctx->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 			INIT_WORK(&ctx->reg_work, c4iw_register_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 			queue_work(reg_workq, &ctx->reg_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	case CXGB4_STATE_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		pr_info("%s: Down\n", pci_name(ctx->lldi.pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		if (ctx->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 			c4iw_remove(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	case CXGB4_STATE_FATAL_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	case CXGB4_STATE_START_RECOVERY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		pr_info("%s: Fatal Error\n", pci_name(ctx->lldi.pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		if (ctx->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 			struct ib_event event = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 			ctx->dev->rdev.flags |= T4_FATAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			event.event  = IB_EVENT_DEVICE_FATAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 			event.device = &ctx->dev->ibdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 			ib_dispatch_event(&event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 			c4iw_remove(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	case CXGB4_STATE_DETACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		pr_info("%s: Detach\n", pci_name(ctx->lldi.pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 		if (ctx->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 			c4iw_remove(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) static void stop_queues(struct uld_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	struct c4iw_qp *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	unsigned long index, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	xa_lock_irqsave(&ctx->dev->qps, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	ctx->dev->rdev.stats.db_state_transitions++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	ctx->dev->db_state = STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	if (ctx->dev->rdev.flags & T4_STATUS_PAGE_DISABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		xa_for_each(&ctx->dev->qps, index, qp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 			t4_disable_wq_db(&qp->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		ctx->dev->rdev.status_page->db_off = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	xa_unlock_irqrestore(&ctx->dev->qps, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) static void resume_rc_qp(struct c4iw_qp *qp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	spin_lock(&qp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	t4_ring_sq_db(&qp->wq, qp->wq.sq.wq_pidx_inc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	qp->wq.sq.wq_pidx_inc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	t4_ring_rq_db(&qp->wq, qp->wq.rq.wq_pidx_inc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	qp->wq.rq.wq_pidx_inc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	spin_unlock(&qp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) static void resume_a_chunk(struct uld_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	struct c4iw_qp *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	for (i = 0; i < DB_FC_RESUME_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		qp = list_first_entry(&ctx->dev->db_fc_list, struct c4iw_qp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 				      db_fc_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		list_del_init(&qp->db_fc_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		resume_rc_qp(qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		if (list_empty(&ctx->dev->db_fc_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) static void resume_queues(struct uld_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	xa_lock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	if (ctx->dev->db_state != STOPPED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	ctx->dev->db_state = FLOW_CONTROL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		if (list_empty(&ctx->dev->db_fc_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			struct c4iw_qp *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 			unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 			WARN_ON(ctx->dev->db_state != FLOW_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 			ctx->dev->db_state = NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 			ctx->dev->rdev.stats.db_state_transitions++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			if (ctx->dev->rdev.flags & T4_STATUS_PAGE_DISABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 				xa_for_each(&ctx->dev->qps, index, qp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 					t4_enable_wq_db(&qp->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 				ctx->dev->rdev.status_page->db_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 			if (cxgb4_dbfifo_count(ctx->dev->rdev.lldi.ports[0], 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 			    < (ctx->dev->rdev.lldi.dbfifo_int_thresh <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 			       DB_FC_DRAIN_THRESH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 				resume_a_chunk(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 			if (!list_empty(&ctx->dev->db_fc_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 				xa_unlock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 				if (DB_FC_RESUME_DELAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 					set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 					schedule_timeout(DB_FC_RESUME_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 				xa_lock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 				if (ctx->dev->db_state != FLOW_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	if (ctx->dev->db_state != NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		ctx->dev->rdev.stats.db_fc_interruptions++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	xa_unlock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) struct qp_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	unsigned idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	struct c4iw_qp **qps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) static void deref_qps(struct qp_list *qp_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	for (idx = 0; idx < qp_list->idx; idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		c4iw_qp_rem_ref(&qp_list->qps[idx]->ibqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) static void recover_lost_dbs(struct uld_ctx *ctx, struct qp_list *qp_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	for (idx = 0; idx < qp_list->idx; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		struct c4iw_qp *qp = qp_list->qps[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		xa_lock_irq(&qp->rhp->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		spin_lock(&qp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 		ret = cxgb4_sync_txq_pidx(qp->rhp->rdev.lldi.ports[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 					  qp->wq.sq.qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 					  t4_sq_host_wq_pidx(&qp->wq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 					  t4_sq_wq_size(&qp->wq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 			pr_err("%s: Fatal error - DB overflow recovery failed - error syncing SQ qid %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 			       pci_name(ctx->lldi.pdev), qp->wq.sq.qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 			spin_unlock(&qp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 			xa_unlock_irq(&qp->rhp->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		qp->wq.sq.wq_pidx_inc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		ret = cxgb4_sync_txq_pidx(qp->rhp->rdev.lldi.ports[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 					  qp->wq.rq.qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 					  t4_rq_host_wq_pidx(&qp->wq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 					  t4_rq_wq_size(&qp->wq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 			pr_err("%s: Fatal error - DB overflow recovery failed - error syncing RQ qid %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 			       pci_name(ctx->lldi.pdev), qp->wq.rq.qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 			spin_unlock(&qp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 			xa_unlock_irq(&qp->rhp->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		qp->wq.rq.wq_pidx_inc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		spin_unlock(&qp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		xa_unlock_irq(&qp->rhp->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		/* Wait for the dbfifo to drain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		while (cxgb4_dbfifo_count(qp->rhp->rdev.lldi.ports[0], 1) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 			schedule_timeout(usecs_to_jiffies(10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) static void recover_queues(struct uld_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	struct c4iw_qp *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	struct qp_list qp_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	/* slow everybody down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	schedule_timeout(usecs_to_jiffies(1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	/* flush the SGE contexts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	ret = cxgb4_flush_eq_cache(ctx->dev->rdev.lldi.ports[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 		pr_err("%s: Fatal error - DB overflow recovery failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 		       pci_name(ctx->lldi.pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	/* Count active queues so we can build a list of queues to recover */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	xa_lock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	WARN_ON(ctx->dev->db_state != STOPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	ctx->dev->db_state = RECOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	xa_for_each(&ctx->dev->qps, index, qp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	qp_list.qps = kcalloc(count, sizeof(*qp_list.qps), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	if (!qp_list.qps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		xa_unlock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	qp_list.idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	/* add and ref each qp so it doesn't get freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	xa_for_each(&ctx->dev->qps, index, qp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		c4iw_qp_add_ref(&qp->ibqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		qp_list.qps[qp_list.idx++] = qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	xa_unlock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	/* now traverse the list in a safe context to recover the db state*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	recover_lost_dbs(ctx, &qp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	/* we're almost done!  deref the qps and clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	deref_qps(&qp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	kfree(qp_list.qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	xa_lock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	WARN_ON(ctx->dev->db_state != RECOVERY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	ctx->dev->db_state = STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	xa_unlock_irq(&ctx->dev->qps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) static int c4iw_uld_control(void *handle, enum cxgb4_control control, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	struct uld_ctx *ctx = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	switch (control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	case CXGB4_CONTROL_DB_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		stop_queues(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 		ctx->dev->rdev.stats.db_full++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	case CXGB4_CONTROL_DB_EMPTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		resume_queues(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		mutex_lock(&ctx->dev->rdev.stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 		ctx->dev->rdev.stats.db_empty++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 		mutex_unlock(&ctx->dev->rdev.stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	case CXGB4_CONTROL_DB_DROP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		recover_queues(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		mutex_lock(&ctx->dev->rdev.stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		ctx->dev->rdev.stats.db_drop++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 		mutex_unlock(&ctx->dev->rdev.stats.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 		pr_warn("%s: unknown control cmd %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 			pci_name(ctx->lldi.pdev), control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) static struct cxgb4_uld_info c4iw_uld_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	.name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	.nrxq = MAX_ULD_QSETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	.ntxq = MAX_ULD_QSETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	.rxq_size = 511,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	.ciq = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	.lro = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	.add = c4iw_uld_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	.rx_handler = c4iw_uld_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	.state_change = c4iw_uld_state_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	.control = c4iw_uld_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) void _c4iw_free_wr_wait(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	struct c4iw_wr_wait *wr_waitp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	wr_waitp = container_of(kref, struct c4iw_wr_wait, kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	pr_debug("Free wr_wait %p\n", wr_waitp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	kfree(wr_waitp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) struct c4iw_wr_wait *c4iw_alloc_wr_wait(gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	struct c4iw_wr_wait *wr_waitp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	wr_waitp = kzalloc(sizeof(*wr_waitp), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	if (wr_waitp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 		kref_init(&wr_waitp->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		pr_debug("wr_wait %p\n", wr_waitp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	return wr_waitp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) static int __init c4iw_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	err = c4iw_cm_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	c4iw_debugfs_root = debugfs_create_dir(DRV_NAME, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	reg_workq = create_singlethread_workqueue("Register_iWARP_device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	if (!reg_workq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		pr_err("Failed creating workqueue to register iwarp device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	cxgb4_register_uld(CXGB4_ULD_RDMA, &c4iw_uld_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) static void __exit c4iw_exit_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	struct uld_ctx *ctx, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	mutex_lock(&dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	list_for_each_entry_safe(ctx, tmp, &uld_ctx_list, entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		if (ctx->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 			c4iw_remove(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		kfree(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	mutex_unlock(&dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	flush_workqueue(reg_workq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	destroy_workqueue(reg_workq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	cxgb4_unregister_uld(CXGB4_ULD_RDMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	c4iw_cm_term();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	debugfs_remove_recursive(c4iw_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) module_init(c4iw_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) module_exit(c4iw_exit_module);