Commit 7414705e authored by Robert Love's avatar Robert Love Committed by James Bottomley

libfc: Add runtime debugging with debug_logging module parameter

This patch adds the /sys/module/libfc/parameters/debug_logging
file to sysfs as a module parameter. It accepts an integer
bitmask for logging. Currently it supports:

   bit
LSB 0 = general libfc debugging
    1 = lport debugging
    2 = disc debugging
    3 = rport debugging
    4 = fcp debugging
    5 = EM debugging
    6 = exch/seq debugging
    7 = scsi logging (mostly error handling)

the other bits are not used at this time.

The patch converts all of the libfc source files to use
these new macros and removes the old FC_DBG macro.
Signed-off-by: default avatarRobert Love <robert.w.love@intel.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent 650bd12b
...@@ -45,14 +45,6 @@ ...@@ -45,14 +45,6 @@
#define FC_DISC_DELAY 3 #define FC_DISC_DELAY 3
static int fc_disc_debug;
#define FC_DEBUG_DISC(fmt...) \
do { \
if (fc_disc_debug) \
FC_DBG(fmt); \
} while (0)
static void fc_disc_gpn_ft_req(struct fc_disc *); static void fc_disc_gpn_ft_req(struct fc_disc *);
static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *); static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *);
static int fc_disc_new_target(struct fc_disc *, struct fc_rport *, static int fc_disc_new_target(struct fc_disc *, struct fc_rport *,
...@@ -137,8 +129,8 @@ static void fc_disc_rport_callback(struct fc_lport *lport, ...@@ -137,8 +129,8 @@ static void fc_disc_rport_callback(struct fc_lport *lport,
struct fc_rport_libfc_priv *rdata = rport->dd_data; struct fc_rport_libfc_priv *rdata = rport->dd_data;
struct fc_disc *disc = &lport->disc; struct fc_disc *disc = &lport->disc;
FC_DEBUG_DISC("Received a %d event for port (%6x)\n", event, FC_DISC_DBG(disc, "Received a %d event for port (%6x)\n", event,
rport->port_id); rport->port_id);
switch (event) { switch (event) {
case RPORT_EV_CREATED: case RPORT_EV_CREATED:
...@@ -191,8 +183,7 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp, ...@@ -191,8 +183,7 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
lport = disc->lport; lport = disc->lport;
FC_DEBUG_DISC("Received an RSCN event on port (%6x)\n", FC_DISC_DBG(disc, "Received an RSCN event\n");
fc_host_port_id(lport->host));
/* make sure the frame contains an RSCN message */ /* make sure the frame contains an RSCN message */
rp = fc_frame_payload_get(fp, sizeof(*rp)); rp = fc_frame_payload_get(fp, sizeof(*rp));
...@@ -225,8 +216,8 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp, ...@@ -225,8 +216,8 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
*/ */
switch (fmt) { switch (fmt) {
case ELS_ADDR_FMT_PORT: case ELS_ADDR_FMT_PORT:
FC_DEBUG_DISC("Port address format for port (%6x)\n", FC_DISC_DBG(disc, "Port address format for port "
ntoh24(pp->rscn_fid)); "(%6x)\n", ntoh24(pp->rscn_fid));
dp = kzalloc(sizeof(*dp), GFP_KERNEL); dp = kzalloc(sizeof(*dp), GFP_KERNEL);
if (!dp) { if (!dp) {
redisc = 1; redisc = 1;
...@@ -243,19 +234,19 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp, ...@@ -243,19 +234,19 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
case ELS_ADDR_FMT_DOM: case ELS_ADDR_FMT_DOM:
case ELS_ADDR_FMT_FAB: case ELS_ADDR_FMT_FAB:
default: default:
FC_DEBUG_DISC("Address format is (%d)\n", fmt); FC_DISC_DBG(disc, "Address format is (%d)\n", fmt);
redisc = 1; redisc = 1;
break; break;
} }
} }
lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
if (redisc) { if (redisc) {
FC_DEBUG_DISC("RSCN received: rediscovering\n"); FC_DISC_DBG(disc, "RSCN received: rediscovering\n");
fc_disc_restart(disc); fc_disc_restart(disc);
} else { } else {
FC_DEBUG_DISC("RSCN received: not rediscovering. " FC_DISC_DBG(disc, "RSCN received: not rediscovering. "
"redisc %d state %d in_prog %d\n", "redisc %d state %d in_prog %d\n",
redisc, lport->state, disc->pending); redisc, lport->state, disc->pending);
list_for_each_entry_safe(dp, next, &disc_ports, peers) { list_for_each_entry_safe(dp, next, &disc_ports, peers) {
list_del(&dp->peers); list_del(&dp->peers);
rport = lport->tt.rport_lookup(lport, dp->ids.port_id); rport = lport->tt.rport_lookup(lport, dp->ids.port_id);
...@@ -270,7 +261,7 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp, ...@@ -270,7 +261,7 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
fc_frame_free(fp); fc_frame_free(fp);
return; return;
reject: reject:
FC_DEBUG_DISC("Received a bad RSCN frame\n"); FC_DISC_DBG(disc, "Received a bad RSCN frame\n");
rjt_data.fp = NULL; rjt_data.fp = NULL;
rjt_data.reason = ELS_RJT_LOGIC; rjt_data.reason = ELS_RJT_LOGIC;
rjt_data.explan = ELS_EXPL_NONE; rjt_data.explan = ELS_EXPL_NONE;
...@@ -302,7 +293,8 @@ static void fc_disc_recv_req(struct fc_seq *sp, struct fc_frame *fp, ...@@ -302,7 +293,8 @@ static void fc_disc_recv_req(struct fc_seq *sp, struct fc_frame *fp,
mutex_unlock(&disc->disc_mutex); mutex_unlock(&disc->disc_mutex);
break; break;
default: default:
FC_DBG("Received an unsupported request. opcode (%x)\n", op); FC_DISC_DBG(disc, "Received an unsupported request, "
"the opcode is (%x)\n", op);
break; break;
} }
} }
...@@ -320,12 +312,10 @@ static void fc_disc_restart(struct fc_disc *disc) ...@@ -320,12 +312,10 @@ static void fc_disc_restart(struct fc_disc *disc)
struct fc_rport_libfc_priv *rdata, *next; struct fc_rport_libfc_priv *rdata, *next;
struct fc_lport *lport = disc->lport; struct fc_lport *lport = disc->lport;
FC_DEBUG_DISC("Restarting discovery for port (%6x)\n", FC_DISC_DBG(disc, "Restarting discovery\n");
fc_host_port_id(lport->host));
list_for_each_entry_safe(rdata, next, &disc->rports, peers) { list_for_each_entry_safe(rdata, next, &disc->rports, peers) {
rport = PRIV_TO_RPORT(rdata); rport = PRIV_TO_RPORT(rdata);
FC_DEBUG_DISC("list_del(%6x)\n", rport->port_id);
list_del(&rdata->peers); list_del(&rdata->peers);
lport->tt.rport_logoff(rport); lport->tt.rport_logoff(rport);
} }
...@@ -485,8 +475,7 @@ static void fc_disc_done(struct fc_disc *disc) ...@@ -485,8 +475,7 @@ static void fc_disc_done(struct fc_disc *disc)
struct fc_lport *lport = disc->lport; struct fc_lport *lport = disc->lport;
enum fc_disc_event event; enum fc_disc_event event;
FC_DEBUG_DISC("Discovery complete for port (%6x)\n", FC_DISC_DBG(disc, "Discovery complete\n");
fc_host_port_id(lport->host));
event = disc->event; event = disc->event;
disc->event = DISC_EV_NONE; disc->event = DISC_EV_NONE;
...@@ -510,10 +499,10 @@ static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp) ...@@ -510,10 +499,10 @@ static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp)
{ {
struct fc_lport *lport = disc->lport; struct fc_lport *lport = disc->lport;
unsigned long delay = 0; unsigned long delay = 0;
if (fc_disc_debug)
FC_DBG("Error %ld, retries %d/%d\n", FC_DISC_DBG(disc, "Error %ld, retries %d/%d\n",
PTR_ERR(fp), disc->retry_count, PTR_ERR(fp), disc->retry_count,
FC_DISC_RETRY_LIMIT); FC_DISC_RETRY_LIMIT);
if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) { if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) {
/* /*
...@@ -649,9 +638,9 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len) ...@@ -649,9 +638,9 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
&disc->rogue_rports); &disc->rogue_rports);
lport->tt.rport_login(rport); lport->tt.rport_login(rport);
} else } else
FC_DBG("Failed to allocate memory for " printk(KERN_WARNING "libfc: Failed to allocate "
"the newly discovered port (%6x)\n", "memory for the newly discovered port "
dp.ids.port_id); "(%6x)\n", dp.ids.port_id);
} }
if (np->fp_flags & FC_NS_FID_LAST) { if (np->fp_flags & FC_NS_FID_LAST) {
...@@ -671,9 +660,8 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len) ...@@ -671,9 +660,8 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
*/ */
if (error == 0 && len > 0 && len < sizeof(*np)) { if (error == 0 && len > 0 && len < sizeof(*np)) {
if (np != &disc->partial_buf) { if (np != &disc->partial_buf) {
FC_DEBUG_DISC("Partial buffer remains " FC_DISC_DBG(disc, "Partial buffer remains "
"for discovery by (%6x)\n", "for discovery\n");
fc_host_port_id(lport->host));
memcpy(&disc->partial_buf, np, len); memcpy(&disc->partial_buf, np, len);
} }
disc->buf_len = (unsigned char) len; disc->buf_len = (unsigned char) len;
...@@ -721,8 +709,7 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp, ...@@ -721,8 +709,7 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
int error; int error;
mutex_lock(&disc->disc_mutex); mutex_lock(&disc->disc_mutex);
FC_DEBUG_DISC("Received a GPN_FT response on port (%6x)\n", FC_DISC_DBG(disc, "Received a GPN_FT response\n");
fc_host_port_id(disc->lport->host));
if (IS_ERR(fp)) { if (IS_ERR(fp)) {
fc_disc_error(disc, fp); fc_disc_error(disc, fp);
...@@ -738,30 +725,30 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp, ...@@ -738,30 +725,30 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
disc->seq_count == 0) { disc->seq_count == 0) {
cp = fc_frame_payload_get(fp, sizeof(*cp)); cp = fc_frame_payload_get(fp, sizeof(*cp));
if (!cp) { if (!cp) {
FC_DBG("GPN_FT response too short, len %d\n", FC_DISC_DBG(disc, "GPN_FT response too short, len %d\n",
fr_len(fp)); fr_len(fp));
} else if (ntohs(cp->ct_cmd) == FC_FS_ACC) { } else if (ntohs(cp->ct_cmd) == FC_FS_ACC) {
/* Accepted, parse the response. */ /* Accepted, parse the response. */
buf = cp + 1; buf = cp + 1;
len -= sizeof(*cp); len -= sizeof(*cp);
} else if (ntohs(cp->ct_cmd) == FC_FS_RJT) { } else if (ntohs(cp->ct_cmd) == FC_FS_RJT) {
FC_DBG("GPN_FT rejected reason %x exp %x " FC_DISC_DBG(disc, "GPN_FT rejected reason %x exp %x "
"(check zoning)\n", cp->ct_reason, "(check zoning)\n", cp->ct_reason,
cp->ct_explan); cp->ct_explan);
disc->event = DISC_EV_FAILED; disc->event = DISC_EV_FAILED;
fc_disc_done(disc); fc_disc_done(disc);
} else { } else {
FC_DBG("GPN_FT unexpected response code %x\n", FC_DISC_DBG(disc, "GPN_FT unexpected response code "
ntohs(cp->ct_cmd)); "%x\n", ntohs(cp->ct_cmd));
} }
} else if (fr_sof(fp) == FC_SOF_N3 && } else if (fr_sof(fp) == FC_SOF_N3 &&
seq_cnt == disc->seq_count) { seq_cnt == disc->seq_count) {
buf = fh + 1; buf = fh + 1;
} else { } else {
FC_DBG("GPN_FT unexpected frame - out of sequence? " FC_DISC_DBG(disc, "GPN_FT unexpected frame - out of sequence? "
"seq_cnt %x expected %x sof %x eof %x\n", "seq_cnt %x expected %x sof %x eof %x\n",
seq_cnt, disc->seq_count, fr_sof(fp), fr_eof(fp)); seq_cnt, disc->seq_count, fr_sof(fp), fr_eof(fp));
} }
if (buf) { if (buf) {
error = fc_disc_gpn_ft_parse(disc, buf, len); error = fc_disc_gpn_ft_parse(disc, buf, len);
......
...@@ -32,18 +32,7 @@ ...@@ -32,18 +32,7 @@
#include <scsi/libfc.h> #include <scsi/libfc.h>
#include <scsi/fc_encode.h> #include <scsi/fc_encode.h>
/* static struct kmem_cache *fc_em_cachep; /* cache for exchanges */
* fc_exch_debug can be set in debugger or at compile time to get more logs.
*/
static int fc_exch_debug;
#define FC_DEBUG_EXCH(fmt...) \
do { \
if (fc_exch_debug) \
FC_DBG(fmt); \
} while (0)
static struct kmem_cache *fc_em_cachep; /* cache for exchanges */
/* /*
* Structure and function definitions for managing Fibre Channel Exchanges * Structure and function definitions for managing Fibre Channel Exchanges
...@@ -333,8 +322,8 @@ static inline void fc_exch_timer_set_locked(struct fc_exch *ep, ...@@ -333,8 +322,8 @@ static inline void fc_exch_timer_set_locked(struct fc_exch *ep,
if (ep->state & (FC_EX_RST_CLEANUP | FC_EX_DONE)) if (ep->state & (FC_EX_RST_CLEANUP | FC_EX_DONE))
return; return;
FC_DEBUG_EXCH("Exchange (%4x) timed out, notifying the upper layer\n", FC_EXCH_DBG(ep, "Exchange timed out, notifying the upper layer\n");
ep->xid);
if (schedule_delayed_work(&ep->timeout_work, if (schedule_delayed_work(&ep->timeout_work,
msecs_to_jiffies(timer_msec))) msecs_to_jiffies(timer_msec)))
fc_exch_hold(ep); /* hold for timer */ fc_exch_hold(ep); /* hold for timer */
...@@ -545,7 +534,7 @@ struct fc_exch *fc_exch_alloc(struct fc_exch_mgr *mp, ...@@ -545,7 +534,7 @@ struct fc_exch *fc_exch_alloc(struct fc_exch_mgr *mp,
/* alloc a new xid */ /* alloc a new xid */
xid = fc_em_alloc_xid(mp, fp); xid = fc_em_alloc_xid(mp, fp);
if (!xid) { if (!xid) {
printk(KERN_ERR "fc_em_alloc_xid() failed\n"); printk(KERN_WARNING "libfc: Failed to allocate an exhange\n");
goto err; goto err;
} }
} }
...@@ -820,8 +809,8 @@ static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp) ...@@ -820,8 +809,8 @@ static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp)
struct fc_exch *ep = fc_seq_exch(sp); struct fc_exch *ep = fc_seq_exch(sp);
sp = fc_seq_alloc(ep, ep->seq_id++); sp = fc_seq_alloc(ep, ep->seq_id++);
FC_DEBUG_EXCH("exch %4x f_ctl %6x seq %2x\n", FC_EXCH_DBG(ep, "f_ctl %6x seq %2x\n",
ep->xid, ep->f_ctl, sp->id); ep->f_ctl, sp->id);
return sp; return sp;
} }
/* /*
...@@ -901,7 +890,7 @@ void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd, ...@@ -901,7 +890,7 @@ void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
fc_exch_els_rec(sp, els_data->fp); fc_exch_els_rec(sp, els_data->fp);
break; break;
default: default:
FC_DBG("Invalid ELS CMD:%x\n", els_cmd); FC_EXCH_DBG(fc_seq_exch(sp), "Invalid ELS CMD:%x\n", els_cmd);
} }
} }
EXPORT_SYMBOL(fc_seq_els_rsp_send); EXPORT_SYMBOL(fc_seq_els_rsp_send);
...@@ -1134,7 +1123,7 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp, ...@@ -1134,7 +1123,7 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp,
lp->tt.lport_recv(lp, sp, fp); lp->tt.lport_recv(lp, sp, fp);
fc_exch_release(ep); /* release from lookup */ fc_exch_release(ep); /* release from lookup */
} else { } else {
FC_DEBUG_EXCH("exch/seq lookup failed: reject %x\n", reject); FC_EM_DBG(mp, "exch/seq lookup failed: reject %x\n", reject);
fc_frame_free(fp); fc_frame_free(fp);
} }
} }
...@@ -1242,10 +1231,10 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) ...@@ -1242,10 +1231,10 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */ sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
if (!sp) { if (!sp) {
atomic_inc(&mp->stats.xid_not_found); atomic_inc(&mp->stats.xid_not_found);
FC_DEBUG_EXCH("seq lookup failed\n"); FC_EM_DBG(mp, "seq lookup failed\n");
} else { } else {
atomic_inc(&mp->stats.non_bls_resp); atomic_inc(&mp->stats.non_bls_resp);
FC_DEBUG_EXCH("non-BLS response to sequence"); FC_EM_DBG(mp, "non-BLS response to sequence");
} }
fc_frame_free(fp); fc_frame_free(fp);
} }
...@@ -1266,8 +1255,8 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp) ...@@ -1266,8 +1255,8 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp)
int rc = 1, has_rec = 0; int rc = 1, has_rec = 0;
fh = fc_frame_header_get(fp); fh = fc_frame_header_get(fp);
FC_DEBUG_EXCH("exch: BLS rctl %x - %s\n", FC_EXCH_DBG(ep, "exch: BLS rctl %x - %s\n", fh->fh_r_ctl,
fh->fh_r_ctl, fc_exch_rctl_name(fh->fh_r_ctl)); fc_exch_rctl_name(fh->fh_r_ctl));
if (cancel_delayed_work_sync(&ep->timeout_work)) if (cancel_delayed_work_sync(&ep->timeout_work))
fc_exch_release(ep); /* release from pending timer hold */ fc_exch_release(ep); /* release from pending timer hold */
...@@ -1359,9 +1348,9 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp) ...@@ -1359,9 +1348,9 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp)
case FC_RCTL_ACK_0: case FC_RCTL_ACK_0:
break; break;
default: default:
FC_DEBUG_EXCH("BLS rctl %x - %s received", FC_EXCH_DBG(ep, "BLS rctl %x - %s received",
fh->fh_r_ctl, fh->fh_r_ctl,
fc_exch_rctl_name(fh->fh_r_ctl)); fc_exch_rctl_name(fh->fh_r_ctl));
break; break;
} }
fc_frame_free(fp); fc_frame_free(fp);
...@@ -1599,7 +1588,8 @@ static void fc_exch_rrq_resp(struct fc_seq *sp, struct fc_frame *fp, void *arg) ...@@ -1599,7 +1588,8 @@ static void fc_exch_rrq_resp(struct fc_seq *sp, struct fc_frame *fp, void *arg)
if (err == -FC_EX_CLOSED || err == -FC_EX_TIMEOUT) if (err == -FC_EX_CLOSED || err == -FC_EX_TIMEOUT)
goto cleanup; goto cleanup;
FC_DBG("Cannot process RRQ, because of frame error %d\n", err); FC_EXCH_DBG(aborted_ep, "Cannot process RRQ, "
"frame error %d\n", err);
return; return;
} }
...@@ -1608,12 +1598,13 @@ static void fc_exch_rrq_resp(struct fc_seq *sp, struct fc_frame *fp, void *arg) ...@@ -1608,12 +1598,13 @@ static void fc_exch_rrq_resp(struct fc_seq *sp, struct fc_frame *fp, void *arg)
switch (op) { switch (op) {
case ELS_LS_RJT: case ELS_LS_RJT:
FC_DBG("LS_RJT for RRQ"); FC_EXCH_DBG(aborted_ep, "LS_RJT for RRQ");
/* fall through */ /* fall through */
case ELS_LS_ACC: case ELS_LS_ACC:
goto cleanup; goto cleanup;
default: default:
FC_DBG("unexpected response op %x for RRQ", op); FC_EXCH_DBG(aborted_ep, "unexpected response op %x "
"for RRQ", op);
return; return;
} }
...@@ -1740,8 +1731,8 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp, ...@@ -1740,8 +1731,8 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
size_t len; size_t len;
if (max_xid <= min_xid || min_xid == 0 || max_xid == FC_XID_UNKNOWN) { if (max_xid <= min_xid || min_xid == 0 || max_xid == FC_XID_UNKNOWN) {
FC_DBG("Invalid min_xid 0x:%x and max_xid 0x:%x\n", FC_LPORT_DBG(lp, "Invalid min_xid 0x:%x and max_xid 0x:%x\n",
min_xid, max_xid); min_xid, max_xid);
return NULL; return NULL;
} }
...@@ -1878,7 +1869,8 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp, ...@@ -1878,7 +1869,8 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp,
/* lport lock ? */ /* lport lock ? */
if (!lp || !mp || (lp->state == LPORT_ST_NONE)) { if (!lp || !mp || (lp->state == LPORT_ST_NONE)) {
FC_DBG("fc_lport or EM is not allocated and configured"); FC_LPORT_DBG(lp, "Receiving frames for an lport that "
"has not been initialized correctly\n");
fc_frame_free(fp); fc_frame_free(fp);
return; return;
} }
...@@ -1904,7 +1896,7 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp, ...@@ -1904,7 +1896,7 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp,
fc_exch_recv_req(lp, mp, fp); fc_exch_recv_req(lp, mp, fp);
break; break;
default: default:
FC_DBG("dropping invalid frame (eof %x)", fr_eof(fp)); FC_EM_DBG(mp, "dropping invalid frame (eof %x)", fr_eof(fp));
fc_frame_free(fp); fc_frame_free(fp);
break; break;
} }
......
...@@ -43,13 +43,9 @@ MODULE_AUTHOR("Open-FCoE.org"); ...@@ -43,13 +43,9 @@ MODULE_AUTHOR("Open-FCoE.org");
MODULE_DESCRIPTION("libfc"); MODULE_DESCRIPTION("libfc");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
static int fc_fcp_debug; unsigned int fc_debug_logging;
module_param_named(debug_logging, fc_debug_logging, int, S_IRUGO|S_IWUSR);
#define FC_DEBUG_FCP(fmt...) \ MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
do { \
if (fc_fcp_debug) \
FC_DBG(fmt); \
} while (0)
static struct kmem_cache *scsi_pkt_cachep; static struct kmem_cache *scsi_pkt_cachep;
...@@ -347,8 +343,8 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) ...@@ -347,8 +343,8 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
if ((fr_flags(fp) & FCPHF_CRC_UNCHECKED) && if ((fr_flags(fp) & FCPHF_CRC_UNCHECKED) &&
fc_frame_crc_check(fp)) fc_frame_crc_check(fp))
goto crc_err; goto crc_err;
FC_DEBUG_FCP("data received past end. len %zx offset %zx " FC_FCP_DBG(fsp, "data received past end. len %zx offset %zx "
"data_len %x\n", len, offset, fsp->data_len); "data_len %x\n", len, offset, fsp->data_len);
fc_fcp_retry_cmd(fsp); fc_fcp_retry_cmd(fsp);
return; return;
} }
...@@ -411,7 +407,8 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) ...@@ -411,7 +407,8 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
stats->ErrorFrames++; stats->ErrorFrames++;
/* FIXME - per cpu count, not total count! */ /* FIXME - per cpu count, not total count! */
if (stats->InvalidCRCCount++ < 5) if (stats->InvalidCRCCount++ < 5)
printk(KERN_WARNING "CRC error on data frame for port (%6x)\n", printk(KERN_WARNING "libfc: CRC error on data "
"frame for port (%6x)\n",
fc_host_port_id(lp->host)); fc_host_port_id(lp->host));
/* /*
* Assume the frame is total garbage. * Assume the frame is total garbage.
...@@ -475,14 +472,14 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, ...@@ -475,14 +472,14 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq,
WARN_ON(seq_blen <= 0); WARN_ON(seq_blen <= 0);
if (unlikely(offset + seq_blen > fsp->data_len)) { if (unlikely(offset + seq_blen > fsp->data_len)) {
/* this should never happen */ /* this should never happen */
FC_DEBUG_FCP("xfer-ready past end. seq_blen %zx offset %zx\n", FC_FCP_DBG(fsp, "xfer-ready past end. seq_blen %zx "
seq_blen, offset); "offset %zx\n", seq_blen, offset);
fc_fcp_send_abort(fsp); fc_fcp_send_abort(fsp);
return 0; return 0;
} else if (offset != fsp->xfer_len) { } else if (offset != fsp->xfer_len) {
/* Out of Order Data Request - no problem, but unexpected. */ /* Out of Order Data Request - no problem, but unexpected. */
FC_DEBUG_FCP("xfer-ready non-contiguous. " FC_FCP_DBG(fsp, "xfer-ready non-contiguous. "
"seq_blen %zx offset %zx\n", seq_blen, offset); "seq_blen %zx offset %zx\n", seq_blen, offset);
} }
/* /*
...@@ -493,7 +490,7 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, ...@@ -493,7 +490,7 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq,
t_blen = fsp->max_payload; t_blen = fsp->max_payload;
if (lp->seq_offload) { if (lp->seq_offload) {
t_blen = min(seq_blen, (size_t)lp->lso_max); t_blen = min(seq_blen, (size_t)lp->lso_max);
FC_DEBUG_FCP("fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n", FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n",
fsp, seq_blen, lp->lso_max, t_blen); fsp, seq_blen, lp->lso_max, t_blen);
} }
...@@ -694,7 +691,7 @@ static void fc_fcp_reduce_can_queue(struct fc_lport *lp) ...@@ -694,7 +691,7 @@ static void fc_fcp_reduce_can_queue(struct fc_lport *lp)
if (!can_queue) if (!can_queue)
can_queue = 1; can_queue = 1;
lp->host->can_queue = can_queue; lp->host->can_queue = can_queue;
shost_printk(KERN_ERR, lp->host, "Could not allocate frame.\n" shost_printk(KERN_ERR, lp->host, "libfc: Could not allocate frame.\n"
"Reducing can_queue to %d.\n", can_queue); "Reducing can_queue to %d.\n", can_queue);
done: done:
spin_unlock_irqrestore(lp->host->host_lock, flags); spin_unlock_irqrestore(lp->host->host_lock, flags);
...@@ -768,7 +765,7 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) ...@@ -768,7 +765,7 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg)
fc_fcp_resp(fsp, fp); fc_fcp_resp(fsp, fp);
} else { } else {
FC_DBG("unexpected frame. r_ctl %x\n", r_ctl); FC_FCP_DBG(fsp, "unexpected frame. r_ctl %x\n", r_ctl);
} }
unlock: unlock:
fc_fcp_unlock_pkt(fsp); fc_fcp_unlock_pkt(fsp);
...@@ -877,17 +874,17 @@ static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) ...@@ -877,17 +874,17 @@ static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
return; return;
} }
fsp->status_code = FC_DATA_OVRRUN; fsp->status_code = FC_DATA_OVRRUN;
FC_DBG("tgt %6x xfer len %zx greater than expected len %x. " FC_FCP_DBG(fsp, "tgt %6x xfer len %zx greater than expected, "
"data len %x\n", "len %x, data len %x\n",
fsp->rport->port_id, fsp->rport->port_id,
fsp->xfer_len, expected_len, fsp->data_len); fsp->xfer_len, expected_len, fsp->data_len);
} }
fc_fcp_complete_locked(fsp); fc_fcp_complete_locked(fsp);
return; return;
len_err: len_err:
FC_DBG("short FCP response. flags 0x%x len %u respl %u snsl %u\n", FC_FCP_DBG(fsp, "short FCP response. flags 0x%x len %u respl %u "
flags, fr_len(fp), respl, snsl); "snsl %u\n", flags, fr_len(fp), respl, snsl);
err: err:
fsp->status_code = FC_ERROR; fsp->status_code = FC_ERROR;
fc_fcp_complete_locked(fsp); fc_fcp_complete_locked(fsp);
...@@ -1107,13 +1104,11 @@ static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) ...@@ -1107,13 +1104,11 @@ static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
if (fc_fcp_lock_pkt(fsp)) if (fc_fcp_lock_pkt(fsp))
return; return;
switch (error) { if (error == -FC_EX_CLOSED) {
case -FC_EX_CLOSED:
fc_fcp_retry_cmd(fsp); fc_fcp_retry_cmd(fsp);
goto unlock; goto unlock;
default:
FC_DBG("unknown error %ld\n", PTR_ERR(fp));
} }
/* /*
* clear abort pending, because the lower layer * clear abort pending, because the lower layer
* decided to force completion. * decided to force completion.
...@@ -1145,10 +1140,10 @@ static int fc_fcp_pkt_abort(struct fc_lport *lp, struct fc_fcp_pkt *fsp) ...@@ -1145,10 +1140,10 @@ static int fc_fcp_pkt_abort(struct fc_lport *lp, struct fc_fcp_pkt *fsp)
fsp->wait_for_comp = 0; fsp->wait_for_comp = 0;
if (!rc) { if (!rc) {
FC_DBG("target abort cmd failed\n"); FC_FCP_DBG(fsp, "target abort cmd failed\n");
rc = FAILED; rc = FAILED;
} else if (fsp->state & FC_SRB_ABORTED) { } else if (fsp->state & FC_SRB_ABORTED) {
FC_DBG("target abort cmd passed\n"); FC_FCP_DBG(fsp, "target abort cmd passed\n");
rc = SUCCESS; rc = SUCCESS;
fc_fcp_complete_locked(fsp); fc_fcp_complete_locked(fsp);
} }
...@@ -1213,7 +1208,7 @@ static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp, ...@@ -1213,7 +1208,7 @@ static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp,
spin_unlock_bh(&fsp->scsi_pkt_lock); spin_unlock_bh(&fsp->scsi_pkt_lock);
if (!rc) { if (!rc) {
FC_DBG("lun reset failed\n"); FC_SCSI_DBG(lp, "lun reset failed\n");
return FAILED; return FAILED;
} }
...@@ -1221,7 +1216,7 @@ static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp, ...@@ -1221,7 +1216,7 @@ static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp,
if (fsp->cdb_status != FCP_TMF_CMPL) if (fsp->cdb_status != FCP_TMF_CMPL)
return FAILED; return FAILED;
FC_DBG("lun reset to lun %u completed\n", lun); FC_SCSI_DBG(lp, "lun reset to lun %u completed\n", lun);
fc_fcp_cleanup_each_cmd(lp, id, lun, FC_CMD_ABORTED); fc_fcp_cleanup_each_cmd(lp, id, lun, FC_CMD_ABORTED);
return SUCCESS; return SUCCESS;
} }
...@@ -1388,13 +1383,13 @@ static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) ...@@ -1388,13 +1383,13 @@ static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
rjt = fc_frame_payload_get(fp, sizeof(*rjt)); rjt = fc_frame_payload_get(fp, sizeof(*rjt));
switch (rjt->er_reason) { switch (rjt->er_reason) {
default: default:
FC_DEBUG_FCP("device %x unexpected REC reject " FC_FCP_DBG(fsp, "device %x unexpected REC reject "
"reason %d expl %d\n", "reason %d expl %d\n",
fsp->rport->port_id, rjt->er_reason, fsp->rport->port_id, rjt->er_reason,
rjt->er_explan); rjt->er_explan);
/* fall through */ /* fall through */
case ELS_RJT_UNSUP: case ELS_RJT_UNSUP:
FC_DEBUG_FCP("device does not support REC\n"); FC_FCP_DBG(fsp, "device does not support REC\n");
rp = fsp->rport->dd_data; rp = fsp->rport->dd_data;
/* /*
* if we do not spport RECs or got some bogus * if we do not spport RECs or got some bogus
...@@ -1514,8 +1509,8 @@ static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) ...@@ -1514,8 +1509,8 @@ static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
break; break;
default: default:
FC_DBG("REC %p fid %x error unexpected error %d\n", FC_FCP_DBG(fsp, "REC %p fid %x error unexpected error %d\n",
fsp, fsp->rport->port_id, error); fsp, fsp->rport->port_id, error);
fsp->status_code = FC_CMD_PLOGO; fsp->status_code = FC_CMD_PLOGO;
/* fall through */ /* fall through */
...@@ -1524,9 +1519,9 @@ static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) ...@@ -1524,9 +1519,9 @@ static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
* Assume REC or LS_ACC was lost. * Assume REC or LS_ACC was lost.
* The exchange manager will have aborted REC, so retry. * The exchange manager will have aborted REC, so retry.
*/ */
FC_DBG("REC fid %x error error %d retry %d/%d\n", FC_FCP_DBG(fsp, "REC fid %x error error %d retry %d/%d\n",
fsp->rport->port_id, error, fsp->recov_retry, fsp->rport->port_id, error, fsp->recov_retry,
FC_MAX_RECOV_RETRY); FC_MAX_RECOV_RETRY);
if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY)
fc_fcp_rec(fsp); fc_fcp_rec(fsp);
else else
...@@ -2011,9 +2006,11 @@ int fc_eh_device_reset(struct scsi_cmnd *sc_cmd) ...@@ -2011,9 +2006,11 @@ int fc_eh_device_reset(struct scsi_cmnd *sc_cmd)
if (lp->state != LPORT_ST_READY) if (lp->state != LPORT_ST_READY)
return rc; return rc;
FC_SCSI_DBG(lp, "Resetting rport (%6x)\n", rport->port_id);
fsp = fc_fcp_pkt_alloc(lp, GFP_NOIO); fsp = fc_fcp_pkt_alloc(lp, GFP_NOIO);
if (fsp == NULL) { if (fsp == NULL) {
FC_DBG("could not allocate scsi_pkt\n"); printk(KERN_WARNING "libfc: could not allocate scsi_pkt\n");
sc_cmd->result = DID_NO_CONNECT << 16; sc_cmd->result = DID_NO_CONNECT << 16;
goto out; goto out;
} }
...@@ -2048,17 +2045,21 @@ int fc_eh_host_reset(struct scsi_cmnd *sc_cmd) ...@@ -2048,17 +2045,21 @@ int fc_eh_host_reset(struct scsi_cmnd *sc_cmd)
struct fc_lport *lp = shost_priv(shost); struct fc_lport *lp = shost_priv(shost);
unsigned long wait_tmo; unsigned long wait_tmo;
FC_SCSI_DBG(lp, "Resetting host\n");
lp->tt.lport_reset(lp); lp->tt.lport_reset(lp);
wait_tmo = jiffies + FC_HOST_RESET_TIMEOUT; wait_tmo = jiffies + FC_HOST_RESET_TIMEOUT;
while (!fc_fcp_lport_queue_ready(lp) && time_before(jiffies, wait_tmo)) while (!fc_fcp_lport_queue_ready(lp) && time_before(jiffies, wait_tmo))
msleep(1000); msleep(1000);
if (fc_fcp_lport_queue_ready(lp)) { if (fc_fcp_lport_queue_ready(lp)) {
shost_printk(KERN_INFO, shost, "Host reset succeeded.\n"); shost_printk(KERN_INFO, shost, "libfc: Host reset succeeded "
"on port (%6x)\n", fc_host_port_id(lp->host));
return SUCCESS; return SUCCESS;
} else { } else {
shost_printk(KERN_INFO, shost, "Host reset failed. " shost_printk(KERN_INFO, shost, "libfc: Host reset failed, "
"lport not ready.\n"); "port (%6x) is not ready.\n",
fc_host_port_id(lp->host));
return FAILED; return FAILED;
} }
} }
...@@ -2117,7 +2118,8 @@ void fc_fcp_destroy(struct fc_lport *lp) ...@@ -2117,7 +2118,8 @@ void fc_fcp_destroy(struct fc_lport *lp)
struct fc_fcp_internal *si = fc_get_scsi_internal(lp); struct fc_fcp_internal *si = fc_get_scsi_internal(lp);
if (!list_empty(&si->scsi_pkt_queue)) if (!list_empty(&si->scsi_pkt_queue))
printk(KERN_ERR "Leaked scsi packets.\n"); printk(KERN_ERR "libfc: Leaked SCSI packets when destroying "
"port (%6x)\n", fc_host_port_id(lp->host));
mempool_destroy(si->scsi_pkt_pool); mempool_destroy(si->scsi_pkt_pool);
kfree(si); kfree(si);
...@@ -2166,7 +2168,8 @@ static int __init libfc_init(void) ...@@ -2166,7 +2168,8 @@ static int __init libfc_init(void)
sizeof(struct fc_fcp_pkt), sizeof(struct fc_fcp_pkt),
0, SLAB_HWCACHE_ALIGN, NULL); 0, SLAB_HWCACHE_ALIGN, NULL);
if (scsi_pkt_cachep == NULL) { if (scsi_pkt_cachep == NULL) {
FC_DBG("Unable to allocate SRB cache...module load failed!"); printk(KERN_ERR "libfc: Unable to allocate SRB cache, "
"module load failed!");
return -ENOMEM; return -ENOMEM;
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -107,7 +107,6 @@ static inline int fc_ct_fill(struct fc_lport *lport, struct fc_frame *fp, ...@@ -107,7 +107,6 @@ static inline int fc_ct_fill(struct fc_lport *lport, struct fc_frame *fp,
break; break;
default: default:
FC_DBG("Invalid op code %x \n", op);
return -EINVAL; return -EINVAL;
} }
*r_ctl = FC_RCTL_DD_UNSOL_CTL; *r_ctl = FC_RCTL_DD_UNSOL_CTL;
...@@ -298,7 +297,6 @@ static inline int fc_els_fill(struct fc_lport *lport, struct fc_rport *rport, ...@@ -298,7 +297,6 @@ static inline int fc_els_fill(struct fc_lport *lport, struct fc_rport *rport,
break; break;
default: default:
FC_DBG("Invalid op code %x \n", op);
return -EINVAL; return -EINVAL;
} }
......
...@@ -34,17 +34,72 @@ ...@@ -34,17 +34,72 @@
#include <scsi/fc_frame.h> #include <scsi/fc_frame.h>
#define LIBFC_DEBUG #define FC_LIBFC_LOGGING 0x01 /* General logging, not categorized */
#define FC_LPORT_LOGGING 0x02 /* lport layer logging */
#ifdef LIBFC_DEBUG #define FC_DISC_LOGGING 0x04 /* discovery layer logging */
/* Log messages */ #define FC_RPORT_LOGGING 0x08 /* rport layer logging */
#define FC_DBG(fmt, args...) \ #define FC_FCP_LOGGING 0x10 /* I/O path logging */
do { \ #define FC_EM_LOGGING 0x20 /* Exchange Manager logging */
printk(KERN_INFO "%s " fmt, __func__, ##args); \ #define FC_EXCH_LOGGING 0x40 /* Exchange/Sequence logging */
} while (0) #define FC_SCSI_LOGGING 0x80 /* SCSI logging (mostly error handling) */
#else
#define FC_DBG(fmt, args...) extern unsigned int fc_debug_logging;
#endif
#define FC_CHECK_LOGGING(LEVEL, CMD) \
do { \
if (unlikely(fc_debug_logging & LEVEL)) \
do { \
CMD; \
} while (0); \
} while (0);
#define FC_LIBFC_DBG(fmt, args...) \
FC_CHECK_LOGGING(FC_LIBFC_LOGGING, \
printk(KERN_INFO "libfc: " fmt, ##args);)
#define FC_LPORT_DBG(lport, fmt, args...) \
FC_CHECK_LOGGING(FC_LPORT_LOGGING, \
printk(KERN_INFO "lport: %6x: " fmt, \
fc_host_port_id(lport->host), ##args);)
#define FC_DISC_DBG(disc, fmt, args...) \
FC_CHECK_LOGGING(FC_DISC_LOGGING, \
printk(KERN_INFO "disc: %6x: " fmt, \
fc_host_port_id(disc->lport->host), \
##args);)
#define FC_RPORT_DBG(rport, fmt, args...) \
do { \
struct fc_rport_libfc_priv *rdata = rport->dd_data; \
struct fc_lport *lport = rdata->local_port; \
FC_CHECK_LOGGING(FC_RPORT_LOGGING, \
printk(KERN_INFO "rport: %6x: %6x: " fmt, \
fc_host_port_id(lport->host), \
rport->port_id, ##args);) \
} while (0);
#define FC_FCP_DBG(pkt, fmt, args...) \
FC_CHECK_LOGGING(FC_FCP_LOGGING, \
printk(KERN_INFO "fcp: %6x: %6x: " fmt, \
fc_host_port_id(pkt->lp->host), \
pkt->rport->port_id, ##args);)
#define FC_EM_DBG(em, fmt, args...) \
FC_CHECK_LOGGING(FC_EM_LOGGING, \
printk(KERN_INFO "em: %6x: " fmt, \
fc_host_port_id(em->lp->host), \
##args);)
#define FC_EXCH_DBG(exch, fmt, args...) \
FC_CHECK_LOGGING(FC_EXCH_LOGGING, \
printk(KERN_INFO "exch: %6x: %4x: " fmt, \
fc_host_port_id(exch->lp->host), \
exch->xid, ##args);)
#define FC_SCSI_DBG(lport, fmt, args...) \
FC_CHECK_LOGGING(FC_SCSI_LOGGING, \
printk(KERN_INFO "scsi: %6x: " fmt, \
fc_host_port_id(lport->host), ##args);)
/* /*
* libfc error codes * libfc error codes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment