2019-05-28 10:10:09 -07:00
// SPDX-License-Identifier: GPL-2.0-only
2005-04-16 15:20:36 -07:00
/*
* wanXL serial card driver for Linux
* host part
*
* Copyright ( C ) 2003 Krzysztof Halasa < khc @ pm . waw . pl >
*
* Status :
* - Only DTE ( external clock ) support with NRZ and NRZI encodings
* - wanXL100 will require minor driver modifications , no access to hw
*/
2011-06-26 19:01:28 +00:00
# define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2005-04-16 15:20:36 -07:00
# include <linux/module.h>
# include <linux/kernel.h>
# include <linux/slab.h>
# include <linux/sched.h>
# include <linux/types.h>
# include <linux/fcntl.h>
# include <linux/string.h>
# include <linux/errno.h>
# include <linux/init.h>
2011-06-06 10:43:46 +00:00
# include <linux/interrupt.h>
2005-04-16 15:20:36 -07:00
# include <linux/ioport.h>
# include <linux/netdevice.h>
# include <linux/hdlc.h>
# include <linux/pci.h>
2005-06-26 18:22:14 -04:00
# include <linux/dma-mapping.h>
2005-11-30 23:47:05 -05:00
# include <linux/delay.h>
2005-04-16 15:20:36 -07:00
# include <asm/io.h>
# include "wanxl.h"
2021-05-24 22:47:09 +08:00
static const char * version = " wanXL serial card driver version: 0.48 " ;
2005-04-16 15:20:36 -07:00
# define PLX_CTL_RESET 0x40000000 /* adapter reset */
# undef DEBUG_PKT
# undef DEBUG_PCI
/* MAILBOX #1 - PUTS COMMANDS */
# define MBX1_CMD_ABORTJ 0x85000000 /* Abort and Jump */
# ifdef __LITTLE_ENDIAN
# define MBX1_CMD_BSWAP 0x8C000001 /* little-endian Byte Swap Mode */
# else
# define MBX1_CMD_BSWAP 0x8C000000 /* big-endian Byte Swap Mode */
# endif
/* MAILBOX #2 - DRAM SIZE */
# define MBX2_MEMSZ_MASK 0xFFFF0000 /* PUTS Memory Size Register mask */
2014-08-10 13:06:47 +05:30
struct port {
2005-04-16 15:20:36 -07:00
struct net_device * dev ;
2014-08-10 13:06:47 +05:30
struct card * card ;
2005-04-16 15:20:36 -07:00
spinlock_t lock ; /* for wanxl_xmit */
2021-05-24 22:47:11 +08:00
int node ; /* physical port #0 - 3 */
2005-04-16 15:20:36 -07:00
unsigned int clock_type ;
int tx_in , tx_out ;
struct sk_buff * tx_skbs [ TX_BUFFERS ] ;
2014-08-10 13:06:47 +05:30
} ;
2005-04-16 15:20:36 -07:00
2014-08-10 13:06:47 +05:30
struct card_status {
2005-04-16 15:20:36 -07:00
desc_t rx_descs [ RX_QUEUE_LENGTH ] ;
port_status_t port_status [ 4 ] ;
2014-08-10 13:06:47 +05:30
} ;
2005-04-16 15:20:36 -07:00
2014-08-10 13:06:47 +05:30
struct card {
2005-04-16 15:20:36 -07:00
int n_ports ; /* 1, 2 or 4 ports */
u8 irq ;
u8 __iomem * plx ; /* PLX PCI9060 virtual base address */
struct pci_dev * pdev ; /* for pci_name(pdev) */
int rx_in ;
struct sk_buff * rx_skbs [ RX_QUEUE_LENGTH ] ;
2014-08-10 13:06:47 +05:30
struct card_status * status ; /* shared between host and card */
2005-04-16 15:20:36 -07:00
dma_addr_t status_address ;
2020-02-26 15:23:17 -06:00
struct port ports [ ] ; /* 1 - 4 port structures follow */
2014-08-10 13:06:47 +05:30
} ;
2005-04-16 15:20:36 -07:00
2014-08-10 13:06:47 +05:30
static inline struct port * dev_to_port ( struct net_device * dev )
2005-04-16 15:20:36 -07:00
{
2014-08-10 13:06:47 +05:30
return ( struct port * ) dev_to_hdlc ( dev ) - > priv ;
2005-04-16 15:20:36 -07:00
}
2014-08-10 13:06:47 +05:30
static inline port_status_t * get_status ( struct port * port )
2005-04-16 15:20:36 -07:00
{
return & port - > card - > status - > port_status [ port - > node ] ;
}
# ifdef DEBUG_PCI
static inline dma_addr_t pci_map_single_debug ( struct pci_dev * pdev , void * ptr ,
size_t size , int direction )
{
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
dma_addr_t addr = dma_map_single ( & pdev - > dev , ptr , size , direction ) ;
2021-05-24 22:47:10 +08:00
2005-04-16 15:20:36 -07:00
if ( addr + size > 0x100000000LL )
2011-06-26 19:01:28 +00:00
pr_crit ( " %s: pci_map_single() returned memory at 0x%llx! \n " ,
pci_name ( pdev ) , ( unsigned long long ) addr ) ;
2005-04-16 15:20:36 -07:00
return addr ;
}
# undef pci_map_single
# define pci_map_single pci_map_single_debug
# endif
/* Cable and/or personality module change interrupt service */
2014-08-10 13:06:47 +05:30
static inline void wanxl_cable_intr ( struct port * port )
2005-04-16 15:20:36 -07:00
{
u32 value = get_status ( port ) - > cable ;
int valid = 1 ;
const char * cable , * pm , * dte = " " , * dsr = " " , * dcd = " " ;
2021-05-24 22:47:13 +08:00
switch ( value & 0x7 ) {
2021-05-24 22:47:12 +08:00
case STATUS_CABLE_V35 :
cable = " V.35 " ;
break ;
case STATUS_CABLE_X21 :
cable = " X.21 " ;
break ;
case STATUS_CABLE_V24 :
cable = " V.24 " ;
break ;
case STATUS_CABLE_EIA530 :
cable = " EIA530 " ;
break ;
case STATUS_CABLE_NONE :
cable = " no " ;
break ;
default :
cable = " invalid " ;
2005-04-16 15:20:36 -07:00
}
2021-05-24 22:47:13 +08:00
switch ( ( value > > STATUS_CABLE_PM_SHIFT ) & 0x7 ) {
2021-05-24 22:47:12 +08:00
case STATUS_CABLE_V35 :
pm = " V.35 " ;
break ;
case STATUS_CABLE_X21 :
pm = " X.21 " ;
break ;
case STATUS_CABLE_V24 :
pm = " V.24 " ;
break ;
case STATUS_CABLE_EIA530 :
pm = " EIA530 " ;
break ;
case STATUS_CABLE_NONE :
pm = " no personality " ;
valid = 0 ;
break ;
default :
pm = " invalid personality " ;
valid = 0 ;
2005-04-16 15:20:36 -07:00
}
if ( valid ) {
if ( ( value & 7 ) = = ( ( value > > STATUS_CABLE_PM_SHIFT ) & 7 ) ) {
dsr = ( value & STATUS_CABLE_DSR ) ? " , DSR ON " :
" , DSR off " ;
dcd = ( value & STATUS_CABLE_DCD ) ? " , carrier ON " :
" , carrier off " ;
}
dte = ( value & STATUS_CABLE_DCE ) ? " DCE " : " DTE " ;
}
2011-06-26 19:01:28 +00:00
netdev_info ( port - > dev , " %s%s module, %s cable%s%s \n " ,
pm , dte , cable , dsr , dcd ) ;
2005-04-16 15:20:36 -07:00
2006-07-12 13:46:12 -07:00
if ( value & STATUS_CABLE_DCD )
netif_carrier_on ( port - > dev ) ;
else
netif_carrier_off ( port - > dev ) ;
2005-04-16 15:20:36 -07:00
}
/* Transmit complete interrupt service */
2014-08-10 13:06:47 +05:30
static inline void wanxl_tx_intr ( struct port * port )
2005-04-16 15:20:36 -07:00
{
struct net_device * dev = port - > dev ;
2021-05-24 22:47:10 +08:00
2005-04-16 15:20:36 -07:00
while ( 1 ) {
2021-05-24 22:47:11 +08:00
desc_t * desc = & get_status ( port ) - > tx_descs [ port - > tx_in ] ;
2005-04-16 15:20:36 -07:00
struct sk_buff * skb = port - > tx_skbs [ port - > tx_in ] ;
switch ( desc - > stat ) {
case PACKET_FULL :
case PACKET_EMPTY :
netif_wake_queue ( dev ) ;
return ;
case PACKET_UNDERRUN :
2008-06-30 23:26:53 +02:00
dev - > stats . tx_errors + + ;
dev - > stats . tx_fifo_errors + + ;
2005-04-16 15:20:36 -07:00
break ;
default :
2008-06-30 23:26:53 +02:00
dev - > stats . tx_packets + + ;
dev - > stats . tx_bytes + = skb - > len ;
2005-04-16 15:20:36 -07:00
}
2021-05-24 22:47:11 +08:00
desc - > stat = PACKET_EMPTY ; /* Free descriptor */
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
dma_unmap_single ( & port - > card - > pdev - > dev , desc - > address ,
skb - > len , DMA_TO_DEVICE ) ;
2019-02-25 23:01:50 +08:00
dev_consume_skb_irq ( skb ) ;
2021-05-24 22:47:11 +08:00
port - > tx_in = ( port - > tx_in + 1 ) % TX_BUFFERS ;
}
2005-04-16 15:20:36 -07:00
}
/* Receive complete interrupt service */
2014-08-10 13:06:47 +05:30
static inline void wanxl_rx_intr ( struct card * card )
2005-04-16 15:20:36 -07:00
{
desc_t * desc ;
2021-05-24 22:47:10 +08:00
2005-04-16 15:20:36 -07:00
while ( desc = & card - > status - > rx_descs [ card - > rx_in ] ,
desc - > stat ! = PACKET_EMPTY ) {
if ( ( desc - > stat & PACKET_PORT_MASK ) > card - > n_ports )
2011-06-26 19:01:28 +00:00
pr_crit ( " %s: received packet for nonexistent port \n " ,
pci_name ( card - > pdev ) ) ;
2005-04-16 15:20:36 -07:00
else {
struct sk_buff * skb = card - > rx_skbs [ card - > rx_in ] ;
2014-08-10 13:06:47 +05:30
struct port * port = & card - > ports [ desc - > stat &
2005-04-16 15:20:36 -07:00
PACKET_PORT_MASK ] ;
struct net_device * dev = port - > dev ;
if ( ! skb )
2008-06-30 23:26:53 +02:00
dev - > stats . rx_dropped + + ;
2005-04-16 15:20:36 -07:00
else {
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
dma_unmap_single ( & card - > pdev - > dev ,
desc - > address , BUFFER_LENGTH ,
DMA_FROM_DEVICE ) ;
2005-04-16 15:20:36 -07:00
skb_put ( skb , desc - > length ) ;
# ifdef DEBUG_PKT
printk ( KERN_DEBUG " %s RX(%i): " , dev - > name ,
skb - > len ) ;
debug_frame ( skb ) ;
# endif
2008-06-30 23:26:53 +02:00
dev - > stats . rx_packets + + ;
dev - > stats . rx_bytes + = skb - > len ;
2005-04-16 15:20:36 -07:00
skb - > protocol = hdlc_type_trans ( skb , dev ) ;
netif_rx ( skb ) ;
skb = NULL ;
}
if ( ! skb ) {
skb = dev_alloc_skb ( BUFFER_LENGTH ) ;
desc - > address = skb ?
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
dma_map_single ( & card - > pdev - > dev ,
skb - > data ,
2005-04-16 15:20:36 -07:00
BUFFER_LENGTH ,
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
DMA_FROM_DEVICE ) : 0 ;
2005-04-16 15:20:36 -07:00
card - > rx_skbs [ card - > rx_in ] = skb ;
}
}
desc - > stat = PACKET_EMPTY ; /* Free descriptor */
card - > rx_in = ( card - > rx_in + 1 ) % RX_QUEUE_LENGTH ;
}
}
2021-05-24 22:47:09 +08:00
static irqreturn_t wanxl_intr ( int irq , void * dev_id )
2005-04-16 15:20:36 -07:00
{
2014-08-10 13:06:47 +05:30
struct card * card = dev_id ;
2021-05-24 22:47:11 +08:00
int i ;
u32 stat ;
int handled = 0 ;
2005-04-16 15:20:36 -07:00
2021-05-24 22:47:11 +08:00
while ( ( stat = readl ( card - > plx + PLX_DOORBELL_FROM_CARD ) ) ! = 0 ) {
handled = 1 ;
2005-04-16 15:20:36 -07:00
writel ( stat , card - > plx + PLX_DOORBELL_FROM_CARD ) ;
2021-05-24 22:47:11 +08:00
for ( i = 0 ; i < card - > n_ports ; i + + ) {
2005-04-16 15:20:36 -07:00
if ( stat & ( 1 < < ( DOORBELL_FROM_CARD_TX_0 + i ) ) )
wanxl_tx_intr ( & card - > ports [ i ] ) ;
if ( stat & ( 1 < < ( DOORBELL_FROM_CARD_CABLE_0 + i ) ) )
wanxl_cable_intr ( & card - > ports [ i ] ) ;
}
if ( stat & ( 1 < < DOORBELL_FROM_CARD_RX ) )
wanxl_rx_intr ( card ) ;
2021-05-24 22:47:11 +08:00
}
2005-04-16 15:20:36 -07:00
2021-05-24 22:47:11 +08:00
return IRQ_RETVAL ( handled ) ;
2005-04-16 15:20:36 -07:00
}
2009-08-31 19:50:47 +00:00
static netdev_tx_t wanxl_xmit ( struct sk_buff * skb , struct net_device * dev )
2005-04-16 15:20:36 -07:00
{
2014-08-10 13:06:47 +05:30
struct port * port = dev_to_port ( dev ) ;
2005-04-16 15:20:36 -07:00
desc_t * desc ;
2021-05-24 22:47:11 +08:00
spin_lock ( & port - > lock ) ;
2005-04-16 15:20:36 -07:00
desc = & get_status ( port ) - > tx_descs [ port - > tx_out ] ;
2021-05-24 22:47:11 +08:00
if ( desc - > stat ! = PACKET_EMPTY ) {
/* should never happen - previous xmit should stop queue */
2005-04-16 15:20:36 -07:00
# ifdef DEBUG_PKT
printk ( KERN_DEBUG " %s: transmitter buffer full \n " , dev - > name ) ;
# endif
netif_stop_queue ( dev ) ;
2011-06-28 20:29:51 +00:00
spin_unlock ( & port - > lock ) ;
2009-06-12 06:22:29 +00:00
return NETDEV_TX_BUSY ; /* request packet to be queued */
2005-04-16 15:20:36 -07:00
}
# ifdef DEBUG_PKT
printk ( KERN_DEBUG " %s TX(%i): " , dev - > name , skb - > len ) ;
debug_frame ( skb ) ;
# endif
port - > tx_skbs [ port - > tx_out ] = skb ;
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
desc - > address = dma_map_single ( & port - > card - > pdev - > dev , skb - > data ,
skb - > len , DMA_TO_DEVICE ) ;
2005-04-16 15:20:36 -07:00
desc - > length = skb - > len ;
desc - > stat = PACKET_FULL ;
writel ( 1 < < ( DOORBELL_TO_CARD_TX_0 + port - > node ) ,
port - > card - > plx + PLX_DOORBELL_TO_CARD ) ;
port - > tx_out = ( port - > tx_out + 1 ) % TX_BUFFERS ;
if ( get_status ( port ) - > tx_descs [ port - > tx_out ] . stat ! = PACKET_EMPTY ) {
netif_stop_queue ( dev ) ;
# ifdef DEBUG_PKT
printk ( KERN_DEBUG " %s: transmitter buffer full \n " , dev - > name ) ;
# endif
}
spin_unlock ( & port - > lock ) ;
2009-07-05 19:23:38 -07:00
return NETDEV_TX_OK ;
2005-04-16 15:20:36 -07:00
}
static int wanxl_attach ( struct net_device * dev , unsigned short encoding ,
unsigned short parity )
{
2014-08-10 13:06:47 +05:30
struct port * port = dev_to_port ( dev ) ;
2005-04-16 15:20:36 -07:00
if ( encoding ! = ENCODING_NRZ & &
encoding ! = ENCODING_NRZI )
return - EINVAL ;
if ( parity ! = PARITY_NONE & &
parity ! = PARITY_CRC32_PR1_CCITT & &
parity ! = PARITY_CRC16_PR1_CCITT & &
parity ! = PARITY_CRC32_PR0_CCITT & &
parity ! = PARITY_CRC16_PR0_CCITT )
return - EINVAL ;
get_status ( port ) - > encoding = encoding ;
get_status ( port ) - > parity = parity ;
return 0 ;
}
static int wanxl_ioctl ( struct net_device * dev , struct ifreq * ifr , int cmd )
{
const size_t size = sizeof ( sync_serial_settings ) ;
sync_serial_settings line ;
2014-08-10 13:06:47 +05:30
struct port * port = dev_to_port ( dev ) ;
2005-04-16 15:20:36 -07:00
if ( cmd ! = SIOCWANDEV )
return hdlc_ioctl ( dev , ifr , cmd ) ;
switch ( ifr - > ifr_settings . type ) {
case IF_GET_IFACE :
ifr - > ifr_settings . type = IF_IFACE_SYNC_SERIAL ;
if ( ifr - > ifr_settings . size < size ) {
ifr - > ifr_settings . size = size ; /* data size wanted */
return - ENOBUFS ;
}
2013-10-16 12:46:50 +02:00
memset ( & line , 0 , sizeof ( line ) ) ;
2005-04-16 15:20:36 -07:00
line . clock_type = get_status ( port ) - > clocking ;
line . clock_rate = 0 ;
line . loopback = 0 ;
if ( copy_to_user ( ifr - > ifr_settings . ifs_ifsu . sync , & line , size ) )
return - EFAULT ;
return 0 ;
case IF_IFACE_SYNC_SERIAL :
if ( ! capable ( CAP_NET_ADMIN ) )
return - EPERM ;
if ( dev - > flags & IFF_UP )
return - EBUSY ;
if ( copy_from_user ( & line , ifr - > ifr_settings . ifs_ifsu . sync ,
size ) )
return - EFAULT ;
if ( line . clock_type ! = CLOCK_EXT & &
line . clock_type ! = CLOCK_TXFROMRX )
return - EINVAL ; /* No such clock setting */
if ( line . loopback ! = 0 )
return - EINVAL ;
get_status ( port ) - > clocking = line . clock_type ;
return 0 ;
default :
return hdlc_ioctl ( dev , ifr , cmd ) ;
2021-05-24 22:47:11 +08:00
}
2005-04-16 15:20:36 -07:00
}
static int wanxl_open ( struct net_device * dev )
{
2014-08-10 13:06:47 +05:30
struct port * port = dev_to_port ( dev ) ;
2005-04-16 15:20:36 -07:00
u8 __iomem * dbr = port - > card - > plx + PLX_DOORBELL_TO_CARD ;
unsigned long timeout ;
int i ;
if ( get_status ( port ) - > open ) {
2011-06-26 19:01:28 +00:00
netdev_err ( dev , " port already open \n " ) ;
2005-04-16 15:20:36 -07:00
return - EIO ;
}
2021-05-24 22:47:14 +08:00
i = hdlc_open ( dev ) ;
if ( i )
2005-04-16 15:20:36 -07:00
return i ;
port - > tx_in = port - > tx_out = 0 ;
for ( i = 0 ; i < TX_BUFFERS ; i + + )
get_status ( port ) - > tx_descs [ i ] . stat = PACKET_EMPTY ;
/* signal the card */
writel ( 1 < < ( DOORBELL_TO_CARD_OPEN_0 + port - > node ) , dbr ) ;
timeout = jiffies + HZ ;
2008-12-22 09:17:55 +00:00
do {
2005-04-16 15:20:36 -07:00
if ( get_status ( port ) - > open ) {
netif_start_queue ( dev ) ;
return 0 ;
}
2008-12-22 09:17:55 +00:00
} while ( time_after ( timeout , jiffies ) ) ;
2005-04-16 15:20:36 -07:00
2011-06-26 19:01:28 +00:00
netdev_err ( dev , " unable to open port \n " ) ;
2005-04-16 15:20:36 -07:00
/* ask the card to close the port, should it be still alive */
writel ( 1 < < ( DOORBELL_TO_CARD_CLOSE_0 + port - > node ) , dbr ) ;
return - EFAULT ;
}
static int wanxl_close ( struct net_device * dev )
{
2014-08-10 13:06:47 +05:30
struct port * port = dev_to_port ( dev ) ;
2005-04-16 15:20:36 -07:00
unsigned long timeout ;
int i ;
hdlc_close ( dev ) ;
/* signal the card */
writel ( 1 < < ( DOORBELL_TO_CARD_CLOSE_0 + port - > node ) ,
port - > card - > plx + PLX_DOORBELL_TO_CARD ) ;
timeout = jiffies + HZ ;
2008-12-22 09:17:55 +00:00
do {
2005-04-16 15:20:36 -07:00
if ( ! get_status ( port ) - > open )
break ;
2008-12-22 09:17:55 +00:00
} while ( time_after ( timeout , jiffies ) ) ;
2005-04-16 15:20:36 -07:00
if ( get_status ( port ) - > open )
2011-06-26 19:01:28 +00:00
netdev_err ( dev , " unable to close port \n " ) ;
2005-04-16 15:20:36 -07:00
netif_stop_queue ( dev ) ;
for ( i = 0 ; i < TX_BUFFERS ; i + + ) {
desc_t * desc = & get_status ( port ) - > tx_descs [ i ] ;
if ( desc - > stat ! = PACKET_EMPTY ) {
desc - > stat = PACKET_EMPTY ;
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
dma_unmap_single ( & port - > card - > pdev - > dev ,
desc - > address , port - > tx_skbs [ i ] - > len ,
DMA_TO_DEVICE ) ;
2005-04-16 15:20:36 -07:00
dev_kfree_skb ( port - > tx_skbs [ i ] ) ;
}
}
return 0 ;
}
static struct net_device_stats * wanxl_get_stats ( struct net_device * dev )
{
2014-08-10 13:06:47 +05:30
struct port * port = dev_to_port ( dev ) ;
2005-04-16 15:20:36 -07:00
2008-06-30 23:26:53 +02:00
dev - > stats . rx_over_errors = get_status ( port ) - > rx_overruns ;
dev - > stats . rx_frame_errors = get_status ( port ) - > rx_frame_errors ;
dev - > stats . rx_errors = dev - > stats . rx_over_errors +
dev - > stats . rx_frame_errors ;
return & dev - > stats ;
2005-04-16 15:20:36 -07:00
}
2014-08-10 13:06:47 +05:30
static int wanxl_puts_command ( struct card * card , u32 cmd )
2005-04-16 15:20:36 -07:00
{
unsigned long timeout = jiffies + 5 * HZ ;
writel ( cmd , card - > plx + PLX_MAILBOX_1 ) ;
do {
if ( readl ( card - > plx + PLX_MAILBOX_1 ) = = 0 )
return 0 ;
schedule ( ) ;
2021-05-24 22:47:13 +08:00
} while ( time_after ( timeout , jiffies ) ) ;
2005-04-16 15:20:36 -07:00
return - 1 ;
}
2014-08-10 13:06:47 +05:30
static void wanxl_reset ( struct card * card )
2005-04-16 15:20:36 -07:00
{
u32 old_value = readl ( card - > plx + PLX_CONTROL ) & ~ PLX_CTL_RESET ;
writel ( 0x80 , card - > plx + PLX_MAILBOX_0 ) ;
writel ( old_value | PLX_CTL_RESET , card - > plx + PLX_CONTROL ) ;
readl ( card - > plx + PLX_CONTROL ) ; /* wait for posted write */
udelay ( 1 ) ;
writel ( old_value , card - > plx + PLX_CONTROL ) ;
readl ( card - > plx + PLX_CONTROL ) ; /* wait for posted write */
}
static void wanxl_pci_remove_one ( struct pci_dev * pdev )
{
2014-08-10 13:06:47 +05:30
struct card * card = pci_get_drvdata ( pdev ) ;
2005-04-16 15:20:36 -07:00
int i ;
for ( i = 0 ; i < card - > n_ports ; i + + ) {
unregister_hdlc_device ( card - > ports [ i ] . dev ) ;
free_netdev ( card - > ports [ i ] . dev ) ;
}
/* unregister and free all host resources */
if ( card - > irq )
free_irq ( card - > irq , card ) ;
wanxl_reset ( card ) ;
for ( i = 0 ; i < RX_QUEUE_LENGTH ; i + + )
if ( card - > rx_skbs [ i ] ) {
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
dma_unmap_single ( & card - > pdev - > dev ,
2005-04-16 15:20:36 -07:00
card - > status - > rx_descs [ i ] . address ,
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
BUFFER_LENGTH , DMA_FROM_DEVICE ) ;
2005-04-16 15:20:36 -07:00
dev_kfree_skb ( card - > rx_skbs [ i ] ) ;
}
if ( card - > plx )
iounmap ( card - > plx ) ;
if ( card - > status )
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
dma_free_coherent ( & pdev - > dev , sizeof ( struct card_status ) ,
card - > status , card - > status_address ) ;
2005-04-16 15:20:36 -07:00
pci_release_regions ( pdev ) ;
pci_disable_device ( pdev ) ;
kfree ( card ) ;
}
# include "wanxlfw.inc"
2009-01-08 22:52:11 +01:00
static const struct net_device_ops wanxl_ops = {
. ndo_open = wanxl_open ,
. ndo_stop = wanxl_close ,
. ndo_start_xmit = hdlc_start_xmit ,
. ndo_do_ioctl = wanxl_ioctl ,
. ndo_get_stats = wanxl_get_stats ,
} ;
2012-12-03 09:24:19 -05:00
static int wanxl_pci_init_one ( struct pci_dev * pdev ,
2012-12-06 14:30:56 +00:00
const struct pci_device_id * ent )
2005-04-16 15:20:36 -07:00
{
2014-08-10 13:06:47 +05:30
struct card * card ;
2005-04-16 15:20:36 -07:00
u32 ramsize , stat ;
unsigned long timeout ;
u32 plx_phy ; /* PLX PCI base address */
u32 mem_phy ; /* memory PCI base addr */
u8 __iomem * mem ; /* memory virtual base addr */
2019-02-07 21:16:48 -06:00
int i , ports ;
2005-04-16 15:20:36 -07:00
# ifndef MODULE
2011-06-26 19:01:28 +00:00
pr_info_once ( " %s \n " , version ) ;
2005-04-16 15:20:36 -07:00
# endif
i = pci_enable_device ( pdev ) ;
if ( i )
return i ;
/* QUICC can only access first 256 MB of host RAM directly,
but PLX9060 DMA does 32 - bits for actual packet data transfers */
/* FIXME when PCI/DMA subsystems are fixed.
We set both dma_mask and consistent_dma_mask to 28 bits
and pray pci_alloc_consistent ( ) will use this info . It should
work on most platforms */
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
if ( dma_set_coherent_mask ( & pdev - > dev , DMA_BIT_MASK ( 28 ) ) | |
dma_set_mask ( & pdev - > dev , DMA_BIT_MASK ( 28 ) ) ) {
2011-06-26 19:01:28 +00:00
pr_err ( " No usable DMA configuration \n " ) ;
2015-12-12 00:58:19 +05:30
pci_disable_device ( pdev ) ;
2005-04-16 15:20:36 -07:00
return - EIO ;
}
i = pci_request_regions ( pdev , " wanXL " ) ;
if ( i ) {
pci_disable_device ( pdev ) ;
return i ;
}
switch ( pdev - > device ) {
2021-05-24 22:47:12 +08:00
case PCI_DEVICE_ID_SBE_WANXL100 :
ports = 1 ;
break ;
case PCI_DEVICE_ID_SBE_WANXL200 :
ports = 2 ;
break ;
default :
ports = 4 ;
2005-04-16 15:20:36 -07:00
}
2019-02-07 21:16:48 -06:00
card = kzalloc ( struct_size ( card , ports , ports ) , GFP_KERNEL ) ;
2005-04-16 15:20:36 -07:00
if ( card = = NULL ) {
pci_release_regions ( pdev ) ;
pci_disable_device ( pdev ) ;
return - ENOBUFS ;
}
pci_set_drvdata ( pdev , card ) ;
card - > pdev = pdev ;
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
card - > status = dma_alloc_coherent ( & pdev - > dev ,
sizeof ( struct card_status ) ,
& card - > status_address , GFP_KERNEL ) ;
2005-04-16 15:20:36 -07:00
if ( card - > status = = NULL ) {
wanxl_pci_remove_one ( pdev ) ;
return - ENOBUFS ;
}
# ifdef DEBUG_PCI
printk ( KERN_DEBUG " wanXL %s: pci_alloc_consistent() returned memory "
" at 0x%LX \n " , pci_name ( pdev ) ,
( unsigned long long ) card - > status_address ) ;
# endif
/* FIXME when PCI/DMA subsystems are fixed.
We set both dma_mask and consistent_dma_mask back to 32 bits
to indicate the card can do 32 - bit DMA addressing */
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
if ( dma_set_coherent_mask ( & pdev - > dev , DMA_BIT_MASK ( 32 ) ) | |
dma_set_mask ( & pdev - > dev , DMA_BIT_MASK ( 32 ) ) ) {
2011-06-26 19:01:28 +00:00
pr_err ( " No usable DMA configuration \n " ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - EIO ;
}
/* set up PLX mapping */
plx_phy = pci_resource_start ( pdev , 0 ) ;
2006-06-22 22:29:28 +02:00
2020-01-06 09:43:50 +01:00
card - > plx = ioremap ( plx_phy , 0x70 ) ;
2006-06-22 22:29:28 +02:00
if ( ! card - > plx ) {
2011-06-26 19:01:28 +00:00
pr_err ( " ioremap() failed \n " ) ;
2021-05-20 11:47:46 +08:00
wanxl_pci_remove_one ( pdev ) ;
2006-06-22 22:29:28 +02:00
return - EFAULT ;
}
2005-04-16 15:20:36 -07:00
# if RESET_WHILE_LOADING
wanxl_reset ( card ) ;
# endif
timeout = jiffies + 20 * HZ ;
while ( ( stat = readl ( card - > plx + PLX_MAILBOX_0 ) ) ! = 0 ) {
if ( time_before ( timeout , jiffies ) ) {
2011-06-26 19:01:28 +00:00
pr_warn ( " %s: timeout waiting for PUTS to complete \n " ,
pci_name ( pdev ) ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - ENODEV ;
}
2021-05-24 22:47:13 +08:00
switch ( stat & 0xC0 ) {
2005-04-16 15:20:36 -07:00
case 0x00 : /* hmm - PUTS completed with non-zero code? */
case 0x80 : /* PUTS still testing the hardware */
break ;
default :
2011-06-26 19:01:28 +00:00
pr_warn ( " %s: PUTS test 0x%X failed \n " ,
pci_name ( pdev ) , stat & 0x30 ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - ENODEV ;
}
schedule ( ) ;
}
/* get on-board memory size (PUTS detects no more than 4 MB) */
ramsize = readl ( card - > plx + PLX_MAILBOX_2 ) & MBX2_MEMSZ_MASK ;
/* set up on-board RAM mapping */
mem_phy = pci_resource_start ( pdev , 2 ) ;
/* sanity check the board's reported memory size */
if ( ramsize < BUFFERS_ADDR +
( TX_BUFFERS + RX_BUFFERS ) * BUFFER_LENGTH * ports ) {
2011-06-26 19:01:28 +00:00
pr_warn ( " %s: no enough on-board RAM (%u bytes detected, %u bytes required) \n " ,
pci_name ( pdev ) , ramsize ,
BUFFERS_ADDR +
( TX_BUFFERS + RX_BUFFERS ) * BUFFER_LENGTH * ports ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - ENODEV ;
}
if ( wanxl_puts_command ( card , MBX1_CMD_BSWAP ) ) {
2011-06-26 19:01:28 +00:00
pr_warn ( " %s: unable to Set Byte Swap Mode \n " , pci_name ( pdev ) ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - ENODEV ;
}
for ( i = 0 ; i < RX_QUEUE_LENGTH ; i + + ) {
struct sk_buff * skb = dev_alloc_skb ( BUFFER_LENGTH ) ;
2021-05-24 22:47:10 +08:00
2005-04-16 15:20:36 -07:00
card - > rx_skbs [ i ] = skb ;
if ( skb )
card - > status - > rx_descs [ i ] . address =
wan: wanxl: switch from 'pci_' to 'dma_' API
The wrappers in include/linux/pci-dma-compat.h should go away.
The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'wanxl_pci_init_one()', GFP_KERNEL can be used
because it is a probe function and no lock is acquired.
Moreover, just a few lines above, GFP_KERNEL is already used.
@@
@@
- PCI_DMA_BIDIRECTIONAL
+ DMA_BIDIRECTIONAL
@@
@@
- PCI_DMA_TODEVICE
+ DMA_TO_DEVICE
@@
@@
- PCI_DMA_FROMDEVICE
+ DMA_FROM_DEVICE
@@
@@
- PCI_DMA_NONE
+ DMA_NONE
@@
expression e1, e2, e3;
@@
- pci_alloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-04 22:08:09 +02:00
dma_map_single ( & card - > pdev - > dev , skb - > data ,
BUFFER_LENGTH , DMA_FROM_DEVICE ) ;
2005-04-16 15:20:36 -07:00
}
2020-01-06 09:43:50 +01:00
mem = ioremap ( mem_phy , PDM_OFFSET + sizeof ( firmware ) ) ;
2006-06-22 22:29:28 +02:00
if ( ! mem ) {
2011-06-26 19:01:28 +00:00
pr_err ( " ioremap() failed \n " ) ;
2021-05-20 11:47:46 +08:00
wanxl_pci_remove_one ( pdev ) ;
2006-06-22 22:29:28 +02:00
return - EFAULT ;
}
2005-04-16 15:20:36 -07:00
for ( i = 0 ; i < sizeof ( firmware ) ; i + = 4 )
2021-05-24 22:47:09 +08:00
writel ( ntohl ( * ( __be32 * ) ( firmware + i ) ) , mem + PDM_OFFSET + i ) ;
2005-04-16 15:20:36 -07:00
for ( i = 0 ; i < ports ; i + + )
writel ( card - > status_address +
( void * ) & card - > status - > port_status [ i ] -
( void * ) card - > status , mem + PDM_OFFSET + 4 + i * 4 ) ;
writel ( card - > status_address , mem + PDM_OFFSET + 20 ) ;
writel ( PDM_OFFSET , mem ) ;
iounmap ( mem ) ;
writel ( 0 , card - > plx + PLX_MAILBOX_5 ) ;
if ( wanxl_puts_command ( card , MBX1_CMD_ABORTJ ) ) {
2011-06-26 19:01:28 +00:00
pr_warn ( " %s: unable to Abort and Jump \n " , pci_name ( pdev ) ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - ENODEV ;
}
timeout = jiffies + 5 * HZ ;
do {
2021-05-24 22:47:14 +08:00
stat = readl ( card - > plx + PLX_MAILBOX_5 ) ;
if ( stat )
2005-04-16 15:20:36 -07:00
break ;
schedule ( ) ;
2021-05-24 22:47:13 +08:00
} while ( time_after ( timeout , jiffies ) ) ;
2005-04-16 15:20:36 -07:00
if ( ! stat ) {
2011-06-26 19:01:28 +00:00
pr_warn ( " %s: timeout while initializing card firmware \n " ,
pci_name ( pdev ) ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - ENODEV ;
}
# if DETECT_RAM
ramsize = stat ;
# endif
2011-06-26 19:01:28 +00:00
pr_info ( " %s: at 0x%X, %u KB of RAM at 0x%X, irq %u \n " ,
pci_name ( pdev ) , plx_phy , ramsize / 1024 , mem_phy , pdev - > irq ) ;
2005-04-16 15:20:36 -07:00
/* Allocate IRQ */
2006-07-01 19:29:39 -07:00
if ( request_irq ( pdev - > irq , wanxl_intr , IRQF_SHARED , " wanXL " , card ) ) {
2011-06-26 19:01:28 +00:00
pr_warn ( " %s: could not allocate IRQ%i \n " ,
pci_name ( pdev ) , pdev - > irq ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - EBUSY ;
}
card - > irq = pdev - > irq ;
for ( i = 0 ; i < ports ; i + + ) {
hdlc_device * hdlc ;
2014-08-10 13:06:47 +05:30
struct port * port = & card - > ports [ i ] ;
2005-04-16 15:20:36 -07:00
struct net_device * dev = alloc_hdlcdev ( port ) ;
2021-05-24 22:47:10 +08:00
2005-04-16 15:20:36 -07:00
if ( ! dev ) {
2011-06-26 19:01:28 +00:00
pr_err ( " %s: unable to allocate memory \n " ,
pci_name ( pdev ) ) ;
2005-04-16 15:20:36 -07:00
wanxl_pci_remove_one ( pdev ) ;
return - ENOMEM ;
}
port - > dev = dev ;
hdlc = dev_to_hdlc ( dev ) ;
spin_lock_init ( & port - > lock ) ;
dev - > tx_queue_len = 50 ;
2009-01-08 22:52:11 +01:00
dev - > netdev_ops = & wanxl_ops ;
2005-04-16 15:20:36 -07:00
hdlc - > attach = wanxl_attach ;
hdlc - > xmit = wanxl_xmit ;
port - > card = card ;
port - > node = i ;
get_status ( port ) - > clocking = CLOCK_EXT ;
if ( register_hdlc_device ( dev ) ) {
2011-06-26 19:01:28 +00:00
pr_err ( " %s: unable to register hdlc device \n " ,
pci_name ( pdev ) ) ;
2005-04-16 15:20:36 -07:00
free_netdev ( dev ) ;
wanxl_pci_remove_one ( pdev ) ;
return - ENOBUFS ;
}
card - > n_ports + + ;
}
2011-06-26 19:01:28 +00:00
pr_info ( " %s: port " , pci_name ( pdev ) ) ;
2005-04-16 15:20:36 -07:00
for ( i = 0 ; i < ports ; i + + )
2011-06-26 19:01:28 +00:00
pr_cont ( " %s #%i: %s " ,
i ? " , " : " " , i , card - > ports [ i ] . dev - > name ) ;
pr_cont ( " \n " ) ;
2005-04-16 15:20:36 -07:00
for ( i = 0 ; i < ports ; i + + )
wanxl_cable_intr ( & card - > ports [ i ] ) ; /* get carrier status etc.*/
return 0 ;
}
2014-08-08 15:56:03 +02:00
static const struct pci_device_id wanxl_pci_tbl [ ] = {
2005-04-16 15:20:36 -07:00
{ PCI_VENDOR_ID_SBE , PCI_DEVICE_ID_SBE_WANXL100 , PCI_ANY_ID ,
PCI_ANY_ID , 0 , 0 , 0 } ,
{ PCI_VENDOR_ID_SBE , PCI_DEVICE_ID_SBE_WANXL200 , PCI_ANY_ID ,
PCI_ANY_ID , 0 , 0 , 0 } ,
{ PCI_VENDOR_ID_SBE , PCI_DEVICE_ID_SBE_WANXL400 , PCI_ANY_ID ,
PCI_ANY_ID , 0 , 0 , 0 } ,
{ 0 , }
} ;
static struct pci_driver wanxl_pci_driver = {
. name = " wanXL " ,
. id_table = wanxl_pci_tbl ,
. probe = wanxl_pci_init_one ,
. remove = wanxl_pci_remove_one ,
} ;
static int __init wanxl_init_module ( void )
{
# ifdef MODULE
2011-06-26 19:01:28 +00:00
pr_info ( " %s \n " , version ) ;
2005-04-16 15:20:36 -07:00
# endif
2006-08-19 17:48:59 -04:00
return pci_register_driver ( & wanxl_pci_driver ) ;
2005-04-16 15:20:36 -07:00
}
static void __exit wanxl_cleanup_module ( void )
{
pci_unregister_driver ( & wanxl_pci_driver ) ;
}
MODULE_AUTHOR ( " Krzysztof Halasa <khc@pm.waw.pl> " ) ;
MODULE_DESCRIPTION ( " SBE Inc. wanXL serial port driver " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;
MODULE_DEVICE_TABLE ( pci , wanxl_pci_tbl ) ;
module_init ( wanxl_init_module ) ;
module_exit ( wanxl_cleanup_module ) ;