aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDhananjay Phadke <dhananjay@netxen.com>2008-08-08 03:08:39 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-08-14 04:43:05 -0400
commit9dc28efeee98a4f81d5469d3576f55c5e6d1a5db (patch)
treea2b856eceadcd954fd8a8fad699143e848a44b29
parent8d792cd990938c4d06b86141465ff8d52a946a0a (diff)
netxen: fix mac addr setup
For NX3031 mac addr should be read from firmware. mac addr in flash is still valid, but can be overridden by firmware if running in virtualization environment. For old revisions, mac addr is retrieved directly from flash. Signed-off-by: Dhananjay Phadke <dhananjay@netxen.com> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
-rw-r--r--drivers/net/netxen/netxen_nic.h3
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c51
-rw-r--r--drivers/net/netxen/netxen_nic_main.c65
-rw-r--r--drivers/net/netxen/netxen_nic_phan_reg.h2
4 files changed, 83 insertions, 38 deletions
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index 93a7b9b668d5..2cf6e41291e6 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -1615,7 +1615,8 @@ dma_watchdog_wakeup(struct netxen_adapter *adapter)
1615 1615
1616 1616
1617int netxen_is_flash_supported(struct netxen_adapter *adapter); 1617int netxen_is_flash_supported(struct netxen_adapter *adapter);
1618int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 mac[]); 1618int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac);
1619int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac);
1619extern void netxen_change_ringparam(struct netxen_adapter *adapter); 1620extern void netxen_change_ringparam(struct netxen_adapter *adapter);
1620extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, 1621extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr,
1621 int *valp); 1622 int *valp);
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index 9aa20f961618..f5db48bcd266 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -733,31 +733,56 @@ static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
733 return 0; 733 return 0;
734} 734}
735 735
736int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 mac[]) 736int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
737{ 737{
738 __le32 *pmac = (__le32 *) & mac[0]; 738 __le32 *pmac = (__le32 *) mac;
739 u32 offset;
739 740
740 if (netxen_get_flash_block(adapter, 741 offset = NETXEN_USER_START +
741 NETXEN_USER_START + 742 offsetof(struct netxen_new_user_info, mac_addr) +
742 offsetof(struct netxen_new_user_info, 743 adapter->portnum * sizeof(u64);
743 mac_addr), 744
744 FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) { 745 if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
745 return -1; 746 return -1;
746 } 747
747 if (*mac == cpu_to_le64(~0ULL)) { 748 if (*mac == cpu_to_le64(~0ULL)) {
749
750 offset = NETXEN_USER_START_OLD +
751 offsetof(struct netxen_user_old_info, mac_addr) +
752 adapter->portnum * sizeof(u64);
753
748 if (netxen_get_flash_block(adapter, 754 if (netxen_get_flash_block(adapter,
749 NETXEN_USER_START_OLD + 755 offset, sizeof(u64), pmac) == -1)
750 offsetof(struct netxen_user_old_info,
751 mac_addr),
752 FLASH_NUM_PORTS * sizeof(u64),
753 pmac) == -1)
754 return -1; 756 return -1;
757
755 if (*mac == cpu_to_le64(~0ULL)) 758 if (*mac == cpu_to_le64(~0ULL))
756 return -1; 759 return -1;
757 } 760 }
758 return 0; 761 return 0;
759} 762}
760 763
764int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac)
765{
766 uint32_t crbaddr, mac_hi, mac_lo;
767 int pci_func = adapter->ahw.pci_func;
768
769 crbaddr = CRB_MAC_BLOCK_START +
770 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
771
772 adapter->hw_read_wx(adapter, crbaddr, &mac_lo, 4);
773 adapter->hw_read_wx(adapter, crbaddr+4, &mac_hi, 4);
774
775 mac_hi = cpu_to_le32(mac_hi);
776 mac_lo = cpu_to_le32(mac_lo);
777
778 if (pci_func & 1)
779 *mac = ((mac_lo >> 16) | ((u64)mac_hi << 16));
780 else
781 *mac = ((mac_lo) | ((u64)mac_hi << 32));
782
783 return 0;
784}
785
761#define CRB_WIN_LOCK_TIMEOUT 100000000 786#define CRB_WIN_LOCK_TIMEOUT 100000000
762 787
763static int crb_win_lock(struct netxen_adapter *adapter) 788static int crb_win_lock(struct netxen_adapter *adapter)
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 7615c715e66e..6fc42cd30729 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -501,6 +501,44 @@ static void netxen_init_msix_entries(struct netxen_adapter *adapter)
501 adapter->msix_entries[i].entry = i; 501 adapter->msix_entries[i].entry = i;
502} 502}
503 503
504static int
505netxen_read_mac_addr(struct netxen_adapter *adapter)
506{
507 int i;
508 unsigned char *p;
509 __le64 mac_addr;
510 DECLARE_MAC_BUF(mac);
511 struct net_device *netdev = adapter->netdev;
512 struct pci_dev *pdev = adapter->pdev;
513
514 if (netxen_is_flash_supported(adapter) != 0)
515 return -EIO;
516
517 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
518 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
519 return -EIO;
520 } else {
521 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
522 return -EIO;
523 }
524
525 p = (unsigned char *)&mac_addr;
526 for (i = 0; i < 6; i++)
527 netdev->dev_addr[i] = *(p + 5 - i);
528
529 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
530
531 /* set station address */
532
533 if (!is_valid_ether_addr(netdev->perm_addr)) {
534 dev_warn(&pdev->dev, "Bad MAC address %s.\n",
535 print_mac(mac, netdev->dev_addr));
536 } else
537 adapter->macaddr_set(adapter, netdev->dev_addr);
538
539 return 0;
540}
541
504/* 542/*
505 * netxen_nic_probe() 543 * netxen_nic_probe()
506 * 544 *
@@ -529,10 +567,8 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
529 unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0; 567 unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0;
530 int i = 0, err; 568 int i = 0, err;
531 int first_driver, first_boot; 569 int first_driver, first_boot;
532 __le64 mac_addr[FLASH_NUM_PORTS + 1];
533 u32 val; 570 u32 val;
534 int pci_func_id = PCI_FUNC(pdev->devfn); 571 int pci_func_id = PCI_FUNC(pdev->devfn);
535 DECLARE_MAC_BUF(mac);
536 struct netxen_legacy_intr_set *legacy_intrp; 572 struct netxen_legacy_intr_set *legacy_intrp;
537 uint8_t revision_id; 573 uint8_t revision_id;
538 574
@@ -904,28 +940,9 @@ request_msi:
904 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); 940 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
905 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); 941 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
906 942
907 if (netxen_is_flash_supported(adapter) == 0 && 943 err = netxen_read_mac_addr(adapter);
908 netxen_get_flash_mac_addr(adapter, mac_addr) == 0) { 944 if (err)
909 unsigned char *p; 945 dev_warn(&pdev->dev, "failed to read mac addr\n");
910
911 p = (unsigned char *)&mac_addr[adapter->portnum];
912 netdev->dev_addr[0] = *(p + 5);
913 netdev->dev_addr[1] = *(p + 4);
914 netdev->dev_addr[2] = *(p + 3);
915 netdev->dev_addr[3] = *(p + 2);
916 netdev->dev_addr[4] = *(p + 1);
917 netdev->dev_addr[5] = *(p + 0);
918
919 memcpy(netdev->perm_addr, netdev->dev_addr,
920 netdev->addr_len);
921 if (!is_valid_ether_addr(netdev->perm_addr)) {
922 printk(KERN_ERR "%s: Bad MAC address %s.\n",
923 netxen_nic_driver_name,
924 print_mac(mac, netdev->dev_addr));
925 } else {
926 adapter->macaddr_set(adapter, netdev->dev_addr);
927 }
928 }
929 946
930 netif_carrier_off(netdev); 947 netif_carrier_off(netdev);
931 netif_stop_queue(netdev); 948 netif_stop_queue(netdev);
diff --git a/drivers/net/netxen/netxen_nic_phan_reg.h b/drivers/net/netxen/netxen_nic_phan_reg.h
index 83e5ee57bfef..b293adcc95ab 100644
--- a/drivers/net/netxen/netxen_nic_phan_reg.h
+++ b/drivers/net/netxen/netxen_nic_phan_reg.h
@@ -125,6 +125,8 @@
125#define CRB_SW_INT_MASK_2 NETXEN_NIC_REG(0x1e4) 125#define CRB_SW_INT_MASK_2 NETXEN_NIC_REG(0x1e4)
126#define CRB_SW_INT_MASK_3 NETXEN_NIC_REG(0x1e8) 126#define CRB_SW_INT_MASK_3 NETXEN_NIC_REG(0x1e8)
127 127
128#define CRB_MAC_BLOCK_START NETXEN_CAM_RAM(0x1c0)
129
128/* 130/*
129 * capabilities register, can be used to selectively enable/disable features 131 * capabilities register, can be used to selectively enable/disable features
130 * for backward compability 132 * for backward compability