33 *
44 * Debug traces for zfcp.
55 *
6- * Copyright IBM Corp. 2002, 2015
6+ * Copyright IBM Corp. 2002, 2016
77 */
88
99#define KMSG_COMPONENT "zfcp"
@@ -356,23 +356,57 @@ void zfcp_dbf_rec_run_wka(char *tag, struct zfcp_fc_wka_port *wka_port,
356356}
357357
358358static inline
359- void zfcp_dbf_san (char * tag , struct zfcp_dbf * dbf , void * data , u8 id , u16 len ,
360- u64 req_id , u32 d_id )
359+ void zfcp_dbf_san (char * tag , struct zfcp_dbf * dbf ,
360+ char * paytag , struct scatterlist * sg , u8 id , u16 len ,
361+ u64 req_id , u32 d_id , u16 cap_len )
361362{
362363 struct zfcp_dbf_san * rec = & dbf -> san_buf ;
363364 u16 rec_len ;
364365 unsigned long flags ;
366+ struct zfcp_dbf_pay * payload = & dbf -> pay_buf ;
367+ u16 pay_sum = 0 ;
365368
366369 spin_lock_irqsave (& dbf -> san_lock , flags );
367370 memset (rec , 0 , sizeof (* rec ));
368371
369372 rec -> id = id ;
370373 rec -> fsf_req_id = req_id ;
371374 rec -> d_id = d_id ;
372- rec_len = min (len , (u16 )ZFCP_DBF_SAN_MAX_PAYLOAD );
373- memcpy (rec -> payload , data , rec_len );
374375 memcpy (rec -> tag , tag , ZFCP_DBF_TAG_LEN );
376+ rec -> pl_len = len ; /* full length even if we cap pay below */
377+ if (!sg )
378+ goto out ;
379+ rec_len = min_t (unsigned int , sg -> length , ZFCP_DBF_SAN_MAX_PAYLOAD );
380+ memcpy (rec -> payload , sg_virt (sg ), rec_len ); /* part of 1st sg entry */
381+ if (len <= rec_len )
382+ goto out ; /* skip pay record if full content in rec->payload */
383+
384+ /* if (len > rec_len):
385+ * dump data up to cap_len ignoring small duplicate in rec->payload
386+ */
387+ spin_lock_irqsave (& dbf -> pay_lock , flags );
388+ memset (payload , 0 , sizeof (* payload ));
389+ memcpy (payload -> area , paytag , ZFCP_DBF_TAG_LEN );
390+ payload -> fsf_req_id = req_id ;
391+ payload -> counter = 0 ;
392+ for (; sg && pay_sum < cap_len ; sg = sg_next (sg )) {
393+ u16 pay_len , offset = 0 ;
394+
395+ while (offset < sg -> length && pay_sum < cap_len ) {
396+ pay_len = min ((u16 )ZFCP_DBF_PAY_MAX_REC ,
397+ (u16 )(sg -> length - offset ));
398+ /* cap_len <= pay_sum < cap_len+ZFCP_DBF_PAY_MAX_REC */
399+ memcpy (payload -> data , sg_virt (sg ) + offset , pay_len );
400+ debug_event (dbf -> pay , 1 , payload ,
401+ zfcp_dbf_plen (pay_len ));
402+ payload -> counter ++ ;
403+ offset += pay_len ;
404+ pay_sum += pay_len ;
405+ }
406+ }
407+ spin_unlock (& dbf -> pay_lock );
375408
409+ out :
376410 debug_event (dbf -> san , 1 , rec , sizeof (* rec ));
377411 spin_unlock_irqrestore (& dbf -> san_lock , flags );
378412}
@@ -389,9 +423,62 @@ void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
389423 struct zfcp_fsf_ct_els * ct_els = fsf -> data ;
390424 u16 length ;
391425
392- length = (u16 )(ct_els -> req -> length );
393- zfcp_dbf_san (tag , dbf , sg_virt (ct_els -> req ), ZFCP_DBF_SAN_REQ , length ,
394- fsf -> req_id , d_id );
426+ length = (u16 )zfcp_qdio_real_bytes (ct_els -> req );
427+ zfcp_dbf_san (tag , dbf , "san_req" , ct_els -> req , ZFCP_DBF_SAN_REQ ,
428+ length , fsf -> req_id , d_id , length );
429+ }
430+
431+ static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft (char * tag ,
432+ struct zfcp_fsf_req * fsf ,
433+ u16 len )
434+ {
435+ struct zfcp_fsf_ct_els * ct_els = fsf -> data ;
436+ struct fc_ct_hdr * reqh = sg_virt (ct_els -> req );
437+ struct fc_ns_gid_ft * reqn = (struct fc_ns_gid_ft * )(reqh + 1 );
438+ struct scatterlist * resp_entry = ct_els -> resp ;
439+ struct fc_gpn_ft_resp * acc ;
440+ int max_entries , x , last = 0 ;
441+
442+ if (!(memcmp (tag , "fsscth2" , 7 ) == 0
443+ && ct_els -> d_id == FC_FID_DIR_SERV
444+ && reqh -> ct_rev == FC_CT_REV
445+ && reqh -> ct_in_id [0 ] == 0
446+ && reqh -> ct_in_id [1 ] == 0
447+ && reqh -> ct_in_id [2 ] == 0
448+ && reqh -> ct_fs_type == FC_FST_DIR
449+ && reqh -> ct_fs_subtype == FC_NS_SUBTYPE
450+ && reqh -> ct_options == 0
451+ && reqh -> _ct_resvd1 == 0
452+ && reqh -> ct_cmd == FC_NS_GPN_FT
453+ /* reqh->ct_mr_size can vary so do not match but read below */
454+ && reqh -> _ct_resvd2 == 0
455+ && reqh -> ct_reason == 0
456+ && reqh -> ct_explan == 0
457+ && reqh -> ct_vendor == 0
458+ && reqn -> fn_resvd == 0
459+ && reqn -> fn_domain_id_scope == 0
460+ && reqn -> fn_area_id_scope == 0
461+ && reqn -> fn_fc4_type == FC_TYPE_FCP ))
462+ return len ; /* not GPN_FT response so do not cap */
463+
464+ acc = sg_virt (resp_entry );
465+ max_entries = (reqh -> ct_mr_size * 4 / sizeof (struct fc_gpn_ft_resp ))
466+ + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one
467+ * to account for header as 1st pseudo "entry" */ ;
468+
469+ /* the basic CT_IU preamble is the same size as one entry in the GPN_FT
470+ * response, allowing us to skip special handling for it - just skip it
471+ */
472+ for (x = 1 ; x < max_entries && !last ; x ++ ) {
473+ if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1 ))
474+ acc ++ ;
475+ else
476+ acc = sg_virt (++ resp_entry );
477+
478+ last = acc -> fp_flags & FC_NS_FID_LAST ;
479+ }
480+ len = min (len , (u16 )(x * sizeof (struct fc_gpn_ft_resp )));
481+ return len ; /* cap after last entry */
395482}
396483
397484/**
@@ -405,9 +492,10 @@ void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
405492 struct zfcp_fsf_ct_els * ct_els = fsf -> data ;
406493 u16 length ;
407494
408- length = (u16 )(ct_els -> resp -> length );
409- zfcp_dbf_san (tag , dbf , sg_virt (ct_els -> resp ), ZFCP_DBF_SAN_RES , length ,
410- fsf -> req_id , ct_els -> d_id );
495+ length = (u16 )zfcp_qdio_real_bytes (ct_els -> resp );
496+ zfcp_dbf_san (tag , dbf , "san_res" , ct_els -> resp , ZFCP_DBF_SAN_RES ,
497+ length , fsf -> req_id , ct_els -> d_id ,
498+ zfcp_dbf_san_res_cap_len_if_gpn_ft (tag , fsf , length ));
411499}
412500
413501/**
@@ -421,11 +509,13 @@ void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
421509 struct fsf_status_read_buffer * srb =
422510 (struct fsf_status_read_buffer * ) fsf -> data ;
423511 u16 length ;
512+ struct scatterlist sg ;
424513
425514 length = (u16 )(srb -> length -
426515 offsetof(struct fsf_status_read_buffer , payload ));
427- zfcp_dbf_san (tag , dbf , srb -> payload .data , ZFCP_DBF_SAN_ELS , length ,
428- fsf -> req_id , ntoh24 (srb -> d_id ));
516+ sg_init_one (& sg , srb -> payload .data , length );
517+ zfcp_dbf_san (tag , dbf , "san_els" , & sg , ZFCP_DBF_SAN_ELS , length ,
518+ fsf -> req_id , ntoh24 (srb -> d_id ), length );
429519}
430520
431521/**
0 commit comments