lpfc_debugfs.c
来自「linux 内核源代码」· C语言 代码 · 共 1,003 行 · 第 1/2 页
C
1,003 行
#ifdef CONFIG_LPFC_DEBUG_FS struct lpfc_debugfs_trc *dtp; int index; if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc || !phba || !phba->slow_ring_trc) return; index = atomic_inc_return(&phba->slow_ring_trc_cnt) & (lpfc_debugfs_max_slow_ring_trc - 1); dtp = phba->slow_ring_trc + index; dtp->fmt = fmt; dtp->data1 = data1; dtp->data2 = data2; dtp->data3 = data3; dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); dtp->jif = jiffies;#endif return;}#ifdef CONFIG_LPFC_DEBUG_FSstatic intlpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file){ struct lpfc_vport *vport = inode->i_private; struct lpfc_debug *debug; int size; int rc = -ENOMEM; if (!lpfc_debugfs_max_disc_trc) { rc = -ENOSPC; goto out; } debug = kmalloc(sizeof(*debug), GFP_KERNEL); if (!debug) goto out; /* Round to page boundry */ size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); size = PAGE_ALIGN(size); debug->buffer = kmalloc(size, GFP_KERNEL); if (!debug->buffer) { kfree(debug); goto out; } debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size); file->private_data = debug; rc = 0;out: return rc;}static intlpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file){ struct lpfc_hba *phba = inode->i_private; struct lpfc_debug *debug; int size; int rc = -ENOMEM; if (!lpfc_debugfs_max_slow_ring_trc) { rc = -ENOSPC; goto out; } debug = kmalloc(sizeof(*debug), GFP_KERNEL); if (!debug) goto out; /* Round to page boundry */ size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); size = PAGE_ALIGN(size); debug->buffer = kmalloc(size, GFP_KERNEL); if (!debug->buffer) { kfree(debug); goto out; } debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size); file->private_data = debug; rc = 0;out: return rc;}static intlpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file){ struct lpfc_hba *phba = inode->i_private; struct lpfc_debug *debug; int rc = -ENOMEM; debug = kmalloc(sizeof(*debug), GFP_KERNEL); if (!debug) goto out; /* Round to page boundry */ debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL); if (!debug->buffer) { kfree(debug); goto out; } debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer, LPFC_HBQINFO_SIZE); file->private_data = debug; rc = 0;out: return rc;}static intlpfc_debugfs_dumpslim_open(struct inode *inode, struct file *file){ struct lpfc_hba *phba = inode->i_private; struct lpfc_debug *debug; int rc = -ENOMEM; debug = kmalloc(sizeof(*debug), GFP_KERNEL); if (!debug) goto out; /* Round to page boundry */ debug->buffer = kmalloc(LPFC_DUMPSLIM_SIZE, GFP_KERNEL); if (!debug->buffer) { kfree(debug); goto out; } debug->len = lpfc_debugfs_dumpslim_data(phba, debug->buffer, LPFC_DUMPSLIM_SIZE); file->private_data = debug; rc = 0;out: return rc;}static intlpfc_debugfs_nodelist_open(struct inode *inode, struct file *file){ struct lpfc_vport *vport = inode->i_private; struct lpfc_debug *debug; int rc = -ENOMEM; debug = kmalloc(sizeof(*debug), GFP_KERNEL); if (!debug) goto out; /* Round to page boundry */ debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL); if (!debug->buffer) { kfree(debug); goto out; } debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer, LPFC_NODELIST_SIZE); file->private_data = debug; rc = 0;out: return rc;}static loff_tlpfc_debugfs_lseek(struct file *file, loff_t off, int whence){ struct lpfc_debug *debug; loff_t pos = -1; debug = file->private_data; switch (whence) { case 0: pos = off; break; case 1: pos = file->f_pos + off; break; case 2: pos = debug->len - off; } return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);}static ssize_tlpfc_debugfs_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos){ struct lpfc_debug *debug = file->private_data; return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer, debug->len);}static intlpfc_debugfs_release(struct inode *inode, struct file *file){ struct lpfc_debug *debug = file->private_data; kfree(debug->buffer); kfree(debug); return 0;}#undef lpfc_debugfs_op_disc_trcstatic struct file_operations lpfc_debugfs_op_disc_trc = { .owner = THIS_MODULE, .open = lpfc_debugfs_disc_trc_open, .llseek = lpfc_debugfs_lseek, .read = lpfc_debugfs_read, .release = lpfc_debugfs_release,};#undef lpfc_debugfs_op_nodeliststatic struct file_operations lpfc_debugfs_op_nodelist = { .owner = THIS_MODULE, .open = lpfc_debugfs_nodelist_open, .llseek = lpfc_debugfs_lseek, .read = lpfc_debugfs_read, .release = lpfc_debugfs_release,};#undef lpfc_debugfs_op_hbqinfostatic struct file_operations lpfc_debugfs_op_hbqinfo = { .owner = THIS_MODULE, .open = lpfc_debugfs_hbqinfo_open, .llseek = lpfc_debugfs_lseek, .read = lpfc_debugfs_read, .release = lpfc_debugfs_release,};#undef lpfc_debugfs_op_dumpslimstatic struct file_operations lpfc_debugfs_op_dumpslim = { .owner = THIS_MODULE, .open = lpfc_debugfs_dumpslim_open, .llseek = lpfc_debugfs_lseek, .read = lpfc_debugfs_read, .release = lpfc_debugfs_release,};#undef lpfc_debugfs_op_slow_ring_trcstatic struct file_operations lpfc_debugfs_op_slow_ring_trc = { .owner = THIS_MODULE, .open = lpfc_debugfs_slow_ring_trc_open, .llseek = lpfc_debugfs_lseek, .read = lpfc_debugfs_read, .release = lpfc_debugfs_release,};static struct dentry *lpfc_debugfs_root = NULL;static atomic_t lpfc_debugfs_hba_count;#endifinline voidlpfc_debugfs_initialize(struct lpfc_vport *vport){#ifdef CONFIG_LPFC_DEBUG_FS struct lpfc_hba *phba = vport->phba; char name[64]; uint32_t num, i; if (!lpfc_debugfs_enable) return; /* Setup lpfc root directory */ if (!lpfc_debugfs_root) { lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL); atomic_set(&lpfc_debugfs_hba_count, 0); if (!lpfc_debugfs_root) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cannot create debugfs root\n"); goto debug_failed; } } if (!lpfc_debugfs_start_time) lpfc_debugfs_start_time = jiffies; /* Setup lpfcX directory for specific HBA */ snprintf(name, sizeof(name), "lpfc%d", phba->brd_no); if (!phba->hba_debugfs_root) { phba->hba_debugfs_root = debugfs_create_dir(name, lpfc_debugfs_root); if (!phba->hba_debugfs_root) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cannot create debugfs hba\n"); goto debug_failed; } atomic_inc(&lpfc_debugfs_hba_count); atomic_set(&phba->debugfs_vport_count, 0); /* Setup hbqinfo */ snprintf(name, sizeof(name), "hbqinfo"); phba->debug_hbqinfo = debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, phba->hba_debugfs_root, phba, &lpfc_debugfs_op_hbqinfo); if (!phba->debug_hbqinfo) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cannot create debugfs hbqinfo\n"); goto debug_failed; } /* Setup dumpslim */ snprintf(name, sizeof(name), "dumpslim"); phba->debug_dumpslim = debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, phba->hba_debugfs_root, phba, &lpfc_debugfs_op_dumpslim); if (!phba->debug_dumpslim) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cannot create debugfs dumpslim\n"); goto debug_failed; } /* Setup slow ring trace */ if (lpfc_debugfs_max_slow_ring_trc) { num = lpfc_debugfs_max_slow_ring_trc - 1; if (num & lpfc_debugfs_max_slow_ring_trc) { /* Change to be a power of 2 */ num = lpfc_debugfs_max_slow_ring_trc; i = 0; while (num > 1) { num = num >> 1; i++; } lpfc_debugfs_max_slow_ring_trc = (1 << i); printk(KERN_ERR "lpfc_debugfs_max_disc_trc changed to " "%d\n", lpfc_debugfs_max_disc_trc); } } snprintf(name, sizeof(name), "slow_ring_trace"); phba->debug_slow_ring_trc = debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, phba->hba_debugfs_root, phba, &lpfc_debugfs_op_slow_ring_trc); if (!phba->debug_slow_ring_trc) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cannot create debugfs " "slow_ring_trace\n"); goto debug_failed; } if (!phba->slow_ring_trc) { phba->slow_ring_trc = kmalloc( (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_slow_ring_trc), GFP_KERNEL); if (!phba->slow_ring_trc) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cannot create debugfs " "slow_ring buffer\n"); goto debug_failed; } atomic_set(&phba->slow_ring_trc_cnt, 0); memset(phba->slow_ring_trc, 0, (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_slow_ring_trc)); } } snprintf(name, sizeof(name), "vport%d", vport->vpi); if (!vport->vport_debugfs_root) { vport->vport_debugfs_root = debugfs_create_dir(name, phba->hba_debugfs_root); if (!vport->vport_debugfs_root) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cant create debugfs"); goto debug_failed; } atomic_inc(&phba->debugfs_vport_count); } if (lpfc_debugfs_max_disc_trc) { num = lpfc_debugfs_max_disc_trc - 1; if (num & lpfc_debugfs_max_disc_trc) { /* Change to be a power of 2 */ num = lpfc_debugfs_max_disc_trc; i = 0; while (num > 1) { num = num >> 1; i++; } lpfc_debugfs_max_disc_trc = (1 << i); printk(KERN_ERR "lpfc_debugfs_max_disc_trc changed to %d\n", lpfc_debugfs_max_disc_trc); } } vport->disc_trc = kzalloc( (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc), GFP_KERNEL); if (!vport->disc_trc) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cannot create debugfs disc trace " "buffer\n"); goto debug_failed; } atomic_set(&vport->disc_trc_cnt, 0); snprintf(name, sizeof(name), "discovery_trace"); vport->debug_disc_trc = debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, vport->vport_debugfs_root, vport, &lpfc_debugfs_op_disc_trc); if (!vport->debug_disc_trc) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cannot create debugfs " "discovery_trace\n"); goto debug_failed; } snprintf(name, sizeof(name), "nodelist"); vport->debug_nodelist = debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, vport->vport_debugfs_root, vport, &lpfc_debugfs_op_nodelist); if (!vport->debug_nodelist) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0409 Cant create debugfs nodelist"); goto debug_failed; }debug_failed: return;#endif}inline voidlpfc_debugfs_terminate(struct lpfc_vport *vport){#ifdef CONFIG_LPFC_DEBUG_FS struct lpfc_hba *phba = vport->phba; if (vport->disc_trc) { kfree(vport->disc_trc); vport->disc_trc = NULL; } if (vport->debug_disc_trc) { debugfs_remove(vport->debug_disc_trc); /* discovery_trace */ vport->debug_disc_trc = NULL; } if (vport->debug_nodelist) { debugfs_remove(vport->debug_nodelist); /* nodelist */ vport->debug_nodelist = NULL; } if (vport->vport_debugfs_root) { debugfs_remove(vport->vport_debugfs_root); /* vportX */ vport->vport_debugfs_root = NULL; atomic_dec(&phba->debugfs_vport_count); } if (atomic_read(&phba->debugfs_vport_count) == 0) { if (phba->debug_hbqinfo) { debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */ phba->debug_hbqinfo = NULL; } if (phba->debug_dumpslim) { debugfs_remove(phba->debug_dumpslim); /* dumpslim */ phba->debug_dumpslim = NULL; } if (phba->slow_ring_trc) { kfree(phba->slow_ring_trc); phba->slow_ring_trc = NULL; } if (phba->debug_slow_ring_trc) { /* slow_ring_trace */ debugfs_remove(phba->debug_slow_ring_trc); phba->debug_slow_ring_trc = NULL; } if (phba->hba_debugfs_root) { debugfs_remove(phba->hba_debugfs_root); /* lpfcX */ phba->hba_debugfs_root = NULL; atomic_dec(&lpfc_debugfs_hba_count); } if (atomic_read(&lpfc_debugfs_hba_count) == 0) { debugfs_remove(lpfc_debugfs_root); /* lpfc */ lpfc_debugfs_root = NULL; } }#endif return;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?