Skip to content

Commit a8650a5

Browse files
Karan Tilak Kumarmartinkpetersen
authored andcommitted
scsi: fnic: Add stats and related functionality
Add statistics and related functionality for FDLS. Add supporting functions to display stats. Reviewed-by: Sesidhar Baddela <sebaddel@cisco.com> Reviewed-by: Arulprabhu Ponnusamy <arulponn@cisco.com> Reviewed-by: Gian Carlo Boffa <gcboffa@cisco.com> Signed-off-by: Karan Tilak Kumar <kartilak@cisco.com> Link: https://lore.kernel.org/r/20241212020312.4786-13-kartilak@cisco.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 9243626 commit a8650a5

File tree

6 files changed

+196
-19
lines changed

6 files changed

+196
-19
lines changed

drivers/scsi/fnic/fdls_disc.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ static void fdls_send_fabric_flogi(struct fnic_iport_s *iport)
877877
oxid);
878878

879879
fnic_send_fcoe_frame(iport, frame, frame_size);
880+
atomic64_inc(&iport->iport_stats.fabric_flogi_sent);
880881
err_out:
881882
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
882883
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
@@ -919,6 +920,7 @@ static void fdls_send_fabric_plogi(struct fnic_iport_s *iport)
919920
oxid);
920921

921922
fnic_send_fcoe_frame(iport, frame, frame_size);
923+
atomic64_inc(&iport->iport_stats.fabric_plogi_sent);
922924

923925
err_out:
924926
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
@@ -1080,6 +1082,7 @@ static void fdls_send_scr(struct fnic_iport_s *iport)
10801082
oxid);
10811083

10821084
fnic_send_fcoe_frame(iport, frame, frame_size);
1085+
atomic64_inc(&iport->iport_stats.fabric_scr_sent);
10831086

10841087
err_out:
10851088
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
@@ -1201,6 +1204,8 @@ fdls_send_tgt_adisc(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
12011204
"0x%x: FDLS send ADISC to tgt fcid: 0x%x",
12021205
iport->fcid, tport->fcid);
12031206

1207+
atomic64_inc(&iport->iport_stats.tport_adisc_sent);
1208+
12041209
fnic_send_fcoe_frame(iport, frame, frame_size);
12051210

12061211
err_out:
@@ -1310,6 +1315,7 @@ fdls_send_tgt_plogi(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
13101315
iport->fcid, tport->fcid, oxid);
13111316

13121317
fnic_send_fcoe_frame(iport, frame, frame_size);
1318+
atomic64_inc(&iport->iport_stats.tport_plogi_sent);
13131319

13141320
err_out:
13151321
timeout = max(2 * iport->e_d_tov, iport->plogi_timeout);
@@ -1515,6 +1521,7 @@ fdls_send_tgt_prli(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
15151521
iport->fcid, tport->fcid, oxid);
15161522

15171523
fnic_send_fcoe_frame(iport, frame, frame_size);
1524+
atomic64_inc(&iport->iport_stats.tport_prli_sent);
15181525

15191526
err_out:
15201527
timeout = max(2 * iport->e_d_tov, iport->plogi_timeout);
@@ -1626,6 +1633,8 @@ void fdls_tgt_logout(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
16261633
iport->fcid, oxid);
16271634

16281635
fnic_send_fcoe_frame(iport, frame, frame_size);
1636+
1637+
atomic64_inc(&iport->iport_stats.tport_logo_sent);
16291638
}
16301639

16311640
static void fdls_tgt_discovery_start(struct fnic_iport_s *iport)
@@ -2515,6 +2524,7 @@ fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport,
25152524

