Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / scsi / bnx2i / bnx2i_sysfs.c
1 /* bnx2i_sysfs.c: QLogic NetXtreme II iSCSI driver.
2  *
3  * Copyright (c) 2004 - 2013 Broadcom Corporation
4  * Copyright (c) 2014, QLogic Corporation
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation.
9  *
10  * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
11  * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com)
12  * Maintained by: QLogic-Storage-Upstream@qlogic.com
13  */
14
15 #include "bnx2i.h"
16
17 /**
18  * bnx2i_dev_to_hba - maps dev pointer to adapter struct
19  * @dev:        device pointer
20  *
21  * Map device to hba structure
22  */
23 static inline struct bnx2i_hba *bnx2i_dev_to_hba(struct device *dev)
24 {
25         struct Scsi_Host *shost = class_to_shost(dev);
26         return iscsi_host_priv(shost);
27 }
28
29
30 /**
31  * bnx2i_show_sq_info - return(s currently configured send queue (SQ) size
32  * @dev:        device pointer
33  * @buf:        buffer to return current SQ size parameter
34  *
35  * Returns current SQ size parameter, this paramater determines the number
36  * outstanding iSCSI commands supported on a connection
37  */
38 static ssize_t bnx2i_show_sq_info(struct device *dev,
39                                   struct device_attribute *attr, char *buf)
40 {
41         struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
42
43         return sprintf(buf, "0x%x\n", hba->max_sqes);
44 }
45
46
47 /**
48  * bnx2i_set_sq_info - update send queue (SQ) size parameter
49  * @dev:        device pointer
50  * @buf:        buffer to return current SQ size parameter
51  * @count:      parameter buffer size
52  *
53  * Interface for user to change shared queue size allocated for each conn
54  * Must be within SQ limits and a power of 2. For the latter this is needed
55  * because of how libiscsi preallocates tasks.
56  */
57 static ssize_t bnx2i_set_sq_info(struct device *dev,
58                                  struct device_attribute *attr,
59                                  const char *buf, size_t count)
60 {
61         struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
62         u32 val;
63         int max_sq_size;
64
65         if (hba->ofld_conns_active)
66                 goto skip_config;
67
68         if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
69                 max_sq_size = BNX2I_5770X_SQ_WQES_MAX;
70         else
71                 max_sq_size = BNX2I_570X_SQ_WQES_MAX;
72
73         if (sscanf(buf, " 0x%x ", &val) > 0) {
74                 if ((val >= BNX2I_SQ_WQES_MIN) && (val <= max_sq_size) &&
75                     (is_power_of_2(val)))
76                         hba->max_sqes = val;
77         }
78
79         return count;
80
81 skip_config:
82         printk(KERN_ERR "bnx2i: device busy, cannot change SQ size\n");
83         return 0;
84 }
85
86
87 /**
88  * bnx2i_show_ccell_info - returns command cell (HQ) size
89  * @dev:        device pointer
90  * @buf:        buffer to return current SQ size parameter
91  *
92  * returns per-connection TCP history queue size parameter
93  */
94 static ssize_t bnx2i_show_ccell_info(struct device *dev,
95                                      struct device_attribute *attr, char *buf)
96 {
97         struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
98
99         return sprintf(buf, "0x%x\n", hba->num_ccell);
100 }
101
102
103 /**
104  * bnx2i_get_link_state - set command cell (HQ) size
105  * @dev:        device pointer
106  * @buf:        buffer to return current SQ size parameter
107  * @count:      parameter buffer size
108  *
109  * updates per-connection TCP history queue size parameter
110  */
111 static ssize_t bnx2i_set_ccell_info(struct device *dev,
112                                     struct device_attribute *attr,
113                                     const char *buf, size_t count)
114 {
115         u32 val;
116         struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev);
117
118         if (hba->ofld_conns_active)
119                 goto skip_config;
120
121         if (sscanf(buf, " 0x%x ", &val) > 0) {
122                 if ((val >= BNX2I_CCELLS_MIN) &&
123                     (val <= BNX2I_CCELLS_MAX)) {
124                         hba->num_ccell = val;
125                 }
126         }
127
128         return count;
129
130 skip_config:
131         printk(KERN_ERR "bnx2i: device busy, cannot change CCELL size\n");
132         return 0;
133 }
134
135
136 static DEVICE_ATTR(sq_size, S_IRUGO | S_IWUSR,
137                    bnx2i_show_sq_info, bnx2i_set_sq_info);
138 static DEVICE_ATTR(num_ccell, S_IRUGO | S_IWUSR,
139                    bnx2i_show_ccell_info, bnx2i_set_ccell_info);
140
141 struct device_attribute *bnx2i_dev_attributes[] = {
142         &dev_attr_sq_size,
143         &dev_attr_num_ccell,
144         NULL
145 };