ReactOS  0.4.15-dev-1636-gf634010
scsiport.h File Reference
#include <ntifs.h>
#include <stdio.h>
#include <scsi.h>
#include <ntddscsi.h>
#include <ntdddisk.h>
#include <mountdev.h>
Include dependency graph for scsiport.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _STORAGE_ADAPTER_DESCRIPTOR_WIN8
 
struct  _CONFIGURATION_INFO
 
struct  _SCSI_PORT_DEVICE_BASE
 
struct  _SCSI_SG_ADDRESS
 
struct  _SCSI_REQUEST_BLOCK_INFO
 
struct  _SCSI_PORT_COMMON_EXTENSION
 
struct  _SCSI_PORT_LUN_EXTENSION
 
struct  _SCSI_BUS_INFO
 
struct  _SCSI_PORT_INTERRUPT_DATA
 
struct  _SCSI_PORT_SAVE_INTERRUPT
 
struct  _SCSI_PORT_DEVICE_EXTENSION
 
struct  _RESETBUS_PARAMS
 
struct  _SCSIPORT_DRIVER_EXTENSION
 

Macros

#define TAG_SCSIPORT   'ISCS'
 
#define LUS_NUMBER   8
 
#define MAX_SG_LIST   17
 
#define SCSI_PORT_DEVICE_BUSY   0x00001
 
#define SCSI_PORT_LU_ACTIVE   0x00002
 
#define SCSI_PORT_NOTIFICATION_NEEDED   0x00004
 
#define SCSI_PORT_NEXT_REQUEST_READY   0x00008
 
#define SCSI_PORT_FLUSH_ADAPTERS   0x00010
 
#define SCSI_PORT_MAP_TRANSFER   0x00020
 
#define SCSI_PORT_RESET   0x00080
 
#define SCSI_PORT_RESET_REQUEST   0x00100
 
#define SCSI_PORT_RESET_REPORTED   0x00200
 
#define SCSI_PORT_REQUEST_PENDING   0x00800
 
#define SCSI_PORT_DISCONNECT_ALLOWED   0x01000
 
#define SCSI_PORT_DISABLE_INT_REQUESET   0x02000
 
#define SCSI_PORT_DISABLE_INTERRUPTS   0x04000
 
#define SCSI_PORT_ENABLE_INT_REQUEST   0x08000
 
#define SCSI_PORT_TIMER_NEEDED   0x10000
 
#define LUNEX_FROZEN_QUEUE   0x0001
 
#define LUNEX_NEED_REQUEST_SENSE   0x0004
 
#define LUNEX_BUSY   0x0008
 
#define LUNEX_FULL_QUEUE   0x0010
 
#define LUNEX_REQUEST_PENDING   0x0020
 
#define SCSI_PORT_SCAN_IN_PROGRESS   0x8000
 
#define ALIGNAS_PTR   DECLSPEC_ALIGN(4)
 

Typedefs

typedef struct _STORAGE_ADAPTER_DESCRIPTOR_WIN8 STORAGE_ADAPTER_DESCRIPTOR_WIN8
 
typedef struct _STORAGE_ADAPTER_DESCRIPTOR_WIN8PSTORAGE_ADAPTER_DESCRIPTOR_WIN8
 
typedef enum _SCSI_PORT_TIMER_STATES SCSI_PORT_TIMER_STATES
 
typedef struct _CONFIGURATION_INFO CONFIGURATION_INFO
 
typedef struct _CONFIGURATION_INFOPCONFIGURATION_INFO
 
typedef struct _SCSI_PORT_DEVICE_BASE SCSI_PORT_DEVICE_BASE
 
typedef struct _SCSI_PORT_DEVICE_BASEPSCSI_PORT_DEVICE_BASE
 
typedef struct _SCSI_SG_ADDRESS SCSI_SG_ADDRESS
 
typedef struct _SCSI_SG_ADDRESSPSCSI_SG_ADDRESS
 
typedef struct _SCSI_REQUEST_BLOCK_INFO SCSI_REQUEST_BLOCK_INFO
 
typedef struct _SCSI_REQUEST_BLOCK_INFOPSCSI_REQUEST_BLOCK_INFO
 
typedef struct _SCSI_PORT_COMMON_EXTENSION SCSI_PORT_COMMON_EXTENSION
 
typedef struct _SCSI_PORT_COMMON_EXTENSIONPSCSI_PORT_COMMON_EXTENSION
 
typedef struct _SCSI_PORT_LUN_EXTENSION SCSI_PORT_LUN_EXTENSION
 
typedef struct _SCSI_PORT_LUN_EXTENSIONPSCSI_PORT_LUN_EXTENSION
 
typedef struct _SCSI_BUS_INFO SCSI_BUS_INFO
 
typedef struct _SCSI_BUS_INFOPSCSI_BUS_INFO
 
typedef struct _SCSI_PORT_INTERRUPT_DATA SCSI_PORT_INTERRUPT_DATA
 
typedef struct _SCSI_PORT_INTERRUPT_DATAPSCSI_PORT_INTERRUPT_DATA
 
typedef struct _SCSI_PORT_SAVE_INTERRUPT SCSI_PORT_SAVE_INTERRUPT
 
typedef struct _SCSI_PORT_SAVE_INTERRUPTPSCSI_PORT_SAVE_INTERRUPT
 
typedef struct _SCSI_PORT_DEVICE_EXTENSION SCSI_PORT_DEVICE_EXTENSION
 
typedef struct _SCSI_PORT_DEVICE_EXTENSIONPSCSI_PORT_DEVICE_EXTENSION
 
typedef struct _RESETBUS_PARAMS RESETBUS_PARAMS
 
typedef struct _RESETBUS_PARAMSPRESETBUS_PARAMS
 
typedef struct _SCSIPORT_DRIVER_EXTENSION SCSI_PORT_DRIVER_EXTENSION
 
typedef struct _SCSIPORT_DRIVER_EXTENSIONPSCSI_PORT_DRIVER_EXTENSION
 

Enumerations

enum  _SCSI_PORT_TIMER_STATES { IDETimerIdle, IDETimerCmdWait, IDETimerResetWaitForBusyNegate, IDETimerResetWaitForDrdyAssert }
 

Functions

FORCEINLINE BOOLEAN VerifyIrpOutBufferSize (_In_ PIRP Irp, _In_ SIZE_T Size)
 
FORCEINLINE BOOLEAN VerifyIrpInBufferSize (_In_ PIRP Irp, _In_ SIZE_T Size)
 
