^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Transport specific attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef SCSI_TRANSPORT_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define SCSI_TRANSPORT_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/transport_class.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct scsi_transport_template {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* the attribute containers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct transport_container host_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct transport_container target_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct transport_container device_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * If set, called from sysfs and legacy procfs rescanning code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int (*user_scan)(struct Scsi_Host *, uint, uint, u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* The size of the specific transport attribute structure (a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * space of this size will be left at the end of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * scsi_* structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int device_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int device_private_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int target_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int target_private_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int host_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* no private offset for the host; there's an alternative mechanism */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * True if the transport wants to use a host-based work-queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned int create_work_queue : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Allows a transport to override the default error handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) void (* eh_strategy_handler)(struct Scsi_Host *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define transport_class_to_shost(tc) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) dev_to_shost((tc)->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* Private area maintenance. The driver requested allocations come
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * directly after the transport class allocations (if any). The idea
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * is that you *must* call these only once. The code assumes that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * initial values are the ones the transport specific code requires */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) scsi_transport_reserve_target(struct scsi_transport_template * t, int space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) BUG_ON(t->target_private_offset != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) t->target_private_offset = ALIGN(t->target_size, sizeof(void *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) t->target_size = t->target_private_offset + space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) scsi_transport_reserve_device(struct scsi_transport_template * t, int space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) BUG_ON(t->device_private_offset != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) t->device_private_offset = ALIGN(t->device_size, sizeof(void *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) t->device_size = t->device_private_offset + space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static inline void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) scsi_transport_target_data(struct scsi_target *starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct Scsi_Host *shost = dev_to_shost(&starget->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return (u8 *)starget->starget_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) + shost->transportt->target_private_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static inline void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) scsi_transport_device_data(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct Scsi_Host *shost = sdev->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return (u8 *)sdev->sdev_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) + shost->transportt->device_private_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #endif /* SCSI_TRANSPORT_H */