@@ -350,6 +350,35 @@ struct smbdirect_socket {
350350 u64 dequeue_reassembly_queue ;
351351 u64 send_empty ;
352352 } statistics ;
353+
354+ struct {
355+ #define SMBDIRECT_LOG_ERR 0x0
356+ #define SMBDIRECT_LOG_INFO 0x1
357+
358+ #define SMBDIRECT_LOG_OUTGOING 0x1
359+ #define SMBDIRECT_LOG_INCOMING 0x2
360+ #define SMBDIRECT_LOG_READ 0x4
361+ #define SMBDIRECT_LOG_WRITE 0x8
362+ #define SMBDIRECT_LOG_RDMA_SEND 0x10
363+ #define SMBDIRECT_LOG_RDMA_RECV 0x20
364+ #define SMBDIRECT_LOG_KEEP_ALIVE 0x40
365+ #define SMBDIRECT_LOG_RDMA_EVENT 0x80
366+ #define SMBDIRECT_LOG_RDMA_MR 0x100
367+ #define SMBDIRECT_LOG_RDMA_RW 0x200
368+ #define SMBDIRECT_LOG_NEGOTIATE 0x400
369+ void * private_ptr ;
370+ bool (* needed )(struct smbdirect_socket * sc ,
371+ void * private_ptr ,
372+ unsigned int lvl ,
373+ unsigned int cls );
374+ void (* vaprintf )(struct smbdirect_socket * sc ,
375+ const char * func ,
376+ unsigned int line ,
377+ void * private_ptr ,
378+ unsigned int lvl ,
379+ unsigned int cls ,
380+ struct va_format * vaf );
381+ } logging ;
353382};
354383
355384static void __smbdirect_socket_disabled_work (struct work_struct * work )
@@ -360,6 +389,100 @@ static void __smbdirect_socket_disabled_work(struct work_struct *work)
360389 WARN_ON_ONCE (1 );
361390}
362391
392+ static bool __smbdirect_log_needed (struct smbdirect_socket * sc ,
393+ void * private_ptr ,
394+ unsigned int lvl ,
395+ unsigned int cls )
396+ {
397+ /*
398+ * Should never be called, the caller should
399+ * set it's own functions.
400+ */
401+ WARN_ON_ONCE (1 );
402+ return false;
403+ }
404+
405+ static void __smbdirect_log_vaprintf (struct smbdirect_socket * sc ,
406+ const char * func ,
407+ unsigned int line ,
408+ void * private_ptr ,
409+ unsigned int lvl ,
410+ unsigned int cls ,
411+ struct va_format * vaf )
412+ {
413+ /*
414+ * Should never be called, the caller should
415+ * set it's own functions.
416+ */
417+ WARN_ON_ONCE (1 );
418+ }
419+
420+ __printf (6 , 7 )
421+ static void __smbdirect_log_printf (struct smbdirect_socket * sc ,
422+ const char * func ,
423+ unsigned int line ,
424+ unsigned int lvl ,
425+ unsigned int cls ,
426+ const char * fmt ,
427+ ...);
428+ __maybe_unused
429+ static void __smbdirect_log_printf (struct smbdirect_socket * sc ,
430+ const char * func ,
431+ unsigned int line ,
432+ unsigned int lvl ,
433+ unsigned int cls ,
434+ const char * fmt ,
435+ ...)
436+ {
437+ struct va_format vaf ;
438+ va_list args ;
439+
440+ va_start (args , fmt );
441+
442+ vaf .fmt = fmt ;
443+ vaf .va = & args ;
444+
445+ sc -> logging .vaprintf (sc ,
446+ func ,
447+ line ,
448+ sc -> logging .private_ptr ,
449+ lvl ,
450+ cls ,
451+ & vaf );
452+ va_end (args );
453+ }
454+
455+ #define ___smbdirect_log_generic (sc , func , line , lvl , cls , fmt , args ...) do { \
456+ if (sc->logging.needed(sc, sc->logging.private_ptr, lvl, cls)) { \
457+ __smbdirect_log_printf(sc, func, line, lvl, cls, fmt, ##args); \
458+ } \
459+ } while (0)
460+ #define __smbdirect_log_generic (sc , lvl , cls , fmt , args ...) \
461+ ___smbdirect_log_generic(sc, __func__, __LINE__, lvl, cls, fmt, ##args)
462+
463+ #define smbdirect_log_outgoing (sc , lvl , fmt , args ...) \
464+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_OUTGOING, fmt, ##args)
465+ #define smbdirect_log_incoming (sc , lvl , fmt , args ...) \
466+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_INCOMING, fmt, ##args)
467+ #define smbdirect_log_read (sc , lvl , fmt , args ...) \
468+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_READ, fmt, ##args)
469+ #define smbdirect_log_write (sc , lvl , fmt , args ...) \
470+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_WRITE, fmt, ##args)
471+ #define smbdirect_log_rdma_send (sc , lvl , fmt , args ...) \
472+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_RDMA_SEND, fmt, ##args)
473+ #define smbdirect_log_rdma_recv (sc , lvl , fmt , args ...) \
474+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_RDMA_RECV, fmt, ##args)
475+ #define smbdirect_log_keep_alive (sc , lvl , fmt , args ...) \
476+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_KEEP_ALIVE, fmt, ##args)
477+ #define smbdirect_log_rdma_event (sc , lvl , fmt , args ...) \
478+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_RDMA_EVENT, fmt, ##args)
479+ #define smbdirect_log_rdma_mr (sc , lvl , fmt , args ...) \
480+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_RDMA_MR, fmt, ##args)
481+ #define smbdirect_log_rdma_rw (sc , lvl , fmt , args ...) \
482+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_RDMA_RW, fmt, ##args)
483+ #define smbdirect_log_negotiate (sc , lvl , fmt , args ...) \
484+ __smbdirect_log_generic(sc, lvl, SMBDIRECT_LOG_NEGOTIATE, fmt, ##args)
485+
363486static __always_inline void smbdirect_socket_init (struct smbdirect_socket * sc )
364487{
365488 /*
@@ -420,6 +543,10 @@ static __always_inline void smbdirect_socket_init(struct smbdirect_socket *sc)
420543 INIT_WORK (& sc -> mr_io .recovery_work , __smbdirect_socket_disabled_work );
421544 disable_work_sync (& sc -> mr_io .recovery_work );
422545 init_waitqueue_head (& sc -> mr_io .cleanup .wait_queue );
546+
547+ sc -> logging .private_ptr = NULL ;
548+ sc -> logging .needed = __smbdirect_log_needed ;
549+ sc -> logging .vaprintf = __smbdirect_log_vaprintf ;
423550}
424551
425552#define __SMBDIRECT_CHECK_STATUS_FAILED (__sc , __expected_status , __error_cmd , __unexpected_cmd ) ({ \
0 commit comments