Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * ASIX AX88172A based USB 2.0 Ethernet Devices
4 * Copyright (C) 2012 OMICRON electronics GmbH
5 *
6 * Supports external PHYs via phylib. Based on the driver for the
7 * AX88772. Original copyrights follow:
8 *
9 * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
10 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
11 * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
12 * Copyright (c) 2002-2003 TiVo Inc.
13 */
14
15#include "asix.h"
16#include <linux/phy.h>
17
18struct ax88172a_private {
19 struct mii_bus *mdio;
20 struct phy_device *phydev;
21 char phy_name[20];
22 u16 phy_addr;
23 u16 oldmode;
24 int use_embdphy;
25 struct asix_rx_fixup_info rx_fixup_info;
26};
27
28/* set MAC link settings according to information from phylib */
29static void ax88172a_adjust_link(struct net_device *netdev)
30{
31 struct phy_device *phydev = netdev->phydev;
32 struct usbnet *dev = netdev_priv(netdev);
33 struct ax88172a_private *priv = dev->driver_priv;
34 u16 mode = 0;
35
36 if (phydev->link) {
37 mode = AX88772_MEDIUM_DEFAULT;
38
39 if (phydev->duplex == DUPLEX_HALF)
40 mode &= ~AX_MEDIUM_FD;
41
42 if (phydev->speed != SPEED_100)
43 mode &= ~AX_MEDIUM_PS;
44 }
45
46 if (mode != priv->oldmode) {
47 asix_write_medium_mode(dev, mode, 0);
48 priv->oldmode = mode;
49 netdev_dbg(netdev, "speed %u duplex %d, setting mode to 0x%04x\n",
50 phydev->speed, phydev->duplex, mode);
51 phy_print_status(phydev);
52 }
53}
54
55static void ax88172a_status(struct usbnet *dev, struct urb *urb)
56{
57 /* link changes are detected by polling the phy */
58}
59
60/* use phylib infrastructure */
61static int ax88172a_init_mdio(struct usbnet *dev)
62{
63 struct ax88172a_private *priv = dev->driver_priv;
64 int ret;
65
66 priv->mdio = mdiobus_alloc();
67 if (!priv->mdio) {
68 netdev_err(dev->net, "Could not allocate MDIO bus\n");
69 return -ENOMEM;
70 }
71
72 priv->mdio->priv = (void *)dev;
73 priv->mdio->read = &asix_mdio_bus_read;
74 priv->mdio->write = &asix_mdio_bus_write;
75 priv->mdio->name = "Asix MDIO Bus";
76 /* mii bus name is usb-<usb bus number>-<usb device number> */
77 snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
78 dev->udev->bus->busnum, dev->udev->devnum);
79
80 ret = mdiobus_register(priv->mdio);
81 if (ret) {
82 netdev_err(dev->net, "Could not register MDIO bus\n");
83 goto mfree;
84 }
85
86 netdev_info(dev->net, "registered mdio bus %s\n", priv->mdio->id);
87 return 0;
88
89mfree:
90 mdiobus_free(priv->mdio);
91 return ret;
92}
93
94static void ax88172a_remove_mdio(struct usbnet *dev)
95{
96 struct ax88172a_private *priv = dev->driver_priv;
97
98 netdev_info(dev->net, "deregistering mdio bus %s\n", priv->mdio->id);
99 mdiobus_unregister(priv->mdio);
100 mdiobus_free(priv->mdio);
101}
102
103static const struct net_device_ops ax88172a_netdev_ops = {
104 .ndo_open = usbnet_open,
105 .ndo_stop = usbnet_stop,
106 .ndo_start_xmit = usbnet_start_xmit,
107 .ndo_tx_timeout = usbnet_tx_timeout,
108 .ndo_change_mtu = usbnet_change_mtu,
109 .ndo_get_stats64 = dev_get_tstats64,
110 .ndo_set_mac_address = asix_set_mac_address,
111 .ndo_validate_addr = eth_validate_addr,
112 .ndo_eth_ioctl = phy_do_ioctl_running,
113 .ndo_set_rx_mode = asix_set_multicast,
114};
115
116static const struct ethtool_ops ax88172a_ethtool_ops = {
117 .get_drvinfo = asix_get_drvinfo,
118 .get_link = usbnet_get_link,
119 .get_msglevel = usbnet_get_msglevel,
120 .set_msglevel = usbnet_set_msglevel,
121 .get_wol = asix_get_wol,
122 .set_wol = asix_set_wol,
123 .get_eeprom_len = asix_get_eeprom_len,
124 .get_eeprom = asix_get_eeprom,
125 .set_eeprom = asix_set_eeprom,
126 .nway_reset = phy_ethtool_nway_reset,
127 .get_link_ksettings = phy_ethtool_get_link_ksettings,
128 .set_link_ksettings = phy_ethtool_set_link_ksettings,
129};
130
131static int ax88172a_reset_phy(struct usbnet *dev, int embd_phy)
132{
133 int ret;
134
135 ret = asix_sw_reset(dev, AX_SWRESET_IPPD, 0);
136 if (ret < 0)
137 goto err;
138
139 msleep(150);
140 ret = asix_sw_reset(dev, AX_SWRESET_CLEAR, 0);
141 if (ret < 0)
142 goto err;
143
144 msleep(150);
145
146 ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_IPPD,
147 0);
148 if (ret < 0)
149 goto err;
150
151 return 0;
152
153err:
154 return ret;
155}
156
157
158static int ax88172a_bind(struct usbnet *dev, struct usb_interface *intf)
159{
160 int ret;
161 u8 buf[ETH_ALEN];
162 struct ax88172a_private *priv;
163
164 ret = usbnet_get_endpoints(dev, intf);
165 if (ret)
166 return ret;
167
168 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
169 if (!priv)
170 return -ENOMEM;
171
172 dev->driver_priv = priv;
173
174 /* Get the MAC address */
175 ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf, 0);
176 if (ret < ETH_ALEN) {
177 netdev_err(dev->net, "Failed to read MAC address: %d\n", ret);
178 ret = -EIO;
179 goto free;
180 }
181 eth_hw_addr_set(dev->net, buf);
182
183 dev->net->netdev_ops = &ax88172a_netdev_ops;
184 dev->net->ethtool_ops = &ax88172a_ethtool_ops;
185
186 /* are we using the internal or the external phy? */
187 ret = asix_read_cmd(dev, AX_CMD_SW_PHY_STATUS, 0, 0, 1, buf, 0);
188 if (ret < 0) {
189 netdev_err(dev->net, "Failed to read software interface selection register: %d\n",
190 ret);
191 goto free;
192 }
193
194 netdev_dbg(dev->net, "AX_CMD_SW_PHY_STATUS = 0x%02x\n", buf[0]);
195 switch (buf[0] & AX_PHY_SELECT_MASK) {
196 case AX_PHY_SELECT_INTERNAL:
197 netdev_dbg(dev->net, "use internal phy\n");
198 priv->use_embdphy = 1;
199 break;
200 case AX_PHY_SELECT_EXTERNAL:
201 netdev_dbg(dev->net, "use external phy\n");
202 priv->use_embdphy = 0;
203 break;
204 default:
205 netdev_err(dev->net, "Interface mode not supported by driver\n");
206 ret = -ENOTSUPP;
207 goto free;
208 }
209
210 ret = asix_read_phy_addr(dev, priv->use_embdphy);
211 if (ret < 0)
212 goto free;
213
214 priv->phy_addr = ret;
215
216 ax88172a_reset_phy(dev, priv->use_embdphy);
217
218 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
219 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
220 /* hard_mtu is still the default - the device does not support
221 jumbo eth frames */
222 dev->rx_urb_size = 2048;
223 }
224
225 /* init MDIO bus */
226 ret = ax88172a_init_mdio(dev);
227 if (ret)
228 goto free;
229
230 return 0;
231
232free:
233 kfree(priv);
234 return ret;
235}
236
237static int ax88172a_stop(struct usbnet *dev)
238{
239 struct ax88172a_private *priv = dev->driver_priv;
240
241 netdev_dbg(dev->net, "Stopping interface\n");
242
243 if (priv->phydev) {
244 netdev_info(dev->net, "Disconnecting from phy %s\n",
245 priv->phy_name);
246 phy_stop(priv->phydev);
247 phy_disconnect(priv->phydev);
248 }
249
250 return 0;
251}
252
253static void ax88172a_unbind(struct usbnet *dev, struct usb_interface *intf)
254{
255 struct ax88172a_private *priv = dev->driver_priv;
256
257 ax88172a_remove_mdio(dev);
258 kfree(priv);
259}
260
261static int ax88172a_reset(struct usbnet *dev)
262{
263 struct asix_data *data = (struct asix_data *)&dev->data;
264 struct ax88172a_private *priv = dev->driver_priv;
265 int ret;
266 u16 rx_ctl;
267
268 ax88172a_reset_phy(dev, priv->use_embdphy);
269
270 msleep(150);
271 rx_ctl = asix_read_rx_ctl(dev, 0);
272 netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
273 ret = asix_write_rx_ctl(dev, 0x0000, 0);
274 if (ret < 0)
275 goto out;
276
277 rx_ctl = asix_read_rx_ctl(dev, 0);
278 netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
279
280 msleep(150);
281
282 ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
283 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
284 AX88772_IPG2_DEFAULT, 0, NULL, 0);
285 if (ret < 0) {
286 netdev_err(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
287 goto out;
288 }
289
290 /* Rewrite MAC address */
291 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
292 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
293 data->mac_addr, 0);
294 if (ret < 0)
295 goto out;
296
297 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
298 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL, 0);
299 if (ret < 0)
300 goto out;
301
302 rx_ctl = asix_read_rx_ctl(dev, 0);
303 netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
304 rx_ctl);
305
306 rx_ctl = asix_read_medium_status(dev, 0);
307 netdev_dbg(dev->net, "Medium Status is 0x%04x after all initializations\n",
308 rx_ctl);
309
310 /* Connect to PHY */
311 snprintf(priv->phy_name, 20, PHY_ID_FMT,
312 priv->mdio->id, priv->phy_addr);
313
314 priv->phydev = phy_connect(dev->net, priv->phy_name,
315 &ax88172a_adjust_link,
316 PHY_INTERFACE_MODE_MII);
317 if (IS_ERR(priv->phydev)) {
318 netdev_err(dev->net, "Could not connect to PHY device %s\n",
319 priv->phy_name);
320 ret = PTR_ERR(priv->phydev);
321 goto out;
322 }
323
324 netdev_info(dev->net, "Connected to phy %s\n", priv->phy_name);
325
326 /* During power-up, the AX88172A set the power down (BMCR_PDOWN)
327 * bit of the PHY. Bring the PHY up again.
328 */
329 genphy_resume(priv->phydev);
330 phy_start(priv->phydev);
331
332 return 0;
333
334out:
335 return ret;
336
337}
338
339static int ax88172a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
340{
341 struct ax88172a_private *dp = dev->driver_priv;
342 struct asix_rx_fixup_info *rx = &dp->rx_fixup_info;
343
344 return asix_rx_fixup_internal(dev, skb, rx);
345}
346
347const struct driver_info ax88172a_info = {
348 .description = "ASIX AX88172A USB 2.0 Ethernet",
349 .bind = ax88172a_bind,
350 .reset = ax88172a_reset,
351 .stop = ax88172a_stop,
352 .unbind = ax88172a_unbind,
353 .status = ax88172a_status,
354 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
355 FLAG_MULTI_PACKET,
356 .rx_fixup = ax88172a_rx_fixup,
357 .tx_fixup = asix_tx_fixup,
358};
1/*
2 * ASIX AX88172A based USB 2.0 Ethernet Devices
3 * Copyright (C) 2012 OMICRON electronics GmbH
4 *
5 * Supports external PHYs via phylib. Based on the driver for the
6 * AX88772. Original copyrights follow:
7 *
8 * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
9 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
10 * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
11 * Copyright (c) 2002-2003 TiVo Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 */
26
27#include "asix.h"
28#include <linux/phy.h>
29
30struct ax88172a_private {
31 struct mii_bus *mdio;
32 struct phy_device *phydev;
33 char phy_name[20];
34 u16 phy_addr;
35 u16 oldmode;
36 int use_embdphy;
37 struct asix_rx_fixup_info rx_fixup_info;
38};
39
40/* MDIO read and write wrappers for phylib */
41static int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum)
42{
43 return asix_mdio_read(((struct usbnet *)bus->priv)->net, phy_id,
44 regnum);
45}
46
47static int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum,
48 u16 val)
49{
50 asix_mdio_write(((struct usbnet *)bus->priv)->net, phy_id, regnum, val);
51 return 0;
52}
53
54static int ax88172a_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
55{
56 if (!netif_running(net))
57 return -EINVAL;
58
59 if (!net->phydev)
60 return -ENODEV;
61
62 return phy_mii_ioctl(net->phydev, rq, cmd);
63}
64
65/* set MAC link settings according to information from phylib */
66static void ax88172a_adjust_link(struct net_device *netdev)
67{
68 struct phy_device *phydev = netdev->phydev;
69 struct usbnet *dev = netdev_priv(netdev);
70 struct ax88172a_private *priv = dev->driver_priv;
71 u16 mode = 0;
72
73 if (phydev->link) {
74 mode = AX88772_MEDIUM_DEFAULT;
75
76 if (phydev->duplex == DUPLEX_HALF)
77 mode &= ~AX_MEDIUM_FD;
78
79 if (phydev->speed != SPEED_100)
80 mode &= ~AX_MEDIUM_PS;
81 }
82
83 if (mode != priv->oldmode) {
84 asix_write_medium_mode(dev, mode);
85 priv->oldmode = mode;
86 netdev_dbg(netdev, "speed %u duplex %d, setting mode to 0x%04x\n",
87 phydev->speed, phydev->duplex, mode);
88 phy_print_status(phydev);
89 }
90}
91
92static void ax88172a_status(struct usbnet *dev, struct urb *urb)
93{
94 /* link changes are detected by polling the phy */
95}
96
97/* use phylib infrastructure */
98static int ax88172a_init_mdio(struct usbnet *dev)
99{
100 struct ax88172a_private *priv = dev->driver_priv;
101 int ret;
102
103 priv->mdio = mdiobus_alloc();
104 if (!priv->mdio) {
105 netdev_err(dev->net, "Could not allocate MDIO bus\n");
106 return -ENOMEM;
107 }
108
109 priv->mdio->priv = (void *)dev;
110 priv->mdio->read = &asix_mdio_bus_read;
111 priv->mdio->write = &asix_mdio_bus_write;
112 priv->mdio->name = "Asix MDIO Bus";
113 /* mii bus name is usb-<usb bus number>-<usb device number> */
114 snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
115 dev->udev->bus->busnum, dev->udev->devnum);
116
117 ret = mdiobus_register(priv->mdio);
118 if (ret) {
119 netdev_err(dev->net, "Could not register MDIO bus\n");
120 goto mfree;
121 }
122
123 netdev_info(dev->net, "registered mdio bus %s\n", priv->mdio->id);
124 return 0;
125
126mfree:
127 mdiobus_free(priv->mdio);
128 return ret;
129}
130
131static void ax88172a_remove_mdio(struct usbnet *dev)
132{
133 struct ax88172a_private *priv = dev->driver_priv;
134
135 netdev_info(dev->net, "deregistering mdio bus %s\n", priv->mdio->id);
136 mdiobus_unregister(priv->mdio);
137 mdiobus_free(priv->mdio);
138}
139
140static const struct net_device_ops ax88172a_netdev_ops = {
141 .ndo_open = usbnet_open,
142 .ndo_stop = usbnet_stop,
143 .ndo_start_xmit = usbnet_start_xmit,
144 .ndo_tx_timeout = usbnet_tx_timeout,
145 .ndo_change_mtu = usbnet_change_mtu,
146 .ndo_set_mac_address = asix_set_mac_address,
147 .ndo_validate_addr = eth_validate_addr,
148 .ndo_do_ioctl = ax88172a_ioctl,
149 .ndo_set_rx_mode = asix_set_multicast,
150};
151
152static int ax88172a_get_settings(struct net_device *net,
153 struct ethtool_cmd *cmd)
154{
155 if (!net->phydev)
156 return -ENODEV;
157
158 return phy_ethtool_gset(net->phydev, cmd);
159}
160
161static int ax88172a_set_settings(struct net_device *net,
162 struct ethtool_cmd *cmd)
163{
164 if (!net->phydev)
165 return -ENODEV;
166
167 return phy_ethtool_sset(net->phydev, cmd);
168}
169
170static int ax88172a_nway_reset(struct net_device *net)
171{
172 if (!net->phydev)
173 return -ENODEV;
174
175 return phy_start_aneg(net->phydev);
176}
177
178static const struct ethtool_ops ax88172a_ethtool_ops = {
179 .get_drvinfo = asix_get_drvinfo,
180 .get_link = usbnet_get_link,
181 .get_msglevel = usbnet_get_msglevel,
182 .set_msglevel = usbnet_set_msglevel,
183 .get_wol = asix_get_wol,
184 .set_wol = asix_set_wol,
185 .get_eeprom_len = asix_get_eeprom_len,
186 .get_eeprom = asix_get_eeprom,
187 .set_eeprom = asix_set_eeprom,
188 .get_settings = ax88172a_get_settings,
189 .set_settings = ax88172a_set_settings,
190 .nway_reset = ax88172a_nway_reset,
191};
192
193static int ax88172a_reset_phy(struct usbnet *dev, int embd_phy)
194{
195 int ret;
196
197 ret = asix_sw_reset(dev, AX_SWRESET_IPPD);
198 if (ret < 0)
199 goto err;
200
201 msleep(150);
202 ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
203 if (ret < 0)
204 goto err;
205
206 msleep(150);
207
208 ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_IPPD);
209 if (ret < 0)
210 goto err;
211
212 return 0;
213
214err:
215 return ret;
216}
217
218
219static int ax88172a_bind(struct usbnet *dev, struct usb_interface *intf)
220{
221 int ret;
222 u8 buf[ETH_ALEN];
223 struct ax88172a_private *priv;
224
225 usbnet_get_endpoints(dev, intf);
226
227 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
228 if (!priv)
229 return -ENOMEM;
230
231 dev->driver_priv = priv;
232
233 /* Get the MAC address */
234 ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
235 if (ret < 0) {
236 netdev_err(dev->net, "Failed to read MAC address: %d\n", ret);
237 goto free;
238 }
239 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
240
241 dev->net->netdev_ops = &ax88172a_netdev_ops;
242 dev->net->ethtool_ops = &ax88172a_ethtool_ops;
243
244 /* are we using the internal or the external phy? */
245 ret = asix_read_cmd(dev, AX_CMD_SW_PHY_STATUS, 0, 0, 1, buf);
246 if (ret < 0) {
247 netdev_err(dev->net, "Failed to read software interface selection register: %d\n",
248 ret);
249 goto free;
250 }
251
252 netdev_dbg(dev->net, "AX_CMD_SW_PHY_STATUS = 0x%02x\n", buf[0]);
253 switch (buf[0] & AX_PHY_SELECT_MASK) {
254 case AX_PHY_SELECT_INTERNAL:
255 netdev_dbg(dev->net, "use internal phy\n");
256 priv->use_embdphy = 1;
257 break;
258 case AX_PHY_SELECT_EXTERNAL:
259 netdev_dbg(dev->net, "use external phy\n");
260 priv->use_embdphy = 0;
261 break;
262 default:
263 netdev_err(dev->net, "Interface mode not supported by driver\n");
264 ret = -ENOTSUPP;
265 goto free;
266 }
267
268 priv->phy_addr = asix_read_phy_addr(dev, priv->use_embdphy);
269 ax88172a_reset_phy(dev, priv->use_embdphy);
270
271 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
272 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
273 /* hard_mtu is still the default - the device does not support
274 jumbo eth frames */
275 dev->rx_urb_size = 2048;
276 }
277
278 /* init MDIO bus */
279 ret = ax88172a_init_mdio(dev);
280 if (ret)
281 goto free;
282
283 return 0;
284
285free:
286 kfree(priv);
287 return ret;
288}
289
290static int ax88172a_stop(struct usbnet *dev)
291{
292 struct ax88172a_private *priv = dev->driver_priv;
293
294 netdev_dbg(dev->net, "Stopping interface\n");
295
296 if (priv->phydev) {
297 netdev_info(dev->net, "Disconnecting from phy %s\n",
298 priv->phy_name);
299 phy_stop(priv->phydev);
300 phy_disconnect(priv->phydev);
301 }
302
303 return 0;
304}
305
306static void ax88172a_unbind(struct usbnet *dev, struct usb_interface *intf)
307{
308 struct ax88172a_private *priv = dev->driver_priv;
309
310 ax88172a_remove_mdio(dev);
311 kfree(priv);
312}
313
314static int ax88172a_reset(struct usbnet *dev)
315{
316 struct asix_data *data = (struct asix_data *)&dev->data;
317 struct ax88172a_private *priv = dev->driver_priv;
318 int ret;
319 u16 rx_ctl;
320
321 ax88172a_reset_phy(dev, priv->use_embdphy);
322
323 msleep(150);
324 rx_ctl = asix_read_rx_ctl(dev);
325 netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
326 ret = asix_write_rx_ctl(dev, 0x0000);
327 if (ret < 0)
328 goto out;
329
330 rx_ctl = asix_read_rx_ctl(dev);
331 netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
332
333 msleep(150);
334
335 ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
336 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
337 AX88772_IPG2_DEFAULT, 0, NULL);
338 if (ret < 0) {
339 netdev_err(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
340 goto out;
341 }
342
343 /* Rewrite MAC address */
344 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
345 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
346 data->mac_addr);
347 if (ret < 0)
348 goto out;
349
350 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
351 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
352 if (ret < 0)
353 goto out;
354
355 rx_ctl = asix_read_rx_ctl(dev);
356 netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
357 rx_ctl);
358
359 rx_ctl = asix_read_medium_status(dev);
360 netdev_dbg(dev->net, "Medium Status is 0x%04x after all initializations\n",
361 rx_ctl);
362
363 /* Connect to PHY */
364 snprintf(priv->phy_name, 20, PHY_ID_FMT,
365 priv->mdio->id, priv->phy_addr);
366
367 priv->phydev = phy_connect(dev->net, priv->phy_name,
368 &ax88172a_adjust_link,
369 PHY_INTERFACE_MODE_MII);
370 if (IS_ERR(priv->phydev)) {
371 netdev_err(dev->net, "Could not connect to PHY device %s\n",
372 priv->phy_name);
373 ret = PTR_ERR(priv->phydev);
374 goto out;
375 }
376
377 netdev_info(dev->net, "Connected to phy %s\n", priv->phy_name);
378
379 /* During power-up, the AX88172A set the power down (BMCR_PDOWN)
380 * bit of the PHY. Bring the PHY up again.
381 */
382 genphy_resume(priv->phydev);
383 phy_start(priv->phydev);
384
385 return 0;
386
387out:
388 return ret;
389
390}
391
392static int ax88172a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
393{
394 struct ax88172a_private *dp = dev->driver_priv;
395 struct asix_rx_fixup_info *rx = &dp->rx_fixup_info;
396
397 return asix_rx_fixup_internal(dev, skb, rx);
398}
399
400const struct driver_info ax88172a_info = {
401 .description = "ASIX AX88172A USB 2.0 Ethernet",
402 .bind = ax88172a_bind,
403 .reset = ax88172a_reset,
404 .stop = ax88172a_stop,
405 .unbind = ax88172a_unbind,
406 .status = ax88172a_status,
407 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
408 FLAG_MULTI_PACKET,
409 .rx_fixup = ax88172a_rx_fixup,
410 .tx_fixup = asix_tx_fixup,
411};