| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * hfc_usb.c | 
 | 3 |  * | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 4 |  * $Id: hfc_usb.c,v 2.3.2.24 2007/10/14 08:40:29 mbachem Exp $ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 |  * | 
 | 6 |  * modular HiSax ISDN driver for Colognechip HFC-S USB chip | 
 | 7 |  * | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 8 |  * Authors : Peter Sprenger (sprenger@moving-bytes.de) | 
 | 9 |  *           Martin Bachem (m.bachem@gmx.de, info@colognechip.com) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 |  * | 
 | 11 |  *           based on the first hfc_usb driver of | 
 | 12 |  *           Werner Cornelius (werner@isdn-development.de) | 
 | 13 |  * | 
 | 14 |  * This program is free software; you can redistribute it and/or modify | 
 | 15 |  * it under the terms of the GNU General Public License as published by | 
 | 16 |  * the Free Software Foundation; either version 2, or (at your option) | 
 | 17 |  * any later version. | 
 | 18 |  * | 
 | 19 |  * This program is distributed in the hope that it will be useful, | 
 | 20 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 21 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 22 |  * GNU General Public License for more details. | 
 | 23 |  * | 
 | 24 |  * You should have received a copy of the GNU General Public License | 
 | 25 |  * along with this program; if not, write to the Free Software | 
 | 26 |  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
 | 27 |  * | 
 | 28 |  * See Version Histroy at the bottom of this file | 
 | 29 |  * | 
 | 30 | */ | 
 | 31 |  | 
 | 32 | #include <linux/types.h> | 
 | 33 | #include <linux/stddef.h> | 
 | 34 | #include <linux/timer.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/init.h> | 
 | 36 | #include <linux/module.h> | 
 | 37 | #include <linux/kernel_stat.h> | 
 | 38 | #include <linux/usb.h> | 
 | 39 | #include <linux/kernel.h> | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 40 | #include <linux/smp_lock.h> | 
 | 41 | #include <linux/sched.h> | 
 | 42 | #include <linux/moduleparam.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include "hisax.h" | 
 | 44 | #include "hisax_if.h" | 
 | 45 | #include "hfc_usb.h" | 
 | 46 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | static const char *hfcusb_revision = | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 48 |     "$Revision: 2.3.2.24 $ $Date: 2007/10/14 08:40:29 $ "; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 |  | 
 | 50 | /* Hisax debug support | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 51 | *  debug flags defined in hfc_usb.h as HFCUSB_DBG_[*] | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define __debug_variable hfc_debug | 
 | 54 | #include "hisax_debug.h" | 
 | 55 | static u_int debug; | 
 | 56 | module_param(debug, uint, 0); | 
| Adrian Bunk | 672c3fd | 2005-06-25 14:59:18 -0700 | [diff] [blame] | 57 | static int hfc_debug; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 58 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 |  | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 60 | /* private vendor specific data */ | 
 | 61 | typedef struct { | 
 | 62 | 	__u8 led_scheme;	// led display scheme | 
 | 63 | 	signed short led_bits[8];	// array of 8 possible LED bitmask settings | 
 | 64 | 	char *vend_name;	// device name | 
 | 65 | } hfcsusb_vdata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 67 | /* VID/PID device list */ | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 68 | static struct usb_device_id hfcusb_idtab[] = { | 
 | 69 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 70 | 	 USB_DEVICE(0x0959, 0x2bd0), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 71 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 72 | 			  {LED_OFF, {4, 0, 2, 1}, | 
 | 73 | 			   "ISDN USB TA (Cologne Chip HFC-S USB based)"}), | 
 | 74 | 	}, | 
 | 75 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 76 | 	 USB_DEVICE(0x0675, 0x1688), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 77 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 78 | 			  {LED_SCHEME1, {1, 2, 0, 0}, | 
 | 79 | 			   "DrayTek miniVigor 128 USB ISDN TA"}), | 
 | 80 | 	}, | 
 | 81 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 82 | 	 USB_DEVICE(0x07b0, 0x0007), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 83 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 84 | 			  {LED_SCHEME1, {0x80, -64, -32, -16}, | 
 | 85 | 			   "Billion tiny USB ISDN TA 128"}), | 
 | 86 | 	}, | 
 | 87 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 88 | 	 USB_DEVICE(0x0742, 0x2008), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 89 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 90 | 			  {LED_SCHEME1, {4, 0, 2, 1}, | 
 | 91 | 			   "Stollmann USB TA"}), | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 92 | 	}, | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 93 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 94 | 	 USB_DEVICE(0x0742, 0x2009), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 95 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 96 | 			  {LED_SCHEME1, {4, 0, 2, 1}, | 
 | 97 | 			   "Aceex USB ISDN TA"}), | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 98 | 	}, | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 99 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 100 | 	 USB_DEVICE(0x0742, 0x200A), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 101 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 102 | 			  {LED_SCHEME1, {4, 0, 2, 1}, | 
 | 103 | 			   "OEM USB ISDN TA"}), | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 104 | 	}, | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 105 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 106 | 	 USB_DEVICE(0x08e3, 0x0301), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 107 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 108 | 			  {LED_SCHEME1, {2, 0, 1, 4}, | 
 | 109 | 			   "Olitec USB RNIS"}), | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 110 | 	}, | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 111 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 112 | 	 USB_DEVICE(0x07fa, 0x0846), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 113 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 114 | 			  {LED_SCHEME1, {0x80, -64, -32, -16}, | 
 | 115 | 			   "Bewan Modem RNIS USB"}), | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 116 | 	}, | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 117 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 118 | 	 USB_DEVICE(0x07fa, 0x0847), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 119 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 120 | 			  {LED_SCHEME1, {0x80, -64, -32, -16}, | 
 | 121 | 			   "Djinn Numeris USB"}), | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 122 | 	}, | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 123 | 	{ | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 124 | 	 USB_DEVICE(0x07b0, 0x0006), | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 125 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 126 | 			  {LED_SCHEME1, {0x80, -64, -32, -16}, | 
 | 127 | 			   "Twister ISDN TA"}), | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 128 | 	}, | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 129 | 	{ | 
 | 130 | 	 USB_DEVICE(0x071d, 0x1005), | 
 | 131 | 	 .driver_info = (unsigned long) &((hfcsusb_vdata) | 
 | 132 | 			  {LED_SCHEME1, {0x02, 0, 0x01, 0x04}, | 
 | 133 | 			   "Eicon DIVA USB 4.0"}), | 
 | 134 | 	}, | 
| Andrew Morton | d6a1a64 | 2005-11-15 00:09:13 -0800 | [diff] [blame] | 135 | 	{ } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }; | 
 | 137 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* structure defining input+output fifos (interrupt/bulk mode) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | struct usb_fifo;		/* forward definition */ | 
 | 140 | typedef struct iso_urb_struct { | 
 | 141 | 	struct urb *purb; | 
 | 142 | 	__u8 buffer[ISO_BUFFER_SIZE];	/* buffer incoming/outgoing data */ | 
 | 143 | 	struct usb_fifo *owner_fifo;	/* pointer to owner fifo */ | 
 | 144 | } iso_urb_struct; | 
 | 145 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | struct hfcusb_data;		/* forward definition */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 147 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | typedef struct usb_fifo { | 
 | 149 | 	int fifonum;		/* fifo index attached to this structure */ | 
 | 150 | 	int active;		/* fifo is currently active */ | 
 | 151 | 	struct hfcusb_data *hfc;	/* pointer to main structure */ | 
 | 152 | 	int pipe;		/* address of endpoint */ | 
 | 153 | 	__u8 usb_packet_maxlen;	/* maximum length for usb transfer */ | 
 | 154 | 	unsigned int max_size;	/* maximum size of receive/send packet */ | 
 | 155 | 	__u8 intervall;		/* interrupt interval */ | 
 | 156 | 	struct sk_buff *skbuff;	/* actual used buffer */ | 
 | 157 | 	struct urb *urb;	/* transfer structure for usb routines */ | 
 | 158 | 	__u8 buffer[128];	/* buffer incoming/outgoing data */ | 
 | 159 | 	int bit_line;		/* how much bits are in the fifo? */ | 
 | 160 |  | 
 | 161 | 	volatile __u8 usb_transfer_mode;	/* switched between ISO and INT */ | 
 | 162 | 	iso_urb_struct iso[2];	/* need two urbs to have one always for pending */ | 
 | 163 | 	struct hisax_if *hif;	/* hisax interface */ | 
 | 164 | 	int delete_flg;		/* only delete skbuff once */ | 
 | 165 | 	int last_urblen;	/* remember length of last packet */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } usb_fifo; | 
 | 167 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* structure holding all data for one device */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | typedef struct hfcusb_data { | 
 | 170 | 	/* HiSax Interface for loadable Layer1 drivers */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 171 | 	struct hisax_d_if d_if;		/* see hisax_if.h */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | 	struct hisax_b_if b_if[2];	/* see hisax_if.h */ | 
 | 173 | 	int protocol; | 
 | 174 |  | 
 | 175 | 	struct usb_device *dev;	/* our device */ | 
 | 176 | 	int if_used;		/* used interface number */ | 
 | 177 | 	int alt_used;		/* used alternate config */ | 
 | 178 | 	int ctrl_paksize;	/* control pipe packet size */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 179 | 	int ctrl_in_pipe,	/* handles for control pipe */ | 
 | 180 | 	    ctrl_out_pipe; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | 	int cfg_used;		/* configuration index used */ | 
 | 182 | 	int vend_idx;		/* vendor found */ | 
 | 183 | 	int b_mode[2];		/* B-channel mode */ | 
 | 184 | 	int l1_activated;	/* layer 1 activated */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 185 | 	int disc_flag;		/* TRUE if device was disonnected to avoid some USB actions */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | 	int packet_size, iso_packet_size; | 
 | 187 |  | 
 | 188 | 	/* control pipe background handling */ | 
 | 189 | 	ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE];	/* buffer holding queued data */ | 
 | 190 | 	volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt;	/* input/output pointer + count */ | 
 | 191 | 	struct urb *ctrl_urb;	/* transfer structure for control channel */ | 
 | 192 |  | 
 | 193 | 	struct usb_ctrlrequest ctrl_write;	/* buffer for control write request */ | 
 | 194 | 	struct usb_ctrlrequest ctrl_read;	/* same for read request */ | 
 | 195 |  | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 196 | 	__u8 old_led_state, led_state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 |  | 
 | 198 | 	volatile __u8 threshold_mask;	/* threshold actually reported */ | 
 | 199 | 	volatile __u8 bch_enables;	/* or mask for sctrl_r and sctrl register values */ | 
 | 200 |  | 
 | 201 | 	usb_fifo fifos[HFCUSB_NUM_FIFOS];	/* structure holding all fifo data */ | 
 | 202 |  | 
 | 203 | 	volatile __u8 l1_state;	/* actual l1 state */ | 
 | 204 | 	struct timer_list t3_timer;	/* timer 3 for activation/deactivation */ | 
 | 205 | 	struct timer_list t4_timer;	/* timer 4 for activation/deactivation */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } hfcusb_data; | 
 | 207 |  | 
 | 208 |  | 
 | 209 | static void collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, | 
 | 210 | 			     int finish); | 
 | 211 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | static inline const char * | 
 | 213 | symbolic(struct hfcusb_symbolic_list list[], const int num) | 
 | 214 | { | 
 | 215 | 	int i; | 
 | 216 | 	for (i = 0; list[i].name != NULL; i++) | 
 | 217 | 		if (list[i].num == num) | 
 | 218 | 			return (list[i].name); | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 219 | 	return "<unknown ERROR>"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } | 
 | 221 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | static void | 
 | 223 | ctrl_start_transfer(hfcusb_data * hfc) | 
 | 224 | { | 
 | 225 | 	if (hfc->ctrl_cnt) { | 
 | 226 | 		hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe; | 
 | 227 | 		hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write; | 
 | 228 | 		hfc->ctrl_urb->transfer_buffer = NULL; | 
 | 229 | 		hfc->ctrl_urb->transfer_buffer_length = 0; | 
 | 230 | 		hfc->ctrl_write.wIndex = | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 231 | 		    cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | 		hfc->ctrl_write.wValue = | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 233 | 		    cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 |  | 
 | 235 | 		usb_submit_urb(hfc->ctrl_urb, GFP_ATOMIC);	/* start transfer */ | 
 | 236 | 	} | 
 | 237 | }				/* ctrl_start_transfer */ | 
 | 238 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | static int | 
 | 240 | queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val, int action) | 
 | 241 | { | 
 | 242 | 	ctrl_buft *buf; | 
 | 243 |  | 
 | 244 | 	if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) | 
 | 245 | 		return (1);	/* no space left */ | 
 | 246 | 	buf = &hfc->ctrl_buff[hfc->ctrl_in_idx];	/* pointer to new index */ | 
 | 247 | 	buf->hfc_reg = reg; | 
 | 248 | 	buf->reg_val = val; | 
 | 249 | 	buf->action = action; | 
 | 250 | 	if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE) | 
 | 251 | 		hfc->ctrl_in_idx = 0;	/* pointer wrap */ | 
 | 252 | 	if (++hfc->ctrl_cnt == 1) | 
 | 253 | 		ctrl_start_transfer(hfc); | 
 | 254 | 	return (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } | 
 | 256 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | static void | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 258 | ctrl_complete(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { | 
 | 260 | 	hfcusb_data *hfc = (hfcusb_data *) urb->context; | 
 | 261 | 	ctrl_buft *buf; | 
 | 262 |  | 
 | 263 | 	urb->dev = hfc->dev; | 
 | 264 | 	if (hfc->ctrl_cnt) { | 
 | 265 | 		buf = &hfc->ctrl_buff[hfc->ctrl_out_idx]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | 		hfc->ctrl_cnt--;	/* decrement actual count */ | 
 | 267 | 		if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) | 
 | 268 | 			hfc->ctrl_out_idx = 0;	/* pointer wrap */ | 
 | 269 |  | 
 | 270 | 		ctrl_start_transfer(hfc);	/* start next transfer */ | 
 | 271 | 	} | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 272 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | /* write led data to auxport & invert if necessary */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | static void | 
 | 276 | write_led(hfcusb_data * hfc, __u8 led_state) | 
 | 277 | { | 
 | 278 | 	if (led_state != hfc->old_led_state) { | 
 | 279 | 		hfc->old_led_state = led_state; | 
 | 280 | 		queue_control_request(hfc, HFCUSB_P_DATA, led_state, 1); | 
 | 281 | 	} | 
 | 282 | } | 
 | 283 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | static void | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 285 | set_led_bit(hfcusb_data * hfc, signed short led_bits, int on) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 287 | 	if (on) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | 		if (led_bits < 0) | 
 | 289 | 			hfc->led_state &= ~abs(led_bits); | 
 | 290 | 		else | 
 | 291 | 			hfc->led_state |= led_bits; | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 292 | 	} else { | 
 | 293 | 		if (led_bits < 0) | 
 | 294 | 			hfc->led_state |= abs(led_bits); | 
 | 295 | 		else | 
 | 296 | 			hfc->led_state &= ~led_bits; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | 	} | 
 | 298 | } | 
 | 299 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 300 | /* handle LED requests */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | static void | 
 | 302 | handle_led(hfcusb_data * hfc, int event) | 
 | 303 | { | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 304 | 	hfcsusb_vdata *driver_info = | 
 | 305 | 	    (hfcsusb_vdata *) hfcusb_idtab[hfc->vend_idx].driver_info; | 
 | 306 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | 	/* if no scheme -> no LED action */ | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 308 | 	if (driver_info->led_scheme == LED_OFF) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | 		return; | 
 | 310 |  | 
 | 311 | 	switch (event) { | 
 | 312 | 		case LED_POWER_ON: | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 313 | 			set_led_bit(hfc, driver_info->led_bits[0], 1); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 314 | 			set_led_bit(hfc, driver_info->led_bits[1], 0); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 315 | 			set_led_bit(hfc, driver_info->led_bits[2], 0); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 316 | 			set_led_bit(hfc, driver_info->led_bits[3], 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | 			break; | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 318 | 		case LED_POWER_OFF: | 
 | 319 | 			set_led_bit(hfc, driver_info->led_bits[0], 0); | 
 | 320 | 			set_led_bit(hfc, driver_info->led_bits[1], 0); | 
 | 321 | 			set_led_bit(hfc, driver_info->led_bits[2], 0); | 
 | 322 | 			set_led_bit(hfc, driver_info->led_bits[3], 0); | 
 | 323 | 			break; | 
 | 324 | 		case LED_S0_ON: | 
 | 325 | 			set_led_bit(hfc, driver_info->led_bits[1], 1); | 
 | 326 | 			break; | 
 | 327 | 		case LED_S0_OFF: | 
 | 328 | 			set_led_bit(hfc, driver_info->led_bits[1], 0); | 
 | 329 | 			break; | 
 | 330 | 		case LED_B1_ON: | 
 | 331 | 			set_led_bit(hfc, driver_info->led_bits[2], 1); | 
 | 332 | 			break; | 
 | 333 | 		case LED_B1_OFF: | 
 | 334 | 			set_led_bit(hfc, driver_info->led_bits[2], 0); | 
 | 335 | 			break; | 
 | 336 | 		case LED_B2_ON: | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 337 | 			set_led_bit(hfc, driver_info->led_bits[3], 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | 			break; | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 339 | 		case LED_B2_OFF: | 
 | 340 | 			set_led_bit(hfc, driver_info->led_bits[3], 0); | 
 | 341 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 	write_led(hfc, hfc->led_state); | 
 | 344 | } | 
 | 345 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 346 | /* ISDN l1 timer T3 expires */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | static void | 
 | 348 | l1_timer_expire_t3(hfcusb_data * hfc) | 
 | 349 | { | 
 | 350 | 	hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION, | 
 | 351 | 			   NULL); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 352 |  | 
 | 353 | 	DBG(HFCUSB_DBG_STATES, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | 	    "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)"); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 355 |  | 
 | 356 | 	hfc->l1_activated = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | 	handle_led(hfc, LED_S0_OFF); | 
 | 358 | 	/* deactivate : */ | 
 | 359 | 	queue_control_request(hfc, HFCUSB_STATES, 0x10, 1); | 
 | 360 | 	queue_control_request(hfc, HFCUSB_STATES, 3, 1); | 
 | 361 | } | 
 | 362 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 363 | /* ISDN l1 timer T4 expires */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | static void | 
 | 365 | l1_timer_expire_t4(hfcusb_data * hfc) | 
 | 366 | { | 
 | 367 | 	hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION, | 
 | 368 | 			   NULL); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 369 |  | 
 | 370 | 	DBG(HFCUSB_DBG_STATES, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | 	    "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)"); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 372 |  | 
 | 373 | 	hfc->l1_activated = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | 	handle_led(hfc, LED_S0_OFF); | 
 | 375 | } | 
 | 376 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 377 | /* S0 state changed */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | static void | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 379 | s0_state_handler(hfcusb_data * hfc, __u8 state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { | 
 | 381 | 	__u8 old_state; | 
 | 382 |  | 
 | 383 | 	old_state = hfc->l1_state; | 
 | 384 | 	if (state == old_state || state < 1 || state > 8) | 
 | 385 | 		return; | 
 | 386 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 387 | 	DBG(HFCUSB_DBG_STATES, "HFC-S USB: S0 statechange(%d -> %d)", | 
 | 388 | 	    old_state, state); | 
 | 389 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | 	if (state < 4 || state == 7 || state == 8) { | 
 | 391 | 		if (timer_pending(&hfc->t3_timer)) | 
 | 392 | 			del_timer(&hfc->t3_timer); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 393 | 		DBG(HFCUSB_DBG_STATES, "HFC-S USB: T3 deactivated"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | 	} | 
 | 395 | 	if (state >= 7) { | 
 | 396 | 		if (timer_pending(&hfc->t4_timer)) | 
 | 397 | 			del_timer(&hfc->t4_timer); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 398 | 		DBG(HFCUSB_DBG_STATES, "HFC-S USB: T4 deactivated"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | 	} | 
 | 400 |  | 
 | 401 | 	if (state == 7 && !hfc->l1_activated) { | 
 | 402 | 		hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, | 
 | 403 | 				   PH_ACTIVATE | INDICATION, NULL); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 404 | 		DBG(HFCUSB_DBG_STATES, "HFC-S USB: PH_ACTIVATE | INDICATION sent"); | 
 | 405 | 		hfc->l1_activated = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | 		handle_led(hfc, LED_S0_ON); | 
 | 407 | 	} else if (state <= 3 /* && activated */ ) { | 
 | 408 | 		if (old_state == 7 || old_state == 8) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 409 | 			DBG(HFCUSB_DBG_STATES, "HFC-S USB: T4 activated"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | 			if (!timer_pending(&hfc->t4_timer)) { | 
 | 411 | 				hfc->t4_timer.expires = | 
 | 412 | 				    jiffies + (HFC_TIMER_T4 * HZ) / 1000; | 
 | 413 | 				add_timer(&hfc->t4_timer); | 
 | 414 | 			} | 
 | 415 | 		} else { | 
 | 416 | 			hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, | 
 | 417 | 					   PH_DEACTIVATE | INDICATION, | 
 | 418 | 					   NULL); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 419 | 			DBG(HFCUSB_DBG_STATES, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | 			    "HFC-S USB: PH_DEACTIVATE | INDICATION sent"); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 421 | 			hfc->l1_activated = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | 			handle_led(hfc, LED_S0_OFF); | 
 | 423 | 		} | 
 | 424 | 	} | 
 | 425 | 	hfc->l1_state = state; | 
 | 426 | } | 
 | 427 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | static void | 
 | 429 | fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, | 
 | 430 | 	      void *buf, int num_packets, int packet_size, int interval, | 
 | 431 | 	      usb_complete_t complete, void *context) | 
 | 432 | { | 
 | 433 | 	int k; | 
 | 434 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | 	urb->dev = dev; | 
 | 436 | 	urb->pipe = pipe; | 
 | 437 | 	urb->complete = complete; | 
 | 438 | 	urb->number_of_packets = num_packets; | 
 | 439 | 	urb->transfer_buffer_length = packet_size * num_packets; | 
 | 440 | 	urb->context = context; | 
 | 441 | 	urb->transfer_buffer = buf; | 
 | 442 | 	urb->transfer_flags = URB_ISO_ASAP; | 
 | 443 | 	urb->actual_length = 0; | 
 | 444 | 	urb->interval = interval; | 
 | 445 | 	for (k = 0; k < num_packets; k++) { | 
 | 446 | 		urb->iso_frame_desc[k].offset = packet_size * k; | 
 | 447 | 		urb->iso_frame_desc[k].length = packet_size; | 
 | 448 | 		urb->iso_frame_desc[k].actual_length = 0; | 
 | 449 | 	} | 
 | 450 | } | 
 | 451 |  | 
 | 452 | /* allocs urbs and start isoc transfer with two pending urbs to avoid | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 453 |  * gaps in the transfer chain | 
 | 454 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | static int | 
 | 456 | start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb, | 
 | 457 | 		 usb_complete_t complete, int packet_size) | 
 | 458 | { | 
 | 459 | 	int i, k, errcode; | 
 | 460 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 461 | 	DBG(HFCUSB_DBG_INIT, "HFC-S USB: starting ISO-URBs for fifo:%d\n", | 
 | 462 | 	    fifo->fifonum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 |  | 
 | 464 | 	/* allocate Memory for Iso out Urbs */ | 
 | 465 | 	for (i = 0; i < 2; i++) { | 
 | 466 | 		if (!(fifo->iso[i].purb)) { | 
 | 467 | 			fifo->iso[i].purb = | 
 | 468 | 			    usb_alloc_urb(num_packets_per_urb, GFP_KERNEL); | 
 | 469 | 			if (!(fifo->iso[i].purb)) { | 
 | 470 | 				printk(KERN_INFO | 
 | 471 | 				       "alloc urb for fifo %i failed!!!", | 
 | 472 | 				       fifo->fifonum); | 
 | 473 | 			} | 
 | 474 | 			fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo; | 
 | 475 |  | 
 | 476 | 			/* Init the first iso */ | 
 | 477 | 			if (ISO_BUFFER_SIZE >= | 
 | 478 | 			    (fifo->usb_packet_maxlen * | 
 | 479 | 			     num_packets_per_urb)) { | 
 | 480 | 				fill_isoc_urb(fifo->iso[i].purb, | 
 | 481 | 					      fifo->hfc->dev, fifo->pipe, | 
 | 482 | 					      fifo->iso[i].buffer, | 
 | 483 | 					      num_packets_per_urb, | 
 | 484 | 					      fifo->usb_packet_maxlen, | 
 | 485 | 					      fifo->intervall, complete, | 
 | 486 | 					      &fifo->iso[i]); | 
 | 487 | 				memset(fifo->iso[i].buffer, 0, | 
 | 488 | 				       sizeof(fifo->iso[i].buffer)); | 
 | 489 | 				/* defining packet delimeters in fifo->buffer */ | 
 | 490 | 				for (k = 0; k < num_packets_per_urb; k++) { | 
 | 491 | 					fifo->iso[i].purb-> | 
 | 492 | 					    iso_frame_desc[k].offset = | 
 | 493 | 					    k * packet_size; | 
 | 494 | 					fifo->iso[i].purb-> | 
 | 495 | 					    iso_frame_desc[k].length = | 
 | 496 | 					    packet_size; | 
 | 497 | 				} | 
 | 498 | 			} else { | 
 | 499 | 				printk(KERN_INFO | 
 | 500 | 				       "HFC-S USB: ISO Buffer size to small!\n"); | 
 | 501 | 			} | 
 | 502 | 		} | 
 | 503 | 		fifo->bit_line = BITLINE_INF; | 
 | 504 |  | 
 | 505 | 		errcode = usb_submit_urb(fifo->iso[i].purb, GFP_KERNEL); | 
 | 506 | 		fifo->active = (errcode >= 0) ? 1 : 0; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 507 | 		if (errcode < 0) | 
 | 508 | 			printk(KERN_INFO "HFC-S USB: usb_submit_urb URB nr:%d, error(%i): '%s'\n", | 
 | 509 | 			       i, errcode, symbolic(urb_errlist, errcode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | 	} | 
 | 511 | 	return (fifo->active); | 
 | 512 | } | 
 | 513 |  | 
 | 514 | /* stops running iso chain and frees their pending urbs */ | 
 | 515 | static void | 
 | 516 | stop_isoc_chain(usb_fifo * fifo) | 
 | 517 | { | 
 | 518 | 	int i; | 
 | 519 |  | 
 | 520 | 	for (i = 0; i < 2; i++) { | 
 | 521 | 		if (fifo->iso[i].purb) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 522 | 			DBG(HFCUSB_DBG_INIT, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | 			    "HFC-S USB: Stopping iso chain for fifo %i.%i", | 
 | 524 | 			    fifo->fifonum, i); | 
| Alan Stern | ae2d990 | 2007-05-23 13:58:12 -0700 | [diff] [blame] | 525 | 			usb_kill_urb(fifo->iso[i].purb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | 			usb_free_urb(fifo->iso[i].purb); | 
 | 527 | 			fifo->iso[i].purb = NULL; | 
 | 528 | 		} | 
 | 529 | 	} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 530 |  | 
| Alan Stern | ae2d990 | 2007-05-23 13:58:12 -0700 | [diff] [blame] | 531 | 	usb_kill_urb(fifo->urb); | 
 | 532 | 	usb_free_urb(fifo->urb); | 
 | 533 | 	fifo->urb = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | 	fifo->active = 0; | 
 | 535 | } | 
 | 536 |  | 
 | 537 | /* defines how much ISO packets are handled in one URB */ | 
 | 538 | static int iso_packets[8] = | 
 | 539 |     { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, | 
 | 540 | 	ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D | 
 | 541 | }; | 
 | 542 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | static void | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 544 | tx_iso_complete(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { | 
 | 546 | 	iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context; | 
 | 547 | 	usb_fifo *fifo = context_iso_urb->owner_fifo; | 
 | 548 | 	hfcusb_data *hfc = fifo->hfc; | 
 | 549 | 	int k, tx_offset, num_isoc_packets, sink, len, current_len, | 
 | 550 | 	    errcode; | 
 | 551 | 	int frame_complete, transp_mode, fifon, status; | 
 | 552 | 	__u8 threshbit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 |  | 
 | 554 | 	fifon = fifo->fifonum; | 
 | 555 | 	status = urb->status; | 
 | 556 |  | 
 | 557 | 	tx_offset = 0; | 
 | 558 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 559 | 	/* ISO transfer only partially completed, | 
 | 560 | 	   look at individual frame status for details */ | 
 | 561 | 	if (status == -EXDEV) { | 
 | 562 | 		DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: tx_iso_complete with -EXDEV" | 
 | 563 | 		    ", urb->status %d, fifonum %d\n", | 
 | 564 | 		    status, fifon); | 
 | 565 |  | 
 | 566 | 		for (k = 0; k < iso_packets[fifon]; ++k) { | 
 | 567 | 			errcode = urb->iso_frame_desc[k].status; | 
 | 568 | 			if (errcode) | 
 | 569 | 				DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: tx_iso_complete " | 
 | 570 | 				       "packet %i, status: %i\n", | 
 | 571 | 				       k, errcode); | 
 | 572 | 		} | 
 | 573 |  | 
 | 574 | 		// clear status, so go on with ISO transfers | 
 | 575 | 		status = 0; | 
 | 576 | 	} | 
 | 577 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | 	if (fifo->active && !status) { | 
 | 579 | 		transp_mode = 0; | 
 | 580 | 		if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS) | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 581 | 			transp_mode = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 |  | 
 | 583 | 		/* is FifoFull-threshold set for our channel? */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 584 | 		threshbit = (hfc->threshold_mask & (1 << fifon)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | 		num_isoc_packets = iso_packets[fifon]; | 
 | 586 |  | 
 | 587 | 		/* predict dataflow to avoid fifo overflow */ | 
 | 588 | 		if (fifon >= HFCUSB_D_TX) { | 
 | 589 | 			sink = (threshbit) ? SINK_DMIN : SINK_DMAX; | 
 | 590 | 		} else { | 
 | 591 | 			sink = (threshbit) ? SINK_MIN : SINK_MAX; | 
 | 592 | 		} | 
 | 593 | 		fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe, | 
 | 594 | 			      context_iso_urb->buffer, num_isoc_packets, | 
 | 595 | 			      fifo->usb_packet_maxlen, fifo->intervall, | 
 | 596 | 			      tx_iso_complete, urb->context); | 
 | 597 | 		memset(context_iso_urb->buffer, 0, | 
 | 598 | 		       sizeof(context_iso_urb->buffer)); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 599 | 		frame_complete = 0; | 
 | 600 |  | 
 | 601 | 		/* Generate next ISO Packets */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | 		for (k = 0; k < num_isoc_packets; ++k) { | 
 | 603 | 			if (fifo->skbuff) { | 
 | 604 | 				len = fifo->skbuff->len; | 
 | 605 | 				/* we lower data margin every msec */ | 
 | 606 | 				fifo->bit_line -= sink; | 
 | 607 | 				current_len = (0 - fifo->bit_line) / 8; | 
 | 608 | 				/* maximum 15 byte for every ISO packet makes our life easier */ | 
 | 609 | 				if (current_len > 14) | 
 | 610 | 					current_len = 14; | 
 | 611 | 				current_len = | 
 | 612 | 				    (len <= | 
 | 613 | 				     current_len) ? len : current_len; | 
 | 614 | 				/* how much bit do we put on the line? */ | 
 | 615 | 				fifo->bit_line += current_len * 8; | 
 | 616 |  | 
 | 617 | 				context_iso_urb->buffer[tx_offset] = 0; | 
 | 618 | 				if (current_len == len) { | 
 | 619 | 					if (!transp_mode) { | 
 | 620 | 						/* here frame completion */ | 
 | 621 | 						context_iso_urb-> | 
 | 622 | 						    buffer[tx_offset] = 1; | 
 | 623 | 						/* add 2 byte flags and 16bit CRC at end of ISDN frame */ | 
 | 624 | 						fifo->bit_line += 32; | 
 | 625 | 					} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 626 | 					frame_complete = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | 				} | 
 | 628 |  | 
 | 629 | 				memcpy(context_iso_urb->buffer + | 
 | 630 | 				       tx_offset + 1, fifo->skbuff->data, | 
 | 631 | 				       current_len); | 
 | 632 | 				skb_pull(fifo->skbuff, current_len); | 
 | 633 |  | 
 | 634 | 				/* define packet delimeters within the URB buffer */ | 
 | 635 | 				urb->iso_frame_desc[k].offset = tx_offset; | 
 | 636 | 				urb->iso_frame_desc[k].length = | 
 | 637 | 				    current_len + 1; | 
 | 638 |  | 
 | 639 | 				tx_offset += (current_len + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | 			} else { | 
 | 641 | 				urb->iso_frame_desc[k].offset = | 
 | 642 | 				    tx_offset++; | 
 | 643 |  | 
 | 644 | 				urb->iso_frame_desc[k].length = 1; | 
 | 645 | 				fifo->bit_line -= sink;	/* we lower data margin every msec */ | 
 | 646 |  | 
 | 647 | 				if (fifo->bit_line < BITLINE_INF) { | 
 | 648 | 					fifo->bit_line = BITLINE_INF; | 
 | 649 | 				} | 
 | 650 | 			} | 
 | 651 |  | 
 | 652 | 			if (frame_complete) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 653 | 				fifo->delete_flg = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | 				fifo->hif->l1l2(fifo->hif, | 
 | 655 | 						PH_DATA | CONFIRM, | 
| Alan Cox | 17a4506 | 2006-10-03 01:13:55 -0700 | [diff] [blame] | 656 | 						(void *) (unsigned long) fifo->skbuff-> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | 						truesize); | 
 | 658 | 				if (fifo->skbuff && fifo->delete_flg) { | 
 | 659 | 					dev_kfree_skb_any(fifo->skbuff); | 
 | 660 | 					fifo->skbuff = NULL; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 661 | 					fifo->delete_flg = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | 				} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 663 | 				frame_complete = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | 			} | 
 | 665 | 		} | 
 | 666 | 		errcode = usb_submit_urb(urb, GFP_ATOMIC); | 
 | 667 | 		if (errcode < 0) { | 
 | 668 | 			printk(KERN_INFO | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 669 | 			       "HFC-S USB: error submitting ISO URB: %d\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | 			       errcode); | 
 | 671 | 		} | 
 | 672 | 	} else { | 
 | 673 | 		if (status && !hfc->disc_flag) { | 
 | 674 | 			printk(KERN_INFO | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 675 | 			       "HFC-S USB: tx_iso_complete: error(%i): '%s', fifonum=%d\n", | 
 | 676 | 			       status, symbolic(urb_errlist, status), fifon); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | 		} | 
 | 678 | 	} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 679 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | static void | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 682 | rx_iso_complete(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { | 
 | 684 | 	iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context; | 
 | 685 | 	usb_fifo *fifo = context_iso_urb->owner_fifo; | 
 | 686 | 	hfcusb_data *hfc = fifo->hfc; | 
 | 687 | 	int k, len, errcode, offset, num_isoc_packets, fifon, maxlen, | 
 | 688 | 	    status; | 
 | 689 | 	unsigned int iso_status; | 
 | 690 | 	__u8 *buf; | 
 | 691 | 	static __u8 eof[8]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 |  | 
 | 693 | 	fifon = fifo->fifonum; | 
 | 694 | 	status = urb->status; | 
 | 695 |  | 
 | 696 | 	if (urb->status == -EOVERFLOW) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 697 | 		DBG(HFCUSB_DBG_VERBOSE_USB, | 
 | 698 | 		    "HFC-USB: ignoring USB DATAOVERRUN fifo(%i)", fifon); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | 		status = 0; | 
 | 700 | 	} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 701 |  | 
 | 702 | 	/* ISO transfer only partially completed, | 
 | 703 | 	   look at individual frame status for details */ | 
 | 704 | 	if (status == -EXDEV) { | 
 | 705 | 		DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: rx_iso_complete with -EXDEV " | 
 | 706 | 		    "urb->status %d, fifonum %d\n", | 
 | 707 | 		    status, fifon); | 
 | 708 | 		status = 0; | 
 | 709 | 	} | 
 | 710 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | 	if (fifo->active && !status) { | 
 | 712 | 		num_isoc_packets = iso_packets[fifon]; | 
 | 713 | 		maxlen = fifo->usb_packet_maxlen; | 
 | 714 | 		for (k = 0; k < num_isoc_packets; ++k) { | 
 | 715 | 			len = urb->iso_frame_desc[k].actual_length; | 
 | 716 | 			offset = urb->iso_frame_desc[k].offset; | 
 | 717 | 			buf = context_iso_urb->buffer + offset; | 
 | 718 | 			iso_status = urb->iso_frame_desc[k].status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 720 | 			if (iso_status && !hfc->disc_flag) | 
 | 721 | 				DBG(HFCUSB_DBG_VERBOSE_USB, | 
 | 722 | 				    "HFC-S USB: rx_iso_complete " | 
 | 723 | 				    "ISO packet %i, status: %i\n", | 
 | 724 | 				    k, iso_status); | 
 | 725 |  | 
 | 726 | 			if (fifon == HFCUSB_D_RX) { | 
 | 727 | 				DBG(HFCUSB_DBG_VERBOSE_USB, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | 				       "HFC-S USB: ISO-D-RX lst_urblen:%2d " | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 729 | 				       "act_urblen:%2d max-urblen:%2d EOF:0x%0x", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | 				       fifo->last_urblen, len, maxlen, | 
 | 731 | 				       eof[5]); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 732 |  | 
 | 733 | 				DBG_PACKET(HFCUSB_DBG_VERBOSE_USB, buf, len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | 			} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 735 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | 			if (fifo->last_urblen != maxlen) { | 
 | 737 | 				/* the threshold mask is in the 2nd status byte */ | 
 | 738 | 				hfc->threshold_mask = buf[1]; | 
 | 739 | 				/* care for L1 state only for D-Channel | 
 | 740 | 				   to avoid overlapped iso completions */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 741 | 				if (fifon == HFCUSB_D_RX) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | 					/* the S0 state is in the upper half | 
 | 743 | 					   of the 1st status byte */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 744 | 					s0_state_handler(hfc, buf[0] >> 4); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | 				} | 
 | 746 | 				eof[fifon] = buf[0] & 1; | 
 | 747 | 				if (len > 2) | 
 | 748 | 					collect_rx_frame(fifo, buf + 2, | 
 | 749 | 							 len - 2, | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 750 | 							 (len < maxlen) ? | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | 							 eof[fifon] : 0); | 
 | 752 | 			} else { | 
 | 753 | 				collect_rx_frame(fifo, buf, len, | 
 | 754 | 						 (len < | 
 | 755 | 						  maxlen) ? eof[fifon] : | 
 | 756 | 						 0); | 
 | 757 | 			} | 
 | 758 | 			fifo->last_urblen = len; | 
 | 759 | 		} | 
 | 760 |  | 
 | 761 | 		fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe, | 
 | 762 | 			      context_iso_urb->buffer, num_isoc_packets, | 
 | 763 | 			      fifo->usb_packet_maxlen, fifo->intervall, | 
 | 764 | 			      rx_iso_complete, urb->context); | 
 | 765 | 		errcode = usb_submit_urb(urb, GFP_ATOMIC); | 
 | 766 | 		if (errcode < 0) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 767 | 			printk(KERN_ERR | 
 | 768 | 			       "HFC-S USB: error submitting ISO URB: %d\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | 			       errcode); | 
 | 770 | 		} | 
 | 771 | 	} else { | 
 | 772 | 		if (status && !hfc->disc_flag) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 773 | 			printk(KERN_ERR | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | 			       "HFC-S USB: rx_iso_complete : " | 
 | 775 | 			       "urb->status %d, fifonum %d\n", | 
 | 776 | 			       status, fifon); | 
 | 777 | 		} | 
 | 778 | 	} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 779 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 781 | /* collect rx data from INT- and ISO-URBs  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | static void | 
 | 783 | collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish) | 
 | 784 | { | 
 | 785 | 	hfcusb_data *hfc = fifo->hfc; | 
 | 786 | 	int transp_mode, fifon; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 787 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | 	fifon = fifo->fifonum; | 
 | 789 | 	transp_mode = 0; | 
 | 790 | 	if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS) | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 791 | 		transp_mode = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 |  | 
 | 793 | 	if (!fifo->skbuff) { | 
 | 794 | 		fifo->skbuff = dev_alloc_skb(fifo->max_size + 3); | 
 | 795 | 		if (!fifo->skbuff) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 796 | 			printk(KERN_ERR | 
 | 797 | 			       "HFC-S USB: cannot allocate buffer for fifo(%d)\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | 			       fifon); | 
 | 799 | 			return; | 
 | 800 | 		} | 
 | 801 | 	} | 
 | 802 | 	if (len) { | 
 | 803 | 		if (fifo->skbuff->len + len < fifo->max_size) { | 
 | 804 | 			memcpy(skb_put(fifo->skbuff, len), data, len); | 
 | 805 | 		} else { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 806 | 			DBG(HFCUSB_DBG_FIFO_ERR, | 
 | 807 | 			       "HCF-USB: got frame exceeded fifo->max_size(%d) fifo(%d)", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | 			       fifo->max_size, fifon); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 809 | 			DBG_SKB(HFCUSB_DBG_VERBOSE_USB, fifo->skbuff); | 
 | 810 | 			skb_trim(fifo->skbuff, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | 		} | 
 | 812 | 	} | 
 | 813 | 	if (transp_mode && fifo->skbuff->len >= 128) { | 
 | 814 | 		fifo->hif->l1l2(fifo->hif, PH_DATA | INDICATION, | 
 | 815 | 				fifo->skbuff); | 
 | 816 | 		fifo->skbuff = NULL; | 
 | 817 | 		return; | 
 | 818 | 	} | 
 | 819 | 	/* we have a complete hdlc packet */ | 
 | 820 | 	if (finish) { | 
 | 821 | 		if ((!fifo->skbuff->data[fifo->skbuff->len - 1]) | 
 | 822 | 		    && (fifo->skbuff->len > 3)) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 823 |  | 
 | 824 | 			if (fifon == HFCUSB_D_RX) { | 
 | 825 | 				DBG(HFCUSB_DBG_DCHANNEL, | 
 | 826 | 				    "HFC-S USB: D-RX len(%d)", fifo->skbuff->len); | 
 | 827 | 				DBG_SKB(HFCUSB_DBG_DCHANNEL, fifo->skbuff); | 
 | 828 | 			} | 
 | 829 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | 			/* remove CRC & status */ | 
 | 831 | 			skb_trim(fifo->skbuff, fifo->skbuff->len - 3); | 
 | 832 | 			if (fifon == HFCUSB_PCM_RX) { | 
 | 833 | 				fifo->hif->l1l2(fifo->hif, | 
 | 834 | 						PH_DATA_E | INDICATION, | 
 | 835 | 						fifo->skbuff); | 
 | 836 | 			} else | 
 | 837 | 				fifo->hif->l1l2(fifo->hif, | 
 | 838 | 						PH_DATA | INDICATION, | 
 | 839 | 						fifo->skbuff); | 
 | 840 | 			fifo->skbuff = NULL;	/* buffer was freed from upper layer */ | 
 | 841 | 		} else { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 842 | 			DBG(HFCUSB_DBG_FIFO_ERR, | 
 | 843 | 			    "HFC-S USB: ERROR frame len(%d) fifo(%d)", | 
 | 844 | 			    fifo->skbuff->len, fifon); | 
 | 845 | 			DBG_SKB(HFCUSB_DBG_VERBOSE_USB, fifo->skbuff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | 			skb_trim(fifo->skbuff, 0); | 
 | 847 | 		} | 
 | 848 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } | 
 | 850 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | static void | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 852 | rx_int_complete(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | { | 
 | 854 | 	int len; | 
 | 855 | 	int status; | 
 | 856 | 	__u8 *buf, maxlen, fifon; | 
 | 857 | 	usb_fifo *fifo = (usb_fifo *) urb->context; | 
 | 858 | 	hfcusb_data *hfc = fifo->hfc; | 
 | 859 | 	static __u8 eof[8]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 |  | 
 | 861 | 	urb->dev = hfc->dev;	/* security init */ | 
 | 862 |  | 
 | 863 | 	fifon = fifo->fifonum; | 
 | 864 | 	if ((!fifo->active) || (urb->status)) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 865 | 		DBG(HFCUSB_DBG_INIT, "HFC-S USB: RX-Fifo %i is going down (%i)", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | 		    fifon, urb->status); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 867 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | 		fifo->urb->interval = 0;	/* cancel automatic rescheduling */ | 
 | 869 | 		if (fifo->skbuff) { | 
 | 870 | 			dev_kfree_skb_any(fifo->skbuff); | 
 | 871 | 			fifo->skbuff = NULL; | 
 | 872 | 		} | 
 | 873 | 		return; | 
 | 874 | 	} | 
 | 875 | 	len = urb->actual_length; | 
 | 876 | 	buf = fifo->buffer; | 
 | 877 | 	maxlen = fifo->usb_packet_maxlen; | 
 | 878 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 879 | 	if (fifon == HFCUSB_D_RX) { | 
 | 880 | 		DBG(HFCUSB_DBG_VERBOSE_USB, | 
 | 881 | 		       "HFC-S USB: INT-D-RX lst_urblen:%2d " | 
 | 882 | 		       "act_urblen:%2d max-urblen:%2d EOF:0x%0x", | 
 | 883 | 		       fifo->last_urblen, len, maxlen, | 
 | 884 | 		       eof[5]); | 
 | 885 | 		DBG_PACKET(HFCUSB_DBG_VERBOSE_USB, buf, len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 |  | 
 | 888 | 	if (fifo->last_urblen != fifo->usb_packet_maxlen) { | 
 | 889 | 		/* the threshold mask is in the 2nd status byte */ | 
 | 890 | 		hfc->threshold_mask = buf[1]; | 
 | 891 | 		/* the S0 state is in the upper half of the 1st status byte */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 892 | 		s0_state_handler(hfc, buf[0] >> 4); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | 		eof[fifon] = buf[0] & 1; | 
 | 894 | 		/* if we have more than the 2 status bytes -> collect data */ | 
 | 895 | 		if (len > 2) | 
 | 896 | 			collect_rx_frame(fifo, buf + 2, | 
 | 897 | 					 urb->actual_length - 2, | 
 | 898 | 					 (len < maxlen) ? eof[fifon] : 0); | 
 | 899 | 	} else { | 
 | 900 | 		collect_rx_frame(fifo, buf, urb->actual_length, | 
 | 901 | 				 (len < maxlen) ? eof[fifon] : 0); | 
 | 902 | 	} | 
 | 903 | 	fifo->last_urblen = urb->actual_length; | 
 | 904 | 	status = usb_submit_urb(urb, GFP_ATOMIC); | 
 | 905 | 	if (status) { | 
 | 906 | 		printk(KERN_INFO | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 907 | 		       "HFC-S USB: %s error resubmitting URB fifo(%d)\n", | 
| Harvey Harrison | 156f1ed | 2008-04-28 02:14:40 -0700 | [diff] [blame] | 908 | 		       __func__, fifon); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | 	} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 910 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 912 | /* start initial INT-URB for certain fifo */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | static void | 
 | 914 | start_int_fifo(usb_fifo * fifo) | 
 | 915 | { | 
 | 916 | 	int errcode; | 
 | 917 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 918 | 	DBG(HFCUSB_DBG_INIT, "HFC-S USB: starting RX INT-URB for fifo:%d\n", | 
 | 919 | 	    fifo->fifonum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 |  | 
 | 921 | 	if (!fifo->urb) { | 
 | 922 | 		fifo->urb = usb_alloc_urb(0, GFP_KERNEL); | 
 | 923 | 		if (!fifo->urb) | 
 | 924 | 			return; | 
 | 925 | 	} | 
 | 926 | 	usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe, | 
 | 927 | 			 fifo->buffer, fifo->usb_packet_maxlen, | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 928 | 			 rx_int_complete, fifo, fifo->intervall); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | 	fifo->active = 1;	/* must be marked active */ | 
 | 930 | 	errcode = usb_submit_urb(fifo->urb, GFP_KERNEL); | 
 | 931 | 	if (errcode) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 932 | 		printk(KERN_ERR | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | 		       "HFC-S USB: submit URB error(start_int_info): status:%i\n", | 
 | 934 | 		       errcode); | 
 | 935 | 		fifo->active = 0; | 
 | 936 | 		fifo->skbuff = NULL; | 
 | 937 | 	} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 938 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | static void | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 941 | setup_bchannel(hfcusb_data * hfc, int channel, int mode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | { | 
 | 943 | 	__u8 val, idx_table[2] = { 0, 2 }; | 
 | 944 |  | 
 | 945 | 	if (hfc->disc_flag) { | 
 | 946 | 		return; | 
 | 947 | 	} | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 948 | 	DBG(HFCUSB_DBG_STATES, "HFC-S USB: setting channel %d to mode %d", | 
 | 949 | 	    channel, mode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | 	hfc->b_mode[channel] = mode; | 
 | 951 |  | 
 | 952 | 	/* setup CON_HDLC */ | 
 | 953 | 	val = 0; | 
 | 954 | 	if (mode != L1_MODE_NULL) | 
 | 955 | 		val = 8;	/* enable fifo? */ | 
 | 956 | 	if (mode == L1_MODE_TRANS) | 
 | 957 | 		val |= 2;	/* set transparent bit */ | 
 | 958 |  | 
 | 959 | 	/* set FIFO to transmit register */ | 
 | 960 | 	queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel], 1); | 
 | 961 | 	queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1); | 
 | 962 | 	/* reset fifo */ | 
 | 963 | 	queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1); | 
 | 964 | 	/* set FIFO to receive register */ | 
 | 965 | 	queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel] + 1, 1); | 
 | 966 | 	queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1); | 
 | 967 | 	/* reset fifo */ | 
 | 968 | 	queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1); | 
 | 969 |  | 
 | 970 | 	val = 0x40; | 
 | 971 | 	if (hfc->b_mode[0]) | 
 | 972 | 		val |= 1; | 
 | 973 | 	if (hfc->b_mode[1]) | 
 | 974 | 		val |= 2; | 
 | 975 | 	queue_control_request(hfc, HFCUSB_SCTRL, val, 1); | 
 | 976 |  | 
 | 977 | 	val = 0; | 
 | 978 | 	if (hfc->b_mode[0]) | 
 | 979 | 		val |= 1; | 
 | 980 | 	if (hfc->b_mode[1]) | 
 | 981 | 		val |= 2; | 
 | 982 | 	queue_control_request(hfc, HFCUSB_SCTRL_R, val, 1); | 
 | 983 |  | 
 | 984 | 	if (mode == L1_MODE_NULL) { | 
 | 985 | 		if (channel) | 
 | 986 | 			handle_led(hfc, LED_B2_OFF); | 
 | 987 | 		else | 
 | 988 | 			handle_led(hfc, LED_B1_OFF); | 
 | 989 | 	} else { | 
 | 990 | 		if (channel) | 
 | 991 | 			handle_led(hfc, LED_B2_ON); | 
 | 992 | 		else | 
 | 993 | 			handle_led(hfc, LED_B1_ON); | 
 | 994 | 	} | 
 | 995 | } | 
 | 996 |  | 
| Adrian Bunk | 672c3fd | 2005-06-25 14:59:18 -0700 | [diff] [blame] | 997 | static void | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg) | 
 | 999 | { | 
 | 1000 | 	usb_fifo *fifo = my_hisax_if->priv; | 
 | 1001 | 	hfcusb_data *hfc = fifo->hfc; | 
 | 1002 |  | 
 | 1003 | 	switch (pr) { | 
 | 1004 | 		case PH_ACTIVATE | REQUEST: | 
 | 1005 | 			if (fifo->fifonum == HFCUSB_D_TX) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1006 | 				DBG(HFCUSB_DBG_STATES, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | 				    "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST"); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1008 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | 				if (hfc->l1_state != 3 | 
 | 1010 | 				    && hfc->l1_state != 7) { | 
 | 1011 | 					hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, | 
 | 1012 | 							   PH_DEACTIVATE | | 
 | 1013 | 							   INDICATION, | 
 | 1014 | 							   NULL); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1015 | 					DBG(HFCUSB_DBG_STATES, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | 					    "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | 				} else { | 
 | 1018 | 					if (hfc->l1_state == 7) {	/* l1 already active */ | 
 | 1019 | 						hfc->d_if.ifc.l1l2(&hfc-> | 
 | 1020 | 								   d_if. | 
 | 1021 | 								   ifc, | 
 | 1022 | 								   PH_ACTIVATE | 
 | 1023 | 								   | | 
 | 1024 | 								   INDICATION, | 
 | 1025 | 								   NULL); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1026 | 						DBG(HFCUSB_DBG_STATES, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | 						    "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | 					} else { | 
 | 1029 | 						/* force sending sending INFO1 */ | 
 | 1030 | 						queue_control_request(hfc, | 
 | 1031 | 								      HFCUSB_STATES, | 
 | 1032 | 								      0x14, | 
 | 1033 | 								      1); | 
 | 1034 | 						mdelay(1); | 
 | 1035 | 						/* start l1 activation */ | 
 | 1036 | 						queue_control_request(hfc, | 
 | 1037 | 								      HFCUSB_STATES, | 
 | 1038 | 								      0x04, | 
 | 1039 | 								      1); | 
 | 1040 | 						if (!timer_pending | 
 | 1041 | 						    (&hfc->t3_timer)) { | 
 | 1042 | 							hfc->t3_timer. | 
 | 1043 | 							    expires = | 
 | 1044 | 							    jiffies + | 
 | 1045 | 							    (HFC_TIMER_T3 * | 
 | 1046 | 							     HZ) / 1000; | 
 | 1047 | 							add_timer(&hfc-> | 
 | 1048 | 								  t3_timer); | 
 | 1049 | 						} | 
 | 1050 | 					} | 
 | 1051 | 				} | 
 | 1052 | 			} else { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1053 | 				DBG(HFCUSB_DBG_STATES, | 
 | 1054 | 				    "HFC_USB: hfc_usb_d_l2l1 B-chan: PH_ACTIVATE | REQUEST"); | 
 | 1055 | 				setup_bchannel(hfc, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | 					    (fifo->fifonum == | 
 | 1057 | 					     HFCUSB_B1_TX) ? 0 : 1, | 
| Alan Cox | 17a4506 | 2006-10-03 01:13:55 -0700 | [diff] [blame] | 1058 | 					    (long) arg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | 				fifo->hif->l1l2(fifo->hif, | 
 | 1060 | 						PH_ACTIVATE | INDICATION, | 
 | 1061 | 						NULL); | 
 | 1062 | 			} | 
 | 1063 | 			break; | 
 | 1064 | 		case PH_DEACTIVATE | REQUEST: | 
 | 1065 | 			if (fifo->fifonum == HFCUSB_D_TX) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1066 | 				DBG(HFCUSB_DBG_STATES, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | 				    "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | 			} else { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1069 | 				DBG(HFCUSB_DBG_STATES, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | 				    "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST"); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1071 | 				setup_bchannel(hfc, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | 					    (fifo->fifonum == | 
 | 1073 | 					     HFCUSB_B1_TX) ? 0 : 1, | 
 | 1074 | 					    (int) L1_MODE_NULL); | 
 | 1075 | 				fifo->hif->l1l2(fifo->hif, | 
 | 1076 | 						PH_DEACTIVATE | INDICATION, | 
 | 1077 | 						NULL); | 
 | 1078 | 			} | 
 | 1079 | 			break; | 
 | 1080 | 		case PH_DATA | REQUEST: | 
 | 1081 | 			if (fifo->skbuff && fifo->delete_flg) { | 
 | 1082 | 				dev_kfree_skb_any(fifo->skbuff); | 
 | 1083 | 				fifo->skbuff = NULL; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1084 | 				fifo->delete_flg = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | 			} | 
 | 1086 | 			fifo->skbuff = arg;	/* we have a new buffer */ | 
 | 1087 | 			break; | 
 | 1088 | 		default: | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1089 | 			DBG(HFCUSB_DBG_STATES, | 
 | 1090 | 			       "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x", pr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | 			break; | 
 | 1092 | 	} | 
 | 1093 | } | 
 | 1094 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1095 | /* initial init HFC-S USB chip registers, HiSax interface, USB URBs */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | static int | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1097 | hfc_usb_init(hfcusb_data * hfc) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | { | 
 | 1099 | 	usb_fifo *fifo; | 
 | 1100 | 	int i, err; | 
 | 1101 | 	u_char b; | 
 | 1102 | 	struct hisax_b_if *p_b_if[2]; | 
 | 1103 |  | 
 | 1104 | 	/* check the chip id */ | 
 | 1105 | 	if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) { | 
 | 1106 | 		printk(KERN_INFO "HFC-USB: cannot read chip id\n"); | 
 | 1107 | 		return (1); | 
 | 1108 | 	} | 
 | 1109 | 	if (b != HFCUSB_CHIPID) { | 
 | 1110 | 		printk(KERN_INFO "HFC-S USB: Invalid chip id 0x%02x\n", b); | 
 | 1111 | 		return (1); | 
 | 1112 | 	} | 
 | 1113 |  | 
 | 1114 | 	/* first set the needed config, interface and alternate */ | 
 | 1115 | 	err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used); | 
 | 1116 |  | 
 | 1117 | 	/* do Chip reset */ | 
 | 1118 | 	write_usb(hfc, HFCUSB_CIRM, 8); | 
 | 1119 | 	/* aux = output, reset off */ | 
 | 1120 | 	write_usb(hfc, HFCUSB_CIRM, 0x10); | 
 | 1121 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1122 | 	/* set USB_SIZE to match wMaxPacketSize for INT or BULK transfers */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | 	write_usb(hfc, HFCUSB_USB_SIZE, | 
 | 1124 | 		  (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4)); | 
 | 1125 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1126 | 	/* set USB_SIZE_I to match wMaxPacketSize for ISO transfers */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | 	write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size); | 
 | 1128 |  | 
 | 1129 | 	/* enable PCM/GCI master mode */ | 
 | 1130 | 	write_usb(hfc, HFCUSB_MST_MODE1, 0);	/* set default values */ | 
 | 1131 | 	write_usb(hfc, HFCUSB_MST_MODE0, 1);	/* enable master mode */ | 
 | 1132 |  | 
 | 1133 | 	/* init the fifos */ | 
 | 1134 | 	write_usb(hfc, HFCUSB_F_THRES, | 
 | 1135 | 		  (HFCUSB_TX_THRESHOLD / | 
 | 1136 | 		   8) | ((HFCUSB_RX_THRESHOLD / 8) << 4)); | 
 | 1137 |  | 
 | 1138 | 	fifo = hfc->fifos; | 
 | 1139 | 	for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { | 
 | 1140 | 		write_usb(hfc, HFCUSB_FIFO, i);	/* select the desired fifo */ | 
 | 1141 | 		fifo[i].skbuff = NULL;	/* init buffer pointer */ | 
 | 1142 | 		fifo[i].max_size = | 
 | 1143 | 		    (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN; | 
 | 1144 | 		fifo[i].last_urblen = 0; | 
 | 1145 | 		/* set 2 bit for D- & E-channel */ | 
 | 1146 | 		write_usb(hfc, HFCUSB_HDLC_PAR, | 
 | 1147 | 			  ((i <= HFCUSB_B2_RX) ? 0 : 2)); | 
 | 1148 | 		/* rx hdlc, enable IFF for D-channel */ | 
 | 1149 | 		write_usb(hfc, HFCUSB_CON_HDLC, | 
 | 1150 | 			  ((i == HFCUSB_D_TX) ? 0x09 : 0x08)); | 
 | 1151 | 		write_usb(hfc, HFCUSB_INC_RES_F, 2);	/* reset the fifo */ | 
 | 1152 | 	} | 
 | 1153 |  | 
 | 1154 | 	write_usb(hfc, HFCUSB_CLKDEL, 0x0f);	/* clock delay value */ | 
 | 1155 | 	write_usb(hfc, HFCUSB_STATES, 3 | 0x10);	/* set deactivated mode */ | 
 | 1156 | 	write_usb(hfc, HFCUSB_STATES, 3);	/* enable state machine */ | 
 | 1157 |  | 
 | 1158 | 	write_usb(hfc, HFCUSB_SCTRL_R, 0);	/* disable both B receivers */ | 
 | 1159 | 	write_usb(hfc, HFCUSB_SCTRL, 0x40);	/* disable B transmitters + capacitive mode */ | 
 | 1160 |  | 
 | 1161 | 	/* set both B-channel to not connected */ | 
 | 1162 | 	hfc->b_mode[0] = L1_MODE_NULL; | 
 | 1163 | 	hfc->b_mode[1] = L1_MODE_NULL; | 
 | 1164 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1165 | 	hfc->l1_activated = 0; | 
 | 1166 | 	hfc->disc_flag = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | 	hfc->led_state = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | 	hfc->old_led_state = 0; | 
 | 1169 |  | 
 | 1170 | 	/* init the t3 timer */ | 
 | 1171 | 	init_timer(&hfc->t3_timer); | 
 | 1172 | 	hfc->t3_timer.data = (long) hfc; | 
 | 1173 | 	hfc->t3_timer.function = (void *) l1_timer_expire_t3; | 
 | 1174 |  | 
 | 1175 | 	/* init the t4 timer */ | 
 | 1176 | 	init_timer(&hfc->t4_timer); | 
 | 1177 | 	hfc->t4_timer.data = (long) hfc; | 
 | 1178 | 	hfc->t4_timer.function = (void *) l1_timer_expire_t4; | 
 | 1179 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | 	/* init the background machinery for control requests */ | 
 | 1181 | 	hfc->ctrl_read.bRequestType = 0xc0; | 
 | 1182 | 	hfc->ctrl_read.bRequest = 1; | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 1183 | 	hfc->ctrl_read.wLength = cpu_to_le16(1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | 	hfc->ctrl_write.bRequestType = 0x40; | 
 | 1185 | 	hfc->ctrl_write.bRequest = 0; | 
 | 1186 | 	hfc->ctrl_write.wLength = 0; | 
 | 1187 | 	usb_fill_control_urb(hfc->ctrl_urb, | 
 | 1188 | 			     hfc->dev, | 
 | 1189 | 			     hfc->ctrl_out_pipe, | 
 | 1190 | 			     (u_char *) & hfc->ctrl_write, | 
 | 1191 | 			     NULL, 0, ctrl_complete, hfc); | 
 | 1192 | 	/* Init All Fifos */ | 
 | 1193 | 	for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { | 
 | 1194 | 		hfc->fifos[i].iso[0].purb = NULL; | 
 | 1195 | 		hfc->fifos[i].iso[1].purb = NULL; | 
 | 1196 | 		hfc->fifos[i].active = 0; | 
 | 1197 | 	} | 
 | 1198 | 	/* register Modul to upper Hisax Layers */ | 
 | 1199 | 	hfc->d_if.owner = THIS_MODULE; | 
 | 1200 | 	hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX]; | 
 | 1201 | 	hfc->d_if.ifc.l2l1 = hfc_usb_l2l1; | 
 | 1202 | 	for (i = 0; i < 2; i++) { | 
 | 1203 | 		hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX + i * 2]; | 
 | 1204 | 		hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1; | 
 | 1205 | 		p_b_if[i] = &hfc->b_if[i]; | 
 | 1206 | 	} | 
 | 1207 | 	/* default Prot: EURO ISDN, should be a module_param */ | 
 | 1208 | 	hfc->protocol = 2; | 
| Alan Stern | ae2d990 | 2007-05-23 13:58:12 -0700 | [diff] [blame] | 1209 | 	i = hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol); | 
 | 1210 | 	if (i) { | 
 | 1211 | 		printk(KERN_INFO "HFC-S USB: hisax_register -> %d\n", i); | 
 | 1212 | 		return i; | 
 | 1213 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 |  | 
 | 1215 | #ifdef CONFIG_HISAX_DEBUG | 
 | 1216 | 	hfc_debug = debug; | 
 | 1217 | #endif | 
 | 1218 |  | 
 | 1219 | 	for (i = 0; i < 4; i++) | 
 | 1220 | 		hfc->fifos[i].hif = &p_b_if[i / 2]->ifc; | 
 | 1221 | 	for (i = 4; i < 8; i++) | 
 | 1222 | 		hfc->fifos[i].hif = &hfc->d_if.ifc; | 
 | 1223 |  | 
 | 1224 | 	/* 3 (+1) INT IN + 3 ISO OUT */ | 
 | 1225 | 	if (hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) { | 
 | 1226 | 		start_int_fifo(hfc->fifos + HFCUSB_D_RX); | 
 | 1227 | 		if (hfc->fifos[HFCUSB_PCM_RX].pipe) | 
 | 1228 | 			start_int_fifo(hfc->fifos + HFCUSB_PCM_RX); | 
 | 1229 | 		start_int_fifo(hfc->fifos + HFCUSB_B1_RX); | 
 | 1230 | 		start_int_fifo(hfc->fifos + HFCUSB_B2_RX); | 
 | 1231 | 	} | 
 | 1232 | 	/* 3 (+1) ISO IN + 3 ISO OUT */ | 
 | 1233 | 	if (hfc->cfg_used == CNF_3ISO3ISO || hfc->cfg_used == CNF_4ISO3ISO) { | 
 | 1234 | 		start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, | 
 | 1235 | 				 rx_iso_complete, 16); | 
 | 1236 | 		if (hfc->fifos[HFCUSB_PCM_RX].pipe) | 
 | 1237 | 			start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, | 
 | 1238 | 					 ISOC_PACKETS_D, rx_iso_complete, | 
 | 1239 | 					 16); | 
 | 1240 | 		start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, | 
 | 1241 | 				 rx_iso_complete, 16); | 
 | 1242 | 		start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, | 
 | 1243 | 				 rx_iso_complete, 16); | 
 | 1244 | 	} | 
 | 1245 |  | 
 | 1246 | 	start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, | 
 | 1247 | 			 tx_iso_complete, 1); | 
 | 1248 | 	start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, | 
 | 1249 | 			 tx_iso_complete, 1); | 
 | 1250 | 	start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, | 
 | 1251 | 			 tx_iso_complete, 1); | 
 | 1252 |  | 
 | 1253 | 	handle_led(hfc, LED_POWER_ON); | 
 | 1254 |  | 
 | 1255 | 	return (0); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1256 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1258 | /* initial callback for each plugged USB device */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | static int | 
 | 1260 | hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) | 
 | 1261 | { | 
 | 1262 | 	struct usb_device *dev = interface_to_usbdev(intf); | 
 | 1263 | 	hfcusb_data *context; | 
 | 1264 | 	struct usb_host_interface *iface = intf->cur_altsetting; | 
 | 1265 | 	struct usb_host_interface *iface_used = NULL; | 
 | 1266 | 	struct usb_host_endpoint *ep; | 
 | 1267 | 	int ifnum = iface->desc.bInterfaceNumber; | 
 | 1268 | 	int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf, | 
 | 1269 | 	    attr, cfg_found, cidx, ep_addr; | 
 | 1270 | 	int cmptbl[16], small_match, iso_packet_size, packet_size, | 
 | 1271 | 	    alt_used = 0; | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 1272 | 	hfcsusb_vdata *driver_info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 |  | 
 | 1274 | 	vend_idx = 0xffff; | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 1275 | 	for (i = 0; hfcusb_idtab[i].idVendor; i++) { | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 1276 | 		if ((le16_to_cpu(dev->descriptor.idVendor) == hfcusb_idtab[i].idVendor) | 
 | 1277 | 		    && (le16_to_cpu(dev->descriptor.idProduct) == hfcusb_idtab[i].idProduct)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | 			vend_idx = i; | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 1279 | 			continue; | 
 | 1280 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | 	} | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 1282 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | 	printk(KERN_INFO | 
 | 1284 | 	       "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n", | 
 | 1285 | 	       ifnum, iface->desc.bAlternateSetting, intf->minor); | 
 | 1286 |  | 
 | 1287 | 	if (vend_idx != 0xffff) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | 		/* if vendor and product ID is OK, start probing alternate settings */ | 
 | 1289 | 		alt_idx = 0; | 
 | 1290 | 		small_match = 0xffff; | 
 | 1291 |  | 
 | 1292 | 		/* default settings */ | 
 | 1293 | 		iso_packet_size = 16; | 
 | 1294 | 		packet_size = 64; | 
 | 1295 |  | 
 | 1296 | 		while (alt_idx < intf->num_altsetting) { | 
 | 1297 | 			iface = intf->altsetting + alt_idx; | 
 | 1298 | 			probe_alt_setting = iface->desc.bAlternateSetting; | 
 | 1299 | 			cfg_used = 0; | 
 | 1300 |  | 
 | 1301 | 			/* check for config EOL element */ | 
 | 1302 | 			while (validconf[cfg_used][0]) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1303 | 				cfg_found = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | 				vcf = validconf[cfg_used]; | 
 | 1305 | 				/* first endpoint descriptor */ | 
 | 1306 | 				ep = iface->endpoint; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1307 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | 				memcpy(cmptbl, vcf, 16 * sizeof(int)); | 
 | 1309 |  | 
 | 1310 | 				/* check for all endpoints in this alternate setting */ | 
 | 1311 | 				for (i = 0; i < iface->desc.bNumEndpoints; | 
 | 1312 | 				     i++) { | 
 | 1313 | 					ep_addr = | 
 | 1314 | 					    ep->desc.bEndpointAddress; | 
 | 1315 | 					/* get endpoint base */ | 
 | 1316 | 					idx = ((ep_addr & 0x7f) - 1) * 2; | 
 | 1317 | 					if (ep_addr & 0x80) | 
 | 1318 | 						idx++; | 
 | 1319 | 					attr = ep->desc.bmAttributes; | 
 | 1320 | 					if (cmptbl[idx] == EP_NUL) { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1321 | 						cfg_found = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | 					} | 
 | 1323 | 					if (attr == USB_ENDPOINT_XFER_INT | 
 | 1324 | 					    && cmptbl[idx] == EP_INT) | 
 | 1325 | 						cmptbl[idx] = EP_NUL; | 
 | 1326 | 					if (attr == USB_ENDPOINT_XFER_BULK | 
 | 1327 | 					    && cmptbl[idx] == EP_BLK) | 
 | 1328 | 						cmptbl[idx] = EP_NUL; | 
 | 1329 | 					if (attr == USB_ENDPOINT_XFER_ISOC | 
 | 1330 | 					    && cmptbl[idx] == EP_ISO) | 
 | 1331 | 						cmptbl[idx] = EP_NUL; | 
 | 1332 |  | 
 | 1333 | 					/* check if all INT endpoints match minimum interval */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1334 | 					if ((attr == USB_ENDPOINT_XFER_INT) | 
 | 1335 | 					    && (ep->desc.bInterval < vcf[17])) { | 
 | 1336 | 						cfg_found = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | 					} | 
 | 1338 | 					ep++; | 
 | 1339 | 				} | 
 | 1340 | 				for (i = 0; i < 16; i++) { | 
 | 1341 | 					/* all entries must be EP_NOP or EP_NUL for a valid config */ | 
 | 1342 | 					if (cmptbl[i] != EP_NOP | 
 | 1343 | 					    && cmptbl[i] != EP_NUL) | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1344 | 						cfg_found = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | 				} | 
 | 1346 | 				if (cfg_found) { | 
 | 1347 | 					if (cfg_used < small_match) { | 
 | 1348 | 						small_match = cfg_used; | 
 | 1349 | 						alt_used = | 
 | 1350 | 						    probe_alt_setting; | 
 | 1351 | 						iface_used = iface; | 
 | 1352 | 					} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | 				} | 
 | 1354 | 				cfg_used++; | 
 | 1355 | 			} | 
 | 1356 | 			alt_idx++; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1357 | 		} /* (alt_idx < intf->num_altsetting) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 |  | 
 | 1359 | 		/* found a valid USB Ta Endpint config */ | 
 | 1360 | 		if (small_match != 0xffff) { | 
 | 1361 | 			iface = iface_used; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1362 | 			if (!(context = kzalloc(sizeof(hfcusb_data), GFP_KERNEL))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | 				return (-ENOMEM);	/* got no mem */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 |  | 
 | 1365 | 			ep = iface->endpoint; | 
 | 1366 | 			vcf = validconf[small_match]; | 
 | 1367 |  | 
 | 1368 | 			for (i = 0; i < iface->desc.bNumEndpoints; i++) { | 
 | 1369 | 				ep_addr = ep->desc.bEndpointAddress; | 
 | 1370 | 				/* get endpoint base */ | 
 | 1371 | 				idx = ((ep_addr & 0x7f) - 1) * 2; | 
 | 1372 | 				if (ep_addr & 0x80) | 
 | 1373 | 					idx++; | 
 | 1374 | 				cidx = idx & 7; | 
 | 1375 | 				attr = ep->desc.bmAttributes; | 
 | 1376 |  | 
 | 1377 | 				/* init Endpoints */ | 
 | 1378 | 				if (vcf[idx] != EP_NOP | 
 | 1379 | 				    && vcf[idx] != EP_NUL) { | 
 | 1380 | 					switch (attr) { | 
 | 1381 | 						case USB_ENDPOINT_XFER_INT: | 
 | 1382 | 							context-> | 
 | 1383 | 							    fifos[cidx]. | 
 | 1384 | 							    pipe = | 
 | 1385 | 							    usb_rcvintpipe | 
 | 1386 | 							    (dev, | 
 | 1387 | 							     ep->desc. | 
 | 1388 | 							     bEndpointAddress); | 
 | 1389 | 							context-> | 
 | 1390 | 							    fifos[cidx]. | 
 | 1391 | 							    usb_transfer_mode | 
 | 1392 | 							    = USB_INT; | 
 | 1393 | 							packet_size = | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 1394 | 							    le16_to_cpu(ep->desc.wMaxPacketSize); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | 							break; | 
 | 1396 | 						case USB_ENDPOINT_XFER_BULK: | 
 | 1397 | 							if (ep_addr & 0x80) | 
 | 1398 | 								context-> | 
 | 1399 | 								    fifos | 
 | 1400 | 								    [cidx]. | 
 | 1401 | 								    pipe = | 
 | 1402 | 								    usb_rcvbulkpipe | 
 | 1403 | 								    (dev, | 
 | 1404 | 								     ep-> | 
 | 1405 | 								     desc. | 
 | 1406 | 								     bEndpointAddress); | 
 | 1407 | 							else | 
 | 1408 | 								context-> | 
 | 1409 | 								    fifos | 
 | 1410 | 								    [cidx]. | 
 | 1411 | 								    pipe = | 
 | 1412 | 								    usb_sndbulkpipe | 
 | 1413 | 								    (dev, | 
 | 1414 | 								     ep-> | 
 | 1415 | 								     desc. | 
 | 1416 | 								     bEndpointAddress); | 
 | 1417 | 							context-> | 
 | 1418 | 							    fifos[cidx]. | 
 | 1419 | 							    usb_transfer_mode | 
 | 1420 | 							    = USB_BULK; | 
 | 1421 | 							packet_size = | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 1422 | 							    le16_to_cpu(ep->desc.wMaxPacketSize); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | 							break; | 
 | 1424 | 						case USB_ENDPOINT_XFER_ISOC: | 
 | 1425 | 							if (ep_addr & 0x80) | 
 | 1426 | 								context-> | 
 | 1427 | 								    fifos | 
 | 1428 | 								    [cidx]. | 
 | 1429 | 								    pipe = | 
 | 1430 | 								    usb_rcvisocpipe | 
 | 1431 | 								    (dev, | 
 | 1432 | 								     ep-> | 
 | 1433 | 								     desc. | 
 | 1434 | 								     bEndpointAddress); | 
 | 1435 | 							else | 
 | 1436 | 								context-> | 
 | 1437 | 								    fifos | 
 | 1438 | 								    [cidx]. | 
 | 1439 | 								    pipe = | 
 | 1440 | 								    usb_sndisocpipe | 
 | 1441 | 								    (dev, | 
 | 1442 | 								     ep-> | 
 | 1443 | 								     desc. | 
 | 1444 | 								     bEndpointAddress); | 
 | 1445 | 							context-> | 
 | 1446 | 							    fifos[cidx]. | 
 | 1447 | 							    usb_transfer_mode | 
 | 1448 | 							    = USB_ISOC; | 
 | 1449 | 							iso_packet_size = | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 1450 | 							    le16_to_cpu(ep->desc.wMaxPacketSize); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | 							break; | 
 | 1452 | 						default: | 
 | 1453 | 							context-> | 
 | 1454 | 							    fifos[cidx]. | 
 | 1455 | 							    pipe = 0; | 
 | 1456 | 					}	/* switch attribute */ | 
 | 1457 |  | 
 | 1458 | 					if (context->fifos[cidx].pipe) { | 
 | 1459 | 						context->fifos[cidx]. | 
 | 1460 | 						    fifonum = cidx; | 
 | 1461 | 						context->fifos[cidx].hfc = | 
 | 1462 | 						    context; | 
| Karsten Keil | b05121b | 2006-03-06 15:42:41 -0800 | [diff] [blame] | 1463 | 						context->fifos[cidx].usb_packet_maxlen = | 
 | 1464 | 						    le16_to_cpu(ep->desc.wMaxPacketSize); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | 						context->fifos[cidx]. | 
 | 1466 | 						    intervall = | 
 | 1467 | 						    ep->desc.bInterval; | 
 | 1468 | 						context->fifos[cidx]. | 
 | 1469 | 						    skbuff = NULL; | 
 | 1470 | 					} | 
 | 1471 | 				} | 
 | 1472 | 				ep++; | 
 | 1473 | 			} | 
 | 1474 | 			context->dev = dev;	/* save device */ | 
 | 1475 | 			context->if_used = ifnum;	/* save used interface */ | 
 | 1476 | 			context->alt_used = alt_used;	/* and alternate config */ | 
 | 1477 | 			context->ctrl_paksize = dev->descriptor.bMaxPacketSize0;	/* control size */ | 
 | 1478 | 			context->cfg_used = vcf[16];	/* store used config */ | 
 | 1479 | 			context->vend_idx = vend_idx;	/* store found vendor */ | 
 | 1480 | 			context->packet_size = packet_size; | 
 | 1481 | 			context->iso_packet_size = iso_packet_size; | 
 | 1482 |  | 
 | 1483 | 			/* create the control pipes needed for register access */ | 
 | 1484 | 			context->ctrl_in_pipe = | 
 | 1485 | 			    usb_rcvctrlpipe(context->dev, 0); | 
 | 1486 | 			context->ctrl_out_pipe = | 
 | 1487 | 			    usb_sndctrlpipe(context->dev, 0); | 
 | 1488 | 			context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL); | 
 | 1489 |  | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 1490 | 			driver_info = | 
 | 1491 | 			    (hfcsusb_vdata *) hfcusb_idtab[vend_idx]. | 
 | 1492 | 			    driver_info; | 
 | 1493 | 			printk(KERN_INFO "HFC-S USB: detected \"%s\"\n", | 
 | 1494 | 			       driver_info->vend_name); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1495 |  | 
 | 1496 | 			DBG(HFCUSB_DBG_INIT, | 
 | 1497 | 			    "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d), E-Channel(%d)", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | 			    conf_str[small_match], context->if_used, | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1499 | 			    context->alt_used, | 
 | 1500 | 			    validconf[small_match][18]); | 
 | 1501 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | 			/* init the chip and register the driver */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1503 | 			if (hfc_usb_init(context)) { | 
| Alan Stern | ae2d990 | 2007-05-23 13:58:12 -0700 | [diff] [blame] | 1504 | 				usb_kill_urb(context->ctrl_urb); | 
 | 1505 | 				usb_free_urb(context->ctrl_urb); | 
 | 1506 | 				context->ctrl_urb = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | 				kfree(context); | 
 | 1508 | 				return (-EIO); | 
 | 1509 | 			} | 
 | 1510 | 			usb_set_intfdata(intf, context); | 
 | 1511 | 			return (0); | 
 | 1512 | 		} | 
 | 1513 | 	} else { | 
 | 1514 | 		printk(KERN_INFO | 
 | 1515 | 		       "HFC-S USB: no valid vendor found in USB descriptor\n"); | 
 | 1516 | 	} | 
 | 1517 | 	return (-EIO); | 
 | 1518 | } | 
 | 1519 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1520 | /* callback for unplugged USB device */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | static void | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 1522 | hfc_usb_disconnect(struct usb_interface *intf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | { | 
 | 1524 | 	hfcusb_data *context = usb_get_intfdata(intf); | 
 | 1525 | 	int i; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1526 |  | 
 | 1527 | 	handle_led(context, LED_POWER_OFF); | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 1528 | 	schedule_timeout(HZ / 100); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1529 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | 	printk(KERN_INFO "HFC-S USB: device disconnect\n"); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1531 | 	context->disc_flag = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | 	usb_set_intfdata(intf, NULL); | 
| Martin Bachem | 7441dd1 | 2007-10-14 18:10:30 +0200 | [diff] [blame] | 1533 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | 	if (timer_pending(&context->t3_timer)) | 
 | 1535 | 		del_timer(&context->t3_timer); | 
 | 1536 | 	if (timer_pending(&context->t4_timer)) | 
 | 1537 | 		del_timer(&context->t4_timer); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1538 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | 	/* tell all fifos to terminate */ | 
 | 1540 | 	for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { | 
 | 1541 | 		if (context->fifos[i].usb_transfer_mode == USB_ISOC) { | 
 | 1542 | 			if (context->fifos[i].active > 0) { | 
 | 1543 | 				stop_isoc_chain(&context->fifos[i]); | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1544 | 				DBG(HFCUSB_DBG_INIT, | 
 | 1545 | 				    "HFC-S USB: %s stopping ISOC chain Fifo(%i)", | 
| Harvey Harrison | 156f1ed | 2008-04-28 02:14:40 -0700 | [diff] [blame] | 1546 | 				    __func__, i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | 			} | 
 | 1548 | 		} else { | 
 | 1549 | 			if (context->fifos[i].active > 0) { | 
 | 1550 | 				context->fifos[i].active = 0; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1551 | 				DBG(HFCUSB_DBG_INIT, | 
 | 1552 | 				    "HFC-S USB: %s unlinking URB for Fifo(%i)", | 
| Harvey Harrison | 156f1ed | 2008-04-28 02:14:40 -0700 | [diff] [blame] | 1553 | 				    __func__, i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | 			} | 
| Alan Stern | ae2d990 | 2007-05-23 13:58:12 -0700 | [diff] [blame] | 1555 | 			usb_kill_urb(context->fifos[i].urb); | 
 | 1556 | 			usb_free_urb(context->fifos[i].urb); | 
 | 1557 | 			context->fifos[i].urb = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | 		} | 
 | 1559 | 		context->fifos[i].active = 0; | 
 | 1560 | 	} | 
| Alan Stern | ae2d990 | 2007-05-23 13:58:12 -0700 | [diff] [blame] | 1561 | 	usb_kill_urb(context->ctrl_urb); | 
 | 1562 | 	usb_free_urb(context->ctrl_urb); | 
 | 1563 | 	context->ctrl_urb = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | 	hisax_unregister(&context->d_if); | 
 | 1565 | 	kfree(context);		/* free our structure again */ | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1566 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | static struct usb_driver hfc_drv = { | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 1569 | 	.name  = "hfc_usb", | 
 | 1570 | 	.id_table = hfcusb_idtab, | 
 | 1571 | 	.probe = hfc_usb_probe, | 
 | 1572 | 	.disconnect = hfc_usb_disconnect, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | }; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1574 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | static void __exit | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1576 | hfc_usb_mod_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | { | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1578 | 	usb_deregister(&hfc_drv); /* release our driver */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | 	printk(KERN_INFO "HFC-S USB: module removed\n"); | 
 | 1580 | } | 
 | 1581 |  | 
 | 1582 | static int __init | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1583 | hfc_usb_mod_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | 	char revstr[30], datestr[30], dummy[30]; | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1586 | #ifndef CONFIG_HISAX_DEBUG | 
 | 1587 | 	hfc_debug = debug; | 
 | 1588 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | 	sscanf(hfcusb_revision, | 
 | 1590 | 	       "%s %s $ %s %s %s $ ", dummy, revstr, | 
 | 1591 | 	       dummy, datestr, dummy); | 
 | 1592 | 	printk(KERN_INFO | 
 | 1593 | 	       "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n", | 
 | 1594 | 	       revstr, datestr, debug); | 
 | 1595 | 	if (usb_register(&hfc_drv)) { | 
 | 1596 | 		printk(KERN_INFO | 
 | 1597 | 		       "HFC-S USB: Unable to register HFC-S USB module at usb stack\n"); | 
 | 1598 | 		return (-1);	/* unable to register */ | 
 | 1599 | 	} | 
 | 1600 | 	return (0); | 
 | 1601 | } | 
 | 1602 |  | 
| Martin Bachem | d6c59c1 | 2007-08-21 14:26:21 +0200 | [diff] [blame] | 1603 | module_init(hfc_usb_mod_init); | 
 | 1604 | module_exit(hfc_usb_mod_exit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | MODULE_AUTHOR(DRIVER_AUTHOR); | 
 | 1606 | MODULE_DESCRIPTION(DRIVER_DESC); | 
 | 1607 | MODULE_LICENSE("GPL"); | 
| Martin Bachem | 597a107 | 2005-11-07 01:00:20 -0800 | [diff] [blame] | 1608 | MODULE_DEVICE_TABLE(usb, hfcusb_idtab); |