Christoph Hellwig | a497ee3 | 2019-04-30 14:42:40 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Mike Christie | aa387cc | 2011-07-31 22:05:09 +0200 | [diff] [blame] | 2 | /* |
| 3 | * BSG helper library |
| 4 | * |
| 5 | * Copyright (C) 2008 James Smart, Emulex Corporation |
| 6 | * Copyright (C) 2011 Red Hat, Inc. All rights reserved. |
| 7 | * Copyright (C) 2011 Mike Christie |
Mike Christie | aa387cc | 2011-07-31 22:05:09 +0200 | [diff] [blame] | 8 | */ |
| 9 | #ifndef _BLK_BSG_ |
| 10 | #define _BLK_BSG_ |
| 11 | |
| 12 | #include <linux/blkdev.h> |
Benjamin Block | 50b4d48 | 2017-08-24 01:57:56 +0200 | [diff] [blame] | 13 | #include <scsi/scsi_request.h> |
Mike Christie | aa387cc | 2011-07-31 22:05:09 +0200 | [diff] [blame] | 14 | |
| 15 | struct request; |
| 16 | struct device; |
| 17 | struct scatterlist; |
| 18 | struct request_queue; |
| 19 | |
Jens Axboe | 1028e4b | 2018-10-29 09:47:17 -0600 | [diff] [blame] | 20 | typedef int (bsg_job_fn) (struct bsg_job *); |
| 21 | typedef enum blk_eh_timer_return (bsg_timeout_fn)(struct request *); |
| 22 | |
Mike Christie | aa387cc | 2011-07-31 22:05:09 +0200 | [diff] [blame] | 23 | struct bsg_buffer { |
| 24 | unsigned int payload_len; |
| 25 | int sg_cnt; |
| 26 | struct scatterlist *sg_list; |
| 27 | }; |
| 28 | |
| 29 | struct bsg_job { |
| 30 | struct device *dev; |
Mike Christie | aa387cc | 2011-07-31 22:05:09 +0200 | [diff] [blame] | 31 | |
Johannes Thumshirn | bf0f2d3 | 2016-11-17 10:31:18 +0100 | [diff] [blame] | 32 | struct kref kref; |
| 33 | |
Christoph Hellwig | 31156ec | 2018-03-13 17:28:39 +0100 | [diff] [blame] | 34 | unsigned int timeout; |
| 35 | |
Mike Christie | aa387cc | 2011-07-31 22:05:09 +0200 | [diff] [blame] | 36 | /* Transport/driver specific request/reply structs */ |
| 37 | void *request; |
| 38 | void *reply; |
| 39 | |
| 40 | unsigned int request_len; |
| 41 | unsigned int reply_len; |
| 42 | /* |
| 43 | * On entry : reply_len indicates the buffer size allocated for |
| 44 | * the reply. |
| 45 | * |
| 46 | * Upon completion : the message handler must set reply_len |
| 47 | * to indicates the size of the reply to be returned to the |
| 48 | * caller. |
| 49 | */ |
| 50 | |
| 51 | /* DMA payloads for the request/response */ |
| 52 | struct bsg_buffer request_payload; |
| 53 | struct bsg_buffer reply_payload; |
| 54 | |
Christoph Hellwig | 17cb960 | 2018-03-13 17:28:41 +0100 | [diff] [blame] | 55 | int result; |
| 56 | unsigned int reply_payload_rcv_len; |
| 57 | |
Christoph Hellwig | 972248e | 2019-01-29 09:32:03 +0100 | [diff] [blame] | 58 | /* BIDI support */ |
| 59 | struct request *bidi_rq; |
| 60 | struct bio *bidi_bio; |
| 61 | |
Mike Christie | aa387cc | 2011-07-31 22:05:09 +0200 | [diff] [blame] | 62 | void *dd_data; /* Used for driver-specific storage */ |
| 63 | }; |
| 64 | |
| 65 | void bsg_job_done(struct bsg_job *job, int result, |
| 66 | unsigned int reply_payload_rcv_len); |
Christoph Hellwig | c1225f0 | 2017-08-25 17:37:38 +0200 | [diff] [blame] | 67 | struct request_queue *bsg_setup_queue(struct device *dev, const char *name, |
Jens Axboe | 1028e4b | 2018-10-29 09:47:17 -0600 | [diff] [blame] | 68 | bsg_job_fn *job_fn, bsg_timeout_fn *timeout, int dd_job_size); |
Jens Axboe | 5e28b8d | 2018-10-26 11:27:02 -0600 | [diff] [blame] | 69 | void bsg_remove_queue(struct request_queue *q); |
Johannes Thumshirn | fb6f7c8 | 2016-11-17 10:31:23 +0100 | [diff] [blame] | 70 | void bsg_job_put(struct bsg_job *job); |
| 71 | int __must_check bsg_job_get(struct bsg_job *job); |
Mike Christie | aa387cc | 2011-07-31 22:05:09 +0200 | [diff] [blame] | 72 | |
| 73 | #endif |