Nishad Kamdar | 2274048 | 2020-03-15 15:58:48 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * usbatm.h - Generic USB xDSL driver core |
| 4 | * |
| 5 | * Copyright (C) 2001, Alcatel |
| 6 | * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas |
| 7 | * Copyright (C) 2004, David Woodhouse |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 8 | ******************************************************************************/ |
| 9 | |
| 10 | #ifndef _USBATM_H_ |
| 11 | #define _USBATM_H_ |
| 12 | |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 13 | #include <linux/atm.h> |
| 14 | #include <linux/atmdev.h> |
| 15 | #include <linux/completion.h> |
| 16 | #include <linux/device.h> |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 18 | #include <linux/kref.h> |
| 19 | #include <linux/list.h> |
| 20 | #include <linux/stringify.h> |
| 21 | #include <linux/usb.h> |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Joe Perches | 32e2493 | 2013-10-26 20:49:24 -0700 | [diff] [blame] | 23 | #include <linux/ratelimit.h> |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 24 | |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 25 | /* |
| 26 | #define VERBOSE_DEBUG |
| 27 | */ |
| 28 | |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 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...) \ |
Greg Kroah-Hartman | ca4d701 | 2013-06-28 11:32:52 -0700 | [diff] [blame] | 36 | dev_dbg(&(instance)->usb_intf->dev , format , ## arg) |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 37 | |
| 38 | /* FIXME: move to dev_* once ATM is driver model aware */ |
| 39 | #define atm_printk(level, instance, format, arg...) \ |
Andrew Morton | 843c944 | 2005-05-30 01:09:06 -0700 | [diff] [blame] | 40 | printk(level "ATM dev %d: " format , \ |
| 41 | (instance)->atm_dev->number , ## arg) |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 42 | |
| 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) |
Joe Perches | 32e2493 | 2013-10-26 20:49:24 -0700 | [diff] [blame] | 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__) |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 55 | |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 56 | /* flags, set by mini-driver in bind() */ |
| 57 | |
| 58 | #define UDSL_SKIP_HEAVY_INIT (1<<0) |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 59 | #define UDSL_USE_ISOC (1<<1) |
Duncan Sands | a3673d3 | 2006-01-13 11:12:58 +0100 | [diff] [blame] | 60 | #define UDSL_IGNORE_EILSEQ (1<<2) |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 61 | |
| 62 | |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 63 | /* mini driver */ |
| 64 | |
| 65 | struct usbatm_data; |
| 66 | |
| 67 | /* |
| 68 | * Assuming all methods exist and succeed, they are called in this order: |
| 69 | * |
Nicolas Kaiser | 16f76a7 | 2010-06-17 11:55:49 +0200 | [diff] [blame] | 70 | * bind, heavy_init, atm_start, ..., atm_stop, unbind |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 71 | */ |
| 72 | |
| 73 | struct usbatm_driver { |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 74 | const char *driver_name; |
| 75 | |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 76 | /* init device ... can sleep, or cause probe() failure */ |
Nicolas Kaiser | 16f76a7 | 2010-06-17 11:55:49 +0200 | [diff] [blame] | 77 | int (*bind) (struct usbatm_data *, struct usb_interface *, |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 78 | const struct usb_device_id *id); |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 79 | |
| 80 | /* additional device initialization that is too slow to be done in probe() */ |
Nicolas Kaiser | 16f76a7 | 2010-06-17 11:55:49 +0200 | [diff] [blame] | 81 | int (*heavy_init) (struct usbatm_data *, struct usb_interface *); |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 82 | |
| 83 | /* cleanup device ... can sleep, but can't fail */ |
Nicolas Kaiser | 16f76a7 | 2010-06-17 11:55:49 +0200 | [diff] [blame] | 84 | void (*unbind) (struct usbatm_data *, struct usb_interface *); |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 85 | |
| 86 | /* init ATM device ... can sleep, or cause ATM initialization failure */ |
| 87 | int (*atm_start) (struct usbatm_data *, struct atm_dev *); |
| 88 | |
| 89 | /* cleanup ATM device ... can sleep, but can't fail */ |
| 90 | void (*atm_stop) (struct usbatm_data *, struct atm_dev *); |
| 91 | |
Nicolas Kaiser | 16f76a7 | 2010-06-17 11:55:49 +0200 | [diff] [blame] | 92 | int bulk_in; /* bulk rx endpoint */ |
| 93 | int isoc_in; /* isochronous rx endpoint */ |
| 94 | int bulk_out; /* bulk tx endpoint */ |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 95 | |
| 96 | unsigned rx_padding; |
| 97 | unsigned tx_padding; |
| 98 | }; |
| 99 | |
| 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); |
| 103 | |
| 104 | |
| 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 */ |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 109 | unsigned int packet_size; /* endpoint maxpacket */ |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 110 | spinlock_t lock; |
| 111 | struct list_head list; |
| 112 | struct tasklet_struct tasklet; |
| 113 | struct timer_list delay; |
| 114 | struct usbatm_data *usbatm; |
| 115 | }; |
| 116 | |
| 117 | /* main driver data */ |
| 118 | |
| 119 | struct usbatm_data { |
| 120 | /****************** |
| 121 | * public fields * |
Nicolas Kaiser | 16f76a7 | 2010-06-17 11:55:49 +0200 | [diff] [blame] | 122 | ******************/ |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 123 | |
| 124 | /* mini driver */ |
| 125 | struct usbatm_driver *driver; |
| 126 | void *driver_data; |
| 127 | char driver_name[16]; |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 128 | unsigned int flags; /* set by mini-driver in bind() */ |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 129 | |
| 130 | /* USB device */ |
| 131 | struct usb_device *usb_dev; |
| 132 | struct usb_interface *usb_intf; |
| 133 | char description[64]; |
| 134 | |
| 135 | /* ATM device */ |
| 136 | struct atm_dev *atm_dev; |
| 137 | |
| 138 | /******************************** |
| 139 | * private fields - do not use * |
Nicolas Kaiser | 16f76a7 | 2010-06-17 11:55:49 +0200 | [diff] [blame] | 140 | ********************************/ |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 141 | |
| 142 | struct kref refcount; |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 143 | struct mutex serialize; |
Duncan Sands | 0e42a62 | 2006-01-13 10:05:15 +0100 | [diff] [blame] | 144 | int disconnected; |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 145 | |
| 146 | /* heavy init */ |
Pavel Emelyanov | c4504a7 | 2008-02-11 15:26:09 +0300 | [diff] [blame] | 147 | struct task_struct *thread; |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 148 | struct completion thread_started; |
| 149 | struct completion thread_exited; |
| 150 | |
| 151 | /* ATM device */ |
| 152 | struct list_head vcc_list; |
| 153 | |
| 154 | struct usbatm_channel rx_channel; |
| 155 | struct usbatm_channel tx_channel; |
| 156 | |
| 157 | struct sk_buff_head sndqueue; |
Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 158 | struct sk_buff *current_skb; /* being emptied */ |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 159 | |
Duncan Sands | e3fb2f6 | 2006-01-13 11:06:46 +0100 | [diff] [blame] | 160 | struct usbatm_vcc_data *cached_vcc; |
| 161 | int cached_vci; |
| 162 | short cached_vpi; |
| 163 | |
| 164 | unsigned char *cell_buf; /* holds partial rx cell */ |
| 165 | unsigned int buf_usage; |
| 166 | |
Gustavo A. R. Silva | 6bc3f39 | 2020-02-20 07:20:17 -0600 | [diff] [blame] | 167 | struct urb *urbs[]; |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 168 | }; |
| 169 | |
Simon Arlott | 9fc950d | 2009-11-21 15:33:51 +0000 | [diff] [blame] | 170 | static inline void *to_usbatm_driver_data(struct usb_interface *intf) |
| 171 | { |
| 172 | struct usbatm_data *usbatm_instance; |
| 173 | |
| 174 | if (intf == NULL) |
| 175 | return NULL; |
| 176 | |
| 177 | usbatm_instance = usb_get_intfdata(intf); |
| 178 | |
| 179 | if (usbatm_instance == NULL) /* set NULL before unbind() */ |
| 180 | return NULL; |
| 181 | |
| 182 | return usbatm_instance->driver_data; /* set NULL after unbind() */ |
| 183 | } |
| 184 | |
Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 185 | #endif /* _USBATM_H_ */ |