18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158c2ecf20Sopenharmony_ci * SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef __SNIC_TRC_H
198c2ecf20Sopenharmony_ci#define __SNIC_TRC_H
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciextern ssize_t simple_read_from_buffer(void __user *to,
248c2ecf20Sopenharmony_ci					size_t count,
258c2ecf20Sopenharmony_ci					loff_t *ppos,
268c2ecf20Sopenharmony_ci					const void *from,
278c2ecf20Sopenharmony_ci					size_t available);
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciextern unsigned int snic_trace_max_pages;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* Global Data structure for trace to manage trace functionality */
328c2ecf20Sopenharmony_cistruct snic_trc_data {
338c2ecf20Sopenharmony_ci	u64	ts;		/* Time Stamp */
348c2ecf20Sopenharmony_ci	char	*fn;		/* Ptr to Function Name */
358c2ecf20Sopenharmony_ci	u32	hno;		/* SCSI Host ID */
368c2ecf20Sopenharmony_ci	u32	tag;		/* Command Tag */
378c2ecf20Sopenharmony_ci	u64 data[5];
388c2ecf20Sopenharmony_ci} __attribute__((__packed__));
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define SNIC_TRC_ENTRY_SZ  64	/* in Bytes */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct snic_trc {
438c2ecf20Sopenharmony_ci	spinlock_t lock;
448c2ecf20Sopenharmony_ci	struct snic_trc_data *buf;	/* Trace Buffer */
458c2ecf20Sopenharmony_ci	u32	max_idx;		/* Max Index into trace buffer */
468c2ecf20Sopenharmony_ci	u32	rd_idx;
478c2ecf20Sopenharmony_ci	u32	wr_idx;
488c2ecf20Sopenharmony_ci	bool	enable;			/* Control Variable for Tracing */
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	struct dentry *trc_enable;	/* debugfs file object */
518c2ecf20Sopenharmony_ci	struct dentry *trc_file;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ciint snic_trc_init(void);
558c2ecf20Sopenharmony_civoid snic_trc_free(void);
568c2ecf20Sopenharmony_civoid snic_trc_debugfs_init(void);
578c2ecf20Sopenharmony_civoid snic_trc_debugfs_term(void);
588c2ecf20Sopenharmony_cistruct snic_trc_data *snic_get_trc_buf(void);
598c2ecf20Sopenharmony_ciint snic_get_trc_data(char *buf, int buf_sz);
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_civoid snic_debugfs_init(void);
628c2ecf20Sopenharmony_civoid snic_debugfs_term(void);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic inline void
658c2ecf20Sopenharmony_cisnic_trace(char *fn, u16 hno, u32 tag, u64 d1, u64 d2, u64 d3, u64 d4, u64 d5)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	struct snic_trc_data *tr_rec = snic_get_trc_buf();
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	if (!tr_rec)
708c2ecf20Sopenharmony_ci		return;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	tr_rec->fn = (char *)fn;
738c2ecf20Sopenharmony_ci	tr_rec->hno = hno;
748c2ecf20Sopenharmony_ci	tr_rec->tag = tag;
758c2ecf20Sopenharmony_ci	tr_rec->data[0] = d1;
768c2ecf20Sopenharmony_ci	tr_rec->data[1] = d2;
778c2ecf20Sopenharmony_ci	tr_rec->data[2] = d3;
788c2ecf20Sopenharmony_ci	tr_rec->data[3] = d4;
798c2ecf20Sopenharmony_ci	tr_rec->data[4] = d5;
808c2ecf20Sopenharmony_ci	tr_rec->ts = jiffies; /* Update time stamp at last */
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5)			\
848c2ecf20Sopenharmony_ci	do {								\
858c2ecf20Sopenharmony_ci		if (unlikely(snic_glob->trc.enable))			\
868c2ecf20Sopenharmony_ci			snic_trace((char *)__func__,			\
878c2ecf20Sopenharmony_ci				   (u16)(_hno),				\
888c2ecf20Sopenharmony_ci				   (u32)(_tag),				\
898c2ecf20Sopenharmony_ci				   (u64)(d1),				\
908c2ecf20Sopenharmony_ci				   (u64)(d2),				\
918c2ecf20Sopenharmony_ci				   (u64)(d3),				\
928c2ecf20Sopenharmony_ci				   (u64)(d4),				\
938c2ecf20Sopenharmony_ci				   (u64)(d5));				\
948c2ecf20Sopenharmony_ci	} while (0)
958c2ecf20Sopenharmony_ci#else
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5)	\
988c2ecf20Sopenharmony_ci	do {						\
998c2ecf20Sopenharmony_ci		if (unlikely(snic_log_level & 0x2))	\
1008c2ecf20Sopenharmony_ci			SNIC_DBG("SnicTrace: %s %2u %2u %llx %llx %llx %llx %llx", \
1018c2ecf20Sopenharmony_ci				 (char *)__func__,	\
1028c2ecf20Sopenharmony_ci				 (u16)(_hno),		\
1038c2ecf20Sopenharmony_ci				 (u32)(_tag),		\
1048c2ecf20Sopenharmony_ci				 (u64)(d1),		\
1058c2ecf20Sopenharmony_ci				 (u64)(d2),		\
1068c2ecf20Sopenharmony_ci				 (u64)(d3),		\
1078c2ecf20Sopenharmony_ci				 (u64)(d4),		\
1088c2ecf20Sopenharmony_ci				 (u64)(d5));		\
1098c2ecf20Sopenharmony_ci	} while (0)
1108c2ecf20Sopenharmony_ci#endif /* end of CONFIG_SCSI_SNIC_DEBUG_FS */
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define SNIC_TRC_CMD(sc)	\
1138c2ecf20Sopenharmony_ci	((u64)sc->cmnd[0] << 56 | (u64)sc->cmnd[7] << 40 |	\
1148c2ecf20Sopenharmony_ci	 (u64)sc->cmnd[8] << 32 | (u64)sc->cmnd[2] << 24 |	\
1158c2ecf20Sopenharmony_ci	 (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[4] << 8 |	\
1168c2ecf20Sopenharmony_ci	 (u64)sc->cmnd[5])
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#define SNIC_TRC_CMD_STATE_FLAGS(sc)	\
1198c2ecf20Sopenharmony_ci	((u64) CMD_FLAGS(sc) << 32 | CMD_STATE(sc))
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#endif /* end of __SNIC_TRC_H */
122