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",
7 - new_skb = netdev_alloc_skb(bgmac->net_dev, len);
8 + new_skb = netdev_alloc_skb(bgmac->net_dev, len + 2);
10 + skb_reserve(new_skb, 2);
11 skb_put(new_skb, len);
12 skb_copy_from_linear_data_offset(skb, BGMAC_RX_FRAME_OFFSET,
14 @@ -535,7 +536,7 @@ static void bgmac_dma_init(struct bgmac
16 **************************************************/
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)
21 struct bcma_device *core;
23 @@ -584,7 +585,7 @@ u16 bgmac_phy_read(struct bgmac *bgmac,
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)
30 struct bcma_device *core;
32 @@ -617,9 +618,13 @@ void bgmac_phy_write(struct bgmac *bgmac
34 bcma_write32(core, phy_access_addr, tmp);
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",
46 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyforce */
47 @@ -761,6 +766,26 @@ static void bgmac_cmdcfg_maskset(struct
51 +static void bgmac_write_mac_address(struct bgmac *bgmac, u8 *addr)
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);
61 +static void bgmac_set_rx_mode(struct net_device *net_dev)
63 + struct bgmac *bgmac = netdev_priv(net_dev);
65 + if (net_dev->flags & IFF_PROMISC)
66 + bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, true);
68 + bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, true);
71 #if 0 /* We don't use that regs yet */
72 static void bgmac_chip_stats_update(struct bgmac *bgmac)
74 @@ -889,8 +914,10 @@ static void bgmac_chip_reset(struct bgma
76 } else if (ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == 9) {
77 sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII;
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;
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)
90 bgmac_write(bgmac, BGMAC_INT_MASK, 0);
91 + bgmac_read(bgmac, BGMAC_INT_MASK);
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)
98 struct bgmac_dma_ring *ring;
99 - u8 *mac = bgmac->net_dev->dev_addr;
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);
108 - if (bgmac->net_dev->flags & IFF_PROMISC)
109 - bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, false);
111 - bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, false);
112 + bgmac_set_rx_mode(bgmac->net_dev);
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);
122 - bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, true);
123 + bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, false);
125 - bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, true);
126 + bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, false);
128 bgmac_write(bgmac, BGMAC_RXMAX_LENGTH, 32 + ETHER_MAX_LEN);
130 @@ -1160,6 +1179,19 @@ static netdev_tx_t bgmac_start_xmit(stru
131 return bgmac_dma_tx_add(bgmac, ring, skb);
134 +static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
136 + struct bgmac *bgmac = netdev_priv(net_dev);
139 + ret = eth_prepare_mac_addr_change(net_dev, addr);
142 + bgmac_write_mac_address(bgmac, (u8 *)addr);
143 + eth_commit_mac_addr_change(net_dev, addr);
147 static int bgmac_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
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,
161 @@ -1290,6 +1324,12 @@ static int bgmac_probe(struct bcma_devic
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);
171 /* Allocation and references */
172 net_dev = alloc_etherdev(sizeof(*bgmac));
174 --- a/drivers/net/ethernet/broadcom/bgmac.h
175 +++ b/drivers/net/ethernet/broadcom/bgmac.h
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
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);
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);
192 #endif /* _BGMAC_H */