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.
29 netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n", in asix_read_cmd()
52 netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n", in asix_write_cmd()
73 if (rx->ax_skb) { in reset_asix_rx_fixup_info()
75 kfree_skb(rx->ax_skb); in reset_asix_rx_fixup_info()
76 rx->ax_skb = NULL; in reset_asix_rx_fixup_info()
79 /* Assume the Data header 32-bit word is at the start of the current in reset_asix_rx_fixup_info()
82 rx->remaining = 0; in reset_asix_rx_fixup_info()
83 rx->split_head = false; in reset_asix_rx_fixup_info()
84 rx->header = 0; in reset_asix_rx_fixup_info()
90 int offset = 0; in asix_rx_fixup_internal() local
102 if (rx->remaining && (rx->remaining + sizeof(u32) <= skb->len)) { in asix_rx_fixup_internal()
103 offset = ((rx->remaining + 1) & 0xfffe); in asix_rx_fixup_internal()
104 rx->header = get_unaligned_le32(skb->data + offset); in asix_rx_fixup_internal()
105 offset = 0; in asix_rx_fixup_internal()
107 size = (u16)(rx->header & 0x7ff); in asix_rx_fixup_internal()
108 if (size != ((~rx->header >> 16) & 0x7ff)) { in asix_rx_fixup_internal()
109 netdev_err(dev->net, "asix_rx_fixup() Data Header synchronisation was lost, remaining %d\n", in asix_rx_fixup_internal()
110 rx->remaining); in asix_rx_fixup_internal()
115 while (offset + sizeof(u16) <= skb->len) { in asix_rx_fixup_internal()
118 if (!rx->remaining) { in asix_rx_fixup_internal()
119 if (skb->len - offset == sizeof(u16)) { in asix_rx_fixup_internal()
120 rx->header = get_unaligned_le16( in asix_rx_fixup_internal()
121 skb->data + offset); in asix_rx_fixup_internal()
122 rx->split_head = true; in asix_rx_fixup_internal()
123 offset += sizeof(u16); in asix_rx_fixup_internal()
127 if (rx->split_head == true) { in asix_rx_fixup_internal()
128 rx->header |= (get_unaligned_le16( in asix_rx_fixup_internal()
129 skb->data + offset) << 16); in asix_rx_fixup_internal()
130 rx->split_head = false; in asix_rx_fixup_internal()
131 offset += sizeof(u16); in asix_rx_fixup_internal()
133 rx->header = get_unaligned_le32(skb->data + in asix_rx_fixup_internal()
134 offset); in asix_rx_fixup_internal()
135 offset += sizeof(u32); in asix_rx_fixup_internal()
138 /* take frame length from Data header 32-bit word */ in asix_rx_fixup_internal()
139 size = (u16)(rx->header & 0x7ff); in asix_rx_fixup_internal()
140 if (size != ((~rx->header >> 16) & 0x7ff)) { in asix_rx_fixup_internal()
141 netdev_err(dev->net, "asix_rx_fixup() Bad Header Length 0x%x, offset %d\n", in asix_rx_fixup_internal()
142 rx->header, offset); in asix_rx_fixup_internal()
146 if (size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) { in asix_rx_fixup_internal()
147 netdev_dbg(dev->net, "asix_rx_fixup() Bad RX Length %d\n", in asix_rx_fixup_internal()
158 rx->ax_skb = netdev_alloc_skb_ip_align(dev->net, size); in asix_rx_fixup_internal()
160 rx->remaining = size; in asix_rx_fixup_internal()
163 if (rx->remaining > skb->len - offset) { in asix_rx_fixup_internal()
164 copy_length = skb->len - offset; in asix_rx_fixup_internal()
165 rx->remaining -= copy_length; in asix_rx_fixup_internal()
167 copy_length = rx->remaining; in asix_rx_fixup_internal()
168 rx->remaining = 0; in asix_rx_fixup_internal()
171 if (rx->ax_skb) { in asix_rx_fixup_internal()
172 skb_put_data(rx->ax_skb, skb->data + offset, in asix_rx_fixup_internal()
174 if (!rx->remaining) { in asix_rx_fixup_internal()
175 usbnet_skb_return(dev, rx->ax_skb); in asix_rx_fixup_internal()
176 rx->ax_skb = NULL; in asix_rx_fixup_internal()
180 offset += (copy_length + 1) & 0xfffe; in asix_rx_fixup_internal()
183 if (skb->len != offset) { in asix_rx_fixup_internal()
184 netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d, %d\n", in asix_rx_fixup_internal()
185 skb->len, offset); in asix_rx_fixup_internal()
195 struct asix_common_private *dp = dev->driver_priv; in asix_rx_fixup_common()
196 struct asix_rx_fixup_info *rx = &dp->rx_fixup_info; in asix_rx_fixup_common()
208 rx = &dp->rx_fixup_info; in asix_rx_fixup_common_free()
210 if (rx->ax_skb) { in asix_rx_fixup_common_free()
211 kfree_skb(rx->ax_skb); in asix_rx_fixup_common_free()
212 rx->ax_skb = NULL; in asix_rx_fixup_common_free()
226 padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4; in asix_tx_fixup()
232 * - We are allowed to push 4 bytes in headroom if skb_header_cloned() in asix_tx_fixup()
234 * - We are allowed to put 4 bytes at tail if skb_cloned() in asix_tx_fixup()
246 skb->data = memmove(skb->head + 4, skb->data, skb->len); in asix_tx_fixup()
247 skb_set_tail_pointer(skb, skb->len); in asix_tx_fixup()
259 packet_len = ((skb->len ^ 0x0000ffff) << 16) + skb->len; in asix_tx_fixup()
278 netdev_err(dev->net, "Failed to enable software MII access\n"); in asix_set_sw_mii()
287 netdev_err(dev->net, "Failed to enable hardware MII access\n"); in asix_set_hw_mii()
293 int offset = (internal ? 1 : 0); in asix_read_phy_addr() local
297 netdev_dbg(dev->net, "asix_get_phy_addr()\n"); in asix_read_phy_addr()
300 netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret); in asix_read_phy_addr()
303 netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n", in asix_read_phy_addr()
305 ret = buf[offset]; in asix_read_phy_addr()
324 netdev_err(dev->net, "Failed to send software reset: %02x\n", ret); in asix_sw_reset()
335 netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret); in asix_read_rx_ctl()
347 netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode); in asix_write_rx_ctl()
350 netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n", in asix_write_rx_ctl()
363 netdev_err(dev->net, "Error reading Medium Status register: %02x\n", in asix_read_medium_status()
376 netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode); in asix_write_medium_mode()
380 netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n", in asix_write_medium_mode()
390 netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value); in asix_write_gpio()
393 netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n", in asix_write_gpio()
403 * AX88772 & AX88178 have a 16-bit RX_CTL value
408 struct asix_data *data = (struct asix_data *)&dev->data; in asix_set_multicast()
411 if (net->flags & IFF_PROMISC) { in asix_set_multicast()
413 } else if (net->flags & IFF_ALLMULTI || in asix_set_multicast()
419 /* We use the 20 byte dev->data in asix_set_multicast()
426 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); in asix_set_multicast()
430 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26; in asix_set_multicast()
431 data->multi_filter[crc_bits >> 3] |= in asix_set_multicast()
436 AX_MCAST_FILTER_SIZE, data->multi_filter); in asix_set_multicast()
452 mutex_lock(&dev->phy_mutex); in asix_mdio_read()
455 if (ret == -ENODEV || ret == -ETIMEDOUT) in asix_mdio_read()
460 } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV)); in asix_mdio_read()
461 if (ret == -ENODEV || ret == -ETIMEDOUT) { in asix_mdio_read()
462 mutex_unlock(&dev->phy_mutex); in asix_mdio_read()
469 mutex_unlock(&dev->phy_mutex); in asix_mdio_read()
471 netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", in asix_mdio_read()
485 netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", in asix_mdio_write()
488 mutex_lock(&dev->phy_mutex); in asix_mdio_write()
491 if (ret == -ENODEV) in asix_mdio_write()
496 } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV)); in asix_mdio_write()
497 if (ret == -ENODEV) { in asix_mdio_write()
498 mutex_unlock(&dev->phy_mutex); in asix_mdio_write()
505 mutex_unlock(&dev->phy_mutex); in asix_mdio_write()
516 mutex_lock(&dev->phy_mutex); in asix_mdio_read_nopm()
519 if (ret == -ENODEV || ret == -ETIMEDOUT) in asix_mdio_read_nopm()
524 } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV)); in asix_mdio_read_nopm()
525 if (ret == -ENODEV || ret == -ETIMEDOUT) { in asix_mdio_read_nopm()
526 mutex_unlock(&dev->phy_mutex); in asix_mdio_read_nopm()
533 mutex_unlock(&dev->phy_mutex); in asix_mdio_read_nopm()
535 netdev_dbg(dev->net, "asix_mdio_read_nopm() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", in asix_mdio_read_nopm()
550 netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", in asix_mdio_write_nopm()
553 mutex_lock(&dev->phy_mutex); in asix_mdio_write_nopm()
556 if (ret == -ENODEV) in asix_mdio_write_nopm()
561 } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV)); in asix_mdio_write_nopm()
562 if (ret == -ENODEV) { in asix_mdio_write_nopm()
563 mutex_unlock(&dev->phy_mutex); in asix_mdio_write_nopm()
570 mutex_unlock(&dev->phy_mutex); in asix_mdio_write_nopm()
580 wolinfo->supported = 0; in asix_get_wol()
581 wolinfo->wolopts = 0; in asix_get_wol()
584 wolinfo->supported = WAKE_PHY | WAKE_MAGIC; in asix_get_wol()
585 wolinfo->wolopts = 0; in asix_get_wol()
587 wolinfo->wolopts |= WAKE_PHY; in asix_get_wol()
589 wolinfo->wolopts |= WAKE_MAGIC; in asix_get_wol()
597 if (wolinfo->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) in asix_set_wol()
598 return -EINVAL; in asix_set_wol()
600 if (wolinfo->wolopts & WAKE_PHY) in asix_set_wol()
602 if (wolinfo->wolopts & WAKE_MAGIC) in asix_set_wol()
607 return -EINVAL; in asix_set_wol()
625 if (eeprom->len == 0) in asix_get_eeprom()
626 return -EINVAL; in asix_get_eeprom()
628 eeprom->magic = AX_EEPROM_MAGIC; in asix_get_eeprom()
630 first_word = eeprom->offset >> 1; in asix_get_eeprom()
631 last_word = (eeprom->offset + eeprom->len - 1) >> 1; in asix_get_eeprom()
633 eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), in asix_get_eeprom()
636 return -ENOMEM; in asix_get_eeprom()
641 &eeprom_buff[i - first_word], 0) < 0) { in asix_get_eeprom()
643 return -EIO; in asix_get_eeprom()
647 memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); in asix_get_eeprom()
661 netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n", in asix_set_eeprom()
662 eeprom->len, eeprom->offset, eeprom->magic); in asix_set_eeprom()
664 if (eeprom->len == 0) in asix_set_eeprom()
665 return -EINVAL; in asix_set_eeprom()
667 if (eeprom->magic != AX_EEPROM_MAGIC) in asix_set_eeprom()
668 return -EINVAL; in asix_set_eeprom()
670 first_word = eeprom->offset >> 1; in asix_set_eeprom()
671 last_word = (eeprom->offset + eeprom->len - 1) >> 1; in asix_set_eeprom()
673 eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), in asix_set_eeprom()
676 return -ENOMEM; in asix_set_eeprom()
680 if (eeprom->offset & 1) { in asix_set_eeprom()
684 netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word); in asix_set_eeprom()
689 if ((eeprom->offset + eeprom->len) & 1) { in asix_set_eeprom()
691 &eeprom_buff[last_word - first_word], 0); in asix_set_eeprom()
693 netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word); in asix_set_eeprom()
698 memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len); in asix_set_eeprom()
709 netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n", in asix_set_eeprom()
710 i, eeprom_buff[i - first_word]); in asix_set_eeprom()
712 eeprom_buff[i - first_word], 0, NULL, 0); in asix_set_eeprom()
714 netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n", in asix_set_eeprom()
737 strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver)); in asix_get_drvinfo()
738 strlcpy(info->version, DRIVER_VERSION, sizeof(info->version)); in asix_get_drvinfo()
744 struct asix_data *data = (struct asix_data *)&dev->data; in asix_set_mac_address()
748 return -EBUSY; in asix_set_mac_address()
749 if (!is_valid_ether_addr(addr->sa_data)) in asix_set_mac_address()
750 return -EADDRNOTAVAIL; in asix_set_mac_address()
752 memcpy(net->dev_addr, addr->sa_data, ETH_ALEN); in asix_set_mac_address()
754 /* We use the 20 byte dev->data in asix_set_mac_address()
758 memcpy(data->mac_addr, addr->sa_data, ETH_ALEN); in asix_set_mac_address()
760 data->mac_addr); in asix_set_mac_address()