@@ -36,11 +36,15 @@ static int max_devices = 16;
3636module_param (max_devices , int , 0644 );
3737MODULE_PARM_DESC (max_devices , "max number of switchtec device instances" );
3838
39- static bool use_dma_mrpc = 1 ;
39+ static bool use_dma_mrpc = true ;
4040module_param (use_dma_mrpc , bool , 0644 );
4141MODULE_PARM_DESC (use_dma_mrpc ,
4242 "Enable the use of the DMA MRPC feature" );
4343
44+ static int nirqs = 32 ;
45+ module_param (nirqs , int , 0644 );
46+ MODULE_PARM_DESC (nirqs , "number of interrupts to allocate (more may be useful for NTB applications)" );
47+
4448static dev_t switchtec_devt ;
4549static DEFINE_IDA (switchtec_minor_ida );
4650
@@ -60,10 +64,11 @@ struct switchtec_user {
6064
6165 enum mrpc_state state ;
6266
63- struct completion comp ;
67+ wait_queue_head_t cmd_comp ;
6468 struct kref kref ;
6569 struct list_head list ;
6670
71+ bool cmd_done ;
6772 u32 cmd ;
6873 u32 status ;
6974 u32 return_code ;
@@ -92,7 +97,7 @@ static struct switchtec_user *stuser_create(struct switchtec_dev *stdev)
9297 stuser -> stdev = stdev ;
9398 kref_init (& stuser -> kref );
9499 INIT_LIST_HEAD (& stuser -> list );
95- init_completion (& stuser -> comp );
100+ init_waitqueue_head (& stuser -> cmd_comp );
96101 stuser -> event_cnt = atomic_read (& stdev -> event_cnt );
97102
98103 dev_dbg (& stdev -> dev , "%s: %p\n" , __func__ , stuser );
@@ -187,7 +192,7 @@ static int mrpc_queue_cmd(struct switchtec_user *stuser)
187192 kref_get (& stuser -> kref );
188193 stuser -> read_len = sizeof (stuser -> data );
189194 stuser_set_state (stuser , MRPC_QUEUED );
190- init_completion ( & stuser -> comp ) ;
195+ stuser -> cmd_done = false ;
191196 list_add_tail (& stuser -> list , & stdev -> mrpc_queue );
192197
193198 mrpc_cmd_submit (stdev );
@@ -201,7 +206,8 @@ static void mrpc_cleanup_cmd(struct switchtec_dev *stdev)
201206 struct switchtec_user * stuser = list_entry (stdev -> mrpc_queue .next ,
202207 struct switchtec_user , list );
203208
204- complete_all (& stuser -> comp );
209+ stuser -> cmd_done = true;
210+ wake_up_interruptible (& stuser -> cmd_comp );
205211 list_del_init (& stuser -> list );
206212 stuser_put (stuser );
207213 stdev -> mrpc_busy = 0 ;
@@ -362,13 +368,14 @@ static ssize_t field ## _show(struct device *dev, \
362368{ \
363369 struct switchtec_dev *stdev = to_stdev(dev); \
364370 struct sys_info_regs __iomem *si = stdev->mmio_sys_info; \
365- \
366- if (stdev->gen == SWITCHTEC_GEN4) \
371+ if (stdev->gen == SWITCHTEC_GEN3) \
372+ return io_string_show(buf, &si->gen3.field, \
373+ sizeof(si->gen3.field)); \
374+ else if (stdev->gen == SWITCHTEC_GEN4) \
367375 return io_string_show(buf, &si->gen4.field, \
368376 sizeof(si->gen4.field)); \
369377 else \
370- return io_string_show(buf, &si->gen3.field, \
371- sizeof(si->gen3.field)); \
378+ return -ENOTSUPP; \
372379} \
373380\
374381static DEVICE_ATTR_RO(field)
@@ -383,7 +390,7 @@ static ssize_t component_vendor_show(struct device *dev,
383390 struct switchtec_dev * stdev = to_stdev (dev );
384391 struct sys_info_regs __iomem * si = stdev -> mmio_sys_info ;
385392
386- /* component_vendor field not supported after gen4 */
393+ /* component_vendor field not supported after gen3 */
387394 if (stdev -> gen != SWITCHTEC_GEN3 )
388395 return sprintf (buf , "none\n" );
389396
@@ -398,7 +405,7 @@ static ssize_t component_id_show(struct device *dev,
398405 struct switchtec_dev * stdev = to_stdev (dev );
399406 int id = ioread16 (& stdev -> mmio_sys_info -> gen3 .component_id );
400407
401- /* component_id field not supported after gen4 */
408+ /* component_id field not supported after gen3 */
402409 if (stdev -> gen != SWITCHTEC_GEN3 )
403410 return sprintf (buf , "none\n" );
404411
@@ -412,7 +419,7 @@ static ssize_t component_revision_show(struct device *dev,
412419 struct switchtec_dev * stdev = to_stdev (dev );
413420 int rev = ioread8 (& stdev -> mmio_sys_info -> gen3 .component_revision );
414421
415- /* component_revision field not supported after gen4 */
422+ /* component_revision field not supported after gen3 */
416423 if (stdev -> gen != SWITCHTEC_GEN3 )
417424 return sprintf (buf , "255\n" );
418425
@@ -466,7 +473,7 @@ static int switchtec_dev_open(struct inode *inode, struct file *filp)
466473 return PTR_ERR (stuser );
467474
468475 filp -> private_data = stuser ;
469- nonseekable_open (inode , filp );
476+ stream_open (inode , filp );
470477
471478 dev_dbg (& stdev -> dev , "%s: %p\n" , __func__ , stuser );
472479
@@ -572,10 +579,11 @@ static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
572579 mutex_unlock (& stdev -> mrpc_mutex );
573580
574581 if (filp -> f_flags & O_NONBLOCK ) {
575- if (!try_wait_for_completion ( & stuser -> comp ) )
582+ if (!stuser -> cmd_done )
576583 return - EAGAIN ;
577584 } else {
578- rc = wait_for_completion_interruptible (& stuser -> comp );
585+ rc = wait_event_interruptible (stuser -> cmd_comp ,
586+ stuser -> cmd_done );
579587 if (rc < 0 )
580588 return rc ;
581589 }
@@ -629,15 +637,15 @@ static __poll_t switchtec_dev_poll(struct file *filp, poll_table *wait)
629637 struct switchtec_dev * stdev = stuser -> stdev ;
630638 __poll_t ret = 0 ;
631639
632- poll_wait (filp , & stuser -> comp . wait , wait );
640+ poll_wait (filp , & stuser -> cmd_comp , wait );
633641 poll_wait (filp , & stdev -> event_wq , wait );
634642
635643 if (lock_mutex_and_test_alive (stdev ))
636644 return EPOLLIN | EPOLLRDHUP | EPOLLOUT | EPOLLERR | EPOLLHUP ;
637645
638646 mutex_unlock (& stdev -> mrpc_mutex );
639647
640- if (try_wait_for_completion ( & stuser -> comp ) )
648+ if (stuser -> cmd_done )
641649 ret |= EPOLLIN | EPOLLRDNORM ;
642650
643651 if (stuser -> event_cnt != atomic_read (& stdev -> event_cnt ))
@@ -891,7 +899,7 @@ static int ioctl_event_summary(struct switchtec_dev *stdev,
891899 return - ENOMEM ;
892900
893901 s -> global = ioread32 (& stdev -> mmio_sw_event -> global_summary );
894- s -> part_bitmap = ioread32 (& stdev -> mmio_sw_event -> part_event_bitmap );
902+ s -> part_bitmap = ioread64 (& stdev -> mmio_sw_event -> part_event_bitmap );
895903 s -> local_part = ioread32 (& stdev -> mmio_part_cfg -> part_event_summary );
896904
897905 for (i = 0 ; i < stdev -> partition_count ; i ++ ) {
@@ -985,18 +993,18 @@ static u32 __iomem *event_hdr_addr(struct switchtec_dev *stdev,
985993 size_t off ;
986994
987995 if (event_id < 0 || event_id >= SWITCHTEC_IOCTL_MAX_EVENTS )
988- return ERR_PTR (- EINVAL );
996+ return ( u32 __iomem * ) ERR_PTR (- EINVAL );
989997
990998 off = event_regs [event_id ].offset ;
991999
9921000 if (event_regs [event_id ].map_reg == part_ev_reg ) {
9931001 if (index == SWITCHTEC_IOCTL_EVENT_LOCAL_PART_IDX )
9941002 index = stdev -> partition ;
9951003 else if (index < 0 || index >= stdev -> partition_count )
996- return ERR_PTR (- EINVAL );
1004+ return ( u32 __iomem * ) ERR_PTR (- EINVAL );
9971005 } else if (event_regs [event_id ].map_reg == pff_ev_reg ) {
9981006 if (index < 0 || index >= stdev -> pff_csr_count )
999- return ERR_PTR (- EINVAL );
1007+ return ( u32 __iomem * ) ERR_PTR (- EINVAL );
10001008 }
10011009
10021010 return event_regs [event_id ].map_reg (stdev , off , index );
@@ -1105,11 +1113,11 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,
11051113}
11061114
11071115static int ioctl_pff_to_port (struct switchtec_dev * stdev ,
1108- struct switchtec_ioctl_pff_port * up )
1116+ struct switchtec_ioctl_pff_port __user * up )
11091117{
11101118 int i , part ;
11111119 u32 reg ;
1112- struct part_cfg_regs * pcfg ;
1120+ struct part_cfg_regs __iomem * pcfg ;
11131121 struct switchtec_ioctl_pff_port p ;
11141122
11151123 if (copy_from_user (& p , up , sizeof (p )))
@@ -1152,10 +1160,10 @@ static int ioctl_pff_to_port(struct switchtec_dev *stdev,
11521160}
11531161
11541162static int ioctl_port_to_pff (struct switchtec_dev * stdev ,
1155- struct switchtec_ioctl_pff_port * up )
1163+ struct switchtec_ioctl_pff_port __user * up )
11561164{
11571165 struct switchtec_ioctl_pff_port p ;
1158- struct part_cfg_regs * pcfg ;
1166+ struct part_cfg_regs __iomem * pcfg ;
11591167
11601168 if (copy_from_user (& p , up , sizeof (p )))
11611169 return - EFAULT ;
@@ -1242,7 +1250,7 @@ static const struct file_operations switchtec_fops = {
12421250 .read = switchtec_dev_read ,
12431251 .poll = switchtec_dev_poll ,
12441252 .unlocked_ioctl = switchtec_dev_ioctl ,
1245- .compat_ioctl = switchtec_dev_ioctl ,
1253+ .compat_ioctl = compat_ptr_ioctl ,
12461254};
12471255
12481256static void link_event_work (struct work_struct * work )
@@ -1299,7 +1307,7 @@ static void stdev_release(struct device *dev)
12991307{
13001308 struct switchtec_dev * stdev = to_stdev (dev );
13011309
1302- if (stdev -> dma_mrpc ){
1310+ if (stdev -> dma_mrpc ) {
13031311 iowrite32 (0 , & stdev -> mmio_mrpc -> dma_en );
13041312 flush_wc_buf (stdev );
13051313 writeq (0 , & stdev -> mmio_mrpc -> dma_addr );
@@ -1323,7 +1331,8 @@ static void stdev_kill(struct switchtec_dev *stdev)
13231331
13241332 /* Wake up and kill any users waiting on an MRPC request */
13251333 list_for_each_entry_safe (stuser , tmpuser , & stdev -> mrpc_queue , list ) {
1326- complete_all (& stuser -> comp );
1334+ stuser -> cmd_done = true;
1335+ wake_up_interruptible (& stuser -> cmd_comp );
13271336 list_del_init (& stuser -> list );
13281337 stuser_put (stuser );
13291338 }
@@ -1488,12 +1497,16 @@ static int switchtec_init_isr(struct switchtec_dev *stdev)
14881497 int dma_mrpc_irq ;
14891498 int rc ;
14901499
1491- nvecs = pci_alloc_irq_vectors (stdev -> pdev , 1 , 4 ,
1492- PCI_IRQ_MSIX | PCI_IRQ_MSI );
1500+ if (nirqs < 4 )
1501+ nirqs = 4 ;
1502+
1503+ nvecs = pci_alloc_irq_vectors (stdev -> pdev , 1 , nirqs ,
1504+ PCI_IRQ_MSIX | PCI_IRQ_MSI |
1505+ PCI_IRQ_VIRTUAL );
14931506 if (nvecs < 0 )
14941507 return nvecs ;
14951508
1496- event_irq = ioread32 (& stdev -> mmio_part_cfg -> vep_vector_number );
1509+ event_irq = ioread16 (& stdev -> mmio_part_cfg -> vep_vector_number );
14971510 if (event_irq < 0 || event_irq >= nvecs )
14981511 return - EFAULT ;
14991512
@@ -1512,7 +1525,7 @@ static int switchtec_init_isr(struct switchtec_dev *stdev)
15121525 return rc ;
15131526
15141527 dma_mrpc_irq = ioread32 (& stdev -> mmio_mrpc -> dma_vector );
1515- if ( dma_mrpc_irq < 0 || dma_mrpc_irq >= nvecs )
1528+ if (dma_mrpc_irq < 0 || dma_mrpc_irq >= nvecs )
15161529 return - EFAULT ;
15171530
15181531 dma_mrpc_irq = pci_irq_vector (stdev -> pdev , dma_mrpc_irq );
@@ -1530,11 +1543,11 @@ static void init_pff(struct switchtec_dev *stdev)
15301543{
15311544 int i ;
15321545 u32 reg ;
1533- struct part_cfg_regs * pcfg = stdev -> mmio_part_cfg ;
1546+ struct part_cfg_regs __iomem * pcfg = stdev -> mmio_part_cfg ;
15341547
15351548 for (i = 0 ; i < SWITCHTEC_MAX_PFF_CSR ; i ++ ) {
15361549 reg = ioread16 (& stdev -> mmio_pff_csr [i ].vendor_id );
1537- if (reg != MICROSEMI_VENDOR_ID )
1550+ if (reg != PCI_VENDOR_ID_MICROSEMI )
15381551 break ;
15391552 }
15401553
@@ -1561,6 +1574,7 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
15611574 int rc ;
15621575 void __iomem * map ;
15631576 unsigned long res_start , res_len ;
1577+ u32 __iomem * part_id ;
15641578
15651579 rc = pcim_enable_device (pdev );
15661580 if (rc )
@@ -1595,12 +1609,15 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
15951609 stdev -> mmio_sys_info = stdev -> mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET ;
15961610 stdev -> mmio_flash_info = stdev -> mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET ;
15971611 stdev -> mmio_ntb = stdev -> mmio + SWITCHTEC_GAS_NTB_OFFSET ;
1598- if (stdev -> gen == SWITCHTEC_GEN4 )
1599- stdev -> partition = ioread8 (& stdev -> mmio_sys_info ->
1600- gen4 .partition_id );
1612+
1613+ if (stdev -> gen == SWITCHTEC_GEN3 )
1614+ part_id = & stdev -> mmio_sys_info -> gen3 .partition_id ;
1615+ else if (stdev -> gen == SWITCHTEC_GEN4 )
1616+ part_id = & stdev -> mmio_sys_info -> gen4 .partition_id ;
16011617 else
1602- stdev -> partition = ioread8 (& stdev -> mmio_sys_info ->
1603- gen3 .partition_id );
1618+ return - ENOTSUPP ;
1619+
1620+ stdev -> partition = ioread8 (part_id );
16041621 stdev -> partition_count = ioread8 (& stdev -> mmio_ntb -> partition_count );
16051622 stdev -> mmio_part_cfg_all = stdev -> mmio + SWITCHTEC_GAS_PART_CFG_OFFSET ;
16061623 stdev -> mmio_part_cfg = & stdev -> mmio_part_cfg_all [stdev -> partition ];
@@ -1619,8 +1636,10 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,
16191636 if (!ioread32 (& stdev -> mmio_mrpc -> dma_ver ))
16201637 return 0 ;
16211638
1622- stdev -> dma_mrpc = dma_alloc_coherent (& stdev -> pdev -> dev , sizeof (* stdev -> dma_mrpc ),
1623- & stdev -> dma_mrpc_dma_addr , GFP_KERNEL );
1639+ stdev -> dma_mrpc = dma_alloc_coherent (& stdev -> pdev -> dev ,
1640+ sizeof (* stdev -> dma_mrpc ),
1641+ & stdev -> dma_mrpc_dma_addr ,
1642+ GFP_KERNEL );
16241643 if (stdev -> dma_mrpc == NULL )
16251644 return - ENOMEM ;
16261645
@@ -1633,7 +1652,7 @@ static int switchtec_pci_probe(struct pci_dev *pdev,
16331652 struct switchtec_dev * stdev ;
16341653 int rc ;
16351654
1636- if (pdev -> class == MICROSEMI_NTB_CLASSCODE )
1655+ if (pdev -> class == ( PCI_CLASS_BRIDGE_OTHER << 8 ) )
16371656 request_module_nowait ("ntb_hw_switchtec" );
16381657
16391658 stdev = stdev_create (pdev );
@@ -1798,20 +1817,20 @@ static const struct pci_error_handlers switchtec_pci_err_handler = {
17981817
17991818#define SWITCHTEC_PCI_DEVICE (device_id , gen ) \
18001819 { \
1801- .vendor = MICROSEMI_VENDOR_ID , \
1820+ .vendor = PCI_VENDOR_ID_MICROSEMI , \
18021821 .device = device_id, \
18031822 .subvendor = PCI_ANY_ID, \
18041823 .subdevice = PCI_ANY_ID, \
1805- .class = MICROSEMI_MGMT_CLASSCODE , \
1824+ .class = (PCI_CLASS_MEMORY_OTHER << 8) , \
18061825 .class_mask = 0xFFFFFFFF, \
18071826 .driver_data = gen, \
18081827 }, \
18091828 { \
1810- .vendor = MICROSEMI_VENDOR_ID , \
1829+ .vendor = PCI_VENDOR_ID_MICROSEMI , \
18111830 .device = device_id, \
18121831 .subvendor = PCI_ANY_ID, \
18131832 .subdevice = PCI_ANY_ID, \
1814- .class = MICROSEMI_NTB_CLASSCODE , \
1833+ .class = (PCI_CLASS_BRIDGE_OTHER << 8) , \
18151834 .class_mask = 0xFFFFFFFF, \
18161835 .driver_data = gen, \
18171836 }
@@ -1865,6 +1884,15 @@ static const struct pci_device_id switchtec_pci_tbl[] = {
18651884 SWITCHTEC_PCI_DEVICE (0x4252 , SWITCHTEC_GEN4 ), //PAX 52XG4
18661885 SWITCHTEC_PCI_DEVICE (0x4236 , SWITCHTEC_GEN4 ), //PAX 36XG4
18671886 SWITCHTEC_PCI_DEVICE (0x4228 , SWITCHTEC_GEN4 ), //PAX 28XG4
1887+ SWITCHTEC_PCI_DEVICE (0x4352 , SWITCHTEC_GEN4 ), //PFXA 52XG4
1888+ SWITCHTEC_PCI_DEVICE (0x4336 , SWITCHTEC_GEN4 ), //PFXA 36XG4
1889+ SWITCHTEC_PCI_DEVICE (0x4328 , SWITCHTEC_GEN4 ), //PFXA 28XG4
1890+ SWITCHTEC_PCI_DEVICE (0x4452 , SWITCHTEC_GEN4 ), //PSXA 52XG4
1891+ SWITCHTEC_PCI_DEVICE (0x4436 , SWITCHTEC_GEN4 ), //PSXA 36XG4
1892+ SWITCHTEC_PCI_DEVICE (0x4428 , SWITCHTEC_GEN4 ), //PSXA 28XG4
1893+ SWITCHTEC_PCI_DEVICE (0x4552 , SWITCHTEC_GEN4 ), //PAXA 52XG4
1894+ SWITCHTEC_PCI_DEVICE (0x4536 , SWITCHTEC_GEN4 ), //PAXA 36XG4
1895+ SWITCHTEC_PCI_DEVICE (0x4528 , SWITCHTEC_GEN4 ), //PAXA 28XG4
18681896 {0 }
18691897};
18701898MODULE_DEVICE_TABLE (pci , switchtec_pci_tbl );
0 commit comments