~ubuntu-branches/ubuntu/lucid/ndiswrapper/lucid

« back to all changes in this revision

Viewing changes to driver/ndis.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-09-30 14:56:14 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050930145614-eh1a93tehp8nszrm
Tags: 1.1-4ubuntu2
debian/control: Update description to point out that the kernel source
package is not required with the standard Ubuntu kernel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2003-2004 Pontus Fuchs, Giridhar Pemmasani
 
2
 *  Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
5
 *  it under the terms of the GNU General Public License as published by
27
27
#include "iw_ndis.h"
28
28
#include "wrapper.h"
29
29
 
30
 
extern struct list_head ndis_driver_list;
 
30
extern struct list_head ndis_drivers;
 
31
extern KSPIN_LOCK ntoskernel_lock;
31
32
 
32
 
struct list_head handle_ctx_list;
33
 
struct wrap_spinlock atomic_lock;
34
 
struct wrap_spinlock cancel_lock;
 
33
static struct list_head handle_ctx_list;
35
34
 
36
35
static struct work_struct ndis_work;
37
36
static struct list_head ndis_work_list;
38
 
static struct wrap_spinlock ndis_work_list_lock;
 
37
static KSPIN_LOCK ndis_work_list_lock;
39
38
 
40
39
static void ndis_worker(void *data);
41
 
static void wrap_free_timers(struct ndis_handle *handle);
42
40
static void free_handle_ctx(struct ndis_handle *handle);
43
41
 
 
42
/* Some drivers allocate all NDIS_PACKETs they need at the beginning
 
43
 * and others allocate them quite often - every time a packet is
 
44
 * sent/received. We use cache pool for this to avoid memory
 
45
 * fragmentation, just like MDLs */
 
46
static kmem_cache_t *packet_cache;
 
47
 
44
48
/* ndis_init is called once when module is loaded */
45
49
int ndis_init(void)
46
50
{
48
52
        INIT_WORK(&ndis_work, &ndis_worker, NULL);
49
53
        INIT_LIST_HEAD(&ndis_work_list);
50
54
        INIT_LIST_HEAD(&handle_ctx_list);
51
 
        wrap_spin_lock_init(&ndis_work_list_lock);
52
 
 
53
 
        wrap_spin_lock_init(&atomic_lock);
54
 
        wrap_spin_lock_init(&cancel_lock);
 
55
        kspin_lock_init(&ndis_work_list_lock);
 
56
        packet_cache = kmem_cache_create("ndis_packet",
 
57
                                         sizeof(struct ndis_packet), 0, 0,
 
58
                                         NULL, NULL);
 
59
        if (!packet_cache) {
 
60
                ERROR("couldn't allocate packet cache");
 
61
                return -ENOMEM;
 
62
        }
55
63
        return 0;
56
64
}
57
65
 
 
66
/* ndis_exit is called once when module is removed */
 
67
void ndis_exit(void)
 
68
{
 
69
        if (packet_cache && kmem_cache_destroy(packet_cache))
 
70
                ERROR("A Windows driver didn't free all packet(s);"
 
71
                      "memory is leaking");
 
72
        return;
 
73
}
 
74
 
58
75
/* ndis_exit_handle is called for each handle */
59
76
void ndis_exit_handle(struct ndis_handle *handle)
60
77
{
61
 
        struct miniport_char *miniport = &handle->driver->miniport_char;
62
 
 
63
78
        /* TI driver doesn't call NdisMDeregisterInterrupt during halt! */
64
 
        if (handle->ndis_irq) {
65
 
                unsigned long flags;
66
 
 
67
 
                spin_lock_irqsave(K_SPINLOCK(&(handle->ndis_irq->lock)), flags);
68
 
                if (miniport->disable_interrupts)
69
 
                        miniport->disable_interrupts(handle->adapter_ctx);
70
 
                spin_unlock_irqrestore(K_SPINLOCK(&(handle->ndis_irq->lock)),
71
 
                                       flags);
 
79
        if (handle->ndis_irq)
72
80
                NdisMDeregisterInterrupt(handle->ndis_irq);
73
 
        }
74
 
        wrap_free_timers(handle);
75
81
        free_handle_ctx(handle);
76
 
}
77
 
 
78
 
/* ndis_exit is called once when module is removed */
79
 
void ndis_exit(void)
80
 
{
81
 
        wrap_kfree_all();
82
 
}
83
 
 
84
 
static void wrap_free_timers(struct ndis_handle *handle)
85
 
{
86
 
        char canceled;
87
 
        /* Cancel any timers left by bugyy windows driver
88
 
         * Also free the memory for timers
89
 
         */
90
 
        while (1) {
91
 
                struct wrapper_timer *timer;
92
 
                wrap_spin_lock(&handle->timers_lock, DISPATCH_LEVEL);
93
 
                if (list_empty(&handle->timers)) {
94
 
                        wrap_spin_unlock(&handle->timers_lock);
95
 
                        break;
96
 
                }
97
 
 
98
 
                timer = (struct wrapper_timer *)handle->timers.next;
99
 
                list_del(&timer->list);
100
 
                wrap_spin_unlock(&handle->timers_lock);
101
 
 
102
 
                DBGTRACE1("fixing up timer %p, timer->list %p",
103
 
                          timer, &timer->list);
104
 
                wrapper_cancel_timer(timer, &canceled);
105
 
                wrap_kfree(timer);
106
 
        }
 
82
        if (handle->pci_resources)
 
83
                vfree(handle->pci_resources);
107
84
}
108
85
 
109
86
/* remove all 'handle X ctx' pairs for the given handle */
110
87
static void free_handle_ctx(struct ndis_handle *handle)
111
88
{
112
 
        struct list_head *curr, *tmp;
 
89
        struct list_head *cur, *tmp;
113
90
 
114
 
        wrap_spin_lock(&atomic_lock, PASSIVE_LEVEL);
115
 
        list_for_each_safe(curr, tmp, &handle_ctx_list) {
 
91
        kspin_lock(&ntoskernel_lock);
 
92
        list_for_each_safe(cur, tmp, &handle_ctx_list) {
116
93
                struct handle_ctx_entry *handle_ctx =
117
 
                        (struct handle_ctx_entry *)curr;
 
94
                        list_entry(cur, struct handle_ctx_entry, list);
118
95
                if (handle_ctx->handle == handle) {
119
96
                        list_del(&handle_ctx->list);
120
97
                        kfree(handle_ctx);
121
98
                }
122
99
        }
123
 
        wrap_spin_unlock(&atomic_lock);
 
100
        kspin_unlock(&ntoskernel_lock);
124
101
        return;
125
102
}
126
103
 
127
104
/* Called from the driver entry. */
128
 
STDCALL static void WRAP_EXPORT(NdisInitializeWrapper)
 
105
STDCALL void WRAP_EXPORT(NdisInitializeWrapper)
129
106
        (struct ndis_handle **ndis_handle, void *SystemSpecific1,
130
107
         void *SystemSpecific2, void *SystemSpecific3)
131
108
{
135
112
        TRACEEXIT1(return);
136
113
}
137
114
 
138
 
STDCALL static void WRAP_EXPORT(NdisTerminateWrapper)
 
115
STDCALL void WRAP_EXPORT(NdisTerminateWrapper)
139
116
        (struct ndis_handle *handle, void *SystemSpecific1)
140
117
{
141
118
        TRACEEXIT1(return);
142
119
}
143
120
 
144
121
/* Register a miniport with NDIS. Called from driver entry */
145
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMRegisterMiniport)
 
122
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMRegisterMiniport)
146
123
        (struct ndis_driver *ndis_driver,
147
124
         struct miniport_char *miniport_char, UINT char_len)
148
125
{
149
 
        int min_length = ((char *) &miniport_char->co_create_vc) -
 
126
        int i, min_length;
 
127
        int *func;
 
128
        char *miniport_funcs[] = {
 
129
                "query",
 
130
                "reconfig",
 
131
                "reset",
 
132
                "send",
 
133
                "setinfo",
 
134
                "tx_data",
 
135
                "return_packet",
 
136
                "send_packets",
 
137
                "alloc_complete",
 
138
                "co_create_vc",
 
139
                "co_delete_vc",
 
140
                "co_activate_vc",
 
141
                "co_deactivate_vc",
 
142
                "co_send_packets",
 
143
                "co_request",
 
144
                "cancel_send_packets",
 
145
                "pnp_event_notify",
 
146
                "adapter_shutdown",
 
147
        };
 
148
 
 
149
        min_length = ((char *) &miniport_char->co_create_vc) -
150
150
                ((char *) miniport_char);
151
151
 
152
 
        TRACEENTER1("driver: %p", ndis_driver);
 
152
        TRACEENTER1("driver: %p %p %d", ndis_driver, miniport_char, char_len);
153
153
 
154
154
        if (miniport_char->majorVersion < 4) {
155
155
                ERROR("Driver %s using ndis version %d which is too old.",
164
164
        }
165
165
 
166
166
        DBGTRACE1("Version %d.%d", miniport_char->majorVersion,
167
 
                 miniport_char->minorVersion);
168
 
        DBGTRACE1("Len: %08x:%lu", char_len, sizeof(struct miniport_char));
 
167
                  miniport_char->minorVersion);
 
168
        DBGTRACE1("Len: %08x:%u", char_len, (u32)sizeof(struct miniport_char));
169
169
        memcpy(&ndis_driver->miniport_char, miniport_char,
170
170
               sizeof(struct miniport_char));
171
171
 
 
172
        i = 0;
 
173
        func = (int *)&ndis_driver->miniport_char.query;
 
174
        while (i < sizeof(miniport_funcs) / sizeof(miniport_funcs[0])) {
 
175
                DBGTRACE2("miniport function '%s' is at %lx",
 
176
                          miniport_funcs[i], (unsigned long)func[i]);
 
177
                i++;
 
178
        }
 
179
 
172
180
        TRACEEXIT1(return NDIS_STATUS_SUCCESS);
173
181
}
174
182
 
175
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisAllocateMemory)
 
183
STDCALL NDIS_STATUS WRAP_EXPORT(NdisAllocateMemory)
176
184
        (void **dest, UINT length, UINT flags,
177
 
         NDIS_PHY_ADDRESS highest_addr)
 
185
         NDIS_PHY_ADDRESS highest_address)
178
186
{
179
187
        TRACEENTER3("length = %u, flags = %08X", length, flags);
180
188
        if (length <= KMALLOC_THRESHOLD) {
181
 
                if (KeGetCurrentIrql() == PASSIVE_LEVEL)
182
 
                        *dest = (void *)kmalloc(length,
183
 
                                                GFP_KERNEL | __GFP_NOWARN);
 
189
                if (current_irql() < DISPATCH_LEVEL)
 
190
                        *dest = kmalloc(length, GFP_KERNEL);
184
191
                else
185
 
                        *dest = (void *)kmalloc(length,
186
 
                                                GFP_ATOMIC | __GFP_NOWARN);
 
192
                        *dest = kmalloc(length, GFP_ATOMIC);
187
193
        } else if (flags & NDIS_MEMORY_CONTIGUOUS) {
188
194
                WARNING("Allocating %u bytes of physically "
189
195
                       "contiguous memory may fail", length);
190
 
                *dest = (void *)kmalloc(length, GFP_KERNEL | __GFP_NOWARN);
191
 
        } else
 
196
                *dest = kmalloc(length, GFP_KERNEL);
 
197
        } else {
 
198
                if (current_irql() == DISPATCH_LEVEL)
 
199
                        ERROR("Windows driver allocating too big a block"
 
200
                              " at DISPATCH_LEVEL: %d", length);
192
201
                *dest = vmalloc(length);
 
202
        }
193
203
 
194
204
        if (*dest)
195
205
                TRACEEXIT3(return NDIS_STATUS_SUCCESS);
197
207
        TRACEEXIT3(return NDIS_STATUS_FAILURE);
198
208
}
199
209
 
200
 
STDCALL static unsigned int WRAP_EXPORT(NdisAllocateMemoryWithTag)
 
210
STDCALL NDIS_STATUS WRAP_EXPORT(NdisAllocateMemoryWithTag)
201
211
        (void **dest, UINT length, ULONG tag)
202
212
{
203
 
        NDIS_PHY_ADDRESS addr;
204
 
        addr.quad = 0;
205
 
        TRACEEXIT3(return NdisAllocateMemory(dest, length, 0, addr));
 
213
        TRACEEXIT3(return NdisAllocateMemory(dest, length, 0, 0));
206
214
}
207
215
 
208
 
STDCALL static void WRAP_EXPORT(NdisFreeMemory)
 
216
STDCALL void WRAP_EXPORT(NdisFreeMemory)
209
217
        (void *addr, UINT length, UINT flags)
210
218
{
211
219
        struct ndis_work_entry *ndis_work_entry;
212
220
        struct ndis_free_mem_work_item *free_mem;
 
221
        KIRQL irql;
213
222
 
214
 
        TRACEENTER3("length = %u, flags = %08X", length, flags);
 
223
        TRACEENTER3("addr = %p, flags = %08X", addr, flags);
215
224
 
216
225
        if (!addr)
217
226
                TRACEEXIT3(return);
241
250
                free_mem->length = length;
242
251
                free_mem->flags = flags;
243
252
 
244
 
                wrap_spin_lock(&ndis_work_list_lock, PASSIVE_LEVEL);
 
253
                irql = kspin_lock_irql(&ndis_work_list_lock, DISPATCH_LEVEL);
245
254
                list_add_tail(&ndis_work_entry->list, &ndis_work_list);
246
 
                wrap_spin_unlock(&ndis_work_list_lock);
 
255
                kspin_unlock_irql(&ndis_work_list_lock, irql);
247
256
 
248
257
                schedule_work(&ndis_work);
249
258
        }
254
263
/*
255
264
 * This function should not be STDCALL because it's a variable args function.
256
265
 */
257
 
NOREGPARM static void WRAP_EXPORT(NdisWriteErrorLogEntry)
 
266
NOREGPARM void WRAP_EXPORT(NdisWriteErrorLogEntry)
258
267
        (struct ndis_handle *handle, unsigned int error, ULONG count,
259
268
         unsigned int p1)
260
269
{
261
 
        ERROR("log: %08X, count: %d (%08x)\n", error, count, p1);
 
270
        ERROR("log: %08X, count: %d (%08x), return address: %p, entry: %p"
 
271
              " offset: %lu", error, count, p1, __builtin_return_address(0),
 
272
              handle->driver->entry,
 
273
              (unsigned long)addr_offset(handle->driver));
 
274
        return;
262
275
}
263
276
 
264
 
STDCALL static void WRAP_EXPORT(NdisOpenConfiguration)
 
277
STDCALL void WRAP_EXPORT(NdisOpenConfiguration)
265
278
        (NDIS_STATUS *status, struct ndis_handle **confhandle,
266
279
         struct ndis_handle *handle)
267
280
{
272
285
        TRACEEXIT2(return);
273
286
}
274
287
 
275
 
STDCALL static void WRAP_EXPORT(NdisOpenProtocolConfiguration)
 
288
STDCALL void WRAP_EXPORT(NdisOpenProtocolConfiguration)
276
289
        (NDIS_STATUS *status, struct ndis_handle **confhandle,
277
 
         struct ustring *section)
 
290
         struct unicode_string *section)
278
291
{
279
292
        TRACEENTER2("confHandle: %p", confhandle);
280
293
        *confhandle = (struct ndis_handle *)section;
282
295
        TRACEEXIT2(return);
283
296
}
284
297
 
285
 
STDCALL static void WRAP_EXPORT(NdisOpenConfigurationKeyByName)
286
 
        (NDIS_STATUS *status, struct ndis_handle *handle, struct ustring *key,
287
 
         struct ndis_handle **subkeyhandle)
 
298
STDCALL void WRAP_EXPORT(NdisOpenConfigurationKeyByName)
 
299
        (NDIS_STATUS *status, struct ndis_handle *handle,
 
300
         struct unicode_string *key, struct ndis_handle **subkeyhandle)
288
301
{
289
302
        TRACEENTER2("%s", "");
290
303
        *subkeyhandle = handle;
292
305
        TRACEEXIT2(return);
293
306
}
294
307
 
295
 
STDCALL static void WRAP_EXPORT(NdisOpenConfigurationKeyByIndex)
 
308
STDCALL void WRAP_EXPORT(NdisOpenConfigurationKeyByIndex)
296
309
        (NDIS_STATUS *status, struct ndis_handle *handle, ULONG index,
297
 
         struct ustring *key, struct ndis_handle **subkeyhandle)
 
310
         struct unicode_string *key, struct ndis_handle **subkeyhandle)
298
311
{
299
312
        TRACEENTER2("%s", "");
300
313
        *subkeyhandle = handle;
302
315
        TRACEEXIT2(return);
303
316
}
304
317
 
