USB: remove info() macro from usb mtd drivers
[deliverable/linux.git] / drivers / usb / serial / io_edgeport.c
CommitLineData
1da177e4
LT
1/*
2 * Edgeport USB Serial Converter driver
3 *
4 * Copyright (C) 2000 Inside Out Networks, All rights reserved.
5 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * Supports the following devices:
13 * Edgeport/4
14 * Edgeport/4t
15 * Edgeport/2
16 * Edgeport/4i
17 * Edgeport/2i
18 * Edgeport/421
19 * Edgeport/21
20 * Rapidport/4
21 * Edgeport/8
22 * Edgeport/2D8
23 * Edgeport/4D8
24 * Edgeport/8i
25 *
26 * For questions or problems with this driver, contact Inside Out
27 * Networks technical support, or Peter Berger <pberger@brimson.com>,
28 * or Al Borchers <alborchers@steinerpoint.com>.
29 *
1da177e4
LT
30 */
31
1da177e4
LT
32#include <linux/kernel.h>
33#include <linux/jiffies.h>
34#include <linux/errno.h>
35#include <linux/init.h>
36#include <linux/slab.h>
37#include <linux/tty.h>
38#include <linux/tty_driver.h>
39#include <linux/tty_flip.h>
40#include <linux/module.h>
41#include <linux/spinlock.h>
42#include <linux/serial.h>
43#include <linux/ioctl.h>
44#include <linux/wait.h>
5b9ea932
JS
45#include <linux/firmware.h>
46#include <linux/ihex.h>
03f0dbf7 47#include <linux/uaccess.h>
1da177e4 48#include <linux/usb.h>
a969888c 49#include <linux/usb/serial.h>
1da177e4
LT
50#include "io_edgeport.h"
51#include "io_ionsp.h" /* info for the iosp messages */
52#include "io_16654.h" /* 16654 UART defines */
53
54/*
55 * Version Information
56 */
57#define DRIVER_VERSION "v2.7"
58#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
59#define DRIVER_DESC "Edgeport USB Serial Driver"
60
1da177e4
LT
61#define MAX_NAME_LEN 64
62
63#define CHASE_TIMEOUT (5*HZ) /* 5 seconds */
64#define OPEN_TIMEOUT (5*HZ) /* 5 seconds */
65#define COMMAND_TIMEOUT (5*HZ) /* 5 seconds */
66
67/* receive port state */
68enum RXSTATE {
03f0dbf7
AC
69 EXPECT_HDR1 = 0, /* Expect header byte 1 */
70 EXPECT_HDR2 = 1, /* Expect header byte 2 */
71 EXPECT_DATA = 2, /* Expect 'RxBytesRemaining' data */
72 EXPECT_HDR3 = 3, /* Expect header byte 3 (for status hdrs only) */
1da177e4
LT
73};
74
75
03f0dbf7
AC
76/* Transmit Fifo
77 * This Transmit queue is an extension of the edgeport Rx buffer.
78 * The maximum amount of data buffered in both the edgeport
1da177e4
LT
79 * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits.
80 */
81struct TxFifo {
82 unsigned int head; /* index to head pointer (write) */
83 unsigned int tail; /* index to tail pointer (read) */
84 unsigned int count; /* Bytes in queue */
85 unsigned int size; /* Max size of queue (equal to Max number of TxCredits) */
86 unsigned char *fifo; /* allocated Buffer */
87};
88
89/* This structure holds all of the local port information */
90struct edgeport_port {
91 __u16 txCredits; /* our current credits for this port */
92 __u16 maxTxCredits; /* the max size of the port */
93
94 struct TxFifo txfifo; /* transmit fifo -- size will be maxTxCredits */
95 struct urb *write_urb; /* write URB for this port */
cb8eaa8b 96 bool write_in_progress; /* 'true' while a write URB is outstanding */
1da177e4
LT
97 spinlock_t ep_lock;
98
99 __u8 shadowLCR; /* last LCR value received */
100 __u8 shadowMCR; /* last MCR value received */
101 __u8 shadowMSR; /* last MSR value received */
102 __u8 shadowLSR; /* last LSR value received */
103 __u8 shadowXonChar; /* last value set as XON char in Edgeport */
104 __u8 shadowXoffChar; /* last value set as XOFF char in Edgeport */
105 __u8 validDataMask;
106 __u32 baudRate;
107
cb8eaa8b
RK
108 bool open;
109 bool openPending;
110 bool commandPending;
111 bool closePending;
112 bool chaseResponsePending;
1da177e4
LT
113
114 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
115 wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */
116 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
117 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
118
119 struct async_icount icount;
120 struct usb_serial_port *port; /* loop back to the owner of this object */
121};
122
123
124/* This structure holds all of the individual device information */
125struct edgeport_serial {
ad93375a 126 char name[MAX_NAME_LEN+2]; /* string name of this device */
1da177e4
LT
127
128 struct edge_manuf_descriptor manuf_descriptor; /* the manufacturer descriptor */
129 struct edge_boot_descriptor boot_descriptor; /* the boot firmware descriptor */
130 struct edgeport_product_info product_info; /* Product Info */
6e8cf775
GKH
131 struct edge_compatibility_descriptor epic_descriptor; /* Edgeport compatible descriptor */
132 int is_epic; /* flag if EPiC device or not */
1da177e4
LT
133
134 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */
03f0dbf7
AC
135 unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */
136 struct urb *interrupt_read_urb; /* our interrupt urb */
1da177e4
LT
137
138 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
03f0dbf7
AC
139 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
140 struct urb *read_urb; /* our bulk read urb */
cb8eaa8b 141 bool read_in_progress;
1da177e4
LT
142 spinlock_t es_lock;
143
144 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
145
146 __s16 rxBytesAvail; /* the number of bytes that we need to read from this device */
147
148 enum RXSTATE rxState; /* the current state of the bulk receive processor */
149 __u8 rxHeader1; /* receive header byte 1 */
150 __u8 rxHeader2; /* receive header byte 2 */
151 __u8 rxHeader3; /* receive header byte 3 */
152 __u8 rxPort; /* the port that we are currently receiving data for */
153 __u8 rxStatusCode; /* the receive status code */
154 __u8 rxStatusParam; /* the receive status paramater */
155 __s16 rxBytesRemaining; /* the number of port bytes left to read */
156 struct usb_serial *serial; /* loop back to the owner of this object */
157};
158
159/* baud rate information */
160struct divisor_table_entry {
161 __u32 BaudRate;
162 __u16 Divisor;
163};
164
03f0dbf7
AC
165/*
166 * Define table of divisors for Rev A EdgePort/4 hardware
167 * These assume a 3.6864MHz crystal, the standard /16, and
168 * MCR.7 = 0.
169 */
170
4c4c9432 171static const struct divisor_table_entry divisor_table[] = {
03f0dbf7
AC
172 { 50, 4608},
173 { 75, 3072},
174 { 110, 2095}, /* 2094.545455 => 230450 => .0217 % over */
175 { 134, 1713}, /* 1713.011152 => 230398.5 => .00065% under */
1da177e4
LT
176 { 150, 1536},
177 { 300, 768},
178 { 600, 384},
179 { 1200, 192},
180 { 1800, 128},
181 { 2400, 96},
182 { 4800, 48},
183 { 7200, 32},
184 { 9600, 24},
185 { 14400, 16},
186 { 19200, 12},
187 { 38400, 6},
188 { 57600, 4},
189 { 115200, 2},
190 { 230400, 1},
191};
192
193/* local variables */
194static int debug;
195
196static int low_latency = 1; /* tty low latency flag, on by default */
197
03f0dbf7 198static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */
1da177e4
LT
199
200
201/* local function prototypes */
202
203/* function prototypes for all URB callbacks */
03f0dbf7
AC
204static void edge_interrupt_callback(struct urb *urb);
205static void edge_bulk_in_callback(struct urb *urb);
206static void edge_bulk_out_data_callback(struct urb *urb);
207static void edge_bulk_out_cmd_callback(struct urb *urb);
1da177e4
LT
208
209/* function prototypes for the usbserial callbacks */
03f0dbf7
AC
210static int edge_open(struct tty_struct *tty, struct usb_serial_port *port,
211 struct file *filp);
212static void edge_close(struct tty_struct *tty, struct usb_serial_port *port,
213 struct file *filp);
214static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
215 const unsigned char *buf, int count);
216static int edge_write_room(struct tty_struct *tty);
217static int edge_chars_in_buffer(struct tty_struct *tty);
218static void edge_throttle(struct tty_struct *tty);
219static void edge_unthrottle(struct tty_struct *tty);
220static void edge_set_termios(struct tty_struct *tty,
221 struct usb_serial_port *port,
222 struct ktermios *old_termios);
223static int edge_ioctl(struct tty_struct *tty, struct file *file,
224 unsigned int cmd, unsigned long arg);
225static void edge_break(struct tty_struct *tty, int break_state);
226static int edge_tiocmget(struct tty_struct *tty, struct file *file);
227static int edge_tiocmset(struct tty_struct *tty, struct file *file,
228 unsigned int set, unsigned int clear);
229static int edge_startup(struct usb_serial *serial);
230static void edge_shutdown(struct usb_serial *serial);
1da177e4
LT
231
232#include "io_tables.h" /* all of the devices that this driver supports */
233
1da177e4 234/* function prototypes for all of our local functions */
03f0dbf7
AC
235
236static void process_rcvd_data(struct edgeport_serial *edge_serial,
237 unsigned char *buffer, __u16 bufferLength);
238static void process_rcvd_status(struct edgeport_serial *edge_serial,
239 __u8 byte2, __u8 byte3);
240static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
241 unsigned char *data, int length);
242static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr);
243static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
244 __u8 lsr, __u8 data);
245static int send_iosp_ext_cmd(struct edgeport_port *edge_port, __u8 command,
246 __u8 param);
247static int calc_baud_rate_divisor(int baud_rate, int *divisor);
248static int send_cmd_write_baud_rate(struct edgeport_port *edge_port,
249 int baudRate);
250static void change_port_settings(struct tty_struct *tty,
251 struct edgeport_port *edge_port,
252 struct ktermios *old_termios);
253static int send_cmd_write_uart_register(struct edgeport_port *edge_port,
254 __u8 regNum, __u8 regValue);
255static int write_cmd_usb(struct edgeport_port *edge_port,
256 unsigned char *buffer, int writeLength);
257static void send_more_port_data(struct edgeport_serial *edge_serial,
258 struct edgeport_port *edge_port);
259
260static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
261 __u16 length, const __u8 *data);
262static int rom_read(struct usb_serial *serial, __u16 extAddr, __u16 addr,
263 __u16 length, __u8 *data);
264static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
265 __u16 length, const __u8 *data);
266static void get_manufacturing_desc(struct edgeport_serial *edge_serial);
267static void get_boot_desc(struct edgeport_serial *edge_serial);
268static void load_application_firmware(struct edgeport_serial *edge_serial);
269
270static void unicode_to_ascii(char *string, int buflen,
271 __le16 *unicode, int unicode_size);
272
273
274/* ************************************************************************ */
275/* ************************************************************************ */
276/* ************************************************************************ */
277/* ************************************************************************ */
1da177e4
LT
278
279/************************************************************************
280 * *
281 * update_edgeport_E2PROM() Compare current versions of *
282 * Boot ROM and Manufacture *
283 * Descriptors with versions *
284 * embedded in this driver *
285 * *
286 ************************************************************************/
03f0dbf7 287static void update_edgeport_E2PROM(struct edgeport_serial *edge_serial)
1da177e4
LT
288{
289 __u32 BootCurVer;
290 __u32 BootNewVer;
5b9ea932
JS
291 __u8 BootMajorVersion;
292 __u8 BootMinorVersion;
293 __u16 BootBuildNumber;
294 __u32 Bootaddr;
295 const struct ihex_binrec *rec;
296 const struct firmware *fw;
297 const char *fw_name;
1da177e4
LT
298 int response;
299
1da177e4 300 switch (edge_serial->product_info.iDownloadFile) {
03f0dbf7
AC
301 case EDGE_DOWNLOAD_FILE_I930:
302 fw_name = "edgeport/boot.fw";
303 break;
304 case EDGE_DOWNLOAD_FILE_80251:
305 fw_name = "edgeport/boot2.fw";
306 break;
307 default:
308 return;
1da177e4
LT
309 }
310
5b9ea932
JS
311 response = request_ihex_firmware(&fw, fw_name,
312 &edge_serial->serial->dev->dev);
313 if (response) {
314 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
315 fw_name, response);
316 return;
317 }
318
319 rec = (const struct ihex_binrec *)fw->data;
320 BootMajorVersion = rec->data[0];
321 BootMinorVersion = rec->data[1];
322 BootBuildNumber = (rec->data[2] << 8) | rec->data[3];
323
03f0dbf7 324 /* Check Boot Image Version */
1da177e4
LT
325 BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) +
326 (edge_serial->boot_descriptor.MinorVersion << 16) +
327 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber);
328
329 BootNewVer = (BootMajorVersion << 24) +
330 (BootMinorVersion << 16) +
5b9ea932 331 BootBuildNumber;
1da177e4
LT
332
333 dbg("Current Boot Image version %d.%d.%d",
334 edge_serial->boot_descriptor.MajorVersion,
335 edge_serial->boot_descriptor.MinorVersion,
336 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber));
337
338
339 if (BootNewVer > BootCurVer) {
340 dbg("**Update Boot Image from %d.%d.%d to %d.%d.%d",
341 edge_serial->boot_descriptor.MajorVersion,
342 edge_serial->boot_descriptor.MinorVersion,
343 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber),
5b9ea932 344 BootMajorVersion, BootMinorVersion, BootBuildNumber);
1da177e4
LT
345
346 dbg("Downloading new Boot Image");
347
5b9ea932
JS
348 for (rec = ihex_next_binrec(rec); rec;
349 rec = ihex_next_binrec(rec)) {
350 Bootaddr = be32_to_cpu(rec->addr);
351 response = rom_write(edge_serial->serial,
352 Bootaddr >> 16,
353 Bootaddr & 0xFFFF,
354 be16_to_cpu(rec->len),
355 &rec->data[0]);
1da177e4 356 if (response < 0) {
5b9ea932
JS
357 dev_err(&edge_serial->serial->dev->dev,
358 "rom_write failed (%x, %x, %d)\n",
359 Bootaddr >> 16, Bootaddr & 0xFFFF,
360 be16_to_cpu(rec->len));
1da177e4
LT
361 break;
362 }
363 }
364 } else {
365 dbg("Boot Image -- already up to date");
366 }
5b9ea932 367 release_firmware(fw);
1da177e4
LT
368}
369
370
371/************************************************************************
372 * *
373 * Get string descriptor from device *
374 * *
375 ************************************************************************/
03f0dbf7 376static int get_string(struct usb_device *dev, int Id, char *string, int buflen)
1da177e4
LT
377{
378 struct usb_string_descriptor StringDesc;
379 struct usb_string_descriptor *pStringDesc;
380
03f0dbf7 381 dbg("%s - USB String ID = %d", __func__, Id);
1da177e4 382
03f0dbf7
AC
383 if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
384 &StringDesc, sizeof(StringDesc)))
1da177e4 385 return 0;
1da177e4 386
03f0dbf7
AC
387 pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL);
388 if (!pStringDesc)
1da177e4 389 return 0;
1da177e4 390
03f0dbf7
AC
391 if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
392 pStringDesc, StringDesc.bLength)) {
1da177e4
LT
393 kfree(pStringDesc);
394 return 0;
395 }
396
03f0dbf7
AC
397 unicode_to_ascii(string, buflen,
398 pStringDesc->wData, pStringDesc->bLength/2);
1da177e4
LT
399
400 kfree(pStringDesc);
441b62c1 401 dbg("%s - USB String %s", __func__, string);
1da177e4
LT
402 return strlen(string);
403}
404
405
406#if 0
407/************************************************************************
408 *
409 * Get string descriptor from device
410 *
411 ************************************************************************/
03f0dbf7
AC
412static int get_string_desc(struct usb_device *dev, int Id,
413 struct usb_string_descriptor **pRetDesc)
1da177e4
LT
414{
415 struct usb_string_descriptor StringDesc;
416 struct usb_string_descriptor *pStringDesc;
417
03f0dbf7 418 dbg("%s - USB String ID = %d", __func__, Id);
1da177e4 419
03f0dbf7
AC
420 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc,
421 sizeof(StringDesc)))
1da177e4 422 return 0;
1da177e4 423
03f0dbf7
AC
424 pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL);
425 if (!pStringDesc)
1da177e4 426 return -1;
1da177e4 427
03f0dbf7
AC
428 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc,
429 StringDesc.bLength)) {
1da177e4
LT
430 kfree(pStringDesc);
431 return -1;
432 }
433
434 *pRetDesc = pStringDesc;
435 return 0;
436}
437#endif
438
6e8cf775
GKH
439static void dump_product_info(struct edgeport_product_info *product_info)
440{
03f0dbf7 441 /* Dump Product Info structure */
6e8cf775 442 dbg("**Product Information:");
03f0dbf7
AC
443 dbg(" ProductId %x", product_info->ProductId);
444 dbg(" NumPorts %d", product_info->NumPorts);
445 dbg(" ProdInfoVer %d", product_info->ProdInfoVer);
6e8cf775 446 dbg(" IsServer %d", product_info->IsServer);
03f0dbf7
AC
447 dbg(" IsRS232 %d", product_info->IsRS232);
448 dbg(" IsRS422 %d", product_info->IsRS422);
449 dbg(" IsRS485 %d", product_info->IsRS485);
450 dbg(" RomSize %d", product_info->RomSize);
451 dbg(" RamSize %d", product_info->RamSize);
452 dbg(" CpuRev %x", product_info->CpuRev);
6e8cf775
GKH
453 dbg(" BoardRev %x", product_info->BoardRev);
454 dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion,
455 product_info->BootMinorVersion,
456 le16_to_cpu(product_info->BootBuildNumber));
03f0dbf7
AC
457 dbg(" FirmwareMajorVersion %d.%d.%d",
458 product_info->FirmwareMajorVersion,
459 product_info->FirmwareMinorVersion,
460 le16_to_cpu(product_info->FirmwareBuildNumber));
461 dbg(" ManufactureDescDate %d/%d/%d",
462 product_info->ManufactureDescDate[0],
463 product_info->ManufactureDescDate[1],
464 product_info->ManufactureDescDate[2]+1900);
6e8cf775
GKH
465 dbg(" iDownloadFile 0x%x", product_info->iDownloadFile);
466 dbg(" EpicVer %d", product_info->EpicVer);
467}
468
1da177e4
LT
469static void get_product_info(struct edgeport_serial *edge_serial)
470{
471 struct edgeport_product_info *product_info = &edge_serial->product_info;
472
03f0dbf7
AC
473 memset(product_info, 0, sizeof(struct edgeport_product_info));
474
475 product_info->ProductId = (__u16)(le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ~ION_DEVICE_ID_80251_NETCHIP);
476 product_info->NumPorts = edge_serial->manuf_descriptor.NumPorts;
477 product_info->ProdInfoVer = 0;
478
479 product_info->RomSize = edge_serial->manuf_descriptor.RomSize;
480 product_info->RamSize = edge_serial->manuf_descriptor.RamSize;
481 product_info->CpuRev = edge_serial->manuf_descriptor.CpuRev;
482 product_info->BoardRev = edge_serial->manuf_descriptor.BoardRev;
483
484 product_info->BootMajorVersion =
485 edge_serial->boot_descriptor.MajorVersion;
486 product_info->BootMinorVersion =
487 edge_serial->boot_descriptor.MinorVersion;
488 product_info->BootBuildNumber =
489 edge_serial->boot_descriptor.BuildNumber;
490
491 memcpy(product_info->ManufactureDescDate,
492 edge_serial->manuf_descriptor.DescDate,
493 sizeof(edge_serial->manuf_descriptor.DescDate));
494
495 /* check if this is 2nd generation hardware */
496 if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct)
497 & ION_DEVICE_ID_80251_NETCHIP)
498 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251;
499 else
500 product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930;
501
502 /* Determine Product type and set appropriate flags */
1da177e4 503 switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) {
03f0dbf7
AC
504 case ION_DEVICE_ID_EDGEPORT_COMPATIBLE:
505 case ION_DEVICE_ID_EDGEPORT_4T:
506 case ION_DEVICE_ID_EDGEPORT_4:
507 case ION_DEVICE_ID_EDGEPORT_2:
508 case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU:
509 case ION_DEVICE_ID_EDGEPORT_8:
510 case ION_DEVICE_ID_EDGEPORT_421:
511 case ION_DEVICE_ID_EDGEPORT_21:
512 case ION_DEVICE_ID_EDGEPORT_2_DIN:
513 case ION_DEVICE_ID_EDGEPORT_4_DIN:
514 case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU:
515 product_info->IsRS232 = 1;
516 break;
1da177e4 517
03f0dbf7
AC
518 case ION_DEVICE_ID_EDGEPORT_2I: /* Edgeport/2 RS422/RS485 */
519 product_info->IsRS422 = 1;
520 product_info->IsRS485 = 1;
521 break;
1da177e4 522
03f0dbf7
AC
523 case ION_DEVICE_ID_EDGEPORT_8I: /* Edgeport/4 RS422 */
524 case ION_DEVICE_ID_EDGEPORT_4I: /* Edgeport/4 RS422 */
525 product_info->IsRS422 = 1;
526 break;
1da177e4
LT
527 }
528
6e8cf775
GKH
529 dump_product_info(product_info);
530}
1da177e4 531
6e8cf775
GKH
532static int get_epic_descriptor(struct edgeport_serial *ep)
533{
534 int result;
535 struct usb_serial *serial = ep->serial;
536 struct edgeport_product_info *product_info = &ep->product_info;
537 struct edge_compatibility_descriptor *epic = &ep->epic_descriptor;
538 struct edge_compatibility_bits *bits;
539
540 ep->is_epic = 0;
541 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
542 USB_REQUEST_ION_GET_EPIC_DESC,
543 0xC0, 0x00, 0x00,
544 &ep->epic_descriptor,
545 sizeof(struct edge_compatibility_descriptor),
546 300);
547
441b62c1 548 dbg("%s result = %d", __func__, result);
6e8cf775
GKH
549
550 if (result > 0) {
551 ep->is_epic = 1;
552 memset(product_info, 0, sizeof(struct edgeport_product_info));
553
03f0dbf7
AC
554 product_info->NumPorts = epic->NumPorts;
555 product_info->ProdInfoVer = 0;
556 product_info->FirmwareMajorVersion = epic->MajorVersion;
557 product_info->FirmwareMinorVersion = epic->MinorVersion;
558 product_info->FirmwareBuildNumber = epic->BuildNumber;
559 product_info->iDownloadFile = epic->iDownloadFile;
560 product_info->EpicVer = epic->EpicVer;
561 product_info->Epic = epic->Supports;
562 product_info->ProductId = ION_DEVICE_ID_EDGEPORT_COMPATIBLE;
6e8cf775
GKH
563 dump_product_info(product_info);
564
565 bits = &ep->epic_descriptor.Supports;
566 dbg("**EPIC descriptor:");
567 dbg(" VendEnableSuspend: %s", bits->VendEnableSuspend ? "TRUE": "FALSE");
03f0dbf7
AC
568 dbg(" IOSPOpen : %s", bits->IOSPOpen ? "TRUE": "FALSE");
569 dbg(" IOSPClose : %s", bits->IOSPClose ? "TRUE": "FALSE");
570 dbg(" IOSPChase : %s", bits->IOSPChase ? "TRUE": "FALSE");
571 dbg(" IOSPSetRxFlow : %s", bits->IOSPSetRxFlow ? "TRUE": "FALSE");
572 dbg(" IOSPSetTxFlow : %s", bits->IOSPSetTxFlow ? "TRUE": "FALSE");
573 dbg(" IOSPSetXChar : %s", bits->IOSPSetXChar ? "TRUE": "FALSE");
574 dbg(" IOSPRxCheck : %s", bits->IOSPRxCheck ? "TRUE": "FALSE");
575 dbg(" IOSPSetClrBreak : %s", bits->IOSPSetClrBreak ? "TRUE": "FALSE");
576 dbg(" IOSPWriteMCR : %s", bits->IOSPWriteMCR ? "TRUE": "FALSE");
577 dbg(" IOSPWriteLCR : %s", bits->IOSPWriteLCR ? "TRUE": "FALSE");
578 dbg(" IOSPSetBaudRate : %s", bits->IOSPSetBaudRate ? "TRUE": "FALSE");
579 dbg(" TrueEdgeport : %s", bits->TrueEdgeport ? "TRUE": "FALSE");
6e8cf775
GKH
580 }
581
582 return result;
1da177e4
LT
583}
584
585
586/************************************************************************/
587/************************************************************************/
588/* U S B C A L L B A C K F U N C T I O N S */
589/* U S B C A L L B A C K F U N C T I O N S */
590/************************************************************************/
591/************************************************************************/
592
593/*****************************************************************************
594 * edge_interrupt_callback
03f0dbf7 595 * this is the callback function for when we have received data on the
1da177e4
LT
596 * interrupt endpoint.
597 *****************************************************************************/
03f0dbf7 598static void edge_interrupt_callback(struct urb *urb)
1da177e4 599{
cdc97792 600 struct edgeport_serial *edge_serial = urb->context;
1da177e4
LT
601 struct edgeport_port *edge_port;
602 struct usb_serial_port *port;
4a90f09b 603 struct tty_struct *tty;
1da177e4
LT
604 unsigned char *data = urb->transfer_buffer;
605 int length = urb->actual_length;
606 int bytes_avail;
607 int position;
608 int txCredits;
609 int portNumber;
610 int result;
2a393f5f 611 int status = urb->status;
1da177e4 612
441b62c1 613 dbg("%s", __func__);
1da177e4 614
2a393f5f 615 switch (status) {
1da177e4
LT
616 case 0:
617 /* success */
618 break;
619 case -ECONNRESET:
620 case -ENOENT:
621 case -ESHUTDOWN:
622 /* this urb is terminated, clean up */
2a393f5f 623 dbg("%s - urb shutting down with status: %d",
03f0dbf7 624 __func__, status);
1da177e4
LT
625 return;
626 default:
03f0dbf7 627 dbg("%s - nonzero urb status received: %d", __func__, status);
1da177e4
LT
628 goto exit;
629 }
630
03f0dbf7 631 /* process this interrupt-read even if there are no ports open */
1da177e4 632 if (length) {
03f0dbf7
AC
633 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
634 __func__, length, data);
1da177e4
LT
635
636 if (length > 1) {
637 bytes_avail = data[0] | (data[1] << 8);
638 if (bytes_avail) {
639 spin_lock(&edge_serial->es_lock);
640 edge_serial->rxBytesAvail += bytes_avail;
441b62c1 641 dbg("%s - bytes_avail=%d, rxBytesAvail=%d, read_in_progress=%d", __func__, bytes_avail, edge_serial->rxBytesAvail, edge_serial->read_in_progress);
1da177e4
LT
642
643 if (edge_serial->rxBytesAvail > 0 &&
644 !edge_serial->read_in_progress) {
441b62c1 645 dbg("%s - posting a read", __func__);
cb8eaa8b 646 edge_serial->read_in_progress = true;
1da177e4 647
03f0dbf7
AC
648 /* we have pending bytes on the
649 bulk in pipe, send a request */
1da177e4
LT
650 edge_serial->read_urb->dev = edge_serial->serial->dev;
651 result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
652 if (result) {
441b62c1 653 dev_err(&edge_serial->serial->dev->dev, "%s - usb_submit_urb(read bulk) failed with result = %d\n", __func__, result);
cb8eaa8b 654 edge_serial->read_in_progress = false;
1da177e4
LT
655 }
656 }
657 spin_unlock(&edge_serial->es_lock);
658 }
659 }
660 /* grab the txcredits for the ports if available */
661 position = 2;
662 portNumber = 0;
03f0dbf7
AC
663 while ((position < length) &&
664 (portNumber < edge_serial->serial->num_ports)) {
1da177e4
LT
665 txCredits = data[position] | (data[position+1] << 8);
666 if (txCredits) {
667 port = edge_serial->serial->port[portNumber];
668 edge_port = usb_get_serial_port_data(port);
669 if (edge_port->open) {
670 spin_lock(&edge_port->ep_lock);
671 edge_port->txCredits += txCredits;
672 spin_unlock(&edge_port->ep_lock);
03f0dbf7
AC
673 dbg("%s - txcredits for port%d = %d",
674 __func__, portNumber,
675 edge_port->txCredits);
1da177e4 676
03f0dbf7
AC
677 /* tell the tty driver that something
678 has changed */
4a90f09b
AC
679 tty = tty_port_tty_get(
680 &edge_port->port->port);
681 if (tty) {
682 tty_wakeup(tty);
683 tty_kref_put(tty);
684 }
03f0dbf7
AC
685 /* Since we have more credit, check
686 if more data can be sent */
687 send_more_port_data(edge_serial,
688 edge_port);
1da177e4
LT
689 }
690 }
691 position += 2;
692 ++portNumber;
693 }
694 }
695
696exit:
03f0dbf7
AC
697 result = usb_submit_urb(urb, GFP_ATOMIC);
698 if (result)
699 dev_err(&urb->dev->dev,
700 "%s - Error %d submitting control urb\n",
701 __func__, result);
1da177e4
LT
702}
703
704
705/*****************************************************************************
706 * edge_bulk_in_callback
03f0dbf7 707 * this is the callback function for when we have received data on the
1da177e4
LT
708 * bulk in endpoint.
709 *****************************************************************************/
03f0dbf7 710static void edge_bulk_in_callback(struct urb *urb)
1da177e4 711{
cdc97792 712 struct edgeport_serial *edge_serial = urb->context;
1da177e4 713 unsigned char *data = urb->transfer_buffer;
2a393f5f 714 int retval;
1da177e4 715 __u16 raw_data_length;
2a393f5f 716 int status = urb->status;
1da177e4 717
441b62c1 718 dbg("%s", __func__);
1da177e4 719
2a393f5f
GKH
720 if (status) {
721 dbg("%s - nonzero read bulk status received: %d",
441b62c1 722 __func__, status);
cb8eaa8b 723 edge_serial->read_in_progress = false;
1da177e4
LT
724 return;
725 }
726
727 if (urb->actual_length == 0) {
441b62c1 728 dbg("%s - read bulk callback with no data", __func__);
cb8eaa8b 729 edge_serial->read_in_progress = false;
1da177e4
LT
730 return;
731 }
732
733 raw_data_length = urb->actual_length;
734
03f0dbf7
AC
735 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
736 __func__, raw_data_length, data);
1da177e4
LT
737
738 spin_lock(&edge_serial->es_lock);
739
740 /* decrement our rxBytes available by the number that we just got */
741 edge_serial->rxBytesAvail -= raw_data_length;
742
03f0dbf7
AC
743 dbg("%s - Received = %d, rxBytesAvail %d", __func__,
744 raw_data_length, edge_serial->rxBytesAvail);
1da177e4 745
03f0dbf7 746 process_rcvd_data(edge_serial, data, urb->actual_length);
1da177e4
LT
747
748 /* check to see if there's any more data for us to read */
749 if (edge_serial->rxBytesAvail > 0) {
441b62c1 750 dbg("%s - posting a read", __func__);
1da177e4 751 edge_serial->read_urb->dev = edge_serial->serial->dev;
2a393f5f
GKH
752 retval = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
753 if (retval) {
754 dev_err(&urb->dev->dev,
755 "%s - usb_submit_urb(read bulk) failed, "
441b62c1 756 "retval = %d\n", __func__, retval);
cb8eaa8b 757 edge_serial->read_in_progress = false;
1da177e4
LT
758 }
759 } else {
cb8eaa8b 760 edge_serial->read_in_progress = false;
1da177e4
LT
761 }
762
763 spin_unlock(&edge_serial->es_lock);
764}
765
766
767/*****************************************************************************
768 * edge_bulk_out_data_callback
03f0dbf7
AC
769 * this is the callback function for when we have finished sending
770 * serial data on the bulk out endpoint.
1da177e4 771 *****************************************************************************/
03f0dbf7 772static void edge_bulk_out_data_callback(struct urb *urb)
1da177e4 773{
cdc97792 774 struct edgeport_port *edge_port = urb->context;
1da177e4 775 struct tty_struct *tty;
2a393f5f 776 int status = urb->status;
1da177e4 777
441b62c1 778 dbg("%s", __func__);
1da177e4 779
2a393f5f
GKH
780 if (status) {
781 dbg("%s - nonzero write bulk status received: %d",
441b62c1 782 __func__, status);
1da177e4
LT
783 }
784
4a90f09b 785 tty = tty_port_tty_get(&edge_port->port->port);
1da177e4
LT
786
787 if (tty && edge_port->open) {
03f0dbf7
AC
788 /* let the tty driver wakeup if it has a special
789 write_wakeup function */
1da177e4
LT
790 tty_wakeup(tty);
791 }
4a90f09b 792 tty_kref_put(tty);
1da177e4 793
03f0dbf7 794 /* Release the Write URB */
cb8eaa8b 795 edge_port->write_in_progress = false;
1da177e4 796
03f0dbf7
AC
797 /* Check if more data needs to be sent */
798 send_more_port_data((struct edgeport_serial *)
799 (usb_get_serial_data(edge_port->port->serial)), edge_port);
1da177e4
LT
800}
801
802
803/*****************************************************************************
804 * BulkOutCmdCallback
03f0dbf7
AC
805 * this is the callback function for when we have finished sending a
806 * command on the bulk out endpoint.
1da177e4 807 *****************************************************************************/
03f0dbf7 808static void edge_bulk_out_cmd_callback(struct urb *urb)
1da177e4 809{
cdc97792 810 struct edgeport_port *edge_port = urb->context;
1da177e4
LT
811 struct tty_struct *tty;
812 int status = urb->status;
813
441b62c1 814 dbg("%s", __func__);
1da177e4 815
96c706ed 816 atomic_dec(&CmdUrbs);
03f0dbf7
AC
817 dbg("%s - FREE URB %p (outstanding %d)", __func__,
818 urb, atomic_read(&CmdUrbs));
1da177e4
LT
819
820
821 /* clean up the transfer buffer */
1bc3c9e1 822 kfree(urb->transfer_buffer);
1da177e4
LT
823
824 /* Free the command urb */
03f0dbf7 825 usb_free_urb(urb);
1da177e4
LT
826
827 if (status) {
03f0dbf7
AC
828 dbg("%s - nonzero write bulk status received: %d",
829 __func__, status);
1da177e4
LT
830 return;
831 }
832
833 /* Get pointer to tty */
4a90f09b 834 tty = tty_port_tty_get(&edge_port->port->port);
1da177e4
LT
835
836 /* tell the tty driver that something has changed */
837 if (tty && edge_port->open)
838 tty_wakeup(tty);
4a90f09b 839 tty_kref_put(tty);
1da177e4
LT
840
841 /* we have completed the command */
cb8eaa8b 842 edge_port->commandPending = false;
1da177e4
LT
843 wake_up(&edge_port->wait_command);
844}
845
846
847/*****************************************************************************
848 * Driver tty interface functions
849 *****************************************************************************/
850
851/*****************************************************************************
852 * SerialOpen
853 * this function is called by the tty driver when a port is opened
854 * If successful, we return 0
855 * Otherwise we return a negative error number.
856 *****************************************************************************/
95da310e 857static int edge_open(struct tty_struct *tty,
03f0dbf7 858 struct usb_serial_port *port, struct file *filp)
1da177e4
LT
859{
860 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
861 struct usb_serial *serial;
862 struct edgeport_serial *edge_serial;
863 int response;
864
441b62c1 865 dbg("%s - port %d", __func__, port->number);
1da177e4
LT
866
867 if (edge_port == NULL)
868 return -ENODEV;
869
95da310e
AC
870 if (tty)
871 tty->low_latency = low_latency;
1da177e4 872
03f0dbf7
AC
873 /* see if we've set up our endpoint info yet (can't set it up
874 in edge_startup as the structures were not set up at that time.) */
1da177e4
LT
875 serial = port->serial;
876 edge_serial = usb_get_serial_data(serial);
95da310e 877 if (edge_serial == NULL)
1da177e4 878 return -ENODEV;
1da177e4
LT
879 if (edge_serial->interrupt_in_buffer == NULL) {
880 struct usb_serial_port *port0 = serial->port[0];
03f0dbf7 881
1da177e4 882 /* not set up yet, so do it now */
03f0dbf7
AC
883 edge_serial->interrupt_in_buffer =
884 port0->interrupt_in_buffer;
885 edge_serial->interrupt_in_endpoint =
886 port0->interrupt_in_endpointAddress;
1da177e4
LT
887 edge_serial->interrupt_read_urb = port0->interrupt_in_urb;
888 edge_serial->bulk_in_buffer = port0->bulk_in_buffer;
03f0dbf7
AC
889 edge_serial->bulk_in_endpoint =
890 port0->bulk_in_endpointAddress;
1da177e4 891 edge_serial->read_urb = port0->read_urb;
03f0dbf7
AC
892 edge_serial->bulk_out_endpoint =
893 port0->bulk_out_endpointAddress;
894
1da177e4
LT
895 /* set up our interrupt urb */
896 usb_fill_int_urb(edge_serial->interrupt_read_urb,
03f0dbf7
AC
897 serial->dev,
898 usb_rcvintpipe(serial->dev,
899 port0->interrupt_in_endpointAddress),
900 port0->interrupt_in_buffer,
901 edge_serial->interrupt_read_urb->transfer_buffer_length,
902 edge_interrupt_callback, edge_serial,
903 edge_serial->interrupt_read_urb->interval);
904
1da177e4
LT
905 /* set up our bulk in urb */
906 usb_fill_bulk_urb(edge_serial->read_urb, serial->dev,
03f0dbf7
AC
907 usb_rcvbulkpipe(serial->dev,
908 port0->bulk_in_endpointAddress),
909 port0->bulk_in_buffer,
910 edge_serial->read_urb->transfer_buffer_length,
911 edge_bulk_in_callback, edge_serial);
cb8eaa8b 912 edge_serial->read_in_progress = false;
1da177e4
LT
913
914 /* start interrupt read for this edgeport
03f0dbf7
AC
915 * this interrupt will continue as long
916 * as the edgeport is connected */
917 response = usb_submit_urb(edge_serial->interrupt_read_urb,
918 GFP_KERNEL);
1da177e4 919 if (response) {
03f0dbf7
AC
920 dev_err(&port->dev,
921 "%s - Error %d submitting control urb\n",
922 __func__, response);
1da177e4
LT
923 }
924 }
03f0dbf7 925
1da177e4
LT
926 /* initialize our wait queues */
927 init_waitqueue_head(&edge_port->wait_open);
928 init_waitqueue_head(&edge_port->wait_chase);
929 init_waitqueue_head(&edge_port->delta_msr_wait);
930 init_waitqueue_head(&edge_port->wait_command);
931
932 /* initialize our icount structure */
03f0dbf7 933 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1da177e4
LT
934
935 /* initialize our port settings */
03f0dbf7
AC
936 edge_port->txCredits = 0; /* Can't send any data yet */
937 /* Must always set this bit to enable ints! */
938 edge_port->shadowMCR = MCR_MASTER_IE;
cb8eaa8b 939 edge_port->chaseResponsePending = false;
1da177e4
LT
940
941 /* send a open port command */
cb8eaa8b
RK
942 edge_port->openPending = true;
943 edge_port->open = false;
03f0dbf7 944 response = send_iosp_ext_cmd(edge_port, IOSP_CMD_OPEN_PORT, 0);
1da177e4
LT
945
946 if (response < 0) {
03f0dbf7
AC
947 dev_err(&port->dev, "%s - error sending open port command\n",
948 __func__);
cb8eaa8b 949 edge_port->openPending = false;
1da177e4
LT
950 return -ENODEV;
951 }
952
953 /* now wait for the port to be completely opened */
03f0dbf7
AC
954 wait_event_timeout(edge_port->wait_open, !edge_port->openPending,
955 OPEN_TIMEOUT);
1da177e4 956
cb8eaa8b 957 if (!edge_port->open) {
1da177e4 958 /* open timed out */
441b62c1 959 dbg("%s - open timedout", __func__);
cb8eaa8b 960 edge_port->openPending = false;
1da177e4
LT
961 return -ENODEV;
962 }
963
964 /* create the txfifo */
965 edge_port->txfifo.head = 0;
966 edge_port->txfifo.tail = 0;
967 edge_port->txfifo.count = 0;
968 edge_port->txfifo.size = edge_port->maxTxCredits;
03f0dbf7 969 edge_port->txfifo.fifo = kmalloc(edge_port->maxTxCredits, GFP_KERNEL);
1da177e4
LT
970
971 if (!edge_port->txfifo.fifo) {
441b62c1 972 dbg("%s - no memory", __func__);
03f0dbf7 973 edge_close(tty, port, filp);
1da177e4
LT
974 return -ENOMEM;
975 }
976
977 /* Allocate a URB for the write */
03f0dbf7 978 edge_port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
cb8eaa8b 979 edge_port->write_in_progress = false;
1da177e4
LT
980
981 if (!edge_port->write_urb) {
441b62c1 982 dbg("%s - no memory", __func__);
03f0dbf7 983 edge_close(tty, port, filp);
1da177e4
LT
984 return -ENOMEM;
985 }
986
03f0dbf7
AC
987 dbg("%s(%d) - Initialize TX fifo to %d bytes",
988 __func__, port->number, edge_port->maxTxCredits);
1da177e4 989
441b62c1 990 dbg("%s exited", __func__);
1da177e4
LT
991
992 return 0;
993}
994
995
996/************************************************************************
997 *
998 * block_until_chase_response
999 *
1000 * This function will block the close until one of the following:
1001 * 1. Response to our Chase comes from Edgeport
dc0d5c1e 1002 * 2. A timeout of 10 seconds without activity has expired
1da177e4
LT
1003 * (1K of Edgeport data @ 2400 baud ==> 4 sec to empty)
1004 *
1005 ************************************************************************/
1006static void block_until_chase_response(struct edgeport_port *edge_port)
1007{
1008 DEFINE_WAIT(wait);
1009 __u16 lastCredits;
1010 int timeout = 1*HZ;
1011 int loop = 10;
1012
1013 while (1) {
03f0dbf7 1014 /* Save Last credits */
1da177e4
LT
1015 lastCredits = edge_port->txCredits;
1016
03f0dbf7 1017 /* Did we get our Chase response */
cb8eaa8b 1018 if (!edge_port->chaseResponsePending) {
441b62c1 1019 dbg("%s - Got Chase Response", __func__);
1da177e4 1020
03f0dbf7
AC
1021 /* did we get all of our credit back? */
1022 if (edge_port->txCredits == edge_port->maxTxCredits) {
441b62c1 1023 dbg("%s - Got all credits", __func__);
1da177e4
LT
1024 return;
1025 }
1026 }
1027
03f0dbf7
AC
1028 /* Block the thread for a while */
1029 prepare_to_wait(&edge_port->wait_chase, &wait,
1030 TASK_UNINTERRUPTIBLE);
1da177e4
LT
1031 schedule_timeout(timeout);
1032 finish_wait(&edge_port->wait_chase, &wait);
1033
1034 if (lastCredits == edge_port->txCredits) {
03f0dbf7 1035 /* No activity.. count down. */
1da177e4
LT
1036 loop--;
1037 if (loop == 0) {
cb8eaa8b 1038 edge_port->chaseResponsePending = false;
441b62c1 1039 dbg("%s - Chase TIMEOUT", __func__);
1da177e4
LT
1040 return;
1041 }
1042 } else {
03f0dbf7
AC
1043 /* Reset timeout value back to 10 seconds */
1044 dbg("%s - Last %d, Current %d", __func__,
1045 lastCredits, edge_port->txCredits);
1da177e4
LT
1046 loop = 10;
1047 }
1048 }
1049}
1050
1051
1052/************************************************************************
1053 *
1054 * block_until_tx_empty
1055 *
1056 * This function will block the close until one of the following:
1057 * 1. TX count are 0
1058 * 2. The edgeport has stopped
dc0d5c1e 1059 * 3. A timeout of 3 seconds without activity has expired
1da177e4
LT
1060 *
1061 ************************************************************************/
03f0dbf7 1062static void block_until_tx_empty(struct edgeport_port *edge_port)
1da177e4
LT
1063{
1064 DEFINE_WAIT(wait);
1065 struct TxFifo *fifo = &edge_port->txfifo;
1066 __u32 lastCount;
1067 int timeout = HZ/10;
1068 int loop = 30;
1069
1070 while (1) {
03f0dbf7 1071 /* Save Last count */
1da177e4
LT
1072 lastCount = fifo->count;
1073
03f0dbf7 1074 /* Is the Edgeport Buffer empty? */
1da177e4 1075 if (lastCount == 0) {
441b62c1 1076 dbg("%s - TX Buffer Empty", __func__);
1da177e4
LT
1077 return;
1078 }
1079
03f0dbf7
AC
1080 /* Block the thread for a while */
1081 prepare_to_wait(&edge_port->wait_chase, &wait,
1082 TASK_UNINTERRUPTIBLE);
1da177e4
LT
1083 schedule_timeout(timeout);
1084 finish_wait(&edge_port->wait_chase, &wait);
1085
441b62c1 1086 dbg("%s wait", __func__);
1da177e4
LT
1087
1088 if (lastCount == fifo->count) {
03f0dbf7 1089 /* No activity.. count down. */
1da177e4
LT
1090 loop--;
1091 if (loop == 0) {
441b62c1 1092 dbg("%s - TIMEOUT", __func__);
1da177e4
LT
1093 return;
1094 }
1095 } else {
03f0dbf7 1096 /* Reset timeout value back to seconds */
1da177e4
LT
1097 loop = 30;
1098 }
1099 }
1100}
1101
1102
1103/*****************************************************************************
1104 * edge_close
1105 * this function is called by the tty driver when a port is closed
1106 *****************************************************************************/
95da310e 1107static void edge_close(struct tty_struct *tty,
03f0dbf7 1108 struct usb_serial_port *port, struct file *filp)
1da177e4
LT
1109{
1110 struct edgeport_serial *edge_serial;
1111 struct edgeport_port *edge_port;
1112 int status;
1113
441b62c1 1114 dbg("%s - port %d", __func__, port->number);
03f0dbf7 1115
1da177e4
LT
1116 edge_serial = usb_get_serial_data(port->serial);
1117 edge_port = usb_get_serial_port_data(port);
03f0dbf7 1118 if (edge_serial == NULL || edge_port == NULL)
1da177e4 1119 return;
03f0dbf7
AC
1120
1121 /* block until tx is empty */
1da177e4
LT
1122 block_until_tx_empty(edge_port);
1123
cb8eaa8b 1124 edge_port->closePending = true;
1da177e4 1125
6e8cf775
GKH
1126 if ((!edge_serial->is_epic) ||
1127 ((edge_serial->is_epic) &&
1128 (edge_serial->epic_descriptor.Supports.IOSPChase))) {
1129 /* flush and chase */
cb8eaa8b 1130 edge_port->chaseResponsePending = true;
6e8cf775 1131
441b62c1 1132 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__);
03f0dbf7
AC
1133 status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0);
1134 if (status == 0)
1135 /* block until chase finished */
6e8cf775 1136 block_until_chase_response(edge_port);
03f0dbf7 1137 else
cb8eaa8b 1138 edge_port->chaseResponsePending = false;
1da177e4
LT
1139 }
1140
6e8cf775
GKH
1141 if ((!edge_serial->is_epic) ||
1142 ((edge_serial->is_epic) &&
1143 (edge_serial->epic_descriptor.Supports.IOSPClose))) {
1144 /* close the port */
441b62c1 1145 dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__);
03f0dbf7 1146 send_iosp_ext_cmd(edge_port, IOSP_CMD_CLOSE_PORT, 0);
6e8cf775 1147 }
1da177e4 1148
03f0dbf7 1149 /* port->close = true; */
cb8eaa8b
RK
1150 edge_port->closePending = false;
1151 edge_port->open = false;
1152 edge_port->openPending = false;
1da177e4 1153
9a25f44f 1154 usb_kill_urb(edge_port->write_urb);
1da177e4
LT
1155
1156 if (edge_port->write_urb) {
03f0dbf7
AC
1157 /* if this urb had a transfer buffer already
1158 (old transfer) free it */
1bc3c9e1
JJ
1159 kfree(edge_port->write_urb->transfer_buffer);
1160 usb_free_urb(edge_port->write_urb);
1da177e4
LT
1161 edge_port->write_urb = NULL;
1162 }
1bc3c9e1
JJ
1163 kfree(edge_port->txfifo.fifo);
1164 edge_port->txfifo.fifo = NULL;
1da177e4 1165
441b62c1 1166 dbg("%s exited", __func__);
03f0dbf7 1167}
1da177e4
LT
1168
1169/*****************************************************************************
1170 * SerialWrite
03f0dbf7
AC
1171 * this function is called by the tty driver when data should be written
1172 * to the port.
1173 * If successful, we return the number of bytes written, otherwise we
1174 * return a negative error number.
1da177e4 1175 *****************************************************************************/
95da310e
AC
1176static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1177 const unsigned char *data, int count)
1da177e4
LT
1178{
1179 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1180 struct TxFifo *fifo;
1181 int copySize;
1182 int bytesleft;
1183 int firsthalf;
1184 int secondhalf;
1185 unsigned long flags;
1186
441b62c1 1187 dbg("%s - port %d", __func__, port->number);
1da177e4
LT
1188
1189 if (edge_port == NULL)
1190 return -ENODEV;
1191
03f0dbf7 1192 /* get a pointer to the Tx fifo */
1da177e4
LT
1193 fifo = &edge_port->txfifo;
1194
1195 spin_lock_irqsave(&edge_port->ep_lock, flags);
1196
03f0dbf7
AC
1197 /* calculate number of bytes to put in fifo */
1198 copySize = min((unsigned int)count,
1199 (edge_port->txCredits - fifo->count));
1da177e4 1200
03f0dbf7
AC
1201 dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes",
1202 __func__, port->number, count,
1203 edge_port->txCredits - fifo->count, copySize);
1da177e4 1204
03f0dbf7
AC
1205 /* catch writes of 0 bytes which the tty driver likes to give us,
1206 and when txCredits is empty */
1da177e4 1207 if (copySize == 0) {
441b62c1 1208 dbg("%s - copySize = Zero", __func__);
1da177e4
LT
1209 goto finish_write;
1210 }
1211
03f0dbf7
AC
1212 /* queue the data
1213 * since we can never overflow the buffer we do not have to check for a
1214 * full condition
1215 *
1216 * the copy is done is two parts -- first fill to the end of the buffer
1217 * then copy the reset from the start of the buffer
1218 */
1da177e4 1219 bytesleft = fifo->size - fifo->head;
03f0dbf7
AC
1220 firsthalf = min(bytesleft, copySize);
1221 dbg("%s - copy %d bytes of %d into fifo ", __func__,
1222 firsthalf, bytesleft);
1da177e4
LT
1223
1224 /* now copy our data */
1225 memcpy(&fifo->fifo[fifo->head], data, firsthalf);
03f0dbf7
AC
1226 usb_serial_debug_data(debug, &port->dev, __func__,
1227 firsthalf, &fifo->fifo[fifo->head]);
1da177e4 1228
03f0dbf7 1229 /* update the index and size */
1da177e4
LT
1230 fifo->head += firsthalf;
1231 fifo->count += firsthalf;
1232
03f0dbf7
AC
1233 /* wrap the index */
1234 if (fifo->head == fifo->size)
1da177e4 1235 fifo->head = 0;
1da177e4
LT
1236
1237 secondhalf = copySize-firsthalf;
1238
1239 if (secondhalf) {
441b62c1 1240 dbg("%s - copy rest of data %d", __func__, secondhalf);
1da177e4 1241 memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf);
03f0dbf7
AC
1242 usb_serial_debug_data(debug, &port->dev, __func__,
1243 secondhalf, &fifo->fifo[fifo->head]);
1244 /* update the index and size */
1da177e4
LT
1245 fifo->count += secondhalf;
1246 fifo->head += secondhalf;
03f0dbf7
AC
1247 /* No need to check for wrap since we can not get to end of
1248 * the fifo in this part
1249 */
1da177e4
LT
1250 }
1251
1252finish_write:
1253 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1254
03f0dbf7
AC
1255 send_more_port_data((struct edgeport_serial *)
1256 usb_get_serial_data(port->serial), edge_port);
1da177e4 1257
03f0dbf7
AC
1258 dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__,
1259 copySize, edge_port->txCredits, fifo->count);
1da177e4 1260
03f0dbf7 1261 return copySize;
1da177e4
LT
1262}
1263
1264
1265/************************************************************************
1266 *
1267 * send_more_port_data()
1268 *
1269 * This routine attempts to write additional UART transmit data
1270 * to a port over the USB bulk pipe. It is called (1) when new
1271 * data has been written to a port's TxBuffer from higher layers
1272 * (2) when the peripheral sends us additional TxCredits indicating
1273 * that it can accept more Tx data for a given port; and (3) when
1274 * a bulk write completes successfully and we want to see if we
1275 * can transmit more.
1276 *
1277 ************************************************************************/
03f0dbf7
AC
1278static void send_more_port_data(struct edgeport_serial *edge_serial,
1279 struct edgeport_port *edge_port)
1da177e4
LT
1280{
1281 struct TxFifo *fifo = &edge_port->txfifo;
1282 struct urb *urb;
1283 unsigned char *buffer;
1284 int status;
1285 int count;
1286 int bytesleft;
1287 int firsthalf;
1288 int secondhalf;
1289 unsigned long flags;
1290
441b62c1 1291 dbg("%s(%d)", __func__, edge_port->port->number);
1da177e4
LT
1292
1293 spin_lock_irqsave(&edge_port->ep_lock, flags);
1294
1295 if (edge_port->write_in_progress ||
1296 !edge_port->open ||
1297 (fifo->count == 0)) {
03f0dbf7
AC
1298 dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d",
1299 __func__, edge_port->port->number,
1300 fifo->count, edge_port->write_in_progress);
1da177e4
LT
1301 goto exit_send;
1302 }
1303
03f0dbf7
AC
1304 /* since the amount of data in the fifo will always fit into the
1305 * edgeport buffer we do not need to check the write length
1306 *
1307 * Do we have enough credits for this port to make it worthwhile
1308 * to bother queueing a write. If it's too small, say a few bytes,
1309 * it's better to wait for more credits so we can do a larger write.
1310 */
1311 if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits, EDGE_FW_BULK_MAX_PACKET_SIZE)) {
1312 dbg("%s(%d) Not enough credit - fifo %d TxCredit %d",
1313 __func__, edge_port->port->number, fifo->count,
1314 edge_port->txCredits);
1da177e4
LT
1315 goto exit_send;
1316 }
1317
03f0dbf7 1318 /* lock this write */
cb8eaa8b 1319 edge_port->write_in_progress = true;
1da177e4 1320
03f0dbf7 1321 /* get a pointer to the write_urb */
1da177e4
LT
1322 urb = edge_port->write_urb;
1323
1bc3c9e1
JJ
1324 /* make sure transfer buffer is freed */
1325 kfree(urb->transfer_buffer);
1326 urb->transfer_buffer = NULL;
1da177e4 1327
03f0dbf7
AC
1328 /* build the data header for the buffer and port that we are about
1329 to send out */
1da177e4 1330 count = fifo->count;
03f0dbf7 1331 buffer = kmalloc(count+2, GFP_ATOMIC);
1da177e4 1332 if (buffer == NULL) {
03f0dbf7
AC
1333 dev_err(&edge_port->port->dev,
1334 "%s - no more kernel memory...\n", __func__);
cb8eaa8b 1335 edge_port->write_in_progress = false;
1da177e4
LT
1336 goto exit_send;
1337 }
03f0dbf7
AC
1338 buffer[0] = IOSP_BUILD_DATA_HDR1(edge_port->port->number
1339 - edge_port->port->serial->minor, count);
1340 buffer[1] = IOSP_BUILD_DATA_HDR2(edge_port->port->number
1341 - edge_port->port->serial->minor, count);
1da177e4
LT
1342
1343 /* now copy our data */
1344 bytesleft = fifo->size - fifo->tail;
03f0dbf7 1345 firsthalf = min(bytesleft, count);
1da177e4
LT
1346 memcpy(&buffer[2], &fifo->fifo[fifo->tail], firsthalf);
1347 fifo->tail += firsthalf;
1348 fifo->count -= firsthalf;
03f0dbf7 1349 if (fifo->tail == fifo->size)
1da177e4 1350 fifo->tail = 0;
1da177e4
LT
1351
1352 secondhalf = count-firsthalf;
1353 if (secondhalf) {
03f0dbf7
AC
1354 memcpy(&buffer[2+firsthalf], &fifo->fifo[fifo->tail],
1355 secondhalf);
1da177e4
LT
1356 fifo->tail += secondhalf;
1357 fifo->count -= secondhalf;
1358 }
1359
1360 if (count)
03f0dbf7
AC
1361 usb_serial_debug_data(debug, &edge_port->port->dev,
1362 __func__, count, &buffer[2]);
1da177e4
LT
1363
1364 /* fill up the urb with all of our data and submit it */
03f0dbf7
AC
1365 usb_fill_bulk_urb(urb, edge_serial->serial->dev,
1366 usb_sndbulkpipe(edge_serial->serial->dev,
1367 edge_serial->bulk_out_endpoint),
1368 buffer, count+2,
1369 edge_bulk_out_data_callback, edge_port);
1da177e4
LT
1370
1371 /* decrement the number of credits we have by the number we just sent */
1372 edge_port->txCredits -= count;
1373 edge_port->icount.tx += count;
1374
1375 urb->dev = edge_serial->serial->dev;
1376 status = usb_submit_urb(urb, GFP_ATOMIC);
1377 if (status) {
1378 /* something went wrong */
03f0dbf7
AC
1379 dev_err(&edge_port->port->dev,
1380 "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n",
1381 __func__, status);
cb8eaa8b 1382 edge_port->write_in_progress = false;
1da177e4
LT
1383
1384 /* revert the credits as something bad happened. */
1385 edge_port->txCredits += count;
1386 edge_port->icount.tx -= count;
1387 }
03f0dbf7
AC
1388 dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d",
1389 __func__, count, edge_port->txCredits, fifo->count);
1da177e4
LT
1390
1391exit_send:
1392 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1393}
1394
1395
1396/*****************************************************************************
1397 * edge_write_room
03f0dbf7
AC
1398 * this function is called by the tty driver when it wants to know how
1399 * many bytes of data we can accept for a specific port. If successful,
1400 * we return the amount of room that we have for this port (the txCredits)
1401 * otherwise we return a negative error number.
1da177e4 1402 *****************************************************************************/
95da310e 1403static int edge_write_room(struct tty_struct *tty)
1da177e4 1404{
95da310e 1405 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
1406 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1407 int room;
1408 unsigned long flags;
1409
441b62c1 1410 dbg("%s", __func__);
1da177e4
LT
1411
1412 if (edge_port == NULL)
d76f2f44 1413 return 0;
cb8eaa8b 1414 if (edge_port->closePending)
d76f2f44 1415 return 0;
1da177e4 1416
441b62c1 1417 dbg("%s - port %d", __func__, port->number);
1da177e4
LT
1418
1419 if (!edge_port->open) {
441b62c1 1420 dbg("%s - port not opened", __func__);
d76f2f44 1421 return 0;
1da177e4
LT
1422 }
1423
03f0dbf7 1424 /* total of both buffers is still txCredit */
1da177e4
LT
1425 spin_lock_irqsave(&edge_port->ep_lock, flags);
1426 room = edge_port->txCredits - edge_port->txfifo.count;
1427 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1428
441b62c1 1429 dbg("%s - returns %d", __func__, room);
1da177e4
LT
1430 return room;
1431}
1432
1433
1434/*****************************************************************************
1435 * edge_chars_in_buffer
03f0dbf7
AC
1436 * this function is called by the tty driver when it wants to know how
1437 * many bytes of data we currently have outstanding in the port (data that
1438 * has been written, but hasn't made it out the port yet)
1439 * If successful, we return the number of bytes left to be written in the
1440 * system,
1da177e4
LT
1441 * Otherwise we return a negative error number.
1442 *****************************************************************************/
95da310e 1443static int edge_chars_in_buffer(struct tty_struct *tty)
1da177e4 1444{
95da310e 1445 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
1446 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1447 int num_chars;
1448 unsigned long flags;
1449
441b62c1 1450 dbg("%s", __func__);
1da177e4
LT
1451
1452 if (edge_port == NULL)
d76f2f44 1453 return 0;
cb8eaa8b 1454 if (edge_port->closePending)
d76f2f44 1455 return 0;
1da177e4
LT
1456
1457 if (!edge_port->open) {
441b62c1 1458 dbg("%s - port not opened", __func__);
d76f2f44 1459 return 0;
1da177e4
LT
1460 }
1461
1462 spin_lock_irqsave(&edge_port->ep_lock, flags);
03f0dbf7
AC
1463 num_chars = edge_port->maxTxCredits - edge_port->txCredits +
1464 edge_port->txfifo.count;
1da177e4
LT
1465 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1466 if (num_chars) {
03f0dbf7
AC
1467 dbg("%s(port %d) - returns %d", __func__,
1468 port->number, num_chars);
1da177e4
LT
1469 }
1470
1471 return num_chars;
1472}
1473
1474
1475/*****************************************************************************
1476 * SerialThrottle
1477 * this function is called by the tty driver when it wants to stop the data
1478 * being read from the port.
1479 *****************************************************************************/
95da310e 1480static void edge_throttle(struct tty_struct *tty)
1da177e4 1481{
95da310e 1482 struct usb_serial_port *port = tty->driver_data;
1da177e4 1483 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1da177e4
LT
1484 int status;
1485
441b62c1 1486 dbg("%s - port %d", __func__, port->number);
1da177e4
LT
1487
1488 if (edge_port == NULL)
1489 return;
1490
1491 if (!edge_port->open) {
441b62c1 1492 dbg("%s - port not opened", __func__);
1da177e4
LT
1493 return;
1494 }
1495
1da177e4
LT
1496 /* if we are implementing XON/XOFF, send the stop character */
1497 if (I_IXOFF(tty)) {
1498 unsigned char stop_char = STOP_CHAR(tty);
03f0dbf7
AC
1499 status = edge_write(tty, port, &stop_char, 1);
1500 if (status <= 0)
1da177e4 1501 return;
1da177e4
LT
1502 }
1503
1504 /* if we are implementing RTS/CTS, toggle that line */
1505 if (tty->termios->c_cflag & CRTSCTS) {
1506 edge_port->shadowMCR &= ~MCR_RTS;
03f0dbf7
AC
1507 status = send_cmd_write_uart_register(edge_port, MCR,
1508 edge_port->shadowMCR);
1509 if (status != 0)
1da177e4 1510 return;
1da177e4
LT
1511 }
1512
1513 return;
1514}
1515
1516
1517/*****************************************************************************
1518 * edge_unthrottle
03f0dbf7
AC
1519 * this function is called by the tty driver when it wants to resume the
1520 * data being read from the port (called after SerialThrottle is called)
1da177e4 1521 *****************************************************************************/
95da310e 1522static void edge_unthrottle(struct tty_struct *tty)
1da177e4 1523{
95da310e 1524 struct usb_serial_port *port = tty->driver_data;
1da177e4 1525 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1da177e4
LT
1526 int status;
1527
441b62c1 1528 dbg("%s - port %d", __func__, port->number);
1da177e4
LT
1529
1530 if (edge_port == NULL)
1531 return;
1532
1533 if (!edge_port->open) {
441b62c1 1534 dbg("%s - port not opened", __func__);
1da177e4
LT
1535 return;
1536 }
1537
1da177e4
LT
1538 /* if we are implementing XON/XOFF, send the start character */
1539 if (I_IXOFF(tty)) {
1540 unsigned char start_char = START_CHAR(tty);
95da310e
AC
1541 status = edge_write(tty, port, &start_char, 1);
1542 if (status <= 0)
1da177e4 1543 return;
1da177e4 1544 }
1da177e4
LT
1545 /* if we are implementing RTS/CTS, toggle that line */
1546 if (tty->termios->c_cflag & CRTSCTS) {
1547 edge_port->shadowMCR |= MCR_RTS;
03f0dbf7
AC
1548 send_cmd_write_uart_register(edge_port, MCR,
1549 edge_port->shadowMCR);
1da177e4 1550 }
1da177e4
LT
1551}
1552
1553
1554/*****************************************************************************
1555 * SerialSetTermios
03f0dbf7
AC
1556 * this function is called by the tty driver when it wants to change
1557 * the termios structure
1da177e4 1558 *****************************************************************************/
95da310e
AC
1559static void edge_set_termios(struct tty_struct *tty,
1560 struct usb_serial_port *port, struct ktermios *old_termios)
1da177e4
LT
1561{
1562 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1da177e4
LT
1563 unsigned int cflag;
1564
1da177e4 1565 cflag = tty->termios->c_cflag;
441b62c1 1566 dbg("%s - clfag %08x iflag %08x", __func__,
1da177e4 1567 tty->termios->c_cflag, tty->termios->c_iflag);
441b62c1 1568 dbg("%s - old clfag %08x old iflag %08x", __func__,
6ce073bd 1569 old_termios->c_cflag, old_termios->c_iflag);
1da177e4 1570
441b62c1 1571 dbg("%s - port %d", __func__, port->number);
1da177e4
LT
1572
1573 if (edge_port == NULL)
1574 return;
1575
1576 if (!edge_port->open) {
441b62c1 1577 dbg("%s - port not opened", __func__);
1da177e4
LT
1578 return;
1579 }
1580
1581 /* change the port settings to the new ones specified */
95da310e 1582 change_port_settings(tty, edge_port, old_termios);
1da177e4
LT
1583}
1584
1585
1586/*****************************************************************************
1587 * get_lsr_info - get line status register info
1588 *
1589 * Purpose: Let user call ioctl() to get info when the UART physically
1590 * is emptied. On bus types like RS485, the transmitter must
1591 * release the bus after transmitting. This must be done when
1592 * the transmit shift register is empty, not be done when the
1593 * transmit holding register is empty. This functionality
03f0dbf7 1594 * allows an RS485 driver to be written in user space.
1da177e4 1595 *****************************************************************************/
03f0dbf7
AC
1596static int get_lsr_info(struct edgeport_port *edge_port,
1597 unsigned int __user *value)
1da177e4
LT
1598{
1599 unsigned int result = 0;
1600 unsigned long flags;
1601
1602 spin_lock_irqsave(&edge_port->ep_lock, flags);
1603 if (edge_port->maxTxCredits == edge_port->txCredits &&
1604 edge_port->txfifo.count == 0) {
441b62c1 1605 dbg("%s -- Empty", __func__);
1da177e4
LT
1606 result = TIOCSER_TEMT;
1607 }
1608 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1609
1610 if (copy_to_user(value, &result, sizeof(int)))
1611 return -EFAULT;
1612 return 0;
1613}
1614
03f0dbf7
AC
1615static int edge_tiocmset(struct tty_struct *tty, struct file *file,
1616 unsigned int set, unsigned int clear)
1da177e4 1617{
95da310e 1618 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
1619 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1620 unsigned int mcr;
1621
441b62c1 1622 dbg("%s - port %d", __func__, port->number);
1da177e4
LT
1623
1624 mcr = edge_port->shadowMCR;
1625 if (set & TIOCM_RTS)
1626 mcr |= MCR_RTS;
1627 if (set & TIOCM_DTR)
1628 mcr |= MCR_DTR;
1629 if (set & TIOCM_LOOP)
1630 mcr |= MCR_LOOPBACK;
1631
1632 if (clear & TIOCM_RTS)
1633 mcr &= ~MCR_RTS;
1634 if (clear & TIOCM_DTR)
1635 mcr &= ~MCR_DTR;
1636 if (clear & TIOCM_LOOP)
1637 mcr &= ~MCR_LOOPBACK;
1638
1639 edge_port->shadowMCR = mcr;
1640
1641 send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR);
1642
1643 return 0;
1644}
1645
95da310e 1646static int edge_tiocmget(struct tty_struct *tty, struct file *file)
1da177e4 1647{
95da310e 1648 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
1649 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1650 unsigned int result = 0;
1651 unsigned int msr;
1652 unsigned int mcr;
1653
441b62c1 1654 dbg("%s - port %d", __func__, port->number);
1da177e4
LT
1655
1656 msr = edge_port->shadowMSR;
1657 mcr = edge_port->shadowMCR;
1658 result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
1659 | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
1660 | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
1661 | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
1662 | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
1663 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
1664
1665
441b62c1 1666 dbg("%s -- %x", __func__, result);
1da177e4
LT
1667
1668 return result;
1669}
1670
03f0dbf7
AC
1671static int get_serial_info(struct edgeport_port *edge_port,
1672 struct serial_struct __user *retinfo)
1da177e4
LT
1673{
1674 struct serial_struct tmp;
1675
1676 if (!retinfo)
1677 return -EFAULT;
1678
1679 memset(&tmp, 0, sizeof(tmp));
1680
1681 tmp.type = PORT_16550A;
1682 tmp.line = edge_port->port->serial->minor;
1683 tmp.port = edge_port->port->number;
1684 tmp.irq = 0;
1685 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1686 tmp.xmit_fifo_size = edge_port->maxTxCredits;
1687 tmp.baud_base = 9600;
1688 tmp.close_delay = 5*HZ;
1689 tmp.closing_wait = 30*HZ;
1da177e4
LT
1690
1691 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1692 return -EFAULT;
1693 return 0;
1694}
1695
1696
1697
1698/*****************************************************************************
1699 * SerialIoctl
1700 * this function handles any ioctl calls to the driver
1701 *****************************************************************************/
95da310e
AC
1702static int edge_ioctl(struct tty_struct *tty, struct file *file,
1703 unsigned int cmd, unsigned long arg)
1da177e4 1704{
95da310e 1705 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
1706 DEFINE_WAIT(wait);
1707 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1708 struct async_icount cnow;
1709 struct async_icount cprev;
1710 struct serial_icounter_struct icount;
1711
441b62c1 1712 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1da177e4
LT
1713
1714 switch (cmd) {
03f0dbf7
AC
1715 case TIOCSERGETLSR:
1716 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1717 return get_lsr_info(edge_port, (unsigned int __user *) arg);
1718
1719 case TIOCGSERIAL:
1720 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1721 return get_serial_info(edge_port, (struct serial_struct __user *) arg);
1722
1723 case TIOCMIWAIT:
1724 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1725 cprev = edge_port->icount;
1726 while (1) {
1727 prepare_to_wait(&edge_port->delta_msr_wait,
1728 &wait, TASK_INTERRUPTIBLE);
1729 schedule();
1730 finish_wait(&edge_port->delta_msr_wait, &wait);
1731 /* see if a signal did it */
1732 if (signal_pending(current))
1733 return -ERESTARTSYS;
1734 cnow = edge_port->icount;
1735 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1736 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1737 return -EIO; /* no change => error */
1738 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1739 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1740 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1741 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1742 return 0;
1da177e4 1743 }
03f0dbf7
AC
1744 cprev = cnow;
1745 }
1746 /* NOTREACHED */
1747 break;
1da177e4 1748
03f0dbf7
AC
1749 case TIOCGICOUNT:
1750 cnow = edge_port->icount;
1751 memset(&icount, 0, sizeof(icount));
1752 icount.cts = cnow.cts;
1753 icount.dsr = cnow.dsr;
1754 icount.rng = cnow.rng;
1755 icount.dcd = cnow.dcd;
1756 icount.rx = cnow.rx;
1757 icount.tx = cnow.tx;
1758 icount.frame = cnow.frame;
1759 icount.overrun = cnow.overrun;
1760 icount.parity = cnow.parity;
1761 icount.brk = cnow.brk;
1762 icount.buf_overrun = cnow.buf_overrun;
1763
1764 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
1765 __func__, port->number, icount.rx, icount.tx);
1766 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1767 return -EFAULT;
1768 return 0;
1da177e4 1769 }
1da177e4
LT
1770 return -ENOIOCTLCMD;
1771}
1772
1773
1774/*****************************************************************************
1775 * SerialBreak
1776 * this function sends a break to the port
1777 *****************************************************************************/
03f0dbf7 1778static void edge_break(struct tty_struct *tty, int break_state)
1da177e4 1779{
95da310e 1780 struct usb_serial_port *port = tty->driver_data;
1da177e4 1781 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
6e8cf775 1782 struct edgeport_serial *edge_serial = usb_get_serial_data(port->serial);
1da177e4
LT
1783 int status;
1784
6e8cf775
GKH
1785 if ((!edge_serial->is_epic) ||
1786 ((edge_serial->is_epic) &&
1787 (edge_serial->epic_descriptor.Supports.IOSPChase))) {
1788 /* flush and chase */
cb8eaa8b 1789 edge_port->chaseResponsePending = true;
6e8cf775 1790
441b62c1 1791 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__);
03f0dbf7 1792 status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0);
6e8cf775 1793 if (status == 0) {
03f0dbf7 1794 /* block until chase finished */
6e8cf775
GKH
1795 block_until_chase_response(edge_port);
1796 } else {
cb8eaa8b 1797 edge_port->chaseResponsePending = false;
6e8cf775 1798 }
1da177e4
LT
1799 }
1800
6e8cf775
GKH
1801 if ((!edge_serial->is_epic) ||
1802 ((edge_serial->is_epic) &&
1803 (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) {
1804 if (break_state == -1) {
441b62c1 1805 dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__);
03f0dbf7
AC
1806 status = send_iosp_ext_cmd(edge_port,
1807 IOSP_CMD_SET_BREAK, 0);
6e8cf775 1808 } else {
441b62c1 1809 dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__);
03f0dbf7
AC
1810 status = send_iosp_ext_cmd(edge_port,
1811 IOSP_CMD_CLEAR_BREAK, 0);
6e8cf775 1812 }
03f0dbf7
AC
1813 if (status)
1814 dbg("%s - error sending break set/clear command.",
1815 __func__);
1da177e4
LT
1816 }
1817
1818 return;
1819}
1820
1821
1822/*****************************************************************************
1823 * process_rcvd_data
1824 * this function handles the data received on the bulk in pipe.
1825 *****************************************************************************/
03f0dbf7
AC
1826static void process_rcvd_data(struct edgeport_serial *edge_serial,
1827 unsigned char *buffer, __u16 bufferLength)
1da177e4
LT
1828{
1829 struct usb_serial_port *port;
1830 struct edgeport_port *edge_port;
1831 struct tty_struct *tty;
1832 __u16 lastBufferLength;
1833 __u16 rxLen;
1834
441b62c1 1835 dbg("%s", __func__);
1da177e4
LT
1836
1837 lastBufferLength = bufferLength + 1;
1838
1839 while (bufferLength > 0) {
1840 /* failsafe incase we get a message that we don't understand */
1841 if (lastBufferLength == bufferLength) {
441b62c1 1842 dbg("%s - stuck in loop, exiting it.", __func__);
1da177e4
LT
1843 break;
1844 }
1845 lastBufferLength = bufferLength;
1846
1847 switch (edge_serial->rxState) {
03f0dbf7
AC
1848 case EXPECT_HDR1:
1849 edge_serial->rxHeader1 = *buffer;
1850 ++buffer;
1851 --bufferLength;
1da177e4 1852
03f0dbf7
AC
1853 if (bufferLength == 0) {
1854 edge_serial->rxState = EXPECT_HDR2;
1855 break;
1856 }
1857 /* otherwise, drop on through */
1858 case EXPECT_HDR2:
1859 edge_serial->rxHeader2 = *buffer;
1860 ++buffer;
1861 --bufferLength;
1862
1863 dbg("%s - Hdr1=%02X Hdr2=%02X", __func__,
1864 edge_serial->rxHeader1, edge_serial->rxHeader2);
1865 /* Process depending on whether this header is
1866 * data or status */
1867
1868 if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) {
1869 /* Decode this status header and go to
1870 * EXPECT_HDR1 (if we can process the status
1871 * with only 2 bytes), or go to EXPECT_HDR3 to
1872 * get the third byte. */
1873 edge_serial->rxPort =
1874 IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1875 edge_serial->rxStatusCode =
1876 IOSP_GET_STATUS_CODE(
1877 edge_serial->rxHeader1);
1878
1879 if (!IOSP_STATUS_IS_2BYTE(
1880 edge_serial->rxStatusCode)) {
1881 /* This status needs additional bytes.
1882 * Save what we have and then wait for
1883 * more data.
1884 */
1885 edge_serial->rxStatusParam
1886 = edge_serial->rxHeader2;
1887 edge_serial->rxState = EXPECT_HDR3;
1da177e4
LT
1888 break;
1889 }
03f0dbf7
AC
1890 /* We have all the header bytes, process the
1891 status now */
1892 process_rcvd_status(edge_serial,
1893 edge_serial->rxHeader2, 0);
1894 edge_serial->rxState = EXPECT_HDR1;
1895 break;
1896 } else {
1897 edge_serial->rxPort =
1898 IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1899 edge_serial->rxBytesRemaining =
1900 IOSP_GET_HDR_DATA_LEN(
1901 edge_serial->rxHeader1,
1902 edge_serial->rxHeader2);
1903 dbg("%s - Data for Port %u Len %u",
1904 __func__,
1905 edge_serial->rxPort,
1906 edge_serial->rxBytesRemaining);
1907
1908 /* ASSERT(DevExt->RxPort < DevExt->NumPorts);
1909 * ASSERT(DevExt->RxBytesRemaining <
1910 * IOSP_MAX_DATA_LENGTH);
1911 */
1da177e4 1912
03f0dbf7
AC
1913 if (bufferLength == 0) {
1914 edge_serial->rxState = EXPECT_DATA;
1da177e4 1915 break;
1da177e4 1916 }
03f0dbf7
AC
1917 /* Else, drop through */
1918 }
1919 case EXPECT_DATA: /* Expect data */
1920 if (bufferLength < edge_serial->rxBytesRemaining) {
1921 rxLen = bufferLength;
1922 /* Expect data to start next buffer */
1923 edge_serial->rxState = EXPECT_DATA;
1924 } else {
1925 /* BufLen >= RxBytesRemaining */
1926 rxLen = edge_serial->rxBytesRemaining;
1927 /* Start another header next time */
1928 edge_serial->rxState = EXPECT_HDR1;
1929 }
1da177e4 1930
03f0dbf7
AC
1931 bufferLength -= rxLen;
1932 edge_serial->rxBytesRemaining -= rxLen;
1da177e4 1933
03f0dbf7
AC
1934 /* spit this data back into the tty driver if this
1935 port is open */
1936 if (rxLen) {
1937 port = edge_serial->serial->port[
1938 edge_serial->rxPort];
1939 edge_port = usb_get_serial_port_data(port);
1940 if (edge_port->open) {
4a90f09b
AC
1941 tty = tty_port_tty_get(
1942 &edge_port->port->port);
03f0dbf7
AC
1943 if (tty) {
1944 dbg("%s - Sending %d bytes to TTY for port %d",
1945 __func__, rxLen, edge_serial->rxPort);
1946 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen);
4a90f09b 1947 tty_kref_put(tty);
1da177e4 1948 }
03f0dbf7 1949 edge_port->icount.rx += rxLen;
1da177e4 1950 }
03f0dbf7
AC
1951 buffer += rxLen;
1952 }
1953 break;
1da177e4 1954
03f0dbf7
AC
1955 case EXPECT_HDR3: /* Expect 3rd byte of status header */
1956 edge_serial->rxHeader3 = *buffer;
1957 ++buffer;
1958 --bufferLength;
1959
1960 /* We have all the header bytes, process the
1961 status now */
1962 process_rcvd_status(edge_serial,
1963 edge_serial->rxStatusParam,
1964 edge_serial->rxHeader3);
1965 edge_serial->rxState = EXPECT_HDR1;
1966 break;
1da177e4
LT
1967 }
1968 }
1969}
1970
1971
1972/*****************************************************************************
1973 * process_rcvd_status
03f0dbf7
AC
1974 * this function handles the any status messages received on the
1975 * bulk in pipe.
1da177e4 1976 *****************************************************************************/
03f0dbf7
AC
1977static void process_rcvd_status(struct edgeport_serial *edge_serial,
1978 __u8 byte2, __u8 byte3)
1da177e4
LT
1979{
1980 struct usb_serial_port *port;
1981 struct edgeport_port *edge_port;
4a90f09b 1982 struct tty_struct *tty;
1da177e4
LT
1983 __u8 code = edge_serial->rxStatusCode;
1984
1985 /* switch the port pointer to the one being currently talked about */
1986 port = edge_serial->serial->port[edge_serial->rxPort];
1987 edge_port = usb_get_serial_port_data(port);
1988 if (edge_port == NULL) {
03f0dbf7
AC
1989 dev_err(&edge_serial->serial->dev->dev,
1990 "%s - edge_port == NULL for port %d\n",
1991 __func__, edge_serial->rxPort);
1da177e4
LT
1992 return;
1993 }
1994
441b62c1 1995 dbg("%s - port %d", __func__, edge_serial->rxPort);
1da177e4
LT
1996
1997 if (code == IOSP_EXT_STATUS) {
1998 switch (byte2) {
03f0dbf7
AC
1999 case IOSP_EXT_STATUS_CHASE_RSP:
2000 /* we want to do EXT status regardless of port
2001 * open/closed */
2002 dbg("%s - Port %u EXT CHASE_RSP Data = %02x",
2003 __func__, edge_serial->rxPort, byte3);
2004 /* Currently, the only EXT_STATUS is Chase, so process
2005 * here instead of one more call to one more subroutine
2006 * If/when more EXT_STATUS, there'll be more work to do
2007 * Also, we currently clear flag and close the port
2008 * regardless of content of above's Byte3.
2009 * We could choose to do something else when Byte3 says
2010 * Timeout on Chase from Edgeport, like wait longer in
2011 * block_until_chase_response, but for now we don't.
2012 */
2013 edge_port->chaseResponsePending = false;
2014 wake_up(&edge_port->wait_chase);
2015 return;
1da177e4 2016
03f0dbf7
AC
2017 case IOSP_EXT_STATUS_RX_CHECK_RSP:
2018 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3);
2019 /* Port->RxCheckRsp = true; */
2020 return;
1da177e4
LT
2021 }
2022 }
2023
2024 if (code == IOSP_STATUS_OPEN_RSP) {
2025 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3);
2026 edge_port->maxTxCredits = edge_port->txCredits;
441b62c1 2027 dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits);
03f0dbf7 2028 handle_new_msr(edge_port, byte2);
1da177e4 2029
03f0dbf7
AC
2030 /* send the current line settings to the port so we are
2031 in sync with any further termios calls */
4a90f09b
AC
2032 tty = tty_port_tty_get(&edge_port->port->port);
2033 if (tty) {
2034 change_port_settings(tty,
2035 edge_port, tty->termios);
2036 tty_kref_put(tty);
2037 }
1da177e4
LT
2038
2039 /* we have completed the open */
cb8eaa8b
RK
2040 edge_port->openPending = false;
2041 edge_port->open = true;
1da177e4
LT
2042 wake_up(&edge_port->wait_open);
2043 return;
2044 }
2045
03f0dbf7
AC
2046 /* If port is closed, silently discard all rcvd status. We can
2047 * have cases where buffered status is received AFTER the close
2048 * port command is sent to the Edgeport.
2049 */
2050 if (!edge_port->open || edge_port->closePending)
1da177e4 2051 return;
1da177e4
LT
2052
2053 switch (code) {
03f0dbf7
AC
2054 /* Not currently sent by Edgeport */
2055 case IOSP_STATUS_LSR:
2056 dbg("%s - Port %u LSR Status = %02x",
2057 __func__, edge_serial->rxPort, byte2);
2058 handle_new_lsr(edge_port, false, byte2, 0);
2059 break;
1da177e4 2060
03f0dbf7
AC
2061 case IOSP_STATUS_LSR_DATA:
2062 dbg("%s - Port %u LSR Status = %02x, Data = %02x",
2063 __func__, edge_serial->rxPort, byte2, byte3);
2064 /* byte2 is LSR Register */
2065 /* byte3 is broken data byte */
2066 handle_new_lsr(edge_port, true, byte2, byte3);
2067 break;
2068 /*
2069 * case IOSP_EXT_4_STATUS:
2070 * dbg("%s - Port %u LSR Status = %02x Data = %02x",
2071 * __func__, edge_serial->rxPort, byte2, byte3);
2072 * break;
2073 */
2074 case IOSP_STATUS_MSR:
2075 dbg("%s - Port %u MSR Status = %02x",
2076 __func__, edge_serial->rxPort, byte2);
2077 /*
2078 * Process this new modem status and generate appropriate
2079 * events, etc, based on the new status. This routine
2080 * also saves the MSR in Port->ShadowMsr.
2081 */
2082 handle_new_msr(edge_port, byte2);
2083 break;
1da177e4 2084
03f0dbf7
AC
2085 default:
2086 dbg("%s - Unrecognized IOSP status code %u\n", __func__, code);
2087 break;
1da177e4 2088 }
1da177e4
LT
2089 return;
2090}
2091
2092
2093/*****************************************************************************
2094 * edge_tty_recv
2095 * this function passes data on to the tty flip buffer
2096 *****************************************************************************/
03f0dbf7
AC
2097static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
2098 unsigned char *data, int length)
1da177e4
LT
2099{
2100 int cnt;
2101
2102 do {
33f0f88f
AC
2103 cnt = tty_buffer_request_room(tty, length);
2104 if (cnt < length) {
2105 dev_err(dev, "%s - dropping data, %d bytes lost\n",
441b62c1 2106 __func__, length - cnt);
03f0dbf7 2107 if (cnt == 0)
33f0f88f 2108 break;
1da177e4 2109 }
33f0f88f 2110 tty_insert_flip_string(tty, data, cnt);
1da177e4
LT
2111 data += cnt;
2112 length -= cnt;
2113 } while (length > 0);
2114
2115 tty_flip_buffer_push(tty);
2116}
2117
2118
2119/*****************************************************************************
2120 * handle_new_msr
2121 * this function handles any change to the msr register for a port.
2122 *****************************************************************************/
2123static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2124{
2125 struct async_icount *icount;
2126
441b62c1 2127 dbg("%s %02x", __func__, newMsr);
1da177e4 2128
03f0dbf7
AC
2129 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
2130 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1da177e4
LT
2131 icount = &edge_port->icount;
2132
2133 /* update input line counters */
03f0dbf7 2134 if (newMsr & EDGEPORT_MSR_DELTA_CTS)
1da177e4 2135 icount->cts++;
03f0dbf7 2136 if (newMsr & EDGEPORT_MSR_DELTA_DSR)
1da177e4 2137 icount->dsr++;
03f0dbf7 2138 if (newMsr & EDGEPORT_MSR_DELTA_CD)
1da177e4 2139 icount->dcd++;
03f0dbf7 2140 if (newMsr & EDGEPORT_MSR_DELTA_RI)
1da177e4 2141 icount->rng++;
1da177e4
LT
2142 wake_up_interruptible(&edge_port->delta_msr_wait);
2143 }
2144
2145 /* Save the new modem status */
2146 edge_port->shadowMSR = newMsr & 0xf0;
2147
2148 return;
2149}
2150
2151
2152/*****************************************************************************
2153 * handle_new_lsr
2154 * this function handles any change to the lsr register for a port.
2155 *****************************************************************************/
03f0dbf7
AC
2156static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
2157 __u8 lsr, __u8 data)
1da177e4 2158{
03f0dbf7
AC
2159 __u8 newLsr = (__u8) (lsr & (__u8)
2160 (LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
2161 struct async_icount *icount;
1da177e4 2162
441b62c1 2163 dbg("%s - %02x", __func__, newLsr);
1da177e4
LT
2164
2165 edge_port->shadowLSR = lsr;
2166
2167 if (newLsr & LSR_BREAK) {
03f0dbf7
AC
2168 /*
2169 * Parity and Framing errors only count if they
2170 * occur exclusive of a break being
2171 * received.
2172 */
1da177e4
LT
2173 newLsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
2174 }
2175
2176 /* Place LSR data byte into Rx buffer */
4a90f09b
AC
2177 if (lsrData) {
2178 struct tty_struct *tty =
2179 tty_port_tty_get(&edge_port->port->port);
2180 if (tty) {
2181 edge_tty_recv(&edge_port->port->dev, tty, &data, 1);
2182 tty_kref_put(tty);
2183 }
2184 }
1da177e4
LT
2185 /* update input line counters */
2186 icount = &edge_port->icount;
03f0dbf7 2187 if (newLsr & LSR_BREAK)
1da177e4 2188 icount->brk++;
03f0dbf7 2189 if (newLsr & LSR_OVER_ERR)
1da177e4 2190 icount->overrun++;
03f0dbf7 2191 if (newLsr & LSR_PAR_ERR)
1da177e4 2192 icount->parity++;
03f0dbf7 2193 if (newLsr & LSR_FRM_ERR)
1da177e4 2194 icount->frame++;
1da177e4
LT
2195
2196 return;
2197}
2198
2199
2200/****************************************************************************
2201 * sram_write
03f0dbf7 2202 * writes a number of bytes to the Edgeport device's sram starting at the
1da177e4
LT
2203 * given address.
2204 * If successful returns the number of bytes written, otherwise it returns
2205 * a negative error number of the problem.
2206 ****************************************************************************/
03f0dbf7
AC
2207static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
2208 __u16 length, const __u8 *data)
1da177e4
LT
2209{
2210 int result;
2211 __u16 current_length;
2212 unsigned char *transfer_buffer;
2213
441b62c1 2214 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
1da177e4 2215
03f0dbf7 2216 transfer_buffer = kmalloc(64, GFP_KERNEL);
1da177e4 2217 if (!transfer_buffer) {
03f0dbf7
AC
2218 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
2219 __func__, 64);
1da177e4
LT
2220 return -ENOMEM;
2221 }
2222
2223 /* need to split these writes up into 64 byte chunks */
2224 result = 0;
2225 while (length > 0) {
03f0dbf7 2226 if (length > 64)
1da177e4 2227 current_length = 64;
03f0dbf7 2228 else
1da177e4 2229 current_length = length;
03f0dbf7
AC
2230
2231/* dbg("%s - writing %x, %x, %d", __func__,
2232 extAddr, addr, current_length); */
2233 memcpy(transfer_buffer, data, current_length);
2234 result = usb_control_msg(serial->dev,
2235 usb_sndctrlpipe(serial->dev, 0),
2236 USB_REQUEST_ION_WRITE_RAM,
2237 0x40, addr, extAddr, transfer_buffer,
2238 current_length, 300);
1da177e4
LT
2239 if (result < 0)
2240 break;
2241 length -= current_length;
2242 addr += current_length;
2243 data += current_length;
03f0dbf7 2244 }
1da177e4 2245
03f0dbf7 2246 kfree(transfer_buffer);
1da177e4
LT
2247 return result;
2248}
2249
2250
2251/****************************************************************************
2252 * rom_write
2253 * writes a number of bytes to the Edgeport device's ROM starting at the
2254 * given address.
2255 * If successful returns the number of bytes written, otherwise it returns
2256 * a negative error number of the problem.
2257 ****************************************************************************/
03f0dbf7
AC
2258static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr,
2259 __u16 length, const __u8 *data)
1da177e4
LT
2260{
2261 int result;
2262 __u16 current_length;
2263 unsigned char *transfer_buffer;
2264
03f0dbf7 2265/* dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); */
1da177e4 2266
03f0dbf7 2267 transfer_buffer = kmalloc(64, GFP_KERNEL);
1da177e4 2268 if (!transfer_buffer) {
03f0dbf7
AC
2269 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
2270 __func__, 64);
1da177e4
LT
2271 return -ENOMEM;
2272 }
2273
2274 /* need to split these writes up into 64 byte chunks */
2275 result = 0;
2276 while (length > 0) {
03f0dbf7 2277 if (length > 64)
1da177e4 2278 current_length = 64;
03f0dbf7 2279 else
1da177e4 2280 current_length = length;
03f0dbf7
AC
2281/* dbg("%s - writing %x, %x, %d", __func__,
2282 extAddr, addr, current_length); */
2283 memcpy(transfer_buffer, data, current_length);
2284 result = usb_control_msg(serial->dev,
2285 usb_sndctrlpipe(serial->dev, 0),
2286 USB_REQUEST_ION_WRITE_ROM, 0x40,
2287 addr, extAddr,
2288 transfer_buffer, current_length, 300);
1da177e4
LT
2289 if (result < 0)
2290 break;
2291 length -= current_length;
2292 addr += current_length;
2293 data += current_length;
03f0dbf7 2294 }
1da177e4 2295
03f0dbf7 2296 kfree(transfer_buffer);
1da177e4
LT
2297 return result;
2298}
2299
2300
2301/****************************************************************************
2302 * rom_read
2303 * reads a number of bytes from the Edgeport device starting at the given
2304 * address.
2305 * If successful returns the number of bytes read, otherwise it returns
2306 * a negative error number of the problem.
2307 ****************************************************************************/
03f0dbf7
AC
2308static int rom_read(struct usb_serial *serial, __u16 extAddr,
2309 __u16 addr, __u16 length, __u8 *data)
1da177e4
LT
2310{
2311 int result;
2312 __u16 current_length;
2313 unsigned char *transfer_buffer;
2314
441b62c1 2315 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
1da177e4 2316
03f0dbf7 2317 transfer_buffer = kmalloc(64, GFP_KERNEL);
1da177e4 2318 if (!transfer_buffer) {
03f0dbf7
AC
2319 dev_err(&serial->dev->dev,
2320 "%s - kmalloc(%d) failed.\n", __func__, 64);
1da177e4
LT
2321 return -ENOMEM;
2322 }
2323
2324 /* need to split these reads up into 64 byte chunks */
2325 result = 0;
2326 while (length > 0) {
03f0dbf7 2327 if (length > 64)
1da177e4 2328 current_length = 64;
03f0dbf7 2329 else
1da177e4 2330 current_length = length;
03f0dbf7
AC
2331/* dbg("%s - %x, %x, %d", __func__,
2332 extAddr, addr, current_length); */
2333 result = usb_control_msg(serial->dev,
2334 usb_rcvctrlpipe(serial->dev, 0),
2335 USB_REQUEST_ION_READ_ROM,
2336 0xC0, addr, extAddr, transfer_buffer,
2337 current_length, 300);
1da177e4
LT
2338 if (result < 0)
2339 break;
03f0dbf7 2340 memcpy(data, transfer_buffer, current_length);
1da177e4
LT
2341 length -= current_length;
2342 addr += current_length;
2343 data += current_length;
03f0dbf7 2344 }
1da177e4 2345
03f0dbf7 2346 kfree(transfer_buffer);
1da177e4
LT
2347 return result;
2348}
2349
2350
2351/****************************************************************************
2352 * send_iosp_ext_cmd
2353 * Is used to send a IOSP message to the Edgeport device
2354 ****************************************************************************/
03f0dbf7
AC
2355static int send_iosp_ext_cmd(struct edgeport_port *edge_port,
2356 __u8 command, __u8 param)
1da177e4
LT
2357{
2358 unsigned char *buffer;
2359 unsigned char *currentCommand;
2360 int length = 0;
2361 int status = 0;
2362
441b62c1 2363 dbg("%s - %d, %d", __func__, command, param);
1da177e4 2364
03f0dbf7 2365 buffer = kmalloc(10, GFP_ATOMIC);
1da177e4 2366 if (!buffer) {
03f0dbf7
AC
2367 dev_err(&edge_port->port->dev,
2368 "%s - kmalloc(%d) failed.\n", __func__, 10);
1da177e4
LT
2369 return -ENOMEM;
2370 }
2371
2372 currentCommand = buffer;
2373
03f0dbf7
AC
2374 MAKE_CMD_EXT_CMD(&currentCommand, &length,
2375 edge_port->port->number - edge_port->port->serial->minor,
2376 command, param);
1da177e4 2377
03f0dbf7 2378 status = write_cmd_usb(edge_port, buffer, length);
1da177e4
LT
2379 if (status) {
2380 /* something bad happened, let's free up the memory */
2381 kfree(buffer);
2382 }
2383
2384 return status;
2385}
2386
2387
2388/*****************************************************************************
2389 * write_cmd_usb
2390 * this function writes the given buffer out to the bulk write endpoint.
2391 *****************************************************************************/
03f0dbf7
AC
2392static int write_cmd_usb(struct edgeport_port *edge_port,
2393 unsigned char *buffer, int length)
1da177e4 2394{
03f0dbf7
AC
2395 struct edgeport_serial *edge_serial =
2396 usb_get_serial_data(edge_port->port->serial);
1da177e4
LT
2397 int status = 0;
2398 struct urb *urb;
2399 int timeout;
2400
03f0dbf7
AC
2401 usb_serial_debug_data(debug, &edge_port->port->dev,
2402 __func__, length, buffer);
1da177e4
LT
2403
2404 /* Allocate our next urb */
03f0dbf7 2405 urb = usb_alloc_urb(0, GFP_ATOMIC);
1da177e4
LT
2406 if (!urb)
2407 return -ENOMEM;
2408
96c706ed 2409 atomic_inc(&CmdUrbs);
03f0dbf7
AC
2410 dbg("%s - ALLOCATE URB %p (outstanding %d)",
2411 __func__, urb, atomic_read(&CmdUrbs));
1da177e4 2412
03f0dbf7
AC
2413 usb_fill_bulk_urb(urb, edge_serial->serial->dev,
2414 usb_sndbulkpipe(edge_serial->serial->dev,
2415 edge_serial->bulk_out_endpoint),
2416 buffer, length, edge_bulk_out_cmd_callback, edge_port);
1da177e4 2417
cb8eaa8b 2418 edge_port->commandPending = true;
1da177e4
LT
2419 status = usb_submit_urb(urb, GFP_ATOMIC);
2420
2421 if (status) {
2422 /* something went wrong */
03f0dbf7
AC
2423 dev_err(&edge_port->port->dev,
2424 "%s - usb_submit_urb(write command) failed, status = %d\n",
2425 __func__, status);
1da177e4
LT
2426 usb_kill_urb(urb);
2427 usb_free_urb(urb);
96c706ed 2428 atomic_dec(&CmdUrbs);
1da177e4
LT
2429 return status;
2430 }
2431
03f0dbf7 2432 /* wait for command to finish */
1da177e4
LT
2433 timeout = COMMAND_TIMEOUT;
2434#if 0
03f0dbf7 2435 wait_event(&edge_port->wait_command, !edge_port->commandPending);
1da177e4 2436
cb8eaa8b 2437 if (edge_port->commandPending) {
1da177e4 2438 /* command timed out */
441b62c1 2439 dbg("%s - command timed out", __func__);
1da177e4
LT
2440 status = -EINVAL;
2441 }
2442#endif
2443 return status;
2444}
2445
2446
2447/*****************************************************************************
2448 * send_cmd_write_baud_rate
2449 * this function sends the proper command to change the baud rate of the
2450 * specified port.
2451 *****************************************************************************/
03f0dbf7
AC
2452static int send_cmd_write_baud_rate(struct edgeport_port *edge_port,
2453 int baudRate)
1da177e4 2454{
03f0dbf7
AC
2455 struct edgeport_serial *edge_serial =
2456 usb_get_serial_data(edge_port->port->serial);
1da177e4
LT
2457 unsigned char *cmdBuffer;
2458 unsigned char *currCmd;
2459 int cmdLen = 0;
2460 int divisor;
2461 int status;
03f0dbf7
AC
2462 unsigned char number =
2463 edge_port->port->number - edge_port->port->serial->minor;
1da177e4 2464
bc71e479
AK
2465 if (edge_serial->is_epic &&
2466 !edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) {
6e8cf775
GKH
2467 dbg("SendCmdWriteBaudRate - NOT Setting baud rate for port = %d, baud = %d",
2468 edge_port->port->number, baudRate);
2469 return 0;
2470 }
2471
03f0dbf7
AC
2472 dbg("%s - port = %d, baud = %d", __func__,
2473 edge_port->port->number, baudRate);
1da177e4 2474
03f0dbf7 2475 status = calc_baud_rate_divisor(baudRate, &divisor);
1da177e4 2476 if (status) {
03f0dbf7
AC
2477 dev_err(&edge_port->port->dev, "%s - bad baud rate\n",
2478 __func__);
1da177e4
LT
2479 return status;
2480 }
2481
03f0dbf7
AC
2482 /* Alloc memory for the string of commands. */
2483 cmdBuffer = kmalloc(0x100, GFP_ATOMIC);
1da177e4 2484 if (!cmdBuffer) {
03f0dbf7
AC
2485 dev_err(&edge_port->port->dev,
2486 "%s - kmalloc(%d) failed.\n", __func__, 0x100);
1da177e4
LT
2487 return -ENOMEM;
2488 }
2489 currCmd = cmdBuffer;
2490
03f0dbf7
AC
2491 /* Enable access to divisor latch */
2492 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR, LCR_DL_ENABLE);
1da177e4 2493
03f0dbf7
AC
2494 /* Write the divisor itself */
2495 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLL, LOW8(divisor));
2496 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLM, HIGH8(divisor));
1da177e4 2497
03f0dbf7
AC
2498 /* Restore original value to disable access to divisor latch */
2499 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR,
2500 edge_port->shadowLCR);
1da177e4 2501
03f0dbf7 2502 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
1da177e4
LT
2503 if (status) {
2504 /* something bad happened, let's free up the memory */
03f0dbf7 2505 kfree(cmdBuffer);
1da177e4
LT
2506 }
2507
2508 return status;
2509}
2510
2511
2512/*****************************************************************************
2513 * calc_baud_rate_divisor
2514 * this function calculates the proper baud rate divisor for the specified
2515 * baud rate.
2516 *****************************************************************************/
03f0dbf7 2517static int calc_baud_rate_divisor(int baudrate, int *divisor)
1da177e4
LT
2518{
2519 int i;
2520 __u16 custom;
2521
2522
441b62c1 2523 dbg("%s - %d", __func__, baudrate);
1da177e4 2524
52950ed4 2525 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) {
03f0dbf7 2526 if (divisor_table[i].BaudRate == baudrate) {
1da177e4
LT
2527 *divisor = divisor_table[i].Divisor;
2528 return 0;
2529 }
2530 }
2531
03f0dbf7
AC
2532 /* We have tried all of the standard baud rates
2533 * lets try to calculate the divisor for this baud rate
2534 * Make sure the baud rate is reasonable */
1da177e4 2535 if (baudrate > 50 && baudrate < 230400) {
03f0dbf7 2536 /* get divisor */
1da177e4
LT
2537 custom = (__u16)((230400L + baudrate/2) / baudrate);
2538
2539 *divisor = custom;
2540
441b62c1 2541 dbg("%s - Baud %d = %d\n", __func__, baudrate, custom);
1da177e4
LT
2542 return 0;
2543 }
2544
2545 return -1;
2546}
2547
2548
2549/*****************************************************************************
2550 * send_cmd_write_uart_register
03f0dbf7 2551 * this function builds up a uart register message and sends to to the device.
1da177e4 2552 *****************************************************************************/
03f0dbf7
AC
2553static int send_cmd_write_uart_register(struct edgeport_port *edge_port,
2554 __u8 regNum, __u8 regValue)
1da177e4 2555{
03f0dbf7
AC
2556 struct edgeport_serial *edge_serial =
2557 usb_get_serial_data(edge_port->port->serial);
1da177e4
LT
2558 unsigned char *cmdBuffer;
2559 unsigned char *currCmd;
2560 unsigned long cmdLen = 0;
2561 int status;
2562
03f0dbf7
AC
2563 dbg("%s - write to %s register 0x%02x",
2564 (regNum == MCR) ? "MCR" : "LCR", __func__, regValue);
1da177e4 2565
bc71e479
AK
2566 if (edge_serial->is_epic &&
2567 !edge_serial->epic_descriptor.Supports.IOSPWriteMCR &&
2568 regNum == MCR) {
beb7dd86 2569 dbg("SendCmdWriteUartReg - Not writing to MCR Register");
6e8cf775
GKH
2570 return 0;
2571 }
2572
bc71e479
AK
2573 if (edge_serial->is_epic &&
2574 !edge_serial->epic_descriptor.Supports.IOSPWriteLCR &&
2575 regNum == LCR) {
03f0dbf7 2576 dbg("SendCmdWriteUartReg - Not writing to LCR Register");
6e8cf775
GKH
2577 return 0;
2578 }
2579
03f0dbf7
AC
2580 /* Alloc memory for the string of commands. */
2581 cmdBuffer = kmalloc(0x10, GFP_ATOMIC);
2582 if (cmdBuffer == NULL)
1da177e4 2583 return -ENOMEM;
1da177e4
LT
2584
2585 currCmd = cmdBuffer;
2586
03f0dbf7
AC
2587 /* Build a cmd in the buffer to write the given register */
2588 MAKE_CMD_WRITE_REG(&currCmd, &cmdLen,
2589 edge_port->port->number - edge_port->port->serial->minor,
2590 regNum, regValue);
1da177e4
LT
2591
2592 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
2593 if (status) {
2594 /* something bad happened, let's free up the memory */
03f0dbf7 2595 kfree(cmdBuffer);
1da177e4
LT
2596 }
2597
2598 return status;
2599}
2600
2601
2602/*****************************************************************************
2603 * change_port_settings
03f0dbf7
AC
2604 * This routine is called to set the UART on the device to match the
2605 * specified new settings.
1da177e4 2606 *****************************************************************************/
95da310e
AC
2607
2608static void change_port_settings(struct tty_struct *tty,
2609 struct edgeport_port *edge_port, struct ktermios *old_termios)
1da177e4 2610{
03f0dbf7
AC
2611 struct edgeport_serial *edge_serial =
2612 usb_get_serial_data(edge_port->port->serial);
1da177e4
LT
2613 int baud;
2614 unsigned cflag;
2615 __u8 mask = 0xff;
2616 __u8 lData;
2617 __u8 lParity;
2618 __u8 lStop;
2619 __u8 rxFlow;
2620 __u8 txFlow;
2621 int status;
2622
441b62c1 2623 dbg("%s - port %d", __func__, edge_port->port->number);
1da177e4 2624
cb8eaa8b
RK
2625 if (!edge_port->open &&
2626 !edge_port->openPending) {
441b62c1 2627 dbg("%s - port not opened", __func__);
1da177e4
LT
2628 return;
2629 }
2630
1da177e4
LT
2631 cflag = tty->termios->c_cflag;
2632
2633 switch (cflag & CSIZE) {
03f0dbf7
AC
2634 case CS5:
2635 lData = LCR_BITS_5; mask = 0x1f;
2636 dbg("%s - data bits = 5", __func__);
2637 break;
2638 case CS6:
2639 lData = LCR_BITS_6; mask = 0x3f;
2640 dbg("%s - data bits = 6", __func__);
2641 break;
2642 case CS7:
2643 lData = LCR_BITS_7; mask = 0x7f;
2644 dbg("%s - data bits = 7", __func__);
2645 break;
2646 default:
2647 case CS8:
2648 lData = LCR_BITS_8;
2649 dbg("%s - data bits = 8", __func__);
2650 break;
1da177e4
LT
2651 }
2652
2653 lParity = LCR_PAR_NONE;
2654 if (cflag & PARENB) {
2655 if (cflag & CMSPAR) {
2656 if (cflag & PARODD) {
2657 lParity = LCR_PAR_MARK;
441b62c1 2658 dbg("%s - parity = mark", __func__);
1da177e4
LT
2659 } else {
2660 lParity = LCR_PAR_SPACE;
441b62c1 2661 dbg("%s - parity = space", __func__);
1da177e4
LT
2662 }
2663 } else if (cflag & PARODD) {
2664 lParity = LCR_PAR_ODD;
441b62c1 2665 dbg("%s - parity = odd", __func__);
1da177e4
LT
2666 } else {
2667 lParity = LCR_PAR_EVEN;
441b62c1 2668 dbg("%s - parity = even", __func__);
1da177e4
LT
2669 }
2670 } else {
441b62c1 2671 dbg("%s - parity = none", __func__);
1da177e4
LT
2672 }
2673
2674 if (cflag & CSTOPB) {
2675 lStop = LCR_STOP_2;
441b62c1 2676 dbg("%s - stop bits = 2", __func__);
1da177e4
LT
2677 } else {
2678 lStop = LCR_STOP_1;
441b62c1 2679 dbg("%s - stop bits = 1", __func__);
1da177e4
LT
2680 }
2681
2682 /* figure out the flow control settings */
2683 rxFlow = txFlow = 0x00;
2684 if (cflag & CRTSCTS) {
2685 rxFlow |= IOSP_RX_FLOW_RTS;
2686 txFlow |= IOSP_TX_FLOW_CTS;
441b62c1 2687 dbg("%s - RTS/CTS is enabled", __func__);
1da177e4 2688 } else {
441b62c1 2689 dbg("%s - RTS/CTS is disabled", __func__);
1da177e4
LT
2690 }
2691
03f0dbf7
AC
2692 /* if we are implementing XON/XOFF, set the start and stop character
2693 in the device */
1da177e4
LT
2694 if (I_IXOFF(tty) || I_IXON(tty)) {
2695 unsigned char stop_char = STOP_CHAR(tty);
2696 unsigned char start_char = START_CHAR(tty);
2697
6e8cf775
GKH
2698 if ((!edge_serial->is_epic) ||
2699 ((edge_serial->is_epic) &&
2700 (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) {
03f0dbf7
AC
2701 send_iosp_ext_cmd(edge_port,
2702 IOSP_CMD_SET_XON_CHAR, start_char);
2703 send_iosp_ext_cmd(edge_port,
2704 IOSP_CMD_SET_XOFF_CHAR, stop_char);
6e8cf775 2705 }
1da177e4
LT
2706
2707 /* if we are implementing INBOUND XON/XOFF */
2708 if (I_IXOFF(tty)) {
2709 rxFlow |= IOSP_RX_FLOW_XON_XOFF;
03f0dbf7
AC
2710 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2711 __func__, start_char, stop_char);
1da177e4 2712 } else {
441b62c1 2713 dbg("%s - INBOUND XON/XOFF is disabled", __func__);
1da177e4
LT
2714 }
2715
2716 /* if we are implementing OUTBOUND XON/XOFF */
2717 if (I_IXON(tty)) {
2718 txFlow |= IOSP_TX_FLOW_XON_XOFF;
03f0dbf7
AC
2719 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2720 __func__, start_char, stop_char);
1da177e4 2721 } else {
441b62c1 2722 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__);
1da177e4
LT
2723 }
2724 }
2725
2726 /* Set flow control to the configured value */
6e8cf775
GKH
2727 if ((!edge_serial->is_epic) ||
2728 ((edge_serial->is_epic) &&
2729 (edge_serial->epic_descriptor.Supports.IOSPSetRxFlow)))
2730 send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_RX_FLOW, rxFlow);
2731 if ((!edge_serial->is_epic) ||
2732 ((edge_serial->is_epic) &&
2733 (edge_serial->epic_descriptor.Supports.IOSPSetTxFlow)))
2734 send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_TX_FLOW, txFlow);
1da177e4
LT
2735
2736
2737 edge_port->shadowLCR &= ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
2738 edge_port->shadowLCR |= (lData | lParity | lStop);
2739
2740 edge_port->validDataMask = mask;
2741
2742 /* Send the updated LCR value to the EdgePort */
03f0dbf7
AC
2743 status = send_cmd_write_uart_register(edge_port, LCR,
2744 edge_port->shadowLCR);
2745 if (status != 0)
1da177e4 2746 return;
1da177e4
LT
2747
2748 /* set up the MCR register and send it to the EdgePort */
2749 edge_port->shadowMCR = MCR_MASTER_IE;
03f0dbf7 2750 if (cflag & CBAUD)
1da177e4 2751 edge_port->shadowMCR |= (MCR_DTR | MCR_RTS);
03f0dbf7
AC
2752
2753 status = send_cmd_write_uart_register(edge_port, MCR,
2754 edge_port->shadowMCR);
2755 if (status != 0)
1da177e4 2756 return;
1da177e4
LT
2757
2758 /* Determine divisor based on baud rate */
2759 baud = tty_get_baud_rate(tty);
2760 if (!baud) {
2761 /* pick a default, any default... */
2762 baud = 9600;
2763 }
2764
441b62c1 2765 dbg("%s - baud rate = %d", __func__, baud);
03f0dbf7 2766 status = send_cmd_write_baud_rate(edge_port, baud);
6ce073bd
AC
2767 if (status == -1) {
2768 /* Speed change was not possible - put back the old speed */
2769 baud = tty_termios_baud_rate(old_termios);
2770 tty_encode_baud_rate(tty, baud, baud);
2771 }
1da177e4
LT
2772 return;
2773}
2774
2775
2776/****************************************************************************
2777 * unicode_to_ascii
2778 * Turns a string from Unicode into ASCII.
2779 * Doesn't do a good job with any characters that are outside the normal
2780 * ASCII range, but it's only for debugging...
2781 * NOTE: expects the unicode in LE format
2782 ****************************************************************************/
03f0dbf7
AC
2783static void unicode_to_ascii(char *string, int buflen,
2784 __le16 *unicode, int unicode_size)
1da177e4
LT
2785{
2786 int i;
2787
ad93375a 2788 if (buflen <= 0) /* never happens, but... */
1da177e4 2789 return;
ad93375a 2790 --buflen; /* space for nul */
1da177e4 2791
ad93375a
PZ
2792 for (i = 0; i < unicode_size; i++) {
2793 if (i >= buflen)
2794 break;
1da177e4 2795 string[i] = (char)(le16_to_cpu(unicode[i]));
ad93375a
PZ
2796 }
2797 string[i] = 0x00;
1da177e4
LT
2798}
2799
2800
2801/****************************************************************************
2802 * get_manufacturing_desc
03f0dbf7 2803 * reads in the manufacturing descriptor and stores it into the serial
1da177e4
LT
2804 * structure.
2805 ****************************************************************************/
03f0dbf7 2806static void get_manufacturing_desc(struct edgeport_serial *edge_serial)
1da177e4
LT
2807{
2808 int response;
2809
2810 dbg("getting manufacturer descriptor");
2811
03f0dbf7
AC
2812 response = rom_read(edge_serial->serial,
2813 (EDGE_MANUF_DESC_ADDR & 0xffff0000) >> 16,
2814 (__u16)(EDGE_MANUF_DESC_ADDR & 0x0000ffff),
2815 EDGE_MANUF_DESC_LEN,
2816 (__u8 *)(&edge_serial->manuf_descriptor));
1da177e4 2817
03f0dbf7
AC
2818 if (response < 1)
2819 dev_err(&edge_serial->serial->dev->dev,
2820 "error in getting manufacturer descriptor\n");
2821 else {
1da177e4
LT
2822 char string[30];
2823 dbg("**Manufacturer Descriptor");
03f0dbf7
AC
2824 dbg(" RomSize: %dK",
2825 edge_serial->manuf_descriptor.RomSize);
2826 dbg(" RamSize: %dK",
2827 edge_serial->manuf_descriptor.RamSize);
2828 dbg(" CpuRev: %d",
2829 edge_serial->manuf_descriptor.CpuRev);
2830 dbg(" BoardRev: %d",
2831 edge_serial->manuf_descriptor.BoardRev);
2832 dbg(" NumPorts: %d",
2833 edge_serial->manuf_descriptor.NumPorts);
2834 dbg(" DescDate: %d/%d/%d",
2835 edge_serial->manuf_descriptor.DescDate[0],
2836 edge_serial->manuf_descriptor.DescDate[1],
2837 edge_serial->manuf_descriptor.DescDate[2]+1900);
4bc203d9 2838 unicode_to_ascii(string, sizeof(string),
03f0dbf7
AC
2839 edge_serial->manuf_descriptor.SerialNumber,
2840 edge_serial->manuf_descriptor.SerNumLength/2);
1da177e4 2841 dbg(" SerialNumber: %s", string);
4bc203d9 2842 unicode_to_ascii(string, sizeof(string),
03f0dbf7
AC
2843 edge_serial->manuf_descriptor.AssemblyNumber,
2844 edge_serial->manuf_descriptor.AssemblyNumLength/2);
1da177e4 2845 dbg(" AssemblyNumber: %s", string);
4bc203d9 2846 unicode_to_ascii(string, sizeof(string),
ad93375a
PZ
2847 edge_serial->manuf_descriptor.OemAssyNumber,
2848 edge_serial->manuf_descriptor.OemAssyNumLength/2);
1da177e4 2849 dbg(" OemAssyNumber: %s", string);
03f0dbf7
AC
2850 dbg(" UartType: %d",
2851 edge_serial->manuf_descriptor.UartType);
2852 dbg(" IonPid: %d",
2853 edge_serial->manuf_descriptor.IonPid);
2854 dbg(" IonConfig: %d",
2855 edge_serial->manuf_descriptor.IonConfig);
1da177e4
LT
2856 }
2857}
2858
2859
2860/****************************************************************************
2861 * get_boot_desc
03f0dbf7 2862 * reads in the bootloader descriptor and stores it into the serial
1da177e4
LT
2863 * structure.
2864 ****************************************************************************/
03f0dbf7 2865static void get_boot_desc(struct edgeport_serial *edge_serial)
1da177e4
LT
2866{
2867 int response;
2868
2869 dbg("getting boot descriptor");
2870
03f0dbf7
AC
2871 response = rom_read(edge_serial->serial,
2872 (EDGE_BOOT_DESC_ADDR & 0xffff0000) >> 16,
2873 (__u16)(EDGE_BOOT_DESC_ADDR & 0x0000ffff),
2874 EDGE_BOOT_DESC_LEN,
2875 (__u8 *)(&edge_serial->boot_descriptor));
1da177e4 2876
03f0dbf7
AC
2877 if (response < 1)
2878 dev_err(&edge_serial->serial->dev->dev,
2879 "error in getting boot descriptor\n");
2880 else {
1da177e4 2881 dbg("**Boot Descriptor:");
03f0dbf7
AC
2882 dbg(" BootCodeLength: %d",
2883 le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength));
2884 dbg(" MajorVersion: %d",
2885 edge_serial->boot_descriptor.MajorVersion);
2886 dbg(" MinorVersion: %d",
2887 edge_serial->boot_descriptor.MinorVersion);
2888 dbg(" BuildNumber: %d",
2889 le16_to_cpu(edge_serial->boot_descriptor.BuildNumber));
2890 dbg(" Capabilities: 0x%x",
2891 le16_to_cpu(edge_serial->boot_descriptor.Capabilities));
2892 dbg(" UConfig0: %d",
2893 edge_serial->boot_descriptor.UConfig0);
2894 dbg(" UConfig1: %d",
2895 edge_serial->boot_descriptor.UConfig1);
1da177e4
LT
2896 }
2897}
2898
2899
2900/****************************************************************************
2901 * load_application_firmware
2902 * This is called to load the application firmware to the device
2903 ****************************************************************************/
03f0dbf7 2904static void load_application_firmware(struct edgeport_serial *edge_serial)
1da177e4 2905{
5b9ea932
JS
2906 const struct ihex_binrec *rec;
2907 const struct firmware *fw;
2908 const char *fw_name;
2909 const char *fw_info;
1da177e4 2910 int response;
5b9ea932
JS
2911 __u32 Operaddr;
2912 __u16 build;
1da177e4
LT
2913
2914 switch (edge_serial->product_info.iDownloadFile) {
2915 case EDGE_DOWNLOAD_FILE_I930:
5b9ea932
JS
2916 fw_info = "downloading firmware version (930)";
2917 fw_name = "edgeport/down.fw";
1da177e4
LT
2918 break;
2919
2920 case EDGE_DOWNLOAD_FILE_80251:
5b9ea932
JS
2921 fw_info = "downloading firmware version (80251)";
2922 fw_name = "edgeport/down2.fw";
1da177e4
LT
2923 break;
2924
2925 case EDGE_DOWNLOAD_FILE_NONE:
2926 dbg ("No download file specified, skipping download\n");
2927 return;
2928
2929 default:
2930 return;
2931 }
2932
5b9ea932
JS
2933 response = request_ihex_firmware(&fw, fw_name,
2934 &edge_serial->serial->dev->dev);
2935 if (response) {
2936 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
2937 fw_name, response);
2938 return;
2939 }
2940
2941 rec = (const struct ihex_binrec *)fw->data;
2942 build = (rec->data[2] << 8) | rec->data[3];
2943
2944 dbg("%s %d.%d.%d", fw_info, rec->data[0], rec->data[1], build);
2945
2946 edge_serial->product_info.FirmwareMajorVersion = fw->data[0];
2947 edge_serial->product_info.FirmwareMinorVersion = fw->data[1];
2948 edge_serial->product_info.FirmwareBuildNumber = cpu_to_le16(build);
1da177e4 2949
5b9ea932
JS
2950 for (rec = ihex_next_binrec(rec); rec;
2951 rec = ihex_next_binrec(rec)) {
2952 Operaddr = be32_to_cpu(rec->addr);
2953 response = sram_write(edge_serial->serial,
2954 Operaddr >> 16,
2955 Operaddr & 0xFFFF,
2956 be16_to_cpu(rec->len),
2957 &rec->data[0]);
1da177e4 2958 if (response < 0) {
5b9ea932
JS
2959 dev_err(&edge_serial->serial->dev->dev,
2960 "sram_write failed (%x, %x, %d)\n",
2961 Operaddr >> 16, Operaddr & 0xFFFF,
2962 be16_to_cpu(rec->len));
1da177e4
LT
2963 break;
2964 }
2965 }
2966
2967 dbg("sending exec_dl_code");
2968 response = usb_control_msg (edge_serial->serial->dev,
2969 usb_sndctrlpipe(edge_serial->serial->dev, 0),
2970 USB_REQUEST_ION_EXEC_DL_CODE,
2971 0x40, 0x4000, 0x0001, NULL, 0, 3000);
2972
5b9ea932 2973 release_firmware(fw);
1da177e4
LT
2974 return;
2975}
2976
2977
2978/****************************************************************************
2979 * edge_startup
2980 ****************************************************************************/
03f0dbf7 2981static int edge_startup(struct usb_serial *serial)
1da177e4
LT
2982{
2983 struct edgeport_serial *edge_serial;
2984 struct edgeport_port *edge_port;
2985 struct usb_device *dev;
bfd5df3c 2986 int i, j;
6e8cf775 2987 int response;
cb8eaa8b
RK
2988 bool interrupt_in_found;
2989 bool bulk_in_found;
2990 bool bulk_out_found;
6e8cf775
GKH
2991 static __u32 descriptor[3] = { EDGE_COMPATIBILITY_MASK0,
2992 EDGE_COMPATIBILITY_MASK1,
2993 EDGE_COMPATIBILITY_MASK2 };
1da177e4
LT
2994
2995 dev = serial->dev;
2996
2997 /* create our private serial structure */
80b6ca48 2998 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
1da177e4 2999 if (edge_serial == NULL) {
441b62c1 3000 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
1da177e4
LT
3001 return -ENOMEM;
3002 }
1da177e4
LT
3003 spin_lock_init(&edge_serial->es_lock);
3004 edge_serial->serial = serial;
3005 usb_set_serial_data(serial, edge_serial);
3006
3007 /* get the name for the device from the device */
ad93375a
PZ
3008 i = get_string(dev, dev->descriptor.iManufacturer,
3009 &edge_serial->name[0], MAX_NAME_LEN+1);
3010 edge_serial->name[i++] = ' ';
3011 get_string(dev, dev->descriptor.iProduct,
3012 &edge_serial->name[i], MAX_NAME_LEN+2 - i);
1da177e4
LT
3013
3014 dev_info(&serial->dev->dev, "%s detected\n", edge_serial->name);
3015
6e8cf775
GKH
3016 /* Read the epic descriptor */
3017 if (get_epic_descriptor(edge_serial) <= 0) {
3018 /* memcpy descriptor to Supports structures */
3019 memcpy(&edge_serial->epic_descriptor.Supports, descriptor,
3020 sizeof(struct edge_compatibility_bits));
1da177e4 3021
6e8cf775 3022 /* get the manufacturing descriptor for this device */
03f0dbf7 3023 get_manufacturing_desc(edge_serial);
1da177e4 3024
6e8cf775 3025 /* get the boot descriptor */
03f0dbf7 3026 get_boot_desc(edge_serial);
6e8cf775
GKH
3027
3028 get_product_info(edge_serial);
3029 }
1da177e4
LT
3030
3031 /* set the number of ports from the manufacturing description */
3032 /* serial->num_ports = serial->product_info.NumPorts; */
6e8cf775
GKH
3033 if ((!edge_serial->is_epic) &&
3034 (edge_serial->product_info.NumPorts != serial->num_ports)) {
3035 dev_warn(&serial->dev->dev, "Device Reported %d serial ports "
3036 "vs. core thinking we have %d ports, email "
898eb71c 3037 "greg@kroah.com this information.\n",
6e8cf775
GKH
3038 edge_serial->product_info.NumPorts,
3039 serial->num_ports);
1da177e4
LT
3040 }
3041
441b62c1 3042 dbg("%s - time 1 %ld", __func__, jiffies);
1da177e4 3043
6e8cf775
GKH
3044 /* If not an EPiC device */
3045 if (!edge_serial->is_epic) {
3046 /* now load the application firmware into this device */
03f0dbf7 3047 load_application_firmware(edge_serial);
1da177e4 3048
441b62c1 3049 dbg("%s - time 2 %ld", __func__, jiffies);
1da177e4 3050
6e8cf775 3051 /* Check current Edgeport EEPROM and update if necessary */
03f0dbf7 3052 update_edgeport_E2PROM(edge_serial);
1da177e4 3053
441b62c1 3054 dbg("%s - time 3 %ld", __func__, jiffies);
6e8cf775
GKH
3055
3056 /* set the configuration to use #1 */
03f0dbf7
AC
3057/* dbg("set_configuration 1"); */
3058/* usb_set_configuration (dev, 1); */
6e8cf775 3059 }
5b9ea932
JS
3060 dbg(" FirmwareMajorVersion %d.%d.%d",
3061 edge_serial->product_info.FirmwareMajorVersion,
3062 edge_serial->product_info.FirmwareMinorVersion,
3063 le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber));
1da177e4 3064
03f0dbf7 3065 /* we set up the pointers to the endpoints in the edge_open function,
1da177e4
LT
3066 * as the structures aren't created yet. */
3067
3068 /* set up our port private structures */
3069 for (i = 0; i < serial->num_ports; ++i) {
03f0dbf7 3070 edge_port = kmalloc(sizeof(struct edgeport_port), GFP_KERNEL);
1da177e4 3071 if (edge_port == NULL) {
03f0dbf7
AC
3072 dev_err(&serial->dev->dev, "%s - Out of memory\n",
3073 __func__);
bfd5df3c 3074 for (j = 0; j < i; ++j) {
03f0dbf7
AC
3075 kfree(usb_get_serial_port_data(serial->port[j]));
3076 usb_set_serial_port_data(serial->port[j],
3077 NULL);
bfd5df3c 3078 }
1da177e4
LT
3079 usb_set_serial_data(serial, NULL);
3080 kfree(edge_serial);
3081 return -ENOMEM;
3082 }
03f0dbf7 3083 memset(edge_port, 0, sizeof(struct edgeport_port));
1da177e4
LT
3084 spin_lock_init(&edge_port->ep_lock);
3085 edge_port->port = serial->port[i];
3086 usb_set_serial_port_data(serial->port[i], edge_port);
3087 }
6e8cf775
GKH
3088
3089 response = 0;
3090
3091 if (edge_serial->is_epic) {
03f0dbf7
AC
3092 /* EPIC thing, set up our interrupt polling now and our read
3093 * urb, so that the device knows it really is connected. */
cb8eaa8b 3094 interrupt_in_found = bulk_in_found = bulk_out_found = false;
03f0dbf7
AC
3095 for (i = 0; i < serial->interface->altsetting[0]
3096 .desc.bNumEndpoints; ++i) {
6e8cf775
GKH
3097 struct usb_endpoint_descriptor *endpoint;
3098 int buffer_size;
3099
03f0dbf7
AC
3100 endpoint = &serial->interface->altsetting[0].
3101 endpoint[i].desc;
6e8cf775 3102 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
cb8eaa8b 3103 if (!interrupt_in_found &&
6e8cf775
GKH
3104 (usb_endpoint_is_int_in(endpoint))) {
3105 /* we found a interrupt in endpoint */
3106 dbg("found interrupt in");
3107
3108 /* not set up yet, so do it now */
03f0dbf7
AC
3109 edge_serial->interrupt_read_urb =
3110 usb_alloc_urb(0, GFP_KERNEL);
6e8cf775
GKH
3111 if (!edge_serial->interrupt_read_urb) {
3112 err("out of memory");
3113 return -ENOMEM;
3114 }
03f0dbf7
AC
3115 edge_serial->interrupt_in_buffer =
3116 kmalloc(buffer_size, GFP_KERNEL);
6e8cf775
GKH
3117 if (!edge_serial->interrupt_in_buffer) {
3118 err("out of memory");
3119 usb_free_urb(edge_serial->interrupt_read_urb);
3120 return -ENOMEM;
3121 }
03f0dbf7
AC
3122 edge_serial->interrupt_in_endpoint =
3123 endpoint->bEndpointAddress;
6e8cf775
GKH
3124
3125 /* set up our interrupt urb */
03f0dbf7
AC
3126 usb_fill_int_urb(
3127 edge_serial->interrupt_read_urb,
3128 dev,
3129 usb_rcvintpipe(dev,
3130 endpoint->bEndpointAddress),
3131 edge_serial->interrupt_in_buffer,
3132 buffer_size,
3133 edge_interrupt_callback,
3134 edge_serial,
3135 endpoint->bInterval);
6e8cf775 3136
cb8eaa8b 3137 interrupt_in_found = true;
6e8cf775
GKH
3138 }
3139
cb8eaa8b 3140 if (!bulk_in_found &&
03f0dbf7 3141 (usb_endpoint_is_bulk_in(endpoint))) {
6e8cf775
GKH
3142 /* we found a bulk in endpoint */
3143 dbg("found bulk in");
3144
3145 /* not set up yet, so do it now */
03f0dbf7
AC
3146 edge_serial->read_urb =
3147 usb_alloc_urb(0, GFP_KERNEL);
6e8cf775
GKH
3148 if (!edge_serial->read_urb) {
3149 err("out of memory");
3150 return -ENOMEM;
3151 }
03f0dbf7
AC
3152 edge_serial->bulk_in_buffer =
3153 kmalloc(buffer_size, GFP_KERNEL);
6e8cf775 3154 if (!edge_serial->bulk_in_buffer) {
03f0dbf7 3155 err("out of memory");
6e8cf775
GKH
3156 usb_free_urb(edge_serial->read_urb);
3157 return -ENOMEM;
3158 }
03f0dbf7
AC
3159 edge_serial->bulk_in_endpoint =
3160 endpoint->bEndpointAddress;
6e8cf775
GKH
3161
3162 /* set up our bulk in urb */
3163 usb_fill_bulk_urb(edge_serial->read_urb, dev,
03f0dbf7
AC
3164 usb_rcvbulkpipe(dev,
3165 endpoint->bEndpointAddress),
3166 edge_serial->bulk_in_buffer,
3167 le16_to_cpu(endpoint->wMaxPacketSize),
3168 edge_bulk_in_callback,
3169 edge_serial);
cb8eaa8b 3170 bulk_in_found = true;
6e8cf775
GKH
3171 }
3172
cb8eaa8b 3173 if (!bulk_out_found &&
6e8cf775
GKH
3174 (usb_endpoint_is_bulk_out(endpoint))) {
3175 /* we found a bulk out endpoint */
3176 dbg("found bulk out");
03f0dbf7
AC
3177 edge_serial->bulk_out_endpoint =
3178 endpoint->bEndpointAddress;
cb8eaa8b 3179 bulk_out_found = true;
6e8cf775
GKH
3180 }
3181 }
3182
cb8eaa8b 3183 if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) {
03f0dbf7 3184 err("Error - the proper endpoints were not found!");
6e8cf775
GKH
3185 return -ENODEV;
3186 }
3187
3188 /* start interrupt read for this edgeport this interrupt will
3189 * continue as long as the edgeport is connected */
03f0dbf7
AC
3190 response = usb_submit_urb(edge_serial->interrupt_read_urb,
3191 GFP_KERNEL);
6e8cf775 3192 if (response)
03f0dbf7
AC
3193 err("%s - Error %d submitting control urb",
3194 __func__, response);
6e8cf775
GKH
3195 }
3196 return response;
1da177e4
LT
3197}
3198
3199
3200/****************************************************************************
3201 * edge_shutdown
3202 * This function is called whenever the device is removed from the usb bus.
3203 ****************************************************************************/
03f0dbf7 3204static void edge_shutdown(struct usb_serial *serial)
1da177e4 3205{
6e8cf775 3206 struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
1da177e4
LT
3207 int i;
3208
441b62c1 3209 dbg("%s", __func__);
1da177e4
LT
3210
3211 /* stop reads and writes on all ports */
03f0dbf7
AC
3212 for (i = 0; i < serial->num_ports; ++i) {
3213 kfree(usb_get_serial_port_data(serial->port[i]));
1da177e4
LT
3214 usb_set_serial_port_data(serial->port[i], NULL);
3215 }
6e8cf775
GKH
3216 /* free up our endpoint stuff */
3217 if (edge_serial->is_epic) {
74ac07e8 3218 usb_kill_urb(edge_serial->interrupt_read_urb);
6e8cf775
GKH
3219 usb_free_urb(edge_serial->interrupt_read_urb);
3220 kfree(edge_serial->interrupt_in_buffer);
3221
74ac07e8 3222 usb_kill_urb(edge_serial->read_urb);
6e8cf775
GKH
3223 usb_free_urb(edge_serial->read_urb);
3224 kfree(edge_serial->bulk_in_buffer);
3225 }
3226
3227 kfree(edge_serial);
1da177e4
LT
3228 usb_set_serial_data(serial, NULL);
3229}
3230
3231
3232/****************************************************************************
3233 * edgeport_init
3234 * This is called by the module subsystem, or on startup to initialize us
3235 ****************************************************************************/
3236static int __init edgeport_init(void)
3237{
3238 int retval;
3239
3240 retval = usb_serial_register(&edgeport_2port_device);
3241 if (retval)
3242 goto failed_2port_device_register;
3243 retval = usb_serial_register(&edgeport_4port_device);
3244 if (retval)
3245 goto failed_4port_device_register;
3246 retval = usb_serial_register(&edgeport_8port_device);
3247 if (retval)
3248 goto failed_8port_device_register;
6e8cf775
GKH
3249 retval = usb_serial_register(&epic_device);
3250 if (retval)
3251 goto failed_epic_device_register;
1da177e4 3252 retval = usb_register(&io_driver);
03f0dbf7 3253 if (retval)
1da177e4 3254 goto failed_usb_register;
96c706ed 3255 atomic_set(&CmdUrbs, 0);
c197a8db
GKH
3256 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
3257 DRIVER_DESC "\n");
1da177e4
LT
3258 return 0;
3259
3260failed_usb_register:
6e8cf775
GKH
3261 usb_serial_deregister(&epic_device);
3262failed_epic_device_register:
1da177e4
LT
3263 usb_serial_deregister(&edgeport_8port_device);
3264failed_8port_device_register:
3265 usb_serial_deregister(&edgeport_4port_device);
3266failed_4port_device_register:
3267 usb_serial_deregister(&edgeport_2port_device);
3268failed_2port_device_register:
3269 return retval;
3270}
3271
3272
3273/****************************************************************************
3274 * edgeport_exit
3275 * Called when the driver is about to be unloaded.
3276 ****************************************************************************/
3277static void __exit edgeport_exit (void)
3278{
03f0dbf7
AC
3279 usb_deregister(&io_driver);
3280 usb_serial_deregister(&edgeport_2port_device);
3281 usb_serial_deregister(&edgeport_4port_device);
3282 usb_serial_deregister(&edgeport_8port_device);
3283 usb_serial_deregister(&epic_device);
1da177e4
LT
3284}
3285
3286module_init(edgeport_init);
3287module_exit(edgeport_exit);
3288
3289/* Module information */
03f0dbf7
AC
3290MODULE_AUTHOR(DRIVER_AUTHOR);
3291MODULE_DESCRIPTION(DRIVER_DESC);
1da177e4 3292MODULE_LICENSE("GPL");
5b9ea932
JS
3293MODULE_FIRMWARE("edgeport/boot.fw");
3294MODULE_FIRMWARE("edgeport/boot2.fw");
3295MODULE_FIRMWARE("edgeport/down.fw");
3296MODULE_FIRMWARE("edgeport/down2.fw");
1da177e4
LT
3297
3298module_param(debug, bool, S_IRUGO | S_IWUSR);
3299MODULE_PARM_DESC(debug, "Debug enabled or not");
3300
3301module_param(low_latency, bool, S_IRUGO | S_IWUSR);
3302MODULE_PARM_DESC(low_latency, "Low latency enabled or not");
This page took 0.634418 seconds and 5 git commands to generate.