25162525
switch (adisc_rsp->els.adisc_cmd) {
25172526
case ELS_LS_ACC:
2527+
atomic64_inc(&iport->iport_stats.tport_adisc_ls_accepts);
25182528
if (tport->timer_pending) {
25192529
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
25202530
"tport 0x%p Canceling fabric disc timer\n",
@@ -2537,6 +2547,7 @@ fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport,
25372547
break;
25382548

25392549
case ELS_LS_RJT:
2550+
atomic64_inc(&iport->iport_stats.tport_adisc_ls_rejects);
25402551
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
25412552
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
25422553
&& (tport->retry_counter < FDLS_RETRY_COUNT)) {
@@ -2608,11 +2619,13 @@ fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
26082619

26092620
switch (plogi_rsp->els.fl_cmd) {
26102621
case ELS_LS_ACC:
2622+
atomic64_inc(&iport->iport_stats.tport_plogi_ls_accepts);
26112623
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
26122624
"PLOGI accepted by target: 0x%x", tgt_fcid);
26132625
break;
26142626

26152627
case ELS_LS_RJT:
2628+
atomic64_inc(&iport->iport_stats.tport_plogi_ls_rejects);
26162629
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
26172630
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
26182631
&& (tport->retry_counter < iport->max_plogi_retries)) {
@@ -2630,6 +2643,7 @@ fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
26302643
return;
26312644

26322645
default:
2646+
atomic64_inc(&iport->iport_stats.tport_plogi_misc_rejects);
26332647
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
26342648
"PLOGI not accepted from target fcid: 0x%x",
26352649
tgt_fcid);
@@ -2733,6 +2747,7 @@ fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
27332747

27342748
switch (prli_rsp->els_prli.prli_cmd) {
27352749
case ELS_LS_ACC:
2750+
atomic64_inc(&iport->iport_stats.tport_prli_ls_accepts);
27362751
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
27372752
"PRLI accepted from target: 0x%x", tgt_fcid);
27382753

@@ -2749,6 +2764,7 @@ fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
27492764
}
27502765
break;
27512766
case ELS_LS_RJT:
2767+
atomic64_inc(&iport->iport_stats.tport_prli_ls_rejects);
27522768
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
27532769
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
27542770
&& (tport->retry_counter < FDLS_RETRY_COUNT)) {
@@ -2772,6 +2788,7 @@ fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
27722788
break;
27732789

27742790
default:
2791+
atomic64_inc(&iport->iport_stats.tport_prli_misc_rejects);
27752792
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
27762793
"PRLI not accepted from target: 0x%x", tgt_fcid);
27772794
return;
@@ -3075,6 +3092,7 @@ fdls_process_scr_rsp(struct fnic_iport_s *iport,
30753092

30763093
switch (scr_rsp->scr.scr_cmd) {
30773094
case ELS_LS_ACC:
3095+
atomic64_inc(&iport->iport_stats.fabric_scr_ls_accepts);
30783096
if (iport->fabric.timer_pending) {
30793097
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
30803098
"Canceling fabric disc timer %p\n", iport);
@@ -3086,7 +3104,7 @@ fdls_process_scr_rsp(struct fnic_iport_s *iport,
30863104
break;
30873105

30883106
case ELS_LS_RJT:
3089-
3107+
atomic64_inc(&iport->iport_stats.fabric_scr_ls_rejects);
30903108
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
30913109
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
30923110
&& (fdls->retry_counter < FDLS_RETRY_COUNT)) {
@@ -3111,6 +3129,7 @@ fdls_process_scr_rsp(struct fnic_iport_s *iport,
31113129
break;
31123130

31133131
default:
3132+
atomic64_inc(&iport->iport_stats.fabric_scr_misc_rejects);
31143133
break;
31153134
}
31163135
}
@@ -3434,6 +3453,7 @@ fdls_process_flogi_rsp(struct fnic_iport_s *iport,
34343453

34353454
switch (flogi_rsp->els.fl_cmd) {
34363455
case ELS_LS_ACC:
3456+
atomic64_inc(&iport->iport_stats.fabric_flogi_ls_accepts);
34373457
if (iport->fabric.timer_pending) {
34383458
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
34393459
"iport fcid: 0x%x Canceling fabric disc timer\n",
@@ -3507,6 +3527,7 @@ fdls_process_flogi_rsp(struct fnic_iport_s *iport,
35073527
break;
35083528

35093529
case ELS_LS_RJT:
3530+
atomic64_inc(&iport->iport_stats.fabric_flogi_ls_rejects);
35103531
if (fabric->retry_counter < iport->max_flogi_retries) {
35113532
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
35123533
"FLOGI returned ELS_LS_RJT BUSY. Retry from timer routine %p",
@@ -3534,6 +3555,7 @@ fdls_process_flogi_rsp(struct fnic_iport_s *iport,
35343555
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
35353556
"FLOGI response not accepted: 0x%x",
35363557
flogi_rsp->els.fl_cmd);
3558+
atomic64_inc(&iport->iport_stats.fabric_flogi_misc_rejects);
35373559
break;
35383560
}
35393561
}
@@ -3564,6 +3586,7 @@ fdls_process_fabric_plogi_rsp(struct fnic_iport_s *iport,
35643586

35653587
switch (plogi_rsp->els.fl_cmd) {
35663588
case ELS_LS_ACC:
3589+
atomic64_inc(&iport->iport_stats.fabric_plogi_ls_accepts);
35673590
if (iport->fabric.timer_pending) {
35683591
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
35693592
"iport fcid: 0x%x fabric PLOGI response: Accepted\n",
@@ -3576,7 +3599,7 @@ fdls_process_fabric_plogi_rsp(struct fnic_iport_s *iport,
35763599
fdls_send_rpn_id(iport);
35773600
break;
35783601
case ELS_LS_RJT:
3579-
3602+
atomic64_inc(&iport->iport_stats.fabric_plogi_ls_rejects);
35803603
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
35813604
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
35823605
&& (iport->fabric.retry_counter < iport->max_plogi_retries)) {
@@ -3602,6 +3625,7 @@ fdls_process_fabric_plogi_rsp(struct fnic_iport_s *iport,
36023625
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
36033626
"PLOGI response not accepted: 0x%x",
36043627
plogi_rsp->els.fl_cmd);
3628+
atomic64_inc(&iport->iport_stats.fabric_plogi_misc_rejects);
36053629
break;
36063630
}
36073631
}
@@ -3945,6 +3969,7 @@ fdls_process_unsupported_els_req(struct fnic_iport_s *iport,
39453969
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
39463970
"Dropping unsupported ELS with illegal frame bits 0x%x\n",
39473971
d_id);
3972+
atomic64_inc(&iport->iport_stats.unsupported_frames_dropped);
39483973
return;
39493974
}
39503975

@@ -3953,6 +3978,7 @@ fdls_process_unsupported_els_req(struct fnic_iport_s *iport,
39533978
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
39543979
"Dropping unsupported ELS request in iport state: %d",
39553980
iport->state);
3981+
atomic64_inc(&iport->iport_stats.unsupported_frames_dropped);
39563982
return;
39573983
}
39583984

@@ -4381,6 +4407,8 @@ fdls_process_rscn(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
43814407
struct fnic *fnic = iport->fnic;
43824408
uint16_t rscn_payload_len;
43834409

4410+
atomic64_inc(&iport->iport_stats.num_rscns);
4411+
43844412
FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
43854413
"FDLS process RSCN %p", iport);
43864414

drivers/scsi/fnic/fnic_fdls.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,12 @@ struct fnic_iport_s {
305305
uint16_t max_payload_size;
306306
spinlock_t deleted_tport_lst_lock;
307307
struct completion *flogi_reg_done;
308+
struct fnic_iport_stats iport_stats;
308309
char str_wwpn[20];
309310
char str_wwnn[20];
310-
};
311-
struct rport_dd_data_s {
311+
};
312+
313+
struct rport_dd_data_s {
312314
struct fnic_tport_s *tport;
313315
struct fnic_iport_s *iport;
314316
};

drivers/scsi/fnic/fnic_main.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static struct fc_function_template fnic_fc_functions = {
163163
.show_rport_dev_loss_tmo = 1,
164164
.set_rport_dev_loss_tmo = fnic_set_rport_dev_loss_tmo,
165165
.issue_fc_host_lip = fnic_issue_fc_host_lip,
166-
.get_fc_host_stats = NULL,
166+
.get_fc_host_stats = fnic_get_stats,
167167
.reset_fc_host_stats = fnic_reset_host_stats,
168168
.dd_fcrport_size = sizeof(struct rport_dd_data_s),
169169
.terminate_rport_io = fnic_terminate_rport_io,
@@ -174,9 +174,11 @@ static void fnic_get_host_speed(struct Scsi_Host *shost)
174174
{
175175
struct fnic *fnic = *((struct fnic **) shost_priv(shost));
176176
u32 port_speed = vnic_dev_port_speed(fnic->vdev);
177+
struct fnic_stats *fnic_stats = &fnic->fnic_stats;
177178

178179
FNIC_MAIN_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
179180
"port_speed: %d Mbps", port_speed);
181+
atomic64_set(&fnic_stats->misc_stats.port_speed_in_mbps, port_speed);
180182

181183
/* Add in other values as they get defined in fw */
182184
switch (port_speed) {
@@ -234,8 +236,38 @@ static void fnic_get_host_speed(struct Scsi_Host *shost)
234236
/* Placeholder function */
235237
static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *host)
236238
{
239+
int ret;
237240
struct fnic *fnic = *((struct fnic **) shost_priv(host));
238241
struct fc_host_statistics *stats = &fnic->fnic_stats.host_stats;
242+
struct vnic_stats *vs;
243+
unsigned long flags;
244+
245+
if (time_before
246+
(jiffies, fnic->stats_time + HZ / FNIC_STATS_RATE_LIMIT))
247+
return stats;
248+
fnic->stats_time = jiffies;
249+
250+
spin_lock_irqsave(&fnic->fnic_lock, flags);
251+
ret = vnic_dev_stats_dump(fnic->vdev, &fnic->stats);
252+
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
253+
254+
if (ret) {
255+
FNIC_MAIN_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
256+
"fnic: Get vnic stats failed: 0x%x", ret);
257+
return stats;
258+
}
259+
vs = fnic->stats;
260+
stats->tx_frames = vs->tx.tx_unicast_frames_ok;
261+
stats->tx_words = vs->tx.tx_unicast_bytes_ok / 4;
262+
stats->rx_frames = vs->rx.rx_unicast_frames_ok;
263+
stats->rx_words = vs->rx.rx_unicast_bytes_ok / 4;
264+
stats->error_frames = vs->tx.tx_errors + vs->rx.rx_errors;
265+
stats->dumped_frames = vs->tx.tx_drops + vs->rx.rx_drop;
266+
stats->invalid_crc_count = vs->rx.rx_crc_errors;
267+
stats->seconds_since_last_reset =
268+
(jiffies - fnic->stats_reset_time) / HZ;
269+
stats->fcp_input_megabytes = div_u64(fnic->fcp_input_bytes, 1000000);
270+
stats->fcp_output_megabytes = div_u64(fnic->fcp_output_bytes, 1000000);
239271
return stats;
240272
}
241273

drivers/scsi/fnic/fnic_scsi.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ int fnic_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *sc)
490490
if (ret) {
491491
FNIC_SCSI_DBG(KERN_ERR, fnic->lport->host, fnic->fnic_num,
492492
"rport is not ready\n");
493+
atomic64_inc(&fnic_stats->misc_stats.tport_not_ready);
493494
sc->result = ret;
494495
done(sc);
495496
return 0;
@@ -1128,6 +1129,15 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, unsigned int cq_ind
11281129
jiffies_to_msecs(jiffies - start_time)),
11291130
desc, cmd_trace, fnic_flags_and_state(sc));
11301131

1132+
if (sc->sc_data_direction == DMA_FROM_DEVICE) {
1133+
fnic_stats->host_stats.fcp_input_requests++;
1134+
fnic->fcp_input_bytes += xfer_len;
1135+
} else if (sc->sc_data_direction == DMA_TO_DEVICE) {
1136+
fnic_stats->host_stats.fcp_output_requests++;
1137+
fnic->fcp_output_bytes += xfer_len;
1138+
} else
1139+
fnic_stats->host_stats.fcp_control_requests++;
1140+
11311141
/* Call SCSI completion function to complete the IO */
11321142
scsi_done(sc);
11331143

@@ -1977,8 +1987,8 @@ void fnic_scsi_unload_cleanup(struct fnic *fnic)
19771987
{
19781988
int hwq = 0;
19791989

1980-
fc_remove_host(fnic->host);
1981-
scsi_remove_host(fnic->host);
1990+
fc_remove_host(fnic->lport->host);
1991+
scsi_remove_host(fnic->lport->host);
19821992
for (hwq = 0; hwq < fnic->wq_copy_count; hwq++)
19831993
kfree(fnic->sw_copy_wq[hwq].io_req_table);
19841994
}
@@ -2057,6 +2067,7 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
20572067
fnic_priv(sc)->flags);
20582068

20592069
if (iport->state != FNIC_IPORT_STATE_READY) {
2070+
atomic64_inc(&fnic_stats->misc_stats.iport_not_ready);
20602071
FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
20612072
"iport NOT in READY state");
20622073
ret = FAILED;
@@ -2140,6 +2151,7 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
21402151
if (fc_remote_port_chkready(rport) == 0)
21412152
task_req = FCPIO_ITMF_ABT_TASK;
21422153
else {
2154+
atomic64_inc(&fnic_stats->misc_stats.tport_not_ready);
21432155
task_req = FCPIO_ITMF_ABT_TASK_TERM;
21442156
}
21452157

@@ -2577,6 +2589,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
25772589
}
25782590

25792591
if (iport->state != FNIC_IPORT_STATE_READY) {
2592+
atomic64_inc(&fnic_stats->misc_stats.iport_not_ready);
25802593
FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
25812594
"iport NOT in READY state");
25822595
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
@@ -2594,6 +2607,7 @@ int fnic_device_reset(struct scsi_cmnd *sc)
25942607

25952608
/* Check if remote port up */
25962609
if (fc_remote_port_chkready(rport)) {
2610+
atomic64_inc(&fnic_stats->misc_stats.tport_not_ready);
25972611
goto fnic_device_reset_end;
25982612
}
25992613

@@ -3071,6 +3085,7 @@ void fnic_scsi_fcpio_reset(struct fnic *fnic)
30713085
"FW reset completion timed out after %d ms)\n",
30723086
FNIC_FW_RESET_TIMEOUT);
30733087
}
3088+
atomic64_inc(&fnic->fnic_stats.reset_stats.fw_reset_timeouts);
30743089
}
30753090
fnic->fw_reset_done = NULL;
30763091
}

0 commit comments

Comments
 (0)