forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/s390/crypto/ap_card.c
....@@ -12,6 +12,7 @@
1212 #include <linux/init.h>
1313 #include <linux/slab.h>
1414 #include <asm/facility.h>
15
+#include <asm/sclp.h>
1516
1617 #include "ap_bus.h"
1718
....@@ -23,7 +24,7 @@
2324 {
2425 struct ap_card *ac = to_ap_card(dev);
2526
26
- return snprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type);
27
+ return scnprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type);
2728 }
2829
2930 static DEVICE_ATTR_RO(hwtype);
....@@ -33,7 +34,7 @@
3334 {
3435 struct ap_card *ac = to_ap_card(dev);
3536
36
- return snprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
37
+ return scnprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
3738 }
3839
3940 static DEVICE_ATTR_RO(raw_hwtype);
....@@ -43,7 +44,7 @@
4344 {
4445 struct ap_card *ac = to_ap_card(dev);
4546
46
- return snprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
47
+ return scnprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
4748 }
4849
4950 static DEVICE_ATTR_RO(depth);
....@@ -53,7 +54,7 @@
5354 {
5455 struct ap_card *ac = to_ap_card(dev);
5556
56
- return snprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
57
+ return scnprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
5758 }
5859
5960 static DEVICE_ATTR_RO(ap_functions);
....@@ -66,23 +67,25 @@
6667 u64 req_cnt;
6768
6869 req_cnt = 0;
69
- spin_lock_bh(&ap_list_lock);
70
+ spin_lock_bh(&ap_queues_lock);
7071 req_cnt = atomic64_read(&ac->total_request_count);
71
- spin_unlock_bh(&ap_list_lock);
72
- return snprintf(buf, PAGE_SIZE, "%llu\n", req_cnt);
72
+ spin_unlock_bh(&ap_queues_lock);
73
+ return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt);
7374 }
7475
7576 static ssize_t request_count_store(struct device *dev,
7677 struct device_attribute *attr,
7778 const char *buf, size_t count)
7879 {
79
- struct ap_card *ac = to_ap_card(dev);
80
+ int bkt;
8081 struct ap_queue *aq;
82
+ struct ap_card *ac = to_ap_card(dev);
8183
82
- spin_lock_bh(&ap_list_lock);
83
- for_each_ap_queue(aq, ac)
84
- aq->total_request_count = 0;
85
- spin_unlock_bh(&ap_list_lock);
84
+ spin_lock_bh(&ap_queues_lock);
85
+ hash_for_each(ap_queues, bkt, aq, hnode)
86
+ if (ac == aq->card)
87
+ aq->total_request_count = 0;
88
+ spin_unlock_bh(&ap_queues_lock);
8689 atomic64_set(&ac->total_request_count, 0);
8790
8891 return count;
....@@ -93,16 +96,18 @@
9396 static ssize_t requestq_count_show(struct device *dev,
9497 struct device_attribute *attr, char *buf)
9598 {
96
- struct ap_card *ac = to_ap_card(dev);
99
+ int bkt;
97100 struct ap_queue *aq;
98101 unsigned int reqq_cnt;
102
+ struct ap_card *ac = to_ap_card(dev);
99103
100104 reqq_cnt = 0;
101
- spin_lock_bh(&ap_list_lock);
102
- for_each_ap_queue(aq, ac)
103
- reqq_cnt += aq->requestq_count;
104
- spin_unlock_bh(&ap_list_lock);
105
- return snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
105
+ spin_lock_bh(&ap_queues_lock);
106
+ hash_for_each(ap_queues, bkt, aq, hnode)
107
+ if (ac == aq->card)
108
+ reqq_cnt += aq->requestq_count;
109
+ spin_unlock_bh(&ap_queues_lock);
110
+ return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
106111 }
107112
108113 static DEVICE_ATTR_RO(requestq_count);
....@@ -110,16 +115,18 @@
110115 static ssize_t pendingq_count_show(struct device *dev,
111116 struct device_attribute *attr, char *buf)
112117 {
113
- struct ap_card *ac = to_ap_card(dev);
118
+ int bkt;
114119 struct ap_queue *aq;
115120 unsigned int penq_cnt;
121
+ struct ap_card *ac = to_ap_card(dev);
116122
117123 penq_cnt = 0;
118
- spin_lock_bh(&ap_list_lock);
119
- for_each_ap_queue(aq, ac)
120
- penq_cnt += aq->pendingq_count;
121
- spin_unlock_bh(&ap_list_lock);
122
- return snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
124
+ spin_lock_bh(&ap_queues_lock);
125
+ hash_for_each(ap_queues, bkt, aq, hnode)
126
+ if (ac == aq->card)
127
+ penq_cnt += aq->pendingq_count;
128
+ spin_unlock_bh(&ap_queues_lock);
129
+ return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
123130 }
124131
125132 static DEVICE_ATTR_RO(pendingq_count);
....@@ -127,10 +134,43 @@
127134 static ssize_t modalias_show(struct device *dev,
128135 struct device_attribute *attr, char *buf)
129136 {
130
- return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
137
+ return scnprintf(buf, PAGE_SIZE, "ap:t%02X\n",
138
+ to_ap_dev(dev)->device_type);
131139 }
132140
133141 static DEVICE_ATTR_RO(modalias);
142
+
143
+static ssize_t config_show(struct device *dev,
144
+ struct device_attribute *attr, char *buf)
145
+{
146
+ struct ap_card *ac = to_ap_card(dev);
147
+
148
+ return scnprintf(buf, PAGE_SIZE, "%d\n", ac->config ? 1 : 0);
149
+}
150
+
151
+static ssize_t config_store(struct device *dev,
152
+ struct device_attribute *attr,
153
+ const char *buf, size_t count)
154
+{
155
+ int rc = 0, cfg;
156
+ struct ap_card *ac = to_ap_card(dev);
157
+
158
+ if (sscanf(buf, "%d\n", &cfg) != 1 || cfg < 0 || cfg > 1)
159
+ return -EINVAL;
160
+
161
+ if (cfg && !ac->config)
162
+ rc = sclp_ap_configure(ac->id);
163
+ else if (!cfg && ac->config)
164
+ rc = sclp_ap_deconfigure(ac->id);
165
+ if (rc)
166
+ return rc;
167
+
168
+ ac->config = cfg ? true : false;
169
+
170
+ return count;
171
+}
172
+
173
+static DEVICE_ATTR_RW(config);
134174
135175 static struct attribute *ap_card_dev_attrs[] = {
136176 &dev_attr_hwtype.attr,
....@@ -141,6 +181,7 @@
141181 &dev_attr_requestq_count.attr,
142182 &dev_attr_pendingq_count.attr,
143183 &dev_attr_modalias.attr,
184
+ &dev_attr_config.attr,
144185 NULL
145186 };
146187
....@@ -162,11 +203,6 @@
162203 {
163204 struct ap_card *ac = to_ap_card(dev);
164205
165
- if (!list_empty(&ac->list)) {
166
- spin_lock_bh(&ap_list_lock);
167
- list_del_init(&ac->list);
168
- spin_unlock_bh(&ap_list_lock);
169
- }
170206 kfree(ac);
171207 }
172208
....@@ -178,8 +214,6 @@
178214 ac = kzalloc(sizeof(*ac), GFP_KERNEL);
179215 if (!ac)
180216 return NULL;
181
- INIT_LIST_HEAD(&ac->list);
182
- INIT_LIST_HEAD(&ac->queues);
183217 ac->ap_dev.device.release = ap_card_device_release;
184218 ac->ap_dev.device.type = &ap_card_type;
185219 ac->ap_dev.device_type = comp_type;