1 // SPDX-License-Identifier: GPL-2.0+
2 /******************************************************************************
3 * usbatm.h - Generic USB xDSL driver core
5 * Copyright (C) 2001, Alcatel
6 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
7 * Copyright (C) 2004, David Woodhouse
8 ******************************************************************************/
13 #include <linux/atm.h>
14 #include <linux/atmdev.h>
15 #include <linux/completion.h>
16 #include <linux/device.h>
17 #include <linux/kernel.h>
18 #include <linux/kref.h>
19 #include <linux/list.h>
20 #include <linux/stringify.h>
21 #include <linux/usb.h>
22 #include <linux/mutex.h>
23 #include <linux/ratelimit.h>
29 #define usb_err(instance, format, arg...) \
30 dev_err(&(instance)->usb_intf->dev , format , ## arg)
31 #define usb_info(instance, format, arg...) \
32 dev_info(&(instance)->usb_intf->dev , format , ## arg)
33 #define usb_warn(instance, format, arg...) \
34 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
35 #define usb_dbg(instance, format, arg...) \
36 dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
38 /* FIXME: move to dev_* once ATM is driver model aware */
39 #define atm_printk(level, instance, format, arg...) \
40 printk(level "ATM dev %d: " format , \
41 (instance)->atm_dev->number , ## arg)
43 #define atm_err(instance, format, arg...) \
44 atm_printk(KERN_ERR, instance , format , ## arg)
45 #define atm_info(instance, format, arg...) \
46 atm_printk(KERN_INFO, instance , format , ## arg)
47 #define atm_warn(instance, format, arg...) \
48 atm_printk(KERN_WARNING, instance , format , ## arg)
49 #define atm_dbg(instance, format, ...) \
50 pr_debug("ATM dev %d: " format, \
51 (instance)->atm_dev->number, ##__VA_ARGS__)
52 #define atm_rldbg(instance, format, ...) \
53 pr_debug_ratelimited("ATM dev %d: " format, \
54 (instance)->atm_dev->number, ##__VA_ARGS__)
56 /* flags, set by mini-driver in bind() */
58 #define UDSL_SKIP_HEAVY_INIT (1<<0)
59 #define UDSL_USE_ISOC (1<<1)
60 #define UDSL_IGNORE_EILSEQ (1<<2)
68 * Assuming all methods exist and succeed, they are called in this order:
70 * bind, heavy_init, atm_start, ..., atm_stop, unbind
73 struct usbatm_driver
{
74 const char *driver_name
;
76 /* init device ... can sleep, or cause probe() failure */
77 int (*bind
) (struct usbatm_data
*, struct usb_interface
*,
78 const struct usb_device_id
*id
);
80 /* additional device initialization that is too slow to be done in probe() */
81 int (*heavy_init
) (struct usbatm_data
*, struct usb_interface
*);
83 /* cleanup device ... can sleep, but can't fail */
84 void (*unbind
) (struct usbatm_data
*, struct usb_interface
*);
86 /* init ATM device ... can sleep, or cause ATM initialization failure */
87 int (*atm_start
) (struct usbatm_data
*, struct atm_dev
*);
89 /* cleanup ATM device ... can sleep, but can't fail */
90 void (*atm_stop
) (struct usbatm_data
*, struct atm_dev
*);
92 int bulk_in
; /* bulk rx endpoint */
93 int isoc_in
; /* isochronous rx endpoint */
94 int bulk_out
; /* bulk tx endpoint */
100 extern int usbatm_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
,
101 struct usbatm_driver
*driver
);
102 extern void usbatm_usb_disconnect(struct usb_interface
*intf
);
105 struct usbatm_channel
{
106 int endpoint
; /* usb pipe */
107 unsigned int stride
; /* ATM cell size + padding */
108 unsigned int buf_size
; /* urb buffer size */
109 unsigned int packet_size
; /* endpoint maxpacket */
111 struct list_head list
;
112 struct tasklet_struct tasklet
;
113 struct timer_list delay
;
114 struct usbatm_data
*usbatm
;
117 /* main driver data */
125 struct usbatm_driver
*driver
;
127 char driver_name
[16];
128 unsigned int flags
; /* set by mini-driver in bind() */
131 struct usb_device
*usb_dev
;
132 struct usb_interface
*usb_intf
;
133 char description
[64];
136 struct atm_dev
*atm_dev
;
138 /********************************
139 * private fields - do not use *
140 ********************************/
142 struct kref refcount
;
143 struct mutex serialize
;
147 struct task_struct
*thread
;
148 struct completion thread_started
;
149 struct completion thread_exited
;
152 struct list_head vcc_list
;
154 struct usbatm_channel rx_channel
;
155 struct usbatm_channel tx_channel
;
157 struct sk_buff_head sndqueue
;
158 struct sk_buff
*current_skb
; /* being emptied */
160 struct usbatm_vcc_data
*cached_vcc
;
164 unsigned char *cell_buf
; /* holds partial rx cell */
165 unsigned int buf_usage
;
170 static inline void *to_usbatm_driver_data(struct usb_interface
*intf
)
172 struct usbatm_data
*usbatm_instance
;
177 usbatm_instance
= usb_get_intfdata(intf
);
179 if (usbatm_instance
== NULL
) /* set NULL before unbind() */
182 return usbatm_instance
->driver_data
; /* set NULL after unbind() */
185 #endif /* _USBATM_H_ */