305
 
STDCALL static void WRAP_EXPORT(NdisCloseConfiguration)
 
318
STDCALL void WRAP_EXPORT(NdisCloseConfiguration)
306
319
        (struct ndis_handle *handle)
307
320
{
308
321
        TRACEENTER2("handle: %p", handle);
309
322
        return;
310
323
}
311
324
 
312
 
STDCALL static void WRAP_EXPORT(NdisOpenFile)
 
325
STDCALL void WRAP_EXPORT(NdisOpenFile)
313
326
        (NDIS_STATUS *status, struct ndis_bin_file **filehandle,
314
 
         UINT *filelength, struct ustring *filename,
 
327
         UINT *filelength, struct unicode_string *filename,
315
328
         NDIS_PHY_ADDRESS highest_address)
316
329
{
317
 
        struct ustring ansi;
318
 
        struct list_head *curr, *tmp;
 
330
        struct ansi_string ansi;
 
331
        struct list_head *cur, *tmp;
319
332
        struct ndis_bin_file *file;
320
333
 
321
334
        TRACEENTER2("status = %p, filelength = %p, *filelength = %d, "
322
 
                    "filehandle = %p, *filehandle = %p",
 
335
                    "high = %llx, filehandle = %p, *filehandle = %p",
323
336
                    status, filelength, *filelength,
324
 
                    filehandle, *filehandle);
 
337
                    highest_address, filehandle, *filehandle);
325
338
 
326
339
        ansi.buf = kmalloc(MAX_STR_LEN, GFP_KERNEL);
