xref: /openbmc/linux/include/scsi/scsi_transport.h (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
1*ba6d10abSLinus Torvalds /* SPDX-License-Identifier: GPL-2.0-only */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *  Transport specific attributes.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds #ifndef SCSI_TRANSPORT_H
81da177e4SLinus Torvalds #define SCSI_TRANSPORT_H
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds #include <linux/transport_class.h>
11242f9dcbSJens Axboe #include <linux/blkdev.h>
12187f1882SPaul Gortmaker #include <linux/bug.h>
13c3e9dda4SJames Bottomley #include <scsi/scsi_host.h>
14a9b73202SRolf Eike Beer #include <scsi/scsi_device.h>
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds struct scsi_transport_template {
171da177e4SLinus Torvalds 	/* the attribute containers */
181da177e4SLinus Torvalds 	struct transport_container host_attrs;
191da177e4SLinus Torvalds 	struct transport_container target_attrs;
201da177e4SLinus Torvalds 	struct transport_container device_attrs;
211da177e4SLinus Torvalds 
225c44cd2aSJames.Smart@Emulex.Com 	/*
23e02f3f59SChristoph Hellwig 	 * If set, called from sysfs and legacy procfs rescanning code.
245c44cd2aSJames.Smart@Emulex.Com 	 */
259cb78c16SHannes Reinecke 	int (*user_scan)(struct Scsi_Host *, uint, uint, u64);
265c44cd2aSJames.Smart@Emulex.Com 
271da177e4SLinus Torvalds 	/* The size of the specific transport attribute structure (a
281da177e4SLinus Torvalds 	 * space of this size will be left at the end of the
291da177e4SLinus Torvalds 	 * scsi_* structure */
301da177e4SLinus Torvalds 	int	device_size;
31c3e9dda4SJames Bottomley 	int	device_private_offset;
321da177e4SLinus Torvalds 	int	target_size;
33c3e9dda4SJames Bottomley 	int	target_private_offset;
341da177e4SLinus Torvalds 	int	host_size;
35c3e9dda4SJames Bottomley 	/* no private offset for the host; there's an alternative mechanism */
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds 	/*
381da177e4SLinus Torvalds 	 * True if the transport wants to use a host-based work-queue
391da177e4SLinus Torvalds 	 */
401da177e4SLinus Torvalds 	unsigned int create_work_queue : 1;
41c829c394SJames Smart 
42c829c394SJames Smart 	/*
439227c33dSChristoph Hellwig 	 * Allows a transport to override the default error handler.
449227c33dSChristoph Hellwig 	 */
459227c33dSChristoph Hellwig 	void (* eh_strategy_handler)(struct Scsi_Host *);
461da177e4SLinus Torvalds };
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds #define transport_class_to_shost(tc) \
49ee959b00STony Jones 	dev_to_shost((tc)->parent)
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds 
52c3e9dda4SJames Bottomley /* Private area maintenance. The driver requested allocations come
53c3e9dda4SJames Bottomley  * directly after the transport class allocations (if any).  The idea
54c3e9dda4SJames Bottomley  * is that you *must* call these only once.  The code assumes that the
55c3e9dda4SJames Bottomley  * initial values are the ones the transport specific code requires */
56c3e9dda4SJames Bottomley static inline void
scsi_transport_reserve_target(struct scsi_transport_template * t,int space)57c3e9dda4SJames Bottomley scsi_transport_reserve_target(struct scsi_transport_template * t, int space)
58c3e9dda4SJames Bottomley {
59c3e9dda4SJames Bottomley 	BUG_ON(t->target_private_offset != 0);
60c3e9dda4SJames Bottomley 	t->target_private_offset = ALIGN(t->target_size, sizeof(void *));
61c3e9dda4SJames Bottomley 	t->target_size = t->target_private_offset + space;
62c3e9dda4SJames Bottomley }
63c3e9dda4SJames Bottomley static inline void
scsi_transport_reserve_device(struct scsi_transport_template * t,int space)64c3e9dda4SJames Bottomley scsi_transport_reserve_device(struct scsi_transport_template * t, int space)
65c3e9dda4SJames Bottomley {
66c3e9dda4SJames Bottomley 	BUG_ON(t->device_private_offset != 0);
67c3e9dda4SJames Bottomley 	t->device_private_offset = ALIGN(t->device_size, sizeof(void *));
68c3e9dda4SJames Bottomley 	t->device_size = t->device_private_offset + space;
69c3e9dda4SJames Bottomley }
70c3e9dda4SJames Bottomley static inline void *
scsi_transport_target_data(struct scsi_target * starget)71c3e9dda4SJames Bottomley scsi_transport_target_data(struct scsi_target *starget)
72c3e9dda4SJames Bottomley {
73c3e9dda4SJames Bottomley 	struct Scsi_Host *shost = dev_to_shost(&starget->dev);
74c3e9dda4SJames Bottomley 	return (u8 *)starget->starget_data
75c3e9dda4SJames Bottomley 		+ shost->transportt->target_private_offset;
76c3e9dda4SJames Bottomley 
77c3e9dda4SJames Bottomley }
78c3e9dda4SJames Bottomley static inline void *
scsi_transport_device_data(struct scsi_device * sdev)79c3e9dda4SJames Bottomley scsi_transport_device_data(struct scsi_device *sdev)
80c3e9dda4SJames Bottomley {
81c3e9dda4SJames Bottomley 	struct Scsi_Host *shost = sdev->host;
82c3e9dda4SJames Bottomley 	return (u8 *)sdev->sdev_data
83c3e9dda4SJames Bottomley 		+ shost->transportt->device_private_offset;
84c3e9dda4SJames Bottomley }
85c3e9dda4SJames Bottomley 
86d48777a6SChristoph Hellwig void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q);
87d48777a6SChristoph Hellwig 
881da177e4SLinus Torvalds #endif /* SCSI_TRANSPORT_H */
89