Skip to content

Commit ccf25e0

Browse files
committed
Initial release
0 parents  commit ccf25e0

File tree

13 files changed

+3794
-0
lines changed

13 files changed

+3794
-0
lines changed

LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) <year>, <copyright holder>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
3. Neither the name of the copyright holder nor the names of its
13+
contributors may be used to endorse or promote products derived from
14+
this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# NVMe2K - NVMe Driver for Windows 2000
2+
3+
A NVMe (Non-Volatile Memory Express) storage controller driver for Windows 2000, targeting both x86 and Alpha AXP platforms.
4+
5+
## Overview
6+
7+
NVMe2K is a SCSI miniport driver that provides NVMe device support for Windows 2000. It uses the ScsiPort framework to integrate NVMe solid-state drives with the Windows 2000 storage stack.
8+
9+
### Why?
10+
11+
It seemed like a good idea at first.
12+
13+
## Features
14+
15+
- **Full NVMe 1.0 specification support**
16+
- Single I/O queue pair (scalable architecture)
17+
- Admin queue for device management
18+
- PRP (Physical Region Page) based data transfers
19+
- Up to 2MB transfer sizes via PRP lists
20+
21+
- **SCSI Translation Layer**
22+
- Translates SCSI commands to NVMe commands
23+
- Tagged command queuing support
24+
- Ordered queue tag support with automatic flush
25+
- READ/WRITE/FLUSH/INQUIRY/READ_CAPACITY commands
26+
27+
- **Advanced Features**
28+
- SMP-safe with configurable locking (`NVME2K_USE_*_LOCK` defines)
29+
- Custom atomic operations for x86 and Alpha AXP
30+
- Proper alignment for Alpha 64-bit pointers
31+
- Non-tagged request serialization
32+
- Queue depth management and statistics
33+
34+
- **Multi-Platform Support**
35+
- x86 (Pentium and later)
36+
- Alpha AXP (DEC Alpha workstations/servers)
37+
38+
## Architecture
39+
40+
```
41+
Application Layer
42+
43+
SCSI Disk Driver
44+
45+
ScsiPort.sys
46+
47+
nvme2k.sys ← This driver
48+
49+
NVMe Controller (PCI)
50+
```
51+
52+
### Key Components
53+
54+
- **atomic.h** - Platform-specific atomic operations (x86 inline asm, Alpha LL/SC)
55+
- **nvme2k.c** - Main driver logic, SCSI translation, NVMe command handling
56+
- **nvme2k.h** - Data structures, constants, NVMe register definitions
57+
- **nvme2k.inf** - Multi-platform installation file
58+
59+
## Building
60+
61+
### Requirements
62+
63+
- **Windows 2000 DDK**
64+
- Final version (5.00.2195.1) for x86
65+
- RC1 version for Alpha AXP
66+
67+
- **Visual C++ 6.0**
68+
- x86 compiler for x86 builds
69+
- Alpha AXP compiler for Alpha builds
70+
71+
### Build Instructions
72+
73+
#### For x86:
74+
75+
```cmd
76+
REM Set up build environment
77+
cd C:\NTDDK\bin
78+
setenv.bat free REM or 'checked' for debug build
79+
80+
REM Navigate to driver directory
81+
cd <path-to-nvme2k>
82+
83+
REM Build
84+
build -cZ
85+
```
86+
87+
Output: `obj\i386\nvme2k.sys`
88+
89+
#### For Alpha AXP:
90+
91+
```cmd
92+
REM Set up build environment for Alpha
93+
cd C:\NTDDK\bin
94+
setenv.bat free alpha REM or 'checked' for debug build
95+
96+
REM Navigate to driver directory
97+
cd <path-to-nvme2k>
98+
99+
REM Build
100+
build -cZ
101+
```
102+
103+
Output: `obj\alpha\nvme2k.sys`
104+
105+
### Build Options
106+
107+
Edit `nvme2k.h` to configure:
108+
109+
```c
110+
#define NVME2K_DBG // Enable debug logging
111+
// #define NVME2K_DBG_CMD // Extra verbose command logging
112+
113+
// Locking control (comment out to disable)
114+
#define NVME2K_USE_INTERRUPT_LOCK // Serialize HwInterrupt on SMP
115+
#define NVME2K_USE_SUBMISSION_LOCK // Serialize command submission
116+
#define NVME2K_USE_COMPLETION_LOCK // Serialize completion processing
117+
```
118+
119+
## Installation
120+
121+
### Creating Installation Media
122+
123+
Create the following directory structure:
124+
125+
```
126+
DriverDisk\
127+
├── nvme2k.inf
128+
├── i386\
129+
│ └── nvme2k.sys (x86 binary)
130+
└── alpha\
131+
└── nvme2k.sys (Alpha AXP binary)
132+
```
133+
134+
### Installing
135+
136+
1. Copy driver files to installation media
137+
2. Boot Windows 2000
138+
3. Use Device Manager or Add Hardware Wizard
139+
4. Point to the driver location when prompted
140+
5. Select "NVMe Storage Controller (Windows 2000)"
141+
142+
**Note:** The driver requires NVMe devices to be visible on the PCI bus with class code `01-08-02` (Mass Storage - Non-Volatile Memory - NVMe).
143+
144+
## Configuration
145+
146+
The driver supports registry-based configuration via the INF file:
147+
148+
- **MaximumSGList** (Default: 512) - Maximum scatter-gather list entries
149+
- **NumberOfRequests** (Default: 64) - Queue depth
150+
- **MaxQueueDepth** (Default: 64) - Tagged command queue depth
151+
152+
## Debugging
153+
154+
Enable checked (debug) builds and use WinDbg with the Windows 2000 kernel debugger:
155+
156+
```
157+
!scsiport.miniport <DeviceExtension>
158+
!devobj <DeviceObject>
159+
```
160+
161+
Debug messages are output via `ScsiDebugPrint()` and visible in checked builds.
162+
163+
## Known Limitations
164+
165+
- Single I/O queue pair (no multi-queue support)
166+
- No MSI/MSI-X interrupt support (uses legacy INTx)
167+
- Maximum 10 concurrent large transfers (PRP list pool limitation)
168+
- No namespace management (assumes namespace 1)
169+
- No power management features
170+
- Tested primarily in virtualized environments and Windows 2000 RC2 on Alpha
171+
172+
## Technical Notes
173+
174+
### Synchronization Model
175+
176+
The driver uses multiple synchronization strategies:
177+
178+
1. **InterruptLock** - Prevents concurrent ISR execution on SMP systems
179+
2. **SubmissionLock** - Protects submission queue tail pointer
180+
3. **CompletionLock** - Serializes completion queue processing
181+
4. **NonTaggedInFlight** - Ensures only one non-tagged request at a time
182+
183+
All locks can be disabled via `#define` for performance testing.
184+
185+
### Memory Allocation
186+
187+
- **Uncached Extension** - 64KB for queues and PRP lists (DMA-accessible)
188+
- **Admin Queue** - 4KB submission + 4KB completion (power-of-2 sized)
189+
- **I/O Queue** - 4KB submission + 4KB completion (power-of-2 sized)
190+
- **PRP List Pool** - 40KB (10 pages) for scatter-gather
191+
192+
### Command ID Encoding
193+
194+
```
195+
Bit 15: Non-tagged flag (1 = non-tagged, 0 = tagged)
196+
Bit 14: Ordered flush flag (for ORDERED queue tags)
197+
Bits 0-13: QueueTag (tagged) or sequence number (non-tagged)
198+
```
199+
200+
## License
201+
202+
This project is licensed under the **3-Clause BSD License**. See the [LICENSE](LICENSE) file for the full license text.
203+
204+
**USE AT YOUR OWN RISK.** This driver is experimental and may cause data loss, system instability, or hardware damage. Not recommended for production use.
205+
206+
### Summary
207+
208+
- ✅ Free to use, modify, and distribute
209+
- ✅ Commercial use permitted
210+
- ✅ Modification and redistribution allowed
211+
- ⚠️ No warranty provided
212+
- ⚠️ Use at your own risk
213+
214+
## Contributing
215+
216+
Feel free to submit issues or pull requests. Areas of interest:
217+
218+
- Multi-queue support
219+
- MSI-X interrupt support
220+
- Power management
221+
- Additional SCSI command translations
222+
- Performance optimizations
223+
224+
## Acknowledgments
225+
226+
- NVMe specification authors
227+
- Windows 2000 DDK documentation
228+
- Alpha AXP architecture documentation
229+
- Everyone who thought this was a terrible idea (you were right)
230+
231+
---
232+
233+
**Disclaimer:** This is an unofficial, community-developed driver. Not affiliated with Microsoft, Intel, or the NVMe standards body.

