Lines Matching +full:tsn +full:- +full:capable

1 // SPDX-License-Identifier: GPL-2.0
19 #include <uapi/linux/sed-opal.h>
20 #include <linux/sed-opal.h>
21 #include <linux/sed-opal-key.h>
25 #include <linux/key-type.h>
26 #include <keys/user-type.h>
91 u32 tsn; member
286 return -ENOKEY; in update_sed_opal_key()
311 return -ENOKEY; in read_sed_opal_key()
320 down_read(&key->sem); in read_sed_opal_key()
323 if (buflen > key->datalen) in read_sed_opal_key()
324 buflen = key->datalen; in read_sed_opal_key()
326 ret = key->type->read(key, (char *)buffer, buflen); in read_sed_opal_key()
328 up_read(&key->sem); in read_sed_opal_key()
339 switch (key->key_type) { in opal_get_key()
345 ret = read_sed_opal_key(OPAL_AUTH_KEY, key->key, OPAL_KEY_MAX); in opal_get_key()
348 ret = -ENOSPC; in opal_get_key()
351 key->key_len = ret; in opal_get_key()
352 key->key_type = OPAL_INCLUDED; in opal_get_key()
356 ret = -EINVAL; in opal_get_key()
363 if (key->key_type != OPAL_INCLUDED || key->key_len == 0) { in opal_get_key()
364 ret = -EINVAL; in opal_get_key()
376 u8 flags = tper->supported_features; in check_tper()
380 tper->supported_features); in check_tper()
390 u8 sup_feat = lfeat->supported_features; in check_lcksuppt()
398 u8 sup_feat = lfeat->supported_features; in check_lckenabled()
406 u8 sup_feat = lfeat->supported_features; in check_locked()
414 u8 sup_feat = lfeat->supported_features; in check_mbrenabled()
422 u8 sup_feat = lfeat->supported_features; in check_mbrdone()
430 u32 nlo = be32_to_cpu(sum->num_locking_objects); in check_sum()
446 return be16_to_cpu(v100->baseComID); in get_comid_v100()
453 return be16_to_cpu(v200->baseComID); in get_comid_v200()
458 return dev->send_recv(dev->data, dev->comid, TCG_SECP_01, in opal_send_cmd()
459 dev->cmd, IO_BUFFER_LENGTH, in opal_send_cmd()
465 return dev->send_recv(dev->data, dev->comid, TCG_SECP_01, in opal_recv_cmd()
466 dev->resp, IO_BUFFER_LENGTH, in opal_recv_cmd()
473 void *buffer = dev->resp; in opal_recv_check()
479 hdr->cp.outstandingData, in opal_recv_check()
480 hdr->cp.minTransfer); in opal_recv_check()
482 if (hdr->cp.outstandingData == 0 || in opal_recv_check()
483 hdr->cp.minTransfer != 0) in opal_recv_check()
513 dev->align = be64_to_cpu(geo->alignment_granularity); in check_geometry()
514 dev->lowest_lba = be64_to_cpu(geo->lowest_aligned_lba); in check_geometry()
515 dev->logical_block_size = be32_to_cpu(geo->logical_block_size); in check_geometry()
516 dev->align_required = geo->reserved01 & 1; in check_geometry()
522 int error = step->fn(dev, step->data); in execute_step()
526 stepIndex, step->fn, error, in execute_step()
573 const struct d0_header *hdr = (struct d0_header *)dev->resp; in opal_discovery0_end()
574 const u8 *epos = dev->resp, *cpos = dev->resp; in opal_discovery0_end()
576 u32 hlen = be32_to_cpu(hdr->length); in opal_discovery0_end()
578 print_buffer(dev->resp, hlen); in opal_discovery0_end()
579 dev->flags &= OPAL_FL_SUPPORTED; in opal_discovery0_end()
581 if (hlen > IO_BUFFER_LENGTH - sizeof(*hdr)) { in opal_discovery0_end()
584 return -EFAULT; in opal_discovery0_end()
588 buf_out = (u8 __user *)(uintptr_t)discv_out->data; in opal_discovery0_end()
589 len_out = min_t(u64, discv_out->size, hlen); in opal_discovery0_end()
590 if (buf_out && copy_to_user(buf_out, dev->resp, len_out)) in opal_discovery0_end()
591 return -EFAULT; in opal_discovery0_end()
593 discv_out->size = hlen; /* actual size of data */ in opal_discovery0_end()
603 switch (be16_to_cpu(body->code)) { in opal_discovery0_end()
605 supported = check_tper(body->features); in opal_discovery0_end()
608 single_user = check_sum(body->features); in opal_discovery0_end()
610 dev->flags |= OPAL_FL_SUM_SUPPORTED; in opal_discovery0_end()
616 if (check_lcksuppt(body->features)) in opal_discovery0_end()
617 dev->flags |= OPAL_FL_LOCKING_SUPPORTED; in opal_discovery0_end()
618 if (check_lckenabled(body->features)) in opal_discovery0_end()
619 dev->flags |= OPAL_FL_LOCKING_ENABLED; in opal_discovery0_end()
620 if (check_locked(body->features)) in opal_discovery0_end()
621 dev->flags |= OPAL_FL_LOCKED; in opal_discovery0_end()
622 if (check_mbrenabled(body->features)) in opal_discovery0_end()
623 dev->flags |= OPAL_FL_MBR_ENABLED; in opal_discovery0_end()
624 if (check_mbrdone(body->features)) in opal_discovery0_end()
625 dev->flags |= OPAL_FL_MBR_DONE; in opal_discovery0_end()
631 be16_to_cpu(body->code)); in opal_discovery0_end()
634 comid = get_comid_v100(body->features); in opal_discovery0_end()
638 comid = get_comid_v200(body->features); in opal_discovery0_end()
646 be16_to_cpu(body->code)); in opal_discovery0_end()
649 cpos += body->length + 4; in opal_discovery0_end()
654 return -EOPNOTSUPP; in opal_discovery0_end()
663 return -EOPNOTSUPP; in opal_discovery0_end()
666 dev->comid = comid; in opal_discovery0_end()
675 memset(dev->resp, 0, IO_BUFFER_LENGTH); in opal_discovery0()
676 dev->comid = OPAL_DISCOVERY_COMID; in opal_discovery0()
695 return IO_BUFFER_LENGTH - cmd->pos; in remaining_size()
705 *err = -ERANGE; in can_add()
717 cmd->cmd[cmd->pos++] = tok; in add_token_u8()
744 cmd->cmd[cmd->pos++] = header0; in add_medium_atom_header()
745 cmd->cmd[cmd->pos++] = len; in add_medium_atom_header()
766 while (len--) in add_token_u64()
790 return &cmd->cmd[cmd->pos]; in add_bytestring_header()
802 cmd->pos += len; in add_token_bytestring()
809 return -ERANGE; in build_locking_range()
827 return -ERANGE; in build_locking_user()
839 struct opal_header *hdr = (struct opal_header *)cmd->cmd; in set_comid()
841 hdr->cp.extendedComID[0] = comid >> 8; in set_comid()
842 hdr->cp.extendedComID[1] = comid; in set_comid()
843 hdr->cp.extendedComID[2] = 0; in set_comid()
844 hdr->cp.extendedComID[3] = 0; in set_comid()
847 static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn) in cmd_finalize() argument
868 return -EFAULT; in cmd_finalize()
871 hdr = (struct opal_header *) cmd->cmd; in cmd_finalize()
873 hdr->pkt.tsn = cpu_to_be32(tsn); in cmd_finalize()
874 hdr->pkt.hsn = cpu_to_be32(hsn); in cmd_finalize()
876 hdr->subpkt.length = cpu_to_be32(cmd->pos - sizeof(*hdr)); in cmd_finalize()
877 while (cmd->pos % 4) { in cmd_finalize()
878 if (cmd->pos >= IO_BUFFER_LENGTH) { in cmd_finalize()
880 return -ERANGE; in cmd_finalize()
882 cmd->cmd[cmd->pos++] = 0; in cmd_finalize()
884 hdr->pkt.length = cpu_to_be32(cmd->pos - sizeof(hdr->cp) - in cmd_finalize()
885 sizeof(hdr->pkt)); in cmd_finalize()
886 hdr->cp.length = cpu_to_be32(cmd->pos - sizeof(hdr->cp)); in cmd_finalize()
899 return ERR_PTR(-EINVAL); in response_get_token()
902 if (n >= resp->num) { in response_get_token()
904 n, resp->num); in response_get_token()
905 return ERR_PTR(-EINVAL); in response_get_token()
908 tok = &resp->toks[n]; in response_get_token()
909 if (tok->len == 0) { in response_get_token()
910 pr_debug("Token length must be non-zero\n"); in response_get_token()
911 return ERR_PTR(-EINVAL); in response_get_token()
920 tok->pos = pos; in response_parse_tiny()
921 tok->len = 1; in response_parse_tiny()
922 tok->width = OPAL_WIDTH_TINY; in response_parse_tiny()
925 tok->type = OPAL_DTA_TOKENID_SINT; in response_parse_tiny()
927 tok->type = OPAL_DTA_TOKENID_UINT; in response_parse_tiny()
928 tok->stored.u = pos[0] & 0x3f; in response_parse_tiny()
931 return tok->len; in response_parse_tiny()
937 tok->pos = pos; in response_parse_short()
938 tok->len = (pos[0] & SHORT_ATOM_LEN_MASK) + 1; in response_parse_short()
939 tok->width = OPAL_WIDTH_SHORT; in response_parse_short()
942 tok->type = OPAL_DTA_TOKENID_BYTESTRING; in response_parse_short()
944 tok->type = OPAL_DTA_TOKENID_SINT; in response_parse_short()
949 tok->type = OPAL_DTA_TOKENID_UINT; in response_parse_short()
950 if (tok->len > 9) { in response_parse_short()
952 return -EINVAL; in response_parse_short()
954 for (i = tok->len - 1; i > 0; i--) { in response_parse_short()
958 tok->stored.u = u_integer; in response_parse_short()
961 return tok->len; in response_parse_short()
967 tok->pos = pos; in response_parse_medium()
968 tok->len = (((pos[0] & MEDIUM_ATOM_LEN_MASK) << 8) | pos[1]) + 2; in response_parse_medium()
969 tok->width = OPAL_WIDTH_MEDIUM; in response_parse_medium()
972 tok->type = OPAL_DTA_TOKENID_BYTESTRING; in response_parse_medium()
974 tok->type = OPAL_DTA_TOKENID_SINT; in response_parse_medium()
976 tok->type = OPAL_DTA_TOKENID_UINT; in response_parse_medium()
978 return tok->len; in response_parse_medium()
984 tok->pos = pos; in response_parse_long()
985 tok->len = ((pos[1] << 16) | (pos[2] << 8) | pos[3]) + 4; in response_parse_long()
986 tok->width = OPAL_WIDTH_LONG; in response_parse_long()
989 tok->type = OPAL_DTA_TOKENID_BYTESTRING; in response_parse_long()
991 tok->type = OPAL_DTA_TOKENID_SINT; in response_parse_long()
993 tok->type = OPAL_DTA_TOKENID_UINT; in response_parse_long()
995 return tok->len; in response_parse_long()
1001 tok->pos = pos; in response_parse_token()
1002 tok->len = 1; in response_parse_token()
1003 tok->type = OPAL_DTA_TOKENID_TOKEN; in response_parse_token()
1004 tok->width = OPAL_WIDTH_TOKEN; in response_parse_token()
1006 return tok->len; in response_parse_token()
1021 return -EFAULT; in response_parse()
1024 return -EFAULT; in response_parse()
1030 clen = be32_to_cpu(hdr->cp.length); in response_parse()
1031 plen = be32_to_cpu(hdr->pkt.length); in response_parse()
1032 slen = be32_to_cpu(hdr->subpkt.length); in response_parse()
1037 slen > IO_BUFFER_LENGTH - sizeof(*hdr)) { in response_parse()
1041 return -EINVAL; in response_parse()
1045 return -EFAULT; in response_parse()
1047 iter = resp->toks; in response_parse()
1071 total -= token_length; in response_parse()
1075 resp->num = num_entries; in response_parse()
1091 if (tok->type != OPAL_DTA_TOKENID_BYTESTRING) { in response_get_string()
1096 switch (tok->width) { in response_get_string()
1112 *store = tok->pos + skip; in response_get_string()
1114 return tok->len - skip; in response_get_string()
1125 if (tok->type != OPAL_DTA_TOKENID_UINT) { in response_get_u64()
1126 pr_debug("Token is not unsigned int: %d\n", tok->type); in response_get_u64()
1130 if (tok->width != OPAL_WIDTH_TINY && tok->width != OPAL_WIDTH_SHORT) { in response_get_u64()
1131 pr_debug("Atom is not short or tiny: %d\n", tok->width); in response_get_u64()
1135 return tok->stored.u; in response_get_u64()
1141 token->type != OPAL_DTA_TOKENID_TOKEN || in response_token_matches()
1142 token->pos[0] != match) in response_token_matches()
1155 if (resp->num < 5) in response_status()
1158 tok = response_get_token(resp, resp->num - 5); in response_status()
1162 tok = response_get_token(resp, resp->num - 1); in response_status()
1166 return response_get_u64(resp, resp->num - 4); in response_status()
1174 print_buffer(dev->cmd, dev->pos); in parse_and_check_status()
1176 error = response_parse(dev->resp, IO_BUFFER_LENGTH, &dev->parsed); in parse_and_check_status()
1182 return response_status(&dev->parsed); in parse_and_check_status()
1187 dev->pos = sizeof(struct opal_header); in clear_opal_cmd()
1188 memset(dev->cmd, 0, IO_BUFFER_LENGTH); in clear_opal_cmd()
1196 set_comid(dev, dev->comid); in cmd_start()
1214 u32 hsn, tsn; in start_opal_session_cont() local
1221 hsn = response_get_u64(&dev->parsed, 4); in start_opal_session_cont()
1222 tsn = response_get_u64(&dev->parsed, 5); in start_opal_session_cont()
1224 if (hsn != GENERIC_HOST_SESSION_NUM || tsn < FIRST_TPER_SESSION_NUM) { in start_opal_session_cont()
1226 return -EPERM; in start_opal_session_cont()
1229 dev->hsn = hsn; in start_opal_session_cont()
1230 dev->tsn = tsn; in start_opal_session_cont()
1240 list_for_each_entry(iter, &dev->unlk_lst, node) { in add_suspend_info()
1241 if (iter->lr == sus->lr) { in add_suspend_info()
1242 list_del(&iter->node); in add_suspend_info()
1247 list_add_tail(&sus->node, &dev->unlk_lst); in add_suspend_info()
1252 dev->hsn = 0; in end_session_cont()
1253 dev->tsn = 0; in end_session_cont()
1262 ret = cmd_finalize(dev, dev->hsn, dev->tsn); in finalize_and_send()
1268 print_buffer(dev->cmd, dev->pos); in finalize_and_send()
1302 * data will be available in dev->resp->tok[4]
1313 * the result is provided in dev->resp->tok[4]
1321 /* sed-opal UIDs can be split in two halves: in generic_get_table_info()
1338 memcpy(uid, dev->prev_data, min(sizeof(uid), dev->prev_d_len)); in gen_key()
1339 kfree(dev->prev_data); in gen_key()
1340 dev->prev_data = NULL; in gen_key()
1363 keylen = response_get_string(&dev->parsed, 4, &activekey); in get_active_key_cont()
1370 dev->prev_data = kmemdup(activekey, keylen, GFP_KERNEL); in get_active_key_cont()
1372 if (!dev->prev_data) in get_active_key_cont()
1373 return -ENOMEM; in get_active_key_cont()
1375 dev->prev_d_len = keylen; in get_active_key_cont()
1413 len = response_get_u64(&dev->parsed, 4); in generic_table_write_data()
1414 if (size > len || offset > len - size) { in generic_table_write_data()
1417 return -ENOSPC; in generic_table_write_data()
1437 len = min(remaining_size(dev) - (2+1+CMD_FINALIZE_BYTES_NEEDED), in generic_table_write_data()
1438 (size_t)(size - off)); in generic_table_write_data()
1446 err = -EFAULT; in generic_table_write_data()
1450 dev->pos += len; in generic_table_write_data()
1509 err = generic_lr_enable_disable(dev, uid, !!setup->RLE, !!setup->WLE, in enable_global_lr()
1524 lr = setup->session.opal_key.lr; in setup_locking_range()
1540 add_token_u64(&err, dev, setup->range_start); in setup_locking_range()
1545 add_token_u64(&err, dev, setup->range_length); in setup_locking_range()
1550 add_token_u64(&err, dev, !!setup->RLE); in setup_locking_range()
1555 add_token_u64(&err, dev, !!setup->WLE); in setup_locking_range()
1623 lrst->session.opal_key.lr); in locking_range_status()
1631 lrst->session.opal_key.lr, OPAL_RANGESTART, in locking_range_status()
1637 err = response_get_column(&dev->parsed, &tok_n, OPAL_RANGESTART, in locking_range_status()
1638 &lrst->range_start); in locking_range_status()
1643 err = response_get_column(&dev->parsed, &tok_n, OPAL_RANGELENGTH, in locking_range_status()
1644 &lrst->range_length); in locking_range_status()
1649 err = response_get_column(&dev->parsed, &tok_n, OPAL_READLOCKENABLED, in locking_range_status()
1654 lrst->RLE = !!resp; in locking_range_status()
1657 err = response_get_column(&dev->parsed, &tok_n, OPAL_WRITELOCKENABLED, in locking_range_status()
1662 lrst->WLE = !!resp; in locking_range_status()
1665 err = response_get_column(&dev->parsed, &tok_n, OPAL_READLOCKED, &resp); in locking_range_status()
1672 err = response_get_column(&dev->parsed, &tok_n, OPAL_WRITELOCKED, &resp); in locking_range_status()
1679 lrst->l_state = OPAL_RW; in locking_range_status()
1681 lrst->l_state = OPAL_LK; in locking_range_status()
1683 lrst->l_state = OPAL_RO; in locking_range_status()
1686 return -EINVAL; in locking_range_status()
1750 const u8 *key = dev->prev_data; in start_SIDASP_opal_session()
1757 okey->key, in start_SIDASP_opal_session()
1758 okey->key_len); in start_SIDASP_opal_session()
1762 key, dev->prev_d_len); in start_SIDASP_opal_session()
1764 dev->prev_data = NULL; in start_SIDASP_opal_session()
1776 key->key, key->key_len); in start_admin1LSP_opal_session()
1785 okey->key, in start_PSID_opal_session()
1786 okey->key_len); in start_PSID_opal_session()
1793 size_t keylen = session->opal_key.key_len; in start_auth_opal_session()
1796 u8 *key = session->opal_key.key; in start_auth_opal_session()
1799 if (session->sum) in start_auth_opal_session()
1801 session->opal_key.lr); in start_auth_opal_session()
1802 else if (session->who != OPAL_ADMIN1 && !session->sum) in start_auth_opal_session()
1804 session->who - 1); in start_auth_opal_session()
1856 uid[7] = session->who; in internal_activate_user()
1886 add_token_u8(&err, dev, (rev->options & OPAL_PRESERVE) ? in revert_lsp()
1903 if (build_locking_range(uid, sizeof(uid), session->opal_key.lr) < 0) in erase_locking_range()
1904 return -ERANGE; in erase_locking_range()
1972 return generic_table_write_data(dev, shadow->data, shadow->offset, in write_shadow_mbr()
1973 shadow->size, opaluid[OPAL_MBR]); in write_shadow_mbr()
2003 if (usr->who != OPAL_ADMIN1) { in set_new_pw()
2005 if (usr->sum) in set_new_pw()
2006 cpin_uid[7] = usr->opal_key.lr + 1; in set_new_pw()
2008 cpin_uid[7] = usr->who; in set_new_pw()
2011 if (generic_pw_cmd(usr->opal_key.key, usr->opal_key.key_len, in set_new_pw()
2014 return -ERANGE; in set_new_pw()
2027 if (generic_pw_cmd(key->key, key->key_len, cpin_uid, dev)) { in set_sid_cpin_pin()
2029 return -ERANGE; in set_sid_cpin_pin()
2117 lkul->session.who in add_user_to_lr()
2121 lkul->l_state == OPAL_RW ? in add_user_to_lr()
2124 lkul->session.opal_key.lr, users, in add_user_to_lr()
2140 lkul->session.who in add_user_to_lr_ace()
2144 lkul->session.opal_key.lr, users, in add_user_to_lr_ace()
2163 lkul->session.opal_key.lr) < 0) in lock_unlock_locking_range()
2164 return -ERANGE; in lock_unlock_locking_range()
2166 switch (lkul->l_state) { in lock_unlock_locking_range()
2219 set_comid(dev, dev->comid); in lock_unlock_locking_range_sum()
2222 lkul->session.opal_key.lr) < 0) in lock_unlock_locking_range_sum()
2223 return -ERANGE; in lock_unlock_locking_range_sum()
2225 switch (lkul->l_state) { in lock_unlock_locking_range_sum()
2261 if (opal_act->sum) { in activate_lsp()
2263 opal_act->lr[0]); in activate_lsp()
2272 for (i = 1; i < opal_act->num_lrs; i++) { in activate_lsp()
2273 user_lr[7] = opal_act->lr[i]; in activate_lsp()
2299 lc_status = response_get_u64(&dev->parsed, 4); in get_lsp_lifecycle()
2304 return -ENODEV; in get_lsp_lifecycle()
2320 strlen = response_get_string(&dev->parsed, 4, &msid_pin); in get_msid_cpin_pin()
2326 dev->prev_data = kmemdup(msid_pin, strlen, GFP_KERNEL); in get_msid_cpin_pin()
2327 if (!dev->prev_data) in get_msid_cpin_pin()
2328 return -ENOMEM; in get_msid_cpin_pin()
2330 dev->prev_d_len = strlen; in get_msid_cpin_pin()
2339 return generic_table_write_data(dev, write_tbl->data, write_tbl->offset, in write_table_data()
2340 write_tbl->size, write_tbl->table_uid); in write_table_data()
2352 dev->prev_d_len = response_get_string(&dev->parsed, 1, &data_read); in read_table_data_cont()
2353 dev->prev_data = (void *)data_read; in read_table_data_cont()
2354 if (!dev->prev_data) { in read_table_data_cont()
2367 * at a time is : 2048 - (56 + 11) = 1981 = 0x7BD.
2377 u64 offset = read_tbl->offset, read_size = read_tbl->size - 1; in read_table_data()
2380 err = generic_get_table_info(dev, read_tbl->table_uid, OPAL_TABLE_ROWS); in read_table_data()
2386 table_len = response_get_u64(&dev->parsed, 4); in read_table_data()
2389 if (read_size > table_len || offset > table_len - read_size) { in read_table_data()
2392 return -EINVAL; in read_table_data()
2396 err = cmd_start(dev, read_tbl->table_uid, opalmethod[OPAL_GET]); in read_table_data()
2407 len = min(max_read_size, (size_t)(read_size - off)); in read_table_data()
2423 if (dev->prev_d_len > len + 1) { in read_table_data()
2424 err = -EOVERFLOW; in read_table_data()
2428 dst = (u8 __user *)(uintptr_t)read_tbl->data; in read_table_data()
2429 if (copy_to_user(dst + off, dev->prev_data, dev->prev_d_len)) { in read_table_data()
2431 err = -EFAULT; in read_table_data()
2434 dev->prev_data = NULL; in read_table_data()
2447 set_comid(dev, dev->comid); in end_opal_session()
2467 dev->tsn = 0; in setup_opal_dev()
2468 dev->hsn = 0; in setup_opal_dev()
2469 dev->prev_data = NULL; in setup_opal_dev()
2476 mutex_lock(&dev->dev_lock); in check_opal_support()
2480 dev->flags |= OPAL_FL_SUPPORTED; in check_opal_support()
2481 mutex_unlock(&dev->dev_lock); in check_opal_support()
2491 mutex_lock(&dev->dev_lock); in clean_opal_dev()
2492 list_for_each_entry_safe(suspend, next, &dev->unlk_lst, node) { in clean_opal_dev()
2493 list_del(&suspend->node); in clean_opal_dev()
2496 mutex_unlock(&dev->dev_lock); in clean_opal_dev()
2505 kfree(dev->resp); in free_opal_dev()
2506 kfree(dev->cmd); in free_opal_dev()
2520 * Presumably DMA-able buffers must be cache-aligned. Kmalloc makes in init_opal_dev()
2521 * sure the allocated buffer is DMA-safe in that regard. in init_opal_dev()
2523 dev->cmd = kmalloc(IO_BUFFER_LENGTH, GFP_KERNEL); in init_opal_dev()
2524 if (!dev->cmd) in init_opal_dev()
2527 dev->resp = kmalloc(IO_BUFFER_LENGTH, GFP_KERNEL); in init_opal_dev()
2528 if (!dev->resp) in init_opal_dev()
2531 INIT_LIST_HEAD(&dev->unlk_lst); in init_opal_dev()
2532 mutex_init(&dev->dev_lock); in init_opal_dev()
2533 dev->flags = 0; in init_opal_dev()
2534 dev->data = data; in init_opal_dev()
2535 dev->send_recv = send_recv; in init_opal_dev()
2544 kfree(dev->resp); in init_opal_dev()
2547 kfree(dev->cmd); in init_opal_dev()
2561 { get_active_key, &opal_session->opal_key.lr }, in opal_secure_erase_locking_range()
2567 ret = opal_get_key(dev, &opal_session->opal_key); in opal_secure_erase_locking_range()
2570 mutex_lock(&dev->dev_lock); in opal_secure_erase_locking_range()
2573 mutex_unlock(&dev->dev_lock); in opal_secure_erase_locking_range()
2585 mutex_lock(&dev->dev_lock); in opal_get_discv()
2588 mutex_unlock(&dev->dev_lock); in opal_get_discv()
2591 return discv->size; /* modified to actual length of data */ in opal_get_discv()
2598 { start_admin1LSP_opal_session, &rev->key }, in opal_revertlsp()
2603 ret = opal_get_key(dev, &rev->key); in opal_revertlsp()
2606 mutex_lock(&dev->dev_lock); in opal_revertlsp()
2609 mutex_unlock(&dev->dev_lock); in opal_revertlsp()
2624 ret = opal_get_key(dev, &opal_session->opal_key); in opal_erase_locking_range()
2627 mutex_lock(&dev->dev_lock); in opal_erase_locking_range()
2630 mutex_unlock(&dev->dev_lock); in opal_erase_locking_range()
2638 u8 enable_disable = opal_mbr->enable_disable == OPAL_MBR_ENABLE ? in opal_enable_disable_shadow_mbr()
2642 { start_admin1LSP_opal_session, &opal_mbr->key }, in opal_enable_disable_shadow_mbr()
2645 { start_admin1LSP_opal_session, &opal_mbr->key }, in opal_enable_disable_shadow_mbr()
2651 if (opal_mbr->enable_disable != OPAL_MBR_ENABLE && in opal_enable_disable_shadow_mbr()
2652 opal_mbr->enable_disable != OPAL_MBR_DISABLE) in opal_enable_disable_shadow_mbr()
2653 return -EINVAL; in opal_enable_disable_shadow_mbr()
2655 ret = opal_get_key(dev, &opal_mbr->key); in opal_enable_disable_shadow_mbr()
2658 mutex_lock(&dev->dev_lock); in opal_enable_disable_shadow_mbr()
2661 mutex_unlock(&dev->dev_lock); in opal_enable_disable_shadow_mbr()
2669 u8 mbr_done_tf = mbr_done->done_flag == OPAL_MBR_DONE ? in opal_set_mbr_done()
2673 { start_admin1LSP_opal_session, &mbr_done->key }, in opal_set_mbr_done()
2679 if (mbr_done->done_flag != OPAL_MBR_DONE && in opal_set_mbr_done()
2680 mbr_done->done_flag != OPAL_MBR_NOT_DONE) in opal_set_mbr_done()
2681 return -EINVAL; in opal_set_mbr_done()
2683 ret = opal_get_key(dev, &mbr_done->key); in opal_set_mbr_done()
2686 mutex_lock(&dev->dev_lock); in opal_set_mbr_done()
2689 mutex_unlock(&dev->dev_lock); in opal_set_mbr_done()
2698 { start_admin1LSP_opal_session, &info->key }, in opal_write_shadow_mbr()
2704 if (info->size == 0) in opal_write_shadow_mbr()
2707 ret = opal_get_key(dev, &info->key); in opal_write_shadow_mbr()
2710 mutex_lock(&dev->dev_lock); in opal_write_shadow_mbr()
2713 mutex_unlock(&dev->dev_lock); in opal_write_shadow_mbr()
2724 return -ENOMEM; in opal_save()
2726 suspend->unlk = *lk_unlk; in opal_save()
2727 suspend->lr = lk_unlk->session.opal_key.lr; in opal_save()
2729 mutex_lock(&dev->dev_lock); in opal_save()
2732 mutex_unlock(&dev->dev_lock); in opal_save()
2741 { start_admin1LSP_opal_session, &lk_unlk->session.opal_key }, in opal_add_user_to_lr()
2748 if (lk_unlk->l_state != OPAL_RO && in opal_add_user_to_lr()
2749 lk_unlk->l_state != OPAL_RW) { in opal_add_user_to_lr()
2751 return -EINVAL; in opal_add_user_to_lr()
2754 if (lk_unlk->session.who < OPAL_USER1 || in opal_add_user_to_lr()
2755 lk_unlk->session.who > OPAL_USER9) { in opal_add_user_to_lr()
2757 lk_unlk->session.who); in opal_add_user_to_lr()
2758 return -EINVAL; in opal_add_user_to_lr()
2761 if (lk_unlk->session.sum) { in opal_add_user_to_lr()
2764 return -EINVAL; in opal_add_user_to_lr()
2767 ret = opal_get_key(dev, &lk_unlk->session.opal_key); in opal_add_user_to_lr()
2770 mutex_lock(&dev->dev_lock); in opal_add_user_to_lr()
2773 mutex_unlock(&dev->dev_lock); in opal_add_user_to_lr()
2796 mutex_lock(&dev->dev_lock); in opal_reverttper()
2804 mutex_unlock(&dev->dev_lock); in opal_reverttper()
2820 { start_auth_opal_session, &lk_unlk->session }, in __opal_lock_unlock()
2825 { start_auth_opal_session, &lk_unlk->session }, in __opal_lock_unlock()
2830 if (lk_unlk->session.sum) in __opal_lock_unlock()
2855 if (lk_unlk->l_state != OPAL_LK || in opal_lock_check_for_saved_key()
2856 lk_unlk->session.opal_key.key_len > 0) in opal_lock_check_for_saved_key()
2860 * Usually when closing a crypto device (eg: dm-crypt with LUKS) the in opal_lock_check_for_saved_key()
2874 list_for_each_entry(iter, &dev->unlk_lst, node) { in opal_lock_check_for_saved_key()
2875 if ((iter->unlk.flags & OPAL_SAVE_FOR_LOCK) && in opal_lock_check_for_saved_key()
2876 iter->lr == lk_unlk->session.opal_key.lr && in opal_lock_check_for_saved_key()
2877 iter->unlk.session.opal_key.key_len > 0) { in opal_lock_check_for_saved_key()
2878 lk_unlk->session.opal_key.key_len = in opal_lock_check_for_saved_key()
2879 iter->unlk.session.opal_key.key_len; in opal_lock_check_for_saved_key()
2880 memcpy(lk_unlk->session.opal_key.key, in opal_lock_check_for_saved_key()
2881 iter->unlk.session.opal_key.key, in opal_lock_check_for_saved_key()
2882 iter->unlk.session.opal_key.key_len); in opal_lock_check_for_saved_key()
2893 if (lk_unlk->session.who > OPAL_USER9) in opal_lock_unlock()
2894 return -EINVAL; in opal_lock_unlock()
2896 mutex_lock(&dev->dev_lock); in opal_lock_unlock()
2898 ret = opal_get_key(dev, &lk_unlk->session.opal_key); in opal_lock_unlock()
2901 mutex_unlock(&dev->dev_lock); in opal_lock_unlock()
2919 return -ENODEV; in opal_take_ownership()
2924 mutex_lock(&dev->dev_lock); in opal_take_ownership()
2927 mutex_unlock(&dev->dev_lock); in opal_take_ownership()
2936 { start_SIDASP_opal_session, &opal_lr_act->key }, in opal_activate_lsp()
2943 if (!opal_lr_act->num_lrs || opal_lr_act->num_lrs > OPAL_MAX_LRS) in opal_activate_lsp()
2944 return -EINVAL; in opal_activate_lsp()
2946 ret = opal_get_key(dev, &opal_lr_act->key); in opal_activate_lsp()
2949 mutex_lock(&dev->dev_lock); in opal_activate_lsp()
2952 mutex_unlock(&dev->dev_lock); in opal_activate_lsp()
2961 { start_auth_opal_session, &opal_lrs->session }, in opal_setup_locking_range()
2967 ret = opal_get_key(dev, &opal_lrs->session.opal_key); in opal_setup_locking_range()
2970 mutex_lock(&dev->dev_lock); in opal_setup_locking_range()
2973 mutex_unlock(&dev->dev_lock); in opal_setup_locking_range()
2983 { start_auth_opal_session, &opal_lrst->session }, in opal_locking_range_status()
2989 mutex_lock(&dev->dev_lock); in opal_locking_range_status()
2992 mutex_unlock(&dev->dev_lock); in opal_locking_range_status()
2997 sizeof(*opal_lrst) - offsetof(struct opal_lr_status, range_start))) { in opal_locking_range_status()
2999 return -EFAULT; in opal_locking_range_status()
3008 { start_auth_opal_session, &opal_pw->session }, in opal_set_new_pw()
3009 { set_new_pw, &opal_pw->new_user_pw }, in opal_set_new_pw()
3014 if (opal_pw->session.who > OPAL_USER9 || in opal_set_new_pw()
3015 opal_pw->new_user_pw.who > OPAL_USER9) in opal_set_new_pw()
3016 return -EINVAL; in opal_set_new_pw()
3018 mutex_lock(&dev->dev_lock); in opal_set_new_pw()
3021 mutex_unlock(&dev->dev_lock); in opal_set_new_pw()
3028 opal_pw->new_user_pw.opal_key.key, in opal_set_new_pw()
3029 opal_pw->new_user_pw.opal_key.key_len); in opal_set_new_pw()
3030 if (ret != -EOPNOTSUPP) in opal_set_new_pw()
3034 opal_pw->new_user_pw.opal_key.key, in opal_set_new_pw()
3035 opal_pw->new_user_pw.opal_key.key_len); in opal_set_new_pw()
3044 { start_admin1LSP_opal_session, &opal_session->opal_key }, in opal_activate_user()
3051 if (opal_session->who < OPAL_USER1 || in opal_activate_user()
3052 opal_session->who > OPAL_USER9) { in opal_activate_user()
3053 pr_debug("Who was not a valid user: %d\n", opal_session->who); in opal_activate_user()
3054 return -EINVAL; in opal_activate_user()
3057 ret = opal_get_key(dev, &opal_session->opal_key); in opal_activate_user()
3060 mutex_lock(&dev->dev_lock); in opal_activate_user()
3063 mutex_unlock(&dev->dev_lock); in opal_activate_user()
3077 if (!(dev->flags & OPAL_FL_SUPPORTED)) in opal_unlock_from_suspend()
3080 mutex_lock(&dev->dev_lock); in opal_unlock_from_suspend()
3083 list_for_each_entry(suspend, &dev->unlk_lst, node) { in opal_unlock_from_suspend()
3084 dev->tsn = 0; in opal_unlock_from_suspend()
3085 dev->hsn = 0; in opal_unlock_from_suspend()
3087 ret = __opal_lock_unlock(dev, &suspend->unlk); in opal_unlock_from_suspend()
3090 suspend->unlk.session.opal_key.lr, in opal_unlock_from_suspend()
3091 suspend->unlk.session.sum); in opal_unlock_from_suspend()
3095 if (dev->flags & OPAL_FL_MBR_ENABLED) { in opal_unlock_from_suspend()
3096 ret = __opal_set_mbr_done(dev, &suspend->unlk.session.opal_key); in opal_unlock_from_suspend()
3101 mutex_unlock(&dev->dev_lock); in opal_unlock_from_suspend()
3111 { start_admin1LSP_opal_session, &rw_tbl->key }, in opal_read_table()
3116 if (!rw_tbl->size) in opal_read_table()
3127 { start_admin1LSP_opal_session, &rw_tbl->key }, in opal_write_table()
3132 if (!rw_tbl->size) in opal_write_table()
3144 ret = opal_get_key(dev, &rw_tbl->key); in opal_generic_read_write_table()
3147 mutex_lock(&dev->dev_lock); in opal_generic_read_write_table()
3150 bit_set = fls64(rw_tbl->flags) - 1; in opal_generic_read_write_table()
3160 rw_tbl->flags); in opal_generic_read_write_table()
3161 ret = -EINVAL; in opal_generic_read_write_table()
3165 mutex_unlock(&dev->dev_lock); in opal_generic_read_write_table()
3176 * !dev->supported is a valid condition in opal_get_status()
3179 sts.flags = dev->flags; in opal_get_status()
3182 return -EFAULT; in opal_get_status()
3192 return -EINVAL; in opal_get_geometry()
3194 geo.align = dev->align_required; in opal_get_geometry()
3195 geo.logical_block_size = dev->logical_block_size; in opal_get_geometry()
3196 geo.alignment_granularity = dev->align; in opal_get_geometry()
3197 geo.lowest_aligned_lba = dev->lowest_lba; in opal_get_geometry()
3201 return -EFAULT; in opal_get_geometry()
3210 int ret = -ENOTTY; in sed_ioctl()
3212 if (!capable(CAP_SYS_ADMIN)) in sed_ioctl()
3213 return -EACCES; in sed_ioctl()
3215 return -EOPNOTSUPP; in sed_ioctl()
3216 if (!(dev->flags & OPAL_FL_SUPPORTED)) in sed_ioctl()
3217 return -EOPNOTSUPP; in sed_ioctl()
3304 int keylen = OPAL_KEY_MAX - 1; in sed_opal_init()
3319 keylen = OPAL_KEY_MAX - 1; in sed_opal_init()