aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/slicoss/slic_os.h
blob: 2064673f9149042a4c4e99bd3d6aada278f40638 (plain)
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
/**************************************************************************
 *
 * Copyright (c)2000-2002 Alacritech, Inc.  All rights reserved.
 *
 * $Id: slic_os.h,v 1.2 2006/03/27 15:10:15 mook Exp $
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above
 *    copyright notice, this list of conditions and the following
 *    disclaimer in the documentation and/or other materials provided
 *    with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ALACRITECH, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation
 * are those of the authors and should not be interpreted as representing
 * official policies, either expressed or implied, of Alacritech, Inc.
 *
 **************************************************************************/

/*
 * FILENAME: slic_os.h
 *
 * These are the Linux-specific definitions required for the SLICOSS
 * driver, which should allow for greater portability to other OSes.
 */
#ifndef _SLIC_OS_SPECIFIC_H_
#define _SLIC_OS_SPECIFIC_H_

typedef unsigned char       uchar;
typedef u64               ulong64;
typedef char              *pchar;
typedef unsigned char     *puchar;
typedef u16             *pushort;
typedef u32               ulong32;
typedef u32             *pulong32;
typedef int               *plong32;
typedef unsigned int      *puint;
typedef void                *pvoid;
typedef unsigned long      *pulong;
typedef unsigned int        boolean;
typedef unsigned int        wchar;
typedef unsigned int       *pwchar;
typedef unsigned char       UCHAR;
typedef u32               ULONG;
typedef s32               LONG;
#define FALSE               (0)
#define TRUE                (1)

#define SLIC_INIT_SPINLOCK(x)                                                 \
      {                                                                       \
	spin_lock_init(&((x).lock));                                         \
      }
#define SLIC_ACQUIRE_SPINLOCK(x)                                              \
      {                                                                       \
	spin_lock(&((x).lock));                                              \
      }

#define SLIC_RELEASE_SPINLOCK(x)                                              \
      {                                                                       \
	spin_unlock(&((x).lock));                                            \
      }

#define SLIC_ACQUIRE_IRQ_SPINLOCK(x)                                          \
      {                                                                       \
	spin_lock_irqsave(&((x).lock), (x).flags);                           \
      }

#define SLIC_RELEASE_IRQ_SPINLOCK(x)                                          \
      {                                                                       \
	spin_unlock_irqrestore(&((x).lock), (x).flags);                      \
      }

#define ATK_DEBUG  1

#if ATK_DEBUG
#define SLIC_TIMESTAMP(value) {                                             \
	struct timeval  timev;                                              \
	do_gettimeofday(&timev);                                            \
	value = timev.tv_sec*1000000 + timev.tv_usec;                       \
}
#else
#define SLIC_TIMESTAMP(value)
#endif

#define SLIC_ALLOCATE_MEM(len, flag)         kmalloc(len, flag)
#define SLIC_DEALLOCATE_MEM(mem)             kfree(mem)
#define SLIC_DEALLOCATE_IRQ_MEM(mem)         free(mem)
#define SLIC_ALLOCATE_PAGE(x)                (pulong32)get_free_page(GFP_KERNEL)
#define SLIC_DEALLOCATE_PAGE(addr)           free_page((ulong32)addr)
#define SLIC_ALLOCATE_PCIMEM(a, sz, physp)    \
		pci_alloc_consistent((a)->pcidev, (sz), &(physp))
#define SLIC_DEALLOCATE_PCIMEM(a, sz, vp, pp) \
		pci_free_consistent((a)->pcidev, (sz), (vp), (pp))
#define SLIC_GET_PHYSICAL_ADDRESS(addr)       virt_to_bus((addr))
#define SLIC_GET_PHYSICAL_ADDRESS_HIGH(addr)  0

#define SLIC_GET_DMA_ADDRESS_WRITE(a, ptr, sz)  \
		pci_map_single((a)->pcidev, (ptr), (sz), PCI_DMA_TODEVICE)
#define SLIC_GET_DMA_ADDRESS_READ(a, ptr, sz)   \
		pci_map_single((a)->pcidev, (ptr), (sz), PCI_DMA_FROMDEVICE)
#define SLIC_UNGET_DMA_ADDRESS_WRITE(a, pa, sz) \
		pci_unmap_single((a)->pcidev, (pa), (sz), PCI_DMA_TODEVICE)
#define SLIC_UNGET_DMA_ADDRESS_READ(a, pa, sz)  \
		pci_unmap_single((a)->pcidev, (pa), (sz), PCI_DMA_FROMDEVICE)

#define SLIC_ZERO_MEMORY(p, sz)            memset((p), 0, (sz))
#define SLIC_EQUAL_MEMORY(src1, src2, len) (!memcmp(src1, src2, len))
#define SLIC_MOVE_MEMORY(dst, src, len)    memcpy((dst), (src), (len))

#define SLIC_SECS_TO_JIFFS(x)  ((x) * HZ)
#define SLIC_MS_TO_JIFFIES(x)  (SLIC_SECS_TO_JIFFS((x)) / 1000)

#ifdef DEBUG_REGISTER_TRACE
#define WRITE_REG(reg, value, flush)                                      \
	{                                                           \
		adapter->card->reg_type[adapter->card->debug_ix] = 0;   \
		adapter->card->reg_offset[adapter->card->debug_ix] = \
			((puchar)(&reg)) - ((puchar)adapter->slic_regs); \
		adapter->card->reg_value[adapter->card->debug_ix++] = value;  \
		if (adapter->card->debug_ix == 32) \
			adapter->card->debug_ix = 0;                      \
		slic_reg32_write((&reg), (value), (flush));            \
	}
#define WRITE_REG64(a, reg, value, regh, valh, flush)                        \
	{                                                           \
		adapter->card->reg_type[adapter->card->debug_ix] = 1;        \
		adapter->card->reg_offset[adapter->card->debug_ix] = \
			((puchar)(&reg)) - ((puchar)adapter->slic_regs); \
		adapter->card->reg_value[adapter->card->debug_ix] = value;   \
		adapter->card->reg_valueh[adapter->card->debug_ix++] = valh;  \
		if (adapter->card->debug_ix == 32) \
			adapter->card->debug_ix = 0;                      \
		slic_reg64_write((a), (&reg), (value), (&regh), (valh), \
				(flush));\
	}
#else
#define WRITE_REG(reg, value, flush) \
	slic_reg32_write((&reg), (value), (flush))
#define WRITE_REG64(a, reg, value, regh, valh, flush) \
	slic_reg64_write((a), (&reg), (value), (&regh), (valh), (flush))
#endif
#define READ_REG(reg, flush)                    slic_reg32_read((&reg), (flush))
#define READ_REGP16(reg, flush)                 slic_reg16_read((&reg), (flush))

#endif  /* _SLIC_OS_SPECIFIC_H_  */