327
340
        if (!ansi.buf) {
339
352
        DBGTRACE2("Filename: %s", ansi.buf);
340
353
 
341
354
        /* Loop through all drivers and all files to find the requested file */
342
 
        list_for_each_safe(curr, tmp, &ndis_driver_list) {
 
355
        list_for_each_safe(cur, tmp, &ndis_drivers) {
 
356
                struct ndis_driver *driver;
343
357
                int i;
344
 
                struct ndis_driver *driver = (struct ndis_driver *) curr;
345
358
 
346
 
                for (i = 0; i < driver->nr_bin_files; i++) {
 
359
                driver = list_entry(cur, struct ndis_driver, list);
 
360
                for (i = 0; i < driver->num_bin_files; i++) {
347
361
                        int n;
348
 
                        file = driver->bin_files[i];
 
362
                        file = &driver->bin_files[i];
349
363
                        DBGTRACE2("considering %s", file->name);
350
364
                        n = min(strlen(file->name), strlen(ansi.buf));
351
365
                        if (strnicmp(file->name, ansi.buf, n) == 0) {
362
376
        TRACEEXIT2(return);
363
377
}
364
378
 
365
 
STDCALL static void WRAP_EXPORT(NdisMapFile)
 
379
STDCALL void WRAP_EXPORT(NdisMapFile)
366
380
        (NDIS_STATUS *status, void **mappedbuffer,
367
381
         struct ndis_bin_file *filehandle)
368
382
{
378
392
        TRACEEXIT2(return);
379
393
}
380
394
 
381
 
STDCALL static void WRAP_EXPORT(NdisUnmapFile)
382
 
        (struct ndis_bin_file *filehandle)
383
 
{
384
 
        TRACEENTER2("handle: %p", filehandle);
385
 
        TRACEEXIT2(return);
386
 
}
387
 
 
388
 
STDCALL static void WRAP_EXPORT(NdisCloseFile)
389
 
        (struct ndis_bin_file *filehandle)
390
 
{
391
 
        TRACEENTER2("handle: %p", filehandle);
392
 
        TRACEEXIT2(return);
393
 
}
394
 
 
395
 
STDCALL static void WRAP_EXPORT(NdisGetSystemUpTime)
 
395
STDCALL void WRAP_EXPORT(NdisUnmapFile)
 
396
        (struct ndis_bin_file *filehandle)
 
397
{
 
398
        TRACEENTER2("handle: %p", filehandle);
 
399
        TRACEEXIT2(return);
 
400
}
 
401
 
 
402
STDCALL void WRAP_EXPORT(NdisCloseFile)
 
403
        (struct ndis_bin_file *filehandle)
 
404
{
 
405
        TRACEENTER2("handle: %p", filehandle);
 
406
        TRACEEXIT2(return);
 
407
}
 
408
 
 
409
STDCALL void WRAP_EXPORT(NdisGetSystemUpTime)
396
410
        (ULONG *systemuptime)
397
411
{
398
412
        TRACEENTER4("%s", "");
402
416
 
403
417
/* called as macro */
404
418
STDCALL ULONG WRAP_EXPORT(NDIS_BUFFER_TO_SPAN_PAGES)
405
 
        (struct ndis_buffer *buffer)
 
419
        (ndis_buffer *buffer)
406
420
{
407
421
        ULONG_PTR start;
408
422
        ULONG n;
412
426
        if (buffer == NULL)
413
427
                return 0;
414
428
 
415
 
        if (buffer->len == 0)
 
429
        if (MmGetMdlByteCount(buffer) == 0)
416
430
                return 1;
417
431
 
418
 
        start = (ULONG_PTR)(((char *)buffer->data) + buffer->offset);
419
 
        n = SPAN_PAGES(start, buffer->len);
 
432
        start = (ULONG_PTR)(MmGetMdlVirtualAddress(buffer));
 
433
        n = SPAN_PAGES(start, MmGetMdlByteCount(buffer));
420
434
        DBGTRACE4("pages = %u", n);
421
435
        TRACEEXIT3(return n);
422
436
}
423
437
 
424
 
STDCALL static void WRAP_EXPORT(NdisGetBufferPhysicalArraySize)
425
 
        (struct ndis_buffer *buffer, UINT *arraysize)
 
438
STDCALL void WRAP_EXPORT(NdisGetBufferPhysicalArraySize)
 
439
        (ndis_buffer *buffer, UINT *arraysize)
426
440
{
427
441
        TRACEENTER3("Buffer: %p", buffer);
428
442
        *arraysize = NDIS_BUFFER_TO_SPAN_PAGES(buffer);
432
446
static int ndis_encode_setting(struct device_setting *setting,
433
447
                               int device_setting_type)
434
448
{
435
 
        struct ustring ansi;
 
449
        struct ansi_string ansi;
436
450
        struct ndis_config_param *param;
437
451
 
438
452
        TRACEENTER2("type = %d", device_setting_type);
443
457
        case NDIS_CONFIG_PARAM_INT:
444
458
                setting->config_param.data.intval =
445
459
                        simple_strtol(setting->value, NULL, 0);
446
 
                DBGTRACE1("value = %lu", setting->config_param.data.intval);
 
460
                DBGTRACE1("value = %u",
 
461
                          (ULONG)setting->config_param.data.intval);
447
462
                break;
448
463
        case NDIS_CONFIG_PARAM_HEXINT:
449
464
                setting->config_param.data.intval =
450
465
                        simple_strtol(setting->value, NULL, 16);
451
 
                DBGTRACE2("value = %lu", setting->config_param.data.intval);
 
466
                DBGTRACE2("value = %u",
 
467
                          (ULONG)setting->config_param.data.intval);
452
468
                break;
453
469
        case NDIS_CONFIG_PARAM_STRING:
454
470
                ansi.buflen = ansi.len = strlen(setting->value);
471
487
static int ndis_decode_setting(struct device_setting *setting,
472
488
                               struct ndis_config_param *val)
473
489
{
474
 
        struct ustring ansi;
 
490
        struct ansi_string ansi;
475
491
 
476
492
        if (setting->config_param.type == NDIS_CONFIG_PARAM_STRING &&
477
493
            setting->config_param.data.ustring.buf)
479
495
 
480
496
        switch(val->type) {
481
497
        case NDIS_CONFIG_PARAM_INT:
482
 
                snprintf(setting->value, sizeof(long), "%lu",
483
 
                         (unsigned long)val->data.intval);
484
 
                setting->value[sizeof(long)] = 0;
 
498
                snprintf(setting->value, sizeof(u32), "%u", val->data.intval);
 
499
                setting->value[sizeof(ULONG)] = 0;
485
500
                break;
486
501
        case NDIS_CONFIG_PARAM_HEXINT:
487
 
                snprintf(setting->value, sizeof(long), "%lx",
488
 
                         (unsigned long)val->data.intval);
489
 
                setting->value[sizeof(long)] = 0;
 
502
                snprintf(setting->value, sizeof(u32), "%x", val->data.intval);
 
503
                setting->value[sizeof(ULONG)] = 0;
490
504
                break;
491
505
        case NDIS_CONFIG_PARAM_STRING:
492
506
                ansi.buf = setting->value;
507
521
        return NDIS_STATUS_SUCCESS;
508
522
}
509
523
 
510
 
STDCALL static void WRAP_EXPORT(NdisReadConfiguration)
 
524
STDCALL void WRAP_EXPORT(NdisReadConfiguration)
511
525
        (NDIS_STATUS *status, struct ndis_config_param **dest,
512
 
         struct ndis_handle *handle, struct ustring *key,
 
526
         struct ndis_handle *handle, struct unicode_string *key,
513
527
         enum ndis_config_param_type type)
514
528
{
515
529
        struct device_setting *setting;
516
 
        struct ustring ansi;
 
530
        struct ansi_string ansi;
517
531
        char *keyname;
 
532
        int ret;
518
533
 
519
 
        TRACEENTER2("%s", "");
520
 
        if (RtlUnicodeStringToAnsiString(&ansi, key, 1)) {
 
534
        TRACEENTER2("handle: %p", handle);
 
535
        ret = RtlUnicodeStringToAnsiString(&ansi, key, 1);
 
536
        DBGTRACE3("rtl func returns: %d", ret);
 
537
        if (ret) {
521
538
                *dest = NULL;
522
539
                *status = NDIS_STATUS_FAILURE;
523
540
                RtlFreeAnsiString(&ansi);
524
541
                TRACEEXIT2(return);
525
542
        }
 
543
        DBGTRACE3("handle: %p, string: %s", handle, ansi.buf);
526
544
        keyname = ansi.buf;
 
545
        DBGTRACE3("handle: %p, string: %s", handle, keyname);
527
546
 
528
547
        list_for_each_entry(setting, &handle->device->settings, list) {
529
548
                if (stricmp(keyname, setting->name) == 0) {
551
570
 
552
571
STDCALL void WRAP_EXPORT(NdisWriteConfiguration)
553
572
        (NDIS_STATUS *status, struct ndis_handle *handle,
554
 
         struct ustring *key, struct ndis_config_param *param)
 
573
         struct unicode_string *key, struct ndis_config_param *param)
555
574
{
556
 
        struct ustring ansi;
 
575
        struct ansi_string ansi;
557
576
        char *keyname;
558
577
        struct device_setting *setting;
559
578
 
594
613
        TRACEEXIT2(return);
595
614
}
596
615
 
597
 
STDCALL static void WRAP_EXPORT(NdisInitializeString)
598
 
        (struct ustring *dest, UCHAR *src)
 
616
STDCALL void WRAP_EXPORT(NdisInitializeString)
 
617
        (struct unicode_string *dest, UCHAR *src)
599
618
{
600
 
        struct ustring ansi;
 
619
        struct ansi_string ansi;
601
620
 
602
621
        TRACEENTER2("%s", "");
603
622
        ansi.len = ansi.buflen = strlen(src);
607
626
        TRACEEXIT2(return);
608
627
}
609
628
 
610
 
STDCALL static void WRAP_EXPORT(NdisInitAnsiString)
611
 
        (struct ustring *dst, CHAR *src)
 
629
STDCALL void WRAP_EXPORT(NdisInitAnsiString)
 
630
        (struct ansi_string *dst, CHAR *src)
612
631
{
613
632
        RtlInitAnsiString(dst, src);
614
633
        TRACEEXIT2(return);
615
634
}
616
635
 
617
 
STDCALL static void WRAP_EXPORT(NdisInitUnicodeString)
618
 
        (struct ustring *dest, SHORT *src)
 
636
STDCALL void WRAP_EXPORT(NdisInitString)
 
637
        (struct ansi_string *dst, CHAR *src)
 
638
{
 
639
        RtlInitString(dst, src);
 
640
        TRACEEXIT2(return);
 
641
}
 
642
 
 
643
STDCALL void WRAP_EXPORT(NdisInitUnicodeString)
 
644
        (struct unicode_string *dest, const wchar_t *src)
619
645
{
620
646
        int i;
621
647
 
631
657
        for (i = 0 ; src[i] ; i++)
632
658
                ;
633
659
        dest->len = dest->buflen = i * 2;
634
 
        dest->buf = (u8 *)src;
 
660
        dest->buf = (wchar_t *)src;
635
661
        TRACEEXIT2(return);
636
662
}
637
663
 
638
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisAnsiStringToUnicodeString)
639
 
        (struct ustring *dst, struct ustring *src)
 
664
STDCALL NDIS_STATUS WRAP_EXPORT(NdisAnsiStringToUnicodeString)
 
665
        (struct unicode_string *dst, struct ansi_string *src)
640
666
{
641
667
        int dup;
642
668
 
650
676
        TRACEEXIT2(return RtlAnsiStringToUnicodeString(dst, src, 0));
651
677
}
652
678
 
653
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisUnicodeStringToAnsiString)
654
 
        (struct ustring *dst, struct ustring *src)
 
679
STDCALL NDIS_STATUS WRAP_EXPORT(NdisUnicodeStringToAnsiString)
 
680
        (struct ansi_string *dst, struct unicode_string *src)
655
681
{
656
682
        int dup;
657
683
 
672
698
 * we also need handle in them, so we store handle X adapter_ctx map in
673
699
 * a global list.
674
700
 */
675
 
STDCALL static void WRAP_EXPORT(NdisMSetAttributesEx)
676
 
        (struct ndis_handle *handle, void* adapter_ctx,
 
701
STDCALL void WRAP_EXPORT(NdisMSetAttributesEx)
 
702
        (struct ndis_handle *handle, void *adapter_ctx,
677
703
         UINT hangcheck_interval, UINT attributes, ULONG adaptortype)
678
704
{
679
705
        struct handle_ctx_entry *handle_ctx;
685
711
        if (handle_ctx) {
686
712
                handle_ctx->handle = handle;
687
713
                handle_ctx->ctx = adapter_ctx;
688
 
                /* atomic_lock is not meant for use here, but since this
 
714
                /* ntoskernel_lock is not meant for use here, but since this
689
715
                 * function is called during initialization only,
690
716
                 * no harm abusing it */
691
 
                wrap_spin_lock(&atomic_lock, PASSIVE_LEVEL);
 
717
                kspin_lock(&ntoskernel_lock);
692
718
                list_add(&handle_ctx->list, &handle_ctx_list);
693
 
                wrap_spin_unlock(&atomic_lock);
 
719
                kspin_unlock(&ntoskernel_lock);
694
720
        }
695
721
 
696
722
        if (attributes & NDIS_ATTRIBUTE_BUS_MASTER)
723
749
{
724
750
        struct handle_ctx_entry *handle_ctx;
725
751
 
726
 
        wrap_spin_lock(&atomic_lock, PASSIVE_LEVEL);
 
752
        kspin_lock(&ntoskernel_lock);
727
753
        list_for_each_entry(handle_ctx, &handle_ctx_list, list) {
728
754
                if (handle_ctx->ctx == ctx) {
729
 
                        wrap_spin_unlock(&atomic_lock);
 
755
                        kspin_unlock(&ntoskernel_lock);
730
756
                        return handle_ctx->handle;
731
757
                }
732
758
        }
733
 
        wrap_spin_unlock(&atomic_lock);
 
759
        kspin_unlock(&ntoskernel_lock);
734
760
 
735
761
        return NULL;
736
762
}
737
763
 
738
 
STDCALL static unsigned int WRAP_EXPORT(NdisReadPciSlotInformation)
 
764
STDCALL ULONG WRAP_EXPORT(NdisReadPciSlotInformation)
739
765
        (struct ndis_handle *handle, ULONG slot,
740
766
         ULONG offset, char *buf, ULONG len)
741
767
{
746
772
        return len;
747
773
}
748
774
 
749
 
STDCALL static unsigned int WRAP_EXPORT(NdisWritePciSlotInformation)
 
775
STDCALL ULONG WRAP_EXPORT(NdisWritePciSlotInformation)
750
776
        (struct ndis_handle *handle, ULONG slot,
751
777
         ULONG offset, char *buf, ULONG len)
752
778
{
757
783
        return len;
758
784
}
759
785
 
760
 
STDCALL static void WRAP_EXPORT(NdisMQueryAdapterResources)
 
786
STDCALL void WRAP_EXPORT(NdisMQueryAdapterResources)
761
787
        (NDIS_STATUS *status, struct ndis_handle *handle,
762
788
         struct ndis_resource_list *resource_list, UINT *size)
763
789
{
770
796
                    resource_list, *size, pci_dev->irq);
771
797
 
772
798
        resource_list->version = 1;
773
 
        resource_list->revision = 0;
774
799
 
775
800
        /* Put all memory and port resources */
776
801
        i = 0;
803
828
        entry->u.interrupt.affinity = -1;
804
829
 
805
830
        resource_list->length = len;
806
 
        *size = (char*) (&resource_list->list[len]) - (char*)resource_list;
 
831
        *size = (char *) (&resource_list->list[len]) - (char *)resource_list;
807
832
        *status = NDIS_STATUS_SUCCESS;
808
833
 
809
834
 
821
846
        TRACEEXIT2(return);
822
847
}
823
848
 
824
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMMapIoSpace)
 
849
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMPciAssignResources)
 
850
        (struct ndis_handle *handle, ULONG slot_number,
 
851
         struct ndis_resource_list **resources)
 
852
{
 
853
        UINT size;
 
854
        NDIS_STATUS status;
 
855
 
 
856
        size = sizeof(struct ndis_resource_list) +
 
857
                sizeof(struct ndis_resource_entry) * 20;
 
858
        handle->pci_resources = vmalloc(size);
 
859
        if (!handle->resources) {
 
860
                ERROR("couldn't allocate memory");
 
861
                TRACEEXIT2(return NDIS_STATUS_SUCCESS);
 
862
        }
 
863
        NdisMQueryAdapterResources(&status, handle, handle->pci_resources,
 
864
                                   &size);
 
865
        *resources = handle->pci_resources;
 
866
        TRACEEXIT2(return NDIS_STATUS_SUCCESS);
 
867
}
 
868
 
 
869
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMMapIoSpace)
825
870
        (void **virt, struct ndis_handle *handle,
826
871
         NDIS_PHY_ADDRESS phy_addr, UINT len)
827
872
{
828
 
        ULONG_PTR addr;
829
 
 
830
 
        addr = (ULONG_PTR)phy_addr.quad;
831
 
 
832
 
        TRACEENTER2("%p, %u", (void *)addr, len);
833
 
        *virt = ioremap(addr, len);
 
873
        TRACEENTER2("%016llx, %d", phy_addr, len);
 
874
        *virt = ioremap(phy_addr, len);
834
875
        if (*virt == NULL) {
835
876
                ERROR("%s", "ioremap failed");
836
877
                TRACEEXIT2(return NDIS_STATUS_FAILURE);
837
878
        }
838
879
 
839
 
        handle->mem_start = addr;
840
 
        handle->mem_end = addr + len -1;
 
880
        handle->mem_start = phy_addr;
 
881
        handle->mem_end = phy_addr + len -1;
 
882
 
841
883
        DBGTRACE2("ioremap successful %p", *virt);
842
884
        TRACEEXIT2(return NDIS_STATUS_SUCCESS);
843
885
}
844
886
 
845
 
STDCALL static void WRAP_EXPORT(NdisMUnmapIoSpace)
 
887
STDCALL void WRAP_EXPORT(NdisMUnmapIoSpace)
846
888
        (struct ndis_handle *handle, void *virtaddr, UINT len)
847
889
{
848
890
        TRACEENTER2("%p, %d", virtaddr, len);
849
891
        iounmap(virtaddr);
850
892
}
851
893
 
852
 
STDCALL static void WRAP_EXPORT(NdisAllocateSpinLock)
853
 
        (struct ndis_spinlock *lock)
854
 
{
855
 
        TRACEENTER4("lock %p", lock);
856
 
 
857
 
#ifdef CONFIG_DEBUG_SPINLOCK
858
 
        lock->lock = wrap_kmalloc(sizeof(struct wrap_spinlock), GFP_ATOMIC);
859
 
        if (!lock->lock) {
860
 
                ERROR("coudln't allocate memory");
861
 
                TRACEEXIT2(return);
862
 
        }
863
 
#endif
864
 
        wrap_spin_lock_init(NDIS_SPINLOCK(lock));
865
 
 
866
 
        TRACEEXIT4(return);
867
 
}
868
 
 
869
 
STDCALL static void WRAP_EXPORT(NdisFreeSpinLock)
870
 
        (struct ndis_spinlock *lock)
871
 
{
872
 
        TRACEENTER4("lock %p", lock);
873
 
        lock->use_bh = PASSIVE_LEVEL;
874
 
 
875
 
        TRACEEXIT4(return);
876
 
}
877
 
 
878
 
STDCALL static void WRAP_EXPORT(NdisAcquireSpinLock)
879
 
        (struct ndis_spinlock *lock)
880
 
{
881
 
        TRACEENTER5("lock %p", lock);
882
 
        /* TI ACX 100 driver doesn't call NdisAllocateSpinLock before
883
 
         * calling NdisAcquireSpinLock and in those cases, lock seems
884
 
         * to be set to 0, so check if that is the case and initialize
885
 
         * it */
886
 
        if (NDIS_SPINLOCK(lock) == 0) {
887
 
                WARNING("Windows driver is using uninitialized spinlock %p",
888
 
                        lock);
889
 
                NdisAllocateSpinLock(lock);
890
 
        }
891
 
        wrap_spin_lock(NDIS_SPINLOCK(lock), PASSIVE_LEVEL);
892
 
        TRACEEXIT5(return);
893
 
}
894
 
 
895
 
STDCALL static void WRAP_EXPORT(NdisReleaseSpinLock)
896
 
        (struct ndis_spinlock *lock)
897
 
{
898
 
        TRACEENTER5("lock %p", lock);
899
 
        wrap_spin_unlock(NDIS_SPINLOCK(lock));
900
 
        TRACEEXIT5(return);
901
 
}
902
 
 
903
 
STDCALL static void WRAP_EXPORT(NdisDprAcquireSpinLock)
904
 
        (struct ndis_spinlock *lock)
905
 
{
906
 
        TRACEENTER5("lock %p", lock);
907
 
        /* we use PASSIVE_LEVEL here because this function is not
908
 
         * supposed to change IRQL */
909
 
        wrap_spin_lock(NDIS_SPINLOCK(lock), PASSIVE_LEVEL);
910
 
        TRACEEXIT5(return);
911
 
}
912
 
 
913
 
STDCALL static void WRAP_EXPORT(NdisDprReleaseSpinLock)
914
 
        (struct ndis_spinlock *lock)
915
 
{
916
 
        TRACEENTER5("lock %p", lock);
917
 
        wrap_spin_unlock(NDIS_SPINLOCK(lock));
918
 
        TRACEEXIT5(return);
919
 
}
920
 
 
921
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMAllocateMapRegisters)
 
894
STDCALL void WRAP_EXPORT(NdisAllocateSpinLock)
 
895
        (struct ndis_spinlock *lock)
 
896
{
 
897
        TRACEENTER4("lock %p", lock);
 
898
 
 
899
        KeInitializeSpinLock(&lock->klock);
 
900
 
 
901
        TRACEEXIT4(return);
 
902
}
 
903
 
 
904
STDCALL void WRAP_EXPORT(NdisFreeSpinLock)
 
905
        (struct ndis_spinlock *lock)
 
906
{
 
907
        TRACEENTER4("lock %p", lock);
 
908
        TRACEEXIT4(return);
 
909
}
 
910
 
 
911
STDCALL void WRAP_EXPORT(NdisAcquireSpinLock)
 
912
        (struct ndis_spinlock *lock)
 
913
{
 
914
        TRACEENTER5("lock %p", lock);
 
915
        lock->irql = kspin_lock_irql(&lock->klock, DISPATCH_LEVEL);
 
916
        TRACEEXIT5(return);
 
917
}
 
918
 
 
919
STDCALL void WRAP_EXPORT(NdisReleaseSpinLock)
 
920
        (struct ndis_spinlock *lock)
 
921
{
 
922
        TRACEENTER5("lock %p", lock);
 
923
        kspin_unlock_irql(&lock->klock, lock->irql);
 
924
        TRACEEXIT5(return);
 
925
}
 
926
 
 
927
STDCALL void WRAP_EXPORT(NdisDprAcquireSpinLock)
 
928
        (struct ndis_spinlock *lock)
 
929
{
 
930
        TRACEENTER5("lock %p", lock);
 
931
        kspin_lock(&lock->klock);
 
932
        TRACEEXIT5(return);
 
933
}
 
934
 
 
935
STDCALL void WRAP_EXPORT(NdisDprReleaseSpinLock)
 
936
        (struct ndis_spinlock *lock)
 
937
{
 
938
        TRACEENTER5("lock %p", lock);
 
939
        kspin_unlock(&lock->klock);
 
940
        TRACEEXIT5(return);
 
941
}
 
942
 
 
943
STDCALL void WRAP_EXPORT(NdisInitializeReadWriteLock)
 
944
        (struct ndis_rw_lock *rw_lock)
 
945
{
 
946
        memset(rw_lock, 0, sizeof(*rw_lock));
 
947
        KeInitializeSpinLock(&rw_lock->u.s.klock);
 
948
        return;
 
949
}
 
950
 
 
951
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMAllocateMapRegisters)
922
952
        (struct ndis_handle *handle, UINT dmachan,
923
953
         NDIS_DMA_SIZE dmasize, ULONG basemap, ULONG size)
924
954
{
943
973
        TRACEEXIT2(return NDIS_STATUS_SUCCESS);
944
974
}
945
975
 
946
 
STDCALL static void WRAP_EXPORT(NdisMFreeMapRegisters)
 
976
STDCALL void WRAP_EXPORT(NdisMFreeMapRegisters)
947
977
        (struct ndis_handle *handle)
948
978
{
949
979
        TRACEENTER2("handle: %p", handle);
954
984
        TRACEEXIT2(return);
955
985
}
956
986
 
957
 
STDCALL static void WRAP_EXPORT(NdisMAllocateSharedMemory)
958
 
        (struct ndis_handle *handle, unsigned long size,
959
 
         char cached, void **virt, NDIS_PHY_ADDRESS *phys)
 
987
STDCALL void WRAP_EXPORT(NdisMAllocateSharedMemory)
 
988
        (struct ndis_handle *handle, ULONG size,
 
989
         BOOLEAN cached, void **virt, NDIS_PHY_ADDRESS *phys)
960
990
{
961
991
        dma_addr_t p;
962
992
        void *v;
963
993
 
964
 
        TRACEENTER3("map count: %d, size: %lu, cached: %d",
 
994
        TRACEENTER3("map count: %d, size: %u, cached: %d",
965
995
                    handle->map_count, size, cached);
966
996
 
967
997
//      if (handle->map_dma_addr == NULL)
970
1000
        v = PCI_DMA_ALLOC_COHERENT(handle->dev.pci, size, &p);
971
1001
        if (!v) {
972
1002
                ERROR("Failed to allocate DMA coherent memory. "
973
 
                      "Windows driver requested %ld bytes of "
 
1003
                      "Windows driver requested %d bytes of "
974
1004
                      "%scached memory\n", size, cached ? "" : "un-");
975
1005
        }
976
1006
 
977
 
        *(char **)virt = v;
978
 
        if (v == NULL)
979
 
                phys->quad = 0;
980
 
        else
981
 
                phys->quad = p;
982
 
 
 
1007
        *virt = v;
 
1008
        *phys = p;
983
1009
        DBGTRACE3("allocated shared memory: %p", v);
984
1010
}
985
1011
 
986
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMAllocateSharedMemoryAsync)
 
1012
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMAllocateSharedMemoryAsync)
987
1013
        (struct ndis_handle *handle, ULONG size, BOOLEAN cached,
988
1014
         void *ctx)
989
1015
{
990
1016
        struct ndis_work_entry *ndis_work_entry;
991
1017
        struct ndis_alloc_mem_work_item *alloc_mem;
 
1018
        KIRQL irql;
992
1019
 
993
1020
        TRACEENTER3("%s", "");
994
1021
        ndis_work_entry = kmalloc(sizeof(*ndis_work_entry), GFP_ATOMIC);
1003
1030
        alloc_mem->cached = cached;
1004
1031
        alloc_mem->ctx = ctx;
1005
1032
 
1006
 
        wrap_spin_lock(&ndis_work_list_lock, DISPATCH_LEVEL);
 
1033
        irql = kspin_lock_irql(&ndis_work_list_lock, DISPATCH_LEVEL);
1007
1034
        list_add_tail(&ndis_work_entry->list, &ndis_work_list);
1008
 
        wrap_spin_unlock(&ndis_work_list_lock);
 
1035
        kspin_unlock_irql(&ndis_work_list_lock, irql);
1009
1036
 
1010
1037
        schedule_work(&ndis_work);
1011
1038
        TRACEEXIT3(return NDIS_STATUS_PENDING);
1012
1039
}
1013
1040
 
1014
 
STDCALL static void WRAP_EXPORT(NdisMFreeSharedMemory)
 
1041
STDCALL void WRAP_EXPORT(NdisMFreeSharedMemory)
1015
1042
        (struct ndis_handle *handle, ULONG size, BOOLEAN cached,
1016
1043
         void *virt, NDIS_PHY_ADDRESS addr)
1017
1044
{
1018
1045
        TRACEENTER3("%s", "");
1019
1046
        /* FIXME: do USB drivers call this? */
1020
 
#ifdef CONFIG_X86_64
1021
 
        PCI_DMA_FREE_COHERENT(handle->dev.pci, size, virt, addr.quad);
1022
 
#else
1023
 
        PCI_DMA_FREE_COHERENT(handle->dev.pci, size, virt, addr.s.low);
1024
 
#endif
 
1047
        PCI_DMA_FREE_COHERENT(handle->dev.pci, size, virt, addr);
1025
1048
        TRACEEXIT3(return);
1026
1049
}
1027
1050
 
1028
 
STDCALL static void WRAP_EXPORT(NdisAllocateBufferPool)
1029
 
        (NDIS_STATUS *status, void *poolhandle, UINT size)
 
1051
/* Some drivers allocate NDIS_BUFFER (aka MDL) very often; instead of
 
1052
 * allocating and freeing with kernel functions, we chain them into
 
1053
 * ndis_buffer_pool. When an MDL is freed, it is added to the list of
 
1054
 * free MDLs. When allocated, we first check if there is one in free
 
1055
 * list and if so just return it; otherwise, we allocate a new one and
 
1056
 * return that. This reduces memory fragmentation. Windows DDK says
 
1057
 * that the driver itself shouldn't check what is returned in
 
1058
 * pool_handle, presumably because buffer pools are not used in
 
1059
 * XP. However, as long as driver follows rest of the semantics - that
 
1060
 * it should indicate maximum number of MDLs used with num_descr and
 
1061
 * pass the same pool_handle in other buffer functions, this should
 
1062
 * work. Sadly, though, NdisFreeBuffer doesn't pass the pool_handle,
 
1063
 * so we use 'process' field of MDL to store pool_handle. */
 
1064
STDCALL void WRAP_EXPORT(NdisAllocateBufferPool)
 
1065
        (NDIS_STATUS *status, struct ndis_buffer_pool **pool_handle,
 
1066
         UINT num_descr)
1030
1067
{
1031
 
        TRACEENTER4("%s", "");
 
1068
        struct ndis_buffer_pool *pool;
 
1069
 
 
1070
        TRACEENTER3("buffers: %d", num_descr);
 
1071
        pool = kmalloc(sizeof(*pool), GFP_ATOMIC);
 
1072
        if (!pool) {
 
1073
                *status = NDIS_STATUS_RESOURCES;
 
1074
                TRACEEXIT3(return);
 
1075
        }
 
1076
        kspin_lock_init(&pool->lock);
 
1077
        pool->max_descr = num_descr;
 
1078
        pool->num_allocated_descr = 0;
 
1079
        pool->free_descr = NULL;
 
1080
        *pool_handle = pool;
1032
1081
        *status = NDIS_STATUS_SUCCESS;
1033
 
}
1034
 
 
1035
 
STDCALL static void WRAP_EXPORT(NdisFreeBufferPool)
1036
 
        (void *poolhandle)
1037
 
{
1038
 
        TRACEENTER4("%s", "");
1039
 
 
1040
 
        TRACEEXIT4(return);
1041
 
}
1042
 
 
1043
 
STDCALL static void WRAP_EXPORT(NdisAllocateBuffer)
1044
 
        (NDIS_STATUS *status, struct ndis_buffer **buffer,
1045
 
         void *poolhandle, void *virt, UINT len)
1046
 
{
1047
 
        struct ndis_buffer *ndis_buffer = kmalloc(sizeof(struct ndis_buffer),
1048
 
                                                  GFP_ATOMIC);
1049
 
        TRACEENTER4("%s", "");
1050
 
        if (!ndis_buffer) {
1051
 
                ERROR("%s", "Couldn't allocate memory");
 
1082
        TRACEEXIT3(return);
 
1083
}
 
1084
 
 
1085
STDCALL void WRAP_EXPORT(NdisAllocateBuffer)
 
1086
        (NDIS_STATUS *status, ndis_buffer **buffer,
 
1087
         struct ndis_buffer_pool *pool, void *virt, UINT length)
 
1088
{
 
1089
        ndis_buffer *descr;
 
1090
        KIRQL irql;
 
1091
 
 
1092
        TRACEENTER3("pool: %p, allocated: %d",
 
1093
                    pool, pool->num_allocated_descr);
 
1094
        if (!pool) {
1052
1095
                *status = NDIS_STATUS_FAILURE;
1053
1096
                TRACEEXIT4(return);
1054
1097
        }
1055
 
 
1056
 
        memset(ndis_buffer, 0, sizeof(struct ndis_buffer));
1057
 
 
1058
 
        ndis_buffer->data = virt;
1059
 
        ndis_buffer->next = 0;
1060
 
        ndis_buffer->len = len;
1061
 
 
1062
 
        *buffer = ndis_buffer;
1063
 
 
1064
 
        DBGTRACE4("allocated buffer: %p", buffer);
1065
 
        *status = NDIS_STATUS_SUCCESS;
1066
 
        TRACEEXIT4(return);
1067
 
}
1068
 
 
1069
 
STDCALL static void WRAP_EXPORT(NdisFreeBuffer)
1070
 
        (struct ndis_buffer *buffer)
 
1098
        irql = kspin_lock_irql(&pool->lock, DISPATCH_LEVEL);
 
1099
        if (pool->num_allocated_descr < pool->max_descr) {
 
1100
                if (pool->free_descr) {
 
1101
                        descr = pool->free_descr;
 
1102
                        pool->free_descr = descr->next;
 
1103
                        memset(descr, 0, sizeof(*descr));
 
1104
                        MmInitializeMdl(descr, virt, length);
 
1105
                } else
 
1106
                        descr = allocate_init_mdl(virt, length);
 
1107
        } else
 
1108
                descr = NULL;
 
1109
 
 
1110
        if (descr) {
 
1111
                /* NdisFreeBuffer doesn't pass pool, so we store pool
 
1112
                 * in unused field 'process' */
 
1113
                descr->process = pool;
 
1114
                pool->num_allocated_descr++;
 
1115
                *status = NDIS_STATUS_SUCCESS;
 
1116
                DBGTRACE3("allocated buffer %p for %p", descr, virt);
 
1117
        } else
 
1118
                *status = NDIS_STATUS_FAILURE;
 
1119
 
 
1120
        *buffer = descr;
 
1121
        kspin_unlock_irql(&pool->lock, irql);
 
1122
        TRACEEXIT3(return);
 
1123
}
 
1124
 
 
1125
STDCALL void WRAP_EXPORT(NdisFreeBuffer)
 
1126
        (ndis_buffer *descr)
 
1127
{
 
1128
        struct ndis_buffer_pool *pool;
 
1129
        KIRQL irql;
 
1130
 
 
1131
        TRACEENTER3("buffer: %p", descr);
 
1132
        pool = descr->process;
 
1133
        if (!pool) {
 
1134
                ERROR("pool for descriptor %p is invalid", descr);
 
1135
                TRACEEXIT3(return);
 
1136
        }
 
1137
        irql = kspin_lock_irql(&pool->lock, DISPATCH_LEVEL);
 
1138
        descr->next = pool->free_descr;
 
1139
        pool->free_descr = descr;
 
1140
        pool->num_allocated_descr--;
 
1141
        kspin_unlock_irql(&pool->lock, irql);
 
1142
        TRACEEXIT3(return);
 
1143
}
 
1144
 
 
1145
STDCALL void WRAP_EXPORT(NdisFreeBufferPool)
 
1146
        (struct ndis_buffer_pool *pool)
 
1147
{
 
1148
        ndis_buffer *cur, *prev;
 
1149
        KIRQL irql;
 
1150
 
 
1151
        TRACEENTER3("pool: %p", pool);
 
1152
        irql = kspin_lock_irql(&pool->lock, DISPATCH_LEVEL);
 
1153
        cur = pool->free_descr;
 
1154
        while (cur) {
 
1155
                prev = cur;
 
1156
                cur = cur->next;
 
1157
                prev->process = NULL;
 
1158
                free_mdl(prev);
 
1159
        }
 
1160
        kspin_unlock_irql(&pool->lock, irql);
 
1161
        kfree(pool);
 
1162
        TRACEEXIT3(return);
 
1163
}
 
1164
 
 
1165
STDCALL void WRAP_EXPORT(NdisAdjustBufferLength)
 
1166
        (ndis_buffer *buffer, UINT length)
1071
1167
{
1072
1168
        TRACEENTER4("%p", buffer);
1073
 
 
1074
 
        if (buffer)
1075
 
                kfree(buffer);
1076
 
        TRACEEXIT4(return);
1077
 
}
1078
 
 
1079
 
STDCALL static void WRAP_EXPORT(NdisAdjustBufferLength)
1080
 
        (struct ndis_buffer *buf, UINT len)
1081
 
{
1082
 
        TRACEENTER4("%s", "");
1083
 
        buf->len = len;
1084
 
}
1085
 
 
1086
 
STDCALL static void WRAP_EXPORT(NdisQueryBuffer)
1087
 
        (struct ndis_buffer *buf, void **adr, UINT *len)
1088
 
{
1089
 
        TRACEENTER3("%s", "");
1090
 
        if (adr)
1091
 
                *adr = buf->data;
1092
 
        if (len)
1093
 
                *len = buf->len;
1094
 
}
1095
 
 
1096
 
STDCALL static void WRAP_EXPORT(NdisQueryBufferSafe)
1097
 
        (struct ndis_buffer *buf, void **adr,
1098
 
         UINT *len, enum mm_page_priority priority)
1099
 
{
1100
 
        TRACEENTER3("%p, %p, %p", buf, adr, len);
1101
 
        if (adr)
1102
 
                *adr = buf->data;
1103
 
        if (len)
1104
 
                *len = buf->len;
1105
 
}
1106
 
 
1107
 
STDCALL static void *WRAP_EXPORT(NdisBufferVirtualAddress)
1108
 
        (struct ndis_buffer *buf)
1109
 
{
1110
 
        TRACEENTER3("%s", "");
1111
 
        return buf->data;
1112
 
}
1113
 
 
1114
 
STDCALL static ULONG WRAP_EXPORT(NdisBufferLength)
1115
 
        (struct ndis_buffer *buf)
1116
 
{
1117
 
        TRACEENTER3("%s", "");
1118
 
        return buf->len;
1119
 
}
1120
 
 
1121
 
STDCALL static void WRAP_EXPORT(NdisAllocatePacketPool)
1122
 
        (NDIS_STATUS *status, unsigned int *poolhandle,
1123
 
         UINT size, UINT rsvlen)
1124
 
{
1125
 
        TRACEENTER3("size=%d", size);
1126
 
        *poolhandle = 0xa000fff4;
 
1169
        buffer->bytecount = length;
 
1170
}
 
1171
 
 
1172
STDCALL void WRAP_EXPORT(NdisQueryBuffer)
 
1173
        (ndis_buffer *buffer, void **virt, UINT *length)
 
1174
{
 
1175
        TRACEENTER3("buffer: %p", buffer);
 
1176
        if (virt)
 
1177
                *virt = MmGetMdlVirtualAddress(buffer);
 
1178
        if (length)
 
1179
                *length = MmGetMdlByteCount(buffer);
 
1180
        TRACEEXIT3(return);
 
1181
}
 
1182
 
 
1183
STDCALL void WRAP_EXPORT(NdisQueryBufferSafe)
 
1184
        (ndis_buffer *buffer, void **virt, UINT *length,
 
1185
         enum mm_page_priority priority)
 
1186
{
 
1187
        TRACEENTER3("%p, %p, %p", buffer, virt, length);
 
1188
        if (virt)
 
1189
                *virt = MmGetMdlVirtualAddress(buffer);
 
1190
        if (length)
 
1191
                *length = MmGetMdlByteCount(buffer);
 
1192
}
 
1193
 
 
1194
STDCALL void *WRAP_EXPORT(NdisBufferVirtualAddress)
 
1195
        (ndis_buffer *buffer)
 
1196
{
 
1197
        TRACEENTER3("%p", buffer);
 
1198
        return MmGetMdlVirtualAddress(buffer);
 
1199
}
 
1200
 
 
1201
STDCALL ULONG WRAP_EXPORT(NdisBufferLength)
 
1202
        (ndis_buffer *buffer)
 
1203
{
 
1204
        TRACEENTER3("%p", buffer);
 
1205
        return MmGetMdlByteCount(buffer);
 
1206
}
 
1207
 
 
1208
STDCALL void WRAP_EXPORT(NdisAllocatePacketPool)
 
1209
        (NDIS_STATUS *status, struct ndis_packet_pool **pool_handle,
 
1210
         UINT num_descr, UINT rsvlen)
 
1211
{
 
1212
        struct ndis_packet_pool *pool;
 
1213
 
 
1214
        TRACEENTER3("buffers: %d", num_descr);
 
1215
        pool = kmalloc(sizeof(*pool), GFP_ATOMIC);
 
1216
        if (!pool) {
 
1217
                *status = NDIS_STATUS_RESOURCES;
 
1218
                TRACEEXIT3(return);
 
1219
        }
 
1220
        kspin_lock_init(&pool->lock);
 
1221
        pool->max_descr = num_descr;
 
1222
        pool->num_allocated_descr = 0;
 
1223
        pool->free_descr = NULL;
 
1224
        *pool_handle = pool;
1127
1225
        *status = NDIS_STATUS_SUCCESS;
1128
 
}
1129
 
 
1130
 
STDCALL static void WRAP_EXPORT(NdisAllocatePacketPoolEx)
1131
 
        (NDIS_STATUS *status, unsigned int *poolhandle,
1132
 
         UINT size, UINT overflowsize, UINT rsvlen)
1133
 
{
1134
 
        TRACEENTER3("%s", "");
1135
 
        NdisAllocatePacketPool(status, poolhandle, size, rsvlen);
1136
 
        TRACEEXIT3(return);
1137
 
}
1138
 
 
1139
 
STDCALL static UINT WRAP_EXPORT(NdisPacketPoolUsage)
1140
 
        (void *poolhandle)
1141
 
{
1142
 
        UNIMPL();
1143
 
        return 0;
1144
 
}
1145
 
 
1146
 
STDCALL static void WRAP_EXPORT(NdisFreePacketPool)
1147
 
        (void *poolhandle)
1148
 
{
1149
 
        TRACEENTER3("handle: %p", poolhandle);
1150
 
}
1151
 
 
1152
 
STDCALL static void WRAP_EXPORT(NdisAllocatePacket)
1153
 
        (NDIS_STATUS *status, struct ndis_packet **packet_out,
1154
 
         void *poolhandle)
 
1226
        TRACEEXIT3(return);
 
1227
}
 
1228
 
 
1229
STDCALL void WRAP_EXPORT(NdisAllocatePacketPoolEx)
 
1230
        (NDIS_STATUS *status, struct ndis_packet_pool **pool_handle,
 
1231
         UINT num_descr, UINT overflowsize, UINT rsvlen)
 
1232
{
 
1233
        TRACEENTER3("");
 
1234
        NdisAllocatePacketPool(status, pool_handle, num_descr, rsvlen);
 
1235
        TRACEEXIT3(return);
 
1236
}
 
1237
 
 
1238
STDCALL UINT WRAP_EXPORT(NdisPacketPoolUsage)
 
1239
        (struct ndis_packet_pool *pool)
 
1240
{
 
1241
        UINT i;
 
1242
        KIRQL irql;
 
1243
 
 
1244
        irql = kspin_lock_irql(&pool->lock, DISPATCH_LEVEL);
 
1245
        i = pool->num_allocated_descr;
 
1246
        kspin_unlock_irql(&pool->lock, irql);
 
1247
        return i;
 
1248
}
 
1249
 
 
1250
struct ndis_packet *allocate_ndis_packet(void)
1155
1251
{
1156
1252
        struct ndis_packet *packet;
1157
 
 
1158
 
        TRACEENTER3("%s", "");
1159
 
        packet = kmalloc(sizeof(struct ndis_packet), GFP_ATOMIC);
1160
 
        if (!packet) {
1161
 
                ERROR("%s", "Couldn't allocate memory");
1162
 
                *packet_out = NULL;
1163
 
                *status = NDIS_STATUS_FAILURE;
1164
 
                TRACEEXIT3(return);
1165
 
        }
1166
 
        memset(packet, 0, sizeof(struct ndis_packet));
1167
 
        packet->private.oob_offset = offsetof(struct ndis_packet, oob_tx);
1168
 
        packet->private.pool = (void *)0xa000fff4;
1169
 
        packet->private.packet_flags = 0xc0;
1170
 
 
1171
 
/* See comment in wrapper.c/send_one about this */
1172
 
#if 0
1173
 
        {
1174
 
                int i = 0;
1175
 
                /* Poision extra packet info */
1176
 
                int *x = (int*) &packet->ext1;
1177
 
                for (i = 0; i <= 12; i++)
1178
 
                        x[i] = i;
1179
 
 
1180
 
                packet->mediaspecific_size = 0x100;
1181
 
                packet->mediaspecific = (void*) 0x0001f00;
1182
 
        }
1183
 
#endif
1184
 
 
1185
 
 
1186
 
        *packet_out = packet;
1187
 
        *status = NDIS_STATUS_SUCCESS;
1188
 
        TRACEEXIT3(return);
1189
 
}
1190
 
 
1191
 
STDCALL static void WRAP_EXPORT(NdisFreePacket)
1192
 
        (void *packet)
1193
 
{
1194
 
        TRACEENTER3("%s", "");
 
1253
        packet = kmem_cache_alloc(packet_cache, GFP_ATOMIC);
1195
1254
        if (packet) {
1196
 
                memset(packet, 0, sizeof(struct ndis_packet));
1197
 
                kfree(packet);
1198
 
        }
1199
 
        TRACEEXIT3(return);
1200
 
}
1201
 
 
1202
 
STDCALL static void WRAP_EXPORT(NdisMInitializeTimer)
 
1255
                memset(packet, 0, sizeof(*packet));
 
1256
                packet->private.oob_offset =
 
1257
                        offsetof(struct ndis_packet, oob_data);
 
1258
                packet->private.packet_flags = fPACKET_ALLOCATED_BY_NDIS;
 
1259
        }
 
1260
        return packet;
 
1261
}
 
1262
 
 
1263
void free_ndis_packet(struct ndis_packet *packet)
 
1264
{
 
1265
        kmem_cache_free(packet_cache, packet);
 
1266
}
 
1267
 
 
1268
STDCALL void WRAP_EXPORT(NdisAllocatePacket)
 
1269
        (NDIS_STATUS *status, struct ndis_packet **packet,
 
1270
         struct ndis_packet_pool *pool)
 
1271
{
 
1272
        struct ndis_packet *descr;
 
1273
        KIRQL irql;
 
1274
 
 
1275
        TRACEENTER3("pool: %p", pool);
 
1276
        if (!pool) {
 
1277
                *status = NDIS_STATUS_RESOURCES;
 
1278
                TRACEEXIT3(return);
 
1279
        }
 
1280
        irql = kspin_lock_irql(&pool->lock, DISPATCH_LEVEL);
 
1281
        if (pool->num_allocated_descr < pool->max_descr) {
 
1282
                if (pool->free_descr) {
 
1283
                        descr = pool->free_descr;
 
1284
                        pool->free_descr = descr->next;
 
1285
                        memset(descr, 0, sizeof(*descr));
 
1286
                        descr->private.oob_offset =
 
1287
                                offsetof(struct ndis_packet, oob_data);
 
1288
                        descr->private.packet_flags =
 
1289
                                fPACKET_ALLOCATED_BY_NDIS;
 
1290
                } else
 
1291
                        descr = allocate_ndis_packet();
 
1292
        } else
 
1293
                descr = NULL;
 
1294
 
 
1295
        if (descr) {
 
1296
                pool->num_allocated_descr++;
 
1297
                descr->private.pool = pool;
 
1298
                *status = NDIS_STATUS_SUCCESS;
 
1299
        } else
 
1300
                *status = NDIS_STATUS_RESOURCES;
 
1301
        *packet = descr;
 
1302
        kspin_unlock_irql(&pool->lock, irql);
 
1303
        DBGTRACE3("packet: %p, pool: %p", descr, pool);
 
1304
        TRACEEXIT3(return);
 
1305
}
 
1306
 
 
1307
STDCALL void WRAP_EXPORT(NdisDprAllocatePacket)
 
1308
        (NDIS_STATUS *status, struct ndis_packet **packet,
 
1309
         struct ndis_packet_pool *pool)
 
1310
{
 
1311
        NdisAllocatePacket(status, packet, pool);
 
1312
}
 
1313
 
 
1314
STDCALL void WRAP_EXPORT(NdisFreePacket)
 
1315
        (struct ndis_packet *descr)
 
1316
{
 
1317
        struct ndis_packet_pool *pool;
 
1318
        KIRQL irql;
 
1319
 
 
1320
        TRACEENTER3("packet: %p, pool: %p", descr, descr->private.pool);
 
1321
        pool = descr->private.pool;
 
1322
        if (!pool) {
 
1323
                ERROR("pool for descriptor %p is invalid", descr);
 
1324
                TRACEEXIT3(return);
 
1325
        }
 
1326
        irql = kspin_lock_irql(&pool->lock, DISPATCH_LEVEL);
 
1327
        descr->next = pool->free_descr;
 
1328
        pool->free_descr = descr;
 
1329
        pool->num_allocated_descr--;
 
1330
        kspin_unlock_irql(&pool->lock, irql);
 
1331
        TRACEEXIT3(return);
 
1332
}
 
1333
 
 
1334
STDCALL void WRAP_EXPORT(NdisFreePacketPool)
 
1335
        (struct ndis_packet_pool *pool)
 
1336
{
 
1337
        struct ndis_packet *cur, *prev;
 
1338
        KIRQL irql;
 
1339
 
 
1340
        TRACEENTER3("pool: %p", pool);
 
1341
        irql = kspin_lock_irql(&pool->lock, DISPATCH_LEVEL);
 
1342
        cur = pool->free_descr;
 
1343
        while (cur) {
 
1344
                prev = cur;
 
1345
                cur = cur->next;
 
1346
                free_ndis_packet(prev);
 
1347
        }
 
1348
        kspin_unlock_irql(&pool->lock, irql);
 
1349
        kfree(pool);
 
1350
        TRACEEXIT3(return);
 
1351
}
 
1352
 
 
1353
STDCALL void WRAP_EXPORT(NdisSend)
 
1354
        (NDIS_STATUS *status, struct ndis_handle *handle,
 
1355
         struct ndis_packet *packet)
 
1356
{
 
1357
        KIRQL irql;
 
1358
        struct miniport_char *miniport = &handle->driver->miniport_char;
 
1359
 
 
1360
        if (miniport->send_packets) {
 
1361
                struct ndis_packet *packets[1];
 
1362
 
 
1363
                packets[0] = packet;
 
1364
                irql = raise_irql(DISPATCH_LEVEL);
 
1365
                LIN2WIN3(miniport->send_packets, handle->adapter_ctx,
 
1366
                         packets, 1);
 
1367
                lower_irql(irql);
 
1368
                if (test_bit(ATTR_SERIALIZED, &handle->attributes)) {
 
1369
                        *status = packet->oob_data.status;
 
1370
                        switch (*status) {
 
1371
                        case NDIS_STATUS_SUCCESS:
 
1372
                                sendpacket_done(handle, packet);
 
1373
                                break;
 
1374
                        case NDIS_STATUS_PENDING:
 
1375
                                break;
 
1376
                        case NDIS_STATUS_RESOURCES:
 
1377
                                handle->send_ok = 0;
 
1378
                                break;
 
1379
                        case NDIS_STATUS_FAILURE:
 
1380
                        default:
 
1381
                                break;
 
1382
                        }
 
1383
                } else {
 
1384
                        *status = NDIS_STATUS_PENDING;
 
1385
                }
 
1386
        } else {
 
1387
                irql = raise_irql(DISPATCH_LEVEL);
 
1388
                *status = LIN2WIN3(miniport->send, handle->adapter_ctx,
 
1389
                                   packet, 0);
 
1390
                lower_irql(irql);
 
1391
                switch (*status) {
 
1392
                case NDIS_STATUS_SUCCESS:
 
1393
                        sendpacket_done(handle, packet);
 
1394
                        break;
 
1395
                case NDIS_STATUS_PENDING:
 
1396
                        break;
 
1397
                case NDIS_STATUS_RESOURCES:
 
1398
                        handle->send_ok = 0;
 
1399
                        break;
 
1400
                case NDIS_STATUS_FAILURE:
 
1401
                        break;
 
1402
                }
 
1403
        }
 
1404
        TRACEEXIT3(return);
 
1405
}
 
1406
 
 
1407
STDCALL void WRAP_EXPORT(NdisMInitializeTimer)
1203
1408
        (struct ndis_miniport_timer *timer_handle, struct ndis_handle *handle,
1204
1409
         void *func, void *ctx)
1205
1410
{
1211
1416
        TRACEEXIT4(return);
1212
1417
}
1213
1418
 
1214
 
STDCALL static void WRAP_EXPORT(NdisInitializeTimer)
 
1419
STDCALL void WRAP_EXPORT(NdisInitializeTimer)
1215
1420
        (struct ndis_timer *timer_handle, void *func, void *ctx)
1216
1421
{
1217
1422
        TRACEENTER4("%p, %p, %p", timer_handle, func, ctx);
1222
1427
        TRACEEXIT4(return);
1223
1428
}
1224
1429
 
1225
 
STDCALL static void WRAP_EXPORT(NdisSetTimer)
 
1430
STDCALL void WRAP_EXPORT(NdisSetTimer)
1226
1431
        (struct ndis_timer *timer_handle, UINT ms)
1227
1432
{
1228
1433
        unsigned long expires = jiffies + (ms * HZ) / 1000;
1233
1438
        TRACEEXIT4(return);
1234
1439
}
1235
1440
 
1236
 
STDCALL static void WRAP_EXPORT(NdisMSetPeriodicTimer)
 
1441
STDCALL void WRAP_EXPORT(NdisMSetPeriodicTimer)
1237
1442
        (struct ndis_miniport_timer *timer_handle, UINT ms)
1238
1443
{
1239
1444
        unsigned long expires = jiffies + (ms * HZ) / 1000;
1245
1450
        TRACEEXIT4(return);
1246
1451
}
1247
1452
 
1248
 
STDCALL static void WRAP_EXPORT(NdisMCancelTimer)
 
1453
STDCALL void WRAP_EXPORT(NdisMCancelTimer)
1249
1454
        (struct ndis_miniport_timer *timer_handle, BOOLEAN *canceled)
1250
1455
{
1251
1456
        TRACEENTER4("%s", "");
1253
1458
        TRACEEXIT4(return);
1254
1459
}
1255
1460
 
1256
 
STDCALL static void WRAP_EXPORT(NdisCancelTimer)
 
1461
STDCALL void WRAP_EXPORT(NdisCancelTimer)
1257
1462
        (struct ndis_timer *timer_handle, BOOLEAN *canceled)
1258
1463
{
1259
1464
        TRACEENTER4("%s", "");
1261
1466
        TRACEEXIT4(return);
1262
1467
}
1263
1468
 
1264
 
/*
1265
 
 * The driver asks ndis what mac it should use. If this
1266
 
 * function returns failiure it will use it's default mac.
1267
 
 */
1268
 
STDCALL static void WRAP_EXPORT(NdisReadNetworkAddress)
 
1469
STDCALL void WRAP_EXPORT(NdisReadNetworkAddress)
1269
1470
        (NDIS_STATUS *status, void **addr, UINT *len,
1270
1471
         struct ndis_handle *handle)
1271
1472
{
1272
1473
        struct ndis_config_param *setting;
1273
 
        struct ustring key, ansi;
 
1474
        struct unicode_string key;
 
1475
        struct ansi_string ansi;
1274
1476
        int ret;
1275
1477
 
1276
1478
        TRACEENTER1("%s", "");
1302
1504
                        for (i = 0; i < ETH_ALEN; i++)
1303
1505
                                handle->mac[i] = int_mac[i];
1304
1506
                        printk(KERN_INFO "%s: %s ethernet device " MACSTR "\n",
1305
 
                               handle->net_dev->name, DRV_NAME,
 
1507
                               handle->net_dev->name, DRIVER_NAME,
1306
1508
                               MAC2STR(handle->mac));
1307
1509
                        *len = ETH_ALEN;
1308
1510
                        *addr = handle->mac;
1313
1515
        TRACEEXIT1(return);
1314
1516
}
1315
1517
 
1316
 
STDCALL static void WRAP_EXPORT(NdisMRegisterAdapterShutdownHandler)
 
1518
STDCALL void WRAP_EXPORT(NdisMRegisterAdapterShutdownHandler)
1317
1519
        (struct ndis_handle *handle, void *ctx, void *func)
1318
1520
{
1319
1521
        TRACEENTER1("sp:%p", get_sp());
1321
1523
        handle->shutdown_ctx = ctx;
1322
1524
}
1323
1525
 
1324
 
STDCALL static void WRAP_EXPORT(NdisMDeregisterAdapterShutdownHandler)
 
1526
STDCALL void WRAP_EXPORT(NdisMDeregisterAdapterShutdownHandler)
1325
1527
        (struct ndis_handle *handle)
1326
1528
{
1327
1529
        TRACEENTER1("sp:%p", get_sp());
1330
1532
}
1331
1533
 
1332
1534
/* bottom half of the irq handler */
1333
 
void ndis_irq_bh(void *data)
 
1535
static void ndis_irq_bh(void *data)
1334
1536
{
1335
 
        struct ndis_irq *ndis_irq = (struct ndis_irq *) data;
 
1537
        struct ndis_irq *ndis_irq = (struct ndis_irq *)data;
1336
1538
        struct ndis_handle *handle = ndis_irq->handle;
1337
1539
        struct miniport_char *miniport = &handle->driver->miniport_char;
 
1540
        KIRQL irql;
1338
1541
 
1339
1542
        if (ndis_irq->enabled) {
1340
 
                KIRQL irql;
1341
 
 
1342
1543
                irql = raise_irql(DISPATCH_LEVEL);
1343
 
                miniport->handle_interrupt(handle->adapter_ctx);
 
1544
                LIN2WIN1(miniport->handle_interrupt, handle->adapter_ctx);
1344
1545
                if (miniport->enable_interrupts)
1345
 
                        miniport->enable_interrupts(handle->adapter_ctx);
 
1546
                        LIN2WIN1(miniport->enable_interrupts,
 
1547
                                 handle->adapter_ctx);
1346
1548
                lower_irql(irql);
1347
1549
        }
1348
1550
}
1349
1551
 
1350
1552
/* Top half of the irq handler */
1351
 
irqreturn_t ndis_irq_th(int irq, void *data, struct pt_regs *pt_regs)
 
1553
static irqreturn_t ndis_irq_th(int irq, void *data, struct pt_regs *pt_regs)
1352
1554
{
1353
1555
        int recognized = 0;
1354
1556
        int handled = 0;
1363
1565
        miniport = &handle->driver->miniport_char;
1364
1566
        /* this spinlock should be shared with NdisMSynchronizeWithInterrupt
1365
1567
         */
1366
 
        spin_lock_irqsave(K_SPINLOCK(&(ndis_irq->lock)), flags);
 
1568
        kspin_lock_irqsave(&ndis_irq->lock, flags);
1367
1569
        if (ndis_irq->req_isr)
1368
 
                miniport->isr(&recognized, &handled, handle->adapter_ctx);
 
1570
                LIN2WIN3(miniport->isr, &recognized, &handled,
 
1571
                         handle->adapter_ctx);
1369
1572
        else { //if (miniport->disable_interrupts)
1370
 
                miniport->disable_interrupts(handle->adapter_ctx);
 
1573
                LIN2WIN1(miniport->disable_interrupts, handle->adapter_ctx);
1371
1574
                /* it is not shared interrupt, so handler must be called */
1372
1575
                recognized = handled = 1;
1373
1576
        }
1374
 
        spin_unlock_irqrestore(K_SPINLOCK(&(ndis_irq->lock)), flags);
 
1577
        kspin_unlock_irqrestore(&ndis_irq->lock, flags);
1375
1578
 
1376
1579
        if (recognized && handled)
1377
1580
                schedule_work(&handle->irq_work);
1382
1585
        return IRQ_NONE;
1383
1586
}
1384
1587
 
1385
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMRegisterInterrupt)
 
1588
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMRegisterInterrupt)
1386
1589
        (struct ndis_irq *ndis_irq, struct ndis_handle *handle,
1387
1590
         UINT vector, UINT level, BOOLEAN req_isr,
1388
1591
         BOOLEAN shared, enum kinterrupt_mode mode)
1397
1600
        if (shared && !req_isr)
1398
1601
                WARNING("%s", "shared but dynamic interrupt!");
1399
1602
        ndis_irq->shared = shared;
1400
 
#ifdef CONFIG_DEBUG_SPINLOCK
1401
 
        ndis_irq->lock = kmalloc(sizeof(struct wrap_spinlock), GFP_KERNEL);
1402
 
        if (!ndis_irq->lock) {
1403
 
                ERROR("couldn't allocate memory");
1404
 
                TRACEEXIT1(return NDIS_STATUS_RESOURCES);
1405
 
        }
1406
 
#else
1407
 
        check_spin_lock_size(ndis_irq->lock);
1408
 
#endif
1409
 
        spin_lock_init(K_SPINLOCK(&(ndis_irq->lock)));
1410
 
        handle->ndis_irq = ndis_irq;
 
1603
        kspin_lock_init(&ndis_irq->lock);
1411
1604
 
1412
1605
        INIT_WORK(&handle->irq_work, &ndis_irq_bh, ndis_irq);
1413
1606
        if (request_irq(vector, ndis_irq_th, shared? SA_SHIRQ : 0,
1414
1607
                        "ndiswrapper", ndis_irq)) {
1415
1608
                printk(KERN_WARNING "%s: request for irq %d failed\n",
1416
 
                       DRV_NAME, vector);
 
1609
                       DRIVER_NAME, vector);
1417
1610
                TRACEEXIT1(return NDIS_STATUS_RESOURCES);
1418
1611
        }
1419
1612
        ndis_irq->enabled = 1;
1420
 
        printk(KERN_INFO "%s: using irq %d\n", DRV_NAME, vector);
 
1613
        printk(KERN_INFO "%s: using irq %d\n", DRIVER_NAME, vector);
1421
1614
        TRACEEXIT1(return NDIS_STATUS_SUCCESS);
1422
1615
}
1423
1616
 
1424
1617
STDCALL void WRAP_EXPORT(NdisMDeregisterInterrupt)
1425
1618
        (struct ndis_irq *ndis_irq)
1426
1619
{
 
1620
        struct ndis_handle *handle;
 
1621
 
1427
1622
        TRACEENTER1("%p", ndis_irq);
1428
1623
 
1429
 
        if (ndis_irq) {
1430
 
                struct ndis_handle *handle = ndis_irq->handle;
1431
 
                ndis_irq->enabled = 0;
1432
 
                /* flush irq_bh workqueue; calling it before enabled=0
1433
 
                 * will crash since some drivers (Centrino at least) don't
1434
 
                 * expect irq hander to be called anymore */
1435
 
                /* cancel_delayed_work is probably better, but 2.4 kernels
1436
 
                 * don't have equivalent function
1437
 
                 */
 
1624
        if (!ndis_irq)
 
1625
                TRACEEXIT1(return);
 
1626
        handle = ndis_irq->handle;
 
1627
        if (!handle)
 
1628
                TRACEEXIT1(return);
 
1629
 
 
1630
        ndis_irq->enabled = 0;
 
1631
        /* flush irq_bh workqueue; calling it before enabled=0 will
 
1632
         * crash since some drivers (Centrino at least) don't expect
 
1633
         * irq hander to be called anymore */
 
1634
        /* cancel_delayed_work is probably better, but 2.4 kernels
 
1635
         * don't have equivalent function
 
1636
         */
1438
1637
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,6,0)
1439
 
                flush_scheduled_work();
1440
 
//              set_current_state(TASK_INTERRUPTIBLE);
1441
 
//              schedule_timeout(HZ/100);
 
1638
        flush_scheduled_work();
1442
1639
#else
1443
 
                set_current_state(TASK_INTERRUPTIBLE);
1444
 
                schedule_timeout(HZ/10);
1445
 
#endif
1446
 
                free_irq(ndis_irq->irq.irq, ndis_irq);
1447
 
#ifdef CONFIG_DEBUG_SPINLOCK
1448
 
                kfree(ndis_irq->lock);
1449
 
                ndis_irq->lock = NULL;
1450
 
#endif
1451
 
                ndis_irq->handle = NULL;
1452
 
                handle->ndis_irq = NULL;
1453
 
        }
 
1640
        set_current_state(TASK_INTERRUPTIBLE);
 
1641
        schedule_timeout(HZ/10);
 
1642
#endif
 
1643
        free_irq(ndis_irq->irq.irq, ndis_irq);
 
1644
        ndis_irq->handle = NULL;
 
1645
        handle->ndis_irq = NULL;
1454
1646
        TRACEEXIT1(return);
1455
1647
}
1456
1648
 
1457
 
STDCALL static BOOLEAN WRAP_EXPORT(NdisMSynchronizeWithInterrupt)
 
1649
STDCALL BOOLEAN WRAP_EXPORT(NdisMSynchronizeWithInterrupt)
1458
1650
        (struct ndis_irq *ndis_irq, void *func, void *ctx)
1459
1651
{
1460
1652
        unsigned char ret;
1467
1659
                TRACEEXIT5(return 0);
1468
1660
 
1469
1661
        sync_func = func;
1470
 
        spin_lock_irqsave(K_SPINLOCK(&(ndis_irq->lock)), flags);
1471
 
        ret = sync_func(ctx);
1472
 
        spin_unlock_irqrestore(K_SPINLOCK(&(ndis_irq->lock)), flags);
 
1662
        kspin_lock_irqsave(&ndis_irq->lock, flags);
 
1663
        ret = LIN2WIN1(sync_func, ctx);
 
1664
        kspin_unlock_irqrestore(&ndis_irq->lock, flags);
1473
1665
 
1474
1666
        DBGTRACE5("sync_func returns %u", ret);
1475
1667
        TRACEEXIT5(return ret);
1476
1668
}
1477
1669
 
1478
 
/* called via fnuction pointer */
 
1670
/* called via function pointer */
1479
1671
STDCALL void
1480
1672
NdisMIndicateStatus(struct ndis_handle *handle,
1481
1673
                    NDIS_STATUS status, void *buf, UINT len)
1482
1674
{
1483
1675
        TRACEENTER2("%08x", status);
1484
1676
 
1485
 
        DBGTRACE2("%08x", status);
1486
1677
        if (status == NDIS_STATUS_MEDIA_DISCONNECT) {
1487
1678
                handle->link_status = 0;
1488
1679
                handle->send_ok = 0;
1489
 
                set_bit(WRAPPER_LINK_STATUS, &handle->wrapper_work);
1490
 
                schedule_work(&handle->wrapper_worker);
 
1680
                set_bit(LINK_STATUS_CHANGED, &handle->wrapper_work);
1491
1681
        }
1492
 
 
1493
1682
        if (status == NDIS_STATUS_MEDIA_CONNECT) {
1494
1683
                handle->link_status = 1;
1495
1684
                handle->send_ok = 1;
1496
 
                set_bit(WRAPPER_LINK_STATUS, &handle->wrapper_work);
1497
 
                schedule_work(&handle->wrapper_worker);
 
1685
                set_bit(LINK_STATUS_CHANGED, &handle->wrapper_work);
1498
1686
        }
1499
1687
 
1500
1688
        if (status == NDIS_STATUS_MEDIA_SPECIFIC_INDICATION && buf) {
1501
 
                struct ndis_status_indication *status =
1502
 
                        (struct ndis_status_indication *)buf;
1503
 
                DBGTRACE2("%s", "media status");
1504
 
                if (status->status_type == NDIS_STATUS_AUTHENTICATION) {
1505
 
                        struct ndis_auth_req *auth_req;
 
1689
                struct ndis_status_indication *status = buf;
 
1690
                struct ndis_auth_req *auth_req;
 
1691
                struct ndis_radio_status_indication *radio_status;
 
1692
 
 
1693
                switch (status->status_type) {
 
1694
                case Ndis802_11StatusType_Authentication:
1506
1695
                        buf = (char *)buf + sizeof(*status);
1507
1696
                        len -= sizeof(*status);
1508
1697
                        while (len > 0) {
1519
1708
                                len -= auth_req->length;
1520
1709
                                buf = (char *)buf + auth_req->length;
1521
1710
                        }
 
1711
                        break;
 
1712
                case Ndis802_11StatusType_MediaStreamMode:
 
1713
                        break;
 
1714
                case Ndis802_11StatusType_PMKID_CandidateList:
 
1715
                        break;
 
1716
                case Ndis802_11StatusType_RadioState:
 
1717
                        radio_status = buf;
 
1718
                        if (radio_status->radio_state ==
 
1719
                            Ndis802_11RadioStatusOn)
 
1720
                                INFO("radio is turned on");
 
1721
                        else if (radio_status->radio_state ==
 
1722
                                 Ndis802_11RadioStatusHardwareOff)
 
1723
                                INFO("radio is turned off by hardware");
 
1724
                        else if (radio_status->radio_state ==
 
1725
                                 Ndis802_11RadioStatusSoftwareOff)
 
1726
                                INFO("radio is turned off by software");
 
1727
                        break;
1522
1728
                }
1523
1729
        }
1524
1730
 
1529
1735
STDCALL void NdisMIndicateStatusComplete(struct ndis_handle *handle)
1530
1736
{
1531
1737
        TRACEENTER3("%s", "");
 
1738
        schedule_work(&handle->wrapper_worker);
1532
1739
}
1533
1740
 
1534
1741
/* called via function pointer */
1536
1743
NdisMIndicateReceivePacket(struct ndis_handle *handle,
1537
1744
                           struct ndis_packet **packets, UINT nr_packets)
1538
1745
{
1539
 
        struct ndis_buffer *buffer;
 
1746
        ndis_buffer *buffer;
1540
1747
        struct ndis_packet *packet;
1541
1748
        struct sk_buff *skb;
1542
1749
        int i;
1543
1750
        struct ndis_work_entry *ndis_work_entry;
 
1751
        KIRQL irql;
1544
1752
 
1545
1753
        TRACEENTER3("%s", "");
1546
1754
        for (i = 0; i < nr_packets; i++) {
1552
1760
 
1553
1761
                buffer = packet->private.buffer_head;
1554
1762
 
1555
 
                skb = dev_alloc_skb(buffer->len);
 
1763
                skb = dev_alloc_skb(MmGetMdlByteCount(buffer));
1556
1764
                if (skb) {
1557
1765
                        skb->dev = handle->net_dev;
1558
 
                        eth_copy_and_sum(skb, buffer->data, buffer->len, 0);
1559
 
                        skb_put(skb, buffer->len);
 
1766
                        eth_copy_and_sum(skb, MmGetMdlVirtualAddress(buffer),
 
1767
                                         MmGetMdlByteCount(buffer), 0);
 
1768
                        skb_put(skb, MmGetMdlByteCount(buffer));
1560
1769
                        skb->protocol = eth_type_trans(skb, handle->net_dev);
1561
 
                        handle->stats.rx_bytes += buffer->len;
 
1770
                        handle->stats.rx_bytes += MmGetMdlByteCount(buffer);
1562
1771
                        handle->stats.rx_packets++;
1563
1772
                        netif_rx(skb);
1564
1773
                } else
1567
1776
                /* serialized drivers check the status upon return
1568
1777
                 * from this function */
1569
1778
                if (test_bit(ATTR_SERIALIZED, &handle->attributes)) {
1570
 
                        packet->status = NDIS_STATUS_SUCCESS;
 
1779
                        packet->oob_data.status = NDIS_STATUS_SUCCESS;
1571
1780
                        continue;
1572
1781
                }
1573
1782
 
1575
1784
                 * NDIS_STATUS_RESOURCES, then it reclaims the packet
1576
1785
                 * upon return from this function: it doesn't matter
1577
1786
                 * what value we set in the status */
1578
 
                if (packet->status == NDIS_STATUS_RESOURCES) {
1579
 
                        packet->status = NDIS_STATUS_SUCCESS;
 
1787
                if (packet->oob_data.status == NDIS_STATUS_RESOURCES) {
 
1788
                        packet->oob_data.status = NDIS_STATUS_SUCCESS;
1580
1789
                        DBGTRACE3("low on resources");
1581
1790
                        continue;
1582
1791
                }
1583
 
                
1584
 
                if (packet->status != NDIS_STATUS_SUCCESS)
 
1792
 
 
1793
                if (packet->oob_data.status != NDIS_STATUS_SUCCESS)
1585
1794
                        WARNING("invalid packet status %08X",
1586
 
                                packet->status);
 
1795
                                packet->oob_data.status);
1587
1796
                /* deserialized driver doesn't check the status upon
1588
1797
                 * return from this function; we need to call
1589
1798
                 * MiniportReturnPacket later for this packet. Calling
1590
1799
                 * MiniportReturnPacket from here is not correct - the
1591
1800
                 * driver doesn't expect it (at least Centrino driver
1592
1801
                 * crashes) */
1593
 
                packet->status = NDIS_STATUS_PENDING;
 
1802
                packet->oob_data.status = NDIS_STATUS_PENDING;
1594
1803
                ndis_work_entry = kmalloc(sizeof(*ndis_work_entry),
1595
1804
                                          GFP_ATOMIC);
1596
1805
                if (!ndis_work_entry) {
1601
1810
                ndis_work_entry->handle = handle;
1602
1811
                ndis_work_entry->entry.return_packet = packet;
1603
1812
 
1604
 
                wrap_spin_lock(&ndis_work_list_lock, DISPATCH_LEVEL);
 
1813
                irql = kspin_lock_irql(&ndis_work_list_lock, DISPATCH_LEVEL);
1605
1814
                list_add_tail(&ndis_work_entry->list, &ndis_work_list);
1606
 
                wrap_spin_unlock(&ndis_work_list_lock);
1607
 
 
 
1815
                kspin_unlock_irql(&ndis_work_list_lock, irql);
1608
1816
        }
1609
1817
        schedule_work(&ndis_work);
1610
1818
        TRACEEXIT3(return);
1656
1864
        TRACEEXIT3(return);
1657
1865
}
1658
1866
 
1659
 
/* called via function pointer (by NdisMEthIndicateReiceve macro) */
 
1867
/* called via function pointer (by NdisMEthIndicateReceive macro) */
1660
1868
STDCALL void
1661
1869
EthRxIndicateHandler(void *adapter_ctx, void *rx_ctx, char *header1,
1662
1870
                     char *header, UINT header_size, void *look_ahead,
1681
1889
                struct miniport_char *miniport;
1682
1890
                unsigned int res, bytes_txed;
1683
1891
 
1684
 
                NdisAllocatePacket(&res, &packet, NULL);
1685
 
                if (res != NDIS_STATUS_SUCCESS) {
 
1892
                packet = allocate_ndis_packet();
 
1893
                if (!packet) {
1686
1894
                        handle->stats.rx_dropped++;
1687
1895
                        TRACEEXIT3(return);
1688
1896
                }
 
1897
                packet->private.pool = NULL;
1689
1898
 
1690
1899
                miniport = &handle->driver->miniport_char;
1691
1900
                irql = raise_irql(DISPATCH_LEVEL);
1692
 
                res = miniport->tx_data(packet, &bytes_txed, adapter_ctx,
1693
 
                                        rx_ctx, look_ahead_size, packet_size);
 
1901
                res = LIN2WIN6(miniport->tx_data, packet, &bytes_txed,
 
1902
                               adapter_ctx, rx_ctx, look_ahead_size,
 
1903
                               packet_size);
1694
1904
                lower_irql(irql);
1695
1905
                if (res == NDIS_STATUS_SUCCESS) {
 
1906
                        ndis_buffer *buffer;
1696
1907
                        skb = dev_alloc_skb(header_size+look_ahead_size+
1697
1908
                                            bytes_txed);
1698
1909
                        if (skb) {
1699
1910
                                memcpy(skb->data, header, header_size);
1700
1911
                                memcpy(skb->data+header_size, look_ahead,
1701
1912
                                       look_ahead_size);
 
1913
                                buffer = packet->private.buffer_head;
1702
1914
                                memcpy(skb->data+header_size+look_ahead_size,
1703
 
                                       packet->private.buffer_head->data,
 
1915
                                       MmGetMdlVirtualAddress(buffer),
1704
1916
                                       bytes_txed);
1705
1917
                                skb_size = header_size+look_ahead_size+
1706
1918
                                        bytes_txed;
1707
 
                                NdisFreePacket(packet);
 
1919
                                free_ndis_packet(packet);
1708
1920
                        }
1709
1921
                } else if (res == NDIS_STATUS_PENDING) {
1710
1922
                        /* driver will call td_complete */
1711
1923
                        packet->look_ahead = kmalloc(look_ahead_size,
1712
1924
                                                     GFP_ATOMIC);
1713
1925
                        if (!packet->look_ahead) {
1714
 
                                NdisFreePacket(packet);
 
1926
                                free_ndis_packet(packet);
1715
1927
                                handle->stats.rx_dropped++;
1716
1928
                                TRACEEXIT3(return);
1717
1929
                        }
1718
 
                        memcpy(&packet->header, header, 
 
1930
                        memcpy(&packet->header, header,
1719
1931
                               sizeof(packet->header));
1720
1932
                        memcpy(packet->look_ahead, look_ahead,
1721
1933
                               look_ahead_size);
1722
1934
                        packet->look_ahead_size = look_ahead_size;
1723
1935
                } else {
1724
 
                        NdisFreePacket(packet);
 
1936
                        free_ndis_packet(packet);
1725
1937
                        handle->stats.rx_dropped++;
1726
1938
                        TRACEEXIT3(return);
1727
1939
                }
1764
1976
                TRACEEXIT3(return);
1765
1977
        }
1766
1978
 
1767
 
        if ((int)packet->look_ahead_size <= 0) {
1768
 
                WARNING("illegal packet? (look_ahead_size = %d)",
1769
 
                        packet->look_ahead_size);
1770
 
                TRACEEXIT3(return);
1771
 
        }
1772
 
 
1773
 
        skb_size = sizeof(packet->header)+packet->look_ahead_size+bytes_txed;
 
1979
        skb_size = sizeof(packet->header) + packet->look_ahead_size +
 
1980
                bytes_txed;
1774
1981
 
1775
1982
        skb = dev_alloc_skb(skb_size);
1776
1983
        if (!skb) {
1777
1984
                kfree(packet->look_ahead);
1778
 
                NdisFreePacket(packet);
 
1985
                free_ndis_packet(packet);
1779
1986
                handle->stats.rx_dropped++;
1780
1987
                TRACEEXIT3(return);
1781
1988
        }
1782
1989
 
1783
1990
        skb->dev = handle->net_dev;
1784
1991
        memcpy(skb->data, packet->header, sizeof(packet->header));
1785
 
        memcpy(skb->data+sizeof(packet->header), packet->look_ahead,
 
1992
        memcpy(skb->data + sizeof(packet->header), packet->look_ahead,
1786
1993
               packet->look_ahead_size);
1787
 
        memcpy(skb->data+sizeof(packet->header)+packet->look_ahead_size,
1788
 
               packet->private.buffer_head->data, bytes_txed);
 
1994
        memcpy(skb->data + sizeof(packet->header) + packet->look_ahead_size,
 
1995
               MmGetMdlVirtualAddress(packet->private.buffer_head),
 
1996
               bytes_txed);
1789
1997
        kfree(packet->look_ahead);
1790
 
        NdisFreePacket(packet);
 
1998
        free_ndis_packet(packet);
1791
1999
        skb_put(skb, skb_size);
1792
2000
        skb->protocol = eth_type_trans(skb, handle->net_dev);
1793
2001
        handle->stats.rx_bytes += skb_size;
1838
2046
        TRACEEXIT3(return);
1839
2047
}
1840
2048
 
1841
 
STDCALL static void WRAP_EXPORT(NdisMSleep)
 
2049
STDCALL void WRAP_EXPORT(NdisMSleep)
1842
2050
        (ULONG us_to_sleep)
1843
2051
{
1844
2052
        TRACEENTER4("us: %u", us_to_sleep);
1856
2064
        *time = ticks_1601();
1857
2065
}
1858
2066
 
1859
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMRegisterIoPortRange)
 
2067
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMRegisterIoPortRange)
1860
2068
        (void **virt, struct ndis_handle *handle, UINT start, UINT len)
1861
2069
{
1862
 
        ULONG_PTR p;
1863
 
        TRACEENTER3("%u %u", start, len);
1864
 
        p = start;
1865
 
        *virt = (void *)p;
 
2070
        TRACEENTER3("%08x %08x", start, len);
 
2071
        *virt = (void *)(ULONG_PTR)start;
1866
2072
        return NDIS_STATUS_SUCCESS;
1867
2073
}
1868
2074
 
1869
 
STDCALL static void WRAP_EXPORT(NdisMDeregisterIoPortRange)
 
2075
STDCALL void WRAP_EXPORT(NdisMDeregisterIoPortRange)
1870
2076
        (struct ndis_handle *handle, UINT start, UINT len, void* virt)
1871
2077
{
1872
2078
        TRACEENTER1("%08x %08x", start, len);
1873
2079
}
1874
2080
 
1875
 
STDCALL static LONG WRAP_EXPORT(NdisInterlockedDecrement)
 
2081
STDCALL LONG WRAP_EXPORT(NdisInterlockedDecrement)
1876
2082
        (LONG *val)
1877
2083
{
1878
2084
        LONG x;
1879
2085
 
1880
2086
        TRACEENTER4("%s", "");
1881
 
        wrap_spin_lock(&atomic_lock, PASSIVE_LEVEL);
 
2087
        kspin_lock(&ntoskernel_lock);
1882
2088
        (*val)--;
1883
2089
        x = *val;
1884
 
        wrap_spin_unlock(&atomic_lock);
 
2090
        kspin_unlock(&ntoskernel_lock);
1885
2091
        TRACEEXIT4(return x);
1886
2092
}
1887
2093
 
1888
 
STDCALL static LONG WRAP_EXPORT(NdisInterlockedIncrement)
 
2094
STDCALL LONG WRAP_EXPORT(NdisInterlockedIncrement)
1889
2095
        (LONG *val)
1890
2096
{
1891
2097
        LONG x;
1892
2098
 
1893
2099
        TRACEENTER4("%s", "");
1894
 
        wrap_spin_lock(&atomic_lock, PASSIVE_LEVEL);
 
2100
        kspin_lock(&ntoskernel_lock);
1895
2101
        (*val)++;
1896
2102
        x = *val;
1897
 
        wrap_spin_unlock(&atomic_lock);
 
2103
        kspin_unlock(&ntoskernel_lock);
1898
2104
        TRACEEXIT4(return x);
1899
2105
}
1900
2106
 
1901
 
STDCALL static struct list_entry * WRAP_EXPORT(NdisInterlockedInsertHeadList)
 
2107
STDCALL struct list_entry * WRAP_EXPORT(NdisInterlockedInsertHeadList)
1902
2108
        (struct list_entry *head, struct list_entry *entry,
1903
2109
         struct ndis_spinlock *lock)
1904
2110
{
1914
2120
        head->fwd_link = entry;
1915
2121
 
1916
2122
        NdisReleaseSpinLock(lock);
1917
 
        TRACEEXIT4(return (flink != head) ? flink : NULL);
 
2123
        TRACEEXIT4(return (flink == head) ? NULL : flink);
1918
2124
}
1919
2125
 
1920
 
STDCALL static struct list_entry * WRAP_EXPORT(NdisInterlockedInsertTailList)
 
2126
STDCALL struct list_entry * WRAP_EXPORT(NdisInterlockedInsertTailList)
1921
2127
        (struct list_entry *head, struct list_entry *entry,
1922
2128
         struct ndis_spinlock *lock)
1923
2129
{
1933
2139
        head->bwd_link = entry;
1934
2140
 
1935
2141
        NdisReleaseSpinLock(lock);
1936
 
        TRACEEXIT4(return (flink != head) ? flink : NULL);
 
2142
        TRACEEXIT4(return (flink == head) ? NULL : flink);
1937
2143
}
1938
2144
 
1939
 
STDCALL static struct list_entry * WRAP_EXPORT(NdisInterlockedRemoveHeadList)
 
2145
STDCALL struct list_entry * WRAP_EXPORT(NdisInterlockedRemoveHeadList)
1940
2146
        (struct list_entry *head, struct ndis_spinlock *lock)
1941
2147
{
1942
2148
        struct list_entry *flink;
1949
2155
        head->fwd_link->bwd_link = head;
1950
2156
 
1951
2157
        NdisReleaseSpinLock(lock);
1952
 
        TRACEEXIT4(return (flink != head) ? flink : NULL);
 
2158
        TRACEEXIT4(return (flink == head) ? NULL : flink);
1953
2159
}
1954
2160
 
1955
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMInitializeScatterGatherDma)
1956
 
        (struct ndis_handle *handle, BOOLEAN is64bit, ULONG max_phy_map)
 
2161
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMInitializeScatterGatherDma)
 
2162
        (struct ndis_handle *handle, UCHAR dma_size, ULONG max_phy_map)
1957
2163
{
1958
 
        TRACEENTER2("64bit=%d, maxtransfer=%u", is64bit, max_phy_map);
1959
 
        handle->use_scatter_gather = 1;
 
2164
        TRACEENTER2("dma_size=%d, maxtransfer=%u", dma_size, max_phy_map);
 
2165
#ifdef CONFIG_X86_64
 
2166
        if (dma_size != NDIS_DMA_64BITS)
 
2167
                ERROR("DMA size is not 64-bits");
 
2168
#endif
 
2169
        handle->use_sg_dma = 1;
1960
2170
        return NDIS_STATUS_SUCCESS;
1961
2171
}
1962
2172
 
1963
 
STDCALL static ULONG WRAP_EXPORT(NdisMGetDmaAlignment)
 
2173
STDCALL ULONG WRAP_EXPORT(NdisMGetDmaAlignment)
1964
2174
        (struct ndis_handle *handle)
1965
2175
{
1966
2176
        TRACEENTER3("%s", "");
1971
2181
#endif
1972
2182
}
1973
2183
 
1974
 
STDCALL static void WRAP_EXPORT(NdisQueryBufferOffset)
1975
 
        (struct ndis_buffer *buffer, UINT *offset, UINT *length)
 
2184
STDCALL void WRAP_EXPORT(NdisQueryBufferOffset)
 
2185
        (ndis_buffer *buffer, UINT *offset, UINT *length)
1976
2186
{
1977
2187
        TRACEENTER3("%s", "");
1978
 
        *offset = 0;
1979
 
        *length = buffer->len;
 
2188
        *offset = MmGetMdlByteOffset(buffer);
 
2189
        *length = MmGetMdlByteCount(buffer);
1980
2190
}
1981
2191
 
1982
 
STDCALL static CHAR WRAP_EXPORT(NdisSystemProcessorCount)
 
2192
STDCALL CHAR WRAP_EXPORT(NdisSystemProcessorCount)
1983
2193
        (void)
1984
2194
{
1985
2195
        return NR_CPUS;
1986
2196
}
1987
2197
 
1988
 
STDCALL static void WRAP_EXPORT(NdisInitializeEvent)
 
2198
STDCALL void WRAP_EXPORT(NdisInitializeEvent)
1989
2199
        (struct ndis_event *ndis_event)
1990
2200
{
1991
2201
        TRACEENTER3("%p", ndis_event);
1992
 
        KeInitializeEvent(&ndis_event->kevent, NOTIFICATION_EVENT, 0);
 
2202
        KeInitializeEvent(&ndis_event->kevent, NotificationEvent, 0);
1993
2203
}
1994
2204
 
1995
2205
STDCALL BOOLEAN WRAP_EXPORT(NdisWaitEvent)
1996
2206
        (struct ndis_event *ndis_event, UINT ms)
1997
2207
{
1998
2208
        LARGE_INTEGER ticks;
1999
 
        NT_STATUS res;
 
2209
        NTSTATUS res;
2000
2210
 
2001
2211
        TRACEENTER3("%p %u", ndis_event, ms);
2002
2212
        ticks = ms * 10000;
2014
2224
        KeSetEvent(&ndis_event->kevent, 0, 0);
2015
2225
}
2016
2226
 
2017
 
STDCALL static void WRAP_EXPORT(NdisResetEvent)
 
2227
STDCALL void WRAP_EXPORT(NdisResetEvent)
2018
2228
        (struct ndis_event *ndis_event)
2019
2229
{
2020
2230
        TRACEENTER3("%p", ndis_event);
2054
2264
        TRACEENTER3("%s", "");
2055
2265
 
2056
2266
        while (1) {
2057
 
                wrap_spin_lock(&ndis_work_list_lock, PASSIVE_LEVEL);
 
2267
                irql = kspin_lock_irql(&ndis_work_list_lock, DISPATCH_LEVEL);
2058
2268
                if (list_empty(&ndis_work_list))
2059
2269
                        ndis_work_entry = NULL;
2060
2270
                else {
2061
2271
                        ndis_work_entry =
2062
 
                                (struct ndis_work_entry *)ndis_work_list.next;
 
2272
                                list_entry(ndis_work_list.next,
 
2273
                                           struct ndis_work_entry, list);
2063
2274
                        list_del(&ndis_work_entry->list);
2064
2275
                }
2065
 
                wrap_spin_unlock(&ndis_work_list_lock);
 
2276
                kspin_unlock_irql(&ndis_work_list_lock, irql);
2066
2277
 
2067
2278
                if (!ndis_work_entry) {
2068
2279
                        DBGTRACE3("%s", "No more work");
2078
2289
                        DBGTRACE3("Calling work at %p with parameter %p",
2079
2290
                                  sched_work_item->func,
2080
2291
                                  sched_work_item->ctx);
2081
 
                        sched_work_item->func(sched_work_item,
2082
 
                                              sched_work_item->ctx);
 
2292
                        LIN2WIN2(sched_work_item->func, sched_work_item,
 
2293
                                 sched_work_item->ctx);
2083
2294
                        break;
2084
2295
 
2085
2296
                case NDIS_IO_WORK_ITEM:
2088
2299
 
2089
2300
                        DBGTRACE3("Calling work at %p with parameter %p",
2090
2301
                                  io_work_item->func, io_work_item->ctx);
2091
 
                        io_work_item->func(io_work_item->device_object,
2092
 
                                           io_work_item->ctx);
 
2302
                        LIN2WIN2(io_work_item->func,
 
2303
                                io_work_item->device_object,
 
2304
                                io_work_item->ctx);
2093
2305
                        break;
2094
2306
 
2095
2307
                case NDIS_ALLOC_MEM_WORK_ITEM:
2103
2315
                                                  alloc_mem->cached,
2104
2316
                                                  &virt, &phys);
2105
2317
                        irql = raise_irql(DISPATCH_LEVEL);
2106
 
                        miniport->alloc_complete(handle, virt, &phys,
2107
 
                                                 alloc_mem->size,
2108
 
                                                 alloc_mem->ctx);
 
2318
                        LIN2WIN5(miniport->alloc_complete, handle, virt,
 
2319
                                 &phys, alloc_mem->size, alloc_mem->ctx);
2109
2320
                        lower_irql(irql);
2110
2321
                        break;
2111
2322
 
2122
2333
                        packet = ndis_work_entry->entry.return_packet;
2123
2334
                        miniport = &handle->driver->miniport_char;
2124
2335
                        irql = raise_irql(DISPATCH_LEVEL);
2125
 
                        miniport->return_packet(handle->adapter_ctx, packet);
 
2336
                        LIN2WIN2(miniport->return_packet,
 
2337
                                 handle->adapter_ctx, packet);
2126
2338
                        lower_irql(irql);
2127
2339
                        break;
2128
2340
 
2136
2348
        TRACEEXIT3(return);
2137
2349
}
2138
2350
 
2139
 
STDCALL static struct ndis_io_work_item *WRAP_EXPORT(IoAllocateWorkItem)
 
2351
STDCALL struct ndis_io_work_item *WRAP_EXPORT(IoAllocateWorkItem)
2140
2352
        (void *device_object)
2141
2353
{
2142
2354
        struct ndis_io_work_item *io_work_item;
2149
2361
        return io_work_item;
2150
2362
}
2151
2363
 
2152
 
STDCALL static void WRAP_EXPORT(IoFreeWorkItem)
 
2364
STDCALL void WRAP_EXPORT(IoFreeWorkItem)
2153
2365
        (struct ndis_io_work_item *io_work_item)
2154
2366
{
2155
2367
        kfree(io_work_item);
2156
2368
        return;
2157
2369
}
2158
2370
 
2159
 
STDCALL static void WRAP_EXPORT(IoQueueWorkItem)
 
2371
STDCALL void WRAP_EXPORT(IoQueueWorkItem)
2160
2372
        (struct ndis_io_work_item *io_work_item, void *func,
2161
2373
         enum work_queue_type queue_type, void *ctx)
2162
2374
{
2163
2375
        struct ndis_work_entry *ndis_work_entry;
 
2376
        KIRQL irql;
2164
2377
 
2165
2378
        TRACEENTER3("%s", "");
2166
2379
        if (io_work_item == NULL) {
2177
2390
        io_work_item->ctx = ctx;
2178
2391
        ndis_work_entry->entry.io_work_item = io_work_item;
2179
2392
 
2180
 
        wrap_spin_lock(&ndis_work_list_lock, DISPATCH_LEVEL);
 
2393
        irql = kspin_lock_irql(&ndis_work_list_lock, DISPATCH_LEVEL);
2181
2394
        list_add_tail(&ndis_work_entry->list, &ndis_work_list);
2182
 
        wrap_spin_unlock(&ndis_work_list_lock);
 
2395
        kspin_unlock_irql(&ndis_work_list_lock, irql);
2183
2396
 
2184
2397
        schedule_work(&ndis_work);
2185
2398
        TRACEEXIT3(return);
2186
2399
}
2187
2400
 
2188
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisScheduleWorkItem)
 
2401
STDCALL NDIS_STATUS WRAP_EXPORT(NdisScheduleWorkItem)
2189
2402
        (struct ndis_sched_work_item *ndis_sched_work_item)
2190
2403
{
2191
2404
        struct ndis_work_entry *ndis_work_entry;
 
2405
        KIRQL irql;
2192
2406
 
2193
2407
        TRACEENTER3("%s", "");
2194
2408
        /* this function is called from irq_bh by realtek driver */
2199
2413
        ndis_work_entry->type = NDIS_SCHED_WORK_ITEM;
2200
2414
        ndis_work_entry->entry.sched_work_item = ndis_sched_work_item;
2201
2415
 
2202
 
        wrap_spin_lock(&ndis_work_list_lock, DISPATCH_LEVEL);
 
2416
        irql = kspin_lock_irql(&ndis_work_list_lock, DISPATCH_LEVEL);
2203
2417
        list_add_tail(&ndis_work_entry->list, &ndis_work_list);
2204
 
        wrap_spin_unlock(&ndis_work_list_lock);
 
2418
        kspin_unlock_irql(&ndis_work_list_lock, irql);
2205
2419
 
2206
2420
        schedule_work(&ndis_work);
2207
2421
        TRACEEXIT3(return NDIS_STATUS_SUCCESS);
2208
2422
}
2209
2423
 
2210
 
STDCALL static void WRAP_EXPORT(NdisUnchainBufferAtBack)
2211
 
        (struct ndis_packet *packet, struct ndis_buffer **buffer)
 
2424
STDCALL void WRAP_EXPORT(NdisUnchainBufferAtBack)
 
2425
        (struct ndis_packet *packet, ndis_buffer **buffer)
2212
2426
{
2213
 
        struct ndis_buffer *b = packet->private.buffer_head;
2214
 
        struct ndis_buffer *btail = packet->private.buffer_tail;
 
2427
        ndis_buffer *b, *btail;
2215
2428
 
2216
 
        TRACEENTER3("%p", b);
 
2429
        TRACEENTER3("%p", packet);
 
2430
        if (packet == NULL || buffer == NULL)
 
2431
                return;
 
2432
        b = packet->private.buffer_head;
2217
2433
        if (!b) {
2218
 
                /* No buffer in packet */
 
2434
                /* no buffer in packet */
2219
2435
                *buffer = NULL;
2220
2436
                TRACEEXIT3(return);
2221
2437
        }
2222
 
 
 
2438
        btail = packet->private.buffer_tail;
 
2439
        *buffer = btail;
 
2440
        packet->private.valid_counts = FALSE;
2223
2441
        if (b == btail) {
2224
 
                /* Only buffer in packet */
 
2442
                /* one buffer in packet */
2225
2443
                packet->private.buffer_head = NULL;
2226
2444
                packet->private.buffer_tail = NULL;
2227
2445
        } else {
2228
2446
                while (b->next != btail)
2229
2447
                        b = b->next;
2230
2448
                packet->private.buffer_tail = b;
 
2449
                b->next = NULL;
2231
2450
        }
2232
 
        b->next = 0;
2233
 
        packet->private.valid_counts = 0;
2234
 
        *buffer = btail;
2235
2451
        TRACEEXIT3(return);
2236
2452
}
2237
2453
 
2238
 
STDCALL static void WRAP_EXPORT(NdisUnchainBufferAtFront)
2239
 
        (struct ndis_packet *packet, struct ndis_buffer **buffer)
 
2454
STDCALL void WRAP_EXPORT(NdisUnchainBufferAtFront)
 
2455
        (struct ndis_packet *packet, ndis_buffer **buffer)
2240
2456
{
2241
 
        struct ndis_buffer *b = packet->private.buffer_head;
2242
 
 
2243
 
        TRACEENTER3("%p", b);
2244
 
        if (!b) {
2245
 
                /* No buffer in packet */
 
2457
        TRACEENTER3("%p", packet);
 
2458
        if (buffer == NULL)
 
2459
                return;
 
2460
        if (packet == NULL) {
 
2461
                /* no buffer in packet */
2246
2462
                *buffer = NULL;
2247
2463
                TRACEEXIT3(return);
2248
2464
        }
2249
2465
 
2250
 
        if (b == packet->private.buffer_tail) {
2251
 
                /* Only buffer in packet */
 
2466
        packet->private.valid_counts = FALSE;
 
2467
        *buffer = packet->private.buffer_head;
 
2468
        if (packet->private.buffer_head == packet->private.buffer_tail) {
 
2469
                /* one buffer in packet */
2252
2470
                packet->private.buffer_head = NULL;
2253
2471
                packet->private.buffer_tail = NULL;
2254
2472
        } else
2255
 
                packet->private.buffer_head = b->next;
2256
 
 
2257
 
        b->next = NULL;
2258
 
        packet->private.valid_counts = 0;
2259
 
 
2260
 
        *buffer = b;
 
2473
                packet->private.buffer_head = (*buffer)->next;
 
2474
 
2261
2475
        TRACEEXIT3(return);
2262
2476
}
2263
2477
 
2264
 
STDCALL static void WRAP_EXPORT(NdisGetFirstBufferFromPacketSafe)
2265
 
        (struct ndis_packet *packet, struct ndis_buffer **buffer, void **virt,
2266
 
         UINT *len, UINT *totlen, enum mm_page_priority priority)
 
2478
STDCALL void WRAP_EXPORT(NdisGetFirstBufferFromPacketSafe)
 
2479
        (struct ndis_packet *packet, ndis_buffer **first_buffer,
 
2480
         void **first_buffer_va, UINT *first_buffer_length,
 
2481
         UINT *total_buffer_length, enum mm_page_priority priority)
2267
2482
{
2268
 
        struct ndis_buffer *b = packet->private.buffer_head;
 
2483
        ndis_buffer *b = packet->private.buffer_head;
2269
2484
 
2270
2485
        TRACEENTER3("%p", b);
2271
 
 
2272
 
        *buffer = b;
2273
 
        *virt = b->data;
2274
 
        *len = b->len;
2275
 
        *totlen = packet->private.len;
2276
 
}
2277
 
 
2278
 
STDCALL static void WRAP_EXPORT(NdisMStartBufferPhysicalMapping)
2279
 
        (struct ndis_handle *handle, struct ndis_buffer *buf,
 
2486
        *first_buffer = b;
 
2487
        if (b) {
 
2488
                *first_buffer_va = MmGetMdlVirtualAddress(b);
 
2489
                *first_buffer_length = *total_buffer_length =
 
2490
                        MmGetMdlByteCount(b);
 
2491
                for (b = b->next; b != NULL; b = b->next)
 
2492
                        *total_buffer_length += MmGetMdlByteCount(b);
 
2493
        } else {
 
2494
                *first_buffer_va = NULL;
 
2495
                *first_buffer_length = 0;
 
2496
                *total_buffer_length = 0;
 
2497
        }
 
2498
}
 
2499
 
 
2500
STDCALL void WRAP_EXPORT(NdisCopyFromPacketToPacketSafe)
 
2501
        (struct ndis_packet *dst, UINT dst_offset, UINT num_to_copy,
 
2502
         struct ndis_packet *src, UINT src_offset, UINT *num_copied,
 
2503
         enum mm_page_priority priority)
 
2504
{
 
2505
        UINT dst_left, src_left, left, done;
 
2506
        ndis_buffer *dst_buf;
 
2507
        ndis_buffer *src_buf;
 
2508
 
 
2509
        TRACEENTER4("");
 
2510
        if (!dst || !src) {
 
2511
                *num_copied = 0;
 
2512
                TRACEEXIT4(return);
 
2513
        }
 
2514
 
 
2515
        dst_buf = dst->private.buffer_head;
 
2516
        src_buf = src->private.buffer_head;
 
2517
 
 
2518
        if (!dst_buf || !src_buf) {
 
2519
                *num_copied = 0;
 
2520
                TRACEEXIT4(return);
 
2521
        }
 
2522
        dst_left = MmGetMdlByteCount(dst_buf) - dst_offset;
 
2523
        src_left = MmGetMdlByteCount(src_buf) - src_offset;
 
2524
 
 
2525
        left = min(src_left, dst_left);
 
2526
        left = min(left, num_to_copy);
 
2527
        memcpy(MmGetMdlVirtualAddress(dst_buf) + dst_offset,
 
2528
               MmGetMdlVirtualAddress(src_buf) + src_offset, left);
 
2529
 
 
2530
        done = num_to_copy - left;
 
2531
        while (done > 0) {
 
2532
                if (left == dst_left) {
 
2533
                        dst_buf = dst_buf->next;
 
2534
                        if (!dst_buf)
 
2535
                                break;
 
2536
                        dst_left = MmGetMdlByteCount(dst_buf);
 
2537
                } else
 
2538
                        dst_left -= left;
 
2539
                if (left == src_left) {
 
2540
                        src_buf = src_buf->next;
 
2541
                        if (!src_buf)
 
2542
                                break;
 
2543
                        src_left = MmGetMdlByteCount(src_buf);
 
2544
                } else
 
2545
                        src_left -= left;
 
2546
 
 
2547
                left = min(src_left, dst_left);
 
2548
                left = min(left, done);
 
2549
                memcpy(MmGetMdlVirtualAddress(dst_buf),
 
2550
                       MmGetMdlVirtualAddress(src_buf), left);
 
2551
                done -= left;
 
2552
        }
 
2553
        *num_copied = num_to_copy - done;
 
2554
        TRACEEXIT4(return);
 
2555
}
 
2556
 
 
2557
STDCALL void WRAP_EXPORT(NdisCopyFromPacketToPacket)
 
2558
        (struct ndis_packet *dst, UINT dst_offset, UINT num_to_copy,
 
2559
         struct ndis_packet *src, UINT src_offset, UINT *num_copied)
 
2560
{
 
2561
        NdisCopyFromPacketToPacketSafe(dst, dst_offset, num_to_copy,
 
2562
                                       src, src_offset, num_copied,
 
2563
                                       NormalPagePriority);
 
2564
        return;
 
2565
}
 
2566
 
 
2567
STDCALL void WRAP_EXPORT(NdisMStartBufferPhysicalMapping)
 
2568
        (struct ndis_handle *handle, ndis_buffer *buf,
2280
2569
         ULONG phy_map_reg, BOOLEAN write_to_dev,
2281
2570
         struct ndis_phy_addr_unit *phy_addr_array, UINT *array_size)
2282
2571
{
2283
 
        dma_addr_t dma_addr;
2284
2572
        TRACEENTER3("phy_map_reg: %u", phy_map_reg);
 
2573
 
2285
2574
        if (!write_to_dev) {
2286
2575
                ERROR( "dma from device not supported (%d)", write_to_dev);
2287
2576
                *array_size = 0;
2297
2586
 
2298
2587
        if (handle->map_dma_addr[phy_map_reg] != 0) {
2299
2588
//              ERROR("map register already used (%lu)", phy_map_reg);
2300
 
                *array_size = 0;
 
2589
                *array_size = 1;
2301
2590
                return;
2302
2591
        }
2303
2592
 
2304
2593
        // map buffer
2305
2594
        /* FIXME: do USB drivers call this? */
2306
 
        dma_addr = PCI_DMA_MAP_SINGLE(handle->dev.pci, buf->data, buf->len,
2307
 
                                      PCI_DMA_TODEVICE);
2308
 
        phy_addr_array[0].phy_addr.quad = dma_addr;
2309
 
        phy_addr_array[0].length= buf->len;
 
2595
        phy_addr_array[0].phy_addr =
 
2596
                PCI_DMA_MAP_SINGLE(handle->dev.pci,
 
2597
                                   MmGetMdlVirtualAddress(buf),
 
2598
                                   MmGetMdlByteCount(buf), PCI_DMA_TODEVICE);
 
2599
        phy_addr_array[0].length = MmGetMdlByteCount(buf);
2310
2600
 
2311
2601
        *array_size = 1;
2312
2602
 
2313
2603
        // save mapping index
2314
 
        handle->map_dma_addr[phy_map_reg] = dma_addr;
 
2604
        handle->map_dma_addr[phy_map_reg] = phy_addr_array[0].phy_addr;
2315
2605
}
2316
2606
 
2317
 
STDCALL static void WRAP_EXPORT(NdisMCompleteBufferPhysicalMapping)
2318
 
        (struct ndis_handle *handle, struct ndis_buffer *buf,
 
2607
STDCALL void WRAP_EXPORT(NdisMCompleteBufferPhysicalMapping)
 
2608
        (struct ndis_handle *handle, ndis_buffer *buf,
2319
2609
         ULONG phy_map_reg)
2320
2610
{
2321
2611
        TRACEENTER3("%p %u (%u)", handle, phy_map_reg, handle->map_count);
2335
2625
        /* FIXME: do USB drivers call this? */
2336
2626
        PCI_DMA_UNMAP_SINGLE(handle->dev.pci,
2337
2627
                             handle->map_dma_addr[phy_map_reg],
2338
 
                             buf->len, PCI_DMA_TODEVICE);
 
2628
                             MmGetMdlByteCount(buf), PCI_DMA_TODEVICE);
2339
2629
 
2340
2630
        // clear mapping index
2341
2631
        handle->map_dma_addr[phy_map_reg] = 0;
2342
2632
}
2343
2633
 
2344
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMRegisterDevice)
2345
 
        (struct ndis_handle *handle, struct ustring *dev_name,
2346
 
         struct ustring *sym_name, void **funcs,
 
2634
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMRegisterDevice)
 
2635
        (struct ndis_handle *handle, struct unicode_string *dev_name,
 
2636
         struct unicode_string *sym_name, void **funcs,
2347
2637
         struct device_object **dev_object, struct ndis_handle **dev_handle)
2348
2638
{
2349
2639
        TRACEENTER1("%p, %p", *dev_handle, handle);
2352
2642
        return NDIS_STATUS_SUCCESS;
2353
2643
}
2354
2644
 
2355
 
STDCALL static NDIS_STATUS WRAP_EXPORT(NdisMDeregisterDevice)
 
2645
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMDeregisterDevice)
2356
2646
        (struct ndis_handle *handle)
2357
2647
{
2358
2648
        return NDIS_STATUS_SUCCESS;
2359
2649
}
2360
2650
 
2361
 
STDCALL static void WRAP_EXPORT(NdisMGetDeviceProperty)
 
2651
STDCALL void WRAP_EXPORT(NdisMGetDeviceProperty)
2362
2652
        (struct ndis_handle *handle, void **phy_dev, void **func_dev,
2363
2653
         void **next_dev, void **alloc_res, void**trans_res)
2364
2654
{
2370
2660
                next_dev, alloc_res, trans_res);
2371
2661
 
2372
2662
        if (!handle->phys_device_obj) {
2373
 
                dev = kmalloc(
2374
 
                        sizeof(struct device_object), GFP_KERNEL);
 
2663
                /* some drivers don't allocate this pointer, nor is it
 
2664
                 * NULL so use wrap_kmalloc so it gets freed
 
2665
                 * automatically, if indeed we allocate it here */
 
2666
                dev = wrap_kmalloc(sizeof(*dev), GFP_KERNEL);
2375
2667
                if (!dev) {
2376
2668
                        ERROR("%s", "unable to allocate "
2377
2669
                                "DEVICE_OBJECT structure!");
2378
 
                        BUG();
 
2670
                        TRACEEXIT2(return);
2379
2671
                }
2380
2672
        
2381
2673
                for (i = 0; i < (sizeof(*dev)/sizeof(void *)); i++)
2392
2684
                /* assumes that the handle refers to an USB device */
2393
2685
                dev->device.usb = handle->dev.usb;
2394
2686
 
 
2687
                dev->handle = handle;
 
2688
 
2395
2689
                handle->phys_device_obj = dev;
2396
 
                dev->handle = (void *)handle;
2397
2690
        }
2398
2691
 
2399
2692
        if (phy_dev) {
2423
2716
        }
2424
2717
}
2425
2718
 
2426
 
STDCALL static unsigned long WRAP_EXPORT(NdisReadPcmciaAttributeMemory)
2427
 
        (struct ndis_handle *handle, ULONG offset, void *buffer,
2428
 
         ULONG length)
 
2719
STDCALL void WRAP_EXPORT(NdisMRegisterUnloadHandler)
 
2720
        (struct ndis_driver *driver, void *unload)
 
2721
{
 
2722
        if (driver)
 
2723
                driver->driver_unload = unload;
 
2724
        return;
 
2725
}
 
2726
 
 
2727
STDCALL NDIS_STATUS WRAP_EXPORT(NdisMQueryAdapterInstanceName)
 
2728
        (struct unicode_string *name, struct ndis_handle *handle)
 
2729
{
 
2730
        struct ansi_string ansi_string;
 
2731
 
 
2732
        if (handle->driver->bustype == NDIS_PCI_BUS)
 
2733
                ansi_string.buf = "PCI Ethernet Adapter";
 
2734
        else
 
2735
                ansi_string.buf = "USB Ethernet Adapter";
 
2736
        ansi_string.buflen = ansi_string.len = strlen(ansi_string.buf);
 
2737
        if (RtlAnsiStringToUnicodeString(name, &ansi_string, 1))
 
2738
                TRACEEXIT2(return NDIS_STATUS_RESOURCES);
 
2739
        else
 
2740
                TRACEEXIT2(return NDIS_STATUS_SUCCESS);
 
2741
}
 
2742
 
 
2743
STDCALL ULONG WRAP_EXPORT(NdisReadPcmciaAttributeMemory)
 
2744
        (struct ndis_handle *handle, ULONG offset, void *buffer, ULONG length)
2429
2745
{
2430
2746
        UNIMPL();
2431
2747
        return 0;
2432
2748
}
2433
2749
 
2434
 
STDCALL static unsigned long WRAP_EXPORT(NdisWritePcmciaAttributeMemory)
 
2750
STDCALL ULONG WRAP_EXPORT(NdisWritePcmciaAttributeMemory)
2435
2751
        (struct ndis_handle *handle, ULONG offset, void *buffer,
2436
2752
         ULONG length)
2437
2753
{
2440
2756
}
2441
2757
 
2442
2758
 /* Unimplemented...*/
2443
 
STDCALL static void WRAP_EXPORT(NdisMSetAttributes)(void){UNIMPL();}
2444
 
STDCALL static void WRAP_EXPORT(EthFilterDprIndicateReceiveComplete)
 
2759
STDCALL void WRAP_EXPORT(NdisMSetAttributes)(void){UNIMPL();}
 
2760
STDCALL void WRAP_EXPORT(EthFilterDprIndicateReceiveComplete)
2445
2761
        (void){UNIMPL();}
2446
 
STDCALL static void WRAP_EXPORT(EthFilterDprIndicateReceive)(void){UNIMPL();}
2447
 
STDCALL static void WRAP_EXPORT(NdisMPciAssignResources)(void){UNIMPL();}
2448
 
STDCALL static void WRAP_EXPORT(NdisMRemoveMiniport)(void) { UNIMPL(); }
2449
 
//STDCALL static void RndisMSendComplete(void) { UNIMPL(); }
2450
 
//STDCALL static void RndisMInitializeWrapper(void) { UNIMPL(); }
2451
 
STDCALL static void WRAP_EXPORT(RndisMIndicateReceive)(void) { UNIMPL(); }
2452
 
 
2453
 
STDCALL static void WRAP_EXPORT(NdisMCoActivateVcComplete)(void){UNIMPL();}
2454
 
STDCALL static void WRAP_EXPORT(NdisMRegisterUnloadHandler)
2455
 
        (struct ndis_handle *handle, void *unload)
2456
 
{
2457
 
        UNIMPL();
2458
 
        return;
2459
 
}
2460
 
 
2461
 
STDCALL static void WRAP_EXPORT(NdisMCoDeactivateVcComplete)(void)
 
2762
STDCALL void WRAP_EXPORT(EthFilterDprIndicateReceive)(void){UNIMPL();}
 
2763
STDCALL void WRAP_EXPORT(NdisMRemoveMiniport)(void) { UNIMPL(); }
 
2764
//STDCALL void RndisMSendComplete(void) { UNIMPL(); }
 
2765
//STDCALL void RndisMInitializeWrapper(void) { UNIMPL(); }
 
2766
STDCALL void WRAP_EXPORT(RndisMIndicateReceive)(void) { UNIMPL(); }
 
2767
 
 
2768
STDCALL void WRAP_EXPORT(NdisMCoActivateVcComplete)(void){UNIMPL();}
 
2769
 
 
2770
STDCALL void WRAP_EXPORT(NdisMCoDeactivateVcComplete)(void)
2462
2771
{
2463
2772
        UNIMPL();
2464
2773
        return;