aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/dec
diff options
context:
space:
mode:
authorFrancois Romieu <romieu@fr.zoreil.com>2012-03-10 05:50:03 -0500
committerFrancois Romieu <romieu@fr.zoreil.com>2012-04-07 05:47:17 -0400
commit3acf4b5cde8123a7a243d9dcd63f3e6990c8e5bb (patch)
treed2f657a9854e213f86d2fdea49e133036a5fcda6 /drivers/net/ethernet/dec
parent5e3cc4e3aaeae953c224bbe92f0ea8d90dfb1b63 (diff)
uli526x: stop using net_device.{base_addr, irq} and convert to __iomem.
The bulk of the patch comes from the __iomem changes. - the phy read and write operations were carrying the chip id deep down the call chain. Let's waste a pointer and contain the flying spaghetti monster. - phy_{read, write}_1bit only need to access the DCR9 register. The loss of generality here should not hurt. - removed a leftover printk of the EISA era. This is a pure PCI device. Signed-off-by: Francois Romieu <romieu@fr.zoreil.com> Acked-by: Grant Grundler <grundler@parisc-linux.org>
Diffstat (limited to 'drivers/net/ethernet/dec')
-rw-r--r--drivers/net/ethernet/dec/tulip/uli526x.c397
1 files changed, 202 insertions, 195 deletions
diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
index c9b33961826c..75d45f8a37dc 100644
--- a/drivers/net/ethernet/dec/tulip/uli526x.c
+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
@@ -42,6 +42,8 @@
42#include <asm/dma.h> 42#include <asm/dma.h>
43#include <asm/uaccess.h> 43#include <asm/uaccess.h>
44 44
45#define uw32(reg, val) iowrite32(val, ioaddr + (reg))
46#define ur32(reg) ioread32(ioaddr + (reg))
45 47
46/* Board/System/Debug information/definition ---------------- */ 48/* Board/System/Debug information/definition ---------------- */
47#define PCI_ULI5261_ID 0x526110B9 /* ULi M5261 ID*/ 49#define PCI_ULI5261_ID 0x526110B9 /* ULi M5261 ID*/
@@ -110,14 +112,6 @@ do { \
110 112
111#define SROM_V41_CODE 0x14 113#define SROM_V41_CODE 0x14
112 114
113#define SROM_CLK_WRITE(data, ioaddr) \
114 outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr); \
115 udelay(5); \
116 outl(data|CR9_SROM_READ|CR9_SRCS|CR9_SRCLK,ioaddr); \
117 udelay(5); \
118 outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr); \
119 udelay(5);
120
121/* Structure/enum declaration ------------------------------- */ 115/* Structure/enum declaration ------------------------------- */
122struct tx_desc { 116struct tx_desc {
123 __le32 tdes0, tdes1, tdes2, tdes3; /* Data for the card */ 117 __le32 tdes0, tdes1, tdes2, tdes3; /* Data for the card */
@@ -132,12 +126,15 @@ struct rx_desc {
132} __attribute__(( aligned(32) )); 126} __attribute__(( aligned(32) ));
133 127
134struct uli526x_board_info { 128struct uli526x_board_info {
135 u32 chip_id; /* Chip vendor/Device ID */ 129 struct uli_phy_ops {
130 void (*write)(struct uli526x_board_info *, u8, u8, u16);
131 u16 (*read)(struct uli526x_board_info *, u8, u8);
132 } phy;
136 struct net_device *next_dev; /* next device */ 133 struct net_device *next_dev; /* next device */
137 struct pci_dev *pdev; /* PCI device */ 134 struct pci_dev *pdev; /* PCI device */
138 spinlock_t lock; 135 spinlock_t lock;
139 136
140 long ioaddr; /* I/O base address */ 137 void __iomem *ioaddr; /* I/O base address */
141 u32 cr0_data; 138 u32 cr0_data;
142 u32 cr5_data; 139 u32 cr5_data;
143 u32 cr6_data; 140 u32 cr6_data;
@@ -227,21 +224,21 @@ static netdev_tx_t uli526x_start_xmit(struct sk_buff *,
227static int uli526x_stop(struct net_device *); 224static int uli526x_stop(struct net_device *);
228static void uli526x_set_filter_mode(struct net_device *); 225static void uli526x_set_filter_mode(struct net_device *);
229static const struct ethtool_ops netdev_ethtool_ops; 226static const struct ethtool_ops netdev_ethtool_ops;
230static u16 read_srom_word(long, int); 227static u16 read_srom_word(struct uli526x_board_info *, int);
231static irqreturn_t uli526x_interrupt(int, void *); 228static irqreturn_t uli526x_interrupt(int, void *);
232#ifdef CONFIG_NET_POLL_CONTROLLER 229#ifdef CONFIG_NET_POLL_CONTROLLER
233static void uli526x_poll(struct net_device *dev); 230static void uli526x_poll(struct net_device *dev);
234#endif 231#endif
235static void uli526x_descriptor_init(struct net_device *, unsigned long); 232static void uli526x_descriptor_init(struct net_device *, void __iomem *);
236static void allocate_rx_buffer(struct net_device *); 233static void allocate_rx_buffer(struct net_device *);
237static void update_cr6(u32, unsigned long); 234static void update_cr6(u32, void __iomem *);
238static void send_filter_frame(struct net_device *, int); 235static void send_filter_frame(struct net_device *, int);
239static u16 phy_read(unsigned long, u8, u8, u32); 236static u16 phy_readby_cr9(struct uli526x_board_info *, u8, u8);
240static u16 phy_readby_cr10(unsigned long, u8, u8); 237static u16 phy_readby_cr10(struct uli526x_board_info *, u8, u8);
241static void phy_write(unsigned long, u8, u8, u16, u32); 238static void phy_writeby_cr9(struct uli526x_board_info *, u8, u8, u16);
242static void phy_writeby_cr10(unsigned long, u8, u8, u16); 239static void phy_writeby_cr10(struct uli526x_board_info *, u8, u8, u16);
243static void phy_write_1bit(unsigned long, u32, u32); 240static void phy_write_1bit(struct uli526x_board_info *db, u32);
244static u16 phy_read_1bit(unsigned long, u32); 241static u16 phy_read_1bit(struct uli526x_board_info *db);
245static u8 uli526x_sense_speed(struct uli526x_board_info *); 242static u8 uli526x_sense_speed(struct uli526x_board_info *);
246static void uli526x_process_mode(struct uli526x_board_info *); 243static void uli526x_process_mode(struct uli526x_board_info *);
247static void uli526x_timer(unsigned long); 244static void uli526x_timer(unsigned long);
@@ -253,6 +250,18 @@ static void uli526x_free_rxbuffer(struct uli526x_board_info *);
253static void uli526x_init(struct net_device *); 250static void uli526x_init(struct net_device *);
254static void uli526x_set_phyxcer(struct uli526x_board_info *); 251static void uli526x_set_phyxcer(struct uli526x_board_info *);
255 252
253static void srom_clk_write(struct uli526x_board_info *db, u32 data)
254{
255 void __iomem *ioaddr = db->ioaddr;
256
257 uw32(DCR9, data | CR9_SROM_READ | CR9_SRCS);
258 udelay(5);
259 uw32(DCR9, data | CR9_SROM_READ | CR9_SRCS | CR9_SRCLK);
260 udelay(5);
261 uw32(DCR9, data | CR9_SROM_READ | CR9_SRCS);
262 udelay(5);
263}
264
256/* ULI526X network board routine ---------------------------- */ 265/* ULI526X network board routine ---------------------------- */
257 266
258static const struct net_device_ops netdev_ops = { 267static const struct net_device_ops netdev_ops = {
@@ -277,6 +286,7 @@ static int __devinit uli526x_init_one (struct pci_dev *pdev,
277{ 286{
278 struct uli526x_board_info *db; /* board information structure */ 287 struct uli526x_board_info *db; /* board information structure */
279 struct net_device *dev; 288 struct net_device *dev;
289 void __iomem *ioaddr;
280 int i, err; 290 int i, err;
281 291
282 ULI526X_DBUG(0, "uli526x_init_one()", 0); 292 ULI526X_DBUG(0, "uli526x_init_one()", 0);
@@ -338,14 +348,26 @@ static int __devinit uli526x_init_one (struct pci_dev *pdev,
338 db->buf_pool_start = db->buf_pool_ptr; 348 db->buf_pool_start = db->buf_pool_ptr;
339 db->buf_pool_dma_start = db->buf_pool_dma_ptr; 349 db->buf_pool_dma_start = db->buf_pool_dma_ptr;
340 350
341 db->chip_id = ent->driver_data; 351 switch (ent->driver_data) {
342 db->ioaddr = pci_resource_start(pdev, 0); 352 case PCI_ULI5263_ID:
353 db->phy.write = phy_writeby_cr10;
354 db->phy.read = phy_readby_cr10;
355 break;
356 default:
357 db->phy.write = phy_writeby_cr9;
358 db->phy.read = phy_readby_cr9;
359 break;
360 }
343 361
362 /* IO region. */
363 ioaddr = pci_iomap(pdev, 0, 0);
364 if (!ioaddr)
365 goto err_out_free_tx_buf;
366
367 db->ioaddr = ioaddr;
344 db->pdev = pdev; 368 db->pdev = pdev;
345 db->init = 1; 369 db->init = 1;
346 370
347 dev->base_addr = db->ioaddr;
348 dev->irq = pdev->irq;
349 pci_set_drvdata(pdev, dev); 371 pci_set_drvdata(pdev, dev);
350 372
351 /* Register some necessary functions */ 373 /* Register some necessary functions */
@@ -357,24 +379,24 @@ static int __devinit uli526x_init_one (struct pci_dev *pdev,
357 379
358 /* read 64 word srom data */ 380 /* read 64 word srom data */
359 for (i = 0; i < 64; i++) 381 for (i = 0; i < 64; i++)
360 ((__le16 *) db->srom)[i] = cpu_to_le16(read_srom_word(db->ioaddr, i)); 382 ((__le16 *) db->srom)[i] = cpu_to_le16(read_srom_word(db, i));
361 383
362 /* Set Node address */ 384 /* Set Node address */
363 if(((u16 *) db->srom)[0] == 0xffff || ((u16 *) db->srom)[0] == 0) /* SROM absent, so read MAC address from ID Table */ 385 if(((u16 *) db->srom)[0] == 0xffff || ((u16 *) db->srom)[0] == 0) /* SROM absent, so read MAC address from ID Table */
364 { 386 {
365 outl(0x10000, db->ioaddr + DCR0); //Diagnosis mode 387 uw32(DCR0, 0x10000); //Diagnosis mode
366 outl(0x1c0, db->ioaddr + DCR13); //Reset dianostic pointer port 388 uw32(DCR13, 0x1c0); //Reset dianostic pointer port
367 outl(0, db->ioaddr + DCR14); //Clear reset port 389 uw32(DCR14, 0); //Clear reset port
368 outl(0x10, db->ioaddr + DCR14); //Reset ID Table pointer 390 uw32(DCR14, 0x10); //Reset ID Table pointer
369 outl(0, db->ioaddr + DCR14); //Clear reset port 391 uw32(DCR14, 0); //Clear reset port
370 outl(0, db->ioaddr + DCR13); //Clear CR13 392 uw32(DCR13, 0); //Clear CR13
371 outl(0x1b0, db->ioaddr + DCR13); //Select ID Table access port 393 uw32(DCR13, 0x1b0); //Select ID Table access port
372 //Read MAC address from CR14 394 //Read MAC address from CR14
373 for (i = 0; i < 6; i++) 395 for (i = 0; i < 6; i++)
374 dev->dev_addr[i] = inl(db->ioaddr + DCR14); 396 dev->dev_addr[i] = ur32(DCR14);
375 //Read end 397 //Read end
376 outl(0, db->ioaddr + DCR13); //Clear CR13 398 uw32(DCR13, 0); //Clear CR13
377 outl(0, db->ioaddr + DCR0); //Clear CR0 399 uw32(DCR0, 0); //Clear CR0
378 udelay(10); 400 udelay(10);
379 } 401 }
380 else /*Exist SROM*/ 402 else /*Exist SROM*/
@@ -384,16 +406,18 @@ static int __devinit uli526x_init_one (struct pci_dev *pdev,
384 } 406 }
385 err = register_netdev (dev); 407 err = register_netdev (dev);
386 if (err) 408 if (err)
387 goto err_out_free_tx_buf; 409 goto err_out_unmap;
388 410
389 netdev_info(dev, "ULi M%04lx at pci%s, %pM, irq %d\n", 411 netdev_info(dev, "ULi M%04lx at pci%s, %pM, irq %d\n",
390 ent->driver_data >> 16, pci_name(pdev), 412 ent->driver_data >> 16, pci_name(pdev),
391 dev->dev_addr, dev->irq); 413 dev->dev_addr, pdev->irq);
392 414
393 pci_set_master(pdev); 415 pci_set_master(pdev);
394 416
395 return 0; 417 return 0;
396 418
419err_out_unmap:
420 pci_iounmap(pdev, db->ioaddr);
397err_out_free_tx_buf: 421err_out_free_tx_buf:
398 pci_free_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, 422 pci_free_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
399 db->buf_pool_ptr, db->buf_pool_dma_ptr); 423 db->buf_pool_ptr, db->buf_pool_dma_ptr);
@@ -418,6 +442,7 @@ static void __devexit uli526x_remove_one (struct pci_dev *pdev)
418 struct uli526x_board_info *db = netdev_priv(dev); 442 struct uli526x_board_info *db = netdev_priv(dev);
419 443
420 unregister_netdev(dev); 444 unregister_netdev(dev);
445 pci_iounmap(pdev, db->ioaddr);
421 pci_free_consistent(db->pdev, sizeof(struct tx_desc) * 446 pci_free_consistent(db->pdev, sizeof(struct tx_desc) *
422 DESC_ALL_CNT + 0x20, db->desc_pool_ptr, 447 DESC_ALL_CNT + 0x20, db->desc_pool_ptr,
423 db->desc_pool_dma_ptr); 448 db->desc_pool_dma_ptr);
@@ -460,7 +485,8 @@ static int uli526x_open(struct net_device *dev)
460 /* Initialize ULI526X board */ 485 /* Initialize ULI526X board */
461 uli526x_init(dev); 486 uli526x_init(dev);
462 487
463 ret = request_irq(dev->irq, uli526x_interrupt, IRQF_SHARED, dev->name, dev); 488 ret = request_irq(db->pdev->irq, uli526x_interrupt, IRQF_SHARED,
489 dev->name, dev);
464 if (ret) 490 if (ret)
465 return ret; 491 return ret;
466 492
@@ -488,57 +514,57 @@ static int uli526x_open(struct net_device *dev)
488static void uli526x_init(struct net_device *dev) 514static void uli526x_init(struct net_device *dev)
489{ 515{
490 struct uli526x_board_info *db = netdev_priv(dev); 516 struct uli526x_board_info *db = netdev_priv(dev);
491 unsigned long ioaddr = db->ioaddr; 517 struct uli_phy_ops *phy = &db->phy;
518 void __iomem *ioaddr = db->ioaddr;
492 u8 phy_tmp; 519 u8 phy_tmp;
493 u8 timeout; 520 u8 timeout;
494 u16 phy_value;
495 u16 phy_reg_reset; 521 u16 phy_reg_reset;
496 522
497 523
498 ULI526X_DBUG(0, "uli526x_init()", 0); 524 ULI526X_DBUG(0, "uli526x_init()", 0);
499 525
500 /* Reset M526x MAC controller */ 526 /* Reset M526x MAC controller */
501 outl(ULI526X_RESET, ioaddr + DCR0); /* RESET MAC */ 527 uw32(DCR0, ULI526X_RESET); /* RESET MAC */
502 udelay(100); 528 udelay(100);
503 outl(db->cr0_data, ioaddr + DCR0); 529 uw32(DCR0, db->cr0_data);
504 udelay(5); 530 udelay(5);
505 531
506 /* Phy addr : In some boards,M5261/M5263 phy address != 1 */ 532 /* Phy addr : In some boards,M5261/M5263 phy address != 1 */
507 db->phy_addr = 1; 533 db->phy_addr = 1;
508 for(phy_tmp=0;phy_tmp<32;phy_tmp++) 534 for (phy_tmp = 0; phy_tmp < 32; phy_tmp++) {
509 { 535 u16 phy_value;
510 phy_value=phy_read(db->ioaddr,phy_tmp,3,db->chip_id);//peer add 536
511 if(phy_value != 0xffff&&phy_value!=0) 537 phy_value = phy->read(db, phy_tmp, 3); //peer add
512 { 538 if (phy_value != 0xffff && phy_value != 0) {
513 db->phy_addr = phy_tmp; 539 db->phy_addr = phy_tmp;
514 break; 540 break;
515 } 541 }
516 } 542 }
517 if(phy_tmp == 32) 543
544 if (phy_tmp == 32)
518 pr_warn("Can not find the phy address!!!\n"); 545 pr_warn("Can not find the phy address!!!\n");
519 /* Parser SROM and media mode */ 546 /* Parser SROM and media mode */
520 db->media_mode = uli526x_media_mode; 547 db->media_mode = uli526x_media_mode;
521 548
522 /* phyxcer capability setting */ 549 /* phyxcer capability setting */
523 phy_reg_reset = phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id); 550 phy_reg_reset = phy->read(db, db->phy_addr, 0);
524 phy_reg_reset = (phy_reg_reset | 0x8000); 551 phy_reg_reset = (phy_reg_reset | 0x8000);
525 phy_write(db->ioaddr, db->phy_addr, 0, phy_reg_reset, db->chip_id); 552 phy->write(db, db->phy_addr, 0, phy_reg_reset);
526 553
527 /* See IEEE 802.3-2002.pdf (Section 2, Chapter "22.2.4 Management 554 /* See IEEE 802.3-2002.pdf (Section 2, Chapter "22.2.4 Management
528 * functions") or phy data sheet for details on phy reset 555 * functions") or phy data sheet for details on phy reset
529 */ 556 */
530 udelay(500); 557 udelay(500);
531 timeout = 10; 558 timeout = 10;
532 while (timeout-- && 559 while (timeout-- && phy->read(db, db->phy_addr, 0) & 0x8000)
533 phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000) 560 udelay(100);
534 udelay(100);
535 561
536 /* Process Phyxcer Media Mode */ 562 /* Process Phyxcer Media Mode */
537 uli526x_set_phyxcer(db); 563 uli526x_set_phyxcer(db);
538 564
539 /* Media Mode Process */ 565 /* Media Mode Process */
540 if ( !(db->media_mode & ULI526X_AUTO) ) 566 if ( !(db->media_mode & ULI526X_AUTO) )
541 db->op_mode = db->media_mode; /* Force Mode */ 567 db->op_mode = db->media_mode; /* Force Mode */
542 568
543 /* Initialize Transmit/Receive decriptor and CR3/4 */ 569 /* Initialize Transmit/Receive decriptor and CR3/4 */
544 uli526x_descriptor_init(dev, ioaddr); 570 uli526x_descriptor_init(dev, ioaddr);
@@ -551,10 +577,10 @@ static void uli526x_init(struct net_device *dev)
551 577
552 /* Init CR7, interrupt active bit */ 578 /* Init CR7, interrupt active bit */
553 db->cr7_data = CR7_DEFAULT; 579 db->cr7_data = CR7_DEFAULT;
554 outl(db->cr7_data, ioaddr + DCR7); 580 uw32(DCR7, db->cr7_data);
555 581
556 /* Init CR15, Tx jabber and Rx watchdog timer */ 582 /* Init CR15, Tx jabber and Rx watchdog timer */
557 outl(db->cr15_data, ioaddr + DCR15); 583 uw32(DCR15, db->cr15_data);
558 584
559 /* Enable ULI526X Tx/Rx function */ 585 /* Enable ULI526X Tx/Rx function */
560 db->cr6_data |= CR6_RXSC | CR6_TXSC; 586 db->cr6_data |= CR6_RXSC | CR6_TXSC;
@@ -571,6 +597,7 @@ static netdev_tx_t uli526x_start_xmit(struct sk_buff *skb,
571 struct net_device *dev) 597 struct net_device *dev)
572{ 598{
573 struct uli526x_board_info *db = netdev_priv(dev); 599 struct uli526x_board_info *db = netdev_priv(dev);
600 void __iomem *ioaddr = db->ioaddr;
574 struct tx_desc *txptr; 601 struct tx_desc *txptr;
575 unsigned long flags; 602 unsigned long flags;
576 603
@@ -596,7 +623,7 @@ static netdev_tx_t uli526x_start_xmit(struct sk_buff *skb,
596 } 623 }
597 624
598 /* Disable NIC interrupt */ 625 /* Disable NIC interrupt */
599 outl(0, dev->base_addr + DCR7); 626 uw32(DCR7, 0);
600 627
601 /* transmit this packet */ 628 /* transmit this packet */
602 txptr = db->tx_insert_ptr; 629 txptr = db->tx_insert_ptr;
@@ -607,10 +634,10 @@ static netdev_tx_t uli526x_start_xmit(struct sk_buff *skb,
607 db->tx_insert_ptr = txptr->next_tx_desc; 634 db->tx_insert_ptr = txptr->next_tx_desc;
608 635
609 /* Transmit Packet Process */ 636 /* Transmit Packet Process */
610 if ( (db->tx_packet_cnt < TX_DESC_CNT) ) { 637 if (db->tx_packet_cnt < TX_DESC_CNT) {
611 txptr->tdes0 = cpu_to_le32(0x80000000); /* Set owner bit */ 638 txptr->tdes0 = cpu_to_le32(0x80000000); /* Set owner bit */
612 db->tx_packet_cnt++; /* Ready to send */ 639 db->tx_packet_cnt++; /* Ready to send */
613 outl(0x1, dev->base_addr + DCR1); /* Issue Tx polling */ 640 uw32(DCR1, 0x1); /* Issue Tx polling */
614 dev->trans_start = jiffies; /* saved time stamp */ 641 dev->trans_start = jiffies; /* saved time stamp */
615 } 642 }
616 643
@@ -620,7 +647,7 @@ static netdev_tx_t uli526x_start_xmit(struct sk_buff *skb,
620 647
621 /* Restore CR7 to enable interrupt */ 648 /* Restore CR7 to enable interrupt */
622 spin_unlock_irqrestore(&db->lock, flags); 649 spin_unlock_irqrestore(&db->lock, flags);
623 outl(db->cr7_data, dev->base_addr + DCR7); 650 uw32(DCR7, db->cr7_data);
624 651
625 /* free this SKB */ 652 /* free this SKB */
626 dev_kfree_skb(skb); 653 dev_kfree_skb(skb);
@@ -637,9 +664,7 @@ static netdev_tx_t uli526x_start_xmit(struct sk_buff *skb,
637static int uli526x_stop(struct net_device *dev) 664static int uli526x_stop(struct net_device *dev)
638{ 665{
639 struct uli526x_board_info *db = netdev_priv(dev); 666 struct uli526x_board_info *db = netdev_priv(dev);
640 unsigned long ioaddr = dev->base_addr; 667 void __iomem *ioaddr = db->ioaddr;
641
642 ULI526X_DBUG(0, "uli526x_stop", 0);
643 668
644 /* disable system */ 669 /* disable system */
645 netif_stop_queue(dev); 670 netif_stop_queue(dev);
@@ -648,12 +673,12 @@ static int uli526x_stop(struct net_device *dev)
648 del_timer_sync(&db->timer); 673 del_timer_sync(&db->timer);
649 674
650 /* Reset & stop ULI526X board */ 675 /* Reset & stop ULI526X board */
651 outl(ULI526X_RESET, ioaddr + DCR0); 676 uw32(DCR0, ULI526X_RESET);
652 udelay(5); 677 udelay(5);
653 phy_write(db->ioaddr, db->phy_addr, 0, 0x8000, db->chip_id); 678 db->phy.write(db, db->phy_addr, 0, 0x8000);
654 679
655 /* free interrupt */ 680 /* free interrupt */
656 free_irq(dev->irq, dev); 681 free_irq(db->pdev->irq, dev);
657 682
658 /* free allocated rx buffer */ 683 /* free allocated rx buffer */
659 uli526x_free_rxbuffer(db); 684 uli526x_free_rxbuffer(db);
@@ -671,18 +696,18 @@ static irqreturn_t uli526x_interrupt(int irq, void *dev_id)
671{ 696{
672 struct net_device *dev = dev_id; 697 struct net_device *dev = dev_id;
673 struct uli526x_board_info *db = netdev_priv(dev); 698 struct uli526x_board_info *db = netdev_priv(dev);
674 unsigned long ioaddr = dev->base_addr; 699 void __iomem *ioaddr = db->ioaddr;
675 unsigned long flags; 700 unsigned long flags;
676 701
677 spin_lock_irqsave(&db->lock, flags); 702 spin_lock_irqsave(&db->lock, flags);
678 outl(0, ioaddr + DCR7); 703 uw32(DCR7, 0);
679 704
680 /* Got ULI526X status */ 705 /* Got ULI526X status */
681 db->cr5_data = inl(ioaddr + DCR5); 706 db->cr5_data = ur32(DCR5);
682 outl(db->cr5_data, ioaddr + DCR5); 707 uw32(DCR5, db->cr5_data);
683 if ( !(db->cr5_data & 0x180c1) ) { 708 if ( !(db->cr5_data & 0x180c1) ) {
684 /* Restore CR7 to enable interrupt mask */ 709 /* Restore CR7 to enable interrupt mask */
685 outl(db->cr7_data, ioaddr + DCR7); 710 uw32(DCR7, db->cr7_data);
686 spin_unlock_irqrestore(&db->lock, flags); 711 spin_unlock_irqrestore(&db->lock, flags);
687 return IRQ_HANDLED; 712 return IRQ_HANDLED;
688 } 713 }
@@ -710,7 +735,7 @@ static irqreturn_t uli526x_interrupt(int irq, void *dev_id)
710 uli526x_free_tx_pkt(dev, db); 735 uli526x_free_tx_pkt(dev, db);
711 736
712 /* Restore CR7 to enable interrupt mask */ 737 /* Restore CR7 to enable interrupt mask */
713 outl(db->cr7_data, ioaddr + DCR7); 738 uw32(DCR7, db->cr7_data);
714 739
715 spin_unlock_irqrestore(&db->lock, flags); 740 spin_unlock_irqrestore(&db->lock, flags);
716 return IRQ_HANDLED; 741 return IRQ_HANDLED;
@@ -719,8 +744,10 @@ static irqreturn_t uli526x_interrupt(int irq, void *dev_id)
719#ifdef CONFIG_NET_POLL_CONTROLLER 744#ifdef CONFIG_NET_POLL_CONTROLLER
720static void uli526x_poll(struct net_device *dev) 745static void uli526x_poll(struct net_device *dev)
721{ 746{
747 struct uli526x_board_info *db = netdev_priv(dev);
748
722 /* ISR grabs the irqsave lock, so this should be safe */ 749 /* ISR grabs the irqsave lock, so this should be safe */
723 uli526x_interrupt(dev->irq, dev); 750 uli526x_interrupt(db->pdev->irq, dev);
724} 751}
725#endif 752#endif
726 753
@@ -954,12 +981,7 @@ static void netdev_get_drvinfo(struct net_device *dev,
954 981
955 strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); 982 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
956 strlcpy(info->version, DRV_VERSION, sizeof(info->version)); 983 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
957 if (np->pdev) 984 strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
958 strlcpy(info->bus_info, pci_name(np->pdev),
959 sizeof(info->bus_info));
960 else
961 sprintf(info->bus_info, "EISA 0x%lx %d",
962 dev->base_addr, dev->irq);
963} 985}
964 986
965static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) { 987static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) {
@@ -999,18 +1021,20 @@ static const struct ethtool_ops netdev_ethtool_ops = {
999 1021
1000static void uli526x_timer(unsigned long data) 1022static void uli526x_timer(unsigned long data)
1001{ 1023{
1002 u32 tmp_cr8;
1003 unsigned char tmp_cr12=0;
1004 struct net_device *dev = (struct net_device *) data; 1024 struct net_device *dev = (struct net_device *) data;
1005 struct uli526x_board_info *db = netdev_priv(dev); 1025 struct uli526x_board_info *db = netdev_priv(dev);
1026 struct uli_phy_ops *phy = &db->phy;
1027 void __iomem *ioaddr = db->ioaddr;
1006 unsigned long flags; 1028 unsigned long flags;
1029 u8 tmp_cr12 = 0;
1030 u32 tmp_cr8;
1007 1031
1008 //ULI526X_DBUG(0, "uli526x_timer()", 0); 1032 //ULI526X_DBUG(0, "uli526x_timer()", 0);
1009 spin_lock_irqsave(&db->lock, flags); 1033 spin_lock_irqsave(&db->lock, flags);
1010 1034
1011 1035
1012 /* Dynamic reset ULI526X : system error or transmit time-out */ 1036 /* Dynamic reset ULI526X : system error or transmit time-out */
1013 tmp_cr8 = inl(db->ioaddr + DCR8); 1037 tmp_cr8 = ur32(DCR8);
1014 if ( (db->interval_rx_cnt==0) && (tmp_cr8) ) { 1038 if ( (db->interval_rx_cnt==0) && (tmp_cr8) ) {
1015 db->reset_cr8++; 1039 db->reset_cr8++;
1016 db->wait_reset = 1; 1040 db->wait_reset = 1;
@@ -1020,7 +1044,7 @@ static void uli526x_timer(unsigned long data)
1020 /* TX polling kick monitor */ 1044 /* TX polling kick monitor */
1021 if ( db->tx_packet_cnt && 1045 if ( db->tx_packet_cnt &&
1022 time_after(jiffies, dev_trans_start(dev) + ULI526X_TX_KICK) ) { 1046 time_after(jiffies, dev_trans_start(dev) + ULI526X_TX_KICK) ) {
1023 outl(0x1, dev->base_addr + DCR1); // Tx polling again 1047 uw32(DCR1, 0x1); // Tx polling again
1024 1048
1025 // TX Timeout 1049 // TX Timeout
1026 if ( time_after(jiffies, dev_trans_start(dev) + ULI526X_TX_TIMEOUT) ) { 1050 if ( time_after(jiffies, dev_trans_start(dev) + ULI526X_TX_TIMEOUT) ) {
@@ -1041,7 +1065,7 @@ static void uli526x_timer(unsigned long data)
1041 } 1065 }
1042 1066
1043 /* Link status check, Dynamic media type change */ 1067 /* Link status check, Dynamic media type change */
1044 if((phy_read(db->ioaddr, db->phy_addr, 5, db->chip_id) & 0x01e0)!=0) 1068 if ((phy->read(db, db->phy_addr, 5) & 0x01e0)!=0)
1045 tmp_cr12 = 3; 1069 tmp_cr12 = 3;
1046 1070
1047 if ( !(tmp_cr12 & 0x3) && !db->link_failed ) { 1071 if ( !(tmp_cr12 & 0x3) && !db->link_failed ) {
@@ -1054,7 +1078,7 @@ static void uli526x_timer(unsigned long data)
1054 /* For Force 10/100M Half/Full mode: Enable Auto-Nego mode */ 1078 /* For Force 10/100M Half/Full mode: Enable Auto-Nego mode */
1055 /* AUTO don't need */ 1079 /* AUTO don't need */
1056 if ( !(db->media_mode & 0x8) ) 1080 if ( !(db->media_mode & 0x8) )
1057 phy_write(db->ioaddr, db->phy_addr, 0, 0x1000, db->chip_id); 1081 phy->write(db, db->phy_addr, 0, 0x1000);
1058 1082
1059 /* AUTO mode, if INT phyxcer link failed, select EXT device */ 1083 /* AUTO mode, if INT phyxcer link failed, select EXT device */
1060 if (db->media_mode & ULI526X_AUTO) { 1084 if (db->media_mode & ULI526X_AUTO) {
@@ -1111,12 +1135,13 @@ static void uli526x_timer(unsigned long data)
1111static void uli526x_reset_prepare(struct net_device *dev) 1135static void uli526x_reset_prepare(struct net_device *dev)
1112{ 1136{
1113 struct uli526x_board_info *db = netdev_priv(dev); 1137 struct uli526x_board_info *db = netdev_priv(dev);
1138 void __iomem *ioaddr = db->ioaddr;
1114 1139
1115 /* Sopt MAC controller */ 1140 /* Sopt MAC controller */
1116 db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */ 1141 db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
1117 update_cr6(db->cr6_data, dev->base_addr); 1142 update_cr6(db->cr6_data, ioaddr);
1118 outl(0, dev->base_addr + DCR7); /* Disable Interrupt */ 1143 uw32(DCR7, 0); /* Disable Interrupt */
1119 outl(inl(dev->base_addr + DCR5), dev->base_addr + DCR5); 1144 uw32(DCR5, ur32(DCR5));
1120 1145
1121 /* Disable upper layer interface */ 1146 /* Disable upper layer interface */
1122 netif_stop_queue(dev); 1147 netif_stop_queue(dev);
@@ -1281,7 +1306,7 @@ static void uli526x_reuse_skb(struct uli526x_board_info *db, struct sk_buff * sk
1281 * Using Chain structure, and allocate Tx/Rx buffer 1306 * Using Chain structure, and allocate Tx/Rx buffer
1282 */ 1307 */
1283 1308
1284static void uli526x_descriptor_init(struct net_device *dev, unsigned long ioaddr) 1309static void uli526x_descriptor_init(struct net_device *dev, void __iomem *ioaddr)
1285{ 1310{
1286 struct uli526x_board_info *db = netdev_priv(dev); 1311 struct uli526x_board_info *db = netdev_priv(dev);
1287 struct tx_desc *tmp_tx; 1312 struct tx_desc *tmp_tx;
@@ -1296,14 +1321,14 @@ static void uli526x_descriptor_init(struct net_device *dev, unsigned long ioaddr
1296 /* tx descriptor start pointer */ 1321 /* tx descriptor start pointer */
1297 db->tx_insert_ptr = db->first_tx_desc; 1322 db->tx_insert_ptr = db->first_tx_desc;
1298 db->tx_remove_ptr = db->first_tx_desc; 1323 db->tx_remove_ptr = db->first_tx_desc;
1299 outl(db->first_tx_desc_dma, ioaddr + DCR4); /* TX DESC address */ 1324 uw32(DCR4, db->first_tx_desc_dma); /* TX DESC address */
1300 1325
1301 /* rx descriptor start pointer */ 1326 /* rx descriptor start pointer */
1302 db->first_rx_desc = (void *)db->first_tx_desc + sizeof(struct tx_desc) * TX_DESC_CNT; 1327 db->first_rx_desc = (void *)db->first_tx_desc + sizeof(struct tx_desc) * TX_DESC_CNT;
1303 db->first_rx_desc_dma = db->first_tx_desc_dma + sizeof(struct tx_desc) * TX_DESC_CNT; 1328 db->first_rx_desc_dma = db->first_tx_desc_dma + sizeof(struct tx_desc) * TX_DESC_CNT;
1304 db->rx_insert_ptr = db->first_rx_desc; 1329 db->rx_insert_ptr = db->first_rx_desc;
1305 db->rx_ready_ptr = db->first_rx_desc; 1330 db->rx_ready_ptr = db->first_rx_desc;
1306 outl(db->first_rx_desc_dma, ioaddr + DCR3); /* RX DESC address */ 1331 uw32(DCR3, db->first_rx_desc_dma); /* RX DESC address */
1307 1332
1308 /* Init Transmit chain */ 1333 /* Init Transmit chain */
1309 tmp_buf = db->buf_pool_start; 1334 tmp_buf = db->buf_pool_start;
@@ -1344,11 +1369,9 @@ static void uli526x_descriptor_init(struct net_device *dev, unsigned long ioaddr
1344 * Update CR6 value 1369 * Update CR6 value
1345 * Firstly stop ULI526X, then written value and start 1370 * Firstly stop ULI526X, then written value and start
1346 */ 1371 */
1347 1372static void update_cr6(u32 cr6_data, void __iomem *ioaddr)
1348static void update_cr6(u32 cr6_data, unsigned long ioaddr)
1349{ 1373{
1350 1374 uw32(DCR6, cr6_data);
1351 outl(cr6_data, ioaddr + DCR6);
1352 udelay(5); 1375 udelay(5);
1353} 1376}
1354 1377
@@ -1367,6 +1390,7 @@ static void update_cr6(u32 cr6_data, unsigned long ioaddr)
1367static void send_filter_frame(struct net_device *dev, int mc_cnt) 1390static void send_filter_frame(struct net_device *dev, int mc_cnt)
1368{ 1391{
1369 struct uli526x_board_info *db = netdev_priv(dev); 1392 struct uli526x_board_info *db = netdev_priv(dev);
1393 void __iomem *ioaddr = db->ioaddr;
1370 struct netdev_hw_addr *ha; 1394 struct netdev_hw_addr *ha;
1371 struct tx_desc *txptr; 1395 struct tx_desc *txptr;
1372 u16 * addrptr; 1396 u16 * addrptr;
@@ -1412,9 +1436,9 @@ static void send_filter_frame(struct net_device *dev, int mc_cnt)
1412 /* Resource Empty */ 1436 /* Resource Empty */
1413 db->tx_packet_cnt++; 1437 db->tx_packet_cnt++;
1414 txptr->tdes0 = cpu_to_le32(0x80000000); 1438 txptr->tdes0 = cpu_to_le32(0x80000000);
1415 update_cr6(db->cr6_data | 0x2000, dev->base_addr); 1439 update_cr6(db->cr6_data | 0x2000, ioaddr);
1416 outl(0x1, dev->base_addr + DCR1); /* Issue Tx polling */ 1440 uw32(DCR1, 0x1); /* Issue Tx polling */
1417 update_cr6(db->cr6_data, dev->base_addr); 1441 update_cr6(db->cr6_data, ioaddr);
1418 dev->trans_start = jiffies; 1442 dev->trans_start = jiffies;
1419 } else 1443 } else
1420 netdev_err(dev, "No Tx resource - Send_filter_frame!\n"); 1444 netdev_err(dev, "No Tx resource - Send_filter_frame!\n");
@@ -1457,37 +1481,38 @@ static void allocate_rx_buffer(struct net_device *dev)
1457 * Read one word data from the serial ROM 1481 * Read one word data from the serial ROM
1458 */ 1482 */
1459 1483
1460static u16 read_srom_word(long ioaddr, int offset) 1484static u16 read_srom_word(struct uli526x_board_info *db, int offset)
1461{ 1485{
1462 int i; 1486 void __iomem *ioaddr = db->ioaddr;
1463 u16 srom_data = 0; 1487 u16 srom_data = 0;
1464 long cr9_ioaddr = ioaddr + DCR9; 1488 int i;
1465 1489
1466 outl(CR9_SROM_READ, cr9_ioaddr); 1490 uw32(DCR9, CR9_SROM_READ);
1467 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr); 1491 uw32(DCR9, CR9_SROM_READ | CR9_SRCS);
1468 1492
1469 /* Send the Read Command 110b */ 1493 /* Send the Read Command 110b */
1470 SROM_CLK_WRITE(SROM_DATA_1, cr9_ioaddr); 1494 srom_clk_write(db, SROM_DATA_1);
1471 SROM_CLK_WRITE(SROM_DATA_1, cr9_ioaddr); 1495 srom_clk_write(db, SROM_DATA_1);
1472 SROM_CLK_WRITE(SROM_DATA_0, cr9_ioaddr); 1496 srom_clk_write(db, SROM_DATA_0);
1473 1497
1474 /* Send the offset */ 1498 /* Send the offset */
1475 for (i = 5; i >= 0; i--) { 1499 for (i = 5; i >= 0; i--) {
1476 srom_data = (offset & (1 << i)) ? SROM_DATA_1 : SROM_DATA_0; 1500 srom_data = (offset & (1 << i)) ? SROM_DATA_1 : SROM_DATA_0;
1477 SROM_CLK_WRITE(srom_data, cr9_ioaddr); 1501 srom_clk_write(db, srom_data);
1478 } 1502 }
1479 1503
1480 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr); 1504 uw32(DCR9, CR9_SROM_READ | CR9_SRCS);
1481 1505
1482 for (i = 16; i > 0; i--) { 1506 for (i = 16; i > 0; i--) {
1483 outl(CR9_SROM_READ | CR9_SRCS | CR9_SRCLK, cr9_ioaddr); 1507 uw32(DCR9, CR9_SROM_READ | CR9_SRCS | CR9_SRCLK);
1484 udelay(5); 1508 udelay(5);
1485 srom_data = (srom_data << 1) | ((inl(cr9_ioaddr) & CR9_CRDOUT) ? 1 : 0); 1509 srom_data = (srom_data << 1) |
1486 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr); 1510 ((ur32(DCR9) & CR9_CRDOUT) ? 1 : 0);
1511 uw32(DCR9, CR9_SROM_READ | CR9_SRCS);
1487 udelay(5); 1512 udelay(5);
1488 } 1513 }
1489 1514
1490 outl(CR9_SROM_READ, cr9_ioaddr); 1515 uw32(DCR9, CR9_SROM_READ);
1491 return srom_data; 1516 return srom_data;
1492} 1517}
1493 1518
@@ -1498,15 +1523,16 @@ static u16 read_srom_word(long ioaddr, int offset)
1498 1523
1499static u8 uli526x_sense_speed(struct uli526x_board_info * db) 1524static u8 uli526x_sense_speed(struct uli526x_board_info * db)
1500{ 1525{
1526 struct uli_phy_ops *phy = &db->phy;
1501 u8 ErrFlag = 0; 1527 u8 ErrFlag = 0;
1502 u16 phy_mode; 1528 u16 phy_mode;
1503 1529
1504 phy_mode = phy_read(db->ioaddr, db->phy_addr, 1, db->chip_id); 1530 phy_mode = phy->read(db, db->phy_addr, 1);
1505 phy_mode = phy_read(db->ioaddr, db->phy_addr, 1, db->chip_id); 1531 phy_mode = phy->read(db, db->phy_addr, 1);
1506 1532
1507 if ( (phy_mode & 0x24) == 0x24 ) { 1533 if ( (phy_mode & 0x24) == 0x24 ) {
1508 1534
1509 phy_mode = ((phy_read(db->ioaddr, db->phy_addr, 5, db->chip_id) & 0x01e0)<<7); 1535 phy_mode = ((phy->read(db, db->phy_addr, 5) & 0x01e0)<<7);
1510 if(phy_mode&0x8000) 1536 if(phy_mode&0x8000)
1511 phy_mode = 0x8000; 1537 phy_mode = 0x8000;
1512 else if(phy_mode&0x4000) 1538 else if(phy_mode&0x4000)
@@ -1541,10 +1567,11 @@ static u8 uli526x_sense_speed(struct uli526x_board_info * db)
1541 1567
1542static void uli526x_set_phyxcer(struct uli526x_board_info *db) 1568static void uli526x_set_phyxcer(struct uli526x_board_info *db)
1543{ 1569{
1570 struct uli_phy_ops *phy = &db->phy;
1544 u16 phy_reg; 1571 u16 phy_reg;
1545 1572
1546 /* Phyxcer capability setting */ 1573 /* Phyxcer capability setting */
1547 phy_reg = phy_read(db->ioaddr, db->phy_addr, 4, db->chip_id) & ~0x01e0; 1574 phy_reg = phy->read(db, db->phy_addr, 4) & ~0x01e0;
1548 1575
1549 if (db->media_mode & ULI526X_AUTO) { 1576 if (db->media_mode & ULI526X_AUTO) {
1550 /* AUTO Mode */ 1577 /* AUTO Mode */
@@ -1565,10 +1592,10 @@ static void uli526x_set_phyxcer(struct uli526x_board_info *db)
1565 phy_reg|=db->PHY_reg4; 1592 phy_reg|=db->PHY_reg4;
1566 db->media_mode|=ULI526X_AUTO; 1593 db->media_mode|=ULI526X_AUTO;
1567 } 1594 }
1568 phy_write(db->ioaddr, db->phy_addr, 4, phy_reg, db->chip_id); 1595 phy->write(db, db->phy_addr, 4, phy_reg);
1569 1596
1570 /* Restart Auto-Negotiation */ 1597 /* Restart Auto-Negotiation */
1571 phy_write(db->ioaddr, db->phy_addr, 0, 0x1200, db->chip_id); 1598 phy->write(db, db->phy_addr, 0, 0x1200);
1572 udelay(50); 1599 udelay(50);
1573} 1600}
1574 1601
@@ -1582,6 +1609,7 @@ static void uli526x_set_phyxcer(struct uli526x_board_info *db)
1582 1609
1583static void uli526x_process_mode(struct uli526x_board_info *db) 1610static void uli526x_process_mode(struct uli526x_board_info *db)
1584{ 1611{
1612 struct uli_phy_ops *phy = &db->phy;
1585 u16 phy_reg; 1613 u16 phy_reg;
1586 1614
1587 /* Full Duplex Mode Check */ 1615 /* Full Duplex Mode Check */
@@ -1593,10 +1621,10 @@ static void uli526x_process_mode(struct uli526x_board_info *db)
1593 update_cr6(db->cr6_data, db->ioaddr); 1621 update_cr6(db->cr6_data, db->ioaddr);
1594 1622
1595 /* 10/100M phyxcer force mode need */ 1623 /* 10/100M phyxcer force mode need */
1596 if ( !(db->media_mode & 0x8)) { 1624 if (!(db->media_mode & 0x8)) {
1597 /* Forece Mode */ 1625 /* Forece Mode */
1598 phy_reg = phy_read(db->ioaddr, db->phy_addr, 6, db->chip_id); 1626 phy_reg = phy->read(db, db->phy_addr, 6);
1599 if ( !(phy_reg & 0x1) ) { 1627 if (!(phy_reg & 0x1)) {
1600 /* parter without N-Way capability */ 1628 /* parter without N-Way capability */
1601 phy_reg = 0x0; 1629 phy_reg = 0x0;
1602 switch(db->op_mode) { 1630 switch(db->op_mode) {
@@ -1605,148 +1633,126 @@ static void uli526x_process_mode(struct uli526x_board_info *db)
1605 case ULI526X_100MHF: phy_reg = 0x2000; break; 1633 case ULI526X_100MHF: phy_reg = 0x2000; break;
1606 case ULI526X_100MFD: phy_reg = 0x2100; break; 1634 case ULI526X_100MFD: phy_reg = 0x2100; break;
1607 } 1635 }
1608 phy_write(db->ioaddr, db->phy_addr, 0, phy_reg, db->chip_id); 1636 phy->write(db, db->phy_addr, 0, phy_reg);
1609 } 1637 }
1610 } 1638 }
1611} 1639}
1612 1640
1613 1641
1614/* 1642/* M5261/M5263 Chip */
1615 * Write a word to Phy register 1643static void phy_writeby_cr9(struct uli526x_board_info *db, u8 phy_addr,
1616 */ 1644 u8 offset, u16 phy_data)
1617
1618static void phy_write(unsigned long iobase, u8 phy_addr, u8 offset, u16 phy_data, u32 chip_id)
1619{ 1645{
1620 u16 i; 1646 u16 i;
1621 unsigned long ioaddr;
1622
1623 if(chip_id == PCI_ULI5263_ID)
1624 {
1625 phy_writeby_cr10(iobase, phy_addr, offset, phy_data);
1626 return;
1627 }
1628 /* M5261/M5263 Chip */
1629 ioaddr = iobase + DCR9;
1630 1647
1631 /* Send 33 synchronization clock to Phy controller */ 1648 /* Send 33 synchronization clock to Phy controller */
1632 for (i = 0; i < 35; i++) 1649 for (i = 0; i < 35; i++)
1633 phy_write_1bit(ioaddr, PHY_DATA_1, chip_id); 1650 phy_write_1bit(db, PHY_DATA_1);
1634 1651
1635 /* Send start command(01) to Phy */ 1652 /* Send start command(01) to Phy */
1636 phy_write_1bit(ioaddr, PHY_DATA_0, chip_id); 1653 phy_write_1bit(db, PHY_DATA_0);
1637 phy_write_1bit(ioaddr, PHY_DATA_1, chip_id); 1654 phy_write_1bit(db, PHY_DATA_1);
1638 1655
1639 /* Send write command(01) to Phy */ 1656 /* Send write command(01) to Phy */
1640 phy_write_1bit(ioaddr, PHY_DATA_0, chip_id); 1657 phy_write_1bit(db, PHY_DATA_0);
1641 phy_write_1bit(ioaddr, PHY_DATA_1, chip_id); 1658 phy_write_1bit(db, PHY_DATA_1);
1642 1659
1643 /* Send Phy address */ 1660 /* Send Phy address */
1644 for (i = 0x10; i > 0; i = i >> 1) 1661 for (i = 0x10; i > 0; i = i >> 1)
1645 phy_write_1bit(ioaddr, phy_addr & i ? PHY_DATA_1 : PHY_DATA_0, chip_id); 1662 phy_write_1bit(db, phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
1646 1663
1647 /* Send register address */ 1664 /* Send register address */
1648 for (i = 0x10; i > 0; i = i >> 1) 1665 for (i = 0x10; i > 0; i = i >> 1)
1649 phy_write_1bit(ioaddr, offset & i ? PHY_DATA_1 : PHY_DATA_0, chip_id); 1666 phy_write_1bit(db, offset & i ? PHY_DATA_1 : PHY_DATA_0);
1650 1667
1651 /* written trasnition */ 1668 /* written trasnition */
1652 phy_write_1bit(ioaddr, PHY_DATA_1, chip_id); 1669 phy_write_1bit(db, PHY_DATA_1);
1653 phy_write_1bit(ioaddr, PHY_DATA_0, chip_id); 1670 phy_write_1bit(db, PHY_DATA_0);
1654 1671
1655 /* Write a word data to PHY controller */ 1672 /* Write a word data to PHY controller */
1656 for ( i = 0x8000; i > 0; i >>= 1) 1673 for (i = 0x8000; i > 0; i >>= 1)
1657 phy_write_1bit(ioaddr, phy_data & i ? PHY_DATA_1 : PHY_DATA_0, chip_id); 1674 phy_write_1bit(db, phy_data & i ? PHY_DATA_1 : PHY_DATA_0);
1658
1659} 1675}
1660 1676
1661 1677static u16 phy_readby_cr9(struct uli526x_board_info *db, u8 phy_addr, u8 offset)
1662/*
1663 * Read a word data from phy register
1664 */
1665
1666static u16 phy_read(unsigned long iobase, u8 phy_addr, u8 offset, u32 chip_id)
1667{ 1678{
1668 int i;
1669 u16 phy_data; 1679 u16 phy_data;
1670 unsigned long ioaddr; 1680 int i;
1671
1672 if(chip_id == PCI_ULI5263_ID)
1673 return phy_readby_cr10(iobase, phy_addr, offset);
1674 /* M5261/M5263 Chip */
1675 ioaddr = iobase + DCR9;
1676 1681
1677 /* Send 33 synchronization clock to Phy controller */ 1682 /* Send 33 synchronization clock to Phy controller */
1678 for (i = 0; i < 35; i++) 1683 for (i = 0; i < 35; i++)
1679 phy_write_1bit(ioaddr, PHY_DATA_1, chip_id); 1684 phy_write_1bit(db, PHY_DATA_1);
1680 1685
1681 /* Send start command(01) to Phy */ 1686 /* Send start command(01) to Phy */
1682 phy_write_1bit(ioaddr, PHY_DATA_0, chip_id); 1687 phy_write_1bit(db, PHY_DATA_0);
1683 phy_write_1bit(ioaddr, PHY_DATA_1, chip_id); 1688 phy_write_1bit(db, PHY_DATA_1);
1684 1689
1685 /* Send read command(10) to Phy */ 1690 /* Send read command(10) to Phy */
1686 phy_write_1bit(ioaddr, PHY_DATA_1, chip_id); 1691 phy_write_1bit(db, PHY_DATA_1);
1687 phy_write_1bit(ioaddr, PHY_DATA_0, chip_id); 1692 phy_write_1bit(db, PHY_DATA_0);
1688 1693
1689 /* Send Phy address */ 1694 /* Send Phy address */
1690 for (i = 0x10; i > 0; i = i >> 1) 1695 for (i = 0x10; i > 0; i = i >> 1)
1691 phy_write_1bit(ioaddr, phy_addr & i ? PHY_DATA_1 : PHY_DATA_0, chip_id); 1696 phy_write_1bit(db, phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
1692 1697
1693 /* Send register address */ 1698 /* Send register address */
1694 for (i = 0x10; i > 0; i = i >> 1) 1699 for (i = 0x10; i > 0; i = i >> 1)
1695 phy_write_1bit(ioaddr, offset & i ? PHY_DATA_1 : PHY_DATA_0, chip_id); 1700 phy_write_1bit(db, offset & i ? PHY_DATA_1 : PHY_DATA_0);
1696 1701
1697 /* Skip transition state */ 1702 /* Skip transition state */
1698 phy_read_1bit(ioaddr, chip_id); 1703 phy_read_1bit(db);
1699 1704
1700 /* read 16bit data */ 1705 /* read 16bit data */
1701 for (phy_data = 0, i = 0; i < 16; i++) { 1706 for (phy_data = 0, i = 0; i < 16; i++) {
1702 phy_data <<= 1; 1707 phy_data <<= 1;
1703 phy_data |= phy_read_1bit(ioaddr, chip_id); 1708 phy_data |= phy_read_1bit(db);
1704 } 1709 }
1705 1710
1706 return phy_data; 1711 return phy_data;
1707} 1712}
1708 1713
1709static u16 phy_readby_cr10(unsigned long iobase, u8 phy_addr, u8 offset) 1714static u16 phy_readby_cr10(struct uli526x_board_info *db, u8 phy_addr,
1715 u8 offset)
1710{ 1716{
1711 unsigned long ioaddr,cr10_value; 1717 void __iomem *ioaddr = db->ioaddr;
1718 u32 cr10_value = phy_addr;
1712 1719
1713 ioaddr = iobase + DCR10; 1720 cr10_value = (cr10_value << 5) + offset;
1714 cr10_value = phy_addr; 1721 cr10_value = (cr10_value << 16) + 0x08000000;
1715 cr10_value = (cr10_value<<5) + offset; 1722 uw32(DCR10, cr10_value);
1716 cr10_value = (cr10_value<<16) + 0x08000000;
1717 outl(cr10_value,ioaddr);
1718 udelay(1); 1723 udelay(1);
1719 while(1) 1724 while (1) {
1720 { 1725 cr10_value = ur32(DCR10);
1721 cr10_value = inl(ioaddr); 1726 if (cr10_value & 0x10000000)
1722 if(cr10_value&0x10000000)
1723 break; 1727 break;
1724 } 1728 }
1725 return cr10_value & 0x0ffff; 1729 return cr10_value & 0x0ffff;
1726} 1730}
1727 1731
1728static void phy_writeby_cr10(unsigned long iobase, u8 phy_addr, u8 offset, u16 phy_data) 1732static void phy_writeby_cr10(struct uli526x_board_info *db, u8 phy_addr,
1733 u8 offset, u16 phy_data)
1729{ 1734{
1730 unsigned long ioaddr,cr10_value; 1735 void __iomem *ioaddr = db->ioaddr;
1736 u32 cr10_value = phy_addr;
1731 1737
1732 ioaddr = iobase + DCR10; 1738 cr10_value = (cr10_value << 5) + offset;
1733 cr10_value = phy_addr; 1739 cr10_value = (cr10_value << 16) + 0x04000000 + phy_data;
1734 cr10_value = (cr10_value<<5) + offset; 1740 uw32(DCR10, cr10_value);
1735 cr10_value = (cr10_value<<16) + 0x04000000 + phy_data;
1736 outl(cr10_value,ioaddr);
1737 udelay(1); 1741 udelay(1);
1738} 1742}
1739/* 1743/*
1740 * Write one bit data to Phy Controller 1744 * Write one bit data to Phy Controller
1741 */ 1745 */
1742 1746
1743static void phy_write_1bit(unsigned long ioaddr, u32 phy_data, u32 chip_id) 1747static void phy_write_1bit(struct uli526x_board_info *db, u32 data)
1744{ 1748{
1745 outl(phy_data , ioaddr); /* MII Clock Low */ 1749 void __iomem *ioaddr = db->ioaddr;
1750
1751 uw32(DCR9, data); /* MII Clock Low */
1746 udelay(1); 1752 udelay(1);
1747 outl(phy_data | MDCLKH, ioaddr); /* MII Clock High */ 1753 uw32(DCR9, data | MDCLKH); /* MII Clock High */
1748 udelay(1); 1754 udelay(1);
1749 outl(phy_data , ioaddr); /* MII Clock Low */ 1755 uw32(DCR9, data); /* MII Clock Low */
1750 udelay(1); 1756 udelay(1);
1751} 1757}
1752 1758
@@ -1755,14 +1761,15 @@ static void phy_write_1bit(unsigned long ioaddr, u32 phy_data, u32 chip_id)
1755 * Read one bit phy data from PHY controller 1761 * Read one bit phy data from PHY controller
1756 */ 1762 */
1757 1763
1758static u16 phy_read_1bit(unsigned long ioaddr, u32 chip_id) 1764static u16 phy_read_1bit(struct uli526x_board_info *db)
1759{ 1765{
1766 void __iomem *ioaddr = db->ioaddr;
1760 u16 phy_data; 1767 u16 phy_data;
1761 1768
1762 outl(0x50000 , ioaddr); 1769 uw32(DCR9, 0x50000);
1763 udelay(1); 1770 udelay(1);
1764 phy_data = ( inl(ioaddr) >> 19 ) & 0x1; 1771 phy_data = (ur32(DCR9) >> 19) & 0x1;
1765 outl(0x40000 , ioaddr); 1772 uw32(DCR9, 0x40000);
1766 udelay(1); 1773 udelay(1);
1767 1774
1768 return phy_data; 1775 return phy_data;