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",
7 - new_skb = netdev_alloc_skb(bgmac->net_dev, len);
8 + new_skb = netdev_alloc_skb_ip_align(bgmac->net_dev, len);
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
14 **************************************************/
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)
19 struct bcma_device *core;
21 @@ -584,7 +584,7 @@ u16 bgmac_phy_read(struct bgmac *bgmac,
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)
28 struct bcma_device *core;
30 @@ -617,9 +617,13 @@ void bgmac_phy_write(struct bgmac *bgmac
32 bcma_write32(core, phy_access_addr, tmp);
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",
44 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyforce */
45 @@ -761,6 +765,26 @@ static void bgmac_cmdcfg_maskset(struct
49 +static void bgmac_write_mac_address(struct bgmac *bgmac, u8 *addr)
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);
59 +static void bgmac_set_rx_mode(struct net_device *net_dev)
61 + struct bgmac *bgmac = netdev_priv(net_dev);
63 + if (net_dev->flags & IFF_PROMISC)
64 + bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, true);
66 + bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, true);
69 #if 0 /* We don't use that regs yet */
70 static void bgmac_chip_stats_update(struct bgmac *bgmac)
72 @@ -889,8 +913,10 @@ static void bgmac_chip_reset(struct bgma
74 } else if (ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == 9) {
75 sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII;
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;
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)
88 bgmac_write(bgmac, BGMAC_INT_MASK, 0);
89 + bgmac_read(bgmac, BGMAC_INT_MASK);
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)
96 struct bgmac_dma_ring *ring;
97 - u8 *mac = bgmac->net_dev->dev_addr;
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);
106 - if (bgmac->net_dev->flags & IFF_PROMISC)
107 - bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, false);
109 - bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, false);
110 + bgmac_set_rx_mode(bgmac->net_dev);
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);
120 - bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, true);
121 + bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, false);
123 - bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, true);
124 + bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, false);
126 bgmac_write(bgmac, BGMAC_RXMAX_LENGTH, 32 + ETHER_MAX_LEN);
128 @@ -1160,6 +1178,19 @@ static netdev_tx_t bgmac_start_xmit(stru
129 return bgmac_dma_tx_add(bgmac, ring, skb);
132 +static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
134 + struct bgmac *bgmac = netdev_priv(net_dev);
137 + ret = eth_prepare_mac_addr_change(net_dev, addr);
140 + bgmac_write_mac_address(bgmac, (u8 *)addr);
141 + eth_commit_mac_addr_change(net_dev, addr);
145 static int bgmac_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
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,
159 @@ -1290,6 +1323,12 @@ static int bgmac_probe(struct bcma_devic
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);
169 /* Allocation and references */
170 net_dev = alloc_etherdev(sizeof(*bgmac));
172 --- a/drivers/net/ethernet/broadcom/bgmac.h
173 +++ b/drivers/net/ethernet/broadcom/bgmac.h
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
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);
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);
190 #endif /* _BGMAC_H */