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