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) 2015-2018 Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * This file is provided under a dual BSD/GPLv2 license.  When using or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * redistributing this file, you may do so under either license.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * GPL LICENSE SUMMARY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * it under the terms of version 2 of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * This program is distributed in the hope that it will be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * BSD LICENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *  - Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *    notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *  - Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *    notice, this list of conditions and the following disclaimer in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *    the documentation and/or other materials provided with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *    distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *  - Neither the name of Intel Corporation nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *    contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *    from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/ratelimit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/fault-inject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include "hfi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include "trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include "debugfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include "device.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include "qp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include "sdma.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include "fault.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) static struct dentry *hfi1_dbg_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) /* wrappers to enforce srcu in seq file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) ssize_t hfi1_seq_read(struct file *file, char __user *buf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 		      loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	struct dentry *d = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	ssize_t r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	r = debugfs_file_get(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	if (unlikely(r))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	r = seq_read(file, buf, size, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	debugfs_file_put(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) loff_t hfi1_seq_lseek(struct file *file, loff_t offset, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	struct dentry *d = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	loff_t r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	r = debugfs_file_get(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	if (unlikely(r))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	r = seq_lseek(file, offset, whence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	debugfs_file_put(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #define private2dd(file) (file_inode(file)->i_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) #define private2ppd(file) (file_inode(file)->i_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	struct hfi1_opcode_stats_perctx *opstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	if (*pos >= ARRAY_SIZE(opstats->stats))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	struct hfi1_opcode_stats_perctx *opstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	if (*pos >= ARRAY_SIZE(opstats->stats))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) static int opcode_stats_show(struct seq_file *s, u8 i, u64 packets, u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	if (!packets && !bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 		return SEQ_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	seq_printf(s, "%02x %llu/%llu\n", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		   (unsigned long long)packets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		   (unsigned long long)bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) static int _opcode_stats_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	loff_t *spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	loff_t i = *spos, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	u64 n_packets = 0, n_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	struct hfi1_ctxtdata *rcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	for (j = 0; j < dd->first_dyn_alloc_ctxt; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		rcd = hfi1_rcd_get_by_index(dd, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 		if (rcd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 			n_packets += rcd->opstats->stats[i].n_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 			n_bytes += rcd->opstats->stats[i].n_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		hfi1_rcd_put(rcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	return opcode_stats_show(s, i, n_packets, n_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) DEBUGFS_SEQ_FILE_OPS(opcode_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) DEBUGFS_SEQ_FILE_OPEN(opcode_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) DEBUGFS_FILE_OPS(opcode_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static void *_tx_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	return _opcode_stats_seq_start(s, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static void *_tx_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	return _opcode_stats_seq_next(s, v, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) static void _tx_opcode_stats_seq_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static int _tx_opcode_stats_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	loff_t *spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	loff_t i = *spos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	u64 n_packets = 0, n_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	for_each_possible_cpu(j) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		struct hfi1_opcode_stats_perctx *s =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 			per_cpu_ptr(dd->tx_opstats, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		n_packets += s->stats[i].n_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		n_bytes += s->stats[i].n_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	return opcode_stats_show(s, i, n_packets, n_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) DEBUGFS_SEQ_FILE_OPS(tx_opcode_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) DEBUGFS_SEQ_FILE_OPEN(tx_opcode_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) DEBUGFS_FILE_OPS(tx_opcode_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) static void *_ctx_stats_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	if (!*pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		return SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	if (*pos >= dd->first_dyn_alloc_ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) static void *_ctx_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	if (v == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	if (*pos >= dd->first_dyn_alloc_ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) static void _ctx_stats_seq_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	/* nothing allocated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static int _ctx_stats_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	loff_t *spos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	loff_t i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	u64 n_packets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	struct hfi1_ctxtdata *rcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	if (v == SEQ_START_TOKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		seq_puts(s, "Ctx:npkts\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	i = *spos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	rcd = hfi1_rcd_get_by_index_safe(dd, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (!rcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		return SEQ_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	for (j = 0; j < ARRAY_SIZE(rcd->opstats->stats); j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		n_packets += rcd->opstats->stats[j].n_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	hfi1_rcd_put(rcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	if (!n_packets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		return SEQ_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	seq_printf(s, "  %llu:%llu\n", i, n_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) DEBUGFS_SEQ_FILE_OPS(ctx_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) DEBUGFS_FILE_OPS(ctx_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	__acquires(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	struct rvt_qp_iter *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	loff_t n = *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	iter = rvt_qp_iter_init(s->private, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	/* stop calls rcu_read_unlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	if (!iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		if (rvt_qp_iter_next(iter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 			kfree(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	} while (n--);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	return iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 				loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	__must_hold(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	struct rvt_qp_iter *iter = iter_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	(*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	if (rvt_qp_iter_next(iter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		kfree(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	return iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	__releases(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) static int _qp_stats_seq_show(struct seq_file *s, void *iter_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	struct rvt_qp_iter *iter = iter_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	if (!iter)
^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) 	qp_iter_print(s, iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) DEBUGFS_SEQ_FILE_OPS(qp_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) DEBUGFS_SEQ_FILE_OPEN(qp_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) DEBUGFS_FILE_OPS(qp_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) static void *_sdes_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	struct hfi1_ibdev *ibd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	if (!dd->per_sdma || *pos >= dd->num_sdma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	if (!dd->per_sdma || *pos >= dd->num_sdma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) static void _sdes_seq_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) static int _sdes_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	loff_t *spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	loff_t i = *spos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	sdma_seqfile_dump_sde(s, &dd->per_sdma[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) DEBUGFS_SEQ_FILE_OPS(sdes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) DEBUGFS_SEQ_FILE_OPEN(sdes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) DEBUGFS_FILE_OPS(sdes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) static void *_rcds_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	struct hfi1_ibdev *ibd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	if (!dd->rcd || *pos >= dd->n_krcv_queues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) static void *_rcds_seq_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	if (!dd->rcd || *pos >= dd->num_rcv_contexts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) static void _rcds_seq_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) static int _rcds_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	struct hfi1_ctxtdata *rcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	loff_t *spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	loff_t i = *spos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	rcd = hfi1_rcd_get_by_index_safe(dd, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	if (rcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		seqfile_dump_rcd(s, rcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	hfi1_rcd_put(rcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) DEBUGFS_SEQ_FILE_OPS(rcds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) DEBUGFS_SEQ_FILE_OPEN(rcds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) DEBUGFS_FILE_OPS(rcds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) static void *_pios_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	struct hfi1_ibdev *ibd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	if (!dd->send_contexts || *pos >= dd->num_send_contexts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) static void *_pios_seq_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	if (!dd->send_contexts || *pos >= dd->num_send_contexts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) static void _pios_seq_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) static int _pios_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	struct send_context_info *sci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	loff_t *spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	loff_t i = *spos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	spin_lock_irqsave(&dd->sc_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	sci = &dd->send_contexts[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	if (sci && sci->type != SC_USER && sci->allocated && sci->sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		seqfile_dump_sci(s, i, sci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	spin_unlock_irqrestore(&dd->sc_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) DEBUGFS_SEQ_FILE_OPS(pios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) DEBUGFS_SEQ_FILE_OPEN(pios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) DEBUGFS_FILE_OPS(pios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) /* read the per-device counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) static ssize_t dev_counters_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 				 size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	u64 *counters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	size_t avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	ssize_t rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	dd = private2dd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	avail = hfi1_read_cntrs(dd, NULL, &counters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	rval =  simple_read_from_buffer(buf, count, ppos, counters, avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) /* read the per-device counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) static ssize_t dev_names_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			      size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	char *names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	size_t avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	ssize_t rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	dd = private2dd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	avail = hfi1_read_cntrs(dd, &names, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	rval =  simple_read_from_buffer(buf, count, ppos, names, avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) struct counter_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	const struct file_operations ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494)  * Could use file_inode(file)->i_ino to figure out which file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495)  * instead of separate routine for each, but for now, this works...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) /* read the per-port names (same for each port) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) static ssize_t portnames_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			      size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	char *names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	size_t avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	ssize_t rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	dd = private2dd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	rval = simple_read_from_buffer(buf, count, ppos, names, avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	return rval;
^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) /* read the per-port counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 				      size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	u64 *counters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	size_t avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	ssize_t rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	avail = hfi1_read_portcntrs(ppd, NULL, &counters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) static void check_dyn_flag(u64 scratch0, char *p, int size, int *used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			   int this_hfi, int hfi, u32 flag, const char *what)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	u32 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	mask = flag << (hfi ? CR_DYN_SHIFT : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	if (scratch0 & mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		*used += scnprintf(p + *used, size - *used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 				   "  0x%08x - HFI%d %s in use, %s device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 				   mask, hfi, what,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 				   this_hfi == hfi ? "this" : "other");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) static ssize_t asic_flags_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			       size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	u64 scratch0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	int used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	dd = ppd->dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	size = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	tmp = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	used += scnprintf(tmp + used, size - used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 			  "Resource flags: 0x%016llx\n", scratch0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	/* check permanent flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	if (scratch0 & CR_THERM_INIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		used += scnprintf(tmp + used, size - used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 				  "  0x%08x - thermal monitoring initialized\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 				  (u32)CR_THERM_INIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	/* check each dynamic flag on each HFI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 			       CR_SBUS, "SBus");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			       CR_EPROM, "EPROM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 			       CR_I2C1, "i2c chain 1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 			       CR_I2C2, "i2c chain 2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) static ssize_t asic_flags_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	char *buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	unsigned long long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	u64 scratch0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	u64 clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	dd = ppd->dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	/* zero terminate and read the expected integer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	buff = memdup_user_nul(buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	if (IS_ERR(buff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		return PTR_ERR(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	ret = kstrtoull(buff, 0, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		goto do_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	clear = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	/* obtain exclusive access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	mutex_lock(&dd->asic_data->asic_resource_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	acquire_hw_mutex(dd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	scratch0 &= ~clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	/* force write to be visible to other HFI on another OS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	(void)read_csr(dd, ASIC_CFG_SCRATCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	release_hw_mutex(dd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	mutex_unlock(&dd->asic_data->asic_resource_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	/* return the number of bytes written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631)  do_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	kfree(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) /* read the dc8051 memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) static ssize_t dc8051_memory_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 				  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	struct hfi1_pportdata *ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	ssize_t rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	void *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	loff_t start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	/* the checks below expect the position to be positive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	if (*ppos < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	tmp = kzalloc(DC8051_DATA_MEM_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	 * Fill in the requested portion of the temporary buffer from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	 * 8051 memory.  The 8051 memory read is done in terms of 8 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	 * Adjust start and end to fit.  Skip reading anything if out of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	 * range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	start = *ppos & ~0x7;	/* round down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	if (start < DC8051_DATA_MEM_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		end = (*ppos + count + 7) & ~0x7; /* round up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		if (end > DC8051_DATA_MEM_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 			end = DC8051_DATA_MEM_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		rval = read_8051_data(ppd->dd, start, end - start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 				      (u64 *)(tmp + start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		if (rval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	rval = simple_read_from_buffer(buf, count, ppos, tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 				       DC8051_DATA_MEM_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) static ssize_t debugfs_lcb_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	struct hfi1_pportdata *ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	struct hfi1_devdata *dd = ppd->dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	unsigned long total, csr_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	u64 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	if (*ppos < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	/* only read 8 byte quantities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	if ((count % 8) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	/* offset must be 8-byte aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	if ((*ppos % 8) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	/* do nothing if out of range or zero count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	if (*ppos >= (LCB_END - LCB_START) || !count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	/* reduce count if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	if (*ppos + count > LCB_END - LCB_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		count = (LCB_END - LCB_START) - *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	csr_off = LCB_START + *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	for (total = 0; total < count; total += 8, csr_off += 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		if (read_lcb_csr(dd, csr_off, (u64 *)&data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 			break; /* failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		if (put_user(data, (unsigned long __user *)(buf + total)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	*ppos += total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	return total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) static ssize_t debugfs_lcb_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 				 size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	struct hfi1_pportdata *ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	struct hfi1_devdata *dd = ppd->dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	unsigned long total, csr_off, data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	if (*ppos < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	/* only write 8 byte quantities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	if ((count % 8) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	/* offset must be 8-byte aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	if ((*ppos % 8) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	/* do nothing if out of range or zero count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (*ppos >= (LCB_END - LCB_START) || !count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	/* reduce count if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	if (*ppos + count > LCB_END - LCB_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		count = (LCB_END - LCB_START) - *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	csr_off = LCB_START + *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	for (total = 0; total < count; total += 8, csr_off += 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		if (get_user(data, (unsigned long __user *)(buf + total)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		if (write_lcb_csr(dd, csr_off, data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			break; /* failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	*ppos += total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	return total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745)  * read the per-port QSFP data for ppd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 				 size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	ret = qsfp_dump(ppd, tmp, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		ret = simple_read_from_buffer(buf, count, ppos, tmp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) /* Do an i2c write operation on the chain for the given HFI. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 				   size_t count, loff_t *ppos, u32 target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	char *buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	int i2c_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	int total_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	/* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	i2c_addr = (*ppos >> 16) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	offset = *ppos & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	/* explicitly reject invalid address 0 to catch cp and cat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if (i2c_addr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	buff = memdup_user(buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	if (IS_ERR(buff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		return PTR_ERR(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	if (total_written < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		ret = total_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		goto _free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	*ppos += total_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	ret = total_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801)  _free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	kfree(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) /* Do an i2c write operation on chain for HFI 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 				  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	return __i2c_debugfs_write(file, buf, count, ppos, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) /* Do an i2c write operation on chain for HFI 1. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 				  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	return __i2c_debugfs_write(file, buf, count, ppos, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) /* Do an i2c read operation on the chain for the given HFI. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 				  size_t count, loff_t *ppos, u32 target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	char *buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	int i2c_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	int total_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	/* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	i2c_addr = (*ppos >> 16) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	offset = *ppos & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	/* explicitly reject invalid address 0 to catch cp and cat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	if (i2c_addr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	buff = kmalloc(count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	if (!buff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	if (total_read < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		ret = total_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		goto _free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	*ppos += total_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	ret = copy_to_user(buf, buff, total_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		goto _free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	ret = total_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861)  _free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	kfree(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) /* Do an i2c read operation on chain for HFI 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 				 size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	return __i2c_debugfs_read(file, buf, count, ppos, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) /* Do an i2c read operation on chain for HFI 1. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 				 size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	return __i2c_debugfs_read(file, buf, count, ppos, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) /* Do a QSFP write operation on the i2c chain for the given HFI. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 				    size_t count, loff_t *ppos, u32 target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	char *buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	int total_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	if (*ppos + count > QSFP_PAGESIZE * 4) /* base page + page00-page03 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	buff = memdup_user(buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	if (IS_ERR(buff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		return PTR_ERR(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	total_written = qsfp_write(ppd, target, *ppos, buff, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	if (total_written < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		ret = total_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		goto _free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	*ppos += total_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	ret = total_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)  _free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	kfree(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) /* Do a QSFP write operation on i2c chain for HFI 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 				   size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	return __qsfp_debugfs_write(file, buf, count, ppos, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) /* Do a QSFP write operation on i2c chain for HFI 1. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 				   size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	return __qsfp_debugfs_write(file, buf, count, ppos, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) /* Do a QSFP read operation on the i2c chain for the given HFI. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 				   size_t count, loff_t *ppos, u32 target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	char *buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	int total_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		goto _return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	buff = kmalloc(count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	if (!buff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		goto _return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	total_read = qsfp_read(ppd, target, *ppos, buff, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	if (total_read < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		ret = total_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		goto _free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	*ppos += total_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	ret = copy_to_user(buf, buff, total_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		goto _free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	ret = total_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965)  _free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	kfree(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)  _return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) /* Do a QSFP read operation on i2c chain for HFI 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 				  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	return __qsfp_debugfs_read(file, buf, count, ppos, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) /* Do a QSFP read operation on i2c chain for HFI 1. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 				  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	return __qsfp_debugfs_read(file, buf, count, ppos, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	ppd = private2ppd(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	return acquire_chip_resource(ppd->dd, i2c_target(target), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) static int i2c1_debugfs_open(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	return __i2c_debugfs_open(in, fp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) static int i2c2_debugfs_open(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	return __i2c_debugfs_open(in, fp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) static int __i2c_debugfs_release(struct inode *in, struct file *fp, u32 target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	ppd = private2ppd(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	release_chip_resource(ppd->dd, i2c_target(target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) static int i2c1_debugfs_release(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	return __i2c_debugfs_release(in, fp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) static int i2c2_debugfs_release(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	return __i2c_debugfs_release(in, fp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	ppd = private2ppd(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	return acquire_chip_resource(ppd->dd, i2c_target(target), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	return __qsfp_debugfs_open(in, fp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) static int qsfp2_debugfs_open(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	return __qsfp_debugfs_open(in, fp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static int __qsfp_debugfs_release(struct inode *in, struct file *fp, u32 target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	ppd = private2ppd(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	release_chip_resource(ppd->dd, i2c_target(target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) static int qsfp1_debugfs_release(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	return __qsfp_debugfs_release(in, fp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static int qsfp2_debugfs_release(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	return __qsfp_debugfs_release(in, fp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) #define EXPROM_WRITE_ENABLE BIT_ULL(14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) static bool exprom_wp_disabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) static int exprom_wp_set(struct hfi1_devdata *dd, bool disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	u64 gpio_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	if (disable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		gpio_val = EXPROM_WRITE_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		exprom_wp_disabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		dd_dev_info(dd, "Disable Expansion ROM Write Protection\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		exprom_wp_disabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		dd_dev_info(dd, "Enable Expansion ROM Write Protection\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	write_csr(dd, ASIC_GPIO_OUT, gpio_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	write_csr(dd, ASIC_GPIO_OE, gpio_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) static ssize_t exprom_wp_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 				      size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) static ssize_t exprom_wp_debugfs_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 				       const char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 				       loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	struct hfi1_pportdata *ppd = private2ppd(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	char cdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	if (count != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	if (get_user(cdata, buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	if (cdata == '0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		exprom_wp_set(ppd->dd, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	else if (cdata == '1')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		exprom_wp_set(ppd->dd, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) static unsigned long exprom_in_use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) static int exprom_wp_debugfs_open(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	if (test_and_set_bit(0, &exprom_in_use))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static int exprom_wp_debugfs_release(struct inode *in, struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	struct hfi1_pportdata *ppd = private2ppd(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	if (exprom_wp_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		exprom_wp_set(ppd->dd, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	clear_bit(0, &exprom_in_use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) #define DEBUGFS_OPS(nm, readroutine, writeroutine)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	.name = nm, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	.ops = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		.owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		.read = readroutine, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		.write = writeroutine, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		.llseek = generic_file_llseek, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	}, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) #define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	.name = nm, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	.ops = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		.owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		.read = readf, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		.write = writef, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 		.llseek = generic_file_llseek, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		.open = openf, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		.release = releasef \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	}, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) static const struct counter_info cntr_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	DEBUGFS_OPS("counter_names", dev_names_read, NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	DEBUGFS_OPS("counters", dev_counters_read, NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	DEBUGFS_OPS("portcounter_names", portnames_read, NULL),
^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 const struct counter_info port_cntr_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	DEBUGFS_XOPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		     i2c1_debugfs_open, i2c1_debugfs_release),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	DEBUGFS_XOPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		     i2c2_debugfs_open, i2c2_debugfs_release),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		     qsfp1_debugfs_open, qsfp1_debugfs_release),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		     qsfp2_debugfs_open, qsfp2_debugfs_release),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	DEBUGFS_XOPS("exprom_wp", exprom_wp_debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		     exprom_wp_debugfs_write, exprom_wp_debugfs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		     exprom_wp_debugfs_release),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	DEBUGFS_OPS("dc8051_memory", dc8051_memory_read, NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	DEBUGFS_OPS("lcb", debugfs_lcb_read, debugfs_lcb_write),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) static void *_sdma_cpu_list_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	if (*pos >= num_online_cpus())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) static void *_sdma_cpu_list_seq_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	if (*pos >= num_online_cpus())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) static void _sdma_cpu_list_seq_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	/* nothing allocated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) static int _sdma_cpu_list_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	loff_t *spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	loff_t i = *spos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	sdma_seqfile_dump_cpu_list(s, dd, (unsigned long)i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) DEBUGFS_SEQ_FILE_OPS(sdma_cpu_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) DEBUGFS_SEQ_FILE_OPEN(sdma_cpu_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) DEBUGFS_FILE_OPS(sdma_cpu_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	char name[sizeof("port0counters") + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	char link[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	struct hfi1_devdata *dd = dd_from_dev(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	struct hfi1_pportdata *ppd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	struct dentry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	int unit = dd->unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	if (!hfi1_dbg_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	snprintf(link, sizeof(link), "%d", unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	root = debugfs_create_dir(name, hfi1_dbg_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	ibd->hfi1_ibdev_dbg = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	ibd->hfi1_ibdev_link =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		debugfs_create_symlink(link, hfi1_dbg_root, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	debugfs_create_file("opcode_stats", 0444, root, ibd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 			    &_opcode_stats_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	debugfs_create_file("tx_opcode_stats", 0444, root, ibd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 			    &_tx_opcode_stats_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	debugfs_create_file("ctx_stats", 0444, root, ibd, &_ctx_stats_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	debugfs_create_file("qp_stats", 0444, root, ibd, &_qp_stats_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	debugfs_create_file("sdes", 0444, root, ibd, &_sdes_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	debugfs_create_file("rcds", 0444, root, ibd, &_rcds_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	debugfs_create_file("pios", 0444, root, ibd, &_pios_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	debugfs_create_file("sdma_cpu_list", 0444, root, ibd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 			    &_sdma_cpu_list_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	/* dev counter files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	for (i = 0; i < ARRAY_SIZE(cntr_ops); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 		debugfs_create_file(cntr_ops[i].name, 0444, root, dd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 				    &cntr_ops[i].ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	/* per port files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	for (ppd = dd->pport, j = 0; j < dd->num_pports; j++, ppd++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 		for (i = 0; i < ARRAY_SIZE(port_cntr_ops); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 			snprintf(name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 				 sizeof(name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 				 port_cntr_ops[i].name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 				 j + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 			debugfs_create_file(name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 					    !port_cntr_ops[i].ops.write ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 						    S_IRUGO :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 						    S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 					    root, ppd, &port_cntr_ops[i].ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	hfi1_fault_init_debugfs(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	if (!hfi1_dbg_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	hfi1_fault_exit_debugfs(ibd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	debugfs_remove(ibd->hfi1_ibdev_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	debugfs_remove_recursive(ibd->hfi1_ibdev_dbg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	ibd->hfi1_ibdev_dbg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)  * driver stats field names, one line per stat, single string.  Used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)  * programs like hfistats to print the stats in a way which works for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)  * different versions of drivers, without changing program source.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)  * if hfi1_ib_stats changes, this needs to change.  Names need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)  * 12 chars or less (w/o newline), for proper display by hfistats utility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) static const char * const hfi1_statnames[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	/* must be element 0*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	"KernIntr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	"ErrorIntr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	"Tx_Errs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	"Rcv_Errs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	"H/W_Errs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	"NoPIOBufs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	"CtxtsOpen",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	"RcvLen_Errs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	"EgrBufFull",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	"EgrHdrFull"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	if (*pos >= ARRAY_SIZE(hfi1_statnames))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) static void *_driver_stats_names_seq_next(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	struct seq_file *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	void *v,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	if (*pos >= ARRAY_SIZE(hfi1_statnames))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) static void _driver_stats_names_seq_stop(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) static int _driver_stats_names_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	loff_t *spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	seq_printf(s, "%s\n", hfi1_statnames[*spos]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) DEBUGFS_SEQ_FILE_OPS(driver_stats_names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) DEBUGFS_SEQ_FILE_OPEN(driver_stats_names)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) DEBUGFS_FILE_OPS(driver_stats_names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	if (*pos >= ARRAY_SIZE(hfi1_statnames))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	return pos;
^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) static void *_driver_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	if (*pos >= ARRAY_SIZE(hfi1_statnames))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) static void _driver_stats_seq_stop(struct seq_file *s, void *v)
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) static u64 hfi1_sps_ints(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	unsigned long index, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	u64 sps_ints = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	xa_lock_irqsave(&hfi1_dev_table, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	xa_for_each(&hfi1_dev_table, index, dd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		sps_ints += get_all_cpu_total(dd->int_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	xa_unlock_irqrestore(&hfi1_dev_table, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	return sps_ints;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) static int _driver_stats_seq_show(struct seq_file *s, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	loff_t *spos = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	u64 *stats = (u64 *)&hfi1_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	size_t sz = seq_get_buf(s, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	if (sz < sizeof(u64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		return SEQ_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	/* special case for interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	if (*spos == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 		*(u64 *)buffer = hfi1_sps_ints();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		*(u64 *)buffer = stats[*spos];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	seq_commit(s,  sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) DEBUGFS_SEQ_FILE_OPS(driver_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) DEBUGFS_SEQ_FILE_OPEN(driver_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) DEBUGFS_FILE_OPS(driver_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) void hfi1_dbg_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	hfi1_dbg_root  = debugfs_create_dir(DRIVER_NAME, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	debugfs_create_file("driver_stats_names", 0444, hfi1_dbg_root, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			    &_driver_stats_names_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	debugfs_create_file("driver_stats", 0444, hfi1_dbg_root, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 			    &_driver_stats_file_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) void hfi1_dbg_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	debugfs_remove_recursive(hfi1_dbg_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	hfi1_dbg_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }