File: macros.h

package info (click to toggle)
eagle-usb 2.1.1-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,108 kB
  • ctags: 2,612
  • sloc: ansic: 27,560; sh: 5,440; perl: 3,269; xml: 1,079; tcl: 915; makefile: 878
file content (197 lines) | stat: -rw-r--r-- 5,655 bytes parent folder | download
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
/*
 *
 * Copyright (c) 2004, Frederick Ros (sl33p3r@free.fr)
 *										    
 * macros.h
 *
 *
 * This file is part of the eagle-usb driver package.
 *
 * eagle-usb driver package 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.
 *
 * "eagle-usb driver package" 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 "ADI USB ADSL Driver for Linux"; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: macros.h,v 1.6 2005/01/17 20:54:42 sleeper Exp $
 */


#ifndef MACROS_H
#define MACROS_H

/*
 * Compatibility macros (USB changed in kernel 2.4.20)
 */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,19)

typedef struct usb_ctrlrequest devrequest;
#define FILL_USB_CTRL_REQUEST(p, t, r, v, i, l)         \
	{                                                   \
            p->bRequestType = t;                        \
            p->bRequest     = r;                        \
            p->wValue       = cpu_to_le16 ((UInt16) v); \
            p->wIndex       = cpu_to_le16 ((UInt16) i); \
            p->wLength      = cpu_to_le16 ((UInt16) l); \
	}

#else
#define FILL_USB_CTRL_REQUEST(p, t, r, v, i, l)         \
	{                                                   \
            p->requesttype = t;                         \
            p->request     = r;                         \
            p->value       = cpu_to_le16 ((UInt16)v);   \
            p->index       = cpu_to_le16 ((UInt16)i);   \
            p->length      = cpu_to_le16 ((UInt16)l);   \
	}

#endif

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
/*
 * Linux 2.6 introduces kmalloc flags
 */
#define USB_SUBMIT_URB(u,f)    usb_submit_urb((u),(f))
#define USB_ALLOC_URB(u,f)     usb_alloc_urb((u),(f))

#define GET_INTF_PTR(u,n)   ((u)->actconfig->interface[(n)])

#define USB_QUEUE_BULK 0


#define FILL_BULK_URB(u,d,p,tb,bl,c,ctx) \
        usb_fill_bulk_urb ((u),(d),(p),(tb),(bl),(c),(ctx))
/*
 * Module reference is now obsolete
 */
#define MODULE_USER_GET
#define MODULE_USER_RELEASE

/*
 * Get Configuration value for config #n
 */
#define GET_CONFIG_VALUE(d,n)  (d)->config[n].desc.bConfigurationValue


#define USB_COMPLETION_PROTO(f,u,r)   void f ( struct urb *u, struct pt_regs *r )

#define USB_DRIVER_CLAIM_INTERFACE(d,i,p)   \
    usb_driver_claim_interface((d), (i), (p))

#define EU_SCHEDULE(w)    schedule_work ( w )
#define EU_FLUSH(w)       flush_scheduled_work()

#define EU_FREE_NETDEV(n)     free_netdev(n)

#else

/*
 *   K E R N E L   2.4
 *
 */
 

#define USB_SUBMIT_URB(u,f)    usb_submit_urb(u)
#define USB_ALLOC_URB(u,f)     usb_alloc_urb((u))

#define GET_INTF_PTR(u,n)   (&((u)->actconfig->interface[(n)]))

#define URB_ASYNC_UNLINK       USB_ASYNC_UNLINK
#define URB_ISO_ASAP       USB_ISO_ASAP

#define MODULE_USER_GET     MOD_INC_USE_COUNT
#define MODULE_USER_RELEASE MOD_DEC_USE_COUNT

/*
 * Get Configuration value for config #n
 */
#define GET_CONFIG_VALUE(d,n)  (d)->config[n].bConfigurationValue

#define USB_COMPLETION_PROTO(f,u,r)   void f ( struct urb *u )

#define USB_DRIVER_CLAIM_INTERFACE(d,i,p)   \
   ( usb_driver_claim_interface((d), (i), (p)) , 0)

#define EU_SCHEDULE(w)    schedule_task ( w )
#define EU_FLUSH(w)       flush_scheduled_tasks()

#define EU_FREE_NETDEV(n)     kfree(n)

#endif

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,6)
/*
 * wait_ms disappear from 2.6.7 in favor of msleep
 */
static __inline__ void wait_ms(unsigned int ms)
{
        if(!in_interrupt()) {
            msleep (ms);
        }
        else
        {
            mdelay (ms);
        }
}

#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)

#define USB_KILL_URB(urb)    usb_kill_urb(urb)

#else

#define USB_KILL_URB(urb)                       \
  do {                                          \
    (urb)->transfer_flags &= ~URB_ASYNC_UNLINK; \
    usb_unlink_urb(urb);                        \
  } while(0)

#endif

#define GET_KBUFFER(_memsize_) kmalloc((_memsize_), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
#define FREE_KBUFFER(_ptr_)                     \
    if (_ptr_)                                  \
    {                                           \
        kfree(_ptr_);                           \
        (_ptr_) = NULL;                         \
    }

#define GET_VBUFFER(_memsize_) vmalloc(_memsize_)
#define FREE_VBUFFER(_ptr_)                     \
    if (_ptr_)                                  \
    {                                           \
        vfree(_ptr_);                           \
        (_ptr_) = NULL;                         \
    }

/*
 * Quasi-function to obtain current status of SM
 */
#define GetOpStatusSM(_ADAPTER_) ((_ADAPTER_->CurrentAdiState&STATE_OPERATIONAL)!=0)

/*
 * Macro for cancelling the StateMachine timer
 */
#define CancelTimerSM(_ADAPTER_) SetTimerInterval(_ADAPTER_,0)

/*
 * Quasi-function to signal beginning of SM reset
 * actual processing would happen later, on next refresh
 */
#define ResetModemSM(_ADAPTER_) if(_ADAPTER_->CurrentAdiState!=STATE_STALLED_FOREVER) \
                                { (_ADAPTER_->CurrentAdiState=STATE_HARD_RESET_INITIATE); }

#define MSEC_TO_JIFFIES(_msec_) ((HZ*(unsigned long)_msec_)/1000)

#endif /* MACROS_H */