NTSTATUS NTAPI ScsiPortDeviceControl (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
VOID FdoScanAdapter (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS FdoCallHWInitialize (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
 Calls HwInitialize routine of the miniport and sets up interrupts Should be called inside ScsiPortInitialize (for legacy drivers) or inside IRP_MN_START_DEVICE for pnp drivers. More...
 
NTSTATUS FdoRemoveAdapter (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS FdoStartAdapter (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS FdoDispatchPnp (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
PDEVICE_OBJECT PdoCreateLunDevice (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
 
PSCSI_PORT_LUN_EXTENSION GetLunByPath (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ UCHAR PathId, _In_ UCHAR TargetId, _In_ UCHAR Lun)
 
PSCSI_REQUEST_BLOCK_INFO SpiGetSrbData (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ PSCSI_PORT_LUN_EXTENSION LunExtension, _In_ UCHAR QueueTag)
 
NTSTATUS PdoDispatchPnp (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
VOID SpiInitOpenKeys (_Inout_ PCONFIGURATION_INFO ConfigInfo, _In_ PSCSI_PORT_DRIVER_EXTENSION DriverExtension)
 
NTSTATUS RegistryInitAdapterKey (_Inout_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS RegistryInitLunKey (_Inout_ PSCSI_PORT_LUN_EXTENSION LunExtension)
 
VOID SpiGetNextRequestFromLun (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _Inout_ PSCSI_PORT_LUN_EXTENSION LunExtension, _Inout_opt_ PKIRQL OldIrql)
 
IO_ALLOCATION_ACTION NTAPI SpiAdapterControl (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID MapRegisterBase, _In_ PVOID Context)
 
IO_ALLOCATION_ACTION NTAPI ScsiPortAllocateAdapterChannel (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID MapRegisterBase, _In_ PVOID Context)
 

Variables

DRIVER_DISPATCH ScsiPortDispatchPower
 
IO_DPC_ROUTINE ScsiPortDpcForIsr
 
DRIVER_DISPATCH ScsiPortDispatchScsi
 
KSYNCHRONIZE_ROUTINE ScsiPortStartPacket
 
DRIVER_STARTIO ScsiPortStartIo
 
KSERVICE_ROUTINE ScsiPortIsr
 

Macro Definition Documentation

◆ ALIGNAS_PTR

#define ALIGNAS_PTR   DECLSPEC_ALIGN(4)

Definition at line 223 of file scsiport.h.

◆ LUNEX_BUSY

#define LUNEX_BUSY   0x0008

Definition at line 48 of file scsiport.h.

◆ LUNEX_FROZEN_QUEUE

#define LUNEX_FROZEN_QUEUE   0x0001

Definition at line 46 of file scsiport.h.

◆ LUNEX_FULL_QUEUE

#define LUNEX_FULL_QUEUE   0x0010

Definition at line 49 of file scsiport.h.

◆ LUNEX_NEED_REQUEST_SENSE

#define LUNEX_NEED_REQUEST_SENSE   0x0004

Definition at line 47 of file scsiport.h.

◆ LUNEX_REQUEST_PENDING

#define LUNEX_REQUEST_PENDING   0x0020

Definition at line 50 of file scsiport.h.

◆ LUS_NUMBER

#define LUS_NUMBER   8

Definition at line 24 of file scsiport.h.

◆ MAX_SG_LIST

#define MAX_SG_LIST   17

Definition at line 26 of file scsiport.h.

◆ SCSI_PORT_DEVICE_BUSY

#define SCSI_PORT_DEVICE_BUSY   0x00001

Definition at line 29 of file scsiport.h.

◆ SCSI_PORT_DISABLE_INT_REQUESET

#define SCSI_PORT_DISABLE_INT_REQUESET   0x02000

Definition at line 40 of file scsiport.h.

◆ SCSI_PORT_DISABLE_INTERRUPTS

#define SCSI_PORT_DISABLE_INTERRUPTS   0x04000

Definition at line 41 of file scsiport.h.

◆ SCSI_PORT_DISCONNECT_ALLOWED

#define SCSI_PORT_DISCONNECT_ALLOWED   0x01000

Definition at line 39 of file scsiport.h.

◆ SCSI_PORT_ENABLE_INT_REQUEST

#define SCSI_PORT_ENABLE_INT_REQUEST   0x08000

Definition at line 42 of file scsiport.h.

◆ SCSI_PORT_FLUSH_ADAPTERS

#define SCSI_PORT_FLUSH_ADAPTERS   0x00010

Definition at line 33 of file scsiport.h.

◆ SCSI_PORT_LU_ACTIVE

#define SCSI_PORT_LU_ACTIVE   0x00002

Definition at line 30 of file scsiport.h.

◆ SCSI_PORT_MAP_TRANSFER

#define SCSI_PORT_MAP_TRANSFER   0x00020

Definition at line 34 of file scsiport.h.

◆ SCSI_PORT_NEXT_REQUEST_READY

#define SCSI_PORT_NEXT_REQUEST_READY   0x00008

Definition at line 32 of file scsiport.h.

◆ SCSI_PORT_NOTIFICATION_NEEDED

#define SCSI_PORT_NOTIFICATION_NEEDED   0x00004

Definition at line 31 of file scsiport.h.

◆ SCSI_PORT_REQUEST_PENDING

#define SCSI_PORT_REQUEST_PENDING   0x00800

Definition at line 38 of file scsiport.h.

◆ SCSI_PORT_RESET

#define SCSI_PORT_RESET   0x00080

Definition at line 35 of file scsiport.h.

◆ SCSI_PORT_RESET_REPORTED

#define SCSI_PORT_RESET_REPORTED   0x00200

Definition at line 37 of file scsiport.h.

◆ SCSI_PORT_RESET_REQUEST

#define SCSI_PORT_RESET_REQUEST   0x00100

Definition at line 36 of file scsiport.h.

◆ SCSI_PORT_SCAN_IN_PROGRESS

#define SCSI_PORT_SCAN_IN_PROGRESS   0x8000

Definition at line 51 of file scsiport.h.

◆ SCSI_PORT_TIMER_NEEDED

#define SCSI_PORT_TIMER_NEEDED   0x10000

Definition at line 43 of file scsiport.h.

◆ TAG_SCSIPORT

#define TAG_SCSIPORT   'ISCS'

Definition at line 21 of file scsiport.h.

Typedef Documentation

◆ CONFIGURATION_INFO

◆ PCONFIGURATION_INFO

◆ PRESETBUS_PARAMS

◆ PSCSI_BUS_INFO

◆ PSCSI_PORT_COMMON_EXTENSION

◆ PSCSI_PORT_DEVICE_BASE

◆ PSCSI_PORT_DEVICE_EXTENSION

◆ PSCSI_PORT_DRIVER_EXTENSION

◆ PSCSI_PORT_INTERRUPT_DATA

◆ PSCSI_PORT_LUN_EXTENSION

◆ PSCSI_PORT_SAVE_INTERRUPT

◆ PSCSI_REQUEST_BLOCK_INFO

◆ PSCSI_SG_ADDRESS

◆ PSTORAGE_ADAPTER_DESCRIPTOR_WIN8

◆ RESETBUS_PARAMS

◆ SCSI_BUS_INFO

◆ SCSI_PORT_COMMON_EXTENSION

◆ SCSI_PORT_DEVICE_BASE

◆ SCSI_PORT_DEVICE_EXTENSION

◆ SCSI_PORT_DRIVER_EXTENSION

◆ SCSI_PORT_INTERRUPT_DATA

◆ SCSI_PORT_LUN_EXTENSION

◆ SCSI_PORT_SAVE_INTERRUPT

◆ SCSI_PORT_TIMER_STATES

◆ SCSI_REQUEST_BLOCK_INFO

◆ SCSI_SG_ADDRESS

◆ STORAGE_ADAPTER_DESCRIPTOR_WIN8

Enumeration Type Documentation

◆ _SCSI_PORT_TIMER_STATES

Enumerator
IDETimerIdle 
IDETimerCmdWait 
IDETimerResetWaitForBusyNegate 
IDETimerResetWaitForDrdyAssert 

Definition at line 71 of file scsiport.h.

Function Documentation

◆ FdoCallHWInitialize()

NTSTATUS FdoCallHWInitialize ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension)

Calls HwInitialize routine of the miniport and sets up interrupts Should be called inside ScsiPortInitialize (for legacy drivers) or inside IRP_MN_START_DEVICE for pnp drivers.

Parameters
[in]DeviceExtensionThe device extension
Returns
NTSTATUS of the operation

Definition at line 362 of file fdo.c.

364 {
365  PPORT_CONFIGURATION_INFORMATION PortConfig = DeviceExtension->PortConfig;
367  KIRQL OldIrql;
368 
369  /* Deal with interrupts */
370  if (DeviceExtension->HwInterrupt == NULL ||
371  (PortConfig->BusInterruptLevel == 0 && PortConfig->BusInterruptVector == 0))
372  {
373  /* No interrupts */
374  DeviceExtension->InterruptCount = 0;
375 
376  DPRINT1("Interrupt Count: 0\n");
377 
379 
380  /* This code path will ALWAYS crash so stop it now */
381  __debugbreak();
382  }
383  else
384  {
385  BOOLEAN InterruptShareable;
387  ULONG InterruptVector[2], i, MappedIrq[2];
388  KIRQL Dirql[2], MaxDirql;
389  KAFFINITY Affinity[2];
390 
391  DeviceExtension->InterruptLevel[0] = PortConfig->BusInterruptLevel;
392  DeviceExtension->InterruptLevel[1] = PortConfig->BusInterruptLevel2;
393 
394  InterruptVector[0] = PortConfig->BusInterruptVector;
395  InterruptVector[1] = PortConfig->BusInterruptVector2;
396 
397  InterruptMode[0] = PortConfig->InterruptMode;
398  InterruptMode[1] = PortConfig->InterruptMode2;
399 
400  DeviceExtension->InterruptCount =
401  (PortConfig->BusInterruptLevel2 != 0 ||
402  PortConfig->BusInterruptVector2 != 0) ? 2 : 1;
403 
404  for (i = 0; i < DeviceExtension->InterruptCount; i++)
405  {
406  /* Register an interrupt handler for this device */
407  MappedIrq[i] = HalGetInterruptVector(
408  PortConfig->AdapterInterfaceType, PortConfig->SystemIoBusNumber,
409  DeviceExtension->InterruptLevel[i], InterruptVector[i], &Dirql[i],
410  &Affinity[i]);
411  }
412 
413  if (DeviceExtension->InterruptCount == 1 || Dirql[0] > Dirql[1])
414  {
415  MaxDirql = Dirql[0];
416  }
417  else
418  {
419  MaxDirql = Dirql[1];
420  }
421 
422  for (i = 0; i < DeviceExtension->InterruptCount; i++)
423  {
424  /* Determine IRQ sharability as usual */
425  if (PortConfig->AdapterInterfaceType == MicroChannel ||
427  {
428  InterruptShareable = TRUE;
429  }
430  else
431  {
432  InterruptShareable = FALSE;
433  }
434 
435  Status = IoConnectInterrupt(&DeviceExtension->Interrupt[i],
436  ScsiPortIsr,
437  DeviceExtension,
438  &DeviceExtension->IrqLock,
439  MappedIrq[i], Dirql[i],
440  MaxDirql,
441  InterruptMode[i],
442  InterruptShareable,
443  Affinity[i],
444  FALSE);
445 
446  if (!(NT_SUCCESS(Status)))
447  {
448  DPRINT1("Could not connect interrupt %d\n", InterruptVector[i]);
449  DeviceExtension->Interrupt[i] = NULL;
450  return Status;
451  }
452  }
453  }
454 
455  /* Save IoAddress (from access ranges) */
456  if (PortConfig->NumberOfAccessRanges != 0)
457  {
458  DeviceExtension->IoAddress = ((*(PortConfig->AccessRanges))[0]).RangeStart.LowPart;
459 
460  DPRINT("Io Address %x\n", DeviceExtension->IoAddress);
461  }
462 
463  /* Set flag that it's allowed to disconnect during this command */
464  DeviceExtension->Flags |= SCSI_PORT_DISCONNECT_ALLOWED;
465 
466  /* Initialize counter of active requests (-1 means there are none) */
467  DeviceExtension->ActiveRequestCounter = -1;
468 
469  /* Analyze what we have about DMA */
470  if (DeviceExtension->AdapterObject != NULL && PortConfig->Master &&
471  PortConfig->NeedPhysicalAddresses)
472  {
473  DeviceExtension->MapRegisters = TRUE;
474  }
475  else
476  {
477  DeviceExtension->MapRegisters = FALSE;
478  }
479 
480  /* Call HwInitialize at DISPATCH_LEVEL */
482 
484  DeviceExtension->Interrupt[0], DeviceExtension->HwInitialize,
485  DeviceExtension->MiniPortDeviceExtension))
486  {
487  DPRINT1("HwInitialize() failed!\n");
490  }
491 
492  /* Check if a notification is needed */
493  if (DeviceExtension->InterruptData.Flags & SCSI_PORT_NOTIFICATION_NEEDED)
494  {
495  /* Call DPC right away, because we're already at DISPATCH_LEVEL */
496  ScsiPortDpcForIsr(NULL, DeviceExtension->Common.DeviceObject, NULL, NULL);
497  }
498 
499  /* Lower irql back to what it was */
501 
502  return STATUS_SUCCESS;
503 }
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
INTERFACE_TYPE AdapterInterfaceType
Definition: srb.h:55
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL _In_ KINTERRUPT_MODE InterruptMode
Definition: iofuncs.h:798
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
KSERVICE_ROUTINE ScsiPortIsr
Definition: scsiport.h:459
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
ACCESS_RANGE(* AccessRanges)[]
Definition: srb.h:70
IO_DPC_ROUTINE ScsiPortDpcForIsr
Definition: scsiport.h:451
#define SCSI_PORT_NOTIFICATION_NEEDED
Definition: scsiport.h:31
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, IN PKSERVICE_ROUTINE ServiceRoutine, IN PVOID ServiceContext, IN PKSPIN_LOCK SpinLock, IN ULONG Vector, IN KIRQL Irql, IN KIRQL SynchronizeIrql, IN KINTERRUPT_MODE InterruptMode, IN BOOLEAN ShareVector, IN KAFFINITY ProcessorEnableMask, IN BOOLEAN FloatingSave)
Definition: irq.c:22
unsigned char BOOLEAN
enum _KINTERRUPT_MODE KINTERRUPT_MODE
void DPRINT(...)
Definition: polytest.cpp:61
KINTERRUPT_MODE InterruptMode2
Definition: srb.h:97
NTHALAPI ULONG NTAPI HalGetInterruptVector(INTERFACE_TYPE, ULONG, ULONG, ULONG, PKIRQL, PKAFFINITY)
KINTERRUPT_MODE InterruptMode
Definition: srb.h:60
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG_PTR KAFFINITY
Definition: compat.h:85
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:115
BOOLEAN NTAPI KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt, IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID SynchronizeContext OPTIONAL)
Definition: interrupt.c:142
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_ADAPTER_HARDWARE_ERROR
Definition: ntstatus.h:430
#define SCSI_PORT_DISCONNECT_ALLOWED
Definition: scsiport.h:39

Referenced by ScsiPortInitialize().

◆ FdoDispatchPnp()

NTSTATUS FdoDispatchPnp ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 709 of file fdo.c.

712 {
714  PSCSI_PORT_DEVICE_EXTENSION portExt = DeviceObject->DeviceExtension;
716 
717  ASSERT(portExt->Common.IsFDO);
718 
719  DPRINT("FDO PnP request %s\n", GetIRPMinorFunctionString(ioStack->MinorFunction));
720 
721  switch (ioStack->MinorFunction)
722  {
723  case IRP_MN_START_DEVICE:
724  {
725  // as we don't support PnP yet, this is a no-op for us
726  // (FdoStartAdapter is being called during initialization for legacy miniports)
728  // status = FdoStartAdapter(DeviceExtension);
729  break;
730  }
732  {
733  return FdoHandleDeviceRelations(portExt, Irp);
734  }
735  default:
736  {
737  // forward irp to next device object
739  return IoCallDriver(portExt->Common.LowerDevice, Irp);
740  }
741  }
742 
743  if (status != STATUS_PENDING)
744  {
745  Irp->IoStatus.Status = status;
747  }
748 
749  return status;
750 }
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2864
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define ASSERT(a)
Definition: mode.c:45
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_START_DEVICE
static NTSTATUS FdoHandleDeviceRelations(_In_ PSCSI_PORT_DEVICE_EXTENSION PortExtension, _Inout_ PIRP Irp)
Definition: fdo.c:651
FORCEINLINE PCHAR GetIRPMinorFunctionString(UCHAR MinorFunction)
Definition: driverdbg.h:13
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by ScsiPortDispatchPnp().

◆ FdoRemoveAdapter()

NTSTATUS FdoRemoveAdapter ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 506 of file fdo.c.

508 {
509  IoStopTimer(DeviceExtension->Common.DeviceObject);
510 
511  // release device interface
512  if (DeviceExtension->InterfaceName.Buffer)
513  {
514  IoSetDeviceInterfaceState(&DeviceExtension->InterfaceName, FALSE);
515 
516  RtlFreeUnicodeString(&DeviceExtension->InterfaceName);
517  RtlInitUnicodeString(&DeviceExtension->InterfaceName, NULL);
518  }
519 
520  // remove the dos device link
521  WCHAR dosNameBuffer[12];
522  UNICODE_STRING dosDeviceName;
523 
524  swprintf(dosNameBuffer, L"\\??\\Scsi%lu:", DeviceExtension->PortNumber);
525  RtlInitUnicodeString(&dosDeviceName, dosNameBuffer);
526 
527  IoDeleteSymbolicLink(&dosDeviceName); // don't check the result
528 
529  // decrease the port count
530  if (DeviceExtension->DeviceStarted)
531  {
533  sysConfig->ScsiPortCount--;
534  }
535 
536  // disconnect the interrupts
537  while (DeviceExtension->InterruptCount)
538  {
539  if (DeviceExtension->Interrupt[--DeviceExtension->InterruptCount])
540  IoDisconnectInterrupt(DeviceExtension->Interrupt[DeviceExtension->InterruptCount]);
541  }
542 
543  // FIXME: delete LUNs
544  if (DeviceExtension->Buses)
545  {
546  for (UINT8 pathId = 0; pathId < DeviceExtension->NumberOfBuses; pathId++)
547  {
548  PSCSI_BUS_INFO bus = &DeviceExtension->Buses[pathId];
549  if (bus->RegistryMapKey)
550  {
551  ZwDeleteKey(bus->RegistryMapKey);
552  ZwClose(bus->RegistryMapKey);
553  bus->RegistryMapKey = NULL;
554  }
555  }
556 
557  ExFreePoolWithTag(DeviceExtension->Buses, TAG_SCSIPORT);
558  }
559 
560  /* Free PortConfig */
561  if (DeviceExtension->PortConfig)
562  {
563  ExFreePoolWithTag(DeviceExtension->PortConfig, TAG_SCSIPORT);
564  }
565 
566  /* Free common buffer (if it exists) */
567  if (DeviceExtension->SrbExtensionBuffer != NULL && DeviceExtension->CommonBufferLength != 0)
568  {
569  if (!DeviceExtension->AdapterObject)
570  {
571  ExFreePoolWithTag(DeviceExtension->SrbExtensionBuffer, TAG_SCSIPORT);
572  }
573  else
574  {
575  HalFreeCommonBuffer(DeviceExtension->AdapterObject,
576  DeviceExtension->CommonBufferLength,
577  DeviceExtension->PhysicalAddress,
578  DeviceExtension->SrbExtensionBuffer,
579  FALSE);
580  }
581  }
582 
583  /* Free SRB info */
584  if (DeviceExtension->SrbInfo != NULL)
585  ExFreePoolWithTag(DeviceExtension->SrbInfo, TAG_SCSIPORT);
586 
587  /* Unmap mapped addresses */
588  while (DeviceExtension->MappedAddressList != NULL)
589  {
590  MmUnmapIoSpace(DeviceExtension->MappedAddressList->MappedAddress,
591  DeviceExtension->MappedAddressList->NumberOfBytes);
592 
593  PVOID ptr = DeviceExtension->MappedAddressList;
594  DeviceExtension->MappedAddressList = DeviceExtension->MappedAddressList->NextMappedAddress;
595 
597  }
598 
599  IoDeleteDevice(DeviceExtension->Common.DeviceObject);
600 
601  return STATUS_SUCCESS;
602 }
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Definition: iorsrce.c:830
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define TAG_SCSIPORT
Definition: scsiport.h:21
#define swprintf
Definition: precomp.h:40
#define FALSE
Definition: types.h:117
VOID NTAPI IoStopTimer(PDEVICE_OBJECT DeviceObject)
Definition: iotimer.c:166
static PVOID ptr
Definition: dispmode.c:27
VOID NTAPI IoDisconnectInterrupt(PKINTERRUPT InterruptObject)
Definition: irq.c:140
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
static const WCHAR L[]
Definition: oid.c:1250
HANDLE RegistryMapKey
Definition: scsiport.h:191
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
#define NULL
Definition: types.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
unsigned char UINT8
VOID NTAPI HalFreeCommonBuffer(IN PADAPTER_OBJECT AdapterObject, IN ULONG Length, IN PHYSICAL_ADDRESS LogicalAddress, IN PVOID VirtualAddress, IN BOOLEAN CacheEnabled)
Definition: dma.c:61

Referenced by ScsiPortInitialize().

◆ FdoScanAdapter()

VOID FdoScanAdapter ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 222 of file fdo.c.

224 {
226  UINT32 totalLUNs = PortExtension->TotalLUCount;
227 
228  DPRINT("FdoScanAdapter() called\n");
229 
230  /* Scan all buses */
231  for (UINT8 pathId = 0; pathId < PortExtension->NumberOfBuses; pathId++)
232  {
233  DPRINT(" Scanning bus/pathID %u\n", pathId);
234 
235  /* Get pointer to the scan information */
236  PSCSI_BUS_INFO currentBus = &PortExtension->Buses[pathId];
237 
238  /* And send INQUIRY to every target */
239  for (UINT8 targetId = 0;
240  targetId < PortExtension->PortConfig->MaximumNumberOfTargets;
241  targetId++)
242  {
243  BOOLEAN targetFound = FALSE;
244 
245  /* TODO: Support scan bottom-up */
246 
247  /* Skip if it's the same address */
248  if (targetId == currentBus->BusIdentifier)
249  continue;
250 
251  /* Scan all logical units */
252  for (UINT8 lun = 0; lun < PortExtension->MaxLunCount; lun++)
253  {
254  // try to find an existing device
255  PSCSI_PORT_LUN_EXTENSION lunExt = GetLunByPath(PortExtension,
256  pathId,
257  targetId,
258  lun);
259 
260  if (lunExt)
261  {
262  // check if the device still exists
264  if (!NT_SUCCESS(status))
265  {
266  // remove the device
268  __debugbreak();
269  }
270 
272  {
273  // remove the device
275  __debugbreak();
276  }
277 
278  /* Decide whether we are continuing or not */
280  continue;
281  else
282  break;
283  }
284 
285  // create a new LUN device
286  PDEVICE_OBJECT lunPDO = PdoCreateLunDevice(PortExtension);
287  if (!lunPDO)
288  {
289  continue;
290  }
291 
292  lunExt = lunPDO->DeviceExtension;
293 
294  lunExt->PathId = pathId;
295  lunExt->TargetId = targetId;
296  lunExt->Lun = lun;
297 
298  DPRINT("Add PDO to list: PDO: %p, FDOExt: %p, PDOExt: %p\n", lunPDO, PortExtension, lunExt);
299 
300  /* Set flag to prevent race conditions */
302 
303  /* Finally send the inquiry command */
304  status = FdoSendInquiry(lunPDO);
305 
306  if (NT_SUCCESS(status))
307  {
308  /* Let's see if we really found a device */
309  PINQUIRYDATA InquiryData = &lunExt->InquiryData;
310 
311  /* Check if this device is unsupported */
313  {
314  IoDeleteDevice(lunPDO);
315  continue;
316  }
317 
318  /* Clear the "in scan" flag */
319  lunExt->Flags &= ~SCSI_PORT_SCAN_IN_PROGRESS;
320 
321  DPRINT("FdoScanAdapter(): Found device of type %d at bus %d tid %d lun %d\n",
322  InquiryData->DeviceType, pathId, targetId, lun);
323 
324  InsertTailList(&currentBus->LunsListHead, &lunExt->LunEntry);
325 
326  DPRINT1("SCSIPORT: created lun device: %p Status: %x\n", lunPDO, status);
327 
328  totalLUNs++;
329  currentBus->LogicalUnitsCount++;
330  targetFound = TRUE;
331  }
332  else
333  {
334  /* Decide whether we are continuing or not */
336  continue;
337  else
338  break;
339  }
340  }
341 
342  if (targetFound)
343  {
344  currentBus->TargetsCount++;
345  }
346  }
347  }
348 
349  PortExtension->TotalLUCount = totalLUNs;
350 }
PDEVICE_OBJECT DeviceObject
Definition: scsiport.h:138
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define SCSI_PORT_SCAN_IN_PROGRESS
Definition: scsiport.h:51
#define InsertTailList(ListHead, Entry)
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
#define FALSE
Definition: types.h:117
unsigned int UINT32
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
UCHAR DeviceTypeQualifier
Definition: cdrw_hw.h:1117
UCHAR LogicalUnitsCount
Definition: scsiport.h:188
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DEVICE_QUALIFIER_NOT_SUPPORTED
Definition: cdrw_hw.h:1155
static NTSTATUS FdoSendInquiry(_In_ PDEVICE_OBJECT DeviceObject)
Definition: fdo.c:18
UCHAR DeviceType
Definition: cdrw_hw.h:1116
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
INQUIRYDATA InquiryData
Definition: scsiport.h:158
UCHAR TargetsCount
Definition: scsiport.h:189
#define DPRINT1
Definition: precomp.h:8
SCSI_PORT_COMMON_EXTENSION Common
Definition: scsiport.h:146
LIST_ENTRY LunsListHead
Definition: scsiport.h:187
#define UNIMPLEMENTED
Definition: debug.h:115
PSCSI_PORT_LUN_EXTENSION GetLunByPath(_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ UCHAR PathId, _In_ UCHAR TargetId, _In_ UCHAR Lun)
Definition: pdo.c:68
PDEVICE_OBJECT PdoCreateLunDevice(_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: pdo.c:18
unsigned char UINT8
static SERVICE_STATUS status
Definition: service.c:31
UCHAR BusIdentifier
Definition: scsiport.h:190
Definition: ps.c:97

Referenced by FdoHandleDeviceRelations(), and ScsiPortInitialize().

◆ FdoStartAdapter()

NTSTATUS FdoStartAdapter ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 605 of file fdo.c.

607 {
608  WCHAR dosNameBuffer[12];
609  UNICODE_STRING dosDeviceName;
611 
612  // Start our timer
613  IoStartTimer(PortExtension->Common.DeviceObject);
614 
615  // Create the dos device link
616  swprintf(dosNameBuffer, L"\\??\\Scsi%u:", PortExtension->PortNumber);
617  RtlInitUnicodeString(&dosDeviceName, dosNameBuffer);
618  status = IoCreateSymbolicLink(&dosDeviceName, &PortExtension->DeviceName);
619  if (!NT_SUCCESS(status))
620  {
621  return status;
622  }
623 
624  // start building a device map
625  RegistryInitAdapterKey(PortExtension);
626 
627  // increase the port count
629  sysConfig->ScsiPortCount++;
630 
631  // Register and enable the device interface
632  status = IoRegisterDeviceInterface(PortExtension->Common.DeviceObject,
633  &StoragePortClassGuid,
634  NULL,
635  &PortExtension->InterfaceName);
636  DPRINT("IoRegisterDeviceInterface status: %x, InterfaceName: %wZ\n",
637  status, &PortExtension->InterfaceName);
638 
639  if (NT_SUCCESS(status))
640  {
641  IoSetDeviceInterfaceState(&PortExtension->InterfaceName, TRUE);
642  }
643 
644  PortExtension->DeviceStarted = TRUE;
645 
646  return STATUS_SUCCESS;
647 }
VOID NTAPI IoStartTimer(IN PDEVICE_OBJECT DeviceObject)
Definition: iotimer.c:133
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Definition: iorsrce.c:830
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define swprintf
Definition: precomp.h:40
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
NTSTATUS RegistryInitAdapterKey(_Inout_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: registry.c:127
#define NULL
Definition: types.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by ScsiPortInitialize().

◆ GetLunByPath()

PSCSI_PORT_LUN_EXTENSION GetLunByPath ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
_In_ UCHAR  PathId,
_In_ UCHAR  TargetId,
_In_ UCHAR  Lun 
)

Definition at line 68 of file pdo.c.

73 {
74  if (PathId >= DeviceExtension->NumberOfBuses)
75  {
76  DPRINT1("Invalid PathId: %u\n", PathId);
77  return NULL;
78  }
79 
80  PSCSI_BUS_INFO bus = &DeviceExtension->Buses[PathId];
81 
82  for (PLIST_ENTRY lunEntry = bus->LunsListHead.Flink;
83  lunEntry != &bus->LunsListHead;
84  lunEntry = lunEntry->Flink)
85  {
87  CONTAINING_RECORD(lunEntry, SCSI_PORT_LUN_EXTENSION, LunEntry);
88 
89  if (lunExt->PathId == PathId &&
90  lunExt->TargetId == TargetId &&
91  lunExt->Lun == Lun)
92  {
93  return lunExt;
94  }
95  }
96 
97  DPRINT("SCSI LUN (%u, %u, %u) was not found\n", PathId, TargetId, Lun);
98  return NULL;
99 }
_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
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: typedefs.h:119
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
LIST_ENTRY LunsListHead
Definition: scsiport.h:187

Referenced by FdoScanAdapter(), ScsiPortGetLogicalUnit(), and ScsiPortNotification().

◆ PdoCreateLunDevice()

PDEVICE_OBJECT PdoCreateLunDevice ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 18 of file pdo.c.

20 {
21  PSCSI_PORT_LUN_EXTENSION LunExtension;
22  PDEVICE_OBJECT LunPDO;
23 
24  ULONG LunExtensionSize = DeviceExtension->LunExtensionSize + sizeof(SCSI_PORT_LUN_EXTENSION);
25 
26  NTSTATUS Status = IoCreateDevice(DeviceExtension->Common.DeviceObject->DriverObject,
27  LunExtensionSize,
28  NULL,
31  FALSE,
32  &LunPDO);
33 
34  if (!NT_SUCCESS(Status))
35  {
36  DPRINT1("Failed to create a Lun PDO, status: %x\n", Status);
37  return NULL;
38  }
39 
40  LunExtension = LunPDO->DeviceExtension;
41 
42  /* Zero everything */
43  RtlZeroMemory(LunExtension, LunExtensionSize);
44 
45  LunExtension->Common.IsFDO = FALSE;
46  LunExtension->Common.DeviceObject = LunPDO;
47  LunExtension->Common.LowerDevice = DeviceExtension->Common.DeviceObject;
48 
49  /* Initialize a list of requests */
50  InitializeListHead(&LunExtension->SrbInfo.Requests);
51 
52  /* Initialize timeout counter */
53  LunExtension->RequestTimeout = -1;
54 
55  /* Set maximum queue size */
56  LunExtension->MaxQueueCount = 256;
57 
58  /* Initialize request queue */
59  KeInitializeDeviceQueue(&LunExtension->DeviceQueue);
60 
61  LunPDO->Flags |= DO_DIRECT_IO;
62  LunPDO->Flags &= ~DO_DEVICE_INITIALIZING;
63 
64  return LunPDO;
65 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
KDEVICE_QUEUE DeviceQueue
Definition: scsiport.h:160
PDEVICE_OBJECT DeviceObject
Definition: scsiport.h:138
PDEVICE_OBJECT LowerDevice
Definition: scsiport.h:139
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI KeInitializeDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
Definition: devqueue.c:22
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
struct _SCSI_PORT_LUN_EXTENSION SCSI_PORT_LUN_EXTENSION
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
SCSI_REQUEST_BLOCK_INFO SrbInfo
Definition: scsiport.h:174
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
SCSI_PORT_COMMON_EXTENSION Common
Definition: scsiport.h:146
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46

Referenced by FdoScanAdapter().

◆ PdoDispatchPnp()

NTSTATUS PdoDispatchPnp ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 554 of file pdo.c.

557 {
559  PSCSI_PORT_LUN_EXTENSION lunExt = DeviceObject->DeviceExtension;
561 
562  DPRINT("PDO PnP request %s\n", GetIRPMinorFunctionString(ioStack->MinorFunction));
563 
564  ASSERT(!lunExt->Common.IsFDO);
565 
566  switch (ioStack->MinorFunction)
567  {
568  case IRP_MN_START_DEVICE:
569  {
570  RegistryInitLunKey(lunExt);
572  break;
573  }
579  {
581  break;
582  }
584  {
586  break;
587  }
589  {
591  break;
592  }
593  case IRP_MN_QUERY_ID:
594  {
595  DPRINT("IRP_MN_QUERY_ID IdType %s\n",
596  DbgGetDeviceIDString(ioStack->Parameters.QueryId.IdType));
597 
598  if (ioStack->Parameters.QueryId.IdType == BusQueryDeviceID)
599  {
601  break;
602  }
603  else if (ioStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
604  {
606  break;
607  }
608  else if (ioStack->Parameters.QueryId.IdType == BusQueryInstanceID)
609  {
611  break;
612  }
613  else if (ioStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
614  {
616  break;
617  }
618 
619  // fallthrough
620  }
621  default:
622  {
623  // do nothing
624  status = Irp->IoStatus.Status;
625  }
626  }
627 
628  if (status != STATUS_PENDING)
629  {
630  Irp->IoStatus.Status = status;
632  }
633 
634  return status;
635 }
static NTSTATUS PdoHandleQueryHardwareId(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:346
static NTSTATUS PdoHandleDeviceRelations(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:524
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_ID
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS PdoHandleQueryCompatibleId(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:457
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define ASSERT(a)
Definition: mode.c:45
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
static NTSTATUS PdoHandleQueryDeviceId(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:263
static NTSTATUS PdoHandleQueryDeviceText(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:168
NTSTATUS RegistryInitLunKey(_Inout_ PSCSI_PORT_LUN_EXTENSION LunExtension)
Definition: registry.c:359
FORCEINLINE PCHAR GetIRPMinorFunctionString(UCHAR MinorFunction)
Definition: driverdbg.h:13
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define IRP_MN_QUERY_DEVICE_RELATIONS
SCSI_PORT_COMMON_EXTENSION Common
Definition: scsiport.h:146
static NTSTATUS PdoHandleQueryInstanceId(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:493
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3124
static SERVICE_STATUS status
Definition: service.c:31
PCHAR DbgGetDeviceIDString(BUS_QUERY_ID_TYPE Type)
Definition: driverdbg.h:93
#define IRP_MN_QUERY_CAPABILITIES
Definition: ps.c:97

Referenced by ScsiPortDispatchPnp().

◆ RegistryInitAdapterKey()

NTSTATUS RegistryInitAdapterKey ( _Inout_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 127 of file registry.c.

129 {
133  WCHAR NameBuffer[64];
134  HANDLE ScsiKey;
135  HANDLE ScsiPortKey = NULL;
136  HANDLE ScsiBusKey = NULL;
137  HANDLE ScsiInitiatorKey = NULL;
139  ULONG UlongData;
141 
142  DPRINT("SpiBuildDeviceMap() called\n");
143 
144  if (DeviceExtension == NULL)
145  {
146  DPRINT1("Invalid parameter\n");
148  }
149 
150  /* Open or create the 'Scsi' subkey */
152  L"\\Registry\\Machine\\Hardware\\DeviceMap\\Scsi");
154  &KeyName,
156  0,
157  NULL);
158  Status = ZwCreateKey(&ScsiKey,
161  0,
162  NULL,
164  NULL);
165  if (!NT_SUCCESS(Status))
166  {
167  DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
168  return Status;
169  }
170 
171  /* Create new 'Scsi Port X' subkey */
172  DPRINT("Scsi Port %lu\n", DeviceExtension->PortNumber);
173 
174  swprintf(NameBuffer,
175  L"Scsi Port %lu",
176  DeviceExtension->PortNumber);
177  RtlInitUnicodeString(&KeyName, NameBuffer);
179  Status = ZwCreateKey(&ScsiPortKey,
182  0,
183  NULL,
185  NULL);
186  ZwClose(ScsiKey);
187  if (!NT_SUCCESS(Status))
188  {
189  DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
190  return Status;
191  }
192 
193  /*
194  * Create port-specific values
195  */
196 
197  /* Set 'DMA Enabled' (REG_DWORD) value */
198  UlongData = (ULONG)!DeviceExtension->PortCapabilities.AdapterUsesPio;
199  DPRINT(" DMA Enabled = %s\n", UlongData ? "TRUE" : "FALSE");
200  RtlInitUnicodeString(&ValueName, L"DMA Enabled");
201  Status = ZwSetValueKey(ScsiPortKey,
202  &ValueName,
203  0,
204  REG_DWORD,
205  &UlongData,
206  sizeof(UlongData));
207  if (!NT_SUCCESS(Status))
208  {
209  DPRINT("ZwSetValueKey('DMA Enabled') failed (Status %lx)\n", Status);
210  ZwClose(ScsiPortKey);
211  return Status;
212  }
213 
214  /* Set 'Driver' (REG_SZ) value */
215  PUNICODE_STRING driverNameU = &DeviceExtension->Common.DeviceObject->DriverObject
216  ->DriverExtension->ServiceKeyName;
217 
219  driverNameU->Length + sizeof(UNICODE_NULL),
220  TAG_SCSIPORT);
221  if (!driverName)
222  {
223  DPRINT("Failed to allocate driverName!\n");
224  ZwClose(ScsiPortKey);
226  }
227 
228  RtlCopyMemory(driverName, driverNameU->Buffer, driverNameU->Length);
229  driverName[driverNameU->Length / sizeof(WCHAR)] = UNICODE_NULL;
230 
231  RtlInitUnicodeString(&ValueName, L"Driver");
232  Status = ZwSetValueKey(ScsiPortKey,
233  &ValueName,
234  0,
235  REG_SZ,
236  driverName,
237  driverNameU->Length + sizeof(UNICODE_NULL));
238 
239  ExFreePoolWithTag(driverName, TAG_SCSIPORT);
240 
241  if (!NT_SUCCESS(Status))
242  {
243  DPRINT("ZwSetValueKey('Driver') failed (Status %lx)\n", Status);
244  ZwClose(ScsiPortKey);
245  return Status;
246  }
247 
248  /* Set 'Interrupt' (REG_DWORD) value (NT4 only) */
249  UlongData = (ULONG)DeviceExtension->PortConfig->BusInterruptLevel;
250  DPRINT(" Interrupt = %lu\n", UlongData);
251  RtlInitUnicodeString(&ValueName, L"Interrupt");
252  Status = ZwSetValueKey(ScsiPortKey,
253  &ValueName,
254  0,
255  REG_DWORD,
256  &UlongData,
257  sizeof(UlongData));
258  if (!NT_SUCCESS(Status))
259  {
260  DPRINT("ZwSetValueKey('Interrupt') failed (Status %lx)\n", Status);
261  ZwClose(ScsiPortKey);
262  return Status;
263  }
264 
265  /* Set 'IOAddress' (REG_DWORD) value (NT4 only) */
266  UlongData = ScsiPortConvertPhysicalAddressToUlong((*DeviceExtension->PortConfig->AccessRanges)[0].RangeStart);
267  DPRINT(" IOAddress = %lx\n", UlongData);
268  RtlInitUnicodeString(&ValueName, L"IOAddress");
269  Status = ZwSetValueKey(ScsiPortKey,
270  &ValueName,
271  0,
272  REG_DWORD,
273  &UlongData,
274  sizeof(UlongData));
275  if (!NT_SUCCESS(Status))
276  {
277  DPRINT("ZwSetValueKey('IOAddress') failed (Status %lx)\n", Status);
278  ZwClose(ScsiPortKey);
279  return Status;
280  }
281 
282  /* Enumerate buses */
283  for (BusNumber = 0; BusNumber < DeviceExtension->NumberOfBuses; BusNumber++)
284  {
285  /* Create 'Scsi Bus X' key */
286  DPRINT(" Scsi Bus %lu\n", BusNumber);
287  swprintf(NameBuffer,
288  L"Scsi Bus %lu",
289  BusNumber);
290  RtlInitUnicodeString(&KeyName, NameBuffer);
292  &KeyName,
294  ScsiPortKey,
295  NULL);
296  Status = ZwCreateKey(&ScsiBusKey,
299  0,
300  NULL,
302  NULL);
303  if (!NT_SUCCESS(Status))
304  {
305  DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
306  goto ByeBye;
307  }
308 
309  /* Create 'Initiator Id X' key */
310  DPRINT(" Initiator Id %lu\n",
311  DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
312  swprintf(NameBuffer,
313  L"Initiator Id %lu",
314  (ULONG)(UCHAR)DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
315  RtlInitUnicodeString(&KeyName, NameBuffer);
317  &KeyName,
319  ScsiBusKey,
320  NULL);
321  Status = ZwCreateKey(&ScsiInitiatorKey,
324  0,
325  NULL,
327  NULL);
328  if (!NT_SUCCESS(Status))
329  {
330  DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
331  goto ByeBye;
332  }
333 
334  /* FIXME: Are there any initiator values (??) */
335 
336  ZwClose(ScsiInitiatorKey);
337  ScsiInitiatorKey = NULL;
338 
339  DeviceExtension->Buses[BusNumber].RegistryMapKey = ScsiBusKey;
340  ScsiBusKey = NULL;
341  }
342 
343 ByeBye:
344  if (ScsiInitiatorKey != NULL)
345  ZwClose(ScsiInitiatorKey);
346 
347  if (ScsiBusKey != NULL)
348  ZwClose(ScsiBusKey);
349 
350  if (ScsiPortKey != NULL)
351  ZwClose(ScsiPortKey);
352 
353  DPRINT("SpiBuildDeviceMap() done\n");
354 
355  return Status;
356 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define ScsiPortConvertPhysicalAddressToUlong(Address)
Definition: srb.h:949
LONG NTSTATUS
Definition: precomp.h:26
#define TAG_SCSIPORT
Definition: scsiport.h:21
uint16_t * PWCHAR
Definition: typedefs.h:56
#define swprintf
Definition: precomp.h:40
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_OPENIF
Definition: winternl.h:229
#define UNICODE_NULL
void DPRINT(...)
Definition: polytest.cpp:61
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define REG_DWORD
Definition: sdbapi.c:596
#define REG_SZ
Definition: layer.c:22

Referenced by FdoStartAdapter().

◆ RegistryInitLunKey()

NTSTATUS RegistryInitLunKey ( _Inout_ PSCSI_PORT_LUN_EXTENSION  LunExtension)

Definition at line 359 of file registry.c.

361 {
362  WCHAR nameBuffer[64];
363  UNICODE_STRING keyName;
364  UNICODE_STRING valueName;
365  OBJECT_ATTRIBUTES objectAttributes;
366  HANDLE targetKey;
368 
369  // get the LUN's bus key
370  PSCSI_PORT_DEVICE_EXTENSION portExt = LunExtension->Common.LowerDevice->DeviceExtension;
371  HANDLE busKey = portExt->Buses[LunExtension->PathId].RegistryMapKey;
372 
373  // create/open 'Target Id X' key
374  swprintf(nameBuffer, L"Target Id %lu", LunExtension->TargetId);
375  RtlInitUnicodeString(&keyName, nameBuffer);
376  InitializeObjectAttributes(&objectAttributes, &keyName, OBJ_KERNEL_HANDLE, busKey, NULL);
377  status = ZwCreateKey(&targetKey,
379  &objectAttributes,
380  0,
381  NULL,
383  NULL);
384  if (!NT_SUCCESS(status))
385  {
386  DPRINT("ZwCreateKey() failed (Status %lx)\n", status);
387  return status;
388  }
389 
390  // Create 'Logical Unit Id X' key
391  swprintf(nameBuffer, L"Logical Unit Id %lu", LunExtension->Lun);
392  RtlInitUnicodeString(&keyName, nameBuffer);
393  InitializeObjectAttributes(&objectAttributes, &keyName, OBJ_KERNEL_HANDLE, targetKey, NULL);
394  status = ZwCreateKey(&LunExtension->RegistryMapKey,
396  &objectAttributes,
397  0,
398  NULL,
400  NULL);
401  if (!NT_SUCCESS(status))
402  {
403  DPRINT("ZwCreateKey() failed (Status %lx)\n", status);
404  goto ByeBye;
405  }
406 
407  // Set 'Identifier' (REG_SZ) value
408  swprintf(nameBuffer,
409  L"%.8S%.16S%.4S",
410  LunExtension->InquiryData.VendorId,
411  LunExtension->InquiryData.ProductId,
412  LunExtension->InquiryData.ProductRevisionLevel);
413  RtlInitUnicodeString(&valueName, L"Identifier");
414  status = ZwSetValueKey(LunExtension->RegistryMapKey,
415  &valueName,
416  0,
417  REG_SZ,
418  nameBuffer,
419  (wcslen(nameBuffer) + 1) * sizeof(WCHAR));
420  if (!NT_SUCCESS(status))
421  {
422  DPRINT("ZwSetValueKey('Identifier') failed (Status %lx)\n", status);
423  goto ByeBye;
424  }
425 
426  // Set 'Type' (REG_SZ) value
427  PWCHAR typeName = (PWCHAR)GetPeripheralTypeW(&LunExtension->InquiryData);
428  DPRINT(" Type = '%S'\n", typeName);
429  RtlInitUnicodeString(&valueName, L"Type");
430  status = ZwSetValueKey(LunExtension->RegistryMapKey,
431  &valueName,
432  0,
433  REG_SZ,
434  typeName,
435  (wcslen(typeName) + 1) * sizeof(WCHAR));
436  if (!NT_SUCCESS(status))
437  {
438  DPRINT("ZwSetValueKey('Type') failed (Status %lx)\n", status);
439  goto ByeBye;
440  }
441 
442  // Set 'InquiryData' (REG_BINARY) value
443  RtlInitUnicodeString(&valueName, L"InquiryData");
444  status = ZwSetValueKey(LunExtension->RegistryMapKey,
445  &valueName,
446  0,
447  REG_BINARY,
448  &LunExtension->InquiryData,
450  if (!NT_SUCCESS(status))
451  {
452  DPRINT("ZwSetValueKey('InquiryData') failed (Status %lx)\n", status);
453  goto ByeBye;
454  }
455 
456 ByeBye:
457  ZwClose(targetKey);
458  // TODO: maybe we will need it in future
459  ZwClose(LunExtension->RegistryMapKey);
460 
461  return status;
462 }
FORCEINLINE PCWSTR GetPeripheralTypeW(_In_ PINQUIRYDATA InquiryData)
Definition: scsitypes.h:87
#define REG_BINARY
Definition: nt_native.h:1496
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:56
#define swprintf
Definition: precomp.h:40
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define INQUIRYDATABUFFERSIZE
Definition: cdrw_hw.h:1113
void DPRINT(...)
Definition: polytest.cpp:61
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define NULL
Definition: types.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
static SERVICE_STATUS status
Definition: service.c:31
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
Definition: ps.c:97

Referenced by PdoDispatchPnp().

◆ ScsiPortAllocateAdapterChannel()

IO_ALLOCATION_ACTION NTAPI ScsiPortAllocateAdapterChannel ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_ PVOID  MapRegisterBase,
_In_ PVOID  Context 
)

◆ ScsiPortDeviceControl()

NTSTATUS NTAPI ScsiPortDeviceControl ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)

Definition at line 404 of file ioctl.c.

407 {
409  PSCSI_PORT_COMMON_EXTENSION comExt = DeviceObject->DeviceExtension;
413 
414  DPRINT("ScsiPortDeviceControl()\n");
415 
416  Irp->IoStatus.Information = 0;
417 
419 
420  switch (Stack->Parameters.DeviceIoControl.IoControlCode)
421  {
423  {
424  DPRINT(" IOCTL_STORAGE_QUERY_PROPERTY\n");
425 
427  {
429  break;
430  }
431 
432  if (comExt->IsFDO)
434  else
436  }
438  {
439  DPRINT(" IOCTL_SCSI_GET_ADDRESS\n");
440 
441  if (comExt->IsFDO)
442  {
444  break;
445  }
446 
447  PSCSI_ADDRESS address = Irp->AssociatedIrp.SystemBuffer;
448  if (!VerifyIrpOutBufferSize(Irp, sizeof(*address)))
449  {
451  break;
452  }
453 
454  lunExt = DeviceObject->DeviceExtension;
455  portExt = comExt->LowerDevice->DeviceExtension;
456 
457  address->Length = sizeof(SCSI_ADDRESS);
458  address->PortNumber = portExt->PortNumber;
459  address->PathId = lunExt->PathId;
460  address->TargetId = lunExt->TargetId;
461  address->Lun = lunExt->Lun;
462 
463  Irp->IoStatus.Information = sizeof(SCSI_ADDRESS);
465  break;
466  }
468  {
469  DPRINT(" IOCTL_SCSI_GET_DUMP_POINTERS\n");
470 
471  if (!comExt->IsFDO)
472  {
474  return IoCallDriver(comExt->LowerDevice, Irp);
475  }
476 
477  PDUMP_POINTERS dumpPointers = Irp->AssociatedIrp.SystemBuffer;
478  if (!VerifyIrpOutBufferSize(Irp, sizeof(*dumpPointers)))
479  {
481  break;
482  }
483 
484  dumpPointers->DeviceObject = DeviceObject;
485  /* More data.. ? */
486 
488  Irp->IoStatus.Information = sizeof(DUMP_POINTERS);
489  break;
490  }
492  {
493  DPRINT(" IOCTL_SCSI_GET_CAPABILITIES\n");
494 
495  if (!comExt->IsFDO)
496  {
498  break;
499  }
500 
502  {
504  break;
505  }
506 
507  portExt = DeviceObject->DeviceExtension;
508 
509  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
510  &portExt->PortCapabilities,
511  sizeof(IO_SCSI_CAPABILITIES));
512 
514  Irp->IoStatus.Information = sizeof(IO_SCSI_CAPABILITIES);
515  break;
516  }
518  {
519  DPRINT(" IOCTL_SCSI_GET_INQUIRY_DATA\n");
520 
521  if (!comExt->IsFDO)
522  {
524  break;
525  }
526 
527  /* Copy inquiry data to the port device extension */
528  status = SpiGetInquiryData(DeviceObject->DeviceExtension, Irp);
529  break;
530  }
531  case IOCTL_SCSI_MINIPORT:
532  DPRINT1("IOCTL_SCSI_MINIPORT unimplemented!\n");
534  break;
535 
537  DPRINT1("IOCTL_SCSI_PASS_THROUGH unimplemented!\n");
539  break;
540 
541  default:
542  DPRINT1("unknown ioctl code: 0x%lX\n", Stack->Parameters.DeviceIoControl.IoControlCode);
544  break;
545  }
546 
547  /* Complete the request with the given status */
548  Irp->IoStatus.Status = status;
550 
551  return status;
552 }
return STATUS_NOT_SUPPORTED
#define IOCTL_SCSI_GET_ADDRESS
Definition: scsi_port.h:52
#define IOCTL_SCSI_MINIPORT
Definition: scsi_port.h:48
IO_SCSI_CAPABILITIES PortCapabilities
Definition: scsiport.c:79
#define IOCTL_SCSI_GET_DUMP_POINTERS
Definition: scsi_port.h:54
PDEVICE_OBJECT LowerDevice
Definition: scsiport.h:139
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
struct _DUMP_POINTERS DUMP_POINTERS
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
_In_ PIRP Irp
Definition: csq.h:116
static NTSTATUS SpiGetInquiryData(_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ PIRP Irp)
Definition: ioctl.c:18
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IOCTL_STORAGE_QUERY_PROPERTY
Definition: ntddstor.h:178
FORCEINLINE BOOLEAN VerifyIrpOutBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:145
GLuint address
Definition: glext.h:9393
FORCEINLINE BOOLEAN VerifyIrpInBufferSize(_In_ PIRP Irp, _In_ SIZE_T Size)
Definition: partmgr.h:160
#define IOCTL_SCSI_PASS_THROUGH
Definition: scsi_port.h:47
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define IOCTL_SCSI_GET_INQUIRY_DATA
Definition: scsi_port.h:49
static NTSTATUS PdoHandleQueryProperty(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: ioctl.c:147
static NTSTATUS FdoHandleQueryProperty(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: ioctl.c:293
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
#define IOCTL_SCSI_GET_CAPABILITIES
Definition: scsi_port.h:50
struct _SCSI_ADDRESS SCSI_ADDRESS
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
struct _IO_SCSI_CAPABILITIES IO_SCSI_CAPABILITIES
PVOID DeviceObject
Definition: ntddscsi.h:321
Definition: ps.c:97

Referenced by ScsiPortInitialize().

◆ SpiAdapterControl()

IO_ALLOCATION_ACTION NTAPI SpiAdapterControl ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_ PVOID  MapRegisterBase,
_In_ PVOID  Context 
)

◆ SpiGetNextRequestFromLun()

VOID SpiGetNextRequestFromLun ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
_Inout_ PSCSI_PORT_LUN_EXTENSION  LunExtension,
_Inout_opt_ PKIRQL  OldIrql 
)

Definition at line 342 of file scsi.c.

347 {
348  PIO_STACK_LOCATION IrpStack;
349  PIRP NextIrp;
352 
353 
354  /* If LUN is not active or queue is more than maximum allowed */
355  if (LunExtension->QueueCount >= LunExtension->MaxQueueCount ||
356  !(LunExtension->Flags & SCSI_PORT_LU_ACTIVE))
357  {
358  /* Release the spinlock and exit */
359  if (OldIrql != NULL)
360  KeReleaseSpinLock(&DeviceExtension->SpinLock, *OldIrql);
361  else
362  KeReleaseSpinLockFromDpcLevel(&DeviceExtension->SpinLock);
363  return;
364  }
365 
366  /* Check if we can get a next request */
367  if (LunExtension->Flags &
370  {
371  /* Pending requests can only be started if the queue is empty */
372  if (IsListEmpty(&LunExtension->SrbInfo.Requests) &&
373  !(LunExtension->Flags &
375  {
376  /* Make sure we have SRB */
377  ASSERT(LunExtension->SrbInfo.Srb == NULL);
378 
379  /* Clear active and pending flags */
380  LunExtension->Flags &= ~(LUNEX_REQUEST_PENDING | SCSI_PORT_LU_ACTIVE);
381 
382  /* Get next Irp, and clear pending requests list */
383  NextIrp = LunExtension->PendingRequest;
384  LunExtension->PendingRequest = NULL;
385 
386  /* Set attempt counter to zero */
387  LunExtension->AttemptCount = 0;
388 
389  /* Release the spinlock */
390  if (OldIrql != NULL)
391  KeReleaseSpinLock(&DeviceExtension->SpinLock, *OldIrql);
392  else
393  KeReleaseSpinLockFromDpcLevel(&DeviceExtension->SpinLock);
394 
395  /* Start the next pending request */
396  IoStartPacket(DeviceExtension->Common.DeviceObject, NextIrp, (PULONG)NULL, NULL);
397 
398  return;
399  }
400  else
401  {
402  /* Release the spinlock, without clearing any flags and exit */
403  if (OldIrql != NULL)
404  KeReleaseSpinLock(&DeviceExtension->SpinLock, *OldIrql);
405  else
406  KeReleaseSpinLockFromDpcLevel(&DeviceExtension->SpinLock);
407 
408  return;
409  }
410  }
411 
412  /* Reset active flag */
413  LunExtension->Flags &= ~SCSI_PORT_LU_ACTIVE;
414 
415  /* Set attempt counter to zero */
416  LunExtension->AttemptCount = 0;
417 
418  /* Remove packet from the device queue */
419  Entry = KeRemoveByKeyDeviceQueue(&LunExtension->DeviceQueue, LunExtension->SortKey);
420 
421  if (Entry != NULL)
422  {
423  /* Get pointer to the next irp */
424  NextIrp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.DeviceQueueEntry);
425 
426  /* Get point to the SRB */
427  IrpStack = IoGetCurrentIrpStackLocation(NextIrp);
428  Srb = (PSCSI_REQUEST_BLOCK)IrpStack->Parameters.Others.Argument1;
429 
430  /* Set new key*/
431  LunExtension->SortKey = Srb->QueueSortKey;
432  LunExtension->SortKey++;
433 
434  /* Release the spinlock */
435  if (OldIrql != NULL)
436  KeReleaseSpinLock(&DeviceExtension->SpinLock, *OldIrql);
437  else
438  KeReleaseSpinLockFromDpcLevel(&DeviceExtension->SpinLock);
439 
440  /* Start the next pending request */
441  IoStartPacket(DeviceExtension->Common.DeviceObject, NextIrp, (PULONG)NULL, NULL);
442  }
443  else
444  {
445  /* Release the spinlock */
446  if (OldIrql != NULL)
447  KeReleaseSpinLock(&DeviceExtension->SpinLock, *OldIrql);
448  else
449  KeReleaseSpinLockFromDpcLevel(&DeviceExtension->SpinLock);
450  }
451 }
#define LUNEX_FULL_QUEUE
Definition: scsiport.h:49
struct _Entry Entry
Definition: kefuncs.h:627
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
#define SCSI_PORT_LU_ACTIVE
Definition: scsiport.h:30
#define LUNEX_REQUEST_PENDING
Definition: scsiport.h:50
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VOID NTAPI IoStartPacket(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PULONG Key, IN PDRIVER_CANCEL CancelFunction)
Definition: device.c:1876
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define ASSERT(a)
Definition: mode.c:45
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define LUNEX_NEED_REQUEST_SENSE
Definition: scsiport.h:47
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
Definition: ketypes.h:566
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue, IN ULONG SortKey)
Definition: devqueue.c:197
IN PSCSI_REQUEST_BLOCK Srb
Definition: class2.h:49
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3124
#define LUNEX_BUSY
Definition: scsiport.h:48
base of all file and directory entries
Definition: entries.h:82
#define LUNEX_FROZEN_QUEUE
Definition: scsiport.h:46

Referenced by FdoSendInquiry(), ScsiPortDispatchScsi(), ScsiPortDpcForIsr(), SpiProcessCompletedRequest(), and SpiSenseCompletionRoutine().

◆ SpiGetSrbData()

PSCSI_REQUEST_BLOCK_INFO SpiGetSrbData ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
_In_ PSCSI_PORT_LUN_EXTENSION  LunExtension,
_In_ UCHAR  QueueTag 
)

Definition at line 102 of file pdo.c.

106 {
107  if (QueueTag == SP_UNTAGGED)
108  {
109  /* Return the pointer to SrbInfo */
110  return &LunExtension->SrbInfo;
111  }
112  else
113  {
114  /* Make sure the tag is valid, if it is - return the data */
115  if (QueueTag > DeviceExtension->SrbDataCount || QueueTag < 1)
116  return NULL;
117  else
118  return &DeviceExtension->SrbInfo[QueueTag -1];
119  }
120 }
#define SP_UNTAGGED
Definition: srb.h:225
#define NULL
Definition: types.h:112

Referenced by ScsiPortGetPhysicalAddress(), ScsiPortNotification(), ScsiPortStartPacket(), and SpiAllocateSrbStructures().

◆ SpiInitOpenKeys()

VOID SpiInitOpenKeys ( _Inout_ PCONFIGURATION_INFO  ConfigInfo,
_In_ PSCSI_PORT_DRIVER_EXTENSION  DriverExtension 
)

Definition at line 18 of file registry.c.

21 {
25  HANDLE parametersKey;
26 
27  DriverExtension->IsLegacyDriver = TRUE;
28 
29  /* Open the service key */
31  &DriverExtension->RegistryPath,
33  NULL,
34  NULL);
35 
36  Status = ZwOpenKey(&ConfigInfo->ServiceKey, KEY_READ, &ObjectAttributes);
37 
38  if (!NT_SUCCESS(Status))
39  {
40  DPRINT("Unable to open driver's registry key %wZ, status 0x%08x\n",
41  DriverExtension->RegistryPath, Status);
42  ConfigInfo->ServiceKey = NULL;
43  }
44 
45  /* If we could open driver's service key, then proceed to the Parameters key */
46  if (ConfigInfo->ServiceKey != NULL)
47  {
48  RtlInitUnicodeString(&KeyName, L"Parameters");
50  &KeyName,
52  ConfigInfo->ServiceKey,
53  NULL);
54 
55  /* Try to open it */
56  Status = ZwOpenKey(&ConfigInfo->DeviceKey, KEY_READ, &ObjectAttributes);
57 
58  if (NT_SUCCESS(Status))
59  {
60  /* Yes, Parameters key exist, and it must be used instead of
61  the Service key */
62  ZwClose(ConfigInfo->ServiceKey);
63  ConfigInfo->ServiceKey = ConfigInfo->DeviceKey;
64  ConfigInfo->DeviceKey = NULL;
65  }
66  }
67 
68  if (ConfigInfo->ServiceKey != NULL)
69  {
70  /* Open the Device key */
71  RtlInitUnicodeString(&KeyName, L"Device");
73  &KeyName,
75  ConfigInfo->ServiceKey,
76  NULL);
77 
78  /* We don't check for failure here - not needed */
79  ZwOpenKey(&ConfigInfo->DeviceKey, KEY_READ, &ObjectAttributes);
80 
81  // Detect the driver PnP capabilities via its Parameters\PnpInterface key
82  // for example: HKLM\SYSTEM\CurrentControlSet\Services\UNIATA\Parameters\PnpInterface
83 
84  RtlInitUnicodeString(&KeyName, L"PnpInterface");
86  &KeyName,
88  ConfigInfo->ServiceKey,
89  NULL);
90 
91  Status = ZwOpenKey(&parametersKey, KEY_READ, &ObjectAttributes);
92 
93  if (NT_SUCCESS(Status))
94  {
95  // if the key exists, it's enough for us for now
96  // (the proper check should iterate over INTERFACE_TYPE values)
97  DriverExtension->IsLegacyDriver = FALSE;
98  ZwClose(parametersKey);
99  }
100  }
101 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
#define NULL
Definition: types.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106

Referenced by ScsiPortInitialize().

◆ VerifyIrpInBufferSize()

FORCEINLINE BOOLEAN VerifyIrpInBufferSize ( _In_ PIRP  Irp,
_In_ SIZE_T  Size 
)

Definition at line 356 of file scsiport.h.

359 {
361  if (ioStack->Parameters.DeviceIoControl.InputBufferLength < Size)
362  {
363  Irp->IoStatus.Information = Size;
364  return FALSE;
365  }
366  return TRUE;
367 }
#define TRUE
Definition: types.h:120
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3124

◆ VerifyIrpOutBufferSize()

FORCEINLINE BOOLEAN VerifyIrpOutBufferSize ( _In_ PIRP  Irp,
_In_ SIZE_T  Size 
)

Definition at line 341 of file scsiport.h.

344 {
346  if (ioStack->Parameters.DeviceIoControl.OutputBufferLength < Size)
347  {
348  Irp->IoStatus.Information = Size;
349  return FALSE;
350  }
351  return TRUE;
352 }
#define TRUE
Definition: types.h:120
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3124

Variable Documentation

◆ ScsiPortDispatchPower

DRIVER_DISPATCH ScsiPortDispatchPower

Definition at line 426 of file scsiport.h.

Referenced by ScsiPortInitialize().

◆ ScsiPortDispatchScsi

DRIVER_DISPATCH ScsiPortDispatchScsi

Definition at line 452 of file scsiport.h.

Referenced by ScsiPortInitialize().

◆ ScsiPortDpcForIsr

IO_DPC_ROUTINE ScsiPortDpcForIsr

Definition at line 451 of file scsiport.h.

Referenced by FdoCallHWInitialize(), ScsiPortInitialize(), and SpiMiniportTimerDpc().

◆ ScsiPortIsr

KSERVICE_ROUTINE ScsiPortIsr

Definition at line 459 of file scsiport.h.

Referenced by FdoCallHWInitialize().

◆ ScsiPortStartIo

DRIVER_STARTIO ScsiPortStartIo

Definition at line 454 of file scsiport.h.

Referenced by ScsiPortInitialize().

◆ ScsiPortStartPacket

KSYNCHRONIZE_ROUTINE ScsiPortStartPacket