# PCI Dual Serial Cards



## Porthos (Oct 31, 2009)

I am making a terminal server for a Cisco CCIE lab.

To do this I have put 7 PCI cards that have two serial interfaces each. I intend to use them via CU.

When FBSD boots, it detects the PCI devices. However, I do not see them in my /dev folder. What do I need to do to write a driver for these devices? Or is there any guides available?

Thanks,


----------



## tingo (Oct 31, 2009)

It would help a lot if you provided more info, like relevant output from `$ dmesg` and `# pciconf -lv`. Note: relevant means only those lines that tell things about the serial cards, not everything else.


----------



## Porthos (Nov 1, 2009)

```
pci2: <simple comms, UART> at device 6.0 (no driver attached)
pci2: <simple comms, UART> at device 6.1 (no driver attached)
pci2: <simple comms, parallel port> at device 6.2 (no driver attached)
pci2: <simple comms, UART> at device 8.0 (no driver attached)
pci2: <simple comms, UART> at device 8.1 (no driver attached)
pci2: <simple comms, parallel port> at device 8.2 (no driver attached)
pci2: <simple comms, UART> at device 10.0 (no driver attached)
pci2: <simple comms, UART> at device 10.1 (no driver attached)
pci2: <simple comms, parallel port> at device 10.2 (no driver attached)
pci2: <simple comms, UART> at device 12.0 (no driver attached)
pci2: <simple comms, UART> at device 12.1 (no driver attached)
pci2: <simple comms, parallel port> at device 12.2 (no driver attached)
pci2: <simple comms, UART> at device 14.0 (no driver attached)
pci2: <simple comms, UART> at device 14.1 (no driver attached)
pci2: <simple comms, parallel port> at device 14.2 (no driver attached)



none3@pci0:2:6:0:       class=0x070002 card=0x1000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = UART
none4@pci0:2:6:1:       class=0x070002 card=0x1000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = UART
none5@pci0:2:6:2:       class=0x070103 card=0x2000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = parallel port
none6@pci0:2:8:0:       class=0x070002 card=0x1000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = UART
none7@pci0:2:8:1:       class=0x070002 card=0x1000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = UART
none8@pci0:2:8:2:       class=0x070103 card=0x2000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = parallel port
none9@pci0:2:10:0:      class=0x070002 card=0x1000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = UART
none10@pci0:2:10:1:     class=0x070002 card=0x1000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = UART
none11@pci0:2:10:2:     class=0x070103 card=0x2000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = parallel port
none12@pci0:2:12:0:     class=0x070002 card=0x1000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = UART
none13@pci0:2:12:1:     class=0x070002 card=0x1000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = UART
none14@pci0:2:12:2:     class=0x070103 card=0x2000a000 chip=0x98659710 rev=0x00 hdr=0x00
    vendor     = 'MosChip Semiconductors (Was: Netmos Technology)'
    class      = simple comms
    subclass   = parallel port
```


----------



## Porthos (Nov 1, 2009)

I accidently left some out, but there all the same kind of card so shouldn't matter.


----------



## tingo (Nov 1, 2009)

ok.
Try to kldload puc(4) and uart(4), to find ut if these cards are supported.


----------



## aragon (Nov 1, 2009)

You might be able to get away with just editing the uart(4) driver's vendor ID database.  Looks like Netmos changed vendor ID when renaming to MosChip?  I see an entry in uart_bus_pci.c that looks similar to your hardware:


```
# grep -n 9710 sys/dev/uart/uart_bus_pci.c 
113:{ 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 },
```

So I guess a good start would be to add an entry for vendor ID 0x9865 and see if uart(4) detects it and then test if it works.

If it does, please PR the change.


----------



## Porthos (Nov 1, 2009)

I tried loading puc and uart and didn't really seem to change anything, and if it did I still don't see them in /dev.

in my uart_bus_pci.c

I see these entries:

I'm not sure why I have 12 of them, unless each one is just 1 of the serial ports on each of the dual serial port cards (I have 6 of them)

Which should I change the vendor ID value for, or all of them?

```
{ 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 },
{ 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 },
{ 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 },
{ 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 },
{ 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 },
{ 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 },

--(Output Omitted)--

{ 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 },
{ 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 }, 
{ 0x1409, 0x7168, 0x1409, 0x4025, "Timedia Technology Serial Port", 0x10,
        8 * DEFAULT_RCLK },
{ 0x1409, 0x7168, 0x1409, 0x4027, "Timedia Technology Serial Port", 0x10,
        8 * DEFAULT_RCLK },
{ 0x1409, 0x7168, 0x1409, 0x4028, "Timedia Technology Serial Port", 0x10,
        8 * DEFAULT_RCLK },
{ 0x1409, 0x7168, 0x1409, 0x5025, "Timedia Technology Serial Port", 0x10,
        8 * DEFAULT_RCLK },
{ 0x1409, 0x7168, 0x1409, 0x5027, "Timedia Technology Serial Port", 0x10,
        8 * DEFAULT_RCLK },
```


