-
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: ufs: Add a bsg endpoint that supports UPIUs
For now, just provide an API to allocate and remove ufs-bsg node. We will use this framework to manage ufs devices by sending UPIU transactions. For the time being, implements an empty bsg_request() - will add some more functionality in coming patches. Nonetheless, we reveal here the protocol we are planning to use: UFS Transport Protocol Transactions. UFS transactions consist of packets called UFS Protocol Information Units (UPIU). There are UPIU’s defined for UFS SCSI commands, responses, data in and data out, task management, utility functions, vendor functions, transaction synchronization and control, and more. By using UPIUs, we get access to the most fine-grained internals of this protocol, and able to communicate with the device in ways, that are sometimes beyond the capacity of the ufs driver. Moreover and as a result, our core structure - ufs_bsg_node has a pretty lean structure: using upiu transactions that contains the outmost detailed info, so we don't really need complex constructs to support it. Signed-off-by: Avri Altman <avri.altman@wdc.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <Bart.VanAssche@wdc.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
- Loading branch information
Avri Altman
authored and
Martin K. Petersen
committed
Oct 11, 2018
1 parent
a851b2b
commit df032bf
Showing
8 changed files
with
192 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* bsg endpoint that supports UPIUs | ||
* | ||
* Copyright (C) 2018 Western Digital Corporation | ||
*/ | ||
#include "ufs_bsg.h" | ||
|
||
|
||
static int ufs_bsg_request(struct bsg_job *job) | ||
{ | ||
struct ufs_bsg_request *bsg_request = job->request; | ||
struct ufs_bsg_reply *bsg_reply = job->reply; | ||
int ret = -ENOTSUPP; | ||
|
||
bsg_reply->reply_payload_rcv_len = 0; | ||
|
||
/* Do Nothing for now */ | ||
dev_err(job->dev, "unsupported message_code 0x%x\n", | ||
bsg_request->msgcode); | ||
|
||
bsg_reply->result = ret; | ||
job->reply_len = sizeof(struct ufs_bsg_reply) + | ||
bsg_reply->reply_payload_rcv_len; | ||
|
||
bsg_job_done(job, ret, bsg_reply->reply_payload_rcv_len); | ||
|
||
return ret; | ||
} | ||
|
||
/** | ||
* ufs_bsg_remove - detach and remove the added ufs-bsg node | ||
* | ||
* Should be called when unloading the driver. | ||
*/ | ||
void ufs_bsg_remove(struct ufs_hba *hba) | ||
{ | ||
struct device *bsg_dev = &hba->bsg_dev; | ||
|
||
if (!hba->bsg_queue) | ||
return; | ||
|
||
bsg_unregister_queue(hba->bsg_queue); | ||
|
||
device_del(bsg_dev); | ||
put_device(bsg_dev); | ||
} | ||
|
||
static inline void ufs_bsg_node_release(struct device *dev) | ||
{ | ||
put_device(dev->parent); | ||
} | ||
|
||
/** | ||
* ufs_bsg_probe - Add ufs bsg device node | ||
* @hba: per adapter object | ||
* | ||
* Called during initial loading of the driver, and before scsi_scan_host. | ||
*/ | ||
int ufs_bsg_probe(struct ufs_hba *hba) | ||
{ | ||
struct device *bsg_dev = &hba->bsg_dev; | ||
struct Scsi_Host *shost = hba->host; | ||
struct device *parent = &shost->shost_gendev; | ||
struct request_queue *q; | ||
int ret; | ||
|
||
device_initialize(bsg_dev); | ||
|
||
bsg_dev->parent = get_device(parent); | ||
bsg_dev->release = ufs_bsg_node_release; | ||
|
||
dev_set_name(bsg_dev, "ufs-bsg"); | ||
|
||
ret = device_add(bsg_dev); | ||
if (ret) | ||
goto out; | ||
|
||
q = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), ufs_bsg_request, 0); | ||
if (IS_ERR(q)) { | ||
ret = PTR_ERR(q); | ||
goto out; | ||
} | ||
|
||
hba->bsg_queue = q; | ||
|
||
return 0; | ||
|
||
out: | ||
dev_err(bsg_dev, "fail to initialize a bsg dev %d\n", shost->host_no); | ||
put_device(bsg_dev); | ||
return ret; | ||
} |
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,23 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (C) 2018 Western Digital Corporation | ||
*/ | ||
#ifndef UFS_BSG_H | ||
#define UFS_BSG_H | ||
|
||
#include <linux/bsg-lib.h> | ||
#include <scsi/scsi.h> | ||
#include <scsi/scsi_host.h> | ||
|
||
#include "ufshcd.h" | ||
#include "ufs.h" | ||
|
||
#ifdef CONFIG_SCSI_UFS_BSG | ||
void ufs_bsg_remove(struct ufs_hba *hba); | ||
int ufs_bsg_probe(struct ufs_hba *hba); | ||
#else | ||
static inline void ufs_bsg_remove(struct ufs_hba *hba) {} | ||
static inline int ufs_bsg_probe(struct ufs_hba *hba) {return 0; } | ||
#endif | ||
|
||
#endif /* UFS_BSG_H */ |
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