~ubuntu-branches/ubuntu/natty/bcmwl/natty

« back to all changes in this revision

Viewing changes to src/src/shared/linux_osl.c

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Milone
  • Date: 2010-02-14 19:58:58 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100214195858-76xedzc2a1gz1ujz
Tags: upstream-5.60.48.36+bdcom
ImportĀ upstreamĀ versionĀ 5.60.48.36+bdcom

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Linux OS Independent Layer
3
3
 *
4
 
 * Copyright 2008, Broadcom Corporation
 
4
 * Copyright (C) 2010, Broadcom Corporation
5
5
 * All Rights Reserved.
6
6
 * 
7
 
 *      Unless you and Broadcom execute a separate written software license
8
 
 * agreement governing use of this software, this software is licensed to you
9
 
 * under the terms of the GNU General Public License version 2, available at
10
 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL"), with the
11
 
 * following added to such license:
12
 
 *      As a special exception, the copyright holders of this software give you
13
 
 * permission to link this software with independent modules, regardless of the
14
 
 * license terms of these independent modules, and to copy and distribute the
15
 
 * resulting executable under terms of your choice, provided that you also meet,
16
 
 * for each linked independent module, the terms and conditions of the license
17
 
 * of that module. An independent module is a module which is not derived from
18
 
 * this software.
19
 
 *
20
7
 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
21
8
 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
22
9
 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
23
10
 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
24
11
 *
25
 
 * $Id: linux_osl.c,v 1.127.2.18 2009/02/26 17:07:07 Exp $
 
12
 * $Id: linux_osl.c,v 1.152.18.5.4.1 2009/11/13 00:32:19 Exp $
26
13
 */
27
14
 
28
15
#define LINUX_PORT
36
23
#include <linux/delay.h>
37
24
#include <pcicfg.h>
38
25
 
 
26
#include <linux/fs.h>
 
27
 
39
28
#define PCI_CFG_RETRY           10
40
29
 
41
30
#define OS_HANDLE_MAGIC         0x1234abcd      
49
38
        char    file[BCM_MEM_FILENAME_LEN];
50
39
} bcm_mem_link_t;
51
40
 
 
41
#if defined(DSLCPE_DELAY_NOT_YET)
 
42
struct shared_osl {
 
43
        int long_delay;
 
44
        spinlock_t *lock;
 
45
        void *wl;
 
46
        unsigned long MIPS;
 
47
};
 
48
#endif
 
49
 
52
50
struct osl_info {
53
51
        osl_pubinfo_t pub;
54
52
        uint magic;
59
57
        bcm_mem_link_t *dbgmem_list;
60
58
};
61
59
 
62
 
bool g_assert_bypass = FALSE;
 
60
uint32 g_assert_type = 0;
63
61
 
64
 
static int16 linuxbcmerrormap[] =  \
 
62
static int16 linuxbcmerrormap[] =
65
63
{       0,                      
66
64
        -EINVAL,                
67
65
        -EINVAL,                
102
100
        -EINVAL,                
103
101
        -EIO,                   
104
102
        -EIO,                   
105
 
        -EINVAL                 
 
103
        -EINVAL,                
106
104
 
107
105
#if BCME_LAST != -40
108
106
#error "You need to add a OS error translation in the linuxbcmerrormap \
109
 
        for new error code defined in bcmuitls.h"
 
107
        for new error code defined in bcmutils.h"
110
108
#endif 
111
109
};
112
110
 
207
205
                nskb = skb->next;
208
206
                skb->next = NULL;
209
207
 
210
 
                if (skb->destructor) {
211
 
 
212
 
                        dev_kfree_skb_any(skb);
213
 
                } else {
214
 
 
215
 
                        dev_kfree_skb(skb);
 
208
                {
 
209
                        if (skb->destructor)
 
210
 
 
211
                                dev_kfree_skb_any(skb);
 
212
                        else
 
213
 
 
214
                                dev_kfree_skb(skb);
216
215
                }
217
216
 
218
217
                osh->pub.pktalloced--;
353
352
}
354
353
 
355
354
void*
356
 
osl_dma_alloc_consistent(osl_t *osh, uint size, ulong *pap)
 
355
osl_dma_alloc_consistent(osl_t *osh, uint size, uint16 align_bits, uint *alloced, ulong *pap)
357
356
{
 
357
        uint16 align = (1 << align_bits);
358
358
        ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
359
359
 
 
360
        if (!ISALIGNED(DMA_CONSISTENT_ALIGN, align))
 
361
                size += align;
 
362
        *alloced = size;
 
363
 
360
364
        return (pci_alloc_consistent(osh->pdev, size, (dma_addr_t*)pap));
361
365
}
362
366
 
371
375
uint BCMFASTPATH
372
376
osl_dma_map(osl_t *osh, void *va, uint size, int direction)
373
377
{
 
378
        int dir;
 
379
 
374
380
        ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
375
 
 
376
 
        if (direction == DMA_TX)
377
 
                return (pci_map_single(osh->pdev, va, size, PCI_DMA_TODEVICE));
378
 
        else {
379
 
                return (pci_map_single(osh->pdev, va, size, PCI_DMA_FROMDEVICE));
380
 
        }
 
381
        dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
 
382
        return (pci_map_single(osh->pdev, va, size, dir));
381
383
}
382
384
 
383
385
void BCMFASTPATH
395
397
osl_assert(char *exp, char *file, int line)
396
398
{
397
399
        char tempbuf[256];
 
400
        char *basename;
 
401
 
 
402
        basename = strrchr(file, '/');
 
403
 
 
404
        if (basename)
 
405
                basename++;
 
406
 
 
407
        if (!basename)
 
408
                basename = file;
 
409
 
398
410
#ifdef BCMDBG_ASSERT
399
 
        snprintf(tempbuf, 256, "assertion \"%s\" failed: file \"%s\", line %d\n", exp, file, line);
 
411
        snprintf(tempbuf, 256, "assertion \"%s\" failed: file \"%s\", line %d\n",
 
412
                exp, basename, line);
400
413
 
401
414
        if (!in_interrupt()) {
402
415
                const int delay = 3;
405
418
                set_current_state(TASK_INTERRUPTIBLE);
406
419
                schedule_timeout(delay * HZ);
407
420
        }
408
 
        if (!g_assert_bypass)
 
421
        if (g_assert_type == 0)
409
422
                panic("%s", tempbuf);
410
423
#endif
411
424
 
439
452
        return (p);
440
453
}
441
454
 
 
455
uint32
 
456
osl_sysuptime(void)
 
457
{
 
458
        return ((uint32)jiffies * (1000 / HZ));
 
459
}
 
460
 
442
461
uint
443
462
osl_pktalloced(osl_t *osh)
444
463
{
449
468
osl_printf(const char *format, ...)
450
469
{
451
470
        va_list args;
452
 
        char buf[1024];
 
471
        static char buf[1024];
453
472
        int len;
454
473
 
455
474
        va_start(args, format);
608
627
        return ((void*)va);
609
628
}
610
629
 
 
630
void *
 
631
osl_cached(void *va)
 
632
{
 
633
        return ((void*)va);
 
634
}
 
635
 
611
636
uint
612
637
osl_getcycles(void)
613
638
{
757
782
        }
758
783
        return (void *)pkt;
759
784
}
 
785
 
 
786
void *
 
787
osl_os_open_image(char *filename)
 
788
{
 
789
        struct file *fp;
 
790
 
 
791
        fp = filp_open(filename, O_RDONLY, 0);
 
792
 
 
793
         if (IS_ERR(fp))
 
794
                 fp = NULL;
 
795
 
 
796
         return fp;
 
797
}
 
798
 
 
799
int
 
800
osl_os_get_image_block(char *buf, int len, void *image)
 
801
{
 
802
        struct file *fp = (struct file *)image;
 
803
        int rdlen;
 
804
 
 
805
        if (!image)
 
806
                return 0;
 
807
 
 
808
        rdlen = kernel_read(fp, fp->f_pos, buf, len);
 
809
        if (rdlen > 0)
 
810
                fp->f_pos += rdlen;
 
811
 
 
812
        return rdlen;
 
813
}
 
814
 
 
815
void
 
816
osl_os_close_image(void *image)
 
817
{
 
818
        if (image)
 
819
                filp_close((struct file *)image, NULL);
 
820
}