aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wan
diff options
context:
space:
mode:
authorKrzysztof Hałasa <khc@pm.waw.pl>2008-07-09 17:13:49 -0400
committerKrzysztof Hałasa <khc@pm.waw.pl>2008-11-21 20:49:48 -0500
commit61e0a6a268947f7385282c6841f3e3d64b4c5cb9 (patch)
tree86a9ee7c3eb2028fe1589df5a94091b153fb273a /drivers/net/wan
parent967834361a4beb3bbd3069189c192dc6fdeef8a9 (diff)
WAN: Simplify HD64572 drivers.
Signed-off-by: Krzysztof Hałasa <khc@pm.waw.pl>
Diffstat (limited to 'drivers/net/wan')
-rw-r--r--drivers/net/wan/hd64572.c139
-rw-r--r--drivers/net/wan/pc300too.c51
-rw-r--r--drivers/net/wan/pci200syn.c55
3 files changed, 110 insertions, 135 deletions
diff --git a/drivers/net/wan/hd64572.c b/drivers/net/wan/hd64572.c
index 46a99a668e41..c7eff0a66a8e 100644
--- a/drivers/net/wan/hd64572.c
+++ b/drivers/net/wan/hd64572.c
@@ -11,13 +11,13 @@
11 * 11 *
12 * We use the following SCA memory map: 12 * We use the following SCA memory map:
13 * 13 *
14 * Packet buffer descriptor rings - starting from winbase or win0base: 14 * Packet buffer descriptor rings - starting from card->rambase:
15 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #0 RX ring 15 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #0 RX ring
16 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #0 TX ring 16 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #0 TX ring
17 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #1 RX ring (if used) 17 * rx_ring_buffers * sizeof(pkt_desc) = logical channel #1 RX ring (if used)
18 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #1 TX ring (if used) 18 * tx_ring_buffers * sizeof(pkt_desc) = logical channel #1 TX ring (if used)
19 * 19 *
20 * Packet data buffers - starting from winbase + buff_offset: 20 * Packet data buffers - starting from card->rambase + buff_offset:
21 * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers 21 * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers
22 * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers 22 * tx_ring_buffers * HDLC_MAX_MRU = logical channel #0 TX buffers
23 * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers (if used) 23 * rx_ring_buffers * HDLC_MAX_MRU = logical channel #0 RX buffers (if used)
@@ -47,16 +47,18 @@
47 47
48#define NAPI_WEIGHT 16 48#define NAPI_WEIGHT 16
49 49
50#define get_msci(port) (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET) 50#define get_msci(port) (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET)
51#define get_dmac_rx(port) (phy_node(port) ? DMAC1RX_OFFSET : DMAC0RX_OFFSET) 51#define get_dmac_rx(port) (port->chan ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)
52#define get_dmac_tx(port) (phy_node(port) ? DMAC1TX_OFFSET : DMAC0TX_OFFSET) 52#define get_dmac_tx(port) (port->chan ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)
53 53
54static int sca_poll(struct napi_struct *napi, int budget); 54#define sca_in(reg, card) readb(card->scabase + (reg))
55#define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
56#define sca_inw(reg, card) readw(card->scabase + (reg))
57#define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
58#define sca_inl(reg, card) readl(card->scabase + (reg))
59#define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
55 60
56static inline struct net_device *port_to_dev(port_t *port) 61static int sca_poll(struct napi_struct *napi, int budget);
57{
58 return port->dev;
59}
60 62
61static inline port_t* dev_to_port(struct net_device *dev) 63static inline port_t* dev_to_port(struct net_device *dev)
62{ 64{
@@ -67,30 +69,29 @@ static inline void enable_intr(port_t *port)
67{ 69{
68 /* enable DMIB and MSCI RXINTA interrupts */ 70 /* enable DMIB and MSCI RXINTA interrupts */
69 sca_outl(sca_inl(IER0, port->card) | 71 sca_outl(sca_inl(IER0, port->card) |
70 (phy_node(port) ? 0x08002200 : 0x00080022), IER0, port->card); 72 (port->chan ? 0x08002200 : 0x00080022), IER0, port->card);
71} 73}
72 74
73static inline void disable_intr(port_t *port) 75static inline void disable_intr(port_t *port)
74{ 76{
75 sca_outl(sca_inl(IER0, port->card) & 77 sca_outl(sca_inl(IER0, port->card) &
76 (phy_node(port) ? 0x00FF00FF : 0xFF00FF00), IER0, port->card); 78 (port->chan ? 0x00FF00FF : 0xFF00FF00), IER0, port->card);
77} 79}
78 80
79static inline u16 next_desc(port_t *port, u16 desc, int transmit) 81static inline u16 next_desc(port_t *port, u16 desc, int transmit)
80{ 82{
81 return (desc + 1) % (transmit ? port_to_card(port)->tx_ring_buffers 83 return (desc + 1) % (transmit ? port->card->tx_ring_buffers
82 : port_to_card(port)->rx_ring_buffers); 84 : port->card->rx_ring_buffers);
83} 85}
84 86
85 87
86static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit) 88static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit)
87{ 89{
88 u16 rx_buffs = port_to_card(port)->rx_ring_buffers; 90 u16 rx_buffs = port->card->rx_ring_buffers;
89 u16 tx_buffs = port_to_card(port)->tx_ring_buffers; 91 u16 tx_buffs = port->card->tx_ring_buffers;
90 92
91 desc %= (transmit ? tx_buffs : rx_buffs); // called with "X + 1" etc. 93 desc %= (transmit ? tx_buffs : rx_buffs); // called with "X + 1" etc.
92 return log_node(port) * (rx_buffs + tx_buffs) + 94 return port->chan * (rx_buffs + tx_buffs) + transmit * rx_buffs + desc;
93 transmit * rx_buffs + desc;
94} 95}
95 96
96 97
@@ -104,39 +105,39 @@ static inline u16 desc_offset(port_t *port, u16 desc, int transmit)
104static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, 105static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc,
105 int transmit) 106 int transmit)
106{ 107{
107 return (pkt_desc __iomem *)(winbase(port_to_card(port)) 108 return (pkt_desc __iomem *)(port->card->rambase +
108 + desc_offset(port, desc, transmit)); 109 desc_offset(port, desc, transmit));
109} 110}
110 111
111 112
112static inline u32 buffer_offset(port_t *port, u16 desc, int transmit) 113static inline u32 buffer_offset(port_t *port, u16 desc, int transmit)
113{ 114{
114 return port_to_card(port)->buff_offset + 115 return port->card->buff_offset +
115 desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU; 116 desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU;
116} 117}
117 118
118 119
119static inline void sca_set_carrier(port_t *port) 120static inline void sca_set_carrier(port_t *port)
120{ 121{
121 if (!(sca_in(get_msci(port) + ST3, port_to_card(port)) & ST3_DCD)) { 122 if (!(sca_in(get_msci(port) + ST3, port->card) & ST3_DCD)) {
122#ifdef DEBUG_LINK 123#ifdef DEBUG_LINK
123 printk(KERN_DEBUG "%s: sca_set_carrier on\n", 124 printk(KERN_DEBUG "%s: sca_set_carrier on\n",
124 port_to_dev(port)->name); 125 port->netdev.name);
125#endif 126#endif
126 netif_carrier_on(port_to_dev(port)); 127 netif_carrier_on(port->netdev);
127 } else { 128 } else {
128#ifdef DEBUG_LINK 129#ifdef DEBUG_LINK
129 printk(KERN_DEBUG "%s: sca_set_carrier off\n", 130 printk(KERN_DEBUG "%s: sca_set_carrier off\n",
130 port_to_dev(port)->name); 131 port->netdev.name);
131#endif 132#endif
132 netif_carrier_off(port_to_dev(port)); 133 netif_carrier_off(port->netdev);
133 } 134 }
134} 135}
135 136
136 137
137static void sca_init_port(port_t *port) 138static void sca_init_port(port_t *port)
138{ 139{
139 card_t *card = port_to_card(port); 140 card_t *card = port->card;
140 int transmit, i; 141 int transmit, i;
141 142
142 port->rxin = 0; 143 port->rxin = 0;
@@ -160,11 +161,11 @@ static void sca_init_port(port_t *port)
160 } 161 }
161 162
162 /* DMA disable - to halt state */ 163 /* DMA disable - to halt state */
163 sca_out(0, transmit ? DSR_TX(phy_node(port)) : 164 sca_out(0, transmit ? DSR_TX(port->chan) :
164 DSR_RX(phy_node(port)), card); 165 DSR_RX(port->chan), card);
165 /* software ABORT - to initial state */ 166 /* software ABORT - to initial state */
166 sca_out(DCR_ABORT, transmit ? DCR_TX(phy_node(port)) : 167 sca_out(DCR_ABORT, transmit ? DCR_TX(port->chan) :
167 DCR_RX(phy_node(port)), card); 168 DCR_RX(port->chan), card);
168 169
169 /* current desc addr */ 170 /* current desc addr */
170 sca_outl(desc_offset(port, 0, transmit), dmac + CDAL, card); 171 sca_outl(desc_offset(port, 0, transmit), dmac + CDAL, card);
@@ -176,26 +177,26 @@ static void sca_init_port(port_t *port)
176 card); 177 card);
177 178
178 /* clear frame end interrupt counter */ 179 /* clear frame end interrupt counter */
179 sca_out(DCR_CLEAR_EOF, transmit ? DCR_TX(phy_node(port)) : 180 sca_out(DCR_CLEAR_EOF, transmit ? DCR_TX(port->chan) :
180 DCR_RX(phy_node(port)), card); 181 DCR_RX(port->chan), card);
181 182
182 if (!transmit) { /* Receive */ 183 if (!transmit) { /* Receive */
183 /* set buffer length */ 184 /* set buffer length */
184 sca_outw(HDLC_MAX_MRU, dmac + BFLL, card); 185 sca_outw(HDLC_MAX_MRU, dmac + BFLL, card);
185 /* Chain mode, Multi-frame */ 186 /* Chain mode, Multi-frame */
186 sca_out(0x14, DMR_RX(phy_node(port)), card); 187 sca_out(0x14, DMR_RX(port->chan), card);
187 sca_out(DIR_EOME, DIR_RX(phy_node(port)), card); 188 sca_out(DIR_EOME, DIR_RX(port->chan), card);
188 /* DMA enable */ 189 /* DMA enable */
189 sca_out(DSR_DE, DSR_RX(phy_node(port)), card); 190 sca_out(DSR_DE, DSR_RX(port->chan), card);
190 } else { /* Transmit */ 191 } else { /* Transmit */
191 /* Chain mode, Multi-frame */ 192 /* Chain mode, Multi-frame */
192 sca_out(0x14, DMR_TX(phy_node(port)), card); 193 sca_out(0x14, DMR_TX(port->chan), card);
193 /* enable underflow interrupts */ 194 /* enable underflow interrupts */
194 sca_out(DIR_EOME, DIR_TX(phy_node(port)), card); 195 sca_out(DIR_EOME, DIR_TX(port->chan), card);
195 } 196 }
196 } 197 }
197 sca_set_carrier(port); 198 sca_set_carrier(port);
198 netif_napi_add(port_to_dev(port), &port->napi, sca_poll, NAPI_WEIGHT); 199 netif_napi_add(port->netdev, &port->napi, sca_poll, NAPI_WEIGHT);
199} 200}
200 201
201 202
@@ -203,7 +204,7 @@ static void sca_init_port(port_t *port)
203static inline void sca_msci_intr(port_t *port) 204static inline void sca_msci_intr(port_t *port)
204{ 205{
205 u16 msci = get_msci(port); 206 u16 msci = get_msci(port);
206 card_t* card = port_to_card(port); 207 card_t* card = port->card;
207 208
208 if (sca_in(msci + ST1, card) & ST1_CDCD) { 209 if (sca_in(msci + ST1, card) & ST1_CDCD) {
209 /* Reset MSCI CDCD status bit */ 210 /* Reset MSCI CDCD status bit */
@@ -216,7 +217,7 @@ static inline void sca_msci_intr(port_t *port)
216static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, 217static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc,
217 u16 rxin) 218 u16 rxin)
218{ 219{
219 struct net_device *dev = port_to_dev(port); 220 struct net_device *dev = port->netdev;
220 struct sk_buff *skb; 221 struct sk_buff *skb;
221 u16 len; 222 u16 len;
222 u32 buff; 223 u32 buff;
@@ -229,7 +230,7 @@ static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc,
229 } 230 }
230 231
231 buff = buffer_offset(port, rxin, 0); 232 buff = buffer_offset(port, rxin, 0);
232 memcpy_fromio(skb->data, winbase(card) + buff, len); 233 memcpy_fromio(skb->data, card->rambase + buff, len);
233 234
234 skb_put(skb, len); 235 skb_put(skb, len);
235#ifdef DEBUG_PKT 236#ifdef DEBUG_PKT
@@ -246,15 +247,15 @@ static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc,
246/* Receive DMA service */ 247/* Receive DMA service */
247static inline int sca_rx_done(port_t *port, int budget) 248static inline int sca_rx_done(port_t *port, int budget)
248{ 249{
249 struct net_device *dev = port_to_dev(port); 250 struct net_device *dev = port->netdev;
250 u16 dmac = get_dmac_rx(port); 251 u16 dmac = get_dmac_rx(port);
251 card_t *card = port_to_card(port); 252 card_t *card = port->card;
252 u8 stat = sca_in(DSR_RX(phy_node(port)), card); /* read DMA Status */ 253 u8 stat = sca_in(DSR_RX(port->chan), card); /* read DMA Status */
253 int received = 0; 254 int received = 0;
254 255
255 /* Reset DSR status bits */ 256 /* Reset DSR status bits */
256 sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE, 257 sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
257 DSR_RX(phy_node(port)), card); 258 DSR_RX(port->chan), card);
258 259
259 if (stat & DSR_BOF) 260 if (stat & DSR_BOF)
260 /* Dropped one or more frames */ 261 /* Dropped one or more frames */
@@ -294,7 +295,7 @@ static inline int sca_rx_done(port_t *port, int budget)
294 } 295 }
295 296
296 /* make sure RX DMA is enabled */ 297 /* make sure RX DMA is enabled */
297 sca_out(DSR_DE, DSR_RX(phy_node(port)), card); 298 sca_out(DSR_DE, DSR_RX(port->chan), card);
298 return received; 299 return received;
299} 300}
300 301
@@ -302,17 +303,17 @@ static inline int sca_rx_done(port_t *port, int budget)
302/* Transmit DMA service */ 303/* Transmit DMA service */
303static inline void sca_tx_done(port_t *port) 304static inline void sca_tx_done(port_t *port)
304{ 305{
305 struct net_device *dev = port_to_dev(port); 306 struct net_device *dev = port->netdev;
306 card_t* card = port_to_card(port); 307 card_t* card = port->card;
307 u8 stat; 308 u8 stat;
308 309
309 spin_lock(&port->lock); 310 spin_lock(&port->lock);
310 311
311 stat = sca_in(DSR_TX(phy_node(port)), card); /* read DMA Status */ 312 stat = sca_in(DSR_TX(port->chan), card); /* read DMA Status */
312 313
313 /* Reset DSR status bits */ 314 /* Reset DSR status bits */
314 sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE, 315 sca_out((stat & (DSR_EOT | DSR_EOM | DSR_BOF | DSR_COF)) | DSR_DWE,
315 DSR_TX(phy_node(port)), card); 316 DSR_TX(port->chan), card);
316 317
317 while (1) { 318 while (1) {
318 pkt_desc __iomem *desc = desc_address(port, port->txlast, 1); 319 pkt_desc __iomem *desc = desc_address(port, port->txlast, 1);
@@ -342,17 +343,17 @@ static int sca_poll(struct napi_struct *napi, int budget)
342 u32 isr0 = sca_inl(ISR0, port->card); 343 u32 isr0 = sca_inl(ISR0, port->card);
343 int received = 0; 344 int received = 0;
344 345
345 if (isr0 & (port->phy_node ? 0x08000000 : 0x00080000)) 346 if (isr0 & (port->chan ? 0x08000000 : 0x00080000))
346 sca_msci_intr(port); 347 sca_msci_intr(port);
347 348
348 if (isr0 & (port->phy_node ? 0x00002000 : 0x00000020)) 349 if (isr0 & (port->chan ? 0x00002000 : 0x00000020))
349 sca_tx_done(port); 350 sca_tx_done(port);
350 351
351 if (isr0 & (port->phy_node ? 0x00000200 : 0x00000002)) 352 if (isr0 & (port->chan ? 0x00000200 : 0x00000002))
352 received = sca_rx_done(port, budget); 353 received = sca_rx_done(port, budget);
353 354
354 if (received < budget) { 355 if (received < budget) {
355 netif_rx_complete(port->dev, napi); 356 netif_rx_complete(port->netdev, napi);
356 enable_intr(port); 357 enable_intr(port);
357 } 358 }
358 359
@@ -370,7 +371,7 @@ static irqreturn_t sca_intr(int irq, void *dev_id)
370 if (port && (isr0 & (i ? 0x08002200 : 0x00080022))) { 371 if (port && (isr0 & (i ? 0x08002200 : 0x00080022))) {
371 handled = 1; 372 handled = 1;
372 disable_intr(port); 373 disable_intr(port);
373 netif_rx_schedule(port->dev, &port->napi); 374 netif_rx_schedule(port->netdev, &port->napi);
374 } 375 }
375 } 376 }
376 377
@@ -380,7 +381,7 @@ static irqreturn_t sca_intr(int irq, void *dev_id)
380 381
381static void sca_set_port(port_t *port) 382static void sca_set_port(port_t *port)
382{ 383{
383 card_t* card = port_to_card(port); 384 card_t* card = port->card;
384 u16 msci = get_msci(port); 385 u16 msci = get_msci(port);
385 u8 md2 = sca_in(msci + MD2, card); 386 u8 md2 = sca_in(msci + MD2, card);
386 unsigned int tmc, br = 10, brv = 1024; 387 unsigned int tmc, br = 10, brv = 1024;
@@ -435,7 +436,7 @@ static void sca_set_port(port_t *port)
435static void sca_open(struct net_device *dev) 436static void sca_open(struct net_device *dev)
436{ 437{
437 port_t *port = dev_to_port(dev); 438 port_t *port = dev_to_port(dev);
438 card_t* card = port_to_card(port); 439 card_t* card = port->card;
439 u16 msci = get_msci(port); 440 u16 msci = get_msci(port);
440 u8 md0, md2; 441 u8 md0, md2;
441 442
@@ -496,7 +497,7 @@ static void sca_close(struct net_device *dev)
496 port_t *port = dev_to_port(dev); 497 port_t *port = dev_to_port(dev);
497 498
498 /* reset channel */ 499 /* reset channel */
499 sca_out(CMD_RESET, get_msci(port) + CMD, port_to_card(port)); 500 sca_out(CMD_RESET, get_msci(port) + CMD, port->card);
500 disable_intr(port); 501 disable_intr(port);
501 napi_disable(&port->napi); 502 napi_disable(&port->napi);
502 netif_stop_queue(dev); 503 netif_stop_queue(dev);
@@ -530,25 +531,25 @@ static int sca_attach(struct net_device *dev, unsigned short encoding,
530static void sca_dump_rings(struct net_device *dev) 531static void sca_dump_rings(struct net_device *dev)
531{ 532{
532 port_t *port = dev_to_port(dev); 533 port_t *port = dev_to_port(dev);
533 card_t *card = port_to_card(port); 534 card_t *card = port->card;
534 u16 cnt; 535 u16 cnt;
535 536
536 printk(KERN_DEBUG "RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive", 537 printk(KERN_DEBUG "RX ring: CDA=%u EDA=%u DSR=%02X in=%u %sactive",
537 sca_inl(get_dmac_rx(port) + CDAL, card), 538 sca_inl(get_dmac_rx(port) + CDAL, card),
538 sca_inl(get_dmac_rx(port) + EDAL, card), 539 sca_inl(get_dmac_rx(port) + EDAL, card),
539 sca_in(DSR_RX(phy_node(port)), card), port->rxin, 540 sca_in(DSR_RX(port->chan), card), port->rxin,
540 sca_in(DSR_RX(phy_node(port)), card) & DSR_DE ? "" : "in"); 541 sca_in(DSR_RX(port->chan), card) & DSR_DE ? "" : "in");
541 for (cnt = 0; cnt < port_to_card(port)->rx_ring_buffers; cnt++) 542 for (cnt = 0; cnt < port->card->rx_ring_buffers; cnt++)
542 printk(" %02X", readb(&(desc_address(port, cnt, 0)->stat))); 543 printk(" %02X", readb(&(desc_address(port, cnt, 0)->stat)));
543 544
544 printk("\n" KERN_DEBUG "TX ring: CDA=%u EDA=%u DSR=%02X in=%u " 545 printk("\n" KERN_DEBUG "TX ring: CDA=%u EDA=%u DSR=%02X in=%u "
545 "last=%u %sactive", 546 "last=%u %sactive",
546 sca_inl(get_dmac_tx(port) + CDAL, card), 547 sca_inl(get_dmac_tx(port) + CDAL, card),
547 sca_inl(get_dmac_tx(port) + EDAL, card), 548 sca_inl(get_dmac_tx(port) + EDAL, card),
548 sca_in(DSR_TX(phy_node(port)), card), port->txin, port->txlast, 549 sca_in(DSR_TX(port->chan), card), port->txin, port->txlast,
549 sca_in(DSR_TX(phy_node(port)), card) & DSR_DE ? "" : "in"); 550 sca_in(DSR_TX(port->chan), card) & DSR_DE ? "" : "in");
550 551
551 for (cnt = 0; cnt < port_to_card(port)->tx_ring_buffers; cnt++) 552 for (cnt = 0; cnt < port->card->tx_ring_buffers; cnt++)
552 printk(" %02X", readb(&(desc_address(port, cnt, 1)->stat))); 553 printk(" %02X", readb(&(desc_address(port, cnt, 1)->stat)));
553 printk("\n"); 554 printk("\n");
554 555
@@ -575,7 +576,7 @@ static void sca_dump_rings(struct net_device *dev)
575static int sca_xmit(struct sk_buff *skb, struct net_device *dev) 576static int sca_xmit(struct sk_buff *skb, struct net_device *dev)
576{ 577{
577 port_t *port = dev_to_port(dev); 578 port_t *port = dev_to_port(dev);
578 card_t *card = port_to_card(port); 579 card_t *card = port->card;
579 pkt_desc __iomem *desc; 580 pkt_desc __iomem *desc;
580 u32 buff, len; 581 u32 buff, len;
581 582
@@ -592,7 +593,7 @@ static int sca_xmit(struct sk_buff *skb, struct net_device *dev)
592 desc = desc_address(port, port->txin, 1); 593 desc = desc_address(port, port->txin, 1);
593 buff = buffer_offset(port, port->txin, 1); 594 buff = buffer_offset(port, port->txin, 1);
594 len = skb->len; 595 len = skb->len;
595 memcpy_toio(winbase(card) + buff, skb->data, len); 596 memcpy_toio(card->rambase + buff, skb->data, len);
596 597
597 writew(len, &desc->len); 598 writew(len, &desc->len);
598 writeb(ST_TX_EOM, &desc->stat); 599 writeb(ST_TX_EOM, &desc->stat);
@@ -602,7 +603,7 @@ static int sca_xmit(struct sk_buff *skb, struct net_device *dev)
602 sca_outl(desc_offset(port, port->txin, 1), 603 sca_outl(desc_offset(port, port->txin, 1),
603 get_dmac_tx(port) + EDAL, card); 604 get_dmac_tx(port) + EDAL, card);
604 605
605 sca_out(DSR_DE, DSR_TX(phy_node(port)), card); /* Enable TX DMA */ 606 sca_out(DSR_DE, DSR_TX(port->chan), card); /* Enable TX DMA */
606 607
607 desc = desc_address(port, port->txin + 1, 1); 608 desc = desc_address(port, port->txin + 1, 1);
608 if (readb(&desc->stat)) /* allow 1 packet gap */ 609 if (readb(&desc->stat)) /* allow 1 packet gap */
diff --git a/drivers/net/wan/pc300too.c b/drivers/net/wan/pc300too.c
index 9b42199d4f83..ac8b0a20a0d8 100644
--- a/drivers/net/wan/pc300too.c
+++ b/drivers/net/wan/pc300too.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Cyclades PC300 synchronous serial card driver for Linux 2 * Cyclades PC300 synchronous serial card driver for Linux
3 * 3 *
4 * Copyright (C) 2000-2007 Krzysztof Halasa <khc@pm.waw.pl> 4 * Copyright (C) 2000-2008 Krzysztof Halasa <khc@pm.waw.pl>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License 7 * under the terms of version 2 of the GNU General Public License
@@ -11,7 +11,7 @@
11 * 11 *
12 * Sources of information: 12 * Sources of information:
13 * Hitachi HD64572 SCA-II User's Manual 13 * Hitachi HD64572 SCA-II User's Manual
14 * Cyclades PC300 Linux driver 14 * Original Cyclades PC300 Linux driver
15 * 15 *
16 * This driver currently supports only PC300/RSV (V.24/V.35) and 16 * This driver currently supports only PC300/RSV (V.24/V.35) and
17 * PC300/X21 cards. 17 * PC300/X21 cards.
@@ -76,7 +76,7 @@ typedef struct {
76 76
77typedef struct port_s { 77typedef struct port_s {
78 struct napi_struct napi; 78 struct napi_struct napi;
79 struct net_device *dev; 79 struct net_device *netdev;
80 struct card_s *card; 80 struct card_s *card;
81 spinlock_t lock; /* TX lock */ 81 spinlock_t lock; /* TX lock */
82 sync_serial_settings settings; 82 sync_serial_settings settings;
@@ -88,7 +88,7 @@ typedef struct port_s {
88 u16 txin; /* tx ring buffer 'in' and 'last' pointers */ 88 u16 txin; /* tx ring buffer 'in' and 'last' pointers */
89 u16 txlast; 89 u16 txlast;
90 u8 rxs, txs, tmc; /* SCA registers */ 90 u8 rxs, txs, tmc; /* SCA registers */
91 u8 phy_node; /* physical port # - 0 or 1 */ 91 u8 chan; /* physical port # - 0 or 1 */
92}port_t; 92}port_t;
93 93
94 94
@@ -109,17 +109,6 @@ typedef struct card_s {
109}card_t; 109}card_t;
110 110
111 111
112#define sca_in(reg, card) readb(card->scabase + (reg))
113#define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
114#define sca_inw(reg, card) readw(card->scabase + (reg))
115#define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
116#define sca_inl(reg, card) readl(card->scabase + (reg))
117#define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
118
119#define port_to_card(port) (port->card)
120#define log_node(port) (port->phy_node)
121#define phy_node(port) (port->phy_node)
122#define winbase(card) (card->rambase)
123#define get_port(card, port) ((port) < (card)->n_ports ? \ 112#define get_port(card, port) ((port) < (card)->n_ports ? \
124 (&(card)->ports[port]) : (NULL)) 113 (&(card)->ports[port]) : (NULL))
125 114
@@ -134,8 +123,8 @@ static void pc300_set_iface(port_t *port)
134 u8 rxs = port->rxs & CLK_BRG_MASK; 123 u8 rxs = port->rxs & CLK_BRG_MASK;
135 u8 txs = port->txs & CLK_BRG_MASK; 124 u8 txs = port->txs & CLK_BRG_MASK;
136 125
137 sca_out(EXS_TES1, (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS, 126 sca_out(EXS_TES1, (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS,
138 port_to_card(port)); 127 port->card);
139 switch(port->settings.clock_type) { 128 switch(port->settings.clock_type) {
140 case CLOCK_INT: 129 case CLOCK_INT:
141 rxs |= CLK_BRG; /* BRG output */ 130 rxs |= CLK_BRG; /* BRG output */
@@ -167,10 +156,10 @@ static void pc300_set_iface(port_t *port)
167 if (port->card->type == PC300_RSV) { 156 if (port->card->type == PC300_RSV) {
168 if (port->iface == IF_IFACE_V35) 157 if (port->iface == IF_IFACE_V35)
169 writel(card->init_ctrl_value | 158 writel(card->init_ctrl_value |
170 PC300_CHMEDIA_MASK(port->phy_node), init_ctrl); 159 PC300_CHMEDIA_MASK(port->chan), init_ctrl);
171 else 160 else
172 writel(card->init_ctrl_value & 161 writel(card->init_ctrl_value &
173 ~PC300_CHMEDIA_MASK(port->phy_node), init_ctrl); 162 ~PC300_CHMEDIA_MASK(port->chan), init_ctrl);
174 } 163 }
175} 164}
176 165
@@ -275,10 +264,8 @@ static void pc300_pci_remove_one(struct pci_dev *pdev)
275 card_t *card = pci_get_drvdata(pdev); 264 card_t *card = pci_get_drvdata(pdev);
276 265
277 for (i = 0; i < 2; i++) 266 for (i = 0; i < 2; i++)
278 if (card->ports[i].card) { 267 if (card->ports[i].card)
279 struct net_device *dev = port_to_dev(&card->ports[i]); 268 unregister_hdlc_device(card->ports[i].netdev);
280 unregister_hdlc_device(dev);
281 }
282 269
283 if (card->irq) 270 if (card->irq)
284 free_irq(card->irq, card); 271 free_irq(card->irq, card);
@@ -293,10 +280,10 @@ static void pc300_pci_remove_one(struct pci_dev *pdev)
293 pci_release_regions(pdev); 280 pci_release_regions(pdev);
294 pci_disable_device(pdev); 281 pci_disable_device(pdev);
295 pci_set_drvdata(pdev, NULL); 282 pci_set_drvdata(pdev, NULL);
296 if (card->ports[0].dev) 283 if (card->ports[0].netdev)
297 free_netdev(card->ports[0].dev); 284 free_netdev(card->ports[0].netdev);
298 if (card->ports[1].dev) 285 if (card->ports[1].netdev)
299 free_netdev(card->ports[1].dev); 286 free_netdev(card->ports[1].netdev);
300 kfree(card); 287 kfree(card);
301} 288}
302 289
@@ -347,7 +334,7 @@ static int __devinit pc300_pci_init_one(struct pci_dev *pdev,
347 card->n_ports = 2; 334 card->n_ports = 2;
348 335
349 for (i = 0; i < card->n_ports; i++) 336 for (i = 0; i < card->n_ports; i++)
350 if (!(card->ports[i].dev = alloc_hdlcdev(&card->ports[i]))) { 337 if (!(card->ports[i].netdev = alloc_hdlcdev(&card->ports[i]))) {
351 printk(KERN_ERR "pc300: unable to allocate memory\n"); 338 printk(KERN_ERR "pc300: unable to allocate memory\n");
352 pc300_pci_remove_one(pdev); 339 pc300_pci_remove_one(pdev);
353 return -ENOMEM; 340 return -ENOMEM;
@@ -452,9 +439,9 @@ static int __devinit pc300_pci_init_one(struct pci_dev *pdev,
452 439
453 for (i = 0; i < card->n_ports; i++) { 440 for (i = 0; i < card->n_ports; i++) {
454 port_t *port = &card->ports[i]; 441 port_t *port = &card->ports[i];
455 struct net_device *dev = port_to_dev(port); 442 struct net_device *dev = port->netdev;
456 hdlc_device *hdlc = dev_to_hdlc(dev); 443 hdlc_device *hdlc = dev_to_hdlc(dev);
457 port->phy_node = i; 444 port->chan = i;
458 445
459 spin_lock_init(&port->lock); 446 spin_lock_init(&port->lock);
460 dev->irq = card->irq; 447 dev->irq = card->irq;
@@ -482,8 +469,8 @@ static int __devinit pc300_pci_init_one(struct pci_dev *pdev,
482 return -ENOBUFS; 469 return -ENOBUFS;
483 } 470 }
484 471
485 printk(KERN_INFO "%s: PC300 node %d\n", 472 printk(KERN_INFO "%s: PC300 channel %d\n",
486 dev->name, port->phy_node); 473 dev->name, port->chan);
487 } 474 }
488 return 0; 475 return 0;
489} 476}
diff --git a/drivers/net/wan/pci200syn.c b/drivers/net/wan/pci200syn.c
index a16311a79e9a..1104d3a692f7 100644
--- a/drivers/net/wan/pci200syn.c
+++ b/drivers/net/wan/pci200syn.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Goramo PCI200SYN synchronous serial card driver for Linux 2 * Goramo PCI200SYN synchronous serial card driver for Linux
3 * 3 *
4 * Copyright (C) 2002-2003 Krzysztof Halasa <khc@pm.waw.pl> 4 * Copyright (C) 2002-2008 Krzysztof Halasa <khc@pm.waw.pl>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License 7 * under the terms of version 2 of the GNU General Public License
@@ -63,7 +63,7 @@ typedef struct {
63 63
64typedef struct port_s { 64typedef struct port_s {
65 struct napi_struct napi; 65 struct napi_struct napi;
66 struct net_device *dev; 66 struct net_device *netdev;
67 struct card_s *card; 67 struct card_s *card;
68 spinlock_t lock; /* TX lock */ 68 spinlock_t lock; /* TX lock */
69 sync_serial_settings settings; 69 sync_serial_settings settings;
@@ -74,7 +74,7 @@ typedef struct port_s {
74 u16 txin; /* tx ring buffer 'in' and 'last' pointers */ 74 u16 txin; /* tx ring buffer 'in' and 'last' pointers */
75 u16 txlast; 75 u16 txlast;
76 u8 rxs, txs, tmc; /* SCA registers */ 76 u8 rxs, txs, tmc; /* SCA registers */
77 u8 phy_node; /* physical port # - 0 or 1 */ 77 u8 chan; /* physical port # - 0 or 1 */
78}port_t; 78}port_t;
79 79
80 80
@@ -92,17 +92,6 @@ typedef struct card_s {
92}card_t; 92}card_t;
93 93
94 94
95#define sca_in(reg, card) readb(card->scabase + (reg))
96#define sca_out(value, reg, card) writeb(value, card->scabase + (reg))
97#define sca_inw(reg, card) readw(card->scabase + (reg))
98#define sca_outw(value, reg, card) writew(value, card->scabase + (reg))
99#define sca_inl(reg, card) readl(card->scabase + (reg))
100#define sca_outl(value, reg, card) writel(value, card->scabase + (reg))
101
102#define port_to_card(port) (port->card)
103#define log_node(port) (port->phy_node)
104#define phy_node(port) (port->phy_node)
105#define winbase(card) (card->rambase)
106#define get_port(card, port) (&card->ports[port]) 95#define get_port(card, port) (&card->ports[port])
107#define sca_flush(card) (sca_in(IER0, card)); 96#define sca_flush(card) (sca_in(IER0, card));
108 97
@@ -132,8 +121,8 @@ static void pci200_set_iface(port_t *port)
132 u8 rxs = port->rxs & CLK_BRG_MASK; 121 u8 rxs = port->rxs & CLK_BRG_MASK;
133 u8 txs = port->txs & CLK_BRG_MASK; 122 u8 txs = port->txs & CLK_BRG_MASK;
134 123
135 sca_out(EXS_TES1, (phy_node(port) ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS, 124 sca_out(EXS_TES1, (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS,
136 port_to_card(port)); 125 port->card);
137 switch(port->settings.clock_type) { 126 switch(port->settings.clock_type) {
138 case CLOCK_INT: 127 case CLOCK_INT:
139 rxs |= CLK_BRG; /* BRG output */ 128 rxs |= CLK_BRG; /* BRG output */
@@ -175,7 +164,7 @@ static int pci200_open(struct net_device *dev)
175 164
176 sca_open(dev); 165 sca_open(dev);
177 pci200_set_iface(port); 166 pci200_set_iface(port);
178 sca_flush(port_to_card(port)); 167 sca_flush(port->card);
179 return 0; 168 return 0;
180} 169}
181 170
@@ -184,7 +173,7 @@ static int pci200_open(struct net_device *dev)
184static int pci200_close(struct net_device *dev) 173static int pci200_close(struct net_device *dev)
185{ 174{
186 sca_close(dev); 175 sca_close(dev);
187 sca_flush(port_to_card(dev_to_port(dev))); 176 sca_flush(dev_to_port(dev)->card);
188 hdlc_close(dev); 177 hdlc_close(dev);
189 return 0; 178 return 0;
190} 179}
@@ -237,7 +226,7 @@ static int pci200_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
237 226
238 memcpy(&port->settings, &new_line, size); /* Update settings */ 227 memcpy(&port->settings, &new_line, size); /* Update settings */
239 pci200_set_iface(port); 228 pci200_set_iface(port);
240 sca_flush(port_to_card(port)); 229 sca_flush(port->card);
241 return 0; 230 return 0;
242 231
243 default: 232 default:
@@ -253,10 +242,8 @@ static void pci200_pci_remove_one(struct pci_dev *pdev)
253 card_t *card = pci_get_drvdata(pdev); 242 card_t *card = pci_get_drvdata(pdev);
254 243
255 for (i = 0; i < 2; i++) 244 for (i = 0; i < 2; i++)
256 if (card->ports[i].card) { 245 if (card->ports[i].card)
257 struct net_device *dev = port_to_dev(&card->ports[i]); 246 unregister_hdlc_device(card->ports[i].netdev);
258 unregister_hdlc_device(dev);
259 }
260 247
261 if (card->irq) 248 if (card->irq)
262 free_irq(card->irq, card); 249 free_irq(card->irq, card);
@@ -271,10 +258,10 @@ static void pci200_pci_remove_one(struct pci_dev *pdev)
271 pci_release_regions(pdev); 258 pci_release_regions(pdev);
272 pci_disable_device(pdev); 259 pci_disable_device(pdev);
273 pci_set_drvdata(pdev, NULL); 260 pci_set_drvdata(pdev, NULL);
274 if (card->ports[0].dev) 261 if (card->ports[0].netdev)
275 free_netdev(card->ports[0].dev); 262 free_netdev(card->ports[0].netdev);
276 if (card->ports[1].dev) 263 if (card->ports[1].netdev)
277 free_netdev(card->ports[1].dev); 264 free_netdev(card->ports[1].netdev);
278 kfree(card); 265 kfree(card);
279} 266}
280 267
@@ -309,9 +296,9 @@ static int __devinit pci200_pci_init_one(struct pci_dev *pdev,
309 return -ENOBUFS; 296 return -ENOBUFS;
310 } 297 }
311 pci_set_drvdata(pdev, card); 298 pci_set_drvdata(pdev, card);
312 card->ports[0].dev = alloc_hdlcdev(&card->ports[0]); 299 card->ports[0].netdev = alloc_hdlcdev(&card->ports[0]);
313 card->ports[1].dev = alloc_hdlcdev(&card->ports[1]); 300 card->ports[1].netdev = alloc_hdlcdev(&card->ports[1]);
314 if (!card->ports[0].dev || !card->ports[1].dev) { 301 if (!card->ports[0].netdev || !card->ports[1].netdev) {
315 printk(KERN_ERR "pci200syn: unable to allocate memory\n"); 302 printk(KERN_ERR "pci200syn: unable to allocate memory\n");
316 pci200_pci_remove_one(pdev); 303 pci200_pci_remove_one(pdev);
317 return -ENOMEM; 304 return -ENOMEM;
@@ -399,9 +386,9 @@ static int __devinit pci200_pci_init_one(struct pci_dev *pdev,
399 386
400 for (i = 0; i < 2; i++) { 387 for (i = 0; i < 2; i++) {
401 port_t *port = &card->ports[i]; 388 port_t *port = &card->ports[i];
402 struct net_device *dev = port_to_dev(port); 389 struct net_device *dev = port->netdev;
403 hdlc_device *hdlc = dev_to_hdlc(dev); 390 hdlc_device *hdlc = dev_to_hdlc(dev);
404 port->phy_node = i; 391 port->chan = i;
405 392
406 spin_lock_init(&port->lock); 393 spin_lock_init(&port->lock);
407 dev->irq = card->irq; 394 dev->irq = card->irq;
@@ -424,8 +411,8 @@ static int __devinit pci200_pci_init_one(struct pci_dev *pdev,
424 return -ENOBUFS; 411 return -ENOBUFS;
425 } 412 }
426 413
427 printk(KERN_INFO "%s: PCI200SYN node %d\n", 414 printk(KERN_INFO "%s: PCI200SYN channel %d\n",
428 dev->name, port->phy_node); 415 dev->name, port->chan);
429 } 416 }
430 417
431 sca_flush(card); 418 sca_flush(card);