atomic.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//
2+
// atomic.h - Atomic operations and synchronization primitives
3+
// Windows 2000 ScsiPort miniport drivers cannot use kernel InterlockedXxx functions
4+
// so we implement them using inline assembly for x86 and Alpha AXP
5+
//
6+
7+
#ifndef _ATOMIC_H_
8+
#define _ATOMIC_H_
9+
10+
//
11+
// ATOMIC type - Use this for variables that need atomic access
12+
// This is just volatile ULONG, but makes code more self-documenting
13+
//
14+
typedef volatile ULONG ATOMIC;
15+
16+
//
17+
// Atomic operations for SMP safety
18+
//
19+
#if defined(_M_IX86)
20+
21+
// x86 inline assembly for atomic increment
22+
// Returns the NEW value (after increment)
23+
static __inline ULONG AtomicIncrement(volatile ULONG *Addend)
24+
{
25+
ULONG result;
26+
__asm {
27+
mov ecx, Addend
28+
mov eax, 1
29+
lock xadd dword ptr [ecx], eax
30+
inc eax
31+
mov result, eax
32+
}
33+
return result;
34+
}
35+
36+
// x86 inline assembly for atomic read (with memory barrier)
37+
static __inline ULONG AtomicRead(volatile ULONG *Value)
38+
{
39+
ULONG result;
40+
__asm {
41+
mov ecx, Value
42+
mov eax, dword ptr [ecx]
43+
mov result, eax
44+
}
45+
return result;
46+
}
47+
48+
// x86 inline assembly for atomic compare-exchange
49+
// Returns TRUE if exchange succeeded, FALSE otherwise
50+
static __inline BOOLEAN AtomicCompareExchange(volatile ULONG *Destination, ULONG Exchange, ULONG Comparand)
51+
{
52+
ULONG result;
53+
__asm {
54+
mov ecx, Destination
55+
mov edx, Exchange
56+
mov eax, Comparand
57+
lock cmpxchg dword ptr [ecx], edx
58+
setz al
59+
movzx eax, al
60+
mov result, eax
61+
}
62+
return (BOOLEAN)result;
63+
}
64+
65+
// x86 inline assembly for atomic write (with memory barrier)
66+
static __inline VOID AtomicSet(volatile ULONG *Destination, ULONG Value)
67+
{
68+
__asm {
69+
mov ecx, Destination
70+
mov eax, Value
71+
lock xchg dword ptr [ecx], eax
72+
}
73+
}
74+
75+
#elif defined(_M_ALPHA)
76+
77+
// Alpha AXP atomic operations implemented in assembly (atomic_alpha.s)
78+
// MSVC for Alpha doesn't support __asm blocks, so we use external assembly
79+
80+
#ifdef __cplusplus
81+
extern "C" {
82+
#endif
83+
84+
// Atomic operations implemented in atomic_alpha.s
85+
ULONG AtomicIncrement(volatile ULONG *Addend);
86+
ULONG AtomicRead(volatile ULONG *Value);
87+
BOOLEAN AtomicCompareExchange(volatile ULONG *Destination, ULONG Exchange, ULONG Comparand);
88+
VOID AtomicSet(volatile ULONG *Destination, ULONG Value);
89+
90+
#ifdef __cplusplus
91+
}
92+
#endif
93+
94+
#else
95+
#error "Unsupported architecture - need atomic operations for x86 or Alpha AXP"
96+
#endif
97+
98+
#endif // _ATOMIC_H_

makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
3+
# file to this component. This file merely indirects to the real make file
4+
# that is shared by all the components of Windows NT
5+
#
6+
!INCLUDE $(NTMAKEENV)\makefile.def
7+

makefile.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)