aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/safe_serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/safe_serial.c')
-rw-r--r--drivers/usb/serial/safe_serial.c60
1 files changed, 26 insertions, 34 deletions
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 4e6dcc199be9..94bddf06ea4f 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -195,18 +195,17 @@ static __u16 __inline__ fcs_compute10 (unsigned char *sp, int len, __u16 fcs)
195 195
196static void safe_read_bulk_callback (struct urb *urb) 196static void safe_read_bulk_callback (struct urb *urb)
197{ 197{
198 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 198 struct usb_serial_port *port = urb->context;
199 unsigned char *data = urb->transfer_buffer; 199 unsigned char *data = urb->transfer_buffer;
200 unsigned char length = urb->actual_length; 200 unsigned char length = urb->actual_length;
201 int i;
202 int result; 201 int result;
203 int status = urb->status; 202 int status = urb->status;
204 203
205 dbg ("%s", __FUNCTION__); 204 dbg ("%s", __func__);
206 205
207 if (status) { 206 if (status) {
208 dbg("%s - nonzero read bulk status received: %d", 207 dbg("%s - nonzero read bulk status received: %d",
209 __FUNCTION__, status); 208 __func__, status);
210 return; 209 return;
211 } 210 }
212 211
@@ -227,28 +226,20 @@ static void safe_read_bulk_callback (struct urb *urb)
227 if (safe) { 226 if (safe) {
228 __u16 fcs; 227 __u16 fcs;
229 if (!(fcs = fcs_compute10 (data, length, CRC10_INITFCS))) { 228 if (!(fcs = fcs_compute10 (data, length, CRC10_INITFCS))) {
230
231 int actual_length = data[length - 2] >> 2; 229 int actual_length = data[length - 2] >> 2;
232
233 if (actual_length <= (length - 2)) { 230 if (actual_length <= (length - 2)) {
234 231 info ("%s - actual: %d", __func__, actual_length);
235 info ("%s - actual: %d", __FUNCTION__, actual_length); 232 tty_insert_flip_string(port->tty, data, actual_length);
236
237 for (i = 0; i < actual_length; i++) {
238 tty_insert_flip_char (port->tty, data[i], 0);
239 }
240 tty_flip_buffer_push (port->tty); 233 tty_flip_buffer_push (port->tty);
241 } else { 234 } else {
242 err ("%s - inconsistent lengths %d:%d", __FUNCTION__, 235 err ("%s - inconsistent lengths %d:%d", __func__,
243 actual_length, length); 236 actual_length, length);
244 } 237 }
245 } else { 238 } else {
246 err ("%s - bad CRC %x", __FUNCTION__, fcs); 239 err ("%s - bad CRC %x", __func__, fcs);
247 } 240 }
248 } else { 241 } else {
249 for (i = 0; i < length; i++) { 242 tty_insert_flip_string(port->tty, data, length);
250 tty_insert_flip_char (port->tty, data[i], 0);
251 }
252 tty_flip_buffer_push (port->tty); 243 tty_flip_buffer_push (port->tty);
253 } 244 }
254 245
@@ -259,7 +250,8 @@ static void safe_read_bulk_callback (struct urb *urb)
259 safe_read_bulk_callback, port); 250 safe_read_bulk_callback, port);
260 251
261 if ((result = usb_submit_urb (urb, GFP_ATOMIC))) { 252 if ((result = usb_submit_urb (urb, GFP_ATOMIC))) {
262 err ("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 253 err ("%s - failed resubmitting read urb, error %d", __func__, result);
254 /* FIXME: Need a mechanism to retry later if this happens */
263 } 255 }
264} 256}
265 257
@@ -274,25 +266,25 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
274 count); 266 count);
275 267
276 if (!port->write_urb) { 268 if (!port->write_urb) {
277 dbg ("%s - write urb NULL", __FUNCTION__); 269 dbg ("%s - write urb NULL", __func__);
278 return (0); 270 return 0;
279 } 271 }
280 272
281 dbg ("safe_write write_urb: %d transfer_buffer_length", 273 dbg ("safe_write write_urb: %d transfer_buffer_length",
282 port->write_urb->transfer_buffer_length); 274 port->write_urb->transfer_buffer_length);
283 275
284 if (!port->write_urb->transfer_buffer_length) { 276 if (!port->write_urb->transfer_buffer_length) {
285 dbg ("%s - write urb transfer_buffer_length zero", __FUNCTION__); 277 dbg ("%s - write urb transfer_buffer_length zero", __func__);
286 return (0); 278 return 0;
287 } 279 }
288 if (count == 0) { 280 if (count == 0) {
289 dbg ("%s - write request of 0 bytes", __FUNCTION__); 281 dbg ("%s - write request of 0 bytes", __func__);
290 return (0); 282 return 0;
291 } 283 }
292 spin_lock_bh(&port->lock); 284 spin_lock_bh(&port->lock);
293 if (port->write_urb_busy) { 285 if (port->write_urb_busy) {
294 spin_unlock_bh(&port->lock); 286 spin_unlock_bh(&port->lock);
295 dbg("%s - already writing", __FUNCTION__); 287 dbg("%s - already writing", __func__);
296 return 0; 288 return 0;
297 } 289 }
298 port->write_urb_busy = 1; 290 port->write_urb_busy = 1;
@@ -332,7 +324,7 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
332 port->write_urb->transfer_buffer_length = count; 324 port->write_urb->transfer_buffer_length = count;
333 } 325 }
334 326
335 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer); 327 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer);
336#ifdef ECHO_TX 328#ifdef ECHO_TX
337 { 329 {
338 int i; 330 int i;
@@ -349,28 +341,31 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
349 port->write_urb->dev = port->serial->dev; 341 port->write_urb->dev = port->serial->dev;
350 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { 342 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) {
351 port->write_urb_busy = 0; 343 port->write_urb_busy = 0;
352 err ("%s - failed submitting write urb, error %d", __FUNCTION__, result); 344 err ("%s - failed submitting write urb, error %d", __func__, result);
353 return 0; 345 return 0;
354 } 346 }
355 dbg ("%s urb: %p submitted", __FUNCTION__, port->write_urb); 347 dbg ("%s urb: %p submitted", __func__, port->write_urb);
356 348
357 return (count); 349 return (count);
358} 350}
359 351
360static int safe_write_room (struct usb_serial_port *port) 352static int safe_write_room (struct usb_serial_port *port)
361{ 353{
362 int room = 0; // Default: no room 354 int room = 0; /* Default: no room */
355 unsigned long flags;
363 356
364 dbg ("%s", __FUNCTION__); 357 dbg ("%s", __func__);
365 358
359 spin_lock_irqsave(&port->lock, flags);
366 if (port->write_urb_busy) 360 if (port->write_urb_busy)
367 room = port->bulk_out_size - (safe ? 2 : 0); 361 room = port->bulk_out_size - (safe ? 2 : 0);
362 spin_unlock_irqrestore(&port->lock, flags);
368 363
369 if (room) { 364 if (room) {
370 dbg ("safe_write_room returns %d", room); 365 dbg ("safe_write_room returns %d", room);
371 } 366 }
372 367
373 return (room); 368 return room;
374} 369}
375 370
376static int safe_startup (struct usb_serial *serial) 371static int safe_startup (struct usb_serial *serial)
@@ -394,9 +389,6 @@ static struct usb_serial_driver safe_device = {
394 }, 389 },
395 .id_table = id_table, 390 .id_table = id_table,
396 .usb_driver = &safe_driver, 391 .usb_driver = &safe_driver,
397 .num_interrupt_in = NUM_DONT_CARE,
398 .num_bulk_in = NUM_DONT_CARE,
399 .num_bulk_out = NUM_DONT_CARE,
400 .num_ports = 1, 392 .num_ports = 1,
401 .write = safe_write, 393 .write = safe_write,
402 .write_room = safe_write_room, 394 .write_room = safe_write_room,