/** * drci_rd_reg - read a DCI register * @dev: usb device * @reg: register address * @buf: buffer to store data * * This is reads data from INIC's direct register communication interface
*/ staticinlineint drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf)
{ int retval;
__le16 *dma_buf;
u8 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL); if (!dma_buf) return -ENOMEM;
/** * hdm_poison_channel - mark buffers of this channel as invalid * @iface: pointer to the interface * @channel: channel ID * * This unlinks all URBs submitted to the HCD, * calls the associated completion function of the core and removes * them from the list. * * Returns 0 on success or error code otherwise.
*/ staticint hdm_poison_channel(struct most_interface *iface, int channel)
{ struct most_dev *mdev = to_mdev(iface); unsignedlong flags;
spinlock_t *lock; /* temp. lock */
if (channel < 0 || channel >= iface->num_channels) {
dev_warn(&mdev->usb_device->dev, "Channel ID out of range.\n"); return -ECHRNG;
}
/** * hdm_write_completion - completion function for submitted Tx URBs * @urb: the URB that has been completed * * This checks the status of the completed URB. In case the URB has been * unlinked before, it is immediately freed. On any other error the MBO * transfer flag is set. On success it frees allocated resources and calls * the completion function. * * Context: interrupt!
*/ staticvoid hdm_write_completion(struct urb *urb)
{ struct mbo *mbo = urb->context; struct most_dev *mdev = to_mdev(mbo->ifp); unsignedint channel = mbo->hdm_channel_id;
spinlock_t *lock = mdev->channel_lock + channel; unsignedlong flags;
spin_lock_irqsave(lock, flags);
mbo->processed_length = 0;
mbo->status = MBO_E_INVAL; if (likely(mdev->is_channel_healthy[channel])) { switch (urb->status) { case 0: case -ESHUTDOWN:
mbo->processed_length = urb->actual_length;
mbo->status = MBO_SUCCESS; break; case -EPIPE:
dev_warn(&mdev->usb_device->dev, "Broken pipe on ep%02x\n",
mdev->ep_address[channel]);
mdev->is_channel_healthy[channel] = false;
mdev->clear_work[channel].pipe = urb->pipe;
schedule_work(&mdev->clear_work[channel].ws); break; case -ENODEV: case -EPROTO:
mbo->status = MBO_E_CLOSE; break;
}
}
spin_unlock_irqrestore(lock, flags);
if (likely(mbo->complete))
mbo->complete(mbo);
usb_free_urb(urb);
}
/** * hdm_read_completion - completion function for submitted Rx URBs * @urb: the URB that has been completed * * This checks the status of the completed URB. In case the URB has been * unlinked before it is immediately freed. On any other error the MBO transfer * flag is set. On success it frees allocated resources, removes * padding bytes -if necessary- and calls the completion function. * * Context: interrupt!
*/ staticvoid hdm_read_completion(struct urb *urb)
{ struct mbo *mbo = urb->context; struct most_dev *mdev = to_mdev(mbo->ifp); unsignedint channel = mbo->hdm_channel_id; struct device *dev = &mdev->usb_device->dev;
spinlock_t *lock = mdev->channel_lock + channel; unsignedlong flags;
spin_lock_irqsave(lock, flags);
mbo->processed_length = 0;
mbo->status = MBO_E_INVAL; if (likely(mdev->is_channel_healthy[channel])) { switch (urb->status) { case 0: case -ESHUTDOWN:
mbo->processed_length = urb->actual_length;
mbo->status = MBO_SUCCESS; if (mdev->padding_active[channel] &&
hdm_remove_padding(mdev, channel, mbo)) {
mbo->processed_length = 0;
mbo->status = MBO_E_INVAL;
} break; case -EPIPE:
dev_warn(dev, "Broken pipe on ep%02x\n",
mdev->ep_address[channel]);
mdev->is_channel_healthy[channel] = false;
mdev->clear_work[channel].pipe = urb->pipe;
schedule_work(&mdev->clear_work[channel].ws); break; case -ENODEV: case -EPROTO:
mbo->status = MBO_E_CLOSE; break; case -EOVERFLOW:
dev_warn(dev, "Babble on ep%02x\n",
mdev->ep_address[channel]); break;
}
}
spin_unlock_irqrestore(lock, flags);
if (likely(mbo->complete))
mbo->complete(mbo);
usb_free_urb(urb);
}
/** * hdm_enqueue - receive a buffer to be used for data transfer * @iface: interface to enqueue to * @channel: ID of the channel * @mbo: pointer to the buffer object * * This allocates a new URB and fills it according to the channel * that is being used for transmission of data. Before the URB is * submitted it is stored in the private anchor list. * * Returns 0 on success. On any error the URB is freed and a error code * is returned. * * Context: Could in _some_ cases be interrupt!
*/ staticint hdm_enqueue(struct most_interface *iface, int channel, struct mbo *mbo)
{ struct most_dev *mdev = to_mdev(iface); struct most_channel_config *conf; int retval = 0; struct urb *urb; unsignedlong length; void *virt_address;
if (!mbo) return -EINVAL; if (iface->num_channels <= channel || channel < 0) return -ECHRNG;
urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_KERNEL); if (!urb) return -ENOMEM;
conf = &mdev->conf[channel];
mutex_lock(&mdev->io_mutex); if (!mdev->usb_device) {
retval = -ENODEV; goto err_free_urb;
}
/** * hdm_configure_channel - receive channel configuration from core * @iface: interface * @channel: channel ID * @conf: structure that holds the configuration information * * The attached network interface controller (NIC) supports a padding mode * to avoid short packets on USB, hence increasing the performance due to a * lower interrupt load. This mode is default for synchronous data and can * be switched on for isochronous data. In case padding is active the * driver needs to know the frame size of the payload in order to calculate * the number of bytes it needs to pad when transmitting or to cut off when * receiving data. *
*/ staticint hdm_configure_channel(struct most_interface *iface, int channel, struct most_channel_config *conf)
{ unsignedint num_frames; unsignedint frame_size; struct most_dev *mdev = to_mdev(iface); struct device *dev = &mdev->usb_device->dev;
if (!conf) {
dev_err(dev, "Bad config pointer.\n"); return -EINVAL;
} if (channel < 0 || channel >= iface->num_channels) {
dev_err(dev, "Channel ID out of range.\n"); return -EINVAL;
}
if (!conf->num_buffers || !conf->buffer_size) {
dev_err(dev, "Misconfig: buffer size or #buffers zero.\n"); return -EINVAL;
}
if (conf->data_type != MOST_CH_SYNC &&
!(conf->data_type == MOST_CH_ISOC &&
conf->packets_per_xact != 0xFF)) {
mdev->padding_active[channel] = false; /* * Since the NIC's padding mode is not going to be * used, we can skip the frame size calculations and * move directly on to exit.
*/ gotoexit;
}
/* calculate extra length to comply w/ HW padding */
conf->extra_len = num_frames * (USB_MTU - frame_size);
exit:
mdev->conf[channel] = *conf; if (conf->data_type == MOST_CH_ASYNC) {
u16 ep = mdev->ep_address[channel];
if (start_sync_ep(mdev->usb_device, ep) < 0)
dev_warn(dev, "sync for ep%02x failed", ep);
} return 0;
}
/** * hdm_request_netinfo - request network information * @iface: pointer to interface * @channel: channel ID * * This is used as trigger to set up the link status timer that * polls for the NI state of the INIC every 2 seconds. *
*/ staticvoid hdm_request_netinfo(struct most_interface *iface, int channel, void (*on_netinfo)(struct most_interface *, unsignedchar, unsignedchar *))
{ struct most_dev *mdev = to_mdev(iface);
mdev->on_netinfo = on_netinfo; if (!on_netinfo) return;
/** * link_stat_timer_handler - schedule work obtaining mac address and link status * @t: pointer to timer_list which holds a pointer to the USB device instance * * The handler runs in interrupt context. That's why we need to defer the * tasks to a work queue.
*/ staticvoid link_stat_timer_handler(struct timer_list *t)
{ struct most_dev *mdev = timer_container_of(mdev, t, link_stat_timer);
/** * wq_netinfo - work queue function to deliver latest networking information * @wq_obj: object that holds data for our deferred work to do * * This retrieves the network interface status of the USB INIC
*/ staticvoid wq_netinfo(struct work_struct *wq_obj)
{ struct most_dev *mdev = to_mdev_from_work(wq_obj); struct usb_device *usb_device = mdev->usb_device; struct device *dev = &usb_device->dev;
u16 hi, mi, lo, link;
u8 hw_addr[6];
hw_addr[0] = hi >> 8;
hw_addr[1] = hi;
hw_addr[2] = mi >> 8;
hw_addr[3] = mi;
hw_addr[4] = lo >> 8;
hw_addr[5] = lo;
if (mdev->on_netinfo)
mdev->on_netinfo(&mdev->iface, link, hw_addr);
}
/** * wq_clear_halt - work queue function * @wq_obj: work_struct object to execute * * This sends a clear_halt to the given USB pipe.
*/ staticvoid wq_clear_halt(struct work_struct *wq_obj)
{ struct clear_hold_work *clear_work = to_clear_hold_work(wq_obj); struct most_dev *mdev = clear_work->mdev; unsignedint channel = clear_work->channel; int pipe = clear_work->pipe; int snd_pipe; int peer;
mutex_lock(&mdev->io_mutex);
most_stop_enqueue(&mdev->iface, channel);
usb_kill_anchored_urbs(&mdev->busy_urbs[channel]); if (usb_clear_halt(mdev->usb_device, pipe))
dev_warn(&mdev->usb_device->dev, "Failed to reset endpoint.\n");
/* If the functional Stall condition has been set on an * asynchronous rx channel, we need to clear the tx channel * too, since the hardware runs its clean-up sequence on both * channels, as they are physically one on the network. * * The USB interface that exposes the asynchronous channels * contains always two endpoints, and two only.
*/ if (mdev->conf[channel].data_type == MOST_CH_ASYNC &&
mdev->conf[channel].direction == MOST_CH_RX) { if (channel == 0)
peer = 1; else
peer = 0;
snd_pipe = usb_sndbulkpipe(mdev->usb_device,
mdev->ep_address[peer]);
usb_clear_halt(mdev->usb_device, snd_pipe);
}
mdev->is_channel_healthy[channel] = true;
most_resume_enqueue(&mdev->iface, channel);
mutex_unlock(&mdev->io_mutex);
}
/* * hdm_usb_fops - file operation table for USB driver
*/ staticconststruct file_operations hdm_usb_fops = {
.owner = THIS_MODULE,
};
kfree(mdev->busy_urbs);
kfree(mdev->cap);
kfree(mdev->conf);
kfree(mdev->ep_address);
kfree(mdev);
} /** * hdm_probe - probe function of USB device driver * @interface: Interface of the attached USB device * @id: Pointer to the USB ID table. * * This allocates and initializes the device instance, adds the new * entry to the internal list, scans the USB descriptors and registers * the interface with the core. * Additionally, the DCI objects are created and the hardware is sync'd. * * Return 0 on success. In case of an error a negative number is returned.
*/ staticint
hdm_probe(struct usb_interface *interface, conststruct usb_device_id *id)
{ struct usb_host_interface *usb_iface_desc = interface->cur_altsetting; struct usb_device *usb_dev = interface_to_usbdev(interface); struct device *dev = &usb_dev->dev; struct most_dev *mdev; unsignedint i; unsignedint num_endpoints; struct most_channel_capability *tmp_cap; struct usb_endpoint_descriptor *ep_desc; int ret = -ENOMEM;
mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); if (!mdev) return -ENOMEM;
/** * hdm_disconnect - disconnect function of USB device driver * @interface: Interface of the attached USB device * * This deregisters the interface with the core, removes the kernel timer * and frees resources. * * Context: hub kernel thread
*/ staticvoid hdm_disconnect(struct usb_interface *interface)
{ struct most_dev *mdev = usb_get_intfdata(interface);
mutex_lock(&mdev->io_mutex); for (i = 0; i < mdev->iface.num_channels; i++)
most_resume_enqueue(&mdev->iface, i);
mutex_unlock(&mdev->io_mutex); return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.