ReactOS  0.4.15-dev-1374-g8d3e80e
pdo.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Storage Stack / SCSIPORT storage port library
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Logical Unit (PDO) functions
5  * COPYRIGHT: Eric Kohl (eric.kohl@reactos.org)
6  * Aleksey Bragin (aleksey@reactos.org)
7  */
8 
9 #include "scsiport.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 
17  _In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
18 {
19  PSCSI_PORT_LUN_EXTENSION LunExtension;
20  ULONG LunExtensionSize;
21 
22  DPRINT("SpiAllocateLunExtension(%p)\n", DeviceExtension);
23 
24  /* Round LunExtensionSize first to the sizeof LONGLONG */
25  LunExtensionSize = (DeviceExtension->LunExtensionSize +
26  sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1);
27 
28  LunExtensionSize += sizeof(SCSI_PORT_LUN_EXTENSION);
29  DPRINT("LunExtensionSize %lu\n", LunExtensionSize);
30 
31  LunExtension = ExAllocatePoolWithTag(NonPagedPool, LunExtensionSize, TAG_SCSIPORT);
32  if (LunExtension == NULL)
33  {
34  DPRINT1("Out of resources!\n");
35  return NULL;
36  }
37 
38  /* Zero everything */
39  RtlZeroMemory(LunExtension, LunExtensionSize);
40 
41  /* Initialize a list of requests */
42  InitializeListHead(&LunExtension->SrbInfo.Requests);
43 
44  /* Initialize timeout counter */
45  LunExtension->RequestTimeout = -1;
46 
47  /* Set maximum queue size */
48  LunExtension->MaxQueueCount = 256;
49 
50  /* Initialize request queue */
51  KeInitializeDeviceQueue(&LunExtension->DeviceQueue);
52 
53  return LunExtension;
54 }
55 
58  _In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
61  _In_ UCHAR Lun)
62 {
63  PSCSI_PORT_LUN_EXTENSION LunExtension;
64 
65  DPRINT("SpiGetLunExtension(%p %u %u %u) called\n",
66  DeviceExtension, PathId, TargetId, Lun);
67 
68  /* Get appropriate list */
69  LunExtension = DeviceExtension->LunExtensionList[(TargetId + Lun) % LUS_NUMBER];
70 
71  /* Iterate it until we find what we need */
72  while (LunExtension)
73  {
74  if (LunExtension->TargetId == TargetId &&
75  LunExtension->Lun == Lun &&
76  LunExtension->PathId == PathId)
77  {
78  /* All matches, return */
79  return LunExtension;
80  }
81 
82  /* Advance to the next item */
83  LunExtension = LunExtension->Next;
84  }
85 
86  /* We did not find anything */
87  DPRINT("Nothing found\n");
88  return NULL;
89 }
90 
93  _In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
96  _In_ UCHAR Lun,
97  _In_ UCHAR QueueTag)
98 {
99  PSCSI_PORT_LUN_EXTENSION LunExtension;
100 
101  if (QueueTag == SP_UNTAGGED)
102  {
103  /* Untagged request, get LU and return pointer to SrbInfo */
104  LunExtension = SpiGetLunExtension(DeviceExtension,
105  PathId,
106  TargetId,
107  Lun);
108 
109  /* Return NULL in case of error */
110  if (!LunExtension)
111  return(NULL);
112 
113  /* Return the pointer to SrbInfo */
114  return &LunExtension->SrbInfo;
115  }
116  else
117  {
118  /* Make sure the tag is valid, if it is - return the data */
119  if (QueueTag > DeviceExtension->SrbDataCount || QueueTag < 1)
120  return NULL;
121  else
122  return &DeviceExtension->SrbInfo[QueueTag -1];
123  }
124 }
KDEVICE_QUEUE DeviceQueue
Definition: scsiport.h:133
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR _In_ UCHAR Lun
Definition: classpnp.h:1310
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR PathId
Definition: classpnp.h:1310
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR TargetId
Definition: classpnp.h:1310
PSCSI_PORT_LUN_EXTENSION SpiGetLunExtension(_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ UCHAR PathId, _In_ UCHAR TargetId, _In_ UCHAR Lun)
Definition: pdo.c:57
VOID NTAPI KeInitializeDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
Definition: devqueue.c:22
#define TAG_SCSIPORT
Definition: scsiport.h:20
PSCSI_PORT_LUN_EXTENSION SpiAllocateLunExtension(_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: pdo.c:16
PSCSI_REQUEST_BLOCK_INFO SpiGetSrbData(_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ UCHAR PathId, _In_ UCHAR TargetId, _In_ UCHAR Lun, _In_ UCHAR QueueTag)
Definition: pdo.c:92
struct _SCSI_PORT_LUN_EXTENSION SCSI_PORT_LUN_EXTENSION
#define LUS_NUMBER
Definition: scsiport.h:23
#define SP_UNTAGGED
Definition: srb.h:225
struct _SCSI_PORT_LUN_EXTENSION * Next
Definition: scsiport.h:126
void DPRINT(...)
Definition: polytest.cpp:61
int64_t LONGLONG
Definition: typedefs.h:68
SCSI_REQUEST_BLOCK_INFO SrbInfo
Definition: scsiport.h:147
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
#define _In_
Definition: no_sal2.h:158
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262