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