*
* We use the following SCA memory map:
*
- * Packet buffer descriptor rings - starting from winbase or win0base:
+ * Packet buffer descriptor rings - starting from card->rambase:
* rx_ring_buffers * sizeof(pkt_desc) = logical channel #0 RX ring
* tx_ring_buffers * sizeof(pkt_desc) = logical channel #0 TX ring
* rx_ring_buffers * sizeof(pkt_desc) = logical channel #1 RX ring (if used)
* tx_ring_buffers * sizeof(pkt_desc) = logical channel #1 TX ring (if used)
*
- * Packet data buffers - starting from winbase + buff_offset:
+ * Packet data buffers - starting from card->rambase + buff_offset:
* rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers
* tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers
* rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers (if used)
#define NAPI_WEIGHT 16
-#define get_msci(port) (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET)
-#define get_dmac_rx(port) (phy_node(port) ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
-#define get_dmac_tx(port) (phy_node(port) ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)
+#define get_msci(port) (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET)
+#define get_dmac_rx(port) (port->chan ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
+#define get_dmac_tx(port) (port->chan ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)
-static int sca_poll(struct napi_struct *napi, int budget);
+#define sca_in(reg, card) readb(card->scabase + (reg))
+#define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
+#define sca_inw(reg, card) readw(card->scabase + (reg))
+#define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
+#define sca_inl(reg, card) readl(card->scabase + (reg))
+#define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
-static inline struct net_device *port_to_dev(port_t *port)
-{
- return port->dev;
-}
+static int sca_poll(struct napi_struct *napi, int budget);
static inline port_t* dev_to_port(struct net_device *dev)
{
{
/* enable DMIB and MSCI RXINTA interrupts */
sca_outl(sca_inl(IER0, port->card) |
- (phy_node(port) ? 0x08002200 : 0x00080022), IER0, port->card);
+ (port->chan ? 0x08002200 : 0x00080022), IER0, port->card);
}
static inline void disable_intr(port_t *port)
{
sca_outl(sca_inl(IER0, port->card) &
- (phy_node(port) ? 0x00FF00FF : 0xFF00FF00), IER0, port->card);
+ (port->chan ? 0x00FF00FF : 0xFF00FF00), IER0, port->card);
}
static inline u16 next_desc(port_t *port, u16 desc, int transmit)
{
- return (desc + 1) % (transmit ? port_to_card(port)->tx_ring_buffers
- : port_to_card(port)->rx_ring_buffers);
+ return (desc + 1) % (transmit ? port->card->tx_ring_buffers
+ : port->card->rx_ring_buffers);
}
static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit)
{
- u16 rx_buffs = port_to_card(port)->rx_ring_buffers;
- u16 tx_buffs = port_to_card(port)->tx_ring_buffers;
+ u16 rx_buffs = port->card->rx_ring_buffers;
+ u16 tx_buffs = port->card->tx_ring_buffers;
desc %= (transmit ? tx_buffs : rx_buffs); // called with "X + 1" etc.
- return log_node(port) * (rx_buffs + tx_buffs) +
- transmit * rx_buffs + desc;
+ return port->chan * (rx_buffs + tx_buffs) + transmit * rx_buffs + desc;
}
static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc,
int transmit)
{
- return (pkt_desc __iomem *)(winbase(port_to_card(port))
- + desc_offset(port, desc, transmit));
+ return (pkt_desc __iomem *)(port->card->rambase +
+ desc_offset(port, desc, transmit));
}
static inline u32 buffer_offset(port_t *port, u16 desc, int transmit)
{
- return port_to_card(port)->buff_offset +
+ return port->card->buff_offset +
desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU;
}
static inline void sca_set_carrier(port_t *port)
{
- if (!(sca_in(get_msci(port) + ST3, port_to_card(port)) & ST3_DCD)) {
+ if (!(sca_in(get_msci(port) + ST3, port->card) & ST3_DCD)) {
#ifdef DEBUG_LINK
printk(KERN_DEBUG "%s: sca_set_carrier on\n",
- port_to_dev(port)->name);
+ port->netdev.name);
#endif
- netif_carrier_on(port_to_dev(port));
+ netif_carrier_on(port->netdev);
} else {
#ifdef DEBUG_LINK
printk(KERN_DEBUG "%s: sca_set_carrier off\n",
- port_to_dev(port)->name);
+ port->netdev.name);
#endif
- netif_carrier_off(port_to_dev(port));
+ netif_carrier_off(port->netdev);
}
}
static void sca_init_port(port_t *port)
{
- card_t *card = port_to_card(port);
+ card_t *card = port->card;
int transmit, i;
port->rxin = 0;
}
/* DMA disable - to halt state */
- sca_out(0, transmit ? DSR_TX(phy_node(port)) :
- DSR_RX(phy_node(port)), card);
+ sca_out(0, transmit ? DSR_TX(port->chan) :
+ DSR_RX(port->chan), card);
/* software ABORT - to initial state */
- sca_out(DCR_ABORT, transmit ? DCR_TX(phy_node(port)) :
- DCR_RX(phy_node(port)), card);
+ sca_out(DCR_ABORT, transmit ? DCR_TX(port->chan) :
+ DCR_RX(port->chan), card);
/* current desc addr */
sca_outl(desc_offset(port, 0, transmit), dmac + CDAL, card);
card);
/* clear frame end interrupt counter */
- sca_out(DCR_CLEAR_EOF, transmit ? DCR_TX(phy_node(port)) :
- DCR_RX(phy_node(port)), card);
+ sca_out(DCR_CLEAR_EOF, transmit ? DCR_TX(port->chan) :
+ DCR_RX(port->chan), card);
if (!transmit) { /* Receive */
/* set buffer length */
sca_outw(HDLC_MAX_MRU, dmac + BFLL, card);
/* Chain mode, Multi-frame */
- sca_out(0x14, DMR_RX(phy_node(port)), card);
- sca_out(DIR_EOME, DIR_RX(phy_node(port)), card);
+ sca_out(0x14, DMR_RX(port->chan), card);
+ sca_out(DIR_EOME, DIR_RX(port->chan), card);
/* DMA enable */
- sca_out(DSR_DE, DSR_RX(phy_node(port)), card);
+ sca_out(DSR_DE, DSR_RX(port->chan), card);
} else { /* Transmit */
/* Chain mode, Multi-frame */
- sca_out(0x14, DMR_TX(phy_node(port)), card);
+ sca_out(0x14, DMR_TX(port->chan), card);
/* enable underflow interrupts */
- sca_out(DIR_EOME, DIR_TX(phy_node(port)), card);
+ sca_out(DIR_EOME, DIR_TX(port->chan), card);
}
}
sca_set_carrier(port);
- netif_napi_add(port_to_dev(port), &port->napi, sca_poll, NAPI_WEIGHT);
+ netif_napi_add(port->netdev, &port->napi, sca_poll, NAPI_WEIGHT);
}
static inline void sca_msci_intr(port_t *port)
{
u16 msci = get_msci(port);
- card_t* card = port_to_card(port);
+ card_t* card = port->card;
if (sca_in(msci + ST1, card) & ST1_CDCD) {
/* Reset MSCI CDCD status bit */
static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc,
u16 rxin)
{
- struct net_device *dev = port_to_dev(port);
+ struct net_device *dev = port->netdev;
struct sk_buff *skb;
u16 len;
u32 buff;
}
buff = buffer_offset(port, rxin, 0);
- memcpy_fromio(skb->data, winbase(card) + buff, len);
+ memcpy_fromio(skb->data, card->rambase + buff, len);
skb_put(skb, len);
#ifdef DEBUG_PKT
/* Receive DMA service */
static inline int sca_rx_done(port_t *port, int budget)
{
- struct net_device *dev = port_to_dev(port);
+ struct net_device *dev = port->netdev;
u16 dmac = get_dmac_rx(port);
- card_t *card = port_to_card(port);
- u8 stat = sca_in(DSR_RX(phy_node(port)), card); /* read DMA Status */
+ card_t *card = port->card;
+ u8 stat = sca_in(DSR_RX(port->chan), card); /* read DMA Status */
int received = 0;
/* Reset DSR status bits */
sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
- DSR_RX(phy_node(port)), card);
+ DSR_RX(port->chan), card);
if (stat & DSR_BOF)
/* Dropped one or more frames */
}
/* make sure RX DMA is enabled */
- sca_out(DSR_DE, DSR_RX(phy_node(port)), card);
+ sca_out(DSR_DE, DSR_RX(port->chan), card);
return received;
}
/* Transmit DMA service */
static inline void sca_tx_done(port_t *port)
{
- struct net_device *dev = port_to_dev(port);
- card_t* card = port_to_card(port);
+ struct net_device *dev = port->netdev;
+ card_t* card = port->card;
u8 stat;
spin_lock(&port->lock);
- stat = sca_in(DSR_TX(phy_node(port)), card); /* read DMA Status */
+ stat = sca_in(DSR_TX(port->chan), card); /* read DMA Status */
/* Reset DSR status bits */
sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
- DSR_TX(phy_node(port)), card);
+ DSR_TX(port->chan), card);
while (1) {
pkt_desc __iomem *desc = desc_address(port, port->txlast, 1);
u32 isr0 = sca_inl(ISR0, port->card);
int received = 0;
- if (isr0 & (port->phy_node ? 0x08000000 : 0x00080000))
+ if (isr0 & (port->chan ? 0x08000000 : 0x00080000))
sca_msci_intr(port);
- if (isr0 & (port->phy_node ? 0x00002000 : 0x00000020))
+ if (isr0 & (port->chan ? 0x00002000 : 0x00000020))
sca_tx_done(port);
- if (isr0 & (port->phy_node ? 0x00000200 : 0x00000002))
+ if (isr0 & (port->chan ? 0x00000200 : 0x00000002))
received = sca_rx_done(port, budget);
if (received < budget) {
- netif_rx_complete(port->dev, napi);
+ netif_rx_complete(port->netdev, napi);
enable_intr(port);
}
if (port && (isr0 & (i ? 0x08002200 : 0x00080022))) {
handled = 1;
disable_intr(port);
- netif_rx_schedule(port->dev, &port->napi);
+ netif_rx_schedule(port->netdev, &port->napi);
}
}
static void sca_set_port(port_t *port)
{
- card_t* card = port_to_card(port);
+ card_t* card = port->card;
u16 msci = get_msci(port);
u8 md2 = sca_in(msci + MD2, card);
unsigned int tmc, br = 10, brv = 1024;
static void sca_open(struct net_device *dev)
{
port_t *port = dev_to_port(dev);
- card_t* card = port_to_card(port);
+ card_t* card = port->card;
u16 msci = get_msci(port);
u8 md0, md2;
port_t *port = dev_to_port(dev);
/* reset channel */
- sca_out(CMD_RESET, get_msci(port) + CMD, port_to_card(port));
+ sca_out(CMD_RESET, get_msci(port) + CMD, port->card);
disable_intr(port);
napi_disable(&port->napi);
netif_stop_queue(dev);
static void sca_dump_rings(struct net_device *dev)
{
port_t *port = dev_to_port(dev);
- card_t *card = port_to_card(port);
+ card_t *card = port->card;
u16 cnt;
printk(KERN_DEBUG "RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive",
sca_inl(get_dmac_rx(port) + CDAL, card),
sca_inl(get_dmac_rx(port) + EDAL, card),
- sca_in(DSR_RX(phy_node(port)), card), port->rxin,
- sca_in(DSR_RX(phy_node(port)), card) & DSR_DE ? "" : "in");
- for (cnt = 0; cnt < port_to_card(port)->rx_ring_buffers; cnt++)
+ sca_in(DSR_RX(port->chan), card), port->rxin,
+ sca_in(DSR_RX(port->chan), card) & DSR_DE ? "" : "in");
+ for (cnt = 0; cnt < port->card->rx_ring_buffers; cnt++)
printk(" %02X", readb(&(desc_address(port, cnt, 0)->stat)));
printk("\n" KERN_DEBUG "TX ring: CDA=%u EDA=%u DSR=%02X in=%u "
"last=%u %sactive",
sca_inl(get_dmac_tx(port) + CDAL, card),
sca_inl(get_dmac_tx(port) + EDAL, card),
- sca_in(DSR_TX(phy_node(port)), card), port->txin, port->txlast,
- sca_in(DSR_TX(phy_node(port)), card) & DSR_DE ? "" : "in");
+ sca_in(DSR_TX(port->chan), card), port->txin, port->txlast,
+ sca_in(DSR_TX(port->chan), card) & DSR_DE ? "" : "in");
- for (cnt = 0; cnt < port_to_card(port)->tx_ring_buffers; cnt++)
+ for (cnt = 0; cnt < port->card->tx_ring_buffers; cnt++)
printk(" %02X", readb(&(desc_address(port, cnt, 1)->stat)));
printk("\n");
static int sca_xmit(struct sk_buff *skb, struct net_device *dev)
{
port_t *port = dev_to_port(dev);
- card_t *card = port_to_card(port);
+ card_t *card = port->card;
pkt_desc __iomem *desc;
u32 buff, len;
desc = desc_address(port, port->txin, 1);
buff = buffer_offset(port, port->txin, 1);
len = skb->len;
- memcpy_toio(winbase(card) + buff, skb->data, len);
+ memcpy_toio(card->rambase + buff, skb->data, len);
writew(len, &desc->len);
writeb(ST_TX_EOM, &desc->stat);
sca_outl(desc_offset(port, port->txin, 1),
get_dmac_tx(port) + EDAL, card);
- sca_out(DSR_DE, DSR_TX(phy_node(port)), card); /* Enable TX DMA */
+ sca_out(DSR_DE, DSR_TX(port->chan), card); /* Enable TX DMA */
desc = desc_address(port, port->txin + 1, 1);
if (readb(&desc->stat)) /* allow 1 packet gap */
/*
* Cyclades PC300 synchronous serial card driver for Linux
*
- * Copyright (C) 2000-2007 Krzysztof Halasa <khc@pm.waw.pl>
+ * Copyright (C) 2000-2008 Krzysztof Halasa <khc@pm.waw.pl>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License
*
* Sources of information:
* Hitachi HD64572 SCA-II User's Manual
- * Cyclades PC300 Linux driver
+ * Original Cyclades PC300 Linux driver
*
* This driver currently supports only PC300/RSV (V.24/V.35) and
* PC300/X21 cards.
typedef struct port_s {
struct napi_struct napi;
- struct net_device *dev;
+ struct net_device *netdev;
struct card_s *card;
spinlock_t lock; /* TX lock */
sync_serial_settings settings;
u16 txin; /* tx ring buffer 'in' and 'last' pointers */
u16 txlast;
u8 rxs, txs, tmc; /* SCA registers */
- u8 phy_node; /* physical port # - 0 or 1 */
+ u8 chan; /* physical port # - 0 or 1 */
}port_t;
}card_t;
-#define sca_in(reg, card) readb(card->scabase + (reg))
-#define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
-#define sca_inw(reg, card) readw(card->scabase + (reg))
-#define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
-#define sca_inl(reg, card) readl(card->scabase + (reg))
-#define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
-
-#define port_to_card(port) (port->card)
-#define log_node(port) (port->phy_node)
-#define phy_node(port) (port->phy_node)
-#define winbase(card) (card->rambase)
#define get_port(card, port) ((port) < (card)->n_ports ? \
(&(card)->ports[port]) : (NULL))
u8 rxs = port->rxs & CLK_BRG_MASK;
u8 txs = port->txs & CLK_BRG_MASK;
- sca_out(EXS_TES1, (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS,
- port_to_card(port));
+ sca_out(EXS_TES1, (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS,
+ port->card);
switch(port->settings.clock_type) {
case CLOCK_INT:
rxs |= CLK_BRG; /* BRG output */
if (port->card->type == PC300_RSV) {
if (port->iface == IF_IFACE_V35)
writel(card->init_ctrl_value |
- PC300_CHMEDIA_MASK(port->phy_node), init_ctrl);
+ PC300_CHMEDIA_MASK(port->chan), init_ctrl);
else
writel(card->init_ctrl_value &
- ~PC300_CHMEDIA_MASK(port->phy_node), init_ctrl);
+ ~PC300_CHMEDIA_MASK(port->chan), init_ctrl);
}
}
card_t *card = pci_get_drvdata(pdev);
for (i = 0; i < 2; i++)
- if (card->ports[i].card) {
- struct net_device *dev = port_to_dev(&card->ports[i]);
- unregister_hdlc_device(dev);
- }
+ if (card->ports[i].card)
+ unregister_hdlc_device(card->ports[i].netdev);
if (card->irq)
free_irq(card->irq, card);
pci_release_regions(pdev);
pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
- if (card->ports[0].dev)
- free_netdev(card->ports[0].dev);
- if (card->ports[1].dev)
- free_netdev(card->ports[1].dev);
+ if (card->ports[0].netdev)
+ free_netdev(card->ports[0].netdev);
+ if (card->ports[1].netdev)
+ free_netdev(card->ports[1].netdev);
kfree(card);
}
card->n_ports = 2;
for (i = 0; i < card->n_ports; i++)
- if (!(card->ports[i].dev = alloc_hdlcdev(&card->ports[i]))) {
+ if (!(card->ports[i].netdev = alloc_hdlcdev(&card->ports[i]))) {
printk(KERN_ERR "pc300: unable to allocate memory\n");
pc300_pci_remove_one(pdev);
return -ENOMEM;
for (i = 0; i < card->n_ports; i++) {
port_t *port = &card->ports[i];
- struct net_device *dev = port_to_dev(port);
+ struct net_device *dev = port->netdev;
hdlc_device *hdlc = dev_to_hdlc(dev);
- port->phy_node = i;
+ port->chan = i;
spin_lock_init(&port->lock);
dev->irq = card->irq;
return -ENOBUFS;
}
- printk(KERN_INFO "%s: PC300 node %d\n",
- dev->name, port->phy_node);
+ printk(KERN_INFO "%s: PC300 channel %d\n",
+ dev->name, port->chan);
}
return 0;
}
/*
* Goramo PCI200SYN synchronous serial card driver for Linux
*
- * Copyright (C) 2002-2003 Krzysztof Halasa <khc@pm.waw.pl>
+ * Copyright (C) 2002-2008 Krzysztof Halasa <khc@pm.waw.pl>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License
typedef struct port_s {
struct napi_struct napi;
- struct net_device *dev;
+ struct net_device *netdev;
struct card_s *card;
spinlock_t lock; /* TX lock */
sync_serial_settings settings;
u16 txin; /* tx ring buffer 'in' and 'last' pointers */
u16 txlast;
u8 rxs, txs, tmc; /* SCA registers */
- u8 phy_node; /* physical port # - 0 or 1 */
+ u8 chan; /* physical port # - 0 or 1 */
}port_t;
}card_t;
-#define sca_in(reg, card) readb(card->scabase + (reg))
-#define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
-#define sca_inw(reg, card) readw(card->scabase + (reg))
-#define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
-#define sca_inl(reg, card) readl(card->scabase + (reg))
-#define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
-
-#define port_to_card(port) (port->card)
-#define log_node(port) (port->phy_node)
-#define phy_node(port) (port->phy_node)
-#define winbase(card) (card->rambase)
#define get_port(card, port) (&card->ports[port])
#define sca_flush(card) (sca_in(IER0, card));
u8 rxs = port->rxs & CLK_BRG_MASK;
u8 txs = port->txs & CLK_BRG_MASK;
- sca_out(EXS_TES1, (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS,
- port_to_card(port));
+ sca_out(EXS_TES1, (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS,
+ port->card);
switch(port->settings.clock_type) {
case CLOCK_INT:
rxs |= CLK_BRG; /* BRG output */
sca_open(dev);
pci200_set_iface(port);
- sca_flush(port_to_card(port));
+ sca_flush(port->card);
return 0;
}
static int pci200_close(struct net_device *dev)
{
sca_close(dev);
- sca_flush(port_to_card(dev_to_port(dev)));
+ sca_flush(dev_to_port(dev)->card);
hdlc_close(dev);
return 0;
}
memcpy(&port->settings, &new_line, size); /* Update settings */
pci200_set_iface(port);
- sca_flush(port_to_card(port));
+ sca_flush(port->card);
return 0;
default:
card_t *card = pci_get_drvdata(pdev);
for (i = 0; i < 2; i++)
- if (card->ports[i].card) {
- struct net_device *dev = port_to_dev(&card->ports[i]);
- unregister_hdlc_device(dev);
- }
+ if (card->ports[i].card)
+ unregister_hdlc_device(card->ports[i].netdev);
if (card->irq)
free_irq(card->irq, card);
pci_release_regions(pdev);
pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
- if (card->ports[0].dev)
- free_netdev(card->ports[0].dev);
- if (card->ports[1].dev)
- free_netdev(card->ports[1].dev);
+ if (card->ports[0].netdev)
+ free_netdev(card->ports[0].netdev);
+ if (card->ports[1].netdev)
+ free_netdev(card->ports[1].netdev);
kfree(card);
}
return -ENOBUFS;
}
pci_set_drvdata(pdev, card);
- card->ports[0].dev = alloc_hdlcdev(&card->ports[0]);
- card->ports[1].dev = alloc_hdlcdev(&card->ports[1]);
- if (!card->ports[0].dev || !card->ports[1].dev) {
+ card->ports[0].netdev = alloc_hdlcdev(&card->ports[0]);
+ card->ports[1].netdev = alloc_hdlcdev(&card->ports[1]);
+ if (!card->ports[0].netdev || !card->ports[1].netdev) {
printk(KERN_ERR "pci200syn: unable to allocate memory\n");
pci200_pci_remove_one(pdev);
return -ENOMEM;
for (i = 0; i < 2; i++) {
port_t *port = &card->ports[i];
- struct net_device *dev = port_to_dev(port);
+ struct net_device *dev = port->netdev;
hdlc_device *hdlc = dev_to_hdlc(dev);
- port->phy_node = i;
+ port->chan = i;
spin_lock_init(&port->lock);
dev->irq = card->irq;
return -ENOBUFS;
}
- printk(KERN_INFO "%s: PCI200SYN node %d\n",
- dev->name, port->phy_node);
+ printk(KERN_INFO "%s: PCI200SYN channel %d\n",
+ dev->name, port->chan);
}
sca_flush(card);