lpfc_attr.c

来自「linux 内核源代码」· C语言 代码 · 共 2,217 行 · 第 1/5 页

C
2,217
字号
	 * prevent udev from issuing mailbox commands until the port is	 * configured.	 */	if (phba->link_state < LPFC_LINK_DOWN ||	    !phba->mbox_mem_pool ||	    (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)		return 0;	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)		return 0;	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);	if (!pmboxq)		return 0;	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));	pmb = &pmboxq->mb;	pmb->mbxCommand = MBX_READ_CONFIG;	pmb->mbxOwner = OWN_HOST;	pmboxq->context1 = NULL;	if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||		(!(psli->sli_flag & LPFC_SLI2_ACTIVE)))		rc = MBX_NOT_FINISHED;	else		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);	if (rc != MBX_SUCCESS) {		if (rc != MBX_TIMEOUT)			mempool_free(pmboxq, phba->mbox_mem_pool);		return 0;	}	if (mrpi)		*mrpi = pmb->un.varRdConfig.max_rpi;	if (arpi)		*arpi = pmb->un.varRdConfig.avail_rpi;	if (mxri)		*mxri = pmb->un.varRdConfig.max_xri;	if (axri)		*axri = pmb->un.varRdConfig.avail_xri;	if (mvpi)		*mvpi = pmb->un.varRdConfig.max_vpi;	if (avpi)		*avpi = pmb->un.varRdConfig.avail_vpi;	mempool_free(pmboxq, phba->mbox_mem_pool);	return 1;}static ssize_tlpfc_max_rpi_show(struct class_device *cdev, char *buf){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	uint32_t cnt;	if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))		return snprintf(buf, PAGE_SIZE, "%d\n", cnt);	return snprintf(buf, PAGE_SIZE, "Unknown\n");}static ssize_tlpfc_used_rpi_show(struct class_device *cdev, char *buf){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	uint32_t cnt, acnt;	if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))		return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));	return snprintf(buf, PAGE_SIZE, "Unknown\n");}static ssize_tlpfc_max_xri_show(struct class_device *cdev, char *buf){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	uint32_t cnt;	if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))		return snprintf(buf, PAGE_SIZE, "%d\n", cnt);	return snprintf(buf, PAGE_SIZE, "Unknown\n");}static ssize_tlpfc_used_xri_show(struct class_device *cdev, char *buf){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	uint32_t cnt, acnt;	if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))		return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));	return snprintf(buf, PAGE_SIZE, "Unknown\n");}static ssize_tlpfc_max_vpi_show(struct class_device *cdev, char *buf){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	uint32_t cnt;	if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))		return snprintf(buf, PAGE_SIZE, "%d\n", cnt);	return snprintf(buf, PAGE_SIZE, "Unknown\n");}static ssize_tlpfc_used_vpi_show(struct class_device *cdev, char *buf){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	uint32_t cnt, acnt;	if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))		return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));	return snprintf(buf, PAGE_SIZE, "Unknown\n");}static ssize_tlpfc_npiv_info_show(struct class_device *cdev, char *buf){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	if (!(phba->max_vpi))		return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");	if (vport->port_type == LPFC_PHYSICAL_PORT)		return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");	return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);}static ssize_tlpfc_poll_show(struct class_device *cdev, char *buf){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);}static ssize_tlpfc_poll_store(struct class_device *cdev, const char *buf,		size_t count){	struct Scsi_Host  *shost = class_to_shost(cdev);	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;	struct lpfc_hba   *phba = vport->phba;	uint32_t creg_val;	uint32_t old_val;	int val=0;	if (!isdigit(buf[0]))		return -EINVAL;	if (sscanf(buf, "%i", &val) != 1)		return -EINVAL;	if ((val & 0x3) != val)		return -EINVAL;	spin_lock_irq(&phba->hbalock);	old_val = phba->cfg_poll;	if (val & ENABLE_FCP_RING_POLLING) {		if ((val & DISABLE_FCP_RING_INT) &&		    !(old_val & DISABLE_FCP_RING_INT)) {			creg_val = readl(phba->HCregaddr);			creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);			writel(creg_val, phba->HCregaddr);			readl(phba->HCregaddr); /* flush */			lpfc_poll_start_timer(phba);		}	} else if (val != 0x0) {		spin_unlock_irq(&phba->hbalock);		return -EINVAL;	}	if (!(val & DISABLE_FCP_RING_INT) &&	    (old_val & DISABLE_FCP_RING_INT))	{		spin_unlock_irq(&phba->hbalock);		del_timer(&phba->fcp_poll_timer);		spin_lock_irq(&phba->hbalock);		creg_val = readl(phba->HCregaddr);		creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);		writel(creg_val, phba->HCregaddr);		readl(phba->HCregaddr); /* flush */	}	phba->cfg_poll = val;	spin_unlock_irq(&phba->hbalock);	return strlen(buf);}#define lpfc_param_show(attr)	\static ssize_t \lpfc_##attr##_show(struct class_device *cdev, char *buf) \{ \	struct Scsi_Host  *shost = class_to_shost(cdev);\	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\	struct lpfc_hba   *phba = vport->phba;\	int val = 0;\	val = phba->cfg_##attr;\	return snprintf(buf, PAGE_SIZE, "%d\n",\			phba->cfg_##attr);\}#define lpfc_param_hex_show(attr)	\static ssize_t \lpfc_##attr##_show(struct class_device *cdev, char *buf) \{ \	struct Scsi_Host  *shost = class_to_shost(cdev);\	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\	struct lpfc_hba   *phba = vport->phba;\	int val = 0;\	val = phba->cfg_##attr;\	return snprintf(buf, PAGE_SIZE, "%#x\n",\			phba->cfg_##attr);\}#define lpfc_param_init(attr, default, minval, maxval)	\static int \lpfc_##attr##_init(struct lpfc_hba *phba, int val) \{ \	if (val >= minval && val <= maxval) {\		phba->cfg_##attr = val;\		return 0;\	}\	lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \			"0449 lpfc_"#attr" attribute cannot be set to %d, "\			"allowed range is ["#minval", "#maxval"]\n", val); \	phba->cfg_##attr = default;\	return -EINVAL;\}#define lpfc_param_set(attr, default, minval, maxval)	\static int \lpfc_##attr##_set(struct lpfc_hba *phba, int val) \{ \	if (val >= minval && val <= maxval) {\		phba->cfg_##attr = val;\		return 0;\	}\	lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \			"0450 lpfc_"#attr" attribute cannot be set to %d, "\			"allowed range is ["#minval", "#maxval"]\n", val); \	return -EINVAL;\}#define lpfc_param_store(attr)	\static ssize_t \lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \{ \	struct Scsi_Host  *shost = class_to_shost(cdev);\	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\	struct lpfc_hba   *phba = vport->phba;\	int val=0;\	if (!isdigit(buf[0]))\		return -EINVAL;\	if (sscanf(buf, "%i", &val) != 1)\		return -EINVAL;\	if (lpfc_##attr##_set(phba, val) == 0) \		return strlen(buf);\	else \		return -EINVAL;\}#define lpfc_vport_param_show(attr)	\static ssize_t \lpfc_##attr##_show(struct class_device *cdev, char *buf) \{ \	struct Scsi_Host  *shost = class_to_shost(cdev);\	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\	int val = 0;\	val = vport->cfg_##attr;\	return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\}#define lpfc_vport_param_hex_show(attr)	\static ssize_t \lpfc_##attr##_show(struct class_device *cdev, char *buf) \{ \	struct Scsi_Host  *shost = class_to_shost(cdev);\	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\	int val = 0;\	val = vport->cfg_##attr;\	return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\}#define lpfc_vport_param_init(attr, default, minval, maxval)	\static int \lpfc_##attr##_init(struct lpfc_vport *vport, int val) \{ \	if (val >= minval && val <= maxval) {\		vport->cfg_##attr = val;\		return 0;\	}\	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \			 "0449 lpfc_"#attr" attribute cannot be set to %d, "\			 "allowed range is ["#minval", "#maxval"]\n", val); \	vport->cfg_##attr = default;\	return -EINVAL;\}#define lpfc_vport_param_set(attr, default, minval, maxval)	\static int \lpfc_##attr##_set(struct lpfc_vport *vport, int val) \{ \	if (val >= minval && val <= maxval) {\		vport->cfg_##attr = val;\		return 0;\	}\	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \			 "0450 lpfc_"#attr" attribute cannot be set to %d, "\			 "allowed range is ["#minval", "#maxval"]\n", val); \	return -EINVAL;\}#define lpfc_vport_param_store(attr)	\static ssize_t \lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \{ \	struct Scsi_Host  *shost = class_to_shost(cdev);\	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\	int val=0;\	if (!isdigit(buf[0]))\		return -EINVAL;\	if (sscanf(buf, "%i", &val) != 1)\		return -EINVAL;\	if (lpfc_##attr##_set(vport, val) == 0) \		return strlen(buf);\	else \		return -EINVAL;\}#define LPFC_ATTR(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_param_init(name, defval, minval, maxval)#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_param_show(name)\lpfc_param_init(name, defval, minval, maxval)\static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_param_show(name)\lpfc_param_init(name, defval, minval, maxval)\lpfc_param_set(name, defval, minval, maxval)\lpfc_param_store(name)\static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\			 lpfc_##name##_show, lpfc_##name##_store)#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_param_hex_show(name)\lpfc_param_init(name, defval, minval, maxval)\static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_param_hex_show(name)\lpfc_param_init(name, defval, minval, maxval)\lpfc_param_set(name, defval, minval, maxval)\lpfc_param_store(name)\static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\			 lpfc_##name##_show, lpfc_##name##_store)#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_vport_param_init(name, defval, minval, maxval)#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_vport_param_show(name)\lpfc_vport_param_init(name, defval, minval, maxval)\static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_vport_param_show(name)\lpfc_vport_param_init(name, defval, minval, maxval)\lpfc_vport_param_set(name, defval, minval, maxval)\lpfc_vport_param_store(name)\static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\			 lpfc_##name##_show, lpfc_##name##_store)#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_vport_param_hex_show(name)\lpfc_vport_param_init(name, defval, minval, maxval)\static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \static int lpfc_##name = defval;\module_param(lpfc_##name, int, 0);\MODULE_PARM_DESC(lpfc_##name, desc);\lpfc_vport_param_hex_show(name)\lpfc_vport_param_init(name, defval, minval, maxval)\lpfc_vport_param_set(name, defval, minval, maxval)\lpfc_vport_param_store(name)\static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\			 lpfc_##name##_show, lpfc_##name##_store)static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?