Back to home page

OSCL-LXR

 
 

    


0001 /* bnx2i_sysfs.c: QLogic NetXtreme II iSCSI driver.
0002  *
0003  * Copyright (c) 2004 - 2013 Broadcom Corporation
0004  * Copyright (c) 2014, QLogic Corporation
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation.
0009  *
0010  * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
0011  * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com)
0012  * Maintained by: QLogic-Storage-Upstream@qlogic.com
0013  */
0014 
0015 #include "bnx2i.h"
0016 
0017 /**
0018  * bnx2i_dev_to_hba - maps dev pointer to adapter struct
0019  * @dev:    device pointer
0020  *
0021  * Map device to hba structure
0022  */
0023 static inline struct bnx2i_hba *bnx2i_dev_to_hba(struct device *dev)
0024 {
0025     struct Scsi_Host *shost = class_to_shost(dev);
0026     return iscsi_host_priv(shost);
0027 }
0028 
0029 
0030 /**
0031  * bnx2i_show_sq_info - return(s currently configured send queue (SQ) size
0032  * @dev:    device pointer
0033  * @attr:   device attribute (unused)
0034  * @buf:    buffer to return current SQ size parameter
0035  *
0036  * Returns current SQ size parameter, this paramater determines the number
0037  * outstanding iSCSI commands supported on a connection
0038  */
0039 static ssize_t bnx2i_show_sq_info(struct device *dev,
0040                   struct device_attribute *attr, char *buf)
0041 {
0042     struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
0043 
0044     return sprintf(buf, "0x%x\n", hba->max_sqes);
0045 }
0046 
0047 
0048 /**
0049  * bnx2i_set_sq_info - update send queue (SQ) size parameter
0050  * @dev:    device pointer
0051  * @attr:   device attribute (unused)
0052  * @buf:    buffer to return current SQ size parameter
0053  * @count:  parameter buffer size
0054  *
0055  * Interface for user to change shared queue size allocated for each conn
0056  * Must be within SQ limits and a power of 2. For the latter this is needed
0057  * because of how libiscsi preallocates tasks.
0058  */
0059 static ssize_t bnx2i_set_sq_info(struct device *dev,
0060                  struct device_attribute *attr,
0061                  const char *buf, size_t count)
0062 {
0063     struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
0064     u32 val;
0065     int max_sq_size;
0066 
0067     if (hba->ofld_conns_active)
0068         goto skip_config;
0069 
0070     if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
0071         max_sq_size = BNX2I_5770X_SQ_WQES_MAX;
0072     else
0073         max_sq_size = BNX2I_570X_SQ_WQES_MAX;
0074 
0075     if (sscanf(buf, " 0x%x ", &val) > 0) {
0076         if ((val >= BNX2I_SQ_WQES_MIN) && (val <= max_sq_size) &&
0077             (is_power_of_2(val)))
0078             hba->max_sqes = val;
0079     }
0080 
0081     return count;
0082 
0083 skip_config:
0084     printk(KERN_ERR "bnx2i: device busy, cannot change SQ size\n");
0085     return 0;
0086 }
0087 
0088 
0089 /**
0090  * bnx2i_show_ccell_info - returns command cell (HQ) size
0091  * @dev:    device pointer
0092  * @attr:   device attribute (unused)
0093  * @buf:    buffer to return current SQ size parameter
0094  *
0095  * returns per-connection TCP history queue size parameter
0096  */
0097 static ssize_t bnx2i_show_ccell_info(struct device *dev,
0098                      struct device_attribute *attr, char *buf)
0099 {
0100     struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
0101 
0102     return sprintf(buf, "0x%x\n", hba->num_ccell);
0103 }
0104 
0105 
0106 /**
0107  * bnx2i_set_ccell_info - set command cell (HQ) size
0108  * @dev:    device pointer
0109  * @attr:   device attribute (unused)
0110  * @buf:    buffer to return current SQ size parameter
0111  * @count:  parameter buffer size
0112  *
0113  * updates per-connection TCP history queue size parameter
0114  */
0115 static ssize_t bnx2i_set_ccell_info(struct device *dev,
0116                     struct device_attribute *attr,
0117                     const char *buf, size_t count)
0118 {
0119     u32 val;
0120     struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
0121 
0122     if (hba->ofld_conns_active)
0123         goto skip_config;
0124 
0125     if (sscanf(buf, " 0x%x ", &val) > 0) {
0126         if ((val >= BNX2I_CCELLS_MIN) &&
0127             (val <= BNX2I_CCELLS_MAX)) {
0128             hba->num_ccell = val;
0129         }
0130     }
0131 
0132     return count;
0133 
0134 skip_config:
0135     printk(KERN_ERR "bnx2i: device busy, cannot change CCELL size\n");
0136     return 0;
0137 }
0138 
0139 
0140 static DEVICE_ATTR(sq_size, S_IRUGO | S_IWUSR,
0141            bnx2i_show_sq_info, bnx2i_set_sq_info);
0142 static DEVICE_ATTR(num_ccell, S_IRUGO | S_IWUSR,
0143            bnx2i_show_ccell_info, bnx2i_set_ccell_info);
0144 
0145 static struct attribute *bnx2i_dev_attributes[] = {
0146     &dev_attr_sq_size.attr,
0147     &dev_attr_num_ccell.attr,
0148     NULL
0149 };
0150 
0151 static const struct attribute_group bnx2i_dev_attr_group = {
0152     .attrs = bnx2i_dev_attributes
0153 };
0154 
0155 const struct attribute_group *bnx2i_dev_groups[] = {
0156     &bnx2i_dev_attr_group,
0157     NULL
0158 };