bfabaee3a5e8f3f2e618832c141e86b1d0ddbb4a
[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 @@ -301,8 +301,9 @@ static int bgmac_dma_rx_read(struct bgma
4                         bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",
5                                   ring->start);
6                 } else {
7 -                       new_skb = netdev_alloc_skb(bgmac->net_dev, len);
8 +                       new_skb = netdev_alloc_skb(bgmac->net_dev, len + 2);
9                         if (new_skb) {
10 +                               skb_reserve(new_skb, 2);
11                                 skb_put(new_skb, len);
12                                 skb_copy_from_linear_data_offset(skb, BGMAC_RX_FRAME_OFFSET,
13                                                                  new_skb->data,
14 @@ -535,7 +536,7 @@ static void bgmac_dma_init(struct bgmac
15   * PHY ops
16   **************************************************/
17  
18 -u16 bgmac_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg)
19 +static u16 bgmac_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg)
20  {
21         struct bcma_device *core;
22         u16 phy_access_addr;
23 @@ -584,7 +585,7 @@ u16 bgmac_phy_read(struct bgmac *bgmac,
24  }
25  
26  /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphywr */
27 -void bgmac_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg, u16 value)
28 +static int bgmac_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg, u16 value)
29  {
30         struct bcma_device *core;
31         u16 phy_access_addr;
32 @@ -617,9 +618,13 @@ void bgmac_phy_write(struct bgmac *bgmac
33         tmp |= value;
34         bcma_write32(core, phy_access_addr, tmp);
35  
36 -       if (!bgmac_wait_value(core, phy_access_addr, BGMAC_PA_START, 0, 1000))
37 +       if (!bgmac_wait_value(core, phy_access_addr, BGMAC_PA_START, 0, 1000)) {
38                 bgmac_err(bgmac, "Writing to PHY %d register 0x%X failed\n",
39                           phyaddr, reg);
40 +               return -ETIMEDOUT;
41 +       }
42 +
43 +       return 0;
44  }
45  
46  /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyforce */
47 @@ -761,6 +766,26 @@ static void bgmac_cmdcfg_maskset(struct
48         udelay(2);
49  }
50  
51 +static void bgmac_write_mac_address(struct bgmac *bgmac, u8 *addr)
52 +{
53 +       u32 tmp;
54 +
55 +       tmp = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
56 +       bgmac_write(bgmac, BGMAC_MACADDR_HIGH, tmp);
57 +       tmp = (addr[4] << 8) | addr[5];
58 +       bgmac_write(bgmac, BGMAC_MACADDR_LOW, tmp);
59 +}
60 +
61 +static void bgmac_set_rx_mode(struct net_device *net_dev)
62 +{
63 +       struct bgmac *bgmac = netdev_priv(net_dev);
64 +
65 +       if (net_dev->flags & IFF_PROMISC)
66 +               bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, true);
67 +       else
68 +               bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, true);
69 +}
70 +
71  #if 0 /* We don't use that regs yet */
72  static void bgmac_chip_stats_update(struct bgmac *bgmac)
73  {
74 @@ -889,8 +914,10 @@ static void bgmac_chip_reset(struct bgma
75                         sw_type = et_swtype;
76                 } else if (ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == 9) {
77                         sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII;
78 -               } else if (0) {
79 -                       /* TODO */
80 +               } else if ((ci->id != BCMA_CHIP_ID_BCM53572 && ci->pkg == 10) ||
81 +                          (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg == 9)) {
82 +                       sw_type = BGMAC_CHIPCTL_1_IF_TYPE_RGMII |
83 +                                 BGMAC_CHIPCTL_1_SW_TYPE_RGMII;
84                 }
85                 bcma_chipco_chipctl_maskset(cc, 1,
86                                             ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK |
87 @@ -948,6 +975,7 @@ static void bgmac_chip_intrs_on(struct b
88  static void bgmac_chip_intrs_off(struct bgmac *bgmac)
89  {
90         bgmac_write(bgmac, BGMAC_INT_MASK, 0);
91 +       bgmac_read(bgmac, BGMAC_INT_MASK);
92  }
93  
94  /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_enable */
95 @@ -1004,8 +1032,6 @@ static void bgmac_enable(struct bgmac *b
96  static void bgmac_chip_init(struct bgmac *bgmac, bool full_init)
97  {
98         struct bgmac_dma_ring *ring;
99 -       u8 *mac = bgmac->net_dev->dev_addr;
100 -       u32 tmp;
101         int i;
102  
103         /* 1 interrupt per received frame */
104 @@ -1014,21 +1040,14 @@ static void bgmac_chip_init(struct bgmac
105         /* Enable 802.3x tx flow control (honor received PAUSE frames) */
106         bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_RPI, 0, true);
107  
108 -       if (bgmac->net_dev->flags & IFF_PROMISC)
109 -               bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, false);
110 -       else
111 -               bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, false);
112 +       bgmac_set_rx_mode(bgmac->net_dev);
113  
114 -       /* Set MAC addr */
115 -       tmp = (mac[0] << 24) | (mac[1] << 16) | (mac[2] << 8) | mac[3];
116 -       bgmac_write(bgmac, BGMAC_MACADDR_HIGH, tmp);
117 -       tmp = (mac[4] << 8) | mac[5];
118 -       bgmac_write(bgmac, BGMAC_MACADDR_LOW, tmp);
119 +       bgmac_write_mac_address(bgmac, bgmac->net_dev->dev_addr);
120  
121         if (bgmac->loopback)
122 -               bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, true);
123 +               bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, false);
124         else
125 -               bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, true);
126 +               bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, false);
127  
128         bgmac_write(bgmac, BGMAC_RXMAX_LENGTH, 32 + ETHER_MAX_LEN);
129  
130 @@ -1160,6 +1179,19 @@ static netdev_tx_t bgmac_start_xmit(stru
131         return bgmac_dma_tx_add(bgmac, ring, skb);
132  }
133  
134 +static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
135 +{
136 +       struct bgmac *bgmac = netdev_priv(net_dev);
137 +       int ret;
138 +
139 +       ret = eth_prepare_mac_addr_change(net_dev, addr);
140 +       if (ret < 0)
141 +               return ret;
142 +       bgmac_write_mac_address(bgmac, (u8 *)addr);
143 +       eth_commit_mac_addr_change(net_dev, addr);
144 +       return 0;
145 +}
146 +
147  static int bgmac_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
148  {
149         struct bgmac *bgmac = netdev_priv(net_dev);
150 @@ -1190,7 +1222,9 @@ static const struct net_device_ops bgmac
151         .ndo_open               = bgmac_open,
152         .ndo_stop               = bgmac_stop,
153         .ndo_start_xmit         = bgmac_start_xmit,
154 -       .ndo_set_mac_address    = eth_mac_addr, /* generic, sets dev_addr */
155 +       .ndo_set_rx_mode        = bgmac_set_rx_mode,
156 +       .ndo_set_mac_address    = bgmac_set_mac_address,
157 +       .ndo_validate_addr      = eth_validate_addr,
158         .ndo_do_ioctl           = bgmac_ioctl,
159  };
160  
161 @@ -1290,6 +1324,12 @@ static int bgmac_probe(struct bcma_devic
162                 return -ENOTSUPP;
163         }
164  
165 +       if (!is_valid_ether_addr(mac)) {
166 +               dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
167 +               eth_random_addr(mac);
168 +               dev_warn(&core->dev, "Using random MAC: %pM\n", mac);
169 +       }
170 +
171         /* Allocation and references */
172         net_dev = alloc_etherdev(sizeof(*bgmac));
173         if (!net_dev)
174 --- a/drivers/net/ethernet/broadcom/bgmac.h
175 +++ b/drivers/net/ethernet/broadcom/bgmac.h
176 @@ -339,7 +339,7 @@
177  #define BGMAC_CHIPCTL_1_SW_TYPE_EPHY           0x00000000
178  #define BGMAC_CHIPCTL_1_SW_TYPE_EPHYMII                0x00000040
179  #define BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII       0x00000080
180 -#define BGMAC_CHIPCTL_1_SW_TYPE_RGMI           0x000000C0
181 +#define BGMAC_CHIPCTL_1_SW_TYPE_RGMII          0x000000C0
182  #define BGMAC_CHIPCTL_1_RXC_DLL_BYPASS         0x00010000
183  
184  #define BGMAC_SPEED_10                         0x0001
185 @@ -450,7 +450,4 @@ static inline void bgmac_set(struct bgma
186         bgmac_maskset(bgmac, offset, ~0, set);
187  }
188  
189 -u16 bgmac_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg);
190 -void bgmac_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg, u16 value);
191 -
192  #endif /* _BGMAC_H */