-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmerge.c
3602 lines (2970 loc) · 93.3 KB
/
merge.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2012
* The ACX100 Open Source Project <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined CONFIG_ACX_MAC80211_PCI || defined CONFIG_ACX_MAC80211_MEM
#define pr_fmt(fmt) "acx.%s: " fmt, __func__
#include "acx_debug.h"
#include <linux/version.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/wireless.h>
#include <linux/netdevice.h>
#include <linux/ioport.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/vmalloc.h>
#include <linux/workqueue.h>
#include <linux/nl80211.h>
#include <linux/dma-mapping.h>
#include <net/iw_handler.h>
#include <net/mac80211.h>
#include <asm/io.h>
#define pr_acx pr_info
#include "acx.h"
#include "merge.h"
/* merge adaptation help */
#include "pci.h"
#include "mem.h"
#include "io-acx.h"
#include "inlines.h"
#include "cmd.h"
#include "ie.h"
#include "utils.h"
#include "cardsetting.h"
#include "rx.h"
#include "tx.h"
#include "main.h"
#include "boot.h"
#include "interrupt-masks.h"
#define RX_BUFFER_SIZE (sizeof(rxbuffer_t) + 32)
/* from mem.c:98 */
#define FW_NO_AUTO_INCREMENT 1
/* identical from pci.c, mem.c */
irqreturn_t acx_interrupt(int irq, void *dev_id)
{
acx_device_t *adev = dev_id;
unsigned long flags;
u16 irqreason;
u16 irqmasked;
if (!adev)
return IRQ_NONE;
/* On a shared irq line, irqs should only be for us, when enabled them */
if (!adev->irqs_active)
return IRQ_NONE;
spin_lock_irqsave(&adev->spinlock, flags);
/* We only get an irq-signal for IO_ACX_IRQ_MASK unmasked irq
* reasons. However masked irq reasons we still read with
* IO_ACX_IRQ_REASON or IO_ACX_IRQ_STATUS_NON_DES
*/
irqreason = read_reg16(adev, IO_ACX_IRQ_STATUS_NON_DES);
irqmasked = irqreason & ~adev->irq_mask;
log(L_IRQ, "irqstatus=%04X, irqmasked=%04X,\n", irqreason, irqmasked);
if (unlikely(irqreason == 0xffff)) {
/* 0xffff value hints at missing hardware, so don't do
* anything. Not very clean, but other drivers do the
* same... */
log(L_IRQ, "irqstatus=FFFF: Device removed?: IRQ_NONE\n");
goto none;
}
/* Our irq-signals are the ones, that were triggered by the
* IO_ACX_IRQ_MASK unmasked irqs.
*/
if (!irqmasked) {
/* We are on a shared IRQ line and it wasn't our IRQ */
log(L_IRQ, "irqmasked zero: IRQ_NONE\n");
goto none;
}
/* Mask all irqs, until we handle them. We will unmask them
* later in the tasklet. */
write_reg16(adev, IO_ACX_IRQ_MASK, HOST_INT_MASK_ALL);
write_flush(adev);
acx_schedule_task(adev, 0);
spin_unlock_irqrestore(&adev->spinlock, flags);
return IRQ_HANDLED;
none:
spin_unlock_irqrestore(&adev->spinlock, flags);
return IRQ_NONE;
}
int acx_upload_radio(acx_device_t *adev)
{
acx_ie_memmap_t mm;
acx_cmd_radioinit_t radioinit;
int res = NOT_OK;
int try;
u32 offset;
acxmem_lock_flags;
firmware_image_t *radio_image=adev->radio_image;
if (!radio_image)
return OK;
acx_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
offset = le32_to_cpu(mm.CodeEnd);
acx_issue_cmd(adev, ACX1xx_CMD_SLEEP, NULL, 0);
for (try = 1; try <= 5; try++) {
acxmem_lock();
res = acx_write_fw(adev, radio_image, offset);
log(L_DEBUG|L_INIT, "acx_write_fw (radio): %d\n", res);
if (OK == res) {
res = acx_validate_fw(adev, radio_image, offset);
log(L_DEBUG|L_INIT, "acx_validate_fw (radio): %d\n", res);
}
acxmem_unlock();
if (OK == res)
break;
pr_acx("radio firmware upload attempt #%d FAILED, "
"retrying...\n", try);
acx_mwait(1000); /* better wait for a while... */
}
acx_issue_cmd(adev, ACX1xx_CMD_WAKE, NULL, 0);
radioinit.offset = cpu_to_le32(offset);
/* no endian conversion needed, remains in card CPU area: */
radioinit.len = radio_image->size;
if (OK != res)
goto fail;
/* will take a moment so let's have a big timeout */
acx_issue_cmd_timeout(adev, ACX1xx_CMD_RADIOINIT, &radioinit,
sizeof(radioinit), CMD_TIMEOUT_MS(1000));
res = acx_interrogate(adev, &mm, ACX1xx_IE_MEMORY_MAP);
fail:
return res;
}
static int acx_allocate(acx_device_t *adev, unsigned int size, dma_addr_t *phy,
void **start, const char *msg)
{
void *ptr;
if (IS_PCI(adev)) {
ptr = dma_alloc_coherent(adev->bus_dev, size, phy, GFP_KERNEL);
log(L_INIT, "bdev:%p size:%d phy:%p ptr:%p\n", adev->bus_dev, size,
(void*) *phy, ptr);
} else {
ptr = vmalloc(size);
*phy = (dma_addr_t) NULL;
}
if (!ptr) {
pr_err("%s: allocation FAILED (%u bytes)\n", msg, size);
return -ENOMEM;
}
log(L_DEBUG, "%s: size=%u ptr=0x%p phy=0x%08llx\n", msg, size, ptr, (unsigned long long) *phy);
memset(ptr, 0, size);
*start = ptr;
return 0;
}
static inline void acx_free(acx_device_t *adev, size_t *size,
void **start, dma_addr_t phy)
{
pr_info("size:%zu, vaddr:%p, dma_handle:%p\n", *size, *start, (void*) phy);
if (IS_PCI(adev))
dma_free_coherent(NULL, *size, *start, phy);
else
vfree(*start);
*size=0;
*start=NULL;
}
/*
* acx_create_rx_host_desc_queue()
*
* the whole size of a data buffer (header plus data body) plus 32
* bytes safety offset at the end
*/
static int acx_create_rx_host_desc_queue(acx_device_t *adev)
{
rxhostdesc_t *hostdesc;
rxbuffer_t *rxbuf;
dma_addr_t hostdesc_phy;
dma_addr_t rxbuf_phy;
int i, rc;
/* allocate the RX host descriptor queue pool, if not already done */
if (!adev->hw_rx_queue.hostdescinfo.start) {
adev->hw_rx_queue.hostdescinfo.size = RX_CNT * sizeof(*hostdesc);
rc = acx_allocate(adev, adev->hw_rx_queue.hostdescinfo.size,
&adev->hw_rx_queue.hostdescinfo.phy,
(void**) &adev->hw_rx_queue.hostdescinfo.start, "rxhostdesc_start");
if (rc)
goto fail;
}
/* check for proper alignment of RX host descriptor pool */
if ((long)adev->hw_rx_queue.hostdescinfo.start & 3) {
pr_acx("driver bug: dma alloc returns unaligned address\n");
goto fail;
}
/* allocate Rx buffer pool which will be used by the acx
* to store the whole content of the received frames in it */
if (!adev->hw_rx_queue.bufinfo.start) {
adev->hw_rx_queue.bufinfo.size = RX_CNT * RX_BUFFER_SIZE;
rc = acx_allocate(adev, adev->hw_rx_queue.bufinfo.size,
&adev->hw_rx_queue.bufinfo.phy,
&adev->hw_rx_queue.bufinfo.start, "rxbuf_start");
if (rc)
goto fail;
}
rxbuf = (rxbuffer_t*) adev->hw_rx_queue.bufinfo.start;
rxbuf_phy = adev->hw_rx_queue.bufinfo.phy;
hostdesc = adev->hw_rx_queue.hostdescinfo.start;
hostdesc_phy = adev->hw_rx_queue.hostdescinfo.phy;
/* don't make any popular C programming pointer arithmetic
* mistakes here, otherwise I'll kill you... (and don't dare
* asking me why I'm warning you about that...) */
for (i = 0; i < RX_CNT; i++) {
hostdesc->data = rxbuf;
hostdesc->hd.data_phy = cpu2acx(rxbuf_phy);
hostdesc->hd.length = cpu_to_le16(RX_BUFFER_SIZE);
CLEAR_BIT(hostdesc->hd.Ctl_16, cpu_to_le16(DESC_CTL_HOSTOWN));
rxbuf++;
rxbuf_phy += sizeof(*rxbuf);
hostdesc_phy += sizeof(*hostdesc);
hostdesc->hd.desc_phy_next = cpu2acx(hostdesc_phy);
hostdesc++;
}
hostdesc--;
hostdesc->hd.desc_phy_next = cpu2acx(adev->hw_rx_queue.hostdescinfo.phy);
return OK;
fail:
pr_acx("FAILED: %d\n", rc);
/* dealloc will be done by free function on error case */
return NOT_OK;
}
// TODO rename into acx_create_tx_hostdesc_queue
static int acx_create_tx_host_desc_queue(acx_device_t *adev, struct hw_tx_queue *tx)
{
txhostdesc_t *hostdesc;
u8 *txbuf;
dma_addr_t hostdesc_phy;
dma_addr_t txbuf_phy;
int i, rc;
/* allocate TX buffer, if not already done */
if (!tx->bufinfo.start) {
tx->bufinfo.size = TX_CNT * WLAN_A4FR_MAXLEN_WEP_FCS;
rc = acx_allocate(adev, tx->bufinfo.size, &tx->bufinfo.phy,
&tx->bufinfo.start, "txbuf_start");
if (rc)
goto fail;
}
/* allocate the TX host descriptor queue pool */
if (!tx->hostdescinfo.start) {
tx->hostdescinfo.size = TX_CNT * 2 * sizeof(*hostdesc);
rc = acx_allocate(adev, tx->hostdescinfo.size, &tx->hostdescinfo.phy,
(void**) &tx->hostdescinfo.start, "txhostdesc_start");
if (rc)
goto fail;
}
/* check for proper alignment of TX host descriptor pool */
if ((long)tx->hostdescinfo.start & 3) {
pr_acx("driver bug: dma alloc returns unaligned address\n");
goto fail;
}
hostdesc = tx->hostdescinfo.start;
hostdesc_phy = tx->hostdescinfo.phy;
txbuf = (u8*) tx->bufinfo.start;
txbuf_phy = tx->bufinfo.phy;
#if 0 /* tx-buffer */
/* Each tx buffer is accessed by hardware via txdesc -> txhostdesc(s)
* -> txbuffer(s). We use only one txhostdesc per txdesc, but it
* looks like acx111 is buggy: it accesses second txhostdesc (via
* hostdesc.desc_phy_next field) even if txdesc->hd.length ==
* hostdesc->hd.length and thus entire packet was placed into first
* txhostdesc. Due to this bug acx111 hangs unless second txhostdesc
* has le16_to_cpu(hostdesc.length) = 3 (or larger) Storing NULL into
* hostdesc.desc_phy_next doesn't seem to help.
*
* Update: although it worked on Xterasys XN-2522g with len=3 trick,
* WG311v2 is even more bogus, doesn't work. Keeping this code
* (#ifdef'ed out) for documentational purposes.
*/
for (i = 0; i < TX_CNT * 2; i++) {
hostdesc_phy += sizeof(*hostdesc);
if (!(i & 1)) {
hostdesc->hd.data_phy = cpu2acx(txbuf_phy);
/* hostdesc->data_offset = ... */
/* hostdesc->reserved = ... */
hostdesc->hd.Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
/* hostdesc->hd.length = ... */
hostdesc->hd.desc_phy_next = cpu2acx(hostdesc_phy);
hostdesc->hd.pNext = ptr2acx(NULL);
/* hostdesc->Status = ... */
/* below: non-hardware fields */
hostdesc->data = txbuf;
txbuf += WLAN_A4FR_MAXLEN_WEP_FCS;
txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS;
} else {
/* hostdesc->hd.data_phy = ... */
/* hostdesc->data_offset = ... */
/* hostdesc->reserved = ... */
/* hostdesc->hd.Ctl_16 = ... */
hostdesc->hd.length = cpu_to_le16(3); /* bug workaround */
/* hostdesc->hd.desc_phy_next = ... */
/* hostdesc->pNext = ... */
/* hostdesc->Status = ... */
/* below: non-hardware fields */
/* hostdesc->data = ... */
}
hostdesc++;
}
#endif /* tx-buffer */
/* We initialize two hostdescs so that they point to adjacent
* memory areas. Thus txbuf is really just a contiguous memory
* area */
for (i = 0; i < TX_CNT * 2; i++) {
hostdesc_phy += sizeof(*hostdesc);
hostdesc->hd.data_phy = cpu2acx(txbuf_phy);
/* done by memset(0): hostdesc->data_offset = 0; */
/* hostdesc->reserved = ... */
hostdesc->hd.Ctl_16 = cpu_to_le16(DESC_CTL_HOSTOWN);
/* hostdesc->hd.length = ... */
hostdesc->hd.desc_phy_next = cpu2acx(hostdesc_phy);
/* done by memset(0): hostdesc->pNext = ptr2acx(NULL); */
/* hostdesc->Status = ... */
/* ->data is a non-hardware field: */
hostdesc->data = txbuf;
if (!(i & 1)) {
txbuf += BUF_LEN_HOSTDESC1;
txbuf_phy += BUF_LEN_HOSTDESC1;
} else {
txbuf += WLAN_A4FR_MAXLEN_WEP_FCS - BUF_LEN_HOSTDESC1;
txbuf_phy += WLAN_A4FR_MAXLEN_WEP_FCS
- BUF_LEN_HOSTDESC1;
}
hostdesc++;
}
hostdesc--;
hostdesc->hd.desc_phy_next = cpu2acx(tx->hostdescinfo.phy);
return OK;
fail:
pr_err("FAILED\n");
/* dealloc will be done by free function on error case */
return NOT_OK;
}
int acx_create_hostdesc_queues(acx_device_t *adev, int num_tx)
{
int res;
int i;
for(i=0; i<num_tx; i++)
{
res = acx_create_tx_host_desc_queue(adev, &adev->hw_tx_queue[i]);
if (OK != res)
return res;
}
res = acx_create_rx_host_desc_queue(adev);
return res;
}
// TODO rename into acx_create_rx_acxdesc_queue
static void acx_create_rx_desc_queue(acx_device_t *adev, u32 rx_queue_start)
{
rxacxdesc_t *rxdesc;
u32 mem_offs;
int i;
adev->hw_rx_queue.tail=0;
/* ACX111 doesn't need any further config: preconfigures itself.
* Simply print ring buffer for debugging */
if (IS_ACX111(adev)) {
/* rxdesc_start already set here */
if (IS_PCI(adev))
adev->hw_rx_queue.acxdescinfo.start = (rxacxdesc_t *)
(adev->iobase2 + rx_queue_start);
else
adev->hw_rx_queue.acxdescinfo.start = (rxacxdesc_t *)
((u8 *) (uintptr_t)rx_queue_start);
rxdesc = adev->hw_rx_queue.acxdescinfo.start;
for (i = 0; i < RX_CNT; i++) {
log(L_DEBUG, "rx descriptor %d @ 0x%p\n", i, rxdesc);
if (IS_PCI(adev))
adev->hw_rx_queue.acxdescinfo.start = (rxacxdesc_t *)
((u8 *)(uintptr_t)adev->iobase2
+ acx2cpu(rxdesc->pNextDesc));
else
adev->hw_rx_queue.acxdescinfo.start = (rxacxdesc_t *)
((u8 *)(ulong)acx2cpu(rxdesc->pNextDesc));
rxdesc = adev->hw_rx_queue.acxdescinfo.start;
}
} else {
/* we didn't pre-calculate rxdesc_start in case of ACX100 */
/* rxdesc_start should be right AFTER Tx pool */
adev->hw_rx_queue.acxdescinfo.start = (rxacxdesc_t *)
((u8 *) adev->hw_tx_queue[0].acxdescinfo.start
+ (TX_CNT * sizeof(txacxdesc_t)));
/* NB: sizeof(txdesc_t) above is valid because we know
* we are in if (acx100) block. Beware of cut-n-pasting
* elsewhere! acx111's txdesc is larger! */
if (IS_PCI(adev))
memset(adev->hw_rx_queue.acxdescinfo.start, 0,
RX_CNT * sizeof(*rxdesc));
else { // IS_MEM
mem_offs = (uintptr_t) adev->hw_rx_queue.acxdescinfo.start;
while (mem_offs < (uintptr_t) adev->hw_rx_queue.acxdescinfo.start
+ (RX_CNT * sizeof(*rxdesc))) {
write_slavemem32(adev, mem_offs, 0);
mem_offs += 4;
}
}
/* loop over whole receive pool */
rxdesc = adev->hw_rx_queue.acxdescinfo.start;
mem_offs = rx_queue_start;
for (i = 0; i < RX_CNT; i++) {
log(L_DEBUG, "rx descriptor @ 0x%p\n", rxdesc);
/* point to next rxdesc */
if (IS_PCI(adev)){
rxdesc->Ctl_8 = DESC_CTL_RECLAIM | DESC_CTL_AUTODMA;
rxdesc->pNextDesc
= cpu2acx(mem_offs + sizeof(*rxdesc));
}
else // IS_MEM
{
write_slavemem32(adev,
(uintptr_t) &(rxdesc->pNextDesc),
(u32) cpu_to_le32 ((uintptr_t)(u8 *) rxdesc
+ sizeof(*rxdesc)));
}
/* go to the next one */
if (IS_PCI(adev))
mem_offs += sizeof(*rxdesc);
rxdesc++;
}
/* go to the last one */
rxdesc--;
/* and point to the first making it a ring buffer */
if (IS_PCI(adev))
rxdesc->pNextDesc = cpu2acx(rx_queue_start);
else // IS_MEM
write_slavemem32(adev, (uintptr_t) &(rxdesc->pNextDesc),
(uintptr_t) cpu_to_le32 (rx_queue_start));
}
}
static void acx_create_tx_desc_queue(acx_device_t *adev, u32 tx_queue_start, int queue_id)
{
struct hw_tx_queue *tx = &adev->hw_tx_queue[queue_id];
txacxdesc_t *txdesc;
txhostdesc_t *hostdesc;
dma_addr_t hostmemptr = 0; // mem.c - init quiets warning
u32 clr;
u32 mem_offs = 0; // mem.c - init quiets warning
int i;
if (IS_ACX100(adev))
tx->acxdescinfo.size = sizeof(*txdesc);
else
/* the acx111 txdesc is 4 bytes larger */
tx->acxdescinfo.size = sizeof(*txdesc) + 4;
/* This refers to an ACX address, not one of ours */
tx->acxdescinfo.start = (IS_PCI(adev))
? (txacxdesc_t *) (adev->iobase2 + tx_queue_start)
: (txacxdesc_t *) (uintptr_t)tx_queue_start;
log(L_INIT, "adev->iobase2=%p,"
"tx_queue_start=%08X,"
"tx->desc_start=%p",
adev->iobase2, tx_queue_start, tx->acxdescinfo.start);
adev->hw_tx_queue[queue_id].head = 0;
adev->hw_tx_queue[queue_id].tail = 0;
adev->hw_tx_queue[queue_id].free = TX_CNT;
txdesc = tx->acxdescinfo.start;
if (IS_PCI(adev)) {
mem_offs = tx_queue_start;
hostmemptr = tx->hostdescinfo.phy;
hostdesc = tx->hostdescinfo.start;
}
if (IS_ACX111(adev)) {
/* ACX111 has a preinitialized Tx buffer! */
/* loop over whole send pool */
/* FIXME: do we have to do the hostmemptr stuff here?? */
for (i = 0; i < TX_CNT; i++) {
txdesc->Ctl_8 = DESC_CTL_HOSTOWN;
/* reserve two (hdr desc and payload desc) */
if (IS_PCI(adev)) {
txdesc->HostMemPtr = ptr2acx(hostmemptr);
hostdesc += 2;
hostmemptr += 2 * sizeof(*hostdesc);
}
txdesc = acx_advance_txacxdesc(adev, txdesc, 1, queue_id);
}
} else {
/* ACX100 Tx buffer needs to be initialized by us */
/* clear whole send pool. sizeof is safe here (we are
* acx100) */
if (IS_PCI(adev))
memset(tx->acxdescinfo.start, 0,
TX_CNT * sizeof(*txdesc));
else {
/* tx->desc_start refers to device memory,
so we can't write directly to it. */
clr = (uintptr_t) tx->acxdescinfo.start;
while (clr < (uintptr_t) tx->acxdescinfo.start
+ (TX_CNT * sizeof(*txdesc))) {
write_slavemem32(adev, clr, 0);
clr += 4;
}
}
/* loop over whole send pool */
for (i = 0; i < TX_CNT; i++) {
log(L_DEBUG, "configure card tx descriptor: 0x%p, "
"size: %zu\n", txdesc, tx->acxdescinfo.size);
if (IS_PCI(adev)) {
/* pointer to hostdesc memory */
txdesc->HostMemPtr = ptr2acx(hostmemptr);
/* initialise ctl */
txdesc->Ctl_8 = (DESC_CTL_HOSTOWN
| DESC_CTL_RECLAIM
| DESC_CTL_AUTODMA
| DESC_CTL_FIRSTFRAG);
/* done by memset(0): txdesc->Ctl2_8 = 0; */
/* point to next txdesc */
txdesc->pNextDesc =
cpu2acx(mem_offs + tx->acxdescinfo.size);
/* reserve two (hdr desc and payload desc) */
hostdesc += 2;
hostmemptr += 2 * sizeof(*hostdesc);
/* go to the next one */
mem_offs += tx->acxdescinfo.size;
/* ++ is safe here (we are acx100) */
txdesc++;
} else {
/* initialise ctl */
/* No auto DMA here */
write_slavemem8(adev, (uintptr_t) &(txdesc->Ctl_8),
(u8) (DESC_CTL_HOSTOWN |
DESC_CTL_FIRSTFRAG));
/* done by memset(0): txdesc->Ctl2_8 = 0; */
/* point to next txdesc */
write_slavemem32(adev, (uintptr_t) &(txdesc->pNextDesc),
(u32)cpu_to_le32((uintptr_t)(u8 *)txdesc
+ tx->acxdescinfo.size));
/* go to the next one */
/* ++ is safe here (we are acx100) */
txdesc++;
}
}
/* go back to the last one */
txdesc--;
/* and point to the first making it a ring buffer */
if (IS_PCI(adev))
txdesc->pNextDesc = cpu2acx(tx_queue_start);
else
write_slavemem32(adev, (uintptr_t) &(txdesc->pNextDesc),
(u32) cpu_to_le32 (tx_queue_start));
}
}
void acx_create_desc_queues(acx_device_t *adev, u32 rx_queue_start,
u32 *tx_queue_start, int num_tx)
{
u32 *p;
int i;
acxmem_lock_flags;
acxmem_lock();
for(i=0; i<num_tx; i++)
acx_create_tx_desc_queue(adev, tx_queue_start[i], i);
acx_create_rx_desc_queue(adev, rx_queue_start);
if (IS_MEM(adev)){
p = (u32 *) adev->acx_queue_indicator;
for (i = 0; i < 4; i++) {
write_slavemem32(adev, (uintptr_t) p, 0);
p++;
}
}
acxmem_unlock();
}
/*
* acx_free_desc_queues
*
* Releases the queues that have been allocated, the others have been
* initialised to NULL so this function can be used if only part of
* the queues were allocated.
*/
void acx_free_desc_queues(acx_device_t *adev)
{
int i;
for (i = 0; i < adev->num_hw_tx_queues; i++) {
acx_free(adev, &adev->hw_tx_queue[i].hostdescinfo.size,
(void**) &adev->hw_tx_queue[i].hostdescinfo.start,
adev->hw_tx_queue[i].hostdescinfo.phy);
acx_free(adev, &adev->hw_tx_queue[i].bufinfo.size,
&adev->hw_tx_queue[i].bufinfo.start,
adev->hw_tx_queue[i].bufinfo.phy);
adev->hw_tx_queue[i].acxdescinfo.start = NULL;
adev->hw_tx_queue[i].acxdescinfo.size = 0;
}
acx_free(adev, &adev->hw_rx_queue.hostdescinfo.size,
(void**) &adev->hw_rx_queue.hostdescinfo.start,
adev->hw_rx_queue.hostdescinfo.phy);
acx_free(adev, &adev->hw_rx_queue.bufinfo.size,
&adev->hw_rx_queue.bufinfo.start, adev->hw_rx_queue.bufinfo.phy);
adev->hw_rx_queue.acxdescinfo.start = NULL;
adev->hw_rx_queue.acxdescinfo.size = 0;
}
/* ########################################## */
/* irq stuff */
void acx_irq_enable(acx_device_t *adev)
{
write_reg16(adev, IO_ACX_IRQ_MASK, adev->irq_mask);
write_reg16(adev, IO_ACX_FEMR, 0x8000);
if (IS_PCI(adev)) // need if ?
write_flush(adev);
adev->irqs_active = 1;
}
void acx_irq_disable(acx_device_t *adev)
{
write_reg16(adev, IO_ACX_IRQ_MASK, HOST_INT_MASK_ALL);
write_reg16(adev, IO_ACX_FEMR, 0x0);
write_flush(adev);
adev->irqs_active = 0;
}
/* ########################################## */
/* logging stuff */
void acx_log_rxbuffer(const acx_device_t *adev)
{
register const struct rxhostdesc *rxhostdesc;
int i;
/* no FN_ENTER here, we don't want that */
pr_debug("entry\n");
rxhostdesc = adev->hw_rx_queue.hostdescinfo.start;
if (unlikely(!rxhostdesc))
return;
for (i = 0; i < RX_CNT; i++) {
if ((rxhostdesc->hd.Ctl_16 & cpu_to_le16(DESC_CTL_HOSTOWN))
&& (rxhostdesc->hd.Status & cpu_to_le32(DESC_STATUS_FULL)))
pr_acx("rx: buf %d full\n", i);
rxhostdesc++;
}
}
void acx_log_txbuffer(acx_device_t *adev, int queue_id)
{
txacxdesc_t *txdesc;
int i;
u8 Ctl_8;
txdesc = adev->hw_tx_queue[queue_id].acxdescinfo.start;
if (unlikely(!txdesc))
return;
pr_acx("tx[%d]: desc->Ctl8's: ", queue_id);
for (i = 0; i < TX_CNT; i++) {
Ctl_8 = (IS_MEM(adev))
? read_slavemem8(adev, (uintptr_t) &(txdesc->Ctl_8))
: txdesc->Ctl_8;
printk("%02X ", Ctl_8);
txdesc = acx_advance_txacxdesc(adev, txdesc, 1, queue_id);
}
printk("\n");
}
/* ####################################################################
* BOM Firmware, EEPROM, Phy
*/
/*
* acx_read_eeprom_byte
*
* Function called to read an octet in the EEPROM.
*
* This function is used by acxmem_e_probe to check if the
* connected card is a legal one or not.
*
* Arguments:
* adev ptr to acx_device structure
* addr address to read in the EEPROM
* charbuf ptr to a char. This is where the read octet
* will be stored
*/
int acx_read_eeprom_byte(acx_device_t *adev, u32 addr, u8 *charbuf)
{
int result;
int count;
write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
write_reg32(adev, IO_ACX_EEPROM_ADDR, addr);
write_flush(adev);
write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
count = 0xffff;
while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
/* scheduling away instead of CPU burning loop doesn't
* seem to work here at all: awful delay, sometimes
* also failure. Doesn't matter anyway (only small
* delay). */
if (unlikely(!--count)) {
pr_acx("%s: timeout waiting for EEPROM read\n",
wiphy_name(adev->hw->wiphy));
result = NOT_OK;
goto fail;
}
cpu_relax();
}
*charbuf = read_reg8(adev, IO_ACX_EEPROM_DATA);
log(L_DEBUG, "EEPROM at 0x%04X = 0x%02X\n", addr, *charbuf);
result = OK;
fail:
return result;
}
char *acx_proc_eeprom_output(int *length, acx_device_t *adev)
{
char *p, *buf;
int i;
acxmem_lock_flags;
acxmem_lock();
p = buf = kmalloc(0x400, GFP_KERNEL);
for (i = 0; i < 0x400; i++) {
acx_read_eeprom_byte(adev, i, p++);
}
*length = i;
acxmem_unlock();
return buf;
}
/*
* We don't lock hw accesses here since we never r/w eeprom in IRQ
* Note: this function sleeps only because of GFP_KERNEL alloc
*/
#ifdef UNUSED /* acx_write_eeprom() */
int acx_write_eeprom(acx_device_t *adev, u32 addr, u32 len,
const u8 *charbuf)
{
u8 *data_verify = NULL;
/* unsigned long flags; // block warn unused */
int count, i;
int result = NOT_OK;
u16 gpio_orig;
pr_acx("WARNING! I would write to EEPROM now. "
"Since I really DON'T want to unless you know "
"what you're doing (THIS CODE WILL PROBABLY "
"NOT WORK YET!), I will abort that now. And "
"definitely make sure to make a "
"/proc/driver/acx_wlan0_eeprom backup copy first!!! "
"(the EEPROM content includes the PCI config header!! "
"If you kill important stuff, then you WILL "
"get in trouble and people DID get in trouble already)\n");
return OK;
/* first we need to enable the OE (EEPROM Output Enable) GPIO
* line to be able to write to the EEPROM. NOTE: an EEPROM
* writing success has been reported, but you probably have to
* modify GPIO_OUT, too, and you probably need to activate a
* different GPIO line instead! */
gpio_orig = read_reg16(adev, IO_ACX_GPIO_OE);
write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig & ~1);
write_flush(adev);
/* ok, now start writing the data out */
for (i = 0; i < len; i++) {
write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
write_reg32(adev, IO_ACX_EEPROM_DATA, *(charbuf + i));
write_flush(adev);
write_reg32(adev, IO_ACX_EEPROM_CTL, 1);
count = 0xffff;
while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
if (unlikely(!--count)) {
pr_acx("WARNING, DANGER!!! "
"Timeout waiting for EEPROM write\n");
goto end;
}
cpu_relax();
}
}
/* disable EEPROM writing */
write_reg16(adev, IO_ACX_GPIO_OE, gpio_orig);
write_flush(adev);
/* now start a verification run */
data_verify = kmalloc(len, GFP_KERNEL);
if (!data_verify)
goto end;
for (i = 0; i < len; i++) {
write_reg32(adev, IO_ACX_EEPROM_CFG, 0);
write_reg32(adev, IO_ACX_EEPROM_ADDR, addr + i);
write_flush(adev);
write_reg32(adev, IO_ACX_EEPROM_CTL, 2);
count = 0xffff;
while (read_reg16(adev, IO_ACX_EEPROM_CTL)) {
if (unlikely(!--count)) {
pr_acx("timeout waiting for EEPROM read\n");
goto end;
}
cpu_relax();
}
data_verify[i] = read_reg16(adev, IO_ACX_EEPROM_DATA);
}
if (!memcmp(charbuf, data_verify, len))
result = OK; /* read data matches, success */
kfree(data_verify);
end:
return result;
}
#endif /* acx_write_eeprom() */
static inline void acx_read_eeprom_area(acx_device_t *adev)
{
#if ACX_DEBUG > 1 /* in acx_read_eeprom_area() */
int offs;
u8 tmp;
if (IS_MEM(adev) || IS_PCI(adev))
for (offs = 0x8c; offs < 0xb9; offs++)
acx_read_eeprom_byte(adev, offs, &tmp);
else
BUG();
#endif /* ACX_DEBUG > 1 : in acx_read_eeprom_area() */
}
/*
* _acx_read_phy_reg - from mem.c, has locking which looks harmless for pci.c
*
* common.c has acx_read_phy_reg too, called (pci|mem|usb), now
* (usb|x). Messing with rx/tx disabling and enabling here
* (write_reg32(adev, IO_ACX_ENABLE, 0b000000xx)) kills traffic
*/
int _acx_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf)
{
int result = NOT_OK;
int count;
acxmem_lock_flags;