Lines Matching +full:use +full:- +full:case

1 // SPDX-License-Identifier: GPL-2.0-or-later
10 #include "nx-842.h"
18 #include <asm/opal-api.h>
25 MODULE_ALIAS_CRYPTO("842-nx");
56 * where the process is executing. Use with VAS function.
76 * setup_indirect_dde - Setup an indirect DDE
85 dde->flags = 0; in setup_indirect_dde()
86 dde->count = dde_count; in setup_indirect_dde()
87 dde->index = 0; in setup_indirect_dde()
88 dde->length = cpu_to_be32(byte_count); in setup_indirect_dde()
89 dde->address = cpu_to_be64(nx842_get_pa(ddl)); in setup_indirect_dde()
93 * setup_direct_dde - Setup single DDE from buffer
105 dde->flags = 0; in setup_direct_dde()
106 dde->count = 0; in setup_direct_dde()
107 dde->index = 0; in setup_direct_dde()
108 dde->length = cpu_to_be32(l); in setup_direct_dde()
109 dde->address = cpu_to_be64(pa); in setup_direct_dde()
115 * setup_ddl - Setup DDL from buffer
129 pr_debug("%s buffer pa 0x%lx not 0x%x-byte aligned\n", in setup_ddl()
131 return -EINVAL; in setup_ddl()
136 * DDE_BUFFER_SIZE_MULT, and pre-last page DDE buffers in setup_ddl()
143 return -EINVAL; in setup_ddl()
147 /* use a single direct DDE */ in setup_ddl()
154 /* use the DDL */ in setup_ddl()
158 len -= ret; in setup_ddl()
166 return -EMSGSIZE; in setup_ddl()
167 total_len -= len; in setup_ddl()
176 ##__VA_ARGS__, (csb)->flags, \
177 (csb)->cs, (csb)->cc, (csb)->ce, \
178 be32_to_cpu((csb)->count))
182 (unsigned long)be64_to_cpu((csb)->address))
190 ktime_t start = wmem->start, now = ktime_get(); in wait_for_csb()
193 while (!(READ_ONCE(csb->flags) & CSB_V)) { in wait_for_csb()
204 if (!(csb->flags & CSB_V)) { in wait_for_csb()
207 return -ETIMEDOUT; in wait_for_csb()
209 if (csb->flags & CSB_F) { in wait_for_csb()
211 return -EPROTO; in wait_for_csb()
213 if (csb->flags & CSB_CH) { in wait_for_csb()
215 return -EPROTO; in wait_for_csb()
219 if (csb->cs) { in wait_for_csb()
221 return -EPROTO; in wait_for_csb()
225 switch (csb->cc) { in wait_for_csb()
227 case CSB_CC_SUCCESS: in wait_for_csb()
229 case CSB_CC_TPBC_GT_SPBC: in wait_for_csb()
236 case CSB_CC_OPERAND_OVERLAP: in wait_for_csb()
239 return -EINVAL; in wait_for_csb()
240 case CSB_CC_INVALID_OPERAND: in wait_for_csb()
242 return -EINVAL; in wait_for_csb()
243 case CSB_CC_NOSPC: in wait_for_csb()
245 return -ENOSPC; in wait_for_csb()
246 case CSB_CC_ABORT: in wait_for_csb()
248 return -EINTR; in wait_for_csb()
249 case CSB_CC_CRC_MISMATCH: in wait_for_csb()
251 return -EINVAL; in wait_for_csb()
252 case CSB_CC_TEMPL_INVALID: in wait_for_csb()
254 return -EINVAL; in wait_for_csb()
255 case CSB_CC_TEMPL_OVERFLOW: in wait_for_csb()
257 return -EINVAL; in wait_for_csb()
258 case CSB_CC_EXCEED_BYTE_COUNT: /* P9 or later */ in wait_for_csb()
264 return -EINVAL; in wait_for_csb()
267 case CSB_CC_INVALID_ALIGN: in wait_for_csb()
270 return -EINVAL; in wait_for_csb()
271 case CSB_CC_DATA_LENGTH: in wait_for_csb()
274 return -EINVAL; in wait_for_csb()
275 case CSB_CC_WR_TRANSLATION: in wait_for_csb()
276 case CSB_CC_TRANSLATION: in wait_for_csb()
277 case CSB_CC_TRANSLATION_DUP1: in wait_for_csb()
278 case CSB_CC_TRANSLATION_DUP2: in wait_for_csb()
279 case CSB_CC_TRANSLATION_DUP3: in wait_for_csb()
280 case CSB_CC_TRANSLATION_DUP4: in wait_for_csb()
281 case CSB_CC_TRANSLATION_DUP5: in wait_for_csb()
282 case CSB_CC_TRANSLATION_DUP6: in wait_for_csb()
283 /* should not happen, we use physical addrs */ in wait_for_csb()
285 return -EPROTO; in wait_for_csb()
286 case CSB_CC_WR_PROTECTION: in wait_for_csb()
287 case CSB_CC_PROTECTION: in wait_for_csb()
288 case CSB_CC_PROTECTION_DUP1: in wait_for_csb()
289 case CSB_CC_PROTECTION_DUP2: in wait_for_csb()
290 case CSB_CC_PROTECTION_DUP3: in wait_for_csb()
291 case CSB_CC_PROTECTION_DUP4: in wait_for_csb()
292 case CSB_CC_PROTECTION_DUP5: in wait_for_csb()
293 case CSB_CC_PROTECTION_DUP6: in wait_for_csb()
294 /* should not happen, we use physical addrs */ in wait_for_csb()
296 return -EPROTO; in wait_for_csb()
297 case CSB_CC_PRIVILEGE: in wait_for_csb()
300 return -EPROTO; in wait_for_csb()
301 case CSB_CC_EXCESSIVE_DDE: in wait_for_csb()
302 /* shouldn't happen, setup_ddl doesn't use many dde's */ in wait_for_csb()
304 return -EINVAL; in wait_for_csb()
305 case CSB_CC_TRANSPORT: in wait_for_csb()
306 case CSB_CC_INVALID_CRB: /* P9 or later */ in wait_for_csb()
309 return -EINVAL; in wait_for_csb()
310 case CSB_CC_INVALID_DDE: /* P9 or later */ in wait_for_csb()
316 return -EINVAL; in wait_for_csb()
317 case CSB_CC_SEGMENTED_DDL: in wait_for_csb()
320 return -EINVAL; in wait_for_csb()
321 case CSB_CC_DDE_OVERFLOW: in wait_for_csb()
324 return -EINVAL; in wait_for_csb()
325 case CSB_CC_SESSION: in wait_for_csb()
328 return -EPROTO; in wait_for_csb()
329 case CSB_CC_CHAIN: in wait_for_csb()
330 /* should not happen, we don't use chained CRBs */ in wait_for_csb()
332 return -EPROTO; in wait_for_csb()
333 case CSB_CC_SEQUENCE: in wait_for_csb()
334 /* should not happen, we don't use chained CRBs */ in wait_for_csb()
336 return -EPROTO; in wait_for_csb()
337 case CSB_CC_UNKNOWN_CODE: in wait_for_csb()
339 return -EPROTO; in wait_for_csb()
342 case CSB_CC_RD_EXTERNAL: in wait_for_csb()
343 case CSB_CC_RD_EXTERNAL_DUP1: in wait_for_csb()
344 case CSB_CC_RD_EXTERNAL_DUP2: in wait_for_csb()
345 case CSB_CC_RD_EXTERNAL_DUP3: in wait_for_csb()
347 return -EPROTO; in wait_for_csb()
348 case CSB_CC_WR_EXTERNAL: in wait_for_csb()
350 return -EPROTO; in wait_for_csb()
351 case CSB_CC_INTERNAL: in wait_for_csb()
353 return -EPROTO; in wait_for_csb()
354 case CSB_CC_PROVISION: in wait_for_csb()
356 return -EPROTO; in wait_for_csb()
357 case CSB_CC_HW: in wait_for_csb()
359 return -EPROTO; in wait_for_csb()
360 case CSB_CC_HW_EXPIRED_TIMER: /* P9 or later */ in wait_for_csb()
362 return -EPROTO; in wait_for_csb()
365 CSB_ERR(csb, "Invalid CC %d", csb->cc); in wait_for_csb()
366 return -EPROTO; in wait_for_csb()
370 if (csb->ce & CSB_CE_TERMINATION) { in wait_for_csb()
372 return -EPROTO; in wait_for_csb()
374 if (csb->ce & CSB_CE_INCOMPLETE) { in wait_for_csb()
376 return -EPROTO; in wait_for_csb()
378 if (!(csb->ce & CSB_CE_TPBC)) { in wait_for_csb()
380 return -EPROTO; in wait_for_csb()
385 be32_to_cpu(csb->count), in wait_for_csb()
400 crb = &wmem->crb; in nx842_config_crb()
401 csb = &crb->csb; in nx842_config_crb()
407 ret = setup_ddl(&crb->source, wmem->ddl_in, in nx842_config_crb()
412 ret = setup_ddl(&crb->target, wmem->ddl_out, in nx842_config_crb()
420 crb->csb_addr = cpu_to_be64(csb_addr); in nx842_config_crb()
426 * nx842_exec_icswx - compress/decompress data using the 842 algorithm
444 * @fc: function code, see CCW Function Codes in nx-842.h
448 * -ENODEV Hardware unavailable
449 * -ENOSPC Output buffer is to small
450 * -EMSGSIZE Input buffer too large
451 * -EINVAL buffer constraints do not fix nx842_constraints
452 * -EPROTO hardware error during operation
453 * -ETIMEDOUT hardware did not complete operation in reasonable time
454 * -EINTR operation was aborted
474 return -ENODEV; in nx842_exec_icswx()
481 crb = &wmem->crb; in nx842_exec_icswx()
482 csb = &crb->csb; in nx842_exec_icswx()
487 ccw = SET_FIELD(CCW_CI_842, ccw, 0); /* use 0 for hw auto-selection */ in nx842_exec_icswx()
490 wmem->start = ktime_get(); in nx842_exec_icswx()
495 pr_debug_ratelimited("icswx CR %x ccw %x crb->ccw %x\n", ret, in nx842_exec_icswx()
497 (unsigned int)be32_to_cpu(crb->ccw)); in nx842_exec_icswx()
508 case ICSWX_INITIATED: in nx842_exec_icswx()
511 case ICSWX_BUSY: in nx842_exec_icswx()
513 ret = -EBUSY; in nx842_exec_icswx()
515 case ICSWX_REJECTED: in nx842_exec_icswx()
517 ret = -EPROTO; in nx842_exec_icswx()
522 *outlenp = be32_to_cpu(csb->count); in nx842_exec_icswx()
528 * nx842_exec_vas - compress/decompress data using the 842 algorithm
546 * @fc: function code, see CCW Function Codes in nx-842.h
551 * -ENODEV Hardware unavailable
552 * -ENOSPC Output buffer is to small
553 * -EMSGSIZE Input buffer too large
554 * -EINVAL buffer constraints do not fix nx842_constraints
555 * -EPROTO hardware error during operation
556 * -ETIMEDOUT hardware did not complete operation in reasonable time
557 * -EINTR operation was aborted
575 crb = &wmem->crb; in nx842_exec_vas()
576 csb = &crb->csb; in nx842_exec_vas()
584 crb->ccw = cpu_to_be32(ccw); in nx842_exec_vas()
587 wmem->start = ktime_get(); in nx842_exec_vas()
615 *outlenp = be32_to_cpu(csb->count); in nx842_exec_vas()
621 * nx842_powernv_compress - Compress data using the 842 algorithm
649 * nx842_powernv_decompress - Decompress data using the 842 algorithm
679 coproc->chip_id = chipid; in nx_add_coprocs_list()
680 INIT_LIST_HEAD(&coproc->list); in nx_add_coprocs_list()
681 list_add(&coproc->list, &nx_coprocs); in nx_add_coprocs_list()
693 vas_init_tx_win_attr(&txattr, coproc->ct); in nx_alloc_txwin()
699 txwin = vas_tx_win_open(coproc->vas.id, coproc->ct, &txattr); in nx_alloc_txwin()
701 pr_err("ibm,nx-842: Can not open TX window: %ld\n", in nx_alloc_txwin()
725 * Kernel requests use only high priority FIFOs. So in nx_open_percpu_txwins()
730 if (coproc->ct != VAS_COP_TYPE_842_HIPRI) in nx_open_percpu_txwins()
733 if (coproc->chip_id == chip_id) { in nx_open_percpu_txwins()
746 return -EINVAL; in nx_open_percpu_txwins()
757 coproc->ct = high; in nx_set_ct()
759 coproc->ct = normal; in nx_set_ct()
762 return -EINVAL; in nx_set_ct()
779 ret = of_property_read_u64(dn, "rx-fifo-address", &rx_fifo); in vas_cfg_coproc_info()
781 pr_err("Missing rx-fifo-address property\n"); in vas_cfg_coproc_info()
785 ret = of_property_read_u32(dn, "rx-fifo-size", &fifo_size); in vas_cfg_coproc_info()
787 pr_err("Missing rx-fifo-size property\n"); in vas_cfg_coproc_info()
817 return -ENOMEM; in vas_cfg_coproc_info()
829 vas_init_rx_win_attr(&rxattr, coproc->ct); in vas_cfg_coproc_info()
845 rxwin = vas_rx_win_open(vasid, coproc->ct, &rxattr); in vas_cfg_coproc_info()
853 coproc->vas.rxwin = rxwin; in vas_cfg_coproc_info()
854 coproc->vas.id = vasid; in vas_cfg_coproc_info()
862 * device-tree property. in vas_cfg_coproc_info()
917 pr_err("ibm,chip-id missing\n"); in nx_powernv_probe_vas()
918 return -EINVAL; in nx_powernv_probe_vas()
924 return -EINVAL; in nx_powernv_probe_vas()
929 "ibm,p9-nx-842", &ct_842); in nx_powernv_probe_vas()
933 NX_CT_GZIP, "ibm,p9-nx-gzip", &ct_gzip); in nx_powernv_probe_vas()
941 return -EINVAL; in nx_powernv_probe_vas()
960 pr_err("ibm,chip-id missing\n"); in nx842_powernv_probe()
961 return -EINVAL; in nx842_powernv_probe()
964 if (of_property_read_u32(dn, "ibm,842-coprocessor-type", &ct)) { in nx842_powernv_probe()
965 pr_err("ibm,842-coprocessor-type missing\n"); in nx842_powernv_probe()
966 return -EINVAL; in nx842_powernv_probe()
969 if (of_property_read_u32(dn, "ibm,842-coprocessor-instance", &ci)) { in nx842_powernv_probe()
970 pr_err("ibm,842-coprocessor-instance missing\n"); in nx842_powernv_probe()
971 return -EINVAL; in nx842_powernv_probe()
976 return -ENOMEM; in nx842_powernv_probe()
978 coproc->ct = ct; in nx842_powernv_probe()
979 coproc->ci = ci; in nx842_powernv_probe()
1011 if (coproc->vas.rxwin) in nx_delete_coprocs()
1012 vas_win_close(coproc->vas.rxwin); in nx_delete_coprocs()
1014 list_del(&coproc->list); in nx_delete_coprocs()
1023 .maximum = (DDL_LEN_MAX - 1) * PAGE_SIZE,
1042 .cra_driver_name = "842-nx",
1068 for_each_compatible_node(dn, NULL, "ibm,power9-nx") { in nx_compress_powernv_init()
1078 for_each_compatible_node(dn, NULL, "ibm,power-nx") in nx_compress_powernv_init()
1082 return -ENODEV; in nx_compress_powernv_init()
1088 * that user space can use GZIP engine. in nx_compress_powernv_init()
1094 "nx-gzip"); in nx_compress_powernv_init()
1127 * use. So delete this API use for GZIP engine. in nx_compress_powernv_exit()