/** * Allocate I/O buffer * * @v intf Data transfer interface * @v len I/O buffer payload length * @ret iobuf I/O buffer */ struct io_buffer * xfer_alloc_iob ( struct interface *intf, size_t len ) { struct interface *dest; xfer_alloc_iob_TYPE ( void * ) *op = intf_get_dest_op ( intf, xfer_alloc_iob, &dest ); void *object = intf_object ( dest ); struct io_buffer *iobuf; DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob %zd\n", INTF_INTF_DBG ( intf, dest ), len ); if ( op ) { iobuf = op ( object, len ); } else { /* Default is to allocate an I/O buffer with no * reserved space. */ iobuf = alloc_iob ( len ); } if ( ! iobuf ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob " "failed\n", INTF_INTF_DBG ( intf, dest ) ); } intf_put ( dest ); return iobuf; }
/** * Deliver datagram * * @v intf Data transfer interface * @v iobuf Datagram I/O buffer * @v meta Data transfer metadata * @ret rc Return status code */ int xfer_deliver ( struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta ) { struct interface *dest; xfer_deliver_TYPE ( void * ) *op = intf_get_dest_op ( intf, xfer_deliver, &dest ); void *object = intf_object ( dest ); int rc; DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " deliver %zd\n", INTF_INTF_DBG ( intf, dest ), iob_len ( iobuf ) ); if ( op ) { rc = op ( object, iobuf, meta ); } else { /* Default is to discard the I/O buffer */ free_iob ( iobuf ); rc = -EPIPE; } if ( rc != 0 ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " deliver failed: %s\n", INTF_INTF_DBG ( intf, dest ), strerror ( rc ) ); } intf_put ( dest ); return rc; }
/** * Plug an object interface into a new destination object interface * * @v intf Object interface * @v dest New destination object interface * * The reference to the existing destination interface is dropped, a * reference to the new destination interface is obtained, and the * interface is updated to point to the new destination interface. * * Note that there is no "unplug" call; instead you must plug the * interface into a null interface. */ void intf_plug ( struct interface *intf, struct interface *dest ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " replug to " INTF_FMT "\n", INTF_INTF_DBG ( intf, intf->dest ), INTF_DBG ( dest ) ); intf_get ( dest ); intf_put ( intf->dest ); intf->dest = dest; }
/** * Report change of flow control window * * @v intf Data transfer interface * * Note that this method is used to indicate only unsolicited changes * in the flow control window. In particular, this method must not be * called as part of the response to xfer_deliver(), since that could * easily lead to an infinite loop. Callers of xfer_deliver() should * assume that the flow control window will have changed without * generating an xfer_window_changed() message. */ void xfer_window_changed ( struct interface *intf ) { struct interface *dest; xfer_window_changed_TYPE ( void * ) *op = intf_get_dest_op ( intf, xfer_window_changed, &dest ); void *object = intf_object ( dest ); if ( op ) { op ( object ); } else { /* Default is to do nothing */ } intf_put ( dest ); }
/** * Report SCSI response * * @v interface SCSI command interface * @v response SCSI response */ void scsi_response ( struct interface *intf, struct scsi_rsp *response ) { struct interface *dest; scsi_response_TYPE ( void * ) *op = intf_get_dest_op ( intf, scsi_response, &dest ); void *object = intf_object ( dest ); if ( op ) { op ( object, response ); } else { /* Default is to ignore the response */ } intf_put ( dest ); }
/** * Poke an object interface * * @v intf Object interface * @v type Operation type * * This is a helper function to implement methods which take no * parameters and return nothing. */ void intf_poke ( struct interface *intf, void ( type ) ( struct interface *intf ) ) { struct interface *dest; intf_poke_TYPE ( void * ) *op = intf_get_dest_op_untyped ( intf, type, &dest ); void *object = intf_object ( dest ); if ( op ) { op ( object ); } else { /* Default is to do nothing */ } intf_put ( dest ); }
/** * Get underlying data transfer buffer * * @v interface Data transfer interface * @ret xferbuf Data transfer buffer, or NULL on error * * This call will check that the xfer_buffer() handler belongs to the * destination interface which also provides xfer_deliver() for this * interface. * * This is done to prevent accidental accesses to a data transfer * buffer which may be located behind a non-transparent datapath via a * series of pass-through interfaces. */ struct xfer_buffer * xfer_buffer ( struct interface *intf ) { struct interface *dest; xfer_buffer_TYPE ( void * ) *op = intf_get_dest_op ( intf, xfer_buffer, &dest ); void *object = intf_object ( dest ); struct interface *xfer_deliver_dest; struct xfer_buffer *xferbuf; /* Check that this operation is provided by the same interface * which handles xfer_deliver(). */ ( void ) intf_get_dest_op ( intf, xfer_deliver, &xfer_deliver_dest ); if ( op && ( dest == xfer_deliver_dest ) ) { xferbuf = op ( object ); } else { /* Default is to not have a data transfer buffer */ xferbuf = NULL; } intf_put ( xfer_deliver_dest ); intf_put ( dest ); return xferbuf; }
/** * Report block device capacity * * @v intf Interface * @v capacity Block device capacity */ void block_capacity ( struct interface *intf, struct block_device_capacity *capacity ) { struct interface *dest; block_capacity_TYPE ( void * ) *op = intf_get_dest_op ( intf, block_capacity, &dest ); void *object = intf_object ( dest ); if ( op ) { op ( object, capacity ); } else { /* Default is to do nothing */ } intf_put ( dest ); }
/** * Report peer discovery statistics * * @v intf Interface * @v peer Selected peer (or NULL) * @v peers List of available peers */ void peerdisc_stat ( struct interface *intf, struct peerdisc_peer *peer, struct list_head *peers ) { struct interface *dest; peerdisc_stat_TYPE ( void * ) *op = intf_get_dest_op ( intf, peerdisc_stat, &dest ); void *object = intf_object ( dest ); if ( op ) { op ( object, peer, peers ); } else { /* Default is to do nothing */ } intf_put ( dest ); }
/** * Get object's ACPI descriptor * * @v intf Interface * @ret desc ACPI descriptor, or NULL */ struct acpi_descriptor * acpi_describe ( struct interface *intf ) { struct interface *dest; acpi_describe_TYPE ( void * ) *op = intf_get_dest_op ( intf, acpi_describe, &dest ); void *object = intf_object ( dest ); struct acpi_descriptor *desc; if ( op ) { desc = op ( object ); } else { desc = NULL; } intf_put ( dest ); return desc; }
/** * Name resolved * * @v intf Object interface * @v sa Completed socket address (if successful) */ void resolv_done ( struct interface *intf, struct sockaddr *sa ) { struct interface *dest; resolv_done_TYPE ( void * ) *op = intf_get_dest_op ( intf, resolv_done, &dest ); void *object = intf_object ( dest ); DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " resolv_done\n", INTF_INTF_DBG ( intf, dest ) ); if ( op ) { op ( object, sa ); } else { /* Default is to ignore resolutions */ } intf_put ( dest ); }
/** * Read block device capacity * * @v control Control interface * @v data Data interface * @ret rc Return status code */ int block_read_capacity ( struct interface *control, struct interface *data ) { struct interface *dest; block_read_capacity_TYPE ( void * ) *op = intf_get_dest_op ( control, block_read_capacity, &dest ); void *object = intf_object ( dest ); int rc; if ( op ) { rc = op ( object, data ); } else { /* Default is to fail to issue the command */ rc = -EOPNOTSUPP; } intf_put ( dest ); return rc; }
/** * Check flow control window * * @v intf Data transfer interface * @ret len Length of window */ size_t xfer_window ( struct interface *intf ) { struct interface *dest; xfer_window_TYPE ( void * ) *op = intf_get_dest_op ( intf, xfer_window, &dest ); void *object = intf_object ( dest ); size_t len; if ( op ) { len = op ( object ); } else { /* Default is to provide an unlimited window */ len = ~( ( size_t ) 0 ); } intf_put ( dest ); return len; }
/** * Close an object interface * * @v intf Object interface * @v rc Reason for close * * Note that this function merely informs the destination object that * the interface is about to be closed; it doesn't actually disconnect * the interface. In most cases, you probably want to use * intf_shutdown() or intf_restart() instead. */ void intf_close ( struct interface *intf, int rc ) { struct interface *dest; intf_close_TYPE ( void * ) *op = intf_get_dest_op ( intf, intf_close, &dest ); void *object = intf_object ( dest ); DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " close (%s)\n", INTF_INTF_DBG ( intf, dest ), strerror ( rc ) ); if ( op ) { op ( object, rc ); } else { /* Default is to ignore intf_close() */ } intf_put ( dest ); }
/** * Issue SCSI command * * @v control SCSI control interface * @v data SCSI data interface * @v command SCSI command * @ret tag Command tag, or negative error */ int scsi_command ( struct interface *control, struct interface *data, struct scsi_cmd *command ) { struct interface *dest; scsi_command_TYPE ( void * ) *op = intf_get_dest_op ( control, scsi_command, &dest ); void *object = intf_object ( dest ); int tap; if ( op ) { tap = op ( object, data, command ); } else { /* Default is to fail to issue the command */ tap = -EOPNOTSUPP; } intf_put ( dest ); return tap; }
/** * Describe object in an ACPI table * * @v intf Interface * @v acpi ACPI table * @v len Length of ACPI table * @ret rc Return status code */ int acpi_describe ( struct interface *intf, struct acpi_description_header *acpi, size_t len ) { struct interface *dest; acpi_describe_TYPE ( void * ) *op = intf_get_dest_op ( intf, acpi_describe, &dest ); void *object = intf_object ( dest ); int rc; if ( op ) { rc = op ( object, acpi, len ); } else { /* Default is to fail to describe */ rc = -EOPNOTSUPP; } intf_put ( dest ); return rc; }
/** * Get object interface destination and operation method * * @v intf Object interface * @v type Operation type * @ret dest Destination interface * @ret func Implementing method, or NULL */ void * intf_get_dest_op_untyped ( struct interface *intf, void *type, struct interface **dest ) { void *func; while ( 1 ) { /* Search for an implementing method provided by the * current destination interface. */ func = intf_get_dest_op_no_passthru_untyped( intf, type, dest ); if ( func ) return func; /* Pass through to the underlying interface, if applicable */ if ( ! ( intf = intf_get_passthru ( *dest ) ) ) return NULL; intf_put ( *dest ); } }
/** * Write to block device * * @v control Control interface * @v data Data interface * @v lba Starting logical block address * @v count Number of logical blocks * @v buffer Data buffer * @v len Length of data buffer * @ret rc Return status code */ int block_write ( struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len ) { struct interface *dest; block_write_TYPE ( void * ) *op = intf_get_dest_op ( control, block_write, &dest ); void *object = intf_object ( dest ); int rc; if ( op ) { rc = op ( object, data, lba, count, buffer, len ); } else { /* Default is to fail to issue the command */ rc = -EOPNOTSUPP; } intf_put ( dest ); return rc; }
/** * Send redirection event * * @v intf Data transfer interface * @v type New location type * @v args Remaining arguments depend upon location type * @ret rc Return status code */ int xfer_vredirect ( struct interface *intf, int type, va_list args ) { struct interface tmp = INTF_INIT ( null_intf_desc ); struct interface *dest; xfer_vredirect_TYPE ( void * ) *op = intf_get_dest_op_no_passthru ( intf, xfer_vredirect, &dest ); void *object = intf_object ( dest ); int rc; DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect\n", INTF_INTF_DBG ( intf, dest ) ); if ( op ) { rc = op ( object, type, args ); } else { /* Default is to reopen the interface as instructed, * then send xfer_window_changed() messages to both * new child and parent interfaces. Since our * original child interface is likely to be closed and * unplugged as a result of the call to * xfer_vreopen(), we create a temporary interface in * order to be able to send xfer_window_changed() to * the parent. */ intf_plug ( &tmp, dest ); rc = xfer_vreopen ( dest, type, args ); if ( rc == 0 ) { xfer_window_changed ( dest ); xfer_window_changed ( &tmp ); } intf_unplug ( &tmp ); } if ( rc != 0 ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect " "failed: %s\n", INTF_INTF_DBG ( intf, dest ), strerror ( rc ) ); } intf_put ( dest ); return rc; }