4242#include <linux/swab.h>
4343#include <linux/slab.h>
4444
45- #define VERSION "0.07"
45+ #define VERSION "1.04"
46+ #define DRIVER_VERSION 0x01
4647#define PTAG "solos-pci"
4748
4849#define CONFIG_RAM_SIZE 128
5657#define FLASH_BUSY 0x60
5758#define FPGA_MODE 0x5C
5859#define FLASH_MODE 0x58
60+ #define GPIO_STATUS 0x54
61+ #define DRIVER_VER 0x50
5962#define TX_DMA_ADDR (port ) (0x40 + (4 * (port)))
6063#define RX_DMA_ADDR (port ) (0x30 + (4 * (port)))
6164
6265#define DATA_RAM_SIZE 32768
6366#define BUF_SIZE 2048
6467#define OLD_BUF_SIZE 4096 /* For FPGA versions <= 2*/
65- #define FPGA_PAGE 528 /* FPGA flash page size*/
66- #define SOLOS_PAGE 512 /* Solos flash page size*/
67- #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
68- #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
68+ /* Old boards use ATMEL AD45DB161D flash */
69+ #define ATMEL_FPGA_PAGE 528 /* FPGA flash page size*/
70+ #define ATMEL_SOLOS_PAGE 512 /* Solos flash page size*/
71+ #define ATMEL_FPGA_BLOCK (ATMEL_FPGA_PAGE * 8) /* FPGA block size*/
72+ #define ATMEL_SOLOS_BLOCK (ATMEL_SOLOS_PAGE * 8) /* Solos block size*/
73+ /* Current boards use M25P/M25PE SPI flash */
74+ #define SPI_FLASH_BLOCK (256 * 64)
6975
7076#define RX_BUF (card , nr ) ((card->buffers) + (nr)*(card->buffer_size)*2)
7177#define TX_BUF (card , nr ) ((card->buffers) + (nr)*(card->buffer_size)*2 + (card->buffer_size))
@@ -122,11 +128,14 @@ struct solos_card {
122128 struct sk_buff_head cli_queue [4 ];
123129 struct sk_buff * tx_skb [4 ];
124130 struct sk_buff * rx_skb [4 ];
131+ unsigned char * dma_bounce ;
125132 wait_queue_head_t param_wq ;
126133 wait_queue_head_t fw_wq ;
127134 int using_dma ;
135+ int dma_alignment ;
128136 int fpga_version ;
129137 int buffer_size ;
138+ int atmel_flash ;
130139};
131140
132141
@@ -451,7 +460,6 @@ static ssize_t console_show(struct device *dev, struct device_attribute *attr,
451460
452461 len = skb -> len ;
453462 memcpy (buf , skb -> data , len );
454- dev_dbg (& card -> dev -> dev , "len: %d\n" , len );
455463
456464 kfree_skb (skb );
457465 return len ;
@@ -498,6 +506,78 @@ static ssize_t console_store(struct device *dev, struct device_attribute *attr,
498506 return err ?:count ;
499507}
500508
509+ struct geos_gpio_attr {
510+ struct device_attribute attr ;
511+ int offset ;
512+ };
513+
514+ #define SOLOS_GPIO_ATTR (_name , _mode , _show , _store , _offset ) \
515+ struct geos_gpio_attr gpio_attr_##_name = { \
516+ .attr = __ATTR(_name, _mode, _show, _store), \
517+ .offset = _offset }
518+
519+ static ssize_t geos_gpio_store (struct device * dev , struct device_attribute * attr ,
520+ const char * buf , size_t count )
521+ {
522+ struct pci_dev * pdev = container_of (dev , struct pci_dev , dev );
523+ struct geos_gpio_attr * gattr = container_of (attr , struct geos_gpio_attr , attr );
524+ struct solos_card * card = pci_get_drvdata (pdev );
525+ uint32_t data32 ;
526+
527+ if (count != 1 && (count != 2 || buf [1 ] != '\n' ))
528+ return - EINVAL ;
529+
530+ spin_lock_irq (& card -> param_queue_lock );
531+ data32 = ioread32 (card -> config_regs + GPIO_STATUS );
532+ if (buf [0 ] == '1' ) {
533+ data32 |= 1 << gattr -> offset ;
534+ iowrite32 (data32 , card -> config_regs + GPIO_STATUS );
535+ } else if (buf [0 ] == '0' ) {
536+ data32 &= ~(1 << gattr -> offset );
537+ iowrite32 (data32 , card -> config_regs + GPIO_STATUS );
538+ } else {
539+ count = - EINVAL ;
540+ }
541+ spin_lock_irq (& card -> param_queue_lock );
542+ return count ;
543+ }
544+
545+ static ssize_t geos_gpio_show (struct device * dev , struct device_attribute * attr ,
546+ char * buf )
547+ {
548+ struct pci_dev * pdev = container_of (dev , struct pci_dev , dev );
549+ struct geos_gpio_attr * gattr = container_of (attr , struct geos_gpio_attr , attr );
550+ struct solos_card * card = pci_get_drvdata (pdev );
551+ uint32_t data32 ;
552+
553+ data32 = ioread32 (card -> config_regs + GPIO_STATUS );
554+ data32 = (data32 >> gattr -> offset ) & 1 ;
555+
556+ return sprintf (buf , "%d\n" , data32 );
557+ }
558+
559+ static ssize_t hardware_show (struct device * dev , struct device_attribute * attr ,
560+ char * buf )
561+ {
562+ struct pci_dev * pdev = container_of (dev , struct pci_dev , dev );
563+ struct geos_gpio_attr * gattr = container_of (attr , struct geos_gpio_attr , attr );
564+ struct solos_card * card = pci_get_drvdata (pdev );
565+ uint32_t data32 ;
566+
567+ data32 = ioread32 (card -> config_regs + GPIO_STATUS );
568+ switch (gattr -> offset ) {
569+ case 0 :
570+ /* HardwareVersion */
571+ data32 = data32 & 0x1F ;
572+ break ;
573+ case 1 :
574+ /* HardwareVariant */
575+ data32 = (data32 >> 5 ) & 0x0F ;
576+ break ;
577+ }
578+ return sprintf (buf , "%d\n" , data32 );
579+ }
580+
501581static DEVICE_ATTR (console , 0644 , console_show , console_store ) ;
502582
503583
@@ -506,6 +586,14 @@ static DEVICE_ATTR(console, 0644, console_show, console_store);
506586
507587#include "solos-attrlist.c"
508588
589+ static SOLOS_GPIO_ATTR (GPIO1 , 0644 , geos_gpio_show , geos_gpio_store , 9 ) ;
590+ static SOLOS_GPIO_ATTR (GPIO2 , 0644 , geos_gpio_show , geos_gpio_store , 10 ) ;
591+ static SOLOS_GPIO_ATTR (GPIO3 , 0644 , geos_gpio_show , geos_gpio_store , 11 ) ;
592+ static SOLOS_GPIO_ATTR (GPIO4 , 0644 , geos_gpio_show , geos_gpio_store , 12 ) ;
593+ static SOLOS_GPIO_ATTR (GPIO5 , 0644 , geos_gpio_show , geos_gpio_store , 13 ) ;
594+ static SOLOS_GPIO_ATTR (PushButton , 0444 , geos_gpio_show , NULL, 14 ) ;
595+ static SOLOS_GPIO_ATTR (HardwareVersion , 0444 , hardware_show , NULL, 0 ) ;
596+ static SOLOS_GPIO_ATTR (HardwareVariant , 0444 , hardware_show , NULL, 1 ) ;
509597#undef SOLOS_ATTR_RO
510598#undef SOLOS_ATTR_RW
511599
@@ -522,6 +610,23 @@ static struct attribute_group solos_attr_group = {
522610 .name = "parameters" ,
523611};
524612
613+ static struct attribute * gpio_attrs [] = {
614+ & gpio_attr_GPIO1 .attr .attr ,
615+ & gpio_attr_GPIO2 .attr .attr ,
616+ & gpio_attr_GPIO3 .attr .attr ,
617+ & gpio_attr_GPIO4 .attr .attr ,
618+ & gpio_attr_GPIO5 .attr .attr ,
619+ & gpio_attr_PushButton .attr .attr ,
620+ & gpio_attr_HardwareVersion .attr .attr ,
621+ & gpio_attr_HardwareVariant .attr .attr ,
622+ NULL
623+ };
624+
625+ static struct attribute_group gpio_attr_group = {
626+ .attrs = gpio_attrs ,
627+ .name = "gpio" ,
628+ };
629+
525630static int flash_upgrade (struct solos_card * card , int chip )
526631{
527632 const struct firmware * fw ;
@@ -533,16 +638,25 @@ static int flash_upgrade(struct solos_card *card, int chip)
533638 switch (chip ) {
534639 case 0 :
535640 fw_name = "solos-FPGA.bin" ;
536- blocksize = FPGA_BLOCK ;
641+ if (card -> atmel_flash )
642+ blocksize = ATMEL_FPGA_BLOCK ;
643+ else
644+ blocksize = SPI_FLASH_BLOCK ;
537645 break ;
538646 case 1 :
539647 fw_name = "solos-Firmware.bin" ;
540- blocksize = SOLOS_BLOCK ;
648+ if (card -> atmel_flash )
649+ blocksize = ATMEL_SOLOS_BLOCK ;
650+ else
651+ blocksize = SPI_FLASH_BLOCK ;
541652 break ;
542653 case 2 :
543654 if (card -> fpga_version > LEGACY_BUFFERS ){
544655 fw_name = "solos-db-FPGA.bin" ;
545- blocksize = FPGA_BLOCK ;
656+ if (card -> atmel_flash )
657+ blocksize = ATMEL_FPGA_BLOCK ;
658+ else
659+ blocksize = SPI_FLASH_BLOCK ;
546660 } else {
547661 dev_info (& card -> dev -> dev , "FPGA version doesn't support"
548662 " daughter board upgrades\n" );
@@ -552,7 +666,10 @@ static int flash_upgrade(struct solos_card *card, int chip)
552666 case 3 :
553667 if (card -> fpga_version > LEGACY_BUFFERS ){
554668 fw_name = "solos-Firmware.bin" ;
555- blocksize = SOLOS_BLOCK ;
669+ if (card -> atmel_flash )
670+ blocksize = ATMEL_SOLOS_BLOCK ;
671+ else
672+ blocksize = SPI_FLASH_BLOCK ;
556673 } else {
557674 dev_info (& card -> dev -> dev , "FPGA version doesn't support"
558675 " daughter board upgrades\n" );
@@ -568,6 +685,9 @@ static int flash_upgrade(struct solos_card *card, int chip)
568685
569686 dev_info (& card -> dev -> dev , "Flash upgrade starting\n" );
570687
688+ /* New FPGAs require driver version before permitting flash upgrades */
689+ iowrite32 (DRIVER_VERSION , card -> config_regs + DRIVER_VER );
690+
571691 numblocks = fw -> size / blocksize ;
572692 dev_info (& card -> dev -> dev , "Firmware size: %zd\n" , fw -> size );
573693 dev_info (& card -> dev -> dev , "Number of blocks: %d\n" , numblocks );
@@ -597,9 +717,13 @@ static int flash_upgrade(struct solos_card *card, int chip)
597717 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
598718 iowrite32 (((chip * 2 ) + 1 ), card -> config_regs + FLASH_MODE );
599719
600- /* Copy block to buffer, swapping each 16 bits */
720+ /* Copy block to buffer, swapping each 16 bits for Atmel flash */
601721 for (i = 0 ; i < blocksize ; i += 4 ) {
602- uint32_t word = swahb32p ((uint32_t * )(fw -> data + offset + i ));
722+ uint32_t word ;
723+ if (card -> atmel_flash )
724+ word = swahb32p ((uint32_t * )(fw -> data + offset + i ));
725+ else
726+ word = * (uint32_t * )(fw -> data + offset + i );
603727 if (card -> fpga_version > LEGACY_BUFFERS )
604728 iowrite32 (word , FLASH_BUF + i );
605729 else
@@ -961,7 +1085,12 @@ static uint32_t fpga_tx(struct solos_card *card)
9611085 tx_started |= 1 << port ;
9621086 oldskb = skb ; /* We're done with this skb already */
9631087 } else if (skb && card -> using_dma ) {
964- SKB_CB (skb )-> dma_addr = pci_map_single (card -> dev , skb -> data ,
1088+ unsigned char * data = skb -> data ;
1089+ if ((unsigned long )data & card -> dma_alignment ) {
1090+ data = card -> dma_bounce + (BUF_SIZE * port );
1091+ memcpy (data , skb -> data , skb -> len );
1092+ }
1093+ SKB_CB (skb )-> dma_addr = pci_map_single (card -> dev , data ,
9651094 skb -> len , PCI_DMA_TODEVICE );
9661095 card -> tx_skb [port ] = skb ;
9671096 iowrite32 (SKB_CB (skb )-> dma_addr ,
@@ -1133,18 +1262,33 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
11331262 db_fpga_upgrade = db_firmware_upgrade = 0 ;
11341263 }
11351264
1265+ /* Stopped using Atmel flash after 0.03-38 */
1266+ if (fpga_ver < 39 )
1267+ card -> atmel_flash = 1 ;
1268+ else
1269+ card -> atmel_flash = 0 ;
1270+
1271+ data32 = ioread32 (card -> config_regs + PORTS );
1272+ card -> nr_ports = (data32 & 0x000000FF );
1273+
11361274 if (card -> fpga_version >= DMA_SUPPORTED ) {
11371275 pci_set_master (dev );
11381276 card -> using_dma = 1 ;
1277+ if (1 ) { /* All known FPGA versions so far */
1278+ card -> dma_alignment = 3 ;
1279+ card -> dma_bounce = kmalloc (card -> nr_ports * BUF_SIZE , GFP_KERNEL );
1280+ if (!card -> dma_bounce ) {
1281+ dev_warn (& card -> dev -> dev , "Failed to allocate DMA bounce buffers\n" );
1282+ /* Fallback to MMIO doesn't work */
1283+ goto out_unmap_both ;
1284+ }
1285+ }
11391286 } else {
11401287 card -> using_dma = 0 ;
11411288 /* Set RX empty flag for all ports */
11421289 iowrite32 (0xF0 , card -> config_regs + FLAGS_ADDR );
11431290 }
11441291
1145- data32 = ioread32 (card -> config_regs + PORTS );
1146- card -> nr_ports = (data32 & 0x000000FF );
1147-
11481292 pci_set_drvdata (dev , card );
11491293
11501294 tasklet_init (& card -> tlet , solos_bh , (unsigned long )card );
@@ -1179,6 +1323,10 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
11791323 if (err )
11801324 goto out_free_irq ;
11811325
1326+ if (card -> fpga_version >= DMA_SUPPORTED &&
1327+ sysfs_create_group (& card -> dev -> dev .kobj , & gpio_attr_group ))
1328+ dev_err (& card -> dev -> dev , "Could not register parameter group for GPIOs\n" );
1329+
11821330 return 0 ;
11831331
11841332 out_free_irq :
@@ -1187,6 +1335,7 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
11871335 tasklet_kill (& card -> tlet );
11881336
11891337 out_unmap_both :
1338+ kfree (card -> dma_bounce );
11901339 pci_set_drvdata (dev , NULL );
11911340 pci_iounmap (dev , card -> buffers );
11921341 out_unmap_config :
@@ -1289,11 +1438,16 @@ static void fpga_remove(struct pci_dev *dev)
12891438 iowrite32 (1 , card -> config_regs + FPGA_MODE );
12901439 (void )ioread32 (card -> config_regs + FPGA_MODE );
12911440
1441+ if (card -> fpga_version >= DMA_SUPPORTED )
1442+ sysfs_remove_group (& card -> dev -> dev .kobj , & gpio_attr_group );
1443+
12921444 atm_remove (card );
12931445
12941446 free_irq (dev -> irq , card );
12951447 tasklet_kill (& card -> tlet );
12961448
1449+ kfree (card -> dma_bounce );
1450+
12971451 /* Release device from reset */
12981452 iowrite32 (0 , card -> config_regs + FPGA_MODE );
12991453 (void )ioread32 (card -> config_regs + FPGA_MODE );
0 commit comments