1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright © 2016 Intel Corporation 4 * 5 * Authors: 6 * Rafael Antognolli <rafael.antognolli@intel.com> 7 * Scott Bauer <scott.bauer@intel.com> 8 */ 9 10 #ifndef LINUX_OPAL_H 11 #define LINUX_OPAL_H 12 13 #include <uapi/linux/sed-opal.h> 14 #include <linux/compiler_types.h> 15 #include <linux/types.h> 16 17 struct opal_dev; 18 19 typedef int (sec_send_recv)(void *data, u16 spsp, u8 secp, void *buffer, 20 size_t len, bool send); 21 22 #ifdef CONFIG_BLK_SED_OPAL 23 void free_opal_dev(struct opal_dev *dev); 24 bool opal_unlock_from_suspend(struct opal_dev *dev); 25 struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv); 26 int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *ioctl_ptr); 27 28 static inline bool is_sed_ioctl(unsigned int cmd) 29 { 30 switch (cmd) { 31 case IOC_OPAL_SAVE: 32 case IOC_OPAL_LOCK_UNLOCK: 33 case IOC_OPAL_TAKE_OWNERSHIP: 34 case IOC_OPAL_ACTIVATE_LSP: 35 case IOC_OPAL_SET_PW: 36 case IOC_OPAL_ACTIVATE_USR: 37 case IOC_OPAL_REVERT_TPR: 38 case IOC_OPAL_LR_SETUP: 39 case IOC_OPAL_ADD_USR_TO_LR: 40 case IOC_OPAL_ENABLE_DISABLE_MBR: 41 case IOC_OPAL_ERASE_LR: 42 case IOC_OPAL_SECURE_ERASE_LR: 43 case IOC_OPAL_PSID_REVERT_TPR: 44 case IOC_OPAL_MBR_DONE: 45 case IOC_OPAL_WRITE_SHADOW_MBR: 46 case IOC_OPAL_GENERIC_TABLE_RW: 47 case IOC_OPAL_GET_STATUS: 48 case IOC_OPAL_GET_LR_STATUS: 49 case IOC_OPAL_GET_GEOMETRY: 50 return true; 51 } 52 return false; 53 } 54 #else 55 static inline void free_opal_dev(struct opal_dev *dev) 56 { 57 } 58 59 static inline bool is_sed_ioctl(unsigned int cmd) 60 { 61 return false; 62 } 63 64 static inline int sed_ioctl(struct opal_dev *dev, unsigned int cmd, 65 void __user *ioctl_ptr) 66 { 67 return 0; 68 } 69 static inline bool opal_unlock_from_suspend(struct opal_dev *dev) 70 { 71 return false; 72 } 73 #define init_opal_dev(data, send_recv) NULL 74 #endif /* CONFIG_BLK_SED_OPAL */ 75 #endif /* LINUX_OPAL_H */ 76