^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * usbatm.h - Generic USB xDSL driver core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2001, Alcatel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2004, David Woodhouse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef _USBATM_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define _USBATM_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/atm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/atmdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/stringify.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/ratelimit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define VERBOSE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define usb_err(instance, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) dev_err(&(instance)->usb_intf->dev , format , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define usb_info(instance, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) dev_info(&(instance)->usb_intf->dev , format , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define usb_warn(instance, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) dev_warn(&(instance)->usb_intf->dev , format , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define usb_dbg(instance, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* FIXME: move to dev_* once ATM is driver model aware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define atm_printk(level, instance, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) printk(level "ATM dev %d: " format , \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) (instance)->atm_dev->number , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define atm_err(instance, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) atm_printk(KERN_ERR, instance , format , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define atm_info(instance, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) atm_printk(KERN_INFO, instance , format , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define atm_warn(instance, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) atm_printk(KERN_WARNING, instance , format , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define atm_dbg(instance, format, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) pr_debug("ATM dev %d: " format, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) (instance)->atm_dev->number, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define atm_rldbg(instance, format, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) pr_debug_ratelimited("ATM dev %d: " format, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) (instance)->atm_dev->number, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* flags, set by mini-driver in bind() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define UDSL_SKIP_HEAVY_INIT (1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define UDSL_USE_ISOC (1<<1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define UDSL_IGNORE_EILSEQ (1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* mini driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct usbatm_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Assuming all methods exist and succeed, they are called in this order:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * bind, heavy_init, atm_start, ..., atm_stop, unbind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct usbatm_driver {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) const char *driver_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* init device ... can sleep, or cause probe() failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int (*bind) (struct usbatm_data *, struct usb_interface *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) const struct usb_device_id *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* additional device initialization that is too slow to be done in probe() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* cleanup device ... can sleep, but can't fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void (*unbind) (struct usbatm_data *, struct usb_interface *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* init ATM device ... can sleep, or cause ATM initialization failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int (*atm_start) (struct usbatm_data *, struct atm_dev *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* cleanup ATM device ... can sleep, but can't fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int bulk_in; /* bulk rx endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int isoc_in; /* isochronous rx endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int bulk_out; /* bulk tx endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned rx_padding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned tx_padding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct usbatm_driver *driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) extern void usbatm_usb_disconnect(struct usb_interface *intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct usbatm_channel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int endpoint; /* usb pipe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned int stride; /* ATM cell size + padding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned int buf_size; /* urb buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned int packet_size; /* endpoint maxpacket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct tasklet_struct tasklet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct timer_list delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct usbatm_data *usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* main driver data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct usbatm_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /******************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * public fields *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ******************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* mini driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct usbatm_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void *driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) char driver_name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) unsigned int flags; /* set by mini-driver in bind() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* USB device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct usb_device *usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct usb_interface *usb_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) char description[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* ATM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct atm_dev *atm_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * private fields - do not use *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct kref refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct mutex serialize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int disconnected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* heavy init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct task_struct *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct completion thread_started;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct completion thread_exited;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* ATM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct list_head vcc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct usbatm_channel rx_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct usbatm_channel tx_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct sk_buff_head sndqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct sk_buff *current_skb; /* being emptied */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct usbatm_vcc_data *cached_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int cached_vci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) short cached_vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) unsigned char *cell_buf; /* holds partial rx cell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) unsigned int buf_usage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct urb *urbs[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static inline void *to_usbatm_driver_data(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct usbatm_data *usbatm_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (intf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) usbatm_instance = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (usbatm_instance == NULL) /* set NULL before unbind() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return usbatm_instance->driver_data; /* set NULL after unbind() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #endif /* _USBATM_H_ */