scsi_transport.h 2.6 KB

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