25 #define SERIAL_DO_RESTART
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/errno.h>
29 #include <linux/signal.h>
32 #include <linux/tty.h>
36 #include <linux/serial.h>
39 #include <linux/string.h>
40 #include <linux/fcntl.h>
41 #include <linux/ptrace.h>
44 #include <linux/slab.h>
47 #include <linux/pci.h>
53 #include <linux/bitops.h>
57 #include <asm/uaccess.h>
63 #define ICOM_DRIVER_NAME "icom"
64 #define ICOM_VERSION_STR "1.3.1"
66 #define ICOM_PORT ((struct icom_port *)port)
67 #define to_icom_adapter(d) container_of(d, struct icom_adapter, kref)
140 unsigned long trace_data)
143 icom_port->
port, trace_pt, trace_data);
148 static void icom_kref_release(
struct kref *
kref);
154 trace(icom_port,
"RET_PORT_MEM", 0);
178 static int __devinit get_port_memory(
struct icom_port *icom_port)
181 unsigned long stgAddr;
182 unsigned long startStgAddr;
189 dev_err(&dev->
dev,
"Can not allocate Transmit buffer\n");
193 trace(icom_port,
"GET_PORT_MEM",
194 (
unsigned long) icom_port->
xmit_buf);
199 dev_err(&dev->
dev,
"Can not allocate Receive buffer\n");
200 free_port_memory(icom_port);
203 trace(icom_port,
"GET_PORT_MEM",
204 (
unsigned long) icom_port->
recv_buf);
209 dev_err(&dev->
dev,
"Can not allocate Status buffer\n");
210 free_port_memory(icom_port);
213 trace(icom_port,
"GET_PORT_MEM",
214 (
unsigned long) icom_port->
statStg);
220 "Can not allocate xmit Restart buffer\n");
221 free_port_memory(icom_port);
233 trace(icom_port,
"FOD_ADDR", stgAddr);
234 stgAddr = stgAddr +
sizeof(icom_port->
statStg->xmit[0]);
235 if (index < (NUM_XBUFFS - 1)) {
236 memset(&icom_port->
statStg->xmit[index], 0,
sizeof(
struct xmit_status_area));
239 trace(icom_port,
"FOD_ADDR", stgAddr);
240 trace(icom_port,
"FOD_XBUFF",
241 (
unsigned long) icom_port->
xmit_buf);
244 }
else if (index == (NUM_XBUFFS - 1)) {
245 memset(&icom_port->
statStg->xmit[index], 0,
sizeof(
struct xmit_status_area));
248 trace(icom_port,
"FOD_XBUFF",
249 (
unsigned long) icom_port->
xmit_buf);
253 memset(&icom_port->
statStg->xmit[index], 0,
sizeof(
struct xmit_status_area));
257 startStgAddr = stgAddr;
260 for (index = 0; index <
NUM_RBUFFS; index++) {
261 trace(icom_port,
"FID_ADDR", stgAddr);
262 stgAddr = stgAddr +
sizeof(icom_port->
statStg->rcv[0]);
266 if (index < (NUM_RBUFFS - 1) ) {
267 offset = stgAddr - (
unsigned long) icom_port->
statStg;
268 icom_port->
statStg->rcv[index].leNext =
270 trace(icom_port,
"FID_RBUFF",
271 (
unsigned long) icom_port->
recv_buf);
274 }
else if (index == (NUM_RBUFFS -1) ) {
275 offset = startStgAddr - (
unsigned long) icom_port->
statStg;
276 icom_port->
statStg->rcv[index].leNext =
278 trace(icom_port,
"FID_RBUFF",
279 (
unsigned long) icom_port->
recv_buf + 2048);
291 static void stop_processor(
struct icom_port *icom_port)
299 port = icom_port->
port;
300 if (port == 0 || port == 1)
307 temp =
readl(stop_proc[port].global_control_reg);
310 writel(temp, stop_proc[port].global_control_reg);
313 readl(stop_proc[port].global_control_reg);
316 "Invalid port assignment\n");
319 spin_unlock_irqrestore(&icom_lock, flags);
322 static void start_processor(
struct icom_port *icom_port)
330 port = icom_port->
port;
331 if (port == 0 || port == 1)
336 temp =
readl(start_proc[port].global_control_reg);
339 writel(temp, start_proc[port].global_control_reg);
342 readl(start_proc[port].global_control_reg);
345 "Invalid port assignment\n");
348 spin_unlock_irqrestore(&icom_lock, flags);
351 static void load_code(
struct icom_port *icom_port)
359 unsigned char *new_page =
NULL;
366 trace(icom_port,
"CLEAR_INTERRUPTS", 0);
369 stop_processor(icom_port);
376 dev_err(&dev->
dev,
"Unable to load icom_call_setup.bin firmware image\n");
382 dev_err(&dev->
dev,
"Invalid firmware image for icom_call_setup.bin found.\n");
389 for (index = 0; index < fw->
size; index++)
396 dev_err(&dev->
dev,
"Unable to load icom_res_dce.bin firmware image\n");
402 dev_err(&dev->
dev,
"Invalid firmware image for icom_res_dce.bin found.\n");
419 start_processor(icom_port);
422 &(icom_port->
dram->HDLCConfigReg));
423 writeb(0x04, &(icom_port->
dram->FlagFillIdleTimer));
425 writeb(0x10, &(icom_port->
dram->async_config3));
435 dev_err(&dev->
dev,
"Can not allocate DMA buffer\n");
441 dev_err(&dev->
dev,
"Unable to load icom_asc.bin firmware image\n");
447 dev_err(&dev->
dev,
"Invalid firmware image for icom_asc.bin found.\n");
453 for (index = 0; index < fw->
size; index++)
454 new_page[index] = fw->
data[index];
458 writeb((
char) ((fw->
size + 16)/16), &icom_port->
dram->mac_length);
459 writel(temp_pci, &icom_port->
dram->mac_load_addr);
473 for (index = 0; index < 10; index++) {
485 cable_id =
readb(&icom_port->
dram->cable_id);
492 dev_err(&dev->
dev,
"Invalid or no cable attached\n");
506 stop_processor(icom_port);
508 dev_err(&icom_port->
adapter->pci_dev->dev,
"Port not opertional\n");
511 if (new_page !=
NULL)
515 static int startup(
struct icom_port *icom_port)
518 unsigned char cable_id, raw_cable_id;
522 trace(icom_port,
"STARTUP", 0);
524 if (!icom_port->
dram) {
527 "Unusable Port, port configuration missing\n");
534 raw_cable_id =
readb(&icom_port->
dram->cable_id);
535 trace(icom_port,
"CABLE_ID", raw_cable_id);
541 if (!(raw_cable_id & ICOM_CABLE_ID_VALID) ||
542 (cable_id != icom_port->
cable_id)) {
545 load_code(icom_port);
548 raw_cable_id =
readb(&icom_port->
dram->cable_id);
550 if (!(raw_cable_id & ICOM_CABLE_ID_VALID) ||
559 port = icom_port->
port;
560 if (port == 0 || port == 1)
565 if (port == 0 || port == 2)
570 temp =
readl(int_mask_tbl[port].global_int_mask);
574 readl(int_mask_tbl[port].global_int_mask);
577 "Invalid port assignment\n");
580 spin_unlock_irqrestore(&icom_lock, flags);
584 static void shutdown(
struct icom_port *icom_port)
587 unsigned char cmdReg;
592 trace(icom_port,
"SHUTDOWN", 0);
597 port = icom_port->
port;
598 if (port == 0 || port == 1)
604 temp =
readl(int_mask_tbl[port].global_int_mask);
608 readl(int_mask_tbl[port].global_int_mask);
611 "Invalid port assignment\n");
613 spin_unlock_irqrestore(&icom_lock, flags);
618 cmdReg =
readb(&icom_port->
dram->CmdReg);
620 writeb(cmdReg & ~CMD_SND_BREAK, &icom_port->
dram->CmdReg);
624 static int icom_write(
struct uart_port *port)
627 unsigned char cmdReg;
629 int temp_tail = port->
state->xmit.tail;
640 while ((port->
state->xmit.head != temp_tail) &&
644 port->
state->xmit.buf[temp_tail];
672 static inline void check_modem_status(
struct icom_port *icom_port)
674 static char old_status = 0;
682 trace(icom_port,
"CHECK_MODEM", status);
683 delta_status = status ^ old_status;
691 delta_status & ICOM_DCD);
694 delta_status & ICOM_CTS);
697 port.delta_msr_wait);
703 static void xmit_interrupt(
u16 port_int_reg,
struct icom_port *icom_port)
705 unsigned short int count;
709 trace(icom_port,
"XMIT_COMPLETE", 0);
712 icom_port->
statStg->xmit[0].flags &=
715 count = (
unsigned short int)
731 trace(icom_port,
"XMIT_DISABLED", 0);
734 static void recv_interrupt(
u16 port_int_reg,
struct icom_port *icom_port)
736 short int count, rcv_buff;
738 unsigned short int status;
743 trace(icom_port,
"RCV_COMPLETE", 0);
750 trace(icom_port,
"FID_STATUS", status);
753 trace(icom_port,
"RCV_COUNT", count);
755 trace(icom_port,
"REAL_COUNT", count);
764 tty_insert_flip_string(tty, icom_port->
recv_buf + offset, count - 1);
773 status &= ~SA_FLAGS_FRAME_ERROR;
775 trace(icom_port,
"BREAK_DET", 0);
788 if (status & SA_FLAGS_FRAME_ERROR)
799 trace(icom_port,
"IGNORE_CHAR", 0);
805 if (status & SA_FLAGS_BREAK_DET) {
807 }
else if (status & SA_FLAGS_PARITY_ERROR) {
808 trace(icom_port,
"PARITY_ERROR", 0);
810 }
else if (status & SA_FLAGS_FRAME_ERROR)
815 tty_insert_flip_char(tty, *(icom_port->
recv_buf + offset + count - 1), flag);
817 if (status & SA_FLAGS_OVERRUN)
825 icom_port->
statStg->rcv[rcv_buff].flags = 0;
826 icom_port->
statStg->rcv[rcv_buff].leLength = 0;
827 icom_port->
statStg->rcv[rcv_buff].WorkingLength =
831 if (rcv_buff == NUM_RBUFFS)
840 static void process_interrupt(
u16 port_int_reg,
841 struct icom_port *icom_port)
845 trace(icom_port,
"INTERRUPT", port_int_reg);
848 xmit_interrupt(port_int_reg, icom_port);
851 recv_interrupt(port_int_reg, icom_port);
859 u32 adapter_interrupts;
862 struct icom_port *icom_port;
865 icom_adapter = (
struct icom_adapter *) dev_id;
868 int_reg = icom_adapter->
base_addr + 0x8024;
870 adapter_interrupts =
readl(int_reg);
872 if (adapter_interrupts & 0x00003FFF) {
875 port_int_reg = (
u16) adapter_interrupts;
876 process_interrupt(port_int_reg, icom_port);
877 check_modem_status(icom_port);
879 if (adapter_interrupts & 0x3FFF0000) {
884 (
u16) (adapter_interrupts >> 16);
885 process_interrupt(port_int_reg, icom_port);
886 check_modem_status(icom_port);
891 writel(adapter_interrupts, int_reg);
893 int_reg = icom_adapter->
base_addr + 0x8004;
895 int_reg = icom_adapter->
base_addr + 0x4004;
898 adapter_interrupts =
readl(int_reg);
900 if (adapter_interrupts & 0x00003FFF) {
903 port_int_reg = (
u16) adapter_interrupts;
904 process_interrupt(port_int_reg, icom_port);
905 check_modem_status(icom_port);
907 if (adapter_interrupts & 0x3FFF0000) {
911 port_int_reg = (
u16) (adapter_interrupts >> 16);
912 process_interrupt(port_int_reg, icom_port);
913 check_modem_status(icom_port);
918 writel(adapter_interrupts, int_reg);
921 adapter_interrupts =
readl(int_reg);
931 static unsigned int icom_tx_empty(
struct uart_port *port)
943 spin_unlock_irqrestore(&port->
lock, flags);
947 static void icom_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
949 unsigned char local_osr;
973 static unsigned int icom_get_mctrl(
struct uart_port *port)
989 static void icom_stop_tx(
struct uart_port *port)
991 unsigned char cmdReg;
998 static void icom_start_tx(
struct uart_port *port)
1000 unsigned char cmdReg;
1005 writeb(cmdReg & ~CMD_HOLD_XMIT,
1011 static void icom_send_xchar(
struct uart_port *port,
char ch)
1013 unsigned char xdata;
1015 unsigned long flags;
1020 for (index = 0; index < 10; index++) {
1023 if (xdata == 0x00) {
1029 spin_unlock_irqrestore(&port->
lock, flags);
1032 spin_unlock_irqrestore(&port->
lock, flags);
1037 static void icom_stop_rx(
struct uart_port *port)
1039 unsigned char cmdReg;
1045 static void icom_enable_ms(
struct uart_port *port)
1050 static void icom_break(
struct uart_port *port,
int break_state)
1052 unsigned char cmdReg;
1053 unsigned long flags;
1058 if (break_state == -1) {
1063 spin_unlock_irqrestore(&port->
lock, flags);
1066 static int icom_open(
struct uart_port *port)
1074 kref_put(&
ICOM_PORT->adapter->kref, icom_kref_release);
1082 static void icom_close(
struct uart_port *port)
1084 unsigned char cmdReg;
1095 kref_put(&
ICOM_PORT->adapter->kref, icom_kref_release);
1098 static void icom_set_termios(
struct uart_port *port,
1103 unsigned cflag, iflag;
1105 char new_config3 = 0;
1108 int rcv_buff, xmit_buff;
1110 unsigned long flags;
1121 switch (cflag &
CSIZE) {
1160 if (icom_acfg_baud[index] == baud) {
1161 new_config3 =
index;
1207 if ((cflag &
CREAD) == 0)
1213 for (index = 0; index < 10; index++) {
1220 for (rcv_buff = 0; rcv_buff <
NUM_RBUFFS; rcv_buff++) {
1221 ICOM_PORT->statStg->rcv[rcv_buff].flags = 0;
1222 ICOM_PORT->statStg->rcv[rcv_buff].leLength = 0;
1223 ICOM_PORT->statStg->rcv[rcv_buff].WorkingLength =
1227 for (xmit_buff = 0; xmit_buff <
NUM_XBUFFS; xmit_buff++) {
1228 ICOM_PORT->statStg->xmit[xmit_buff].flags = 0;
1244 for (index = 0; index < 10; index++) {
1264 spin_unlock_irqrestore(&port->
lock, flags);
1267 static const char *icom_type(
struct uart_port *port)
1272 static void icom_release_port(
struct uart_port *port)
1276 static int icom_request_port(
struct uart_port *port)
1281 static void icom_config_port(
struct uart_port *port,
int flags)
1286 static struct uart_ops icom_ops = {
1287 .tx_empty = icom_tx_empty,
1288 .set_mctrl = icom_set_mctrl,
1289 .get_mctrl = icom_get_mctrl,
1290 .stop_tx = icom_stop_tx,
1291 .start_tx = icom_start_tx,
1292 .send_xchar = icom_send_xchar,
1293 .stop_rx = icom_stop_rx,
1294 .enable_ms = icom_enable_ms,
1295 .break_ctl = icom_break,
1296 .startup = icom_open,
1297 .shutdown = icom_close,
1298 .set_termios = icom_set_termios,
1300 .release_port = icom_release_port,
1301 .request_port = icom_request_port,
1302 .config_port = icom_config_port,
1305 #define ICOM_CONSOLE NULL
1317 static int __devinit icom_init_ports(
struct icom_adapter *icom_adapter)
1321 struct icom_port *icom_port;
1326 for (i = 0; i < 2; i++) {
1328 icom_port->
port =
i;
1336 for (i = 0; i < 4; i++) {
1339 icom_port->
port =
i;
1368 static void icom_port_active(
struct icom_port *icom_port,
struct icom_adapter *icom_adapter,
int port_num)
1376 if (icom_port->
port < 2)
1378 0x8004 + 2 - 2 * icom_port->
port;
1381 0x8024 + 2 - 2 * (icom_port->
port - 2);
1384 static int __devinit icom_load_ports(
struct icom_adapter *icom_adapter)
1386 struct icom_port *icom_port;
1389 for (port_num = 0; port_num < icom_adapter->
numb_ports; port_num++) {
1394 icom_port_active(icom_port, icom_adapter, port_num);
1396 0x2000 * icom_port->
port;
1398 icom_port->
adapter = icom_adapter;
1401 if (get_port_memory(icom_port) != 0) {
1403 "Memory allocation for port FAILED\n");
1410 static int __devinit icom_alloc_adapter(
struct icom_adapter
1413 int adapter_count = 0;
1414 struct icom_adapter *icom_adapter;
1415 struct icom_adapter *cur_adapter_entry;
1418 icom_adapter = (
struct icom_adapter *)
1419 kzalloc(
sizeof(
struct icom_adapter),
GFP_KERNEL);
1421 if (!icom_adapter) {
1429 if (cur_adapter_entry->
index != adapter_count) {
1435 icom_adapter->
index = adapter_count;
1438 *icom_adapter_ref = icom_adapter;
1442 static void icom_free_adapter(
struct icom_adapter *icom_adapter)
1445 kfree(icom_adapter);
1448 static void icom_remove_adapter(
struct icom_adapter *icom_adapter)
1450 struct icom_port *icom_port;
1453 for (index = 0; index < icom_adapter->
numb_ports; index++) {
1458 "Device removed\n");
1470 stop_processor(icom_port);
1472 free_port_memory(icom_port);
1479 icom_free_adapter(icom_adapter);
1482 static void icom_kref_release(
struct kref *
kref)
1484 struct icom_adapter *icom_adapter;
1487 icom_remove_adapter(icom_adapter);
1494 unsigned int command_reg;
1496 struct icom_adapter *icom_adapter;
1497 struct icom_port *icom_port;
1501 dev_err(&dev->
dev,
"Device enable FAILED\n");
1506 dev_err(&dev->
dev,
"pci_request_regions FAILED\n");
1513 if ( (retval = pci_read_config_dword(dev,
PCI_COMMAND, &command_reg))) {
1514 dev_err(&dev->
dev,
"PCI Config read FAILED\n");
1523 pci_write_config_dword(dev, 0x44, 0x8300830A);
1525 pci_write_config_dword(dev, 0x44, 0x42004200);
1526 pci_write_config_dword(dev, 0x48, 0x42004200);
1530 retval = icom_alloc_adapter(&icom_adapter);
1532 dev_err(&dev->
dev,
"icom_alloc_adapter FAILED\n");
1543 retval = icom_init_ports(icom_adapter);
1545 dev_err(&dev->
dev,
"Port configuration failed\n");
1557 (
void *) icom_adapter))) {
1561 retval = icom_load_ports(icom_adapter);
1563 for (index = 0; index < icom_adapter->
numb_ports; index++) {
1575 icom_port->
port + icom_adapter->
index * 4;
1584 kref_init(&icom_adapter->
kref);
1590 icom_free_adapter(icom_adapter);
1601 struct icom_adapter *icom_adapter;
1605 icom_adapter =
list_entry(tmp,
struct icom_adapter,
1606 icom_adapter_entry);
1607 if (icom_adapter->
pci_dev == dev) {
1608 kref_put(&icom_adapter->
kref, icom_kref_release);
1613 dev_err(&dev->
dev,
"Unable to find device to remove\n");
1618 .id_table = icom_pci_table,
1619 .probe = icom_probe,
1623 static int __init icom_init(
void)
1633 ret = pci_register_driver(&icom_pci_driver);
1641 static void __exit icom_exit(
void)
1653 (
"IBM iSeries 2745, 2771, 2772, 2742, 2793 and 2805 Communications adapters");