1 /**************************************************************************
3 * Copyright (c)2000-2002 Alacritech, Inc. All rights reserved.
5 * $Id: slic_os.h,v 1.2 2006/03/27 15:10:15 mook Exp $
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALACRITECH, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * The views and conclusions contained in the software and documentation
32 * are those of the authors and should not be interpreted as representing
33 * official policies, either expressed or implied, of Alacritech, Inc.
35 **************************************************************************/
40 * These are the Linux-specific definitions required for the SLICOSS
41 * driver, which should allow for greater portability to other OSes.
43 #ifndef _SLIC_OS_SPECIFIC_H_
44 #define _SLIC_OS_SPECIFIC_H_
46 typedef unsigned char uchar;
49 typedef unsigned char *puchar;
52 typedef u32 *pulong32;
54 typedef unsigned int *puint;
56 typedef unsigned long *pulong;
57 typedef unsigned int boolean;
58 typedef unsigned int wchar;
59 typedef unsigned int *pwchar;
60 typedef unsigned char UCHAR;
66 #define SLIC_INIT_SPINLOCK(x) \
68 spin_lock_init(&((x).lock)); \
70 #define SLIC_ACQUIRE_SPINLOCK(x) \
72 spin_lock(&((x).lock)); \
75 #define SLIC_RELEASE_SPINLOCK(x) \
77 spin_unlock(&((x).lock)); \
80 #define SLIC_ACQUIRE_IRQ_SPINLOCK(x) \
82 spin_lock_irqsave(&((x).lock), (x).flags); \
85 #define SLIC_RELEASE_IRQ_SPINLOCK(x) \
87 spin_unlock_irqrestore(&((x).lock), (x).flags); \
93 #define SLIC_TIMESTAMP(value) { \
94 struct timeval timev; \
95 do_gettimeofday(&timev); \
96 value = timev.tv_sec*1000000 + timev.tv_usec; \
99 #define SLIC_TIMESTAMP(value)
102 #define SLIC_ALLOCATE_MEM(len, flag) kmalloc(len, flag)
103 #define SLIC_DEALLOCATE_MEM(mem) kfree(mem)
104 #define SLIC_DEALLOCATE_IRQ_MEM(mem) free(mem)
105 #define SLIC_ALLOCATE_PAGE(x) (pulong32)get_free_page(GFP_KERNEL)
106 #define SLIC_DEALLOCATE_PAGE(addr) free_page((ulong32)addr)
107 #define SLIC_ALLOCATE_PCIMEM(a, sz, physp) \
108 pci_alloc_consistent((a)->pcidev, (sz), &(physp))
109 #define SLIC_DEALLOCATE_PCIMEM(a, sz, vp, pp) \
110 pci_free_consistent((a)->pcidev, (sz), (vp), (pp))
111 #define SLIC_GET_PHYSICAL_ADDRESS(addr) virt_to_bus((addr))
112 #define SLIC_GET_PHYSICAL_ADDRESS_HIGH(addr) 0
114 #define SLIC_GET_DMA_ADDRESS_WRITE(a, ptr, sz) \
115 pci_map_single((a)->pcidev, (ptr), (sz), PCI_DMA_TODEVICE)
116 #define SLIC_GET_DMA_ADDRESS_READ(a, ptr, sz) \
117 pci_map_single((a)->pcidev, (ptr), (sz), PCI_DMA_FROMDEVICE)
118 #define SLIC_UNGET_DMA_ADDRESS_WRITE(a, pa, sz) \
119 pci_unmap_single((a)->pcidev, (pa), (sz), PCI_DMA_TODEVICE)
120 #define SLIC_UNGET_DMA_ADDRESS_READ(a, pa, sz) \
121 pci_unmap_single((a)->pcidev, (pa), (sz), PCI_DMA_FROMDEVICE)
123 #define SLIC_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
124 #define SLIC_EQUAL_MEMORY(src1, src2, len) (!memcmp(src1, src2, len))
125 #define SLIC_MOVE_MEMORY(dst, src, len) memcpy((dst), (src), (len))
127 #define SLIC_SECS_TO_JIFFS(x) ((x) * HZ)
128 #define SLIC_MS_TO_JIFFIES(x) (SLIC_SECS_TO_JIFFS((x)) / 1000)
130 #ifdef DEBUG_REGISTER_TRACE
131 #define WRITE_REG(reg, value, flush) \
133 adapter->card->reg_type[adapter->card->debug_ix] = 0; \
134 adapter->card->reg_offset[adapter->card->debug_ix] = \
135 ((puchar)(®)) - ((puchar)adapter->slic_regs); \
136 adapter->card->reg_value[adapter->card->debug_ix++] = value; \
137 if (adapter->card->debug_ix == 32) \
138 adapter->card->debug_ix = 0; \
139 slic_reg32_write((®), (value), (flush)); \
141 #define WRITE_REG64(a, reg, value, regh, valh, flush) \
143 adapter->card->reg_type[adapter->card->debug_ix] = 1; \
144 adapter->card->reg_offset[adapter->card->debug_ix] = \
145 ((puchar)(®)) - ((puchar)adapter->slic_regs); \
146 adapter->card->reg_value[adapter->card->debug_ix] = value; \
147 adapter->card->reg_valueh[adapter->card->debug_ix++] = valh; \
148 if (adapter->card->debug_ix == 32) \
149 adapter->card->debug_ix = 0; \
150 slic_reg64_write((a), (®), (value), (®h), (valh), \
154 #define WRITE_REG(reg, value, flush) \
155 slic_reg32_write((®), (value), (flush))
156 #define WRITE_REG64(a, reg, value, regh, valh, flush) \
157 slic_reg64_write((a), (®), (value), (®h), (valh), (flush))
159 #define READ_REG(reg, flush) slic_reg32_read((®), (flush))
160 #define READ_REGP16(reg, flush) slic_reg16_read((®), (flush))
162 #endif /* _SLIC_OS_SPECIFIC_H_ */