/* Transmit Fifo *ThisTransmitqueueisanextensionoftheedgeportRxbuffer. *Themaximumamountofdatabufferedinboththeedgeport *Rxbuffer(maxTxCredits)andthisbufferwillneverexceedmaxTxCredits.
*/ struct TxFifo { unsignedint head; /* index to head pointer (write) */ unsignedint tail; /* index to tail pointer (read) */ unsignedint count; /* Bytes in queue */ unsignedint size; /* Max size of queue (equal to Max number of TxCredits) */ unsignedchar *fifo; /* allocated Buffer */
};
/* This structure holds all of the local port information */ struct edgeport_port {
__u16 txCredits; /* our current credits for this port */
__u16 maxTxCredits; /* the max size of the port */
struct TxFifo txfifo; /* transmit fifo -- size will be maxTxCredits */ struct urb *write_urb; /* write URB for this port */ bool write_in_progress; /* 'true' while a write URB is outstanding */
spinlock_t ep_lock;
__u8 shadowLCR; /* last LCR value received */
__u8 shadowMCR; /* last MCR value received */
__u8 shadowMSR; /* last MSR value received */
__u8 shadowLSR; /* last LSR value received */
__u8 shadowXonChar; /* last value set as XON char in Edgeport */
__u8 shadowXoffChar; /* last value set as XOFF char in Edgeport */
__u8 validDataMask;
__u32 baudRate;
wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */
wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
struct usb_serial_port *port; /* loop back to the owner of this object */
};
/* This structure holds all of the individual device information */ struct edgeport_serial { char name[MAX_NAME_LEN+2]; /* string name of this device */
struct edge_manuf_descriptor manuf_descriptor; /* the manufacturer descriptor */ struct edge_boot_descriptor boot_descriptor; /* the boot firmware descriptor */ struct edgeport_product_info product_info; /* Product Info */ struct edge_compatibility_descriptor epic_descriptor; /* Edgeport compatible descriptor */ int is_epic; /* flag if EPiC device or not */
__u8 interrupt_in_endpoint; /* the interrupt endpoint handle */ unsignedchar *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */ struct urb *interrupt_read_urb; /* our interrupt urb */
__u8 bulk_in_endpoint; /* the bulk in endpoint handle */ unsignedchar *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ struct urb *read_urb; /* our bulk read urb */ bool read_in_progress;
spinlock_t es_lock;
__u8 bulk_out_endpoint; /* the bulk out endpoint handle */
__s16 rxBytesAvail; /* the number of bytes that we need to read from this device */
enum RXSTATE rxState; /* the current state of the bulk receive processor */
__u8 rxHeader1; /* receive header byte 1 */
__u8 rxHeader2; /* receive header byte 2 */
__u8 rxHeader3; /* receive header byte 3 */
__u8 rxPort; /* the port that we are currently receiving data for */
__u8 rxStatusCode; /* the receive status code */
__u8 rxStatusParam; /* the receive status parameter */
__s16 rxBytesRemaining; /* the number of port bytes left to read */ struct usb_serial *serial; /* loop back to the owner of this object */
};
/* check if this is 2nd generation hardware */ if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct)
& ION_DEVICE_ID_80251_NETCHIP)
product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251; else
product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930;
/* Determine Product type and set appropriate flags */ switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) { case ION_DEVICE_ID_EDGEPORT_COMPATIBLE: case ION_DEVICE_ID_EDGEPORT_4T: case ION_DEVICE_ID_EDGEPORT_4: case ION_DEVICE_ID_EDGEPORT_2: case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU: case ION_DEVICE_ID_EDGEPORT_8: case ION_DEVICE_ID_EDGEPORT_421: case ION_DEVICE_ID_EDGEPORT_21: case ION_DEVICE_ID_EDGEPORT_2_DIN: case ION_DEVICE_ID_EDGEPORT_4_DIN: case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU:
product_info->IsRS232 = 1; break;
result = 0;
} elseif (result >= 0) {
dev_warn(&serial->interface->dev, "short epic descriptor received: %d\n",
result);
result = -EIO;
}
kfree(epic);
return result;
}
/************************************************************************/ /************************************************************************/ /* U S B C A L L B A C K F U N C T I O N S */ /* U S B C A L L B A C K F U N C T I O N S */ /************************************************************************/ /************************************************************************/
/***************************************************************************** *edge_interrupt_callback *thisisthecallbackfunctionforwhenwehavereceiveddataonthe *interruptendpoint.
*****************************************************************************/ staticvoid edge_interrupt_callback(struct urb *urb)
{ struct edgeport_serial *edge_serial = urb->context; struct device *dev; struct edgeport_port *edge_port; struct usb_serial_port *port; unsignedchar *data = urb->transfer_buffer; int length = urb->actual_length; unsignedlong flags; int bytes_avail; int position; int txCredits; int portNumber; int result; int status = urb->status;
switch (status) { case0: /* success */ break; case -ECONNRESET: case -ENOENT: case -ESHUTDOWN: /* this urb is terminated, clean up */
dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status); return; default:
dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __func__, status); gotoexit;
}
dev = &edge_serial->serial->dev->dev;
/* process this interrupt-read even if there are no ports open */ if (length) {
usb_serial_debug_data(dev, __func__, length, data);
if (edge_serial->rxBytesAvail > 0 &&
!edge_serial->read_in_progress) {
dev_dbg(dev, "%s - posting a read\n", __func__);
edge_serial->read_in_progress = true;
/* we have pending bytes on the
bulk in pipe, send a request */
result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); if (result) {
dev_err(dev, "%s - usb_submit_urb(read bulk) failed with result = %d\n",
__func__, result);
edge_serial->read_in_progress = false;
}
}
spin_unlock_irqrestore(&edge_serial->es_lock,
flags);
}
} /* grab the txcredits for the ports if available */
position = 2;
portNumber = 0; while ((position < length - 1) &&
(portNumber < edge_serial->serial->num_ports)) {
txCredits = data[position] | (data[position+1] << 8); if (txCredits) {
port = edge_serial->serial->port[portNumber];
edge_port = usb_get_serial_port_data(port); if (edge_port && edge_port->open) {
spin_lock_irqsave(&edge_port->ep_lock,
flags);
edge_port->txCredits += txCredits;
spin_unlock_irqrestore(&edge_port->ep_lock,
flags);
dev_dbg(dev, "%s - txcredits for port%d = %d\n",
__func__, portNumber,
edge_port->txCredits);
/* tell the tty driver that something
has changed */
tty_port_tty_wakeup(&edge_port->port->port); /* Since we have more credit, check
if more data can be sent */
send_more_port_data(edge_serial,
edge_port);
}
}
position += 2;
++portNumber;
}
}
exit:
result = usb_submit_urb(urb, GFP_ATOMIC); if (result)
dev_err(&urb->dev->dev, "%s - Error %d submitting control urb\n",
__func__, result);
}
/* check to see if there's any more data for us to read */ if (edge_serial->rxBytesAvail > 0) {
dev_dbg(dev, "%s - posting a read\n", __func__);
retval = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); if (retval) {
dev_err(dev, "%s - usb_submit_urb(read bulk) failed, retval = %d\n",
__func__, retval);
edge_serial->read_in_progress = false;
}
} else {
edge_serial->read_in_progress = false;
}
/* see if we've set up our endpoint info yet (can't set it up
in edge_startup as the structures were not set up at that time.) */
serial = port->serial;
edge_serial = usb_get_serial_data(serial); if (edge_serial == NULL) return -ENODEV; if (edge_serial->interrupt_in_buffer == NULL) { struct usb_serial_port *port0 = serial->port[0];
/* not set up yet, so do it now */
edge_serial->interrupt_in_buffer =
port0->interrupt_in_buffer;
edge_serial->interrupt_in_endpoint =
port0->interrupt_in_endpointAddress;
edge_serial->interrupt_read_urb = port0->interrupt_in_urb;
edge_serial->bulk_in_buffer = port0->bulk_in_buffer;
edge_serial->bulk_in_endpoint =
port0->bulk_in_endpointAddress;
edge_serial->read_urb = port0->read_urb;
edge_serial->bulk_out_endpoint =
port0->bulk_out_endpointAddress;
/* set up our interrupt urb */
usb_fill_int_urb(edge_serial->interrupt_read_urb,
serial->dev,
usb_rcvintpipe(serial->dev,
port0->interrupt_in_endpointAddress),
port0->interrupt_in_buffer,
edge_serial->interrupt_read_urb->transfer_buffer_length,
edge_interrupt_callback, edge_serial,
edge_serial->interrupt_read_urb->interval);
/* set up our bulk in urb */
usb_fill_bulk_urb(edge_serial->read_urb, serial->dev,
usb_rcvbulkpipe(serial->dev,
port0->bulk_in_endpointAddress),
port0->bulk_in_buffer,
edge_serial->read_urb->transfer_buffer_length,
edge_bulk_in_callback, edge_serial);
edge_serial->read_in_progress = false;
/* start interrupt read for this edgeport *thisinterruptwillcontinueaslong
* as the edgeport is connected */
response = usb_submit_urb(edge_serial->interrupt_read_urb,
GFP_KERNEL); if (response) {
dev_err(dev, "%s - Error %d submitting control urb\n",
__func__, response);
}
}
/* initialize our port settings */
edge_port->txCredits = 0; /* Can't send any data yet */ /* Must always set this bit to enable ints! */
edge_port->shadowMCR = MCR_MASTER_IE;
edge_port->chaseResponsePending = false;
/* send a open port command */
edge_port->openPending = true;
edge_port->open = false;
response = send_iosp_ext_cmd(edge_port, IOSP_CMD_OPEN_PORT, 0);
if (response < 0) {
dev_err(dev, "%s - error sending open port command\n", __func__);
edge_port->openPending = false; return -ENODEV;
}
/* now wait for the port to be completely opened */
wait_event_timeout(edge_port->wait_open, !edge_port->openPending,
OPEN_TIMEOUT);
if (!edge_port->open) { /* open timed out */
dev_dbg(dev, "%s - open timeout\n", __func__);
edge_port->openPending = false; return -ENODEV;
}
while (1) { /* Save Last credits */
lastCredits = edge_port->txCredits;
/* Did we get our Chase response */ if (!edge_port->chaseResponsePending) {
dev_dbg(dev, "%s - Got Chase Response\n", __func__);
/* did we get all of our credit back? */ if (edge_port->txCredits == edge_port->maxTxCredits) {
dev_dbg(dev, "%s - Got all credits\n", __func__); return;
}
}
/* Block the thread for a while */
prepare_to_wait(&edge_port->wait_chase, &wait,
TASK_UNINTERRUPTIBLE);
schedule_timeout(timeout);
finish_wait(&edge_port->wait_chase, &wait);
if (lastCredits == edge_port->txCredits) { /* No activity.. count down. */
loop--; if (loop == 0) {
edge_port->chaseResponsePending = false;
dev_dbg(dev, "%s - Chase TIMEOUT\n", __func__); return;
}
} else { /* Reset timeout value back to 10 seconds */
dev_dbg(dev, "%s - Last %d, Current %d\n", __func__,
lastCredits, edge_port->txCredits);
loop = 10;
}
}
}
while (1) { /* Save Last count */
lastCount = fifo->count;
/* Is the Edgeport Buffer empty? */ if (lastCount == 0) {
dev_dbg(dev, "%s - TX Buffer Empty\n", __func__); return;
}
/* Block the thread for a while */
prepare_to_wait(&edge_port->wait_chase, &wait,
TASK_UNINTERRUPTIBLE);
schedule_timeout(timeout);
finish_wait(&edge_port->wait_chase, &wait);
dev_dbg(dev, "%s wait\n", __func__);
if (lastCount == fifo->count) { /* No activity.. count down. */
loop--; if (loop == 0) {
dev_dbg(dev, "%s - TIMEOUT\n", __func__); return;
}
} else { /* Reset timeout value back to seconds */
loop = 30;
}
}
}
/* block until tx is empty */
block_until_tx_empty(edge_port);
edge_port->closePending = true;
if (!edge_serial->is_epic ||
edge_serial->epic_descriptor.Supports.IOSPChase) { /* flush and chase */
edge_port->chaseResponsePending = true;
dev_dbg(&port->dev, "%s - Sending IOSP_CMD_CHASE_PORT\n", __func__);
status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0); if (status == 0) /* block until chase finished */
block_until_chase_response(edge_port); else
edge_port->chaseResponsePending = false;
}
if (!edge_serial->is_epic ||
edge_serial->epic_descriptor.Supports.IOSPClose) { /* close the port */
dev_dbg(&port->dev, "%s - Sending IOSP_CMD_CLOSE_PORT\n", __func__);
send_iosp_ext_cmd(edge_port, IOSP_CMD_CLOSE_PORT, 0);
}
if (edge_port->write_urb) { /* if this urb had a transfer buffer already
(old transfer) free it */
kfree(edge_port->write_urb->transfer_buffer);
usb_free_urb(edge_port->write_urb);
edge_port->write_urb = NULL;
}
kfree(edge_port->txfifo.fifo);
edge_port->txfifo.fifo = NULL;
}
/***************************************************************************** *SerialWrite *thisfunctioniscalledbythettydriverwhendatashouldbewritten *totheport. *Ifsuccessful,wereturnthenumberofbyteswritten,otherwisewe *returnanegativeerrornumber.
*****************************************************************************/ staticint edge_write(struct tty_struct *tty, struct usb_serial_port *port, constunsignedchar *data, int count)
{ struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct TxFifo *fifo; int copySize; int bytesleft; int firsthalf; int secondhalf; unsignedlong flags;
if (edge_port == NULL) return -ENODEV;
/* get a pointer to the Tx fifo */
fifo = &edge_port->txfifo;
spin_lock_irqsave(&edge_port->ep_lock, flags);
/* calculate number of bytes to put in fifo */
copySize = min_t(unsignedint, count,
(edge_port->txCredits - fifo->count));
dev_dbg(&port->dev, "%s of %d byte(s) Fifo room %d -- will copy %d bytes\n",
__func__, count, edge_port->txCredits - fifo->count, copySize);
/* catch writes of 0 bytes which the tty driver likes to give us,
and when txCredits is empty */ if (copySize == 0) {
dev_dbg(&port->dev, "%s - copySize = Zero\n", __func__); goto finish_write;
}
/* queue the data *sincewecanneveroverflowthebufferwedonothavetocheckfora *fullcondition * *thecopyisdoneistwoparts--firstfilltotheendofthebuffer *thencopytheresetfromthestartofthebuffer
*/
bytesleft = fifo->size - fifo->head;
firsthalf = min(bytesleft, copySize);
dev_dbg(&port->dev, "%s - copy %d bytes of %d into fifo \n", __func__,
firsthalf, bytesleft);
/* now copy our data */
memcpy(&fifo->fifo[fifo->head], data, firsthalf);
usb_serial_debug_data(&port->dev, __func__, firsthalf, &fifo->fifo[fifo->head]);
/* update the index and size */
fifo->head += firsthalf;
fifo->count += firsthalf;
/* wrap the index */ if (fifo->head == fifo->size)
fifo->head = 0;
secondhalf = copySize-firsthalf;
if (secondhalf) {
dev_dbg(&port->dev, "%s - copy rest of data %d\n", __func__, secondhalf);
memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf);
usb_serial_debug_data(&port->dev, __func__, secondhalf, &fifo->fifo[fifo->head]); /* update the index and size */
fifo->count += secondhalf;
fifo->head += secondhalf; /* No need to check for wrap since we can not get to end of *thefifointhispart
*/
}
/* since the amount of data in the fifo will always fit into the *edgeportbufferwedonotneedtocheckthewritelength * *Dowehaveenoughcreditsforthisporttomakeitworthwhile *tobotherqueueingawrite.Ifit'stoosmall,sayafewbytes, *it'sbettertowaitformorecreditssowecandoalargerwrite.
*/ if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits, EDGE_FW_BULK_MAX_PACKET_SIZE)) {
dev_dbg(dev, "%s Not enough credit - fifo %d TxCredit %d\n",
__func__, fifo->count, edge_port->txCredits); goto exit_send;
}
/* lock this write */
edge_port->write_in_progress = true;
/* get a pointer to the write_urb */
urb = edge_port->write_urb;
/* make sure transfer buffer is freed */
kfree(urb->transfer_buffer);
urb->transfer_buffer = NULL;
/* build the data header for the buffer and port that we are about
to send out */
count = fifo->count;
buffer = kmalloc(count+2, GFP_ATOMIC); if (!buffer) {
edge_port->write_in_progress = false; goto exit_send;
}
buffer[0] = IOSP_BUILD_DATA_HDR1(edge_port->port->port_number, count);
buffer[1] = IOSP_BUILD_DATA_HDR2(edge_port->port->port_number, count);
if (count)
usb_serial_debug_data(&edge_port->port->dev, __func__, count, &buffer[2]);
/* fill up the urb with all of our data and submit it */
usb_fill_bulk_urb(urb, edge_serial->serial->dev,
usb_sndbulkpipe(edge_serial->serial->dev,
edge_serial->bulk_out_endpoint),
buffer, count+2,
edge_bulk_out_data_callback, edge_port);
/* decrement the number of credits we have by the number we just sent */
edge_port->txCredits -= count;
edge_port->port->icount.tx += count;
status = usb_submit_urb(urb, GFP_ATOMIC); if (status) { /* something went wrong */
dev_err_console(edge_port->port, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n",
__func__, status);
edge_port->write_in_progress = false;
/* revert the credits as something bad happened. */
edge_port->txCredits += count;
edge_port->port->icount.tx -= count;
}
dev_dbg(dev, "%s wrote %d byte(s) TxCredit %d, Fifo %d\n",
__func__, count, edge_port->txCredits, fifo->count);
/* total of both buffers is still txCredit */
spin_lock_irqsave(&edge_port->ep_lock, flags);
room = edge_port->txCredits - edge_port->txfifo.count;
spin_unlock_irqrestore(&edge_port->ep_lock, flags);
if (!edge_port->open) {
dev_dbg(&port->dev, "%s - port not opened\n", __func__); return;
}
/* if we are implementing XON/XOFF, send the stop character */ if (I_IXOFF(tty)) { unsignedchar stop_char = STOP_CHAR(tty);
status = edge_write(tty, port, &stop_char, 1); if (status <= 0) return;
}
/* if we are implementing RTS/CTS, toggle that line */ if (C_CRTSCTS(tty)) {
edge_port->shadowMCR &= ~MCR_RTS;
status = send_cmd_write_uart_register(edge_port, MCR,
edge_port->shadowMCR); if (status != 0) return;
}
}
if (!edge_port->open) {
dev_dbg(&port->dev, "%s - port not opened\n", __func__); return;
}
/* if we are implementing XON/XOFF, send the start character */ if (I_IXOFF(tty)) { unsignedchar start_char = START_CHAR(tty);
status = edge_write(tty, port, &start_char, 1); if (status <= 0) return;
} /* if we are implementing RTS/CTS, toggle that line */ if (C_CRTSCTS(tty)) {
edge_port->shadowMCR |= MCR_RTS;
send_cmd_write_uart_register(edge_port, MCR,
edge_port->shadowMCR);
}
}
while (bufferLength > 0) { /* failsafe incase we get a message that we don't understand */ if (lastBufferLength == bufferLength) {
dev_dbg(dev, "%s - stuck in loop, exiting it.\n", __func__); break;
}
lastBufferLength = bufferLength;
switch (edge_serial->rxState) { case EXPECT_HDR1:
edge_serial->rxHeader1 = *buffer;
++buffer;
--bufferLength;
if (bufferLength == 0) {
edge_serial->rxState = EXPECT_HDR2; break;
}
fallthrough; case EXPECT_HDR2:
edge_serial->rxHeader2 = *buffer;
++buffer;
--bufferLength;
dev_dbg(dev, "%s - Hdr1=%02X Hdr2=%02X\n", __func__,
edge_serial->rxHeader1, edge_serial->rxHeader2); /* Process depending on whether this header is
* data or status */
if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) { /* Decode this status header and go to *EXPECT_HDR1(ifwecanprocessthestatus *withonly2bytes),orgotoEXPECT_HDR3to
* get the third byte. */
edge_serial->rxPort =
IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
edge_serial->rxStatusCode =
IOSP_GET_STATUS_CODE(
edge_serial->rxHeader1);
if (!IOSP_STATUS_IS_2BYTE(
edge_serial->rxStatusCode)) { /* This status needs additional bytes. *Savewhatwehaveandthenwaitfor *moredata.
*/
edge_serial->rxStatusParam
= edge_serial->rxHeader2;
edge_serial->rxState = EXPECT_HDR3; break;
} /* We have all the header bytes, process the
status now */
process_rcvd_status(edge_serial,
edge_serial->rxHeader2, 0);
edge_serial->rxState = EXPECT_HDR1; break;
}
edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
edge_serial->rxBytesRemaining = IOSP_GET_HDR_DATA_LEN(edge_serial->rxHeader1,
edge_serial->rxHeader2);
dev_dbg(dev, "%s - Data for Port %u Len %u\n", __func__,
edge_serial->rxPort,
edge_serial->rxBytesRemaining);
if (bufferLength == 0) {
edge_serial->rxState = EXPECT_DATA; break;
}
fallthrough; case EXPECT_DATA: /* Expect data */ if (bufferLength < edge_serial->rxBytesRemaining) {
rxLen = bufferLength; /* Expect data to start next buffer */
edge_serial->rxState = EXPECT_DATA;
} else { /* BufLen >= RxBytesRemaining */
rxLen = edge_serial->rxBytesRemaining; /* Start another header next time */
edge_serial->rxState = EXPECT_HDR1;
}
/* spit this data back into the tty driver if this
port is open */ if (rxLen && edge_serial->rxPort < serial->num_ports) {
port = serial->port[edge_serial->rxPort];
edge_port = usb_get_serial_port_data(port); if (edge_port && edge_port->open) {
dev_dbg(dev, "%s - Sending %d bytes to TTY for port %d\n",
__func__, rxLen,
edge_serial->rxPort);
edge_tty_recv(edge_port->port, buffer,
rxLen);
edge_port->port->icount.rx += rxLen;
}
}
buffer += rxLen; break;
case EXPECT_HDR3: /* Expect 3rd byte of status header */
edge_serial->rxHeader3 = *buffer;
++buffer;
--bufferLength;
/* We have all the header bytes, process the
status now */
process_rcvd_status(edge_serial,
edge_serial->rxStatusParam,
edge_serial->rxHeader3);
edge_serial->rxState = EXPECT_HDR1; break;
}
}
}
/* switch the port pointer to the one being currently talked about */ if (edge_serial->rxPort >= edge_serial->serial->num_ports) return;
port = edge_serial->serial->port[edge_serial->rxPort];
edge_port = usb_get_serial_port_data(port); if (edge_port == NULL) {
dev_err(&edge_serial->serial->dev->dev, "%s - edge_port == NULL for port %d\n",
__func__, edge_serial->rxPort); return;
}
dev = &port->dev;
if (code == IOSP_EXT_STATUS) { switch (byte2) { case IOSP_EXT_STATUS_CHASE_RSP: /* we want to do EXT status regardless of port
* open/closed */
dev_dbg(dev, "%s - Port %u EXT CHASE_RSP Data = %02x\n",
__func__, edge_serial->rxPort, byte3); /* Currently, the only EXT_STATUS is Chase, so process *hereinsteadofonemorecalltoonemoresubroutine *If/whenmoreEXT_STATUS,there'llbemoreworktodo *Also,wecurrentlyclearflagandclosetheport *regardlessofcontentofabove'sByte3. *WecouldchoosetodosomethingelsewhenByte3says *TimeoutonChasefromEdgeport,likewaitlongerin *block_until_chase_response,butfornowwedon't.
*/
edge_port->chaseResponsePending = false;
wake_up(&edge_port->wait_chase); return;
/* send the current line settings to the port so we are
in sync with any further termios calls */
tty = tty_port_tty_get(&edge_port->port->port); if (tty) {
change_port_settings(tty,
edge_port, &tty->termios);
tty_kref_put(tty);
}
/* we have completed the open */
edge_port->openPending = false;
edge_port->open = true;
wake_up(&edge_port->wait_open); return;
}
/* If port is closed, silently discard all rcvd status. We can *havecaseswherebufferedstatusisreceivedAFTERtheclose *portcommandissenttotheEdgeport.
*/ if (!edge_port->open || edge_port->closePending) return;
switch (code) { /* Not currently sent by Edgeport */ case IOSP_STATUS_LSR:
dev_dbg(dev, "%s - Port %u LSR Status = %02x\n",
__func__, edge_serial->rxPort, byte2);
handle_new_lsr(edge_port, false, byte2, 0); break;
case IOSP_STATUS_LSR_DATA:
dev_dbg(dev, "%s - Port %u LSR Status = %02x, Data = %02x\n",
__func__, edge_serial->rxPort, byte2, byte3); /* byte2 is LSR Register */ /* byte3 is broken data byte */
handle_new_lsr(edge_port, true, byte2, byte3); break; /* *caseIOSP_EXT_4_STATUS: *dev_dbg(dev,"%s-Port%uLSRStatus=%02xData=%02x\n", *__func__,edge_serial->rxPort,byte2,byte3); *break;
*/ case IOSP_STATUS_MSR:
dev_dbg(dev, "%s - Port %u MSR Status = %02x\n",
__func__, edge_serial->rxPort, byte2); /* *Processthisnewmodemstatusandgenerateappropriate *events,etc,basedonthenewstatus.Thisroutine *alsosavestheMSRinPort->ShadowMsr.
*/
handle_new_msr(edge_port, byte2); break;
transfer_buffer = kmalloc(64, GFP_KERNEL); if (!transfer_buffer) return -ENOMEM;
/* need to split these writes up into 64 byte chunks */
result = 0; while (length > 0) { if (length > 64)
current_length = 64; else
current_length = length;
/* Restore original value to disable access to divisor latch */
MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR,
edge_port->shadowLCR);
status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); if (status) { /* something bad happened, let's free up the memory */
kfree(cmdBuffer);
}
return status;
}
/***************************************************************************** *calc_baud_rate_divisor *thisfunctioncalculatestheproperbaudratedivisorforthespecified *baudrate.
*****************************************************************************/ staticint calc_baud_rate_divisor(struct device *dev, int baudrate, int *divisor)
{ int i;
__u16 custom;
for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { if (divisor_table[i].BaudRate == baudrate) {
*divisor = divisor_table[i].Divisor; return0;
}
}
/* We have tried all of the standard baud rates *letstrytocalculatethedivisorforthisbaudrate
* Make sure the baud rate is reasonable */ if (baudrate > 50 && baudrate < 230400) { /* get divisor */
custom = (__u16)((230400L + baudrate/2) / baudrate);
if (edge_serial->is_epic &&
!edge_serial->epic_descriptor.Supports.IOSPWriteMCR &&
regNum == MCR) {
dev_dbg(dev, "SendCmdWriteUartReg - Not writing to MCR Register\n"); return0;
}
if (edge_serial->is_epic &&
!edge_serial->epic_descriptor.Supports.IOSPWriteLCR &&
regNum == LCR) {
dev_dbg(dev, "SendCmdWriteUartReg - Not writing to LCR Register\n"); return0;
}
/* Alloc memory for the string of commands. */
cmdBuffer = kmalloc(0x10, GFP_ATOMIC); if (cmdBuffer == NULL) return -ENOMEM;
currCmd = cmdBuffer;
/* Build a cmd in the buffer to write the given register */
MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, edge_port->port->port_number,
regNum, regValue);
status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); if (status) { /* something bad happened, let's free up the memory */
kfree(cmdBuffer);
}
/* figure out the flow control settings */
rxFlow = txFlow = 0x00; if (cflag & CRTSCTS) {
rxFlow |= IOSP_RX_FLOW_RTS;
txFlow |= IOSP_TX_FLOW_CTS;
dev_dbg(dev, "%s - RTS/CTS is enabled\n", __func__);
} else {
dev_dbg(dev, "%s - RTS/CTS is disabled\n", __func__);
}
/* if we are implementing XON/XOFF, set the start and stop character
in the device */ if (I_IXOFF(tty) || I_IXON(tty)) { unsignedchar stop_char = STOP_CHAR(tty); unsignedchar start_char = START_CHAR(tty);
/* if we are implementing INBOUND XON/XOFF */ if (I_IXOFF(tty)) {
rxFlow |= IOSP_RX_FLOW_XON_XOFF;
dev_dbg(dev, "%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
__func__, start_char, stop_char);
} else {
dev_dbg(dev, "%s - INBOUND XON/XOFF is disabled\n", __func__);
}
/* if we are implementing OUTBOUND XON/XOFF */ if (I_IXON(tty)) {
txFlow |= IOSP_TX_FLOW_XON_XOFF;
dev_dbg(dev, "%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
__func__, start_char, stop_char);
} else {
dev_dbg(dev, "%s - OUTBOUND XON/XOFF is disabled\n", __func__);
}
}
/* Set flow control to the configured value */ if (!edge_serial->is_epic ||
edge_serial->epic_descriptor.Supports.IOSPSetRxFlow)
send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_RX_FLOW, rxFlow); if (!edge_serial->is_epic ||
edge_serial->epic_descriptor.Supports.IOSPSetTxFlow)
send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_TX_FLOW, txFlow);
/* Send the updated LCR value to the EdgePort */
status = send_cmd_write_uart_register(edge_port, LCR,
edge_port->shadowLCR); if (status != 0) return;
/* set up the MCR register and send it to the EdgePort */
edge_port->shadowMCR = MCR_MASTER_IE; if (cflag & CBAUD)
edge_port->shadowMCR |= (MCR_DTR | MCR_RTS);
status = send_cmd_write_uart_register(edge_port, MCR,
edge_port->shadowMCR); if (status != 0) return;
/* Determine divisor based on baud rate */
baud = tty_get_baud_rate(tty); if (!baud) { /* pick a default, any default... */
baud = 9600;
}
dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud);
status = send_cmd_write_baud_rate(edge_port, baud); if (status == -1) { /* Speed change was not possible - put back the old speed */
baud = tty_termios_baud_rate(old_termios);
tty_encode_baud_rate(tty, baud, baud);
}
}
/**************************************************************************** *unicode_to_ascii *TurnsastringfromUnicodeintoASCII. *Doesn'tdoagoodjobwithanycharactersthatareoutsidethenormal *ASCIIrange,butit'sonlyfordebugging... *NOTE:expectstheunicodeinLEformat
****************************************************************************/ staticvoid unicode_to_ascii(char *string, int buflen,
__le16 *unicode, int unicode_size)
{ int i;
if (buflen <= 0) /* never happens, but... */ return;
--buflen; /* space for nul */
for (i = 0; i < unicode_size; i++) { if (i >= buflen) break;
string[i] = (char)(le16_to_cpu(unicode[i]));
}
string[i] = 0x00;
}
/* get the name for the device from the device */
i = usb_string(dev, dev->descriptor.iManufacturer,
&edge_serial->name[0], MAX_NAME_LEN+1); if (i < 0)
i = 0;
edge_serial->name[i++] = ' ';
usb_string(dev, dev->descriptor.iProduct,
&edge_serial->name[i], MAX_NAME_LEN+2 - i);
/* Read the epic descriptor */ if (get_epic_descriptor(edge_serial) < 0) { /* memcpy descriptor to Supports structures */
memcpy(&edge_serial->epic_descriptor.Supports, descriptor, sizeof(struct edge_compatibility_bits));
/* get the manufacturing descriptor for this device */
get_manufacturing_desc(edge_serial);
/* get the boot descriptor */
get_boot_desc(edge_serial);
get_product_info(edge_serial);
}
/* set the number of ports from the manufacturing description */ /* serial->num_ports = serial->product_info.NumPorts; */ if ((!edge_serial->is_epic) &&
(edge_serial->product_info.NumPorts != serial->num_ports)) {
dev_warn(ddev, "Device Reported %d serial ports vs. core thinking we have %d ports, email greg@kroah.com this information.\n",
edge_serial->product_info.NumPorts,
serial->num_ports);
}
dev_dbg(ddev, "%s - time 1 %ld\n", __func__, jiffies);
/* If not an EPiC device */ if (!edge_serial->is_epic) { /* now load the application firmware into this device */
load_application_firmware(edge_serial);
dev_dbg(ddev, "%s - time 2 %ld\n", __func__, jiffies);
/* Check current Edgeport EEPROM and update if necessary */
update_edgeport_E2PROM(edge_serial);
dev_dbg(ddev, "%s - time 3 %ld\n", __func__, jiffies);
/* set the configuration to use #1 */ /* dev_dbg(ddev, "set_configuration 1\n"); */ /* usb_set_configuration (dev, 1); */
}
dev_dbg(ddev, " FirmwareMajorVersion %d.%d.%d\n",
edge_serial->product_info.FirmwareMajorVersion,
edge_serial->product_info.FirmwareMinorVersion,
le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber));
/* we set up the pointers to the endpoints in the edge_open function,
* as the structures aren't created yet. */
response = 0;
if (edge_serial->is_epic) { struct usb_host_interface *alt;
alt = serial->interface->cur_altsetting;
/* EPIC thing, set up our interrupt polling now and our read
* urb, so that the device knows it really is connected. */
interrupt_in_found = bulk_in_found = bulk_out_found = false; for (i = 0; i < alt->desc.bNumEndpoints; ++i) { struct usb_endpoint_descriptor *endpoint; int buffer_size;
endpoint = &alt->endpoint[i].desc;
buffer_size = usb_endpoint_maxp(endpoint); if (!interrupt_in_found &&
(usb_endpoint_is_int_in(endpoint))) { /* we found a interrupt in endpoint */
dev_dbg(ddev, "found interrupt in\n");
/* not set up yet, so do it now */
edge_serial->interrupt_read_urb =
usb_alloc_urb(0, GFP_KERNEL); if (!edge_serial->interrupt_read_urb) {
response = -ENOMEM; break;
}
/* set up our bulk in urb */
usb_fill_bulk_urb(edge_serial->read_urb, dev,
usb_rcvbulkpipe(dev,
endpoint->bEndpointAddress),
edge_serial->bulk_in_buffer,
usb_endpoint_maxp(endpoint),
edge_bulk_in_callback,
edge_serial);
bulk_in_found = true;
}
if (!bulk_out_found &&
(usb_endpoint_is_bulk_out(endpoint))) { /* we found a bulk out endpoint */
dev_dbg(ddev, "found bulk out\n");
edge_serial->bulk_out_endpoint =
endpoint->bEndpointAddress;
bulk_out_found = true;
}
}
if (response || !interrupt_in_found || !bulk_in_found ||
!bulk_out_found) { if (!response) {
dev_err(ddev, "expected endpoints not found\n");
response = -ENODEV;
}
goto error;
}
/* start interrupt read for this edgeport this interrupt will
* continue as long as the edgeport is connected */
response = usb_submit_urb(edge_serial->interrupt_read_urb,
GFP_KERNEL); if (response) {
dev_err(ddev, "%s - Error %d submitting control urb\n",
__func__, response);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.