Lines Matching +full:packet +full:- +full:based

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for USB ethernet port of Conexant CX82310-based ADSL routers
50 * - optionally send some data (command parameters)
51 * - optionally wait for the reply
52 * - optionally read some data from the reply
58 struct usb_device *udev = dev->udev; in cx82310_cmd()
62 return -ENOMEM; in cx82310_cmd()
64 /* create command packet */ in cx82310_cmd()
67 memcpy(buf + 4, wdata, min_t(int, wlen, CMD_PACKET_SIZE - 4)); in cx82310_cmd()
69 /* send command packet */ in cx82310_cmd()
74 netdev_err(dev->net, "send command %#x: error %d\n", in cx82310_cmd()
87 netdev_err(dev->net, "reply receive error %d\n", in cx82310_cmd()
95 netdev_err(dev->net, "no reply to command %#x\n", cmd); in cx82310_cmd()
96 ret = -EIO; in cx82310_cmd()
100 netdev_err(dev->net, "got reply to command %#x, expected: %#x\n", in cx82310_cmd()
102 ret = -EIO; in cx82310_cmd()
106 netdev_err(dev->net, "command %#x failed: %#x\n", cmd, in cx82310_cmd()
108 ret = -EIO; in cx82310_cmd()
113 min_t(int, rlen, CMD_PACKET_SIZE - 4)); in cx82310_cmd()
125 netdev_err(dev->net, "unable to enable ethernet mode: %d\n", in cx82310_enable_ethernet()
134 cx82310_enable_ethernet(priv->dev); in cx82310_reenable_work()
137 #define partial_len data[0] /* length of partial packet data */
139 #define partial_data data[2] /* partial packet data */
145 struct usb_device *udev = dev->udev; in cx82310_bind()
151 /* avoid ADSL modems - continue only if iProduct is "USB NET CARD" */ in cx82310_bind()
152 if (usb_string(udev, udev->descriptor.iProduct, buf, sizeof(buf)) > 0 in cx82310_bind()
154 dev_info(&udev->dev, "ignoring: probably an ADSL modem\n"); in cx82310_bind()
155 return -ENODEV; in cx82310_bind()
166 dev->net->hard_header_len = 0; in cx82310_bind()
167 /* we can send at most 1514 bytes of data (+ 2-byte header) per URB */ in cx82310_bind()
168 dev->hard_mtu = CX82310_MTU + 2; in cx82310_bind()
170 dev->rx_urb_size = 4096; in cx82310_bind()
172 dev->partial_data = (unsigned long) kmalloc(dev->hard_mtu, GFP_KERNEL); in cx82310_bind()
173 if (!dev->partial_data) in cx82310_bind()
174 return -ENOMEM; in cx82310_bind()
178 ret = -ENOMEM; in cx82310_bind()
181 dev->driver_priv = priv; in cx82310_bind()
182 INIT_WORK(&priv->reenable_work, cx82310_reenable_work); in cx82310_bind()
183 priv->dev = dev; in cx82310_bind()
186 while (--timeout) { in cx82310_bind()
189 /* the command can time out during boot - it's not an error */ in cx82310_bind()
195 netdev_err(dev->net, "firmware not ready in time\n"); in cx82310_bind()
196 ret = -ETIMEDOUT; in cx82310_bind()
208 netdev_err(dev->net, "unable to read MAC address: %d\n", ret); in cx82310_bind()
211 eth_hw_addr_set(dev->net, addr); in cx82310_bind()
220 kfree(dev->driver_priv); in cx82310_bind()
222 kfree((void *)dev->partial_data); in cx82310_bind()
228 struct cx82310_priv *priv = dev->driver_priv; in cx82310_unbind()
230 kfree((void *)dev->partial_data); in cx82310_unbind()
231 cancel_work_sync(&priv->reenable_work); in cx82310_unbind()
232 kfree(dev->driver_priv); in cx82310_unbind()
236 * RX is NOT easy - we can receive multiple packets per skb, each having 2-byte
237 * packet length at the beginning.
238 * The last packet might be incomplete (when it crosses the 4KB URB size),
240 * If a packet has odd length, there is one extra byte at the end (before next
241 * packet or at the end of the URB).
247 struct cx82310_priv *priv = dev->driver_priv; in cx82310_rx_fixup()
250 * If the last skb ended with an incomplete packet, this skb contains in cx82310_rx_fixup()
251 * end of that packet at the beginning. in cx82310_rx_fixup()
253 if (dev->partial_rem) { in cx82310_rx_fixup()
254 len = dev->partial_len + dev->partial_rem; in cx82310_rx_fixup()
259 memcpy(skb2->data, (void *)dev->partial_data, in cx82310_rx_fixup()
260 dev->partial_len); in cx82310_rx_fixup()
261 memcpy(skb2->data + dev->partial_len, skb->data, in cx82310_rx_fixup()
262 dev->partial_rem); in cx82310_rx_fixup()
264 skb_pull(skb, (dev->partial_rem + 1) & ~1); in cx82310_rx_fixup()
265 dev->partial_rem = 0; in cx82310_rx_fixup()
266 if (skb->len < 2) in cx82310_rx_fixup()
271 while (skb->len > 1) { in cx82310_rx_fixup()
272 /* first two bytes are packet length */ in cx82310_rx_fixup()
273 len = skb->data[0] | (skb->data[1] << 8); in cx82310_rx_fixup()
276 /* if last packet in the skb, let usbnet to process it */ in cx82310_rx_fixup()
277 if (len == skb->len || len + 1 == skb->len) { in cx82310_rx_fixup()
283 netdev_info(dev->net, "router was rebooted, re-enabling ethernet mode"); in cx82310_rx_fixup()
284 schedule_work(&priv->reenable_work); in cx82310_rx_fixup()
286 netdev_err(dev->net, "RX packet too long: %d B\n", len); in cx82310_rx_fixup()
290 /* incomplete packet, save it for the next skb */ in cx82310_rx_fixup()
291 if (len > skb->len) { in cx82310_rx_fixup()
292 dev->partial_len = skb->len; in cx82310_rx_fixup()
293 dev->partial_rem = len - skb->len; in cx82310_rx_fixup()
294 memcpy((void *)dev->partial_data, skb->data, in cx82310_rx_fixup()
295 dev->partial_len); in cx82310_rx_fixup()
296 skb_pull(skb, skb->len); in cx82310_rx_fixup()
304 memcpy(skb2->data, skb->data, len); in cx82310_rx_fixup()
305 /* process the packet */ in cx82310_rx_fixup()
311 /* let usbnet process the last packet */ in cx82310_rx_fixup()
319 int len = skb->len; in cx82310_tx_fixup()
327 skb->data[0] = len; in cx82310_tx_fixup()
328 skb->data[1] = len >> 8; in cx82310_tx_fixup()
374 MODULE_DESCRIPTION("Conexant CX82310-based ADSL router USB ethernet driver");