Lines Matching +full:offset +full:- +full:x

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
7 * Copyright (c) 2002-2003 TiVo Inc.
31 ret = ret < 0 ? ret : -ENODATA; in asix_read_cmd()
33 netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n", in asix_read_cmd()
57 netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n", in asix_write_cmd()
78 netdev_err(dev->net, "Failed to enable software MII access\n"); in asix_set_sw_mii()
88 netdev_err(dev->net, "Failed to enable hardware MII access\n"); in asix_set_hw_mii()
99 if (ret == -ENODEV || ret == -ETIMEDOUT) in asix_check_host_enable()
104 if (ret == -ENODEV) in asix_check_host_enable()
112 return i >= AX_HOST_EN_RETRIES ? -ETIMEDOUT : ret; in asix_check_host_enable()
122 if (rx->ax_skb) { in reset_asix_rx_fixup_info()
124 kfree_skb(rx->ax_skb); in reset_asix_rx_fixup_info()
125 rx->ax_skb = NULL; in reset_asix_rx_fixup_info()
128 /* Assume the Data header 32-bit word is at the start of the current in reset_asix_rx_fixup_info()
131 rx->remaining = 0; in reset_asix_rx_fixup_info()
132 rx->split_head = false; in reset_asix_rx_fixup_info()
133 rx->header = 0; in reset_asix_rx_fixup_info()
139 int offset = 0; in asix_rx_fixup_internal() local
151 if (rx->remaining && (rx->remaining + sizeof(u32) <= skb->len)) { in asix_rx_fixup_internal()
152 offset = ((rx->remaining + 1) & 0xfffe); in asix_rx_fixup_internal()
153 rx->header = get_unaligned_le32(skb->data + offset); in asix_rx_fixup_internal()
154 offset = 0; in asix_rx_fixup_internal()
156 size = (u16)(rx->header & 0x7ff); in asix_rx_fixup_internal()
157 if (size != ((~rx->header >> 16) & 0x7ff)) { in asix_rx_fixup_internal()
158 netdev_err(dev->net, "asix_rx_fixup() Data Header synchronisation was lost, remaining %d\n", in asix_rx_fixup_internal()
159 rx->remaining); in asix_rx_fixup_internal()
164 while (offset + sizeof(u16) <= skb->len) { in asix_rx_fixup_internal()
167 if (!rx->remaining) { in asix_rx_fixup_internal()
168 if (skb->len - offset == sizeof(u16)) { in asix_rx_fixup_internal()
169 rx->header = get_unaligned_le16( in asix_rx_fixup_internal()
170 skb->data + offset); in asix_rx_fixup_internal()
171 rx->split_head = true; in asix_rx_fixup_internal()
172 offset += sizeof(u16); in asix_rx_fixup_internal()
176 if (rx->split_head == true) { in asix_rx_fixup_internal()
177 rx->header |= (get_unaligned_le16( in asix_rx_fixup_internal()
178 skb->data + offset) << 16); in asix_rx_fixup_internal()
179 rx->split_head = false; in asix_rx_fixup_internal()
180 offset += sizeof(u16); in asix_rx_fixup_internal()
182 rx->header = get_unaligned_le32(skb->data + in asix_rx_fixup_internal()
183 offset); in asix_rx_fixup_internal()
184 offset += sizeof(u32); in asix_rx_fixup_internal()
187 /* take frame length from Data header 32-bit word */ in asix_rx_fixup_internal()
188 size = (u16)(rx->header & 0x7ff); in asix_rx_fixup_internal()
189 if (size != ((~rx->header >> 16) & 0x7ff)) { in asix_rx_fixup_internal()
190 netdev_err(dev->net, "asix_rx_fixup() Bad Header Length 0x%x, offset %d\n", in asix_rx_fixup_internal()
191 rx->header, offset); in asix_rx_fixup_internal()
195 if (size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) { in asix_rx_fixup_internal()
196 netdev_dbg(dev->net, "asix_rx_fixup() Bad RX Length %d\n", in asix_rx_fixup_internal()
207 rx->ax_skb = netdev_alloc_skb_ip_align(dev->net, size); in asix_rx_fixup_internal()
209 rx->remaining = size; in asix_rx_fixup_internal()
212 if (rx->remaining > skb->len - offset) { in asix_rx_fixup_internal()
213 copy_length = skb->len - offset; in asix_rx_fixup_internal()
214 rx->remaining -= copy_length; in asix_rx_fixup_internal()
216 copy_length = rx->remaining; in asix_rx_fixup_internal()
217 rx->remaining = 0; in asix_rx_fixup_internal()
220 if (rx->ax_skb) { in asix_rx_fixup_internal()
221 skb_put_data(rx->ax_skb, skb->data + offset, in asix_rx_fixup_internal()
223 if (!rx->remaining) { in asix_rx_fixup_internal()
224 usbnet_skb_return(dev, rx->ax_skb); in asix_rx_fixup_internal()
225 rx->ax_skb = NULL; in asix_rx_fixup_internal()
229 offset += (copy_length + 1) & 0xfffe; in asix_rx_fixup_internal()
232 if (skb->len != offset) { in asix_rx_fixup_internal()
233 netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d, %d\n", in asix_rx_fixup_internal()
234 skb->len, offset); in asix_rx_fixup_internal()
244 struct asix_common_private *dp = dev->driver_priv; in asix_rx_fixup_common()
245 struct asix_rx_fixup_info *rx = &dp->rx_fixup_info; in asix_rx_fixup_common()
257 rx = &dp->rx_fixup_info; in asix_rx_fixup_common_free()
259 if (rx->ax_skb) { in asix_rx_fixup_common_free()
260 kfree_skb(rx->ax_skb); in asix_rx_fixup_common_free()
261 rx->ax_skb = NULL; in asix_rx_fixup_common_free()
275 padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4; in asix_tx_fixup()
281 * - We are allowed to push 4 bytes in headroom if skb_header_cloned() in asix_tx_fixup()
283 * - We are allowed to put 4 bytes at tail if skb_cloned() in asix_tx_fixup()
295 skb->data = memmove(skb->head + 4, skb->data, skb->len); in asix_tx_fixup()
296 skb_set_tail_pointer(skb, skb->len); in asix_tx_fixup()
308 packet_len = ((skb->len ^ 0x0000ffff) << 16) + skb->len; in asix_tx_fixup()
323 int ret, offset; in asix_read_phy_addr() local
331 ret = -EIO; in asix_read_phy_addr()
335 offset = (internal ? 1 : 0); in asix_read_phy_addr()
336 ret = buf[offset]; in asix_read_phy_addr()
338 netdev_dbg(dev->net, "%s PHY address 0x%x\n", in asix_read_phy_addr()
344 netdev_err(dev->net, "Error reading PHY_ID register: %02x\n", ret); in asix_read_phy_addr()
355 netdev_err(dev->net, "Failed to send software reset: %02x\n", ret); in asix_sw_reset()
366 netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret); in asix_read_rx_ctl()
378 netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode); in asix_write_rx_ctl()
381 netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n", in asix_write_rx_ctl()
394 netdev_err(dev->net, "Error reading Medium Status register: %02x\n", in asix_read_medium_status()
407 netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode); in asix_write_medium_mode()
411 netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n", in asix_write_medium_mode()
420 struct phy_device *phydev = netdev->phydev; in asix_adjust_link()
424 if (phydev->link) { in asix_adjust_link()
427 if (phydev->duplex == DUPLEX_HALF) in asix_adjust_link()
430 if (phydev->speed != SPEED_100) in asix_adjust_link()
436 usbnet_link_change(dev, phydev->link, 0); in asix_adjust_link()
443 netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value); in asix_write_gpio()
446 netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n", in asix_write_gpio()
456 * AX88772 & AX88178 have a 16-bit RX_CTL value
461 struct asix_data *data = (struct asix_data *)&dev->data; in asix_set_multicast()
464 if (net->flags & IFF_PROMISC) { in asix_set_multicast()
466 } else if (net->flags & IFF_ALLMULTI || in asix_set_multicast()
472 /* We use the 20 byte dev->data in asix_set_multicast()
479 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); in asix_set_multicast()
483 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26; in asix_set_multicast()
484 data->multi_filter[crc_bits >> 3] |= in asix_set_multicast()
489 AX_MCAST_FILTER_SIZE, data->multi_filter); in asix_set_multicast()
504 mutex_lock(&dev->phy_mutex); in __asix_mdio_read()
507 if (ret == -ENODEV || ret == -ETIMEDOUT) { in __asix_mdio_read()
508 mutex_unlock(&dev->phy_mutex); in __asix_mdio_read()
519 mutex_unlock(&dev->phy_mutex); in __asix_mdio_read()
521 netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", in __asix_mdio_read()
539 netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", in __asix_mdio_write()
542 mutex_lock(&dev->phy_mutex); in __asix_mdio_write()
545 if (ret == -ENODEV) in __asix_mdio_write()
555 mutex_unlock(&dev->phy_mutex); in __asix_mdio_write()
568 struct usbnet *priv = bus->priv; in asix_mdio_bus_read()
570 return __asix_mdio_read(priv->net, phy_id, regnum, false); in asix_mdio_bus_read()
575 struct usbnet *priv = bus->priv; in asix_mdio_bus_write()
577 return __asix_mdio_write(priv->net, phy_id, regnum, val, false); in asix_mdio_bus_write()
598 wolinfo->supported = 0; in asix_get_wol()
599 wolinfo->wolopts = 0; in asix_get_wol()
602 wolinfo->supported = WAKE_PHY | WAKE_MAGIC; in asix_get_wol()
603 wolinfo->wolopts = 0; in asix_get_wol()
605 wolinfo->wolopts |= WAKE_PHY; in asix_get_wol()
607 wolinfo->wolopts |= WAKE_MAGIC; in asix_get_wol()
615 if (wolinfo->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) in asix_set_wol()
616 return -EINVAL; in asix_set_wol()
618 if (wolinfo->wolopts & WAKE_PHY) in asix_set_wol()
620 if (wolinfo->wolopts & WAKE_MAGIC) in asix_set_wol()
625 return -EINVAL; in asix_set_wol()
643 if (eeprom->len == 0) in asix_get_eeprom()
644 return -EINVAL; in asix_get_eeprom()
646 eeprom->magic = AX_EEPROM_MAGIC; in asix_get_eeprom()
648 first_word = eeprom->offset >> 1; in asix_get_eeprom()
649 last_word = (eeprom->offset + eeprom->len - 1) >> 1; in asix_get_eeprom()
651 eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), in asix_get_eeprom()
654 return -ENOMEM; in asix_get_eeprom()
659 &eeprom_buff[i - first_word], 0) < 0) { in asix_get_eeprom()
661 return -EIO; in asix_get_eeprom()
665 memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); in asix_get_eeprom()
679 netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n", in asix_set_eeprom()
680 eeprom->len, eeprom->offset, eeprom->magic); in asix_set_eeprom()
682 if (eeprom->len == 0) in asix_set_eeprom()
683 return -EINVAL; in asix_set_eeprom()
685 if (eeprom->magic != AX_EEPROM_MAGIC) in asix_set_eeprom()
686 return -EINVAL; in asix_set_eeprom()
688 first_word = eeprom->offset >> 1; in asix_set_eeprom()
689 last_word = (eeprom->offset + eeprom->len - 1) >> 1; in asix_set_eeprom()
691 eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), in asix_set_eeprom()
694 return -ENOMEM; in asix_set_eeprom()
698 if (eeprom->offset & 1) { in asix_set_eeprom()
702 netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word); in asix_set_eeprom()
707 if ((eeprom->offset + eeprom->len) & 1) { in asix_set_eeprom()
709 &eeprom_buff[last_word - first_word], 0); in asix_set_eeprom()
711 netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word); in asix_set_eeprom()
716 memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len); in asix_set_eeprom()
727 netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n", in asix_set_eeprom()
728 i, eeprom_buff[i - first_word]); in asix_set_eeprom()
730 eeprom_buff[i - first_word], 0, NULL, 0); in asix_set_eeprom()
732 netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n", in asix_set_eeprom()
755 strscpy(info->driver, DRIVER_NAME, sizeof(info->driver)); in asix_get_drvinfo()
756 strscpy(info->version, DRIVER_VERSION, sizeof(info->version)); in asix_get_drvinfo()
762 struct asix_data *data = (struct asix_data *)&dev->data; in asix_set_mac_address()
766 return -EBUSY; in asix_set_mac_address()
767 if (!is_valid_ether_addr(addr->sa_data)) in asix_set_mac_address()
768 return -EADDRNOTAVAIL; in asix_set_mac_address()
770 eth_hw_addr_set(net, addr->sa_data); in asix_set_mac_address()
772 /* We use the 20 byte dev->data in asix_set_mac_address()
776 memcpy(data->mac_addr, addr->sa_data, ETH_ALEN); in asix_set_mac_address()
778 data->mac_addr); in asix_set_mac_address()