----------



## varda (Nov 4, 2009)

It doesn't work if you kldload puc. That surely checked up for number of times.

For this situation you need to build/recompile custom kernel enabling both devices puc an uart in it at one time.

Usually I'm using generic kernel without any changes. Only if something really required to customise it. So I'm just rebuilding that generic kernel by eliminating all puc depended optionality /sys/conf/files removing puc at the end of every device/line if it still contains it. 

```
sed -b BAK '/_puc/s/[[:space:]*]puc//' /sys/conf/files
```
To looks like:

```
dev/ppc/ppc_puc.c               optional        ppc
dev/uart/uart_bus_puc.c         optional        uart
```

Then after make buildkernel && make installkernel and reboot you'll get generic kernel and can kldload puc (or puc_load="YES" in /boot/loader.conf) which will now pick up and connect uart devices to puc.

Also you can use 2-3 six (6) serial ports NM9845 cards instead of 7 two ports. For example http://st-lab.com/assign.asp?keyid=bc16. It costs just $30-$35


----------



## Porthos (Nov 15, 2009)

Okay, still no luck.

I tried your method varda, but your command to remove the puc statements didn't seem to work, so I went in and removed them manually and tried compiling. Didn't work.


I have yet to try aragon's solution, I will shortly. 

I havn't been lately, thats why I havn't posted in this thread for a while.

Thanks in advanced.


----------



## Porthos (Nov 15, 2009)

I have found that I already have an entry identical to that, aragon. I just have no idea why I can't see them as TTYS in /dev 


So far the only thing that says they don't have drivers is dmsg, and the fact that they are not in /dev for me to cu to. Do I have to make entries for them? How would I do that?


----------



## Porthos (Nov 20, 2009)

bump


----------



## michaelrmgreen (Nov 20, 2009)

The nm9845 card is specifically mentioned in man sio:
http://www.freebsd.org/cgi/man.cgi?...ion=0&manpath=FreeBSD+7.2-RELEASE&format=html


----------



## varda (Nov 24, 2009)

Porthos, sorry, I've not noticed chip=0x98659710. Certainly this is another chip. Try to add to /usr/sys/dev/puc/pucdata.c description for this chip deriving it from one of existing for serial NetMos somewhere between others. For example:

```
{   0x9710, 0x9865, 0xffff, 0,
    "Moschip MCS9865 Dual UART",
    DEFAULT_RCLK,
    PUC_PORT_2S, 0x10, 4, 0,
},
```
Then rebuild kernel and try again.

May be chips compatible or you will need to take a look about documentation this link http://www.moschip.com/mcs9865_downloads.php

The description of puc_cfg is in puc_cfg.h file if reference for fields needs.

I don't have such card and can't try myself. Drop a message here again if you'll try.


----------



## Porthos (Nov 24, 2009)

The exact model name is Mos9865 of the 7 cards. I will try your suggestions again when I get back home. Thanks for the continued help I know I can be rather annoying lol. Will post results


----------



## Porthos (Nov 25, 2009)

I added your example entry, added puc in my kernel conf under the serial section and then recompiled and rebooted. The dmesg does show the device on irq 17 with your example entry but then a few lines after that it freezes during boot. Probably gonna reformat and try drivers approach unless you think I did something wrong?


----------



## varda (Nov 25, 2009)

As a last resort which I can to suggest let's try to update/csup kernel sources. Then modify as said earlier /usr/sys/conf/files:

```
dev/uart/uart_bus_puc.c         optional        uart puc
dev/sio/sio_puc.c           optional        sio puc
```
by removing trailing 'puc' to:

```
dev/uart/uart_bus_puc.c         optional        uart
dev/sio/sio_puc.c           optional        sio
```
Because sio(4) and uart(4) only includes sio_puc.c and uart_puc.c in the kernel if you have 'puc' in your kernel config. The puc kernel module only includes the puc files, it doesn't include sio_puc.c and uart_puc.c.

sio_puc.c present not for all architectures so just ignore if such line doesn't exists.

Add again to /usr/sys/dev/puc/pucdata.c

```
{   0x9710, 0x9865, 0xffff, 0,
    "Moschip MCS9865 Dual UART",
    DEFAULT_RCLK,
    PUC_PORT_2S, 0x10, 4, 0,
},
```

Then without modification 'make buildkernel' for GENERIC config. uart(4) and sio(4) already in it by default.

Install kernel and reboot. At least system will not hang at boot time. And you can experiment with kldload puc and watching to first console or tail of /var/log/messages for events.

That's all what I can to advise quickly. Otherwise something  not very simple with support of this chip in puc(4) driver.

I am not sure that will have such card shortly to check myself.

But you've spent a lot of time on this issue. May be easier to replace them to cards that are supported by FreeBSD?


----------



## Porthos (Nov 26, 2009)

I'm pretty sure that we can get this working, I had puc in the kernel config this last time. That was probably the issue. I'll post here when done trying it out.


----------



## Porthos (Nov 27, 2009)

This is what happens after I kldload puc:



```
puc0: <Moschip MCS9865 Dual UART> port 0xecf8-0xecff mem
0xfe108000-0xfe108fff,0xfe107000-0xfe107fff irq 17 at device 4.0 on pci0
puc0: [FILTER]
uart0: <Non-standard ns8250 class UART with FIFOs> on puc0
uart0: [FILTER]
```


and the machine freezes.


Although it is detecting it I think


----------



## varda (Nov 29, 2009)

I've wrote a message to moschip support but not shure that they'll reply at all.

While postpone card incompatibility.

If you able to insert 7 cards at once then probably you have some specific server with sufficient PCI slots which number is greater than 4-5 usual slots in standard PC. May be this server is not very modern and/or completely compliant to modern PCI specifications and there is set of 3v/5v slots on board.

Please leave only one card and shuffle inserting it between PCI slots. Insert only to 5 volt slots which are common on standard PC's motherboards even IO card is universal.

Also try it on conventional desktop PC, on usual ATX board with modern C2D cpu.


----------



## tingo (Nov 29, 2009)

Porthos said:
			
		

> This is what happens after I kldload puc:
> 
> 
> 
> ...



Try a verbose boot - see if you get any more messages before the machine freezes.


----------



## Porthos (Nov 30, 2009)

It is a Dell PowerEdge 2400, I will add puc to bootloader and will post the dmesg when I get home, got class in 20. Thank you for your ongoing help guys, especially Varda, let me know if you do get a reply. Although I'd doubt it. Perhaps I am entering the code wrong:


```
{   0x9710, 0x9865, 0xffff, 0,
    "Moschip MCS9865 Dual UART",
    DEFAULT_RCLK,
    PUC_PORT_2S, 0x10, 4, 0,
},
```
Is there any changes I should make based on something in the pucdata.c


----------



## varda (Nov 30, 2009)

If module successfully compiled then there's no errors.

This's not a code, this's just a description for that card and this description derived from some already existed. System sees manufacturer ID 0x9710 and device ID 0x9865 at PCI bus and says us what we provided "Moschip MCS9865 Dual UART". Then it should to initialize card/uart ports and at this stage other parameters already may be wrong.

I have assumed that this chip is a continuation of their serial IO product line, may be compatible with previous chips and thus may be supported by the puc(4) driver. 

In past I've successfully added several devices of unknown chinese manufacturers in similar way after finding-out with what they are compatible.

But now I may be wrong.

If you're really have interest to achieve it working then try to contact with manufacturer and try to post a message at FreeBSD developers mailing list to reach puc(4) driver developers or current mainatainers.

Also Dell PowerEdge 2400 is Pentium III based and about 10 years old platform. Please try on more modern system.


----------



## Porthos (Dec 1, 2009)

will sometime later today, and I will also still post the dmesg, just been having a busy day.  Reason for the 10 year old platform is all its really gonna be is a terminal server. Thinking about running CentOS because I found linux drivers but I'm still gonna keep fiddling around with it for a bit, I am not in a big rush.


----------



## varda (Dec 1, 2009)

Got a reply from Moschip support.



> From: support <support@moschip.com>
> Sent: Tue, December 1, 2009 12:05:25 PM
> Subject: RE: MCS9865 under FreeBSD
> 
> ...



Please try it and reply back here. Refer to README and Make file for details inside serial directory of archive. Also you can use cu(1) utility instead attached minicom utility. Somethig like:

```
cu -s 115200 -l ttyu0
```
If driver will not generate cuauX ports.


----------



## Porthos (Dec 2, 2009)

Alright gonna compile it and go from there. 

Will let you know if it works, thanks again for your continued help.

I am running FBSD 7.2 as it is so this should work.

Ya, I was using CU for all these attempts up until now.


----------



## Porthos (Dec 3, 2009)

Okay driver works, I just had to make and make ld and I see all 14.


However when I reboot the drivers are not loaded again and I have to go in and make ld them again. How do I make the drivers do this at boot by default?

To load the drivers I can also use:


```
kldload -v ./mcs9865_uart.ko
```


----------



## varda (Dec 4, 2009)

To load module at boot time just copy generated mcs9865_uart.ko file from compile directory to /boot/modules (as suggested for third party modules) or if it will not work just directly to /boot/kernel where all kernel modules resides. Then add to /boot/loader.conf file following line:

```
mcs9865_uart_load="YES"
```
Reboot and check boot screen.


----------



## Porthos (Dec 4, 2009)

Sweet ^^ Thanks so much for your help Varda, you r hero :e


----------



## varda (Dec 4, 2009)

Please tag this post as solved and add [Solved] in subject line like in other posts.

Good luck


----------

