42
42
#include <linux/swab.h>
43
43
#include <linux/slab.h>
44
44
45
- #define VERSION "0.07"
45
+ #define VERSION "1.04"
46
+ #define DRIVER_VERSION 0x01
46
47
#define PTAG "solos-pci"
47
48
48
49
#define CONFIG_RAM_SIZE 128
56
57
#define FLASH_BUSY 0x60
57
58
#define FPGA_MODE 0x5C
58
59
#define FLASH_MODE 0x58
60
+ #define GPIO_STATUS 0x54
61
+ #define DRIVER_VER 0x50
59
62
#define TX_DMA_ADDR (port ) (0x40 + (4 * (port)))
60
63
#define RX_DMA_ADDR (port ) (0x30 + (4 * (port)))
61
64
62
65
#define DATA_RAM_SIZE 32768
63
66
#define BUF_SIZE 2048
64
67
#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)
69
75
70
76
#define RX_BUF (card , nr ) ((card->buffers) + (nr)*(card->buffer_size)*2)
71
77
#define TX_BUF (card , nr ) ((card->buffers) + (nr)*(card->buffer_size)*2 + (card->buffer_size))
@@ -122,11 +128,14 @@ struct solos_card {
122
128
struct sk_buff_head cli_queue [4 ];
123
129
struct sk_buff * tx_skb [4 ];
124
130
struct sk_buff * rx_skb [4 ];
131
+ unsigned char * dma_bounce ;
125
132
wait_queue_head_t param_wq ;
126
133
wait_queue_head_t fw_wq ;
127
134
int using_dma ;
135
+ int dma_alignment ;
128
136
int fpga_version ;
129
137
int buffer_size ;
138
+ int atmel_flash ;
130
139
};
131
140
132
141
@@ -451,7 +460,6 @@ static ssize_t console_show(struct device *dev, struct device_attribute *attr,
451
460
452
461
len = skb -> len ;
453
462
memcpy (buf , skb -> data , len );
454
- dev_dbg (& card -> dev -> dev , "len: %d\n" , len );
455
463
456
464
kfree_skb (skb );
457
465
return len ;
@@ -498,6 +506,78 @@ static ssize_t console_store(struct device *dev, struct device_attribute *attr,
498
506
return err ?:count ;
499
507
}
500
508
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
+
501
581
static DEVICE_ATTR (console , 0644 , console_show , console_store ) ;
502
582
503
583
@@ -506,6 +586,14 @@ static DEVICE_ATTR(console, 0644, console_show, console_store);
506
586
507
587
#include "solos-attrlist.c"
508
588
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 ) ;
509
597
#undef SOLOS_ATTR_RO
510
598
#undef SOLOS_ATTR_RW
511
599
@@ -522,6 +610,23 @@ static struct attribute_group solos_attr_group = {
522
610
.name = "parameters" ,
523
611
};
524
612
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
+
525
630
static int flash_upgrade (struct solos_card * card , int chip )
526
631
{
527
632
const struct firmware * fw ;
@@ -533,16 +638,25 @@ static int flash_upgrade(struct solos_card *card, int chip)
533
638
switch (chip ) {
534
639
case 0 :
535
640
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 ;
537
645
break ;
538
646
case 1 :
539
647
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 ;
541
652
break ;
542
653
case 2 :
543
654
if (card -> fpga_version > LEGACY_BUFFERS ){
544
655
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 ;
546
660
} else {
547
661
dev_info (& card -> dev -> dev , "FPGA version doesn't support"
548
662
" daughter board upgrades\n" );
@@ -552,7 +666,10 @@ static int flash_upgrade(struct solos_card *card, int chip)
552
666
case 3 :
553
667
if (card -> fpga_version > LEGACY_BUFFERS ){
554
668
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 ;
556
673
} else {
557
674
dev_info (& card -> dev -> dev , "FPGA version doesn't support"
558
675
" daughter board upgrades\n" );
@@ -568,6 +685,9 @@ static int flash_upgrade(struct solos_card *card, int chip)
568
685
569
686
dev_info (& card -> dev -> dev , "Flash upgrade starting\n" );
570
687
688
+ /* New FPGAs require driver version before permitting flash upgrades */
689
+ iowrite32 (DRIVER_VERSION , card -> config_regs + DRIVER_VER );
690
+
571
691
numblocks = fw -> size / blocksize ;
572
692
dev_info (& card -> dev -> dev , "Firmware size: %zd\n" , fw -> size );
573
693
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)
597
717
/* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
598
718
iowrite32 (((chip * 2 ) + 1 ), card -> config_regs + FLASH_MODE );
599
719
600
- /* Copy block to buffer, swapping each 16 bits */
720
+ /* Copy block to buffer, swapping each 16 bits for Atmel flash */
601
721
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 );
603
727
if (card -> fpga_version > LEGACY_BUFFERS )
604
728
iowrite32 (word , FLASH_BUF + i );
605
729
else
@@ -961,7 +1085,12 @@ static uint32_t fpga_tx(struct solos_card *card)
961
1085
tx_started |= 1 << port ;
962
1086
oldskb = skb ; /* We're done with this skb already */
963
1087
} 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 ,
965
1094
skb -> len , PCI_DMA_TODEVICE );
966
1095
card -> tx_skb [port ] = skb ;
967
1096
iowrite32 (SKB_CB (skb )-> dma_addr ,
@@ -1133,18 +1262,33 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1133
1262
db_fpga_upgrade = db_firmware_upgrade = 0 ;
1134
1263
}
1135
1264
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
+
1136
1274
if (card -> fpga_version >= DMA_SUPPORTED ) {
1137
1275
pci_set_master (dev );
1138
1276
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
+ }
1139
1286
} else {
1140
1287
card -> using_dma = 0 ;
1141
1288
/* Set RX empty flag for all ports */
1142
1289
iowrite32 (0xF0 , card -> config_regs + FLAGS_ADDR );
1143
1290
}
1144
1291
1145
- data32 = ioread32 (card -> config_regs + PORTS );
1146
- card -> nr_ports = (data32 & 0x000000FF );
1147
-
1148
1292
pci_set_drvdata (dev , card );
1149
1293
1150
1294
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)
1179
1323
if (err )
1180
1324
goto out_free_irq ;
1181
1325
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
+
1182
1330
return 0 ;
1183
1331
1184
1332
out_free_irq :
@@ -1187,6 +1335,7 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1187
1335
tasklet_kill (& card -> tlet );
1188
1336
1189
1337
out_unmap_both :
1338
+ kfree (card -> dma_bounce );
1190
1339
pci_set_drvdata (dev , NULL );
1191
1340
pci_iounmap (dev , card -> buffers );
1192
1341
out_unmap_config :
@@ -1289,11 +1438,16 @@ static void fpga_remove(struct pci_dev *dev)
1289
1438
iowrite32 (1 , card -> config_regs + FPGA_MODE );
1290
1439
(void )ioread32 (card -> config_regs + FPGA_MODE );
1291
1440
1441
+ if (card -> fpga_version >= DMA_SUPPORTED )
1442
+ sysfs_remove_group (& card -> dev -> dev .kobj , & gpio_attr_group );
1443
+
1292
1444
atm_remove (card );
1293
1445
1294
1446
free_irq (dev -> irq , card );
1295
1447
tasklet_kill (& card -> tlet );
1296
1448
1449
+ kfree (card -> dma_bounce );
1450
+
1297
1451
/* Release device from reset */
1298
1452
iowrite32 (0 , card -> config_regs + FPGA_MODE );
1299
1453
(void )ioread32 (card -> config_regs + FPGA_MODE );
0 commit comments