Skip to content

Commit 9fb1072

Browse files
Greg Joyceaxboe
authored andcommitted
block: sed-opal: Implement IOC_OPAL_DISCOVERY
Add IOC_OPAL_DISCOVERY ioctl to return raw discovery data to a SED Opal application. This allows the application to display drive capabilities and state. Signed-off-by: Greg Joyce <gjoyce@linux.vnet.ibm.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jonathan Derrick <jonathan.derrick@linux.dev> Acked-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lore.kernel.org/r/20230721211534.3437070-2-gjoyce@linux.vnet.ibm.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7222657 commit 9fb1072

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

block/sed-opal.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,11 @@ static int execute_steps(struct opal_dev *dev,
463463
return error;
464464
}
465465

466-
static int opal_discovery0_end(struct opal_dev *dev)
466+
static int opal_discovery0_end(struct opal_dev *dev, void *data)
467467
{
468+
struct opal_discovery *discv_out = data; /* may be NULL */
469+
u8 __user *buf_out;
470+
u64 len_out;
468471
bool found_com_id = false, supported = true, single_user = false;
469472
const struct d0_header *hdr = (struct d0_header *)dev->resp;
470473
const u8 *epos = dev->resp, *cpos = dev->resp;
@@ -480,6 +483,15 @@ static int opal_discovery0_end(struct opal_dev *dev)
480483
return -EFAULT;
481484
}
482485

486+
if (discv_out) {
487+
buf_out = (u8 __user *)(uintptr_t)discv_out->data;
488+
len_out = min_t(u64, discv_out->size, hlen);
489+
if (buf_out && copy_to_user(buf_out, dev->resp, len_out))
490+
return -EFAULT;
491+
492+
discv_out->size = hlen; /* actual size of data */
493+
}
494+
483495
epos += hlen; /* end of buffer */
484496
cpos += sizeof(*hdr); /* current position on buffer */
485497

@@ -565,13 +577,13 @@ static int opal_discovery0(struct opal_dev *dev, void *data)
565577
if (ret)
566578
return ret;
567579

568-
return opal_discovery0_end(dev);
580+
return opal_discovery0_end(dev, data);
569581
}
570582

571583
static int opal_discovery0_step(struct opal_dev *dev)
572584
{
573585
const struct opal_step discovery0_step = {
574-
opal_discovery0,
586+
opal_discovery0, NULL
575587
};
576588

577589
return execute_step(dev, &discovery0_step, 0);
@@ -2435,6 +2447,22 @@ static int opal_secure_erase_locking_range(struct opal_dev *dev,
24352447
return ret;
24362448
}
24372449

2450+
static int opal_get_discv(struct opal_dev *dev, struct opal_discovery *discv)
2451+
{
2452+
const struct opal_step discovery0_step = {
2453+
opal_discovery0, discv
2454+
};
2455+
int ret = 0;
2456+
2457+
mutex_lock(&dev->dev_lock);
2458+
setup_opal_dev(dev);
2459+
ret = execute_step(dev, &discovery0_step, 0);
2460+
mutex_unlock(&dev->dev_lock);
2461+
if (ret)
2462+
return ret;
2463+
return discv->size; /* modified to actual length of data */
2464+
}
2465+
24382466
static int opal_erase_locking_range(struct opal_dev *dev,
24392467
struct opal_session_info *opal_session)
24402468
{
@@ -3056,6 +3084,10 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
30563084
case IOC_OPAL_GET_GEOMETRY:
30573085
ret = opal_get_geometry(dev, arg);
30583086
break;
3087+
case IOC_OPAL_DISCOVERY:
3088+
ret = opal_get_discv(dev, p);
3089+
break;
3090+
30593091
default:
30603092
break;
30613093
}

include/linux/sed-opal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
4747
case IOC_OPAL_GET_STATUS:
4848
case IOC_OPAL_GET_LR_STATUS:
4949
case IOC_OPAL_GET_GEOMETRY:
50+
case IOC_OPAL_DISCOVERY:
5051
return true;
5152
}
5253
return false;

include/uapi/linux/sed-opal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ struct opal_geometry {
173173
__u8 __align[3];
174174
};
175175

176+
struct opal_discovery {
177+
__u64 data;
178+
__u64 size;
179+
};
180+
176181
#define IOC_OPAL_SAVE _IOW('p', 220, struct opal_lock_unlock)
177182
#define IOC_OPAL_LOCK_UNLOCK _IOW('p', 221, struct opal_lock_unlock)
178183
#define IOC_OPAL_TAKE_OWNERSHIP _IOW('p', 222, struct opal_key)
@@ -192,5 +197,6 @@ struct opal_geometry {
192197
#define IOC_OPAL_GET_STATUS _IOR('p', 236, struct opal_status)
193198
#define IOC_OPAL_GET_LR_STATUS _IOW('p', 237, struct opal_lr_status)
194199
#define IOC_OPAL_GET_GEOMETRY _IOR('p', 238, struct opal_geometry)
200+
#define IOC_OPAL_DISCOVERY _IOW('p', 239, struct opal_discovery)
195201

196202
#endif /* _UAPI_SED_OPAL_H */

0 commit comments

Comments
 (0)