blob: a0458bda314872264e283125f64ba19f6ffdc99d [file] [log] [blame]
Linus Torvaldsba6d10a2019-07-11 15:14:01 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Transport specific attributes.
4 *
5 * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#ifndef SCSI_TRANSPORT_H
8#define SCSI_TRANSPORT_H
9
10#include <linux/transport_class.h>
Jens Axboe242f9dc2008-09-14 05:55:09 -070011#include <linux/blkdev.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050012#include <linux/bug.h>
James Bottomleyc3e9dda2005-05-24 16:57:31 -050013#include <scsi/scsi_host.h>
Rolf Eike Beera9b73202007-02-16 01:46:25 -080014#include <scsi/scsi_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16struct 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.Com5c44cd22005-06-10 22:24:30 -040022 /*
Christoph Hellwige02f3f52006-01-13 19:04:00 +010023 * If set, called from sysfs and legacy procfs rescanning code.
James.Smart@Emulex.Com5c44cd22005-06-10 22:24:30 -040024 */
Hannes Reinecke9cb78c12014-06-25 15:27:36 +020025 int (*user_scan)(struct Scsi_Host *, uint, uint, u64);
James.Smart@Emulex.Com5c44cd22005-06-10 22:24:30 -040026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 /* 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 Bottomleyc3e9dda2005-05-24 16:57:31 -050031 int device_private_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 int target_size;
James Bottomleyc3e9dda2005-05-24 16:57:31 -050033 int target_private_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 int host_size;
James Bottomleyc3e9dda2005-05-24 16:57:31 -050035 /* no private offset for the host; there's an alternative mechanism */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 /*
38 * True if the transport wants to use a host-based work-queue
39 */
40 unsigned int create_work_queue : 1;
James Smartc829c392006-03-13 08:28:57 -050041
42 /*
Christoph Hellwig9227c332006-04-01 19:21:04 +020043 * Allows a transport to override the default error handler.
44 */
45 void (* eh_strategy_handler)(struct Scsi_Host *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046};
47
48#define transport_class_to_shost(tc) \
Tony Jonesee959b02008-02-22 00:13:36 +010049 dev_to_shost((tc)->parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51
James Bottomleyc3e9dda2005-05-24 16:57:31 -050052/* 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 */
56static inline void
57scsi_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}
63static inline void
64scsi_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}
70static inline void *
71scsi_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}
78static inline void *
79scsi_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 Hellwigd48777a62017-01-02 21:52:10 +030086void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q);
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#endif /* SCSI_TRANSPORT_H */