9a971e07a8ee2aeadd689cac38015fc0aab4735b
[15.05/openwrt.git] / target / linux / brcm47xx / patches-3.6 / 760-bgmac-fixes.patch
1 --- a/drivers/net/ethernet/broadcom/bgmac.c
2 +++ b/drivers/net/ethernet/broadcom/bgmac.c
3 @@ -761,6 +761,26 @@ static void bgmac_cmdcfg_maskset(struct
4         udelay(2);
5  }
6  
7 +static void bgmac_write_mac_address(struct bgmac *bgmac, u8 *addr)
8 +{
9 +       u32 tmp;
10 +
11 +       tmp = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
12 +       bgmac_write(bgmac, BGMAC_MACADDR_HIGH, tmp);
13 +       tmp = (addr[4] << 8) | addr[5];
14 +       bgmac_write(bgmac, BGMAC_MACADDR_LOW, tmp);
15 +}
16 +
17 +static void bgmac_set_rx_mode(struct net_device *net_dev)
18 +{
19 +       struct bgmac *bgmac = netdev_priv(net_dev);
20 +
21 +       if (net_dev->flags & IFF_PROMISC)
22 +               bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, true);
23 +       else
24 +               bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, true);
25 +}
26 +
27  #if 0 /* We don't use that regs yet */
28  static void bgmac_chip_stats_update(struct bgmac *bgmac)
29  {
30 @@ -889,8 +909,10 @@ static void bgmac_chip_reset(struct bgma
31                         sw_type = et_swtype;
32                 } else if (ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == 9) {
33                         sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII;
34 -               } else if (0) {
35 -                       /* TODO */
36 +               } else if ((ci->id != BCMA_CHIP_ID_BCM53572 && ci->pkg == 10) ||
37 +                          (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg == 9)) {
38 +                       sw_type = BGMAC_CHIPCTL_1_IF_TYPE_RGMII |
39 +                                 BGMAC_CHIPCTL_1_SW_TYPE_RGMII;
40                 }
41                 bcma_chipco_chipctl_maskset(cc, 1,
42                                             ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK |
43 @@ -948,6 +970,7 @@ static void bgmac_chip_intrs_on(struct b
44  static void bgmac_chip_intrs_off(struct bgmac *bgmac)
45  {
46         bgmac_write(bgmac, BGMAC_INT_MASK, 0);
47 +       bgmac_read(bgmac, BGMAC_INT_MASK);
48  }
49  
50  /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_enable */
51 @@ -1004,8 +1027,6 @@ static void bgmac_enable(struct bgmac *b
52  static void bgmac_chip_init(struct bgmac *bgmac, bool full_init)
53  {
54         struct bgmac_dma_ring *ring;
55 -       u8 *mac = bgmac->net_dev->dev_addr;
56 -       u32 tmp;
57         int i;
58  
59         /* 1 interrupt per received frame */
60 @@ -1014,21 +1035,14 @@ static void bgmac_chip_init(struct bgmac
61         /* Enable 802.3x tx flow control (honor received PAUSE frames) */
62         bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_RPI, 0, true);
63  
64 -       if (bgmac->net_dev->flags & IFF_PROMISC)
65 -               bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, false);
66 -       else
67 -               bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, false);
68 +       bgmac_set_rx_mode(bgmac->net_dev);
69  
70 -       /* Set MAC addr */
71 -       tmp = (mac[0] << 24) | (mac[1] << 16) | (mac[2] << 8) | mac[3];
72 -       bgmac_write(bgmac, BGMAC_MACADDR_HIGH, tmp);
73 -       tmp = (mac[4] << 8) | mac[5];
74 -       bgmac_write(bgmac, BGMAC_MACADDR_LOW, tmp);
75 +       bgmac_write_mac_address(bgmac, bgmac->net_dev->dev_addr);
76  
77         if (bgmac->loopback)
78 -               bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, true);
79 +               bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, false);
80         else
81 -               bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, true);
82 +               bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, false);
83  
84         bgmac_write(bgmac, BGMAC_RXMAX_LENGTH, 32 + ETHER_MAX_LEN);
85  
86 @@ -1160,6 +1174,19 @@ static netdev_tx_t bgmac_start_xmit(stru
87         return bgmac_dma_tx_add(bgmac, ring, skb);
88  }
89  
90 +static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
91 +{
92 +       struct bgmac *bgmac = netdev_priv(net_dev);
93 +       int ret;
94 +
95 +       ret = eth_prepare_mac_addr_change(net_dev, addr);
96 +       if (ret < 0)
97 +               return ret;
98 +       bgmac_write_mac_address(bgmac, (u8 *)addr);
99 +       eth_commit_mac_addr_change(net_dev, addr);
100 +       return 0;
101 +}
102 +
103  static int bgmac_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
104  {
105         struct bgmac *bgmac = netdev_priv(net_dev);
106 @@ -1190,7 +1217,9 @@ static const struct net_device_ops bgmac
107         .ndo_open               = bgmac_open,
108         .ndo_stop               = bgmac_stop,
109         .ndo_start_xmit         = bgmac_start_xmit,
110 -       .ndo_set_mac_address    = eth_mac_addr, /* generic, sets dev_addr */
111 +       .ndo_set_rx_mode        = bgmac_set_rx_mode,
112 +       .ndo_set_mac_address    = bgmac_set_mac_address,
113 +       .ndo_validate_addr      = eth_validate_addr,
114         .ndo_do_ioctl           = bgmac_ioctl,
115  };
116  
117 @@ -1290,6 +1319,12 @@ static int bgmac_probe(struct bcma_devic
118                 return -ENOTSUPP;
119         }
120  
121 +       if (!is_valid_ether_addr(mac)) {
122 +               dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
123 +               eth_random_addr(mac);
124 +               dev_warn(&core->dev, "Using random MAC: %pM\n", mac);
125 +       }
126 +
127         /* Allocation and references */
128         net_dev = alloc_etherdev(sizeof(*bgmac));
129         if (!net_dev)
130 --- a/drivers/net/ethernet/broadcom/bgmac.h
131 +++ b/drivers/net/ethernet/broadcom/bgmac.h
132 @@ -339,7 +339,7 @@
133  #define BGMAC_CHIPCTL_1_SW_TYPE_EPHY           0x00000000
134  #define BGMAC_CHIPCTL_1_SW_TYPE_EPHYMII                0x00000040
135  #define BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII       0x00000080
136 -#define BGMAC_CHIPCTL_1_SW_TYPE_RGMI           0x000000C0
137 +#define BGMAC_CHIPCTL_1_SW_TYPE_RGMII          0x000000C0
138  #define BGMAC_CHIPCTL_1_RXC_DLL_BYPASS         0x00010000
139  
140  #define BGMAC_SPEED_10                         0x0001