Linux-libre 5.4.48-gnu
[librecmc/linux-libre.git] / drivers / scsi / snic / snic_stats.h
1 /*
2  * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
3  *
4  * This program is free software; you may redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15  * SOFTWARE.
16  */
17
18 #ifndef __SNIC_STATS_H
19 #define __SNIC_STATS_H
20
21 struct snic_io_stats {
22         atomic64_t active;              /* Active IOs */
23         atomic64_t max_active;          /* Max # active IOs */
24         atomic64_t max_sgl;             /* Max # SGLs for any IO */
25         atomic64_t max_time;            /* Max time to process IO */
26         atomic64_t max_qtime;           /* Max time to Queue the IO */
27         atomic64_t max_cmpl_time;       /* Max time to complete the IO */
28         atomic64_t sgl_cnt[SNIC_MAX_SG_DESC_CNT]; /* SGL Counters */
29         atomic64_t max_io_sz;           /* Max IO Size */
30         atomic64_t compl;               /* IO Completions */
31         atomic64_t fail;                /* IO Failures */
32         atomic64_t req_null;            /* req or req info is NULL */
33         atomic64_t alloc_fail;          /* Alloc Failures */
34         atomic64_t sc_null;
35         atomic64_t io_not_found;        /* IO Not Found */
36         atomic64_t num_ios;             /* Number of IOs */
37 };
38
39 struct snic_abort_stats {
40         atomic64_t num;         /* Abort counter */
41         atomic64_t fail;        /* Abort Failure Counter */
42         atomic64_t drv_tmo;     /* Abort Driver Timeouts */
43         atomic64_t fw_tmo;      /* Abort Firmware Timeouts */
44         atomic64_t io_not_found;/* Abort IO Not Found */
45         atomic64_t q_fail;      /* Abort Queuing Failed */
46 };
47
48 struct snic_reset_stats {
49         atomic64_t dev_resets;          /* Device Reset Counter */
50         atomic64_t dev_reset_fail;      /* Device Reset Failures */
51         atomic64_t dev_reset_aborts;    /* Device Reset Aborts */
52         atomic64_t dev_reset_tmo;       /* Device Reset Timeout */
53         atomic64_t dev_reset_terms;     /* Device Reset terminate */
54         atomic64_t hba_resets;          /* hba/firmware resets */
55         atomic64_t hba_reset_cmpl;      /* hba/firmware reset completions */
56         atomic64_t hba_reset_fail;      /* hba/firmware failures */
57         atomic64_t snic_resets;         /* snic resets */
58         atomic64_t snic_reset_compl;    /* snic reset completions */
59         atomic64_t snic_reset_fail;     /* snic reset failures */
60 };
61
62 struct snic_fw_stats {
63         atomic64_t actv_reqs;           /* Active Requests */
64         atomic64_t max_actv_reqs;       /* Max Active Requests */
65         atomic64_t out_of_res;          /* Firmware Out Of Resources */
66         atomic64_t io_errs;             /* Firmware IO Firmware Errors */
67         atomic64_t scsi_errs;           /* Target hits check condition */
68 };
69
70 struct snic_misc_stats {
71         u64     last_isr_time;
72         u64     last_ack_time;
73         atomic64_t ack_isr_cnt;
74         atomic64_t cmpl_isr_cnt;
75         atomic64_t errnotify_isr_cnt;
76         atomic64_t max_cq_ents;         /* Max CQ Entries */
77         atomic64_t data_cnt_mismat;     /* Data Count Mismatch */
78         atomic64_t io_tmo;
79         atomic64_t io_aborted;
80         atomic64_t sgl_inval;           /* SGL Invalid */
81         atomic64_t abts_wq_alloc_fail;  /* Abort Path WQ desc alloc failure */
82         atomic64_t devrst_wq_alloc_fail;/* Device Reset - WQ desc alloc fail */
83         atomic64_t wq_alloc_fail;       /* IO WQ desc alloc failure */
84         atomic64_t no_icmnd_itmf_cmpls;
85         atomic64_t io_under_run;
86         atomic64_t qfull;
87         atomic64_t qsz_rampup;
88         atomic64_t qsz_rampdown;
89         atomic64_t last_qsz;
90         atomic64_t tgt_not_rdy;
91 };
92
93 struct snic_stats {
94         struct snic_io_stats io;
95         struct snic_abort_stats abts;
96         struct snic_reset_stats reset;
97         struct snic_fw_stats fw;
98         struct snic_misc_stats misc;
99         atomic64_t io_cmpl_skip;
100 };
101
102 void snic_stats_debugfs_init(struct snic *);
103 void snic_stats_debugfs_remove(struct snic *);
104
105 /* Auxillary function to update active IO counter */
106 static inline void
107 snic_stats_update_active_ios(struct snic_stats *s_stats)
108 {
109         struct snic_io_stats *io = &s_stats->io;
110         int nr_active_ios;
111
112         nr_active_ios = atomic64_read(&io->active);
113         if (atomic64_read(&io->max_active) < nr_active_ios)
114                 atomic64_set(&io->max_active, nr_active_ios);
115
116         atomic64_inc(&io->num_ios);
117 }
118
119 /* Auxillary function to update IO completion counter */
120 static inline void
121 snic_stats_update_io_cmpl(struct snic_stats *s_stats)
122 {
123         atomic64_dec(&s_stats->io.active);
124         if (unlikely(atomic64_read(&s_stats->io_cmpl_skip)))
125                 atomic64_dec(&s_stats->io_cmpl_skip);
126         else
127                 atomic64_inc(&s_stats->io.compl);
128 }
129 #endif /* __SNIC_STATS_H */