forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scsi: bsg: Move bsg_scsi_ops to drivers/scsi/
Move the SCSI-specific bsg code in the SCSI midlayer instead of in the common bsg code. This just keeps the common bsg code block/ and also allows building it as a module. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
- Loading branch information
1 parent
d52fe8f
commit 7801104
Showing
10 changed files
with
129 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/bsg.h> | ||
#include <scsi/scsi.h> | ||
#include <scsi/scsi_ioctl.h> | ||
#include <scsi/scsi_cmnd.h> | ||
#include <scsi/scsi_device.h> | ||
#include <scsi/sg.h> | ||
#include "scsi_priv.h" | ||
|
||
#define uptr64(val) ((void __user *)(uintptr_t)(val)) | ||
|
||
static int scsi_bsg_check_proto(struct sg_io_v4 *hdr) | ||
{ | ||
if (hdr->protocol != BSG_PROTOCOL_SCSI || | ||
hdr->subprotocol != BSG_SUB_PROTOCOL_SCSI_CMD) | ||
return -EINVAL; | ||
return 0; | ||
} | ||
|
||
static int scsi_bsg_fill_hdr(struct request *rq, struct sg_io_v4 *hdr, | ||
fmode_t mode) | ||
{ | ||
struct scsi_request *sreq = scsi_req(rq); | ||
|
||
if (hdr->dout_xfer_len && hdr->din_xfer_len) { | ||
pr_warn_once("BIDI support in bsg has been removed.\n"); | ||
return -EOPNOTSUPP; | ||
} | ||
|
||
sreq->cmd_len = hdr->request_len; | ||
if (sreq->cmd_len > BLK_MAX_CDB) { | ||
sreq->cmd = kzalloc(sreq->cmd_len, GFP_KERNEL); | ||
if (!sreq->cmd) | ||
return -ENOMEM; | ||
} | ||
|
||
if (copy_from_user(sreq->cmd, uptr64(hdr->request), sreq->cmd_len)) | ||
return -EFAULT; | ||
if (blk_verify_command(sreq->cmd, mode)) | ||
return -EPERM; | ||
return 0; | ||
} | ||
|
||
static int scsi_bsg_complete_rq(struct request *rq, struct sg_io_v4 *hdr) | ||
{ | ||
struct scsi_request *sreq = scsi_req(rq); | ||
int ret = 0; | ||
|
||
/* | ||
* fill in all the output members | ||
*/ | ||
hdr->device_status = sreq->result & 0xff; | ||
hdr->transport_status = host_byte(sreq->result); | ||
hdr->driver_status = 0; | ||
if (scsi_status_is_check_condition(sreq->result)) | ||
hdr->driver_status = DRIVER_SENSE; | ||
hdr->info = 0; | ||
if (hdr->device_status || hdr->transport_status || hdr->driver_status) | ||
hdr->info |= SG_INFO_CHECK; | ||
hdr->response_len = 0; | ||
|
||
if (sreq->sense_len && hdr->response) { | ||
int len = min_t(unsigned int, hdr->max_response_len, | ||
sreq->sense_len); | ||
|
||
if (copy_to_user(uptr64(hdr->response), sreq->sense, len)) | ||
ret = -EFAULT; | ||
else | ||
hdr->response_len = len; | ||
} | ||
|
||
if (rq_data_dir(rq) == READ) | ||
hdr->din_resid = sreq->resid_len; | ||
else | ||
hdr->dout_resid = sreq->resid_len; | ||
|
||
return ret; | ||
} | ||
|
||
static void scsi_bsg_free_rq(struct request *rq) | ||
{ | ||
scsi_req_free_cmd(scsi_req(rq)); | ||
} | ||
|
||
static const struct bsg_ops scsi_bsg_ops = { | ||
.check_proto = scsi_bsg_check_proto, | ||
.fill_hdr = scsi_bsg_fill_hdr, | ||
.complete_rq = scsi_bsg_complete_rq, | ||
.free_rq = scsi_bsg_free_rq, | ||
}; | ||
|
||
int scsi_bsg_register_queue(struct request_queue *q, struct device *parent) | ||
{ | ||
return bsg_register_queue(q, parent, dev_name(parent), &scsi_bsg_ops); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters