Linus Torvalds | ba6d10a | 2019-07-11 15:14:01 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Transport specific attributes. |
| 4 | * |
| 5 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #ifndef SCSI_TRANSPORT_H |
| 8 | #define SCSI_TRANSPORT_H |
| 9 | |
| 10 | #include <linux/transport_class.h> |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 11 | #include <linux/blkdev.h> |
Paul Gortmaker | 187f188 | 2011-11-23 20:12:59 -0500 | [diff] [blame] | 12 | #include <linux/bug.h> |
James Bottomley | c3e9dda | 2005-05-24 16:57:31 -0500 | [diff] [blame] | 13 | #include <scsi/scsi_host.h> |
Rolf Eike Beer | a9b7320 | 2007-02-16 01:46:25 -0800 | [diff] [blame] | 14 | #include <scsi/scsi_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | struct scsi_transport_template { |
| 17 | /* the attribute containers */ |
| 18 | struct transport_container host_attrs; |
| 19 | struct transport_container target_attrs; |
| 20 | struct transport_container device_attrs; |
| 21 | |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 22 | /* |
Christoph Hellwig | e02f3f5 | 2006-01-13 19:04:00 +0100 | [diff] [blame] | 23 | * If set, called from sysfs and legacy procfs rescanning code. |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 24 | */ |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 25 | int (*user_scan)(struct Scsi_Host *, uint, uint, u64); |
James.Smart@Emulex.Com | 5c44cd2 | 2005-06-10 22:24:30 -0400 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | /* The size of the specific transport attribute structure (a |
| 28 | * space of this size will be left at the end of the |
| 29 | * scsi_* structure */ |
| 30 | int device_size; |
James Bottomley | c3e9dda | 2005-05-24 16:57:31 -0500 | [diff] [blame] | 31 | int device_private_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | int target_size; |
James Bottomley | c3e9dda | 2005-05-24 16:57:31 -0500 | [diff] [blame] | 33 | int target_private_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | int host_size; |
James Bottomley | c3e9dda | 2005-05-24 16:57:31 -0500 | [diff] [blame] | 35 | /* no private offset for the host; there's an alternative mechanism */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * True if the transport wants to use a host-based work-queue |
| 39 | */ |
| 40 | unsigned int create_work_queue : 1; |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 41 | |
| 42 | /* |
Christoph Hellwig | 9227c33 | 2006-04-01 19:21:04 +0200 | [diff] [blame] | 43 | * Allows a transport to override the default error handler. |
| 44 | */ |
| 45 | void (* eh_strategy_handler)(struct Scsi_Host *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | #define transport_class_to_shost(tc) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 49 | dev_to_shost((tc)->parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | |
James Bottomley | c3e9dda | 2005-05-24 16:57:31 -0500 | [diff] [blame] | 52 | /* Private area maintenance. The driver requested allocations come |
| 53 | * directly after the transport class allocations (if any). The idea |
| 54 | * is that you *must* call these only once. The code assumes that the |
| 55 | * initial values are the ones the transport specific code requires */ |
| 56 | static inline void |
| 57 | scsi_transport_reserve_target(struct scsi_transport_template * t, int space) |
| 58 | { |
| 59 | BUG_ON(t->target_private_offset != 0); |
| 60 | t->target_private_offset = ALIGN(t->target_size, sizeof(void *)); |
| 61 | t->target_size = t->target_private_offset + space; |
| 62 | } |
| 63 | static inline void |
| 64 | scsi_transport_reserve_device(struct scsi_transport_template * t, int space) |
| 65 | { |
| 66 | BUG_ON(t->device_private_offset != 0); |
| 67 | t->device_private_offset = ALIGN(t->device_size, sizeof(void *)); |
| 68 | t->device_size = t->device_private_offset + space; |
| 69 | } |
| 70 | static inline void * |
| 71 | scsi_transport_target_data(struct scsi_target *starget) |
| 72 | { |
| 73 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); |
| 74 | return (u8 *)starget->starget_data |
| 75 | + shost->transportt->target_private_offset; |
| 76 | |
| 77 | } |
| 78 | static inline void * |
| 79 | scsi_transport_device_data(struct scsi_device *sdev) |
| 80 | { |
| 81 | struct Scsi_Host *shost = sdev->host; |
| 82 | return (u8 *)sdev->sdev_data |
| 83 | + shost->transportt->device_private_offset; |
| 84 | } |
| 85 | |
Christoph Hellwig | d48777a6 | 2017-01-02 21:52:10 +0300 | [diff] [blame] | 86 | void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q); |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif /* SCSI_TRANSPORT_H */ |