iPXE
ncm.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27#include <string.h>
28#include <errno.h>
29#include <ipxe/netdevice.h>
30#include <ipxe/ethernet.h>
31#include <ipxe/if_ether.h>
32#include <ipxe/profile.h>
33#include <ipxe/usb.h>
34#include <ipxe/usbnet.h>
35#include "ecm.h"
36#include "ncm.h"
37
38/** @file
39 *
40 * CDC-NCM USB Ethernet driver
41 *
42 */
43
44/** Interrupt completion profiler */
45static struct profiler ncm_intr_profiler __profiler =
46 { .name = "ncm.intr" };
47
48/** Bulk IN completion profiler */
49static struct profiler ncm_in_profiler __profiler =
50 { .name = "ncm.in" };
51
52/** Bulk IN per-datagram profiler */
53static struct profiler ncm_in_datagram_profiler __profiler =
54 { .name = "ncm.in_dgram" };
55
56/** Bulk OUT profiler */
57static struct profiler ncm_out_profiler __profiler =
58 { .name = "ncm.out" };
59
60/******************************************************************************
61 *
62 * CDC-NCM communications interface
63 *
64 ******************************************************************************
65 */
66
67/**
68 * Complete interrupt transfer
69 *
70 * @v ep USB endpoint
71 * @v iobuf I/O buffer
72 * @v rc Completion status code
73 */
74static void ncm_intr_complete ( struct usb_endpoint *ep,
75 struct io_buffer *iobuf, int rc ) {
76 struct ncm_device *ncm = container_of ( ep, struct ncm_device,
77 usbnet.intr );
78 struct net_device *netdev = ncm->netdev;
80 size_t len = iob_len ( iobuf );
81
82 /* Profile completions */
83 profile_start ( &ncm_intr_profiler );
84
85 /* Ignore packets cancelled when the endpoint closes */
86 if ( ! ep->open )
87 goto ignore;
88
89 /* Ignore packets with errors */
90 if ( rc != 0 ) {
91 DBGC ( ncm, "NCM %p interrupt failed: %s\n",
92 ncm, strerror ( rc ) );
93 DBGC_HDA ( ncm, 0, iobuf->data, iob_len ( iobuf ) );
94 goto error;
95 }
96
97 /* Extract message header */
98 if ( len < sizeof ( *message ) ) {
99 DBGC ( ncm, "NCM %p underlength interrupt:\n", ncm );
100 DBGC_HDA ( ncm, 0, iobuf->data, iob_len ( iobuf ) );
101 rc = -EINVAL;
102 goto error;
103 }
104 message = iobuf->data;
105
106 /* Parse message header */
107 switch ( message->request ) {
108
110 if ( message->value ) {
111 DBGC ( ncm, "NCM %p link up\n", ncm );
113 } else {
114 DBGC ( ncm, "NCM %p link down\n", ncm );
116 }
117 break;
118
120 /* Ignore */
121 break;
122
123 default:
124 DBGC ( ncm, "NCM %p unrecognised interrupt:\n", ncm );
125 DBGC_HDA ( ncm, 0, iobuf->data, iob_len ( iobuf ) );
126 goto error;
127 }
128
129 /* Free I/O buffer */
130 free_iob ( iobuf );
131 profile_stop ( &ncm_intr_profiler );
132
133 return;
134
135 error:
136 netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
137 ignore:
138 free_iob ( iobuf );
139 return;
140}
141
142/** Interrupt endpoint operations */
146
147/******************************************************************************
148 *
149 * CDC-NCM data interface
150 *
151 ******************************************************************************
152 */
153
154/**
155 * Prefill bulk IN endpoint
156 *
157 * @v ncm CDC-NCM device
158 * @ret rc Return status code
159 */
160static int ncm_in_prefill ( struct ncm_device *ncm ) {
161 struct usb_bus *bus = ncm->bus;
162 size_t mtu;
163 unsigned int count;
164 int rc;
165
166 /* Some devices have a very small number of internal buffers,
167 * and rely on being able to pack multiple packets into each
168 * buffer. We therefore want to use large buffers if
169 * possible. However, large allocations have a reasonable
170 * chance of failure, especially if this is not the first or
171 * only device to be opened.
172 *
173 * We therefore attempt to find a usable buffer size, starting
174 * large and working downwards until allocation succeeds.
175 * Smaller buffers will still work, albeit with a higher
176 * chance of packet loss and so lower overall throughput.
177 */
178 for ( mtu = ncm->mtu ; mtu >= NCM_MIN_NTB_INPUT_SIZE ; mtu >>= 1 ) {
179
180 /* Attempt allocation at this MTU */
182 continue;
183 if ( mtu > bus->mtu )
184 continue;
185 count = ( NCM_IN_MIN_SIZE / mtu );
186 if ( count < NCM_IN_MIN_COUNT )
188 if ( ( count * mtu ) > NCM_IN_MAX_SIZE )
189 continue;
190 usb_refill_init ( &ncm->usbnet.in, 0, mtu, count );
191 if ( ( rc = usb_prefill ( &ncm->usbnet.in ) ) != 0 ) {
192 DBGC ( ncm, "NCM %p could not prefill %dx %zd-byte "
193 "buffers for bulk IN\n", ncm, count, mtu );
194 continue;
195 }
196
197 DBGC ( ncm, "NCM %p using %dx %zd-byte buffers for bulk IN\n",
198 ncm, count, mtu );
199 return 0;
200 }
201
202 DBGC ( ncm, "NCM %p could not prefill bulk IN endpoint\n", ncm );
203 return -ENOMEM;
204}
205
206/**
207 * Complete bulk IN transfer
208 *
209 * @v ep USB endpoint
210 * @v iobuf I/O buffer
211 * @v rc Completion status code
212 */
213static void ncm_in_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf,
214 int rc ) {
215 struct ncm_device *ncm = container_of ( ep, struct ncm_device,
216 usbnet.in );
217 struct net_device *netdev = ncm->netdev;
218 struct ncm_transfer_header *nth;
219 struct ncm_datagram_pointer *ndp;
221 struct io_buffer *pkt;
222 unsigned int remaining;
223 size_t ndp_offset;
224 size_t ndp_len;
225 size_t pkt_offset;
226 size_t pkt_len;
227 size_t headroom;
228 size_t len;
229
230 /* Profile overall bulk IN completion */
231 profile_start ( &ncm_in_profiler );
232
233 /* Ignore packets cancelled when the endpoint closes */
234 if ( ! ep->open )
235 goto ignore;
236
237 /* Record USB errors against the network device */
238 if ( rc != 0 ) {
239 DBGC ( ncm, "NCM %p bulk IN failed: %s\n",
240 ncm, strerror ( rc ) );
241 goto error;
242 }
243
244 /* Locate transfer header */
245 len = iob_len ( iobuf );
246 if ( sizeof ( *nth ) > len ) {
247 DBGC ( ncm, "NCM %p packet too short for NTH:\n", ncm );
248 rc = -EINVAL;
249 goto error;
250 }
251 nth = iobuf->data;
252
253 /* Locate datagram pointer */
254 ndp_offset = le16_to_cpu ( nth->offset );
255 if ( ( ndp_offset + sizeof ( *ndp ) ) > len ) {
256 DBGC ( ncm, "NCM %p packet too short for NDP:\n", ncm );
257 rc = -EINVAL;
258 goto error;
259 }
260 ndp = ( iobuf->data + ndp_offset );
261 ndp_len = le16_to_cpu ( ndp->header_len );
262 if ( ndp_len < offsetof ( typeof ( *ndp ), desc ) ) {
263 DBGC ( ncm, "NCM %p NDP header length too short:\n", ncm );
264 rc = -EINVAL;
265 goto error;
266 }
267 if ( ( ndp_offset + ndp_len ) > len ) {
268 DBGC ( ncm, "NCM %p packet too short for NDP:\n", ncm );
269 rc = -EINVAL;
270 goto error;
271 }
272
273 /* Process datagrams */
274 remaining = ( ( ndp_len - offsetof ( typeof ( *ndp ), desc ) ) /
275 sizeof ( ndp->desc[0] ) );
276 for ( desc = ndp->desc ; remaining && desc->offset ; remaining-- ) {
277
278 /* Profile individual datagrams */
279 profile_start ( &ncm_in_datagram_profiler );
280
281 /* Locate datagram */
282 pkt_offset = le16_to_cpu ( desc->offset );
283 pkt_len = le16_to_cpu ( desc->len );
284 if ( pkt_len < ETH_HLEN ) {
285 DBGC ( ncm, "NCM %p underlength datagram:\n", ncm );
286 rc = -EINVAL;
287 goto error;
288 }
289 if ( ( pkt_offset + pkt_len ) > len ) {
290 DBGC ( ncm, "NCM %p datagram exceeds packet:\n", ncm );
291 rc = -EINVAL;
292 goto error;
293 }
294
295 /* Move to next descriptor */
296 desc++;
297
298 /* Copy data to a new I/O buffer. Our USB buffers may
299 * be very large and so we choose to recycle the
300 * buffers directly rather than attempt reallocation
301 * while the device is running. We therefore copy the
302 * data to a new I/O buffer even if this is the only
303 * (or last) packet within the buffer.
304 *
305 * We reserve enough space at the start of each buffer
306 * to allow for our own transmission header, to
307 * support protocols such as ARP which may modify the
308 * received packet and reuse the same I/O buffer for
309 * transmission.
310 */
311 headroom = ( sizeof ( struct ncm_ntb_header ) + ncm->padding );
312 pkt = alloc_iob ( headroom + pkt_len );
313 if ( ! pkt ) {
314 /* Record error and continue */
316 continue;
317 }
318 iob_reserve ( pkt, headroom );
319 memcpy ( iob_put ( pkt, pkt_len ),
320 ( iobuf->data + pkt_offset ), pkt_len );
321
322 /* Strip CRC, if present */
324 iob_unput ( pkt, 4 /* CRC32 */ );
325
326 /* Hand off to network stack */
327 netdev_rx ( netdev, pkt );
328 profile_stop ( &ncm_in_datagram_profiler );
329 }
330
331 /* Recycle I/O buffer */
332 usb_recycle ( &ncm->usbnet.in, iobuf );
333 profile_stop ( &ncm_in_profiler );
334
335 return;
336
337 error:
338 /* Record error against network device */
339 DBGC_HDA ( ncm, 0, iobuf->data, iob_len ( iobuf ) );
341 ignore:
342 usb_recycle ( &ncm->usbnet.in, iobuf );
343}
344
345/** Bulk IN endpoint operations */
347 .complete = ncm_in_complete,
348};
349
350/**
351 * Transmit packet
352 *
353 * @v ncm CDC-NCM device
354 * @v iobuf I/O buffer
355 * @ret rc Return status code
356 */
357static int ncm_out_transmit ( struct ncm_device *ncm,
358 struct io_buffer *iobuf ) {
359 struct ncm_ntb_header *header;
360 size_t len = iob_len ( iobuf );
361 size_t header_len = ( sizeof ( *header ) + ncm->padding );
362 int rc;
363
364 /* Profile transmissions */
365 profile_start ( &ncm_out_profiler );
366
367 /* Prepend header */
368 if ( ( rc = iob_ensure_headroom ( iobuf, header_len ) ) != 0 )
369 return rc;
370 header = iob_push ( iobuf, header_len );
371
372 /* Populate header */
374 header->nth.header_len = cpu_to_le16 ( sizeof ( header->nth ) );
375 header->nth.sequence = cpu_to_le16 ( ncm->sequence );
376 header->nth.len = cpu_to_le16 ( iob_len ( iobuf ) );
377 header->nth.offset =
378 cpu_to_le16 ( offsetof ( typeof ( *header ), ndp ) );
380 header->ndp.header_len = cpu_to_le16 ( sizeof ( header->ndp ) +
381 sizeof ( header->desc ) );
382 header->ndp.offset = cpu_to_le16 ( 0 );
383 header->desc[0].offset = cpu_to_le16 ( header_len );
384 header->desc[0].len = cpu_to_le16 ( len );
385 memset ( &header->desc[1], 0, sizeof ( header->desc[1] ) );
386
387 /* Enqueue I/O buffer */
388 if ( ( rc = usb_stream ( &ncm->usbnet.out, iobuf, 0 ) ) != 0 )
389 return rc;
390
391 /* Increment sequence number */
392 ncm->sequence++;
393
394 profile_stop ( &ncm_out_profiler );
395 return 0;
396}
397
398/**
399 * Complete bulk OUT transfer
400 *
401 * @v ep USB endpoint
402 * @v iobuf I/O buffer
403 * @v rc Completion status code
404 */
405static void ncm_out_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf,
406 int rc ) {
407 struct ncm_device *ncm = container_of ( ep, struct ncm_device,
408 usbnet.out );
409 struct net_device *netdev = ncm->netdev;
410
411 /* Report TX completion */
412 netdev_tx_complete_err ( netdev, iobuf, rc );
413}
414
415/** Bulk OUT endpoint operations */
419
420/******************************************************************************
421 *
422 * Network device interface
423 *
424 ******************************************************************************
425 */
426
427/**
428 * Open network device
429 *
430 * @v netdev Network device
431 * @ret rc Return status code
432 */
433static int ncm_open ( struct net_device *netdev ) {
434 struct ncm_device *ncm = netdev->priv;
435 struct usb_device *usb = ncm->usb;
437 int rc;
438
439 /* Reset sequence number */
440 ncm->sequence = 0;
441
442 /* Prefill I/O buffers */
443 if ( ( rc = ncm_in_prefill ( ncm ) ) != 0 )
444 goto err_prefill;
445
446 /* Set maximum input size */
447 memset ( &size, 0, sizeof ( size ) );
448 size.mtu = cpu_to_le32 ( ncm->usbnet.in.len );
449 if ( ( rc = usb_control ( usb, NCM_SET_NTB_INPUT_SIZE, 0,
450 ncm->usbnet.comms, &size,
451 sizeof ( size ) ) ) != 0 ) {
452 DBGC ( ncm, "NCM %p could not set input size to %zd: %s\n",
453 ncm, ncm->usbnet.in.len, strerror ( rc ) );
454 goto err_set_ntb_input_size;
455 }
456
457 /* Set MAC address */
458 if ( ( rc = usb_control ( usb, NCM_SET_NET_ADDRESS, 0,
459 ncm->usbnet.comms, netdev->ll_addr,
460 netdev->ll_protocol->ll_addr_len ) ) != 0 ) {
461 DBGC ( ncm, "NCM %p could not set MAC address: %s\n",
462 ncm, strerror ( rc ) );
463 /* Ignore error and continue */
464 }
465
466 /* Open USB network device */
467 if ( ( rc = usbnet_open ( &ncm->usbnet ) ) != 0 ) {
468 DBGC ( ncm, "NCM %p could not open: %s\n",
469 ncm, strerror ( rc ) );
470 goto err_open;
471 }
472
473 return 0;
474
475 usbnet_close ( &ncm->usbnet );
476 err_open:
477 err_set_ntb_input_size:
478 usb_flush ( &ncm->usbnet.in );
479 err_prefill:
480 return rc;
481}
482
483/**
484 * Close network device
485 *
486 * @v netdev Network device
487 */
488static void ncm_close ( struct net_device *netdev ) {
489 struct ncm_device *ncm = netdev->priv;
490
491 /* Close USB network device */
492 usbnet_close ( &ncm->usbnet );
493}
494
495/**
496 * Transmit packet
497 *
498 * @v netdev Network device
499 * @v iobuf I/O buffer
500 * @ret rc Return status code
501 */
502static int ncm_transmit ( struct net_device *netdev,
503 struct io_buffer *iobuf ) {
504 struct ncm_device *ncm = netdev->priv;
505 int rc;
506
507 /* Transmit packet */
508 if ( ( rc = ncm_out_transmit ( ncm, iobuf ) ) != 0 )
509 return rc;
510
511 return 0;
512}
513
514/**
515 * Poll for completed and received packets
516 *
517 * @v netdev Network device
518 */
519static void ncm_poll ( struct net_device *netdev ) {
520 struct ncm_device *ncm = netdev->priv;
521 int rc;
522
523 /* Poll USB bus */
524 usb_poll ( ncm->bus );
525
526 /* Refill endpoints */
527 if ( ( rc = usbnet_refill ( &ncm->usbnet ) ) != 0 )
529
530}
531
532/** CDC-NCM network device operations */
534 .open = ncm_open,
535 .close = ncm_close,
536 .transmit = ncm_transmit,
537 .poll = ncm_poll,
538};
539
540/******************************************************************************
541 *
542 * USB interface
543 *
544 ******************************************************************************
545 */
546
547/**
548 * Probe device
549 *
550 * @v func USB function
551 * @v config Configuration descriptor
552 * @ret rc Return status code
553 */
554static int ncm_probe ( struct usb_function *func,
555 struct usb_configuration_descriptor *config ) {
556 struct usb_device *usb = func->usb;
557 struct net_device *netdev;
558 struct ncm_device *ncm;
559 struct usb_interface_descriptor *comms;
560 struct ecm_ethernet_descriptor *ethernet;
561 struct ncm_ntb_parameters params;
562 unsigned int remainder;
563 unsigned int divisor;
564 int rc;
565
566 /* Allocate and initialise structure */
567 netdev = alloc_etherdev ( sizeof ( *ncm ) );
568 if ( ! netdev ) {
569 rc = -ENOMEM;
570 goto err_alloc;
571 }
573 netdev->dev = &func->dev;
574 ncm = netdev->priv;
575 memset ( ncm, 0, sizeof ( *ncm ) );
576 ncm->usb = usb;
577 ncm->bus = usb->port->hub->bus;
578 ncm->netdev = netdev;
579 usbnet_init ( &ncm->usbnet, func, &ncm_intr_operations,
581 usb_refill_init ( &ncm->usbnet.intr, 0, 0, NCM_INTR_COUNT );
582 DBGC ( ncm, "NCM %p on %s\n", ncm, func->name );
583
584 /* Describe USB network device */
585 if ( ( rc = usbnet_describe ( &ncm->usbnet, config ) ) != 0 ) {
586 DBGC ( ncm, "NCM %p could not describe: %s\n",
587 ncm, strerror ( rc ) );
588 goto err_describe;
589 }
590
591 /* Locate Ethernet descriptor */
592 comms = usb_interface_descriptor ( config, ncm->usbnet.comms, 0 );
593 assert ( comms != NULL );
594 ethernet = ecm_ethernet_descriptor ( config, comms );
595 if ( ! ethernet ) {
596 DBGC ( ncm, "NCM %p has no Ethernet descriptor\n", ncm );
597 rc = -EINVAL;
598 goto err_ethernet;
599 }
600
601 /* Fetch MAC address */
602 if ( ( rc = ecm_fetch_mac ( func, ethernet, netdev ) ) != 0 ) {
603 DBGC ( ncm, "NCM %p could not fetch MAC address: %s\n",
604 ncm, strerror ( rc ) );
605 goto err_fetch_mac;
606 }
607
608 /* Get NTB parameters */
609 if ( ( rc = usb_control ( usb, NCM_GET_NTB_PARAMETERS, 0,
610 ncm->usbnet.comms, &params,
611 sizeof ( params ) ) ) != 0 ) {
612 DBGC ( ncm, "NCM %p could not get NTB parameters: %s\n",
613 ncm, strerror ( rc ) );
614 goto err_ntb_parameters;
615 }
616
617 /* Get maximum supported input size */
618 ncm->mtu = le32_to_cpu ( params.in.mtu );
619 DBGC2 ( ncm, "NCM %p maximum IN size is %zd bytes\n", ncm, ncm->mtu );
620
621 /* Calculate transmit padding */
622 divisor = ( params.out.divisor ?
623 le16_to_cpu ( params.out.divisor ) : 1 );
624 remainder = le16_to_cpu ( params.out.remainder );
625 ncm->padding = ( ( remainder - sizeof ( struct ncm_ntb_header ) -
626 ETH_HLEN ) & ( divisor - 1 ) );
627 DBGC2 ( ncm, "NCM %p using %zd-byte transmit padding\n",
628 ncm, ncm->padding );
629 assert ( ( ( sizeof ( struct ncm_ntb_header ) + ncm->padding +
630 ETH_HLEN ) % divisor ) == remainder );
631
632 /* Register network device */
633 if ( ( rc = register_netdev ( netdev ) ) != 0 )
634 goto err_register;
635
636 usb_func_set_drvdata ( func, ncm );
637 return 0;
638
640 err_register:
641 err_ntb_parameters:
642 err_fetch_mac:
643 err_ethernet:
644 err_describe:
646 netdev_put ( netdev );
647 err_alloc:
648 return rc;
649}
650
651/**
652 * Remove device
653 *
654 * @v func USB function
655 */
656static void ncm_remove ( struct usb_function *func ) {
657 struct ncm_device *ncm = usb_func_get_drvdata ( func );
658 struct net_device *netdev = ncm->netdev;
659
662 netdev_put ( netdev );
663}
664
665/** CDC-NCM device IDs */
666static struct usb_device_id ncm_ids[] = {
667 USB_ROM ( 0xffff, 0xffff, "cdc-ncm", "USB CDC-NCM NIC", 0 ),
668};
669
670/** CDC-NCM driver */
671struct usb_driver ncm_driver __usb_driver = {
672 .ids = ncm_ids,
673 .id_count = ( sizeof ( ncm_ids ) / sizeof ( ncm_ids[0] ) ),
675 .score = USB_SCORE_NORMAL,
676 .probe = ncm_probe,
677 .remove = ncm_remove,
678};
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
uint16_t pkt_len
Definition aqc1xx.h:2
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
struct arbelprm_completion_with_error error
Definition arbel.h:1
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define CDC_NETWORK_CONNECTION
Network connection notification.
Definition cdc.h:50
#define USB_CLASS_CDC
Class code for communications devices.
Definition cdc.h:16
#define CDC_CONNECTION_SPEED_CHANGE
Connection speed change notification.
Definition cdc.h:55
ring len
Length.
Definition dwmac.h:226
int ecm_fetch_mac(struct usb_function *func, struct ecm_ethernet_descriptor *desc, struct net_device *netdev)
Get hardware MAC address.
Definition ecm.c:91
struct ecm_ethernet_descriptor * ecm_ethernet_descriptor(struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface)
Locate Ethernet functional descriptor.
Definition ecm.c:71
CDC-ECM USB Ethernet driver.
uint8_t bus
Bus.
Definition edd.h:1
uint32_t mtu
Maximum MTU.
Definition ena.h:17
struct ena_llq_option header
Header locations.
Definition ena.h:5
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
Error codes.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
Ethernet protocol.
static struct net_device * netdev
Definition gdbudp.c:53
#define DBGC2(...)
Definition compiler.h:522
#define DBGC(...)
Definition compiler.h:505
#define DBGC_HDA(...)
Definition compiler.h:506
uint16_t size
Buffer size.
Definition dwmac.h:3
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ENOMEM
Not enough space.
Definition errno.h:535
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define ETH_HLEN
Definition if_ether.h:10
#define le16_to_cpu(value)
Definition byteswap.h:113
#define le32_to_cpu(value)
Definition byteswap.h:114
#define cpu_to_le32(value)
Definition byteswap.h:108
#define cpu_to_le16(value)
Definition byteswap.h:107
Profiling.
#define __profiler
Declare a profiler.
Definition profile.h:61
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition profile.h:174
static void profile_start(struct profiler *profiler)
Start profiling.
Definition profile.h:161
Universal Serial Bus (USB)
static void usb_recycle(struct usb_endpoint *ep, struct io_buffer *iobuf)
Recycle I/O buffer.
Definition usb.h:633
#define __usb_driver
Declare a USB driver.
Definition usb.h:1453
static void usb_refill_init(struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
Initialise USB endpoint refill.
Definition usb.h:617
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition usb.h:1401
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition usb.h:1072
#define USB_ROM(_vendor, _product, _name, _description, _data)
Definition usb.h:1381
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition usb.h:707
@ USB_SCORE_NORMAL
Normal driver.
Definition usb.h:1465
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition usb.h:718
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
int iob_ensure_headroom(struct io_buffer *iobuf, size_t len)
Ensure I/O buffer has sufficient headroom.
Definition iobuf.c:235
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition iobuf.c:131
#define iob_push(iobuf, len)
Definition iobuf.h:89
#define iob_put(iobuf, len)
Definition iobuf.h:125
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition iobuf.h:217
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
#define iob_reserve(iobuf, len)
Definition iobuf.h:72
#define iob_unput(iobuf, len)
Definition iobuf.h:140
static struct usb_endpoint_driver_operations ncm_in_operations
Bulk IN endpoint operations.
Definition ncm.c:346
static int ncm_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition ncm.c:554
static struct usb_endpoint_driver_operations ncm_intr_operations
Interrupt endpoint operations.
Definition ncm.c:143
static void ncm_out_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk OUT transfer.
Definition ncm.c:405
static void ncm_remove(struct usb_function *func)
Remove device.
Definition ncm.c:656
static void ncm_close(struct net_device *netdev)
Close network device.
Definition ncm.c:488
static int ncm_out_transmit(struct ncm_device *ncm, struct io_buffer *iobuf)
Transmit packet.
Definition ncm.c:357
static int ncm_in_prefill(struct ncm_device *ncm)
Prefill bulk IN endpoint.
Definition ncm.c:160
static int ncm_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition ncm.c:502
static void ncm_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition ncm.c:519
static struct usb_endpoint_driver_operations ncm_out_operations
Bulk OUT endpoint operations.
Definition ncm.c:416
static struct net_device_operations ncm_operations
CDC-NCM network device operations.
Definition ncm.c:533
static void ncm_in_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk IN transfer.
Definition ncm.c:213
static void ncm_intr_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete interrupt transfer.
Definition ncm.c:74
static int ncm_open(struct net_device *netdev)
Open network device.
Definition ncm.c:433
static struct usb_device_id ncm_ids[]
CDC-NCM device IDs.
Definition ncm.c:666
CDC-NCM USB Ethernet driver.
#define NCM_DATAGRAM_POINTER_MAGIC_CRC
CDC-NCM datagram pointer CRC present flag.
Definition ncm.h:121
#define NCM_TRANSFER_HEADER_MAGIC
CDC-NCM transfer header magic.
Definition ncm.h:92
#define NCM_INTR_COUNT
Interrupt ring buffer count.
Definition ncm.h:177
#define NCM_DATAGRAM_POINTER_MAGIC
CDC-NCM datagram pointer magic.
Definition ncm.h:118
#define NCM_IN_MAX_SIZE
Bulk IN ring maximum total buffer size.
Definition ncm.h:171
#define USB_SUBCLASS_CDC_NCM
CDC-NCM subclass.
Definition ncm.h:20
#define NCM_IN_MIN_SIZE
Bulk IN ring minimum total buffer size.
Definition ncm.h:165
#define NCM_GET_NTB_PARAMETERS
Get NTB parameters.
Definition ncm.h:23
#define NCM_SET_NET_ADDRESS
Set MAC address.
Definition ncm.h:56
#define NCM_IN_MIN_COUNT
Bulk IN ring minimum buffer count.
Definition ncm.h:159
#define NCM_MIN_NTB_INPUT_SIZE
Minimum allowed NTB input size.
Definition ncm.h:72
#define NCM_SET_NTB_INPUT_SIZE
Set NTB input size.
Definition ncm.h:61
#define NCM_MAX_NTB_INPUT_SIZE
Maximum allowed NTB input size (16-bit)
Definition ncm.h:75
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition netdevice.c:231
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition netdevice.c:471
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
Network device management.
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:789
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
#define offsetof(type, field)
Get offset of a field within a structure.
Definition stddef.h:25
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
An Ethernet Functional Descriptor.
Definition ecm.h:40
A persistent I/O buffer.
Definition iobuf.h:38
void * data
Start of data.
Definition iobuf.h:53
CDC-NCM datagram descriptor (16-bit)
Definition ncm.h:95
CDC-NCM datagram pointer (16-bit)
Definition ncm.h:103
struct ncm_datagram_descriptor desc[0]
Datagram descriptors.
Definition ncm.h:114
uint16_t header_len
Header length.
Definition ncm.h:107
uint32_t magic
Signature.
Definition ncm.h:105
A CDC-NCM network device.
Definition ncm.h:137
struct net_device * netdev
Network device.
Definition ncm.h:143
struct usb_device * usb
USB device.
Definition ncm.h:139
struct usb_bus * bus
USB bus.
Definition ncm.h:141
size_t mtu
Maximum supported NTB input size.
Definition ncm.h:148
uint16_t sequence
Transmitted packet sequence number.
Definition ncm.h:150
size_t padding
Alignment padding required on transmitted packets.
Definition ncm.h:152
struct usbnet_device usbnet
USB network device.
Definition ncm.h:145
uint16_t remainder
Alignment remainder.
Definition ncm.h:34
uint32_t mtu
Maximum size.
Definition ncm.h:30
uint16_t divisor
Alignment divisor.
Definition ncm.h:32
NTB constructed for transmitted packets (excluding padding)
Definition ncm.h:127
struct ncm_datagram_pointer ndp
Datagram pointer.
Definition ncm.h:131
NTB parameters.
Definition ncm.h:40
struct ncm_ntb_datagram_parameters in
IN datagram parameters.
Definition ncm.h:46
struct ncm_ntb_datagram_parameters out
OUT datagram parameters.
Definition ncm.h:50
Set NTB input size.
Definition ncm.h:66
CDC-NCM transfer header (16-bit)
Definition ncm.h:78
uint16_t offset
Offset of first datagram pointer.
Definition ncm.h:88
Network device operations.
Definition netdevice.h:214
A network device.
Definition netdevice.h:353
A data structure for storing profiling information.
Definition profile.h:27
A USB bus.
Definition usb.h:966
A USB configuration descriptor.
Definition usb.h:210
A USB device ID.
Definition usb.h:1361
A USB device.
Definition usb.h:723
struct usb_port * port
USB port.
Definition usb.h:727
A USB driver.
Definition usb.h:1419
USB endpoint driver operations.
Definition usb.h:489
A USB endpoint.
Definition usb.h:404
size_t len
Refill buffer payload length.
Definition usb.h:438
int open
Endpoint is open.
Definition usb.h:419
A USB function.
Definition usb.h:674
struct usb_device * usb
USB device.
Definition usb.h:678
struct device dev
Generic device.
Definition usb.h:682
const char * name
Name.
Definition usb.h:676
struct usb_bus * bus
USB bus.
Definition usb.h:845
A USB interface descriptor.
Definition usb.h:245
struct usb_hub * hub
USB hub.
Definition usb.h:815
A USB setup data packet.
Definition usb.h:83
struct usb_endpoint out
Bulk OUT endpoint.
Definition usbnet.h:32
struct usb_endpoint intr
Interrupt endpoint.
Definition usbnet.h:28
unsigned int comms
Communications interface.
Definition usbnet.h:21
struct usb_endpoint in
Bulk IN endpoint.
Definition usbnet.h:30
void usb_flush(struct usb_endpoint *ep)
Discard endpoint recycled buffer list.
Definition usb.c:720
int usb_prefill(struct usb_endpoint *ep)
Prefill endpoint recycled buffer list.
Definition usb.c:620
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition usb.c:784
struct usb_interface_descriptor * usb_interface_descriptor(struct usb_configuration_descriptor *config, unsigned int interface, unsigned int alternate)
Locate USB interface descriptor.
Definition usb.c:144
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition usb.c:546
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition usbnet.c:152
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition usbnet.c:55
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition usbnet.c:128
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition usbnet.c:278
USB network devices.
static void usbnet_init(struct usbnet_device *usbnet, struct usb_function *func, struct usb_endpoint_driver_operations *intr, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
Initialise USB network device.
Definition usbnet.h:45
char message[VMCONSOLE_BUFSIZE]
Definition vmconsole.c:54