1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright IBM Corp. 2012, 2019
4*4882a593Smuzhiyun * Author(s): Holger Dengler <hd@linux.vnet.ibm.com>
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #include <linux/module.h>
8*4882a593Smuzhiyun #include <linux/slab.h>
9*4882a593Smuzhiyun #include <linux/init.h>
10*4882a593Smuzhiyun #include <linux/err.h>
11*4882a593Smuzhiyun #include <linux/atomic.h>
12*4882a593Smuzhiyun #include <linux/uaccess.h>
13*4882a593Smuzhiyun #include <linux/mod_devicetable.h>
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include "ap_bus.h"
16*4882a593Smuzhiyun #include "zcrypt_api.h"
17*4882a593Smuzhiyun #include "zcrypt_msgtype6.h"
18*4882a593Smuzhiyun #include "zcrypt_msgtype50.h"
19*4882a593Smuzhiyun #include "zcrypt_error.h"
20*4882a593Smuzhiyun #include "zcrypt_cex4.h"
21*4882a593Smuzhiyun #include "zcrypt_ccamisc.h"
22*4882a593Smuzhiyun #include "zcrypt_ep11misc.h"
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #define CEX4A_MIN_MOD_SIZE 1 /* 8 bits */
25*4882a593Smuzhiyun #define CEX4A_MAX_MOD_SIZE_2K 256 /* 2048 bits */
26*4882a593Smuzhiyun #define CEX4A_MAX_MOD_SIZE_4K 512 /* 4096 bits */
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun #define CEX4C_MIN_MOD_SIZE 16 /* 256 bits */
29*4882a593Smuzhiyun #define CEX4C_MAX_MOD_SIZE 512 /* 4096 bits */
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #define CEX4A_MAX_MESSAGE_SIZE MSGTYPE50_CRB3_MAX_MSG_SIZE
32*4882a593Smuzhiyun #define CEX4C_MAX_MESSAGE_SIZE MSGTYPE06_MAX_MSG_SIZE
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun /* Waiting time for requests to be processed.
35*4882a593Smuzhiyun * Currently there are some types of request which are not deterministic.
36*4882a593Smuzhiyun * But the maximum time limit managed by the stomper code is set to 60sec.
37*4882a593Smuzhiyun * Hence we have to wait at least that time period.
38*4882a593Smuzhiyun */
39*4882a593Smuzhiyun #define CEX4_CLEANUP_TIME (900*HZ)
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun MODULE_AUTHOR("IBM Corporation");
42*4882a593Smuzhiyun MODULE_DESCRIPTION("CEX4/CEX5/CEX6/CEX7 Cryptographic Card device driver, " \
43*4882a593Smuzhiyun "Copyright IBM Corp. 2019");
44*4882a593Smuzhiyun MODULE_LICENSE("GPL");
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun static struct ap_device_id zcrypt_cex4_card_ids[] = {
47*4882a593Smuzhiyun { .dev_type = AP_DEVICE_TYPE_CEX4,
48*4882a593Smuzhiyun .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
49*4882a593Smuzhiyun { .dev_type = AP_DEVICE_TYPE_CEX5,
50*4882a593Smuzhiyun .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
51*4882a593Smuzhiyun { .dev_type = AP_DEVICE_TYPE_CEX6,
52*4882a593Smuzhiyun .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
53*4882a593Smuzhiyun { .dev_type = AP_DEVICE_TYPE_CEX7,
54*4882a593Smuzhiyun .match_flags = AP_DEVICE_ID_MATCH_CARD_TYPE },
55*4882a593Smuzhiyun { /* end of list */ },
56*4882a593Smuzhiyun };
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun MODULE_DEVICE_TABLE(ap, zcrypt_cex4_card_ids);
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun static struct ap_device_id zcrypt_cex4_queue_ids[] = {
61*4882a593Smuzhiyun { .dev_type = AP_DEVICE_TYPE_CEX4,
62*4882a593Smuzhiyun .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
63*4882a593Smuzhiyun { .dev_type = AP_DEVICE_TYPE_CEX5,
64*4882a593Smuzhiyun .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
65*4882a593Smuzhiyun { .dev_type = AP_DEVICE_TYPE_CEX6,
66*4882a593Smuzhiyun .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
67*4882a593Smuzhiyun { .dev_type = AP_DEVICE_TYPE_CEX7,
68*4882a593Smuzhiyun .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE },
69*4882a593Smuzhiyun { /* end of list */ },
70*4882a593Smuzhiyun };
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun MODULE_DEVICE_TABLE(ap, zcrypt_cex4_queue_ids);
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun * CCA card additional device attributes
76*4882a593Smuzhiyun */
cca_serialnr_show(struct device * dev,struct device_attribute * attr,char * buf)77*4882a593Smuzhiyun static ssize_t cca_serialnr_show(struct device *dev,
78*4882a593Smuzhiyun struct device_attribute *attr,
79*4882a593Smuzhiyun char *buf)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun struct cca_info ci;
82*4882a593Smuzhiyun struct ap_card *ac = to_ap_card(dev);
83*4882a593Smuzhiyun struct zcrypt_card *zc = ac->private;
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun memset(&ci, 0, sizeof(ci));
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun if (ap_domain_index >= 0)
88*4882a593Smuzhiyun cca_get_info(ac->id, ap_domain_index, &ci, zc->online);
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%s\n", ci.serial);
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun static struct device_attribute dev_attr_cca_serialnr =
94*4882a593Smuzhiyun __ATTR(serialnr, 0444, cca_serialnr_show, NULL);
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun static struct attribute *cca_card_attrs[] = {
97*4882a593Smuzhiyun &dev_attr_cca_serialnr.attr,
98*4882a593Smuzhiyun NULL,
99*4882a593Smuzhiyun };
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun static const struct attribute_group cca_card_attr_grp = {
102*4882a593Smuzhiyun .attrs = cca_card_attrs,
103*4882a593Smuzhiyun };
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun * CCA queue additional device attributes
107*4882a593Smuzhiyun */
cca_mkvps_show(struct device * dev,struct device_attribute * attr,char * buf)108*4882a593Smuzhiyun static ssize_t cca_mkvps_show(struct device *dev,
109*4882a593Smuzhiyun struct device_attribute *attr,
110*4882a593Smuzhiyun char *buf)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun int n = 0;
113*4882a593Smuzhiyun struct cca_info ci;
114*4882a593Smuzhiyun struct zcrypt_queue *zq = to_ap_queue(dev)->private;
115*4882a593Smuzhiyun static const char * const cao_state[] = { "invalid", "valid" };
116*4882a593Smuzhiyun static const char * const new_state[] = { "empty", "partial", "full" };
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun memset(&ci, 0, sizeof(ci));
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun cca_get_info(AP_QID_CARD(zq->queue->qid),
121*4882a593Smuzhiyun AP_QID_QUEUE(zq->queue->qid),
122*4882a593Smuzhiyun &ci, zq->online);
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun if (ci.new_aes_mk_state >= '1' && ci.new_aes_mk_state <= '3')
125*4882a593Smuzhiyun n = scnprintf(buf, PAGE_SIZE, "AES NEW: %s 0x%016llx\n",
126*4882a593Smuzhiyun new_state[ci.new_aes_mk_state - '1'],
127*4882a593Smuzhiyun ci.new_aes_mkvp);
128*4882a593Smuzhiyun else
129*4882a593Smuzhiyun n = scnprintf(buf, PAGE_SIZE, "AES NEW: - -\n");
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun if (ci.cur_aes_mk_state >= '1' && ci.cur_aes_mk_state <= '2')
132*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n,
133*4882a593Smuzhiyun "AES CUR: %s 0x%016llx\n",
134*4882a593Smuzhiyun cao_state[ci.cur_aes_mk_state - '1'],
135*4882a593Smuzhiyun ci.cur_aes_mkvp);
136*4882a593Smuzhiyun else
137*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "AES CUR: - -\n");
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun if (ci.old_aes_mk_state >= '1' && ci.old_aes_mk_state <= '2')
140*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n,
141*4882a593Smuzhiyun "AES OLD: %s 0x%016llx\n",
142*4882a593Smuzhiyun cao_state[ci.old_aes_mk_state - '1'],
143*4882a593Smuzhiyun ci.old_aes_mkvp);
144*4882a593Smuzhiyun else
145*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "AES OLD: - -\n");
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun if (ci.new_apka_mk_state >= '1' && ci.new_apka_mk_state <= '3')
148*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n,
149*4882a593Smuzhiyun "APKA NEW: %s 0x%016llx\n",
150*4882a593Smuzhiyun new_state[ci.new_apka_mk_state - '1'],
151*4882a593Smuzhiyun ci.new_apka_mkvp);
152*4882a593Smuzhiyun else
153*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "APKA NEW: - -\n");
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun if (ci.cur_apka_mk_state >= '1' && ci.cur_apka_mk_state <= '2')
156*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n,
157*4882a593Smuzhiyun "APKA CUR: %s 0x%016llx\n",
158*4882a593Smuzhiyun cao_state[ci.cur_apka_mk_state - '1'],
159*4882a593Smuzhiyun ci.cur_apka_mkvp);
160*4882a593Smuzhiyun else
161*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "APKA CUR: - -\n");
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun if (ci.old_apka_mk_state >= '1' && ci.old_apka_mk_state <= '2')
164*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n,
165*4882a593Smuzhiyun "APKA OLD: %s 0x%016llx\n",
166*4882a593Smuzhiyun cao_state[ci.old_apka_mk_state - '1'],
167*4882a593Smuzhiyun ci.old_apka_mkvp);
168*4882a593Smuzhiyun else
169*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "APKA OLD: - -\n");
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun return n;
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun static struct device_attribute dev_attr_cca_mkvps =
175*4882a593Smuzhiyun __ATTR(mkvps, 0444, cca_mkvps_show, NULL);
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun static struct attribute *cca_queue_attrs[] = {
178*4882a593Smuzhiyun &dev_attr_cca_mkvps.attr,
179*4882a593Smuzhiyun NULL,
180*4882a593Smuzhiyun };
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun static const struct attribute_group cca_queue_attr_grp = {
183*4882a593Smuzhiyun .attrs = cca_queue_attrs,
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun /*
187*4882a593Smuzhiyun * EP11 card additional device attributes
188*4882a593Smuzhiyun */
ep11_api_ordinalnr_show(struct device * dev,struct device_attribute * attr,char * buf)189*4882a593Smuzhiyun static ssize_t ep11_api_ordinalnr_show(struct device *dev,
190*4882a593Smuzhiyun struct device_attribute *attr,
191*4882a593Smuzhiyun char *buf)
192*4882a593Smuzhiyun {
193*4882a593Smuzhiyun struct ep11_card_info ci;
194*4882a593Smuzhiyun struct ap_card *ac = to_ap_card(dev);
195*4882a593Smuzhiyun struct zcrypt_card *zc = ac->private;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun memset(&ci, 0, sizeof(ci));
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun ep11_get_card_info(ac->id, &ci, zc->online);
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun if (ci.API_ord_nr > 0)
202*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%u\n", ci.API_ord_nr);
203*4882a593Smuzhiyun else
204*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun static struct device_attribute dev_attr_ep11_api_ordinalnr =
208*4882a593Smuzhiyun __ATTR(API_ordinalnr, 0444, ep11_api_ordinalnr_show, NULL);
209*4882a593Smuzhiyun
ep11_fw_version_show(struct device * dev,struct device_attribute * attr,char * buf)210*4882a593Smuzhiyun static ssize_t ep11_fw_version_show(struct device *dev,
211*4882a593Smuzhiyun struct device_attribute *attr,
212*4882a593Smuzhiyun char *buf)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun struct ep11_card_info ci;
215*4882a593Smuzhiyun struct ap_card *ac = to_ap_card(dev);
216*4882a593Smuzhiyun struct zcrypt_card *zc = ac->private;
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun memset(&ci, 0, sizeof(ci));
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun ep11_get_card_info(ac->id, &ci, zc->online);
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun if (ci.FW_version > 0)
223*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%d.%d\n",
224*4882a593Smuzhiyun (int)(ci.FW_version >> 8),
225*4882a593Smuzhiyun (int)(ci.FW_version & 0xFF));
226*4882a593Smuzhiyun else
227*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun static struct device_attribute dev_attr_ep11_fw_version =
231*4882a593Smuzhiyun __ATTR(FW_version, 0444, ep11_fw_version_show, NULL);
232*4882a593Smuzhiyun
ep11_serialnr_show(struct device * dev,struct device_attribute * attr,char * buf)233*4882a593Smuzhiyun static ssize_t ep11_serialnr_show(struct device *dev,
234*4882a593Smuzhiyun struct device_attribute *attr,
235*4882a593Smuzhiyun char *buf)
236*4882a593Smuzhiyun {
237*4882a593Smuzhiyun struct ep11_card_info ci;
238*4882a593Smuzhiyun struct ap_card *ac = to_ap_card(dev);
239*4882a593Smuzhiyun struct zcrypt_card *zc = ac->private;
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun memset(&ci, 0, sizeof(ci));
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun ep11_get_card_info(ac->id, &ci, zc->online);
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun if (ci.serial[0])
246*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%16.16s\n", ci.serial);
247*4882a593Smuzhiyun else
248*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "\n");
249*4882a593Smuzhiyun }
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun static struct device_attribute dev_attr_ep11_serialnr =
252*4882a593Smuzhiyun __ATTR(serialnr, 0444, ep11_serialnr_show, NULL);
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun static const struct {
255*4882a593Smuzhiyun int mode_bit;
256*4882a593Smuzhiyun const char *mode_txt;
257*4882a593Smuzhiyun } ep11_op_modes[] = {
258*4882a593Smuzhiyun { 0, "FIPS2009" },
259*4882a593Smuzhiyun { 1, "BSI2009" },
260*4882a593Smuzhiyun { 2, "FIPS2011" },
261*4882a593Smuzhiyun { 3, "BSI2011" },
262*4882a593Smuzhiyun { 6, "BSICC2017" },
263*4882a593Smuzhiyun { 0, NULL }
264*4882a593Smuzhiyun };
265*4882a593Smuzhiyun
ep11_card_op_modes_show(struct device * dev,struct device_attribute * attr,char * buf)266*4882a593Smuzhiyun static ssize_t ep11_card_op_modes_show(struct device *dev,
267*4882a593Smuzhiyun struct device_attribute *attr,
268*4882a593Smuzhiyun char *buf)
269*4882a593Smuzhiyun {
270*4882a593Smuzhiyun int i, n = 0;
271*4882a593Smuzhiyun struct ep11_card_info ci;
272*4882a593Smuzhiyun struct ap_card *ac = to_ap_card(dev);
273*4882a593Smuzhiyun struct zcrypt_card *zc = ac->private;
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun memset(&ci, 0, sizeof(ci));
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun ep11_get_card_info(ac->id, &ci, zc->online);
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun for (i = 0; ep11_op_modes[i].mode_txt; i++) {
280*4882a593Smuzhiyun if (ci.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
281*4882a593Smuzhiyun if (n > 0)
282*4882a593Smuzhiyun buf[n++] = ' ';
283*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n,
284*4882a593Smuzhiyun "%s", ep11_op_modes[i].mode_txt);
285*4882a593Smuzhiyun }
286*4882a593Smuzhiyun }
287*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun return n;
290*4882a593Smuzhiyun }
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun static struct device_attribute dev_attr_ep11_card_op_modes =
293*4882a593Smuzhiyun __ATTR(op_modes, 0444, ep11_card_op_modes_show, NULL);
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun static struct attribute *ep11_card_attrs[] = {
296*4882a593Smuzhiyun &dev_attr_ep11_api_ordinalnr.attr,
297*4882a593Smuzhiyun &dev_attr_ep11_fw_version.attr,
298*4882a593Smuzhiyun &dev_attr_ep11_serialnr.attr,
299*4882a593Smuzhiyun &dev_attr_ep11_card_op_modes.attr,
300*4882a593Smuzhiyun NULL,
301*4882a593Smuzhiyun };
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun static const struct attribute_group ep11_card_attr_grp = {
304*4882a593Smuzhiyun .attrs = ep11_card_attrs,
305*4882a593Smuzhiyun };
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun /*
308*4882a593Smuzhiyun * EP11 queue additional device attributes
309*4882a593Smuzhiyun */
310*4882a593Smuzhiyun
ep11_mkvps_show(struct device * dev,struct device_attribute * attr,char * buf)311*4882a593Smuzhiyun static ssize_t ep11_mkvps_show(struct device *dev,
312*4882a593Smuzhiyun struct device_attribute *attr,
313*4882a593Smuzhiyun char *buf)
314*4882a593Smuzhiyun {
315*4882a593Smuzhiyun int n = 0;
316*4882a593Smuzhiyun struct ep11_domain_info di;
317*4882a593Smuzhiyun struct zcrypt_queue *zq = to_ap_queue(dev)->private;
318*4882a593Smuzhiyun static const char * const cwk_state[] = { "invalid", "valid" };
319*4882a593Smuzhiyun static const char * const nwk_state[] = { "empty", "uncommitted",
320*4882a593Smuzhiyun "committed" };
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun memset(&di, 0, sizeof(di));
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun if (zq->online)
325*4882a593Smuzhiyun ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
326*4882a593Smuzhiyun AP_QID_QUEUE(zq->queue->qid),
327*4882a593Smuzhiyun &di);
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun if (di.cur_wk_state == '0') {
330*4882a593Smuzhiyun n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s -\n",
331*4882a593Smuzhiyun cwk_state[di.cur_wk_state - '0']);
332*4882a593Smuzhiyun } else if (di.cur_wk_state == '1') {
333*4882a593Smuzhiyun n = scnprintf(buf, PAGE_SIZE, "WK CUR: %s 0x",
334*4882a593Smuzhiyun cwk_state[di.cur_wk_state - '0']);
335*4882a593Smuzhiyun bin2hex(buf + n, di.cur_wkvp, sizeof(di.cur_wkvp));
336*4882a593Smuzhiyun n += 2 * sizeof(di.cur_wkvp);
337*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
338*4882a593Smuzhiyun } else
339*4882a593Smuzhiyun n = scnprintf(buf, PAGE_SIZE, "WK CUR: - -\n");
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun if (di.new_wk_state == '0') {
342*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s -\n",
343*4882a593Smuzhiyun nwk_state[di.new_wk_state - '0']);
344*4882a593Smuzhiyun } else if (di.new_wk_state >= '1' && di.new_wk_state <= '2') {
345*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: %s 0x",
346*4882a593Smuzhiyun nwk_state[di.new_wk_state - '0']);
347*4882a593Smuzhiyun bin2hex(buf + n, di.new_wkvp, sizeof(di.new_wkvp));
348*4882a593Smuzhiyun n += 2 * sizeof(di.new_wkvp);
349*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
350*4882a593Smuzhiyun } else
351*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "WK NEW: - -\n");
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun return n;
354*4882a593Smuzhiyun }
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun static struct device_attribute dev_attr_ep11_mkvps =
357*4882a593Smuzhiyun __ATTR(mkvps, 0444, ep11_mkvps_show, NULL);
358*4882a593Smuzhiyun
ep11_queue_op_modes_show(struct device * dev,struct device_attribute * attr,char * buf)359*4882a593Smuzhiyun static ssize_t ep11_queue_op_modes_show(struct device *dev,
360*4882a593Smuzhiyun struct device_attribute *attr,
361*4882a593Smuzhiyun char *buf)
362*4882a593Smuzhiyun {
363*4882a593Smuzhiyun int i, n = 0;
364*4882a593Smuzhiyun struct ep11_domain_info di;
365*4882a593Smuzhiyun struct zcrypt_queue *zq = to_ap_queue(dev)->private;
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun memset(&di, 0, sizeof(di));
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun if (zq->online)
370*4882a593Smuzhiyun ep11_get_domain_info(AP_QID_CARD(zq->queue->qid),
371*4882a593Smuzhiyun AP_QID_QUEUE(zq->queue->qid),
372*4882a593Smuzhiyun &di);
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun for (i = 0; ep11_op_modes[i].mode_txt; i++) {
375*4882a593Smuzhiyun if (di.op_mode & (1ULL << ep11_op_modes[i].mode_bit)) {
376*4882a593Smuzhiyun if (n > 0)
377*4882a593Smuzhiyun buf[n++] = ' ';
378*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n,
379*4882a593Smuzhiyun "%s", ep11_op_modes[i].mode_txt);
380*4882a593Smuzhiyun }
381*4882a593Smuzhiyun }
382*4882a593Smuzhiyun n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun return n;
385*4882a593Smuzhiyun }
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun static struct device_attribute dev_attr_ep11_queue_op_modes =
388*4882a593Smuzhiyun __ATTR(op_modes, 0444, ep11_queue_op_modes_show, NULL);
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun static struct attribute *ep11_queue_attrs[] = {
391*4882a593Smuzhiyun &dev_attr_ep11_mkvps.attr,
392*4882a593Smuzhiyun &dev_attr_ep11_queue_op_modes.attr,
393*4882a593Smuzhiyun NULL,
394*4882a593Smuzhiyun };
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun static const struct attribute_group ep11_queue_attr_grp = {
397*4882a593Smuzhiyun .attrs = ep11_queue_attrs,
398*4882a593Smuzhiyun };
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun /**
401*4882a593Smuzhiyun * Probe function for CEX4/CEX5/CEX6/CEX7 card device. It always
402*4882a593Smuzhiyun * accepts the AP device since the bus_match already checked
403*4882a593Smuzhiyun * the hardware type.
404*4882a593Smuzhiyun * @ap_dev: pointer to the AP device.
405*4882a593Smuzhiyun */
zcrypt_cex4_card_probe(struct ap_device * ap_dev)406*4882a593Smuzhiyun static int zcrypt_cex4_card_probe(struct ap_device *ap_dev)
407*4882a593Smuzhiyun {
408*4882a593Smuzhiyun /*
409*4882a593Smuzhiyun * Normalized speed ratings per crypto adapter
410*4882a593Smuzhiyun * MEX_1k, MEX_2k, MEX_4k, CRT_1k, CRT_2k, CRT_4k, RNG, SECKEY
411*4882a593Smuzhiyun */
412*4882a593Smuzhiyun static const int CEX4A_SPEED_IDX[NUM_OPS] = {
413*4882a593Smuzhiyun 14, 19, 249, 42, 228, 1458, 0, 0};
414*4882a593Smuzhiyun static const int CEX5A_SPEED_IDX[NUM_OPS] = {
415*4882a593Smuzhiyun 8, 9, 20, 18, 66, 458, 0, 0};
416*4882a593Smuzhiyun static const int CEX6A_SPEED_IDX[NUM_OPS] = {
417*4882a593Smuzhiyun 6, 9, 20, 17, 65, 438, 0, 0};
418*4882a593Smuzhiyun static const int CEX7A_SPEED_IDX[NUM_OPS] = {
419*4882a593Smuzhiyun 6, 8, 17, 15, 54, 362, 0, 0};
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun static const int CEX4C_SPEED_IDX[NUM_OPS] = {
422*4882a593Smuzhiyun 59, 69, 308, 83, 278, 2204, 209, 40};
423*4882a593Smuzhiyun static const int CEX5C_SPEED_IDX[] = {
424*4882a593Smuzhiyun 24, 31, 50, 37, 90, 479, 27, 10};
425*4882a593Smuzhiyun static const int CEX6C_SPEED_IDX[NUM_OPS] = {
426*4882a593Smuzhiyun 16, 20, 32, 27, 77, 455, 24, 9};
427*4882a593Smuzhiyun static const int CEX7C_SPEED_IDX[NUM_OPS] = {
428*4882a593Smuzhiyun 14, 16, 26, 23, 64, 376, 23, 8};
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun static const int CEX4P_SPEED_IDX[NUM_OPS] = {
431*4882a593Smuzhiyun 0, 0, 0, 0, 0, 0, 0, 50};
432*4882a593Smuzhiyun static const int CEX5P_SPEED_IDX[NUM_OPS] = {
433*4882a593Smuzhiyun 0, 0, 0, 0, 0, 0, 0, 10};
434*4882a593Smuzhiyun static const int CEX6P_SPEED_IDX[NUM_OPS] = {
435*4882a593Smuzhiyun 0, 0, 0, 0, 0, 0, 0, 9};
436*4882a593Smuzhiyun static const int CEX7P_SPEED_IDX[NUM_OPS] = {
437*4882a593Smuzhiyun 0, 0, 0, 0, 0, 0, 0, 8};
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun struct ap_card *ac = to_ap_card(&ap_dev->device);
440*4882a593Smuzhiyun struct zcrypt_card *zc;
441*4882a593Smuzhiyun int rc = 0;
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun zc = zcrypt_card_alloc();
444*4882a593Smuzhiyun if (!zc)
445*4882a593Smuzhiyun return -ENOMEM;
446*4882a593Smuzhiyun zc->card = ac;
447*4882a593Smuzhiyun ac->private = zc;
448*4882a593Smuzhiyun if (ap_test_bit(&ac->functions, AP_FUNC_ACCEL)) {
449*4882a593Smuzhiyun if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
450*4882a593Smuzhiyun zc->type_string = "CEX4A";
451*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX4;
452*4882a593Smuzhiyun zc->speed_rating = CEX4A_SPEED_IDX;
453*4882a593Smuzhiyun } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
454*4882a593Smuzhiyun zc->type_string = "CEX5A";
455*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX5;
456*4882a593Smuzhiyun zc->speed_rating = CEX5A_SPEED_IDX;
457*4882a593Smuzhiyun } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
458*4882a593Smuzhiyun zc->type_string = "CEX6A";
459*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX6;
460*4882a593Smuzhiyun zc->speed_rating = CEX6A_SPEED_IDX;
461*4882a593Smuzhiyun } else {
462*4882a593Smuzhiyun zc->type_string = "CEX7A";
463*4882a593Smuzhiyun /* wrong user space type, just for compatibility
464*4882a593Smuzhiyun * with the ZCRYPT_STATUS_MASK ioctl.
465*4882a593Smuzhiyun */
466*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX6;
467*4882a593Smuzhiyun zc->speed_rating = CEX7A_SPEED_IDX;
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun zc->min_mod_size = CEX4A_MIN_MOD_SIZE;
470*4882a593Smuzhiyun if (ap_test_bit(&ac->functions, AP_FUNC_MEX4K) &&
471*4882a593Smuzhiyun ap_test_bit(&ac->functions, AP_FUNC_CRT4K)) {
472*4882a593Smuzhiyun zc->max_mod_size = CEX4A_MAX_MOD_SIZE_4K;
473*4882a593Smuzhiyun zc->max_exp_bit_length =
474*4882a593Smuzhiyun CEX4A_MAX_MOD_SIZE_4K;
475*4882a593Smuzhiyun } else {
476*4882a593Smuzhiyun zc->max_mod_size = CEX4A_MAX_MOD_SIZE_2K;
477*4882a593Smuzhiyun zc->max_exp_bit_length =
478*4882a593Smuzhiyun CEX4A_MAX_MOD_SIZE_2K;
479*4882a593Smuzhiyun }
480*4882a593Smuzhiyun } else if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
481*4882a593Smuzhiyun if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
482*4882a593Smuzhiyun zc->type_string = "CEX4C";
483*4882a593Smuzhiyun /* wrong user space type, must be CEX4
484*4882a593Smuzhiyun * just keep it for cca compatibility
485*4882a593Smuzhiyun */
486*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX3C;
487*4882a593Smuzhiyun zc->speed_rating = CEX4C_SPEED_IDX;
488*4882a593Smuzhiyun } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
489*4882a593Smuzhiyun zc->type_string = "CEX5C";
490*4882a593Smuzhiyun /* wrong user space type, must be CEX5
491*4882a593Smuzhiyun * just keep it for cca compatibility
492*4882a593Smuzhiyun */
493*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX3C;
494*4882a593Smuzhiyun zc->speed_rating = CEX5C_SPEED_IDX;
495*4882a593Smuzhiyun } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
496*4882a593Smuzhiyun zc->type_string = "CEX6C";
497*4882a593Smuzhiyun /* wrong user space type, must be CEX6
498*4882a593Smuzhiyun * just keep it for cca compatibility
499*4882a593Smuzhiyun */
500*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX3C;
501*4882a593Smuzhiyun zc->speed_rating = CEX6C_SPEED_IDX;
502*4882a593Smuzhiyun } else {
503*4882a593Smuzhiyun zc->type_string = "CEX7C";
504*4882a593Smuzhiyun /* wrong user space type, must be CEX7
505*4882a593Smuzhiyun * just keep it for cca compatibility
506*4882a593Smuzhiyun */
507*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX3C;
508*4882a593Smuzhiyun zc->speed_rating = CEX7C_SPEED_IDX;
509*4882a593Smuzhiyun }
510*4882a593Smuzhiyun zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
511*4882a593Smuzhiyun zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
512*4882a593Smuzhiyun zc->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
513*4882a593Smuzhiyun } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
514*4882a593Smuzhiyun if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX4) {
515*4882a593Smuzhiyun zc->type_string = "CEX4P";
516*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX4;
517*4882a593Smuzhiyun zc->speed_rating = CEX4P_SPEED_IDX;
518*4882a593Smuzhiyun } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX5) {
519*4882a593Smuzhiyun zc->type_string = "CEX5P";
520*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX5;
521*4882a593Smuzhiyun zc->speed_rating = CEX5P_SPEED_IDX;
522*4882a593Smuzhiyun } else if (ac->ap_dev.device_type == AP_DEVICE_TYPE_CEX6) {
523*4882a593Smuzhiyun zc->type_string = "CEX6P";
524*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX6;
525*4882a593Smuzhiyun zc->speed_rating = CEX6P_SPEED_IDX;
526*4882a593Smuzhiyun } else {
527*4882a593Smuzhiyun zc->type_string = "CEX7P";
528*4882a593Smuzhiyun /* wrong user space type, just for compatibility
529*4882a593Smuzhiyun * with the ZCRYPT_STATUS_MASK ioctl.
530*4882a593Smuzhiyun */
531*4882a593Smuzhiyun zc->user_space_type = ZCRYPT_CEX6;
532*4882a593Smuzhiyun zc->speed_rating = CEX7P_SPEED_IDX;
533*4882a593Smuzhiyun }
534*4882a593Smuzhiyun zc->min_mod_size = CEX4C_MIN_MOD_SIZE;
535*4882a593Smuzhiyun zc->max_mod_size = CEX4C_MAX_MOD_SIZE;
536*4882a593Smuzhiyun zc->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
537*4882a593Smuzhiyun } else {
538*4882a593Smuzhiyun zcrypt_card_free(zc);
539*4882a593Smuzhiyun return -ENODEV;
540*4882a593Smuzhiyun }
541*4882a593Smuzhiyun zc->online = 1;
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun rc = zcrypt_card_register(zc);
544*4882a593Smuzhiyun if (rc) {
545*4882a593Smuzhiyun ac->private = NULL;
546*4882a593Smuzhiyun zcrypt_card_free(zc);
547*4882a593Smuzhiyun return rc;
548*4882a593Smuzhiyun }
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
551*4882a593Smuzhiyun rc = sysfs_create_group(&ap_dev->device.kobj,
552*4882a593Smuzhiyun &cca_card_attr_grp);
553*4882a593Smuzhiyun if (rc) {
554*4882a593Smuzhiyun zcrypt_card_unregister(zc);
555*4882a593Smuzhiyun ac->private = NULL;
556*4882a593Smuzhiyun zcrypt_card_free(zc);
557*4882a593Smuzhiyun }
558*4882a593Smuzhiyun } else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
559*4882a593Smuzhiyun rc = sysfs_create_group(&ap_dev->device.kobj,
560*4882a593Smuzhiyun &ep11_card_attr_grp);
561*4882a593Smuzhiyun if (rc) {
562*4882a593Smuzhiyun zcrypt_card_unregister(zc);
563*4882a593Smuzhiyun ac->private = NULL;
564*4882a593Smuzhiyun zcrypt_card_free(zc);
565*4882a593Smuzhiyun }
566*4882a593Smuzhiyun }
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun return rc;
569*4882a593Smuzhiyun }
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun /**
572*4882a593Smuzhiyun * This is called to remove the CEX4/CEX5/CEX6/CEX7 card driver
573*4882a593Smuzhiyun * information if an AP card device is removed.
574*4882a593Smuzhiyun */
zcrypt_cex4_card_remove(struct ap_device * ap_dev)575*4882a593Smuzhiyun static void zcrypt_cex4_card_remove(struct ap_device *ap_dev)
576*4882a593Smuzhiyun {
577*4882a593Smuzhiyun struct ap_card *ac = to_ap_card(&ap_dev->device);
578*4882a593Smuzhiyun struct zcrypt_card *zc = ac->private;
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun if (ap_test_bit(&ac->functions, AP_FUNC_COPRO))
581*4882a593Smuzhiyun sysfs_remove_group(&ap_dev->device.kobj, &cca_card_attr_grp);
582*4882a593Smuzhiyun else if (ap_test_bit(&ac->functions, AP_FUNC_EP11))
583*4882a593Smuzhiyun sysfs_remove_group(&ap_dev->device.kobj, &ep11_card_attr_grp);
584*4882a593Smuzhiyun if (zc)
585*4882a593Smuzhiyun zcrypt_card_unregister(zc);
586*4882a593Smuzhiyun }
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun static struct ap_driver zcrypt_cex4_card_driver = {
589*4882a593Smuzhiyun .probe = zcrypt_cex4_card_probe,
590*4882a593Smuzhiyun .remove = zcrypt_cex4_card_remove,
591*4882a593Smuzhiyun .ids = zcrypt_cex4_card_ids,
592*4882a593Smuzhiyun .flags = AP_DRIVER_FLAG_DEFAULT,
593*4882a593Smuzhiyun };
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun /**
596*4882a593Smuzhiyun * Probe function for CEX4/CEX5/CEX6/CEX7 queue device. It always
597*4882a593Smuzhiyun * accepts the AP device since the bus_match already checked
598*4882a593Smuzhiyun * the hardware type.
599*4882a593Smuzhiyun * @ap_dev: pointer to the AP device.
600*4882a593Smuzhiyun */
zcrypt_cex4_queue_probe(struct ap_device * ap_dev)601*4882a593Smuzhiyun static int zcrypt_cex4_queue_probe(struct ap_device *ap_dev)
602*4882a593Smuzhiyun {
603*4882a593Smuzhiyun struct ap_queue *aq = to_ap_queue(&ap_dev->device);
604*4882a593Smuzhiyun struct zcrypt_queue *zq;
605*4882a593Smuzhiyun int rc;
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun if (ap_test_bit(&aq->card->functions, AP_FUNC_ACCEL)) {
608*4882a593Smuzhiyun zq = zcrypt_queue_alloc(CEX4A_MAX_MESSAGE_SIZE);
609*4882a593Smuzhiyun if (!zq)
610*4882a593Smuzhiyun return -ENOMEM;
611*4882a593Smuzhiyun zq->ops = zcrypt_msgtype(MSGTYPE50_NAME,
612*4882a593Smuzhiyun MSGTYPE50_VARIANT_DEFAULT);
613*4882a593Smuzhiyun } else if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
614*4882a593Smuzhiyun zq = zcrypt_queue_alloc(CEX4C_MAX_MESSAGE_SIZE);
615*4882a593Smuzhiyun if (!zq)
616*4882a593Smuzhiyun return -ENOMEM;
617*4882a593Smuzhiyun zq->ops = zcrypt_msgtype(MSGTYPE06_NAME,
618*4882a593Smuzhiyun MSGTYPE06_VARIANT_DEFAULT);
619*4882a593Smuzhiyun } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
620*4882a593Smuzhiyun zq = zcrypt_queue_alloc(CEX4C_MAX_MESSAGE_SIZE);
621*4882a593Smuzhiyun if (!zq)
622*4882a593Smuzhiyun return -ENOMEM;
623*4882a593Smuzhiyun zq->ops = zcrypt_msgtype(MSGTYPE06_NAME,
624*4882a593Smuzhiyun MSGTYPE06_VARIANT_EP11);
625*4882a593Smuzhiyun } else {
626*4882a593Smuzhiyun return -ENODEV;
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun zq->queue = aq;
630*4882a593Smuzhiyun zq->online = 1;
631*4882a593Smuzhiyun atomic_set(&zq->load, 0);
632*4882a593Smuzhiyun ap_queue_init_state(aq);
633*4882a593Smuzhiyun ap_queue_init_reply(aq, &zq->reply);
634*4882a593Smuzhiyun aq->request_timeout = CEX4_CLEANUP_TIME,
635*4882a593Smuzhiyun aq->private = zq;
636*4882a593Smuzhiyun rc = zcrypt_queue_register(zq);
637*4882a593Smuzhiyun if (rc) {
638*4882a593Smuzhiyun aq->private = NULL;
639*4882a593Smuzhiyun zcrypt_queue_free(zq);
640*4882a593Smuzhiyun return rc;
641*4882a593Smuzhiyun }
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
644*4882a593Smuzhiyun rc = sysfs_create_group(&ap_dev->device.kobj,
645*4882a593Smuzhiyun &cca_queue_attr_grp);
646*4882a593Smuzhiyun if (rc) {
647*4882a593Smuzhiyun zcrypt_queue_unregister(zq);
648*4882a593Smuzhiyun aq->private = NULL;
649*4882a593Smuzhiyun zcrypt_queue_free(zq);
650*4882a593Smuzhiyun }
651*4882a593Smuzhiyun } else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
652*4882a593Smuzhiyun rc = sysfs_create_group(&ap_dev->device.kobj,
653*4882a593Smuzhiyun &ep11_queue_attr_grp);
654*4882a593Smuzhiyun if (rc) {
655*4882a593Smuzhiyun zcrypt_queue_unregister(zq);
656*4882a593Smuzhiyun aq->private = NULL;
657*4882a593Smuzhiyun zcrypt_queue_free(zq);
658*4882a593Smuzhiyun }
659*4882a593Smuzhiyun }
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun return rc;
662*4882a593Smuzhiyun }
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun /**
665*4882a593Smuzhiyun * This is called to remove the CEX4/CEX5/CEX6/CEX7 queue driver
666*4882a593Smuzhiyun * information if an AP queue device is removed.
667*4882a593Smuzhiyun */
zcrypt_cex4_queue_remove(struct ap_device * ap_dev)668*4882a593Smuzhiyun static void zcrypt_cex4_queue_remove(struct ap_device *ap_dev)
669*4882a593Smuzhiyun {
670*4882a593Smuzhiyun struct ap_queue *aq = to_ap_queue(&ap_dev->device);
671*4882a593Smuzhiyun struct zcrypt_queue *zq = aq->private;
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO))
674*4882a593Smuzhiyun sysfs_remove_group(&ap_dev->device.kobj, &cca_queue_attr_grp);
675*4882a593Smuzhiyun else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11))
676*4882a593Smuzhiyun sysfs_remove_group(&ap_dev->device.kobj, &ep11_queue_attr_grp);
677*4882a593Smuzhiyun if (zq)
678*4882a593Smuzhiyun zcrypt_queue_unregister(zq);
679*4882a593Smuzhiyun }
680*4882a593Smuzhiyun
681*4882a593Smuzhiyun static struct ap_driver zcrypt_cex4_queue_driver = {
682*4882a593Smuzhiyun .probe = zcrypt_cex4_queue_probe,
683*4882a593Smuzhiyun .remove = zcrypt_cex4_queue_remove,
684*4882a593Smuzhiyun .ids = zcrypt_cex4_queue_ids,
685*4882a593Smuzhiyun .flags = AP_DRIVER_FLAG_DEFAULT,
686*4882a593Smuzhiyun };
687*4882a593Smuzhiyun
zcrypt_cex4_init(void)688*4882a593Smuzhiyun int __init zcrypt_cex4_init(void)
689*4882a593Smuzhiyun {
690*4882a593Smuzhiyun int rc;
691*4882a593Smuzhiyun
692*4882a593Smuzhiyun rc = ap_driver_register(&zcrypt_cex4_card_driver,
693*4882a593Smuzhiyun THIS_MODULE, "cex4card");
694*4882a593Smuzhiyun if (rc)
695*4882a593Smuzhiyun return rc;
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun rc = ap_driver_register(&zcrypt_cex4_queue_driver,
698*4882a593Smuzhiyun THIS_MODULE, "cex4queue");
699*4882a593Smuzhiyun if (rc)
700*4882a593Smuzhiyun ap_driver_unregister(&zcrypt_cex4_card_driver);
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun return rc;
703*4882a593Smuzhiyun }
704*4882a593Smuzhiyun
zcrypt_cex4_exit(void)705*4882a593Smuzhiyun void __exit zcrypt_cex4_exit(void)
706*4882a593Smuzhiyun {
707*4882a593Smuzhiyun ap_driver_unregister(&zcrypt_cex4_queue_driver);
708*4882a593Smuzhiyun ap_driver_unregister(&zcrypt_cex4_card_driver);
709*4882a593Smuzhiyun }
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun module_init(zcrypt_cex4_init);
712*4882a593Smuzhiyun module_exit(zcrypt_cex4_exit);
713