2017-11-07 13:58:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-07-24 14:11:55 +00:00
|
|
|
/*
|
2017-11-21 14:04:41 +00:00
|
|
|
* usb.c - Hardware dependent module for USB
|
2015-07-24 14:11:55 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/uaccess.h>
|
2020-03-10 13:02:40 +00:00
|
|
|
#include <linux/most.h>
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
#define USB_MTU 512
|
|
|
|
#define NO_ISOCHRONOUS_URB 0
|
|
|
|
#define AV_PACKETS_PER_XACT 2
|
|
|
|
#define BUF_CHAIN_SIZE 0xFFFF
|
|
|
|
#define MAX_NUM_ENDPOINTS 30
|
|
|
|
#define MAX_SUFFIX_LEN 10
|
|
|
|
#define MAX_STRING_LEN 80
|
|
|
|
#define MAX_BUF_SIZE 0xFFFF
|
|
|
|
|
|
|
|
#define USB_VENDOR_ID_SMSC 0x0424 /* VID: SMSC */
|
|
|
|
#define USB_DEV_ID_BRDG 0xC001 /* PID: USB Bridge */
|
2016-08-19 09:12:50 +00:00
|
|
|
#define USB_DEV_ID_OS81118 0xCF18 /* PID: USB OS81118 */
|
2016-08-19 09:12:49 +00:00
|
|
|
#define USB_DEV_ID_OS81119 0xCF19 /* PID: USB OS81119 */
|
2016-08-19 09:13:01 +00:00
|
|
|
#define USB_DEV_ID_OS81210 0xCF30 /* PID: USB OS81210 */
|
2015-07-24 14:11:55 +00:00
|
|
|
/* DRCI Addresses */
|
|
|
|
#define DRCI_REG_NI_STATE 0x0100
|
|
|
|
#define DRCI_REG_PACKET_BW 0x0101
|
|
|
|
#define DRCI_REG_NODE_ADDR 0x0102
|
|
|
|
#define DRCI_REG_NODE_POS 0x0103
|
|
|
|
#define DRCI_REG_MEP_FILTER 0x0140
|
|
|
|
#define DRCI_REG_HASH_TBL0 0x0141
|
|
|
|
#define DRCI_REG_HASH_TBL1 0x0142
|
|
|
|
#define DRCI_REG_HASH_TBL2 0x0143
|
|
|
|
#define DRCI_REG_HASH_TBL3 0x0144
|
|
|
|
#define DRCI_REG_HW_ADDR_HI 0x0145
|
|
|
|
#define DRCI_REG_HW_ADDR_MI 0x0146
|
|
|
|
#define DRCI_REG_HW_ADDR_LO 0x0147
|
2015-09-28 15:18:38 +00:00
|
|
|
#define DRCI_REG_BASE 0x1100
|
|
|
|
#define DRCI_COMMAND 0x02
|
2015-07-24 14:11:55 +00:00
|
|
|
#define DRCI_READ_REQ 0xA0
|
|
|
|
#define DRCI_WRITE_REQ 0xA1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct most_dci_obj - Direct Communication Interface
|
|
|
|
* @kobj:position in sysfs
|
|
|
|
* @usb_device: pointer to the usb device
|
2016-09-09 13:25:35 +00:00
|
|
|
* @reg_addr: register address for arbitrary DCI access
|
2015-07-24 14:11:55 +00:00
|
|
|
*/
|
|
|
|
struct most_dci_obj {
|
2017-11-21 14:04:43 +00:00
|
|
|
struct device dev;
|
2015-07-24 14:11:55 +00:00
|
|
|
struct usb_device *usb_device;
|
2016-09-09 13:25:35 +00:00
|
|
|
u16 reg_addr;
|
2015-07-24 14:11:55 +00:00
|
|
|
};
|
2015-10-21 15:50:45 +00:00
|
|
|
|
2017-11-21 14:04:43 +00:00
|
|
|
#define to_dci_obj(p) container_of(p, struct most_dci_obj, dev)
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-08-19 09:12:47 +00:00
|
|
|
struct most_dev;
|
|
|
|
|
|
|
|
struct clear_hold_work {
|
|
|
|
struct work_struct ws;
|
|
|
|
struct most_dev *mdev;
|
|
|
|
unsigned int channel;
|
|
|
|
int pipe;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_clear_hold_work(w) container_of(w, struct clear_hold_work, ws)
|
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
/**
|
|
|
|
* struct most_dev - holds all usb interface specific stuff
|
|
|
|
* @usb_device: pointer to usb device
|
|
|
|
* @iface: hardware interface
|
|
|
|
* @cap: channel capabilities
|
|
|
|
* @conf: channel configuration
|
|
|
|
* @dci: direct communication interface of hardware
|
|
|
|
* @ep_address: endpoint address table
|
|
|
|
* @description: device description
|
|
|
|
* @suffix: suffix for channel name
|
2016-09-19 15:40:25 +00:00
|
|
|
* @channel_lock: synchronize channel access
|
2015-07-24 14:11:55 +00:00
|
|
|
* @padding_active: indicates channel uses padding
|
|
|
|
* @is_channel_healthy: health status table of each channel
|
2016-09-19 15:40:22 +00:00
|
|
|
* @busy_urbs: list of anchored items
|
2015-07-24 14:11:55 +00:00
|
|
|
* @io_mutex: synchronize I/O with disconnect
|
|
|
|
* @link_stat_timer: timer for link status reports
|
|
|
|
* @poll_work_obj: work for polling link status
|
|
|
|
*/
|
|
|
|
struct most_dev {
|
2020-01-23 15:38:17 +00:00
|
|
|
struct device dev;
|
2015-07-24 14:11:55 +00:00
|
|
|
struct usb_device *usb_device;
|
|
|
|
struct most_interface iface;
|
|
|
|
struct most_channel_capability *cap;
|
|
|
|
struct most_channel_config *conf;
|
|
|
|
struct most_dci_obj *dci;
|
|
|
|
u8 *ep_address;
|
|
|
|
char description[MAX_STRING_LEN];
|
|
|
|
char suffix[MAX_NUM_ENDPOINTS][MAX_SUFFIX_LEN];
|
2016-09-19 15:40:25 +00:00
|
|
|
spinlock_t channel_lock[MAX_NUM_ENDPOINTS]; /* sync channel access */
|
2015-07-24 14:11:55 +00:00
|
|
|
bool padding_active[MAX_NUM_ENDPOINTS];
|
|
|
|
bool is_channel_healthy[MAX_NUM_ENDPOINTS];
|
2016-08-19 09:12:47 +00:00
|
|
|
struct clear_hold_work clear_work[MAX_NUM_ENDPOINTS];
|
2016-09-19 15:40:22 +00:00
|
|
|
struct usb_anchor *busy_urbs;
|
2015-07-24 14:11:55 +00:00
|
|
|
struct mutex io_mutex;
|
|
|
|
struct timer_list link_stat_timer;
|
|
|
|
struct work_struct poll_work_obj;
|
2017-12-22 10:09:02 +00:00
|
|
|
void (*on_netinfo)(struct most_interface *most_iface,
|
|
|
|
unsigned char link_state, unsigned char *addrs);
|
2015-07-24 14:11:55 +00:00
|
|
|
};
|
2015-10-21 15:50:45 +00:00
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
#define to_mdev(d) container_of(d, struct most_dev, iface)
|
2020-01-23 15:38:17 +00:00
|
|
|
#define to_mdev_from_dev(d) container_of(d, struct most_dev, dev)
|
2015-07-24 14:11:55 +00:00
|
|
|
#define to_mdev_from_work(w) container_of(w, struct most_dev, poll_work_obj)
|
|
|
|
|
|
|
|
static void wq_clear_halt(struct work_struct *wq_obj);
|
|
|
|
static void wq_netinfo(struct work_struct *wq_obj);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2015-09-28 15:18:43 +00:00
|
|
|
static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf)
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
2015-09-28 15:18:43 +00:00
|
|
|
int retval;
|
2017-01-11 01:38:35 +00:00
|
|
|
__le16 *dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL);
|
2015-09-28 15:18:43 +00:00
|
|
|
u8 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
|
|
|
|
|
|
|
|
if (!dma_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
|
|
|
DRCI_READ_REQ, req_type,
|
|
|
|
0x0000,
|
2017-01-11 01:38:35 +00:00
|
|
|
reg, dma_buf, sizeof(*dma_buf), 5 * HZ);
|
2015-09-28 15:18:44 +00:00
|
|
|
*buf = le16_to_cpu(*dma_buf);
|
2015-09-28 15:18:43 +00:00
|
|
|
kfree(dma_buf);
|
|
|
|
|
|
|
|
return retval;
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drci_wr_reg - write a DCI register
|
|
|
|
* @dev: usb device
|
|
|
|
* @reg: register address
|
|
|
|
* @data: data to write
|
|
|
|
*
|
|
|
|
* This is writes data to INIC's direct register communication interface
|
|
|
|
*/
|
|
|
|
static inline int drci_wr_reg(struct usb_device *dev, u16 reg, u16 data)
|
|
|
|
{
|
|
|
|
return usb_control_msg(dev,
|
|
|
|
usb_sndctrlpipe(dev, 0),
|
|
|
|
DRCI_WRITE_REQ,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
|
|
|
data,
|
|
|
|
reg,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
5 * HZ);
|
|
|
|
}
|
|
|
|
|
2016-10-25 15:44:21 +00:00
|
|
|
static inline int start_sync_ep(struct usb_device *usb_dev, u16 ep)
|
|
|
|
{
|
|
|
|
return drci_wr_reg(usb_dev, DRCI_REG_BASE + DRCI_COMMAND + ep * 16, 1);
|
|
|
|
}
|
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
/**
|
|
|
|
* get_stream_frame_size - calculate frame size of current configuration
|
|
|
|
* @cfg: channel configuration
|
|
|
|
*/
|
|
|
|
static unsigned int get_stream_frame_size(struct most_channel_config *cfg)
|
|
|
|
{
|
|
|
|
unsigned int frame_size = 0;
|
|
|
|
unsigned int sub_size = cfg->subbuffer_size;
|
|
|
|
|
|
|
|
if (!sub_size) {
|
2015-07-30 16:19:41 +00:00
|
|
|
pr_warn("Misconfig: Subbuffer size zero.\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
return frame_size;
|
|
|
|
}
|
|
|
|
switch (cfg->data_type) {
|
2016-09-21 12:49:10 +00:00
|
|
|
case MOST_CH_ISOC:
|
2015-07-24 14:11:55 +00:00
|
|
|
frame_size = AV_PACKETS_PER_XACT * sub_size;
|
|
|
|
break;
|
|
|
|
case MOST_CH_SYNC:
|
|
|
|
if (cfg->packets_per_xact == 0) {
|
2015-07-30 16:19:41 +00:00
|
|
|
pr_warn("Misconfig: Packets per XACT zero\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
frame_size = 0;
|
2015-10-21 15:50:44 +00:00
|
|
|
} else if (cfg->packets_per_xact == 0xFF) {
|
2015-07-24 14:11:55 +00:00
|
|
|
frame_size = (USB_MTU / sub_size) * sub_size;
|
2015-10-21 15:50:44 +00:00
|
|
|
} else {
|
2015-07-24 14:11:55 +00:00
|
|
|
frame_size = cfg->packets_per_xact * sub_size;
|
2015-10-21 15:50:44 +00:00
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_warn("Query frame size of non-streaming channel\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return frame_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-08-14 10:18:02 +00:00
|
|
|
static int hdm_poison_channel(struct most_interface *iface, int channel)
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
2016-08-19 09:12:59 +00:00
|
|
|
struct most_dev *mdev = to_mdev(iface);
|
2016-08-19 09:12:56 +00:00
|
|
|
unsigned long flags;
|
|
|
|
spinlock_t *lock; /* temp. lock */
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-08-19 09:12:58 +00:00
|
|
|
if (unlikely(channel < 0 || channel >= iface->num_channels)) {
|
2015-07-30 16:19:41 +00:00
|
|
|
dev_warn(&mdev->usb_device->dev, "Channel ID out of range.\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
return -ECHRNG;
|
|
|
|
}
|
|
|
|
|
2016-09-19 15:40:25 +00:00
|
|
|
lock = mdev->channel_lock + channel;
|
2016-08-19 09:12:56 +00:00
|
|
|
spin_lock_irqsave(lock, flags);
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->is_channel_healthy[channel] = false;
|
2016-08-19 09:12:56 +00:00
|
|
|
spin_unlock_irqrestore(lock, flags);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-08-19 09:12:47 +00:00
|
|
|
cancel_work_sync(&mdev->clear_work[channel].ws);
|
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
mutex_lock(&mdev->io_mutex);
|
2016-10-04 15:10:21 +00:00
|
|
|
usb_kill_anchored_urbs(&mdev->busy_urbs[channel]);
|
2015-09-04 10:52:06 +00:00
|
|
|
if (mdev->padding_active[channel])
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->padding_active[channel] = false;
|
|
|
|
|
|
|
|
if (mdev->conf[channel].data_type == MOST_CH_ASYNC) {
|
|
|
|
del_timer_sync(&mdev->link_stat_timer);
|
|
|
|
cancel_work_sync(&mdev->poll_work_obj);
|
|
|
|
}
|
|
|
|
mutex_unlock(&mdev->io_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hdm_add_padding - add padding bytes
|
|
|
|
* @mdev: most device
|
|
|
|
* @channel: channel ID
|
|
|
|
* @mbo: buffer object
|
|
|
|
*
|
|
|
|
* This inserts the INIC hardware specific padding bytes into a streaming
|
|
|
|
* channel's buffer
|
|
|
|
*/
|
2015-08-14 10:18:02 +00:00
|
|
|
static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo)
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
|
|
|
struct most_channel_config *conf = &mdev->conf[channel];
|
2016-09-09 13:25:41 +00:00
|
|
|
unsigned int frame_size = get_stream_frame_size(conf);
|
|
|
|
unsigned int j, num_frames;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
if (!frame_size)
|
|
|
|
return -EIO;
|
|
|
|
num_frames = mbo->buffer_length / frame_size;
|
|
|
|
|
|
|
|
if (num_frames < 1) {
|
2015-07-30 16:19:41 +00:00
|
|
|
dev_err(&mdev->usb_device->dev,
|
|
|
|
"Missed minimal transfer unit.\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2017-04-07 13:38:39 +00:00
|
|
|
for (j = num_frames - 1; j > 0; j--)
|
|
|
|
memmove(mbo->virt_address + j * USB_MTU,
|
|
|
|
mbo->virt_address + j * frame_size,
|
2015-07-24 14:11:55 +00:00
|
|
|
frame_size);
|
|
|
|
mbo->buffer_length = num_frames * USB_MTU;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hdm_remove_padding - remove padding bytes
|
|
|
|
* @mdev: most device
|
|
|
|
* @channel: channel ID
|
|
|
|
* @mbo: buffer object
|
|
|
|
*
|
|
|
|
* This takes the INIC hardware specific padding bytes off a streaming
|
|
|
|
* channel's buffer.
|
|
|
|
*/
|
2015-10-15 11:28:56 +00:00
|
|
|
static int hdm_remove_padding(struct most_dev *mdev, int channel,
|
|
|
|
struct mbo *mbo)
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
|
|
|
struct most_channel_config *const conf = &mdev->conf[channel];
|
2016-09-09 13:25:41 +00:00
|
|
|
unsigned int frame_size = get_stream_frame_size(conf);
|
|
|
|
unsigned int j, num_frames;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
if (!frame_size)
|
|
|
|
return -EIO;
|
|
|
|
num_frames = mbo->processed_length / USB_MTU;
|
|
|
|
|
|
|
|
for (j = 1; j < num_frames; j++)
|
|
|
|
memmove(mbo->virt_address + frame_size * j,
|
|
|
|
mbo->virt_address + USB_MTU * j,
|
|
|
|
frame_size);
|
|
|
|
|
|
|
|
mbo->processed_length = frame_size * num_frames;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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!
|
|
|
|
*/
|
|
|
|
static void hdm_write_completion(struct urb *urb)
|
|
|
|
{
|
2016-08-19 09:12:59 +00:00
|
|
|
struct mbo *mbo = urb->context;
|
|
|
|
struct most_dev *mdev = to_mdev(mbo->ifp);
|
|
|
|
unsigned int channel = mbo->hdm_channel_id;
|
2016-09-19 15:40:25 +00:00
|
|
|
spinlock_t *lock = mdev->channel_lock + channel;
|
2015-07-24 14:11:55 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2016-08-19 09:12:56 +00:00
|
|
|
spin_lock_irqsave(lock, flags);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-10-04 15:10:21 +00:00
|
|
|
mbo->processed_length = 0;
|
|
|
|
mbo->status = MBO_E_INVAL;
|
|
|
|
if (likely(mdev->is_channel_healthy[channel])) {
|
2015-07-24 14:11:55 +00:00
|
|
|
switch (urb->status) {
|
2016-10-04 15:10:21 +00:00
|
|
|
case 0:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
mbo->processed_length = urb->actual_length;
|
|
|
|
mbo->status = MBO_SUCCESS;
|
|
|
|
break;
|
2015-07-24 14:11:55 +00:00
|
|
|
case -EPIPE:
|
2018-05-08 09:45:16 +00:00
|
|
|
dev_warn(&mdev->usb_device->dev,
|
|
|
|
"Broken pipe on ep%02x\n",
|
2018-05-08 09:45:07 +00:00
|
|
|
mdev->ep_address[channel]);
|
2016-08-19 09:12:51 +00:00
|
|
|
mdev->is_channel_healthy[channel] = false;
|
2016-08-19 09:12:47 +00:00
|
|
|
mdev->clear_work[channel].pipe = urb->pipe;
|
|
|
|
schedule_work(&mdev->clear_work[channel].ws);
|
2016-10-04 15:10:21 +00:00
|
|
|
break;
|
2015-07-24 14:11:55 +00:00
|
|
|
case -ENODEV:
|
|
|
|
case -EPROTO:
|
|
|
|
mbo->status = MBO_E_CLOSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-19 09:12:55 +00:00
|
|
|
spin_unlock_irqrestore(lock, flags);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
if (likely(mbo->complete))
|
|
|
|
mbo->complete(mbo);
|
|
|
|
usb_free_urb(urb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-10 04:42:49 +00:00
|
|
|
* hdm_read_completion - completion function for submitted Rx URBs
|
2015-07-24 14:11:55 +00:00
|
|
|
* @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!
|
|
|
|
*
|
|
|
|
* **************************************************************************
|
|
|
|
* Error codes returned by in urb->status
|
|
|
|
* or in iso_frame_desc[n].status (for ISO)
|
|
|
|
* *************************************************************************
|
|
|
|
*
|
|
|
|
* USB device drivers may only test urb status values in completion handlers.
|
|
|
|
* This is because otherwise there would be a race between HCDs updating
|
|
|
|
* these values on one CPU, and device drivers testing them on another CPU.
|
|
|
|
*
|
|
|
|
* A transfer's actual_length may be positive even when an error has been
|
|
|
|
* reported. That's because transfers often involve several packets, so that
|
|
|
|
* one or more packets could finish before an error stops further endpoint I/O.
|
|
|
|
*
|
|
|
|
* For isochronous URBs, the urb status value is non-zero only if the URB is
|
|
|
|
* unlinked, the device is removed, the host controller is disabled or the total
|
|
|
|
* transferred length is less than the requested length and the URB_SHORT_NOT_OK
|
|
|
|
* flag is set. Completion handlers for isochronous URBs should only see
|
|
|
|
* urb->status set to zero, -ENOENT, -ECONNRESET, -ESHUTDOWN, or -EREMOTEIO.
|
|
|
|
* Individual frame descriptor status fields may report more status codes.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 0 Transfer completed successfully
|
|
|
|
*
|
|
|
|
* -ENOENT URB was synchronously unlinked by usb_unlink_urb
|
|
|
|
*
|
|
|
|
* -EINPROGRESS URB still pending, no results yet
|
|
|
|
* (That is, if drivers see this it's a bug.)
|
|
|
|
*
|
|
|
|
* -EPROTO (*, **) a) bitstuff error
|
|
|
|
* b) no response packet received within the
|
|
|
|
* prescribed bus turn-around time
|
|
|
|
* c) unknown USB error
|
|
|
|
*
|
|
|
|
* -EILSEQ (*, **) a) CRC mismatch
|
|
|
|
* b) no response packet received within the
|
|
|
|
* prescribed bus turn-around time
|
|
|
|
* c) unknown USB error
|
|
|
|
*
|
|
|
|
* Note that often the controller hardware does not
|
|
|
|
* distinguish among cases a), b), and c), so a
|
|
|
|
* driver cannot tell whether there was a protocol
|
|
|
|
* error, a failure to respond (often caused by
|
|
|
|
* device disconnect), or some other fault.
|
|
|
|
*
|
|
|
|
* -ETIME (**) No response packet received within the prescribed
|
|
|
|
* bus turn-around time. This error may instead be
|
|
|
|
* reported as -EPROTO or -EILSEQ.
|
|
|
|
*
|
|
|
|
* -ETIMEDOUT Synchronous USB message functions use this code
|
|
|
|
* to indicate timeout expired before the transfer
|
|
|
|
* completed, and no other error was reported by HC.
|
|
|
|
*
|
|
|
|
* -EPIPE (**) Endpoint stalled. For non-control endpoints,
|
|
|
|
* reset this status with usb_clear_halt().
|
|
|
|
*
|
|
|
|
* -ECOMM During an IN transfer, the host controller
|
|
|
|
* received data from an endpoint faster than it
|
|
|
|
* could be written to system memory
|
|
|
|
*
|
|
|
|
* -ENOSR During an OUT transfer, the host controller
|
|
|
|
* could not retrieve data from system memory fast
|
|
|
|
* enough to keep up with the USB data rate
|
|
|
|
*
|
|
|
|
* -EOVERFLOW (*) The amount of data returned by the endpoint was
|
|
|
|
* greater than either the max packet size of the
|
|
|
|
* endpoint or the remaining buffer size. "Babble".
|
|
|
|
*
|
|
|
|
* -EREMOTEIO The data read from the endpoint did not fill the
|
|
|
|
* specified buffer, and URB_SHORT_NOT_OK was set in
|
|
|
|
* urb->transfer_flags.
|
|
|
|
*
|
|
|
|
* -ENODEV Device was removed. Often preceded by a burst of
|
|
|
|
* other errors, since the hub driver doesn't detect
|
|
|
|
* device removal events immediately.
|
|
|
|
*
|
|
|
|
* -EXDEV ISO transfer only partially completed
|
|
|
|
* (only set in iso_frame_desc[n].status, not urb->status)
|
|
|
|
*
|
|
|
|
* -EINVAL ISO madness, if this happens: Log off and go home
|
|
|
|
*
|
|
|
|
* -ECONNRESET URB was asynchronously unlinked by usb_unlink_urb
|
|
|
|
*
|
|
|
|
* -ESHUTDOWN The device or host controller has been disabled due
|
|
|
|
* to some problem that could not be worked around,
|
|
|
|
* such as a physical disconnect.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* (*) Error codes like -EPROTO, -EILSEQ and -EOVERFLOW normally indicate
|
|
|
|
* hardware problems such as bad devices (including firmware) or cables.
|
|
|
|
*
|
|
|
|
* (**) This is also one of several codes that different kinds of host
|
|
|
|
* controller use to indicate a transfer has failed because of device
|
|
|
|
* disconnect. In the interval before the hub driver starts disconnect
|
|
|
|
* processing, devices may receive such fault reports for every request.
|
|
|
|
*
|
2017-04-05 13:23:15 +00:00
|
|
|
* See <https://www.kernel.org/doc/Documentation/driver-api/usb/error-codes.rst>
|
2015-07-24 14:11:55 +00:00
|
|
|
*/
|
|
|
|
static void hdm_read_completion(struct urb *urb)
|
|
|
|
{
|
2016-08-19 09:12:59 +00:00
|
|
|
struct mbo *mbo = urb->context;
|
|
|
|
struct most_dev *mdev = to_mdev(mbo->ifp);
|
|
|
|
unsigned int channel = mbo->hdm_channel_id;
|
|
|
|
struct device *dev = &mdev->usb_device->dev;
|
2016-09-19 15:40:25 +00:00
|
|
|
spinlock_t *lock = mdev->channel_lock + channel;
|
2015-07-24 14:11:55 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2016-08-19 09:12:56 +00:00
|
|
|
spin_lock_irqsave(lock, flags);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-10-04 15:10:21 +00:00
|
|
|
mbo->processed_length = 0;
|
|
|
|
mbo->status = MBO_E_INVAL;
|
|
|
|
if (likely(mdev->is_channel_healthy[channel])) {
|
2015-07-24 14:11:55 +00:00
|
|
|
switch (urb->status) {
|
2016-10-04 15:10:21 +00:00
|
|
|
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;
|
2015-07-24 14:11:55 +00:00
|
|
|
case -EPIPE:
|
2018-05-08 09:45:07 +00:00
|
|
|
dev_warn(dev, "Broken pipe on ep%02x\n",
|
|
|
|
mdev->ep_address[channel]);
|
2016-08-19 09:12:51 +00:00
|
|
|
mdev->is_channel_healthy[channel] = false;
|
2016-08-19 09:12:47 +00:00
|
|
|
mdev->clear_work[channel].pipe = urb->pipe;
|
|
|
|
schedule_work(&mdev->clear_work[channel].ws);
|
2016-10-04 15:10:21 +00:00
|
|
|
break;
|
2015-07-24 14:11:55 +00:00
|
|
|
case -ENODEV:
|
|
|
|
case -EPROTO:
|
|
|
|
mbo->status = MBO_E_CLOSE;
|
|
|
|
break;
|
|
|
|
case -EOVERFLOW:
|
2018-05-08 09:45:07 +00:00
|
|
|
dev_warn(dev, "Babble on ep%02x\n",
|
|
|
|
mdev->ep_address[channel]);
|
2015-07-24 14:11:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-08-19 09:12:56 +00:00
|
|
|
|
2016-08-19 09:12:55 +00:00
|
|
|
spin_unlock_irqrestore(lock, flags);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
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!
|
|
|
|
*/
|
2015-10-15 11:28:56 +00:00
|
|
|
static int hdm_enqueue(struct most_interface *iface, int channel,
|
|
|
|
struct mbo *mbo)
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
|
|
|
struct most_dev *mdev;
|
|
|
|
struct most_channel_config *conf;
|
|
|
|
int retval = 0;
|
|
|
|
struct urb *urb;
|
|
|
|
unsigned long length;
|
|
|
|
void *virt_address;
|
|
|
|
|
2020-05-05 10:00:26 +00:00
|
|
|
if (unlikely(!mbo))
|
2015-07-24 14:11:55 +00:00
|
|
|
return -EIO;
|
2016-08-19 09:12:58 +00:00
|
|
|
if (unlikely(iface->num_channels <= channel || channel < 0))
|
2015-07-24 14:11:55 +00:00
|
|
|
return -ECHRNG;
|
|
|
|
|
|
|
|
mdev = to_mdev(iface);
|
|
|
|
conf = &mdev->conf[channel];
|
|
|
|
|
2018-05-08 09:45:15 +00:00
|
|
|
mutex_lock(&mdev->io_mutex);
|
|
|
|
if (!mdev->usb_device) {
|
|
|
|
retval = -ENODEV;
|
2018-09-21 09:28:51 +00:00
|
|
|
goto unlock_io_mutex;
|
2018-05-08 09:45:15 +00:00
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_ATOMIC);
|
2018-05-08 09:45:15 +00:00
|
|
|
if (!urb) {
|
|
|
|
retval = -ENOMEM;
|
2018-09-21 09:28:51 +00:00
|
|
|
goto unlock_io_mutex;
|
2018-05-08 09:45:15 +00:00
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-08-19 09:12:58 +00:00
|
|
|
if ((conf->direction & MOST_CH_TX) && mdev->padding_active[channel] &&
|
|
|
|
hdm_add_padding(mdev, channel, mbo)) {
|
|
|
|
retval = -EIO;
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_free_urb;
|
2016-08-19 09:12:58 +00:00
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
urb->transfer_dma = mbo->bus_address;
|
|
|
|
virt_address = mbo->virt_address;
|
|
|
|
length = mbo->buffer_length;
|
|
|
|
|
|
|
|
if (conf->direction & MOST_CH_TX) {
|
|
|
|
usb_fill_bulk_urb(urb, mdev->usb_device,
|
|
|
|
usb_sndbulkpipe(mdev->usb_device,
|
|
|
|
mdev->ep_address[channel]),
|
|
|
|
virt_address,
|
|
|
|
length,
|
|
|
|
hdm_write_completion,
|
|
|
|
mbo);
|
2018-05-08 09:45:14 +00:00
|
|
|
if (conf->data_type != MOST_CH_ISOC &&
|
|
|
|
conf->data_type != MOST_CH_SYNC)
|
2015-07-24 14:11:55 +00:00
|
|
|
urb->transfer_flags |= URB_ZERO_PACKET;
|
|
|
|
} else {
|
|
|
|
usb_fill_bulk_urb(urb, mdev->usb_device,
|
|
|
|
usb_rcvbulkpipe(mdev->usb_device,
|
|
|
|
mdev->ep_address[channel]),
|
|
|
|
virt_address,
|
2015-09-28 15:18:34 +00:00
|
|
|
length + conf->extra_len,
|
2015-07-24 14:11:55 +00:00
|
|
|
hdm_read_completion,
|
|
|
|
mbo);
|
|
|
|
}
|
|
|
|
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
|
|
|
|
2016-09-19 15:40:22 +00:00
|
|
|
usb_anchor_urb(urb, &mdev->busy_urbs[channel]);
|
2016-07-18 15:25:27 +00:00
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
retval = usb_submit_urb(urb, GFP_KERNEL);
|
|
|
|
if (retval) {
|
2018-05-08 09:45:16 +00:00
|
|
|
dev_err(&mdev->usb_device->dev,
|
|
|
|
"URB submit failed with error %d.\n", retval);
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_unanchor_urb;
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
2018-09-21 09:28:51 +00:00
|
|
|
goto unlock_io_mutex;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2018-09-21 09:28:51 +00:00
|
|
|
err_unanchor_urb:
|
2016-09-19 15:40:22 +00:00
|
|
|
usb_unanchor_urb(urb);
|
2018-09-21 09:28:51 +00:00
|
|
|
err_free_urb:
|
2015-07-24 14:11:55 +00:00
|
|
|
usb_free_urb(urb);
|
2018-09-21 09:28:51 +00:00
|
|
|
unlock_io_mutex:
|
2018-05-08 09:45:15 +00:00
|
|
|
mutex_unlock(&mdev->io_mutex);
|
2015-07-24 14:11:55 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2018-05-08 09:45:03 +00:00
|
|
|
static void *hdm_dma_alloc(struct mbo *mbo, u32 size)
|
|
|
|
{
|
|
|
|
struct most_dev *mdev = to_mdev(mbo->ifp);
|
|
|
|
|
|
|
|
return usb_alloc_coherent(mdev->usb_device, size, GFP_KERNEL,
|
|
|
|
&mbo->bus_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hdm_dma_free(struct mbo *mbo, u32 size)
|
|
|
|
{
|
|
|
|
struct most_dev *mdev = to_mdev(mbo->ifp);
|
|
|
|
|
|
|
|
usb_free_coherent(mdev->usb_device, size, mbo->virt_address,
|
|
|
|
mbo->bus_address);
|
|
|
|
}
|
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
/**
|
|
|
|
* hdm_configure_channel - receive channel configuration from core
|
|
|
|
* @iface: interface
|
|
|
|
* @channel: channel ID
|
|
|
|
* @conf: structure that holds the configuration information
|
2016-10-28 12:46:20 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2015-07-24 14:11:55 +00:00
|
|
|
*/
|
2015-08-14 10:18:02 +00:00
|
|
|
static int hdm_configure_channel(struct most_interface *iface, int channel,
|
|
|
|
struct most_channel_config *conf)
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
|
|
|
unsigned int num_frames;
|
|
|
|
unsigned int frame_size;
|
2016-08-19 09:12:59 +00:00
|
|
|
struct most_dev *mdev = to_mdev(iface);
|
|
|
|
struct device *dev = &mdev->usb_device->dev;
|
2015-07-30 16:19:41 +00:00
|
|
|
|
|
|
|
mdev->is_channel_healthy[channel] = true;
|
2016-08-19 09:12:47 +00:00
|
|
|
mdev->clear_work[channel].channel = channel;
|
|
|
|
mdev->clear_work[channel].mdev = mdev;
|
|
|
|
INIT_WORK(&mdev->clear_work[channel].ws, wq_clear_halt);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2020-05-05 10:00:26 +00:00
|
|
|
if (unlikely(!conf)) {
|
|
|
|
dev_err(dev, "Bad config pointer.\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-08-19 09:12:58 +00:00
|
|
|
if (unlikely(channel < 0 || channel >= iface->num_channels)) {
|
2015-07-30 16:19:41 +00:00
|
|
|
dev_err(dev, "Channel ID out of range.\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-08-19 09:12:58 +00:00
|
|
|
if (!conf->num_buffers || !conf->buffer_size) {
|
2015-07-30 16:19:41 +00:00
|
|
|
dev_err(dev, "Misconfig: buffer size or #buffers zero.\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-08-19 09:12:58 +00:00
|
|
|
if (conf->data_type != MOST_CH_SYNC &&
|
2016-09-21 12:49:10 +00:00
|
|
|
!(conf->data_type == MOST_CH_ISOC &&
|
2016-08-19 09:12:58 +00:00
|
|
|
conf->packets_per_xact != 0xFF)) {
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->padding_active[channel] = false;
|
2016-10-28 12:46:20 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-07-24 14:11:55 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdev->padding_active[channel] = true;
|
|
|
|
|
|
|
|
frame_size = get_stream_frame_size(conf);
|
2016-08-19 09:12:58 +00:00
|
|
|
if (frame_size == 0 || frame_size > USB_MTU) {
|
2015-07-30 16:19:41 +00:00
|
|
|
dev_warn(dev, "Misconfig: frame size wrong\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-04-07 13:38:38 +00:00
|
|
|
num_frames = conf->buffer_size / frame_size;
|
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
if (conf->buffer_size % frame_size) {
|
2017-04-07 13:38:38 +00:00
|
|
|
u16 old_size = conf->buffer_size;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2017-04-07 13:38:38 +00:00
|
|
|
conf->buffer_size = num_frames * frame_size;
|
|
|
|
dev_warn(dev, "%s: fixed buffer size (%d -> %d)\n",
|
|
|
|
mdev->suffix[channel], old_size, conf->buffer_size);
|
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
/* calculate extra length to comply w/ HW padding */
|
2017-04-07 13:38:38 +00:00
|
|
|
conf->extra_len = num_frames * (USB_MTU - frame_size);
|
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
exit:
|
|
|
|
mdev->conf[channel] = *conf;
|
2016-10-25 15:44:20 +00:00
|
|
|
if (conf->data_type == MOST_CH_ASYNC) {
|
|
|
|
u16 ep = mdev->ep_address[channel];
|
|
|
|
|
2016-10-25 15:44:21 +00:00
|
|
|
if (start_sync_ep(mdev->usb_device, ep) < 0)
|
2016-10-25 15:44:20 +00:00
|
|
|
dev_warn(dev, "sync for ep%02x failed", ep);
|
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
*/
|
2017-05-12 10:59:54 +00:00
|
|
|
static void hdm_request_netinfo(struct most_interface *iface, int channel,
|
|
|
|
void (*on_netinfo)(struct most_interface *,
|
|
|
|
unsigned char,
|
|
|
|
unsigned char *))
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
|
|
|
struct most_dev *mdev;
|
|
|
|
|
|
|
|
mdev = to_mdev(iface);
|
2017-05-12 10:59:54 +00:00
|
|
|
mdev->on_netinfo = on_netinfo;
|
|
|
|
if (!on_netinfo)
|
|
|
|
return;
|
|
|
|
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->link_stat_timer.expires = jiffies + HZ;
|
|
|
|
mod_timer(&mdev->link_stat_timer, mdev->link_stat_timer.expires);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-04 15:10:19 +00:00
|
|
|
* link_stat_timer_handler - schedule work obtaining mac address and link status
|
2015-07-24 14:11:55 +00:00
|
|
|
* @data: pointer to USB device instance
|
|
|
|
*
|
|
|
|
* The handler runs in interrupt context. That's why we need to defer the
|
|
|
|
* tasks to a work queue.
|
|
|
|
*/
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
static void link_stat_timer_handler(struct timer_list *t)
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
struct most_dev *mdev = from_timer(mdev, t, link_stat_timer);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-02-20 09:45:38 +00:00
|
|
|
schedule_work(&mdev->poll_work_obj);
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->link_stat_timer.expires = jiffies + (2 * HZ);
|
|
|
|
add_timer(&mdev->link_stat_timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-04 15:10:19 +00:00
|
|
|
* wq_netinfo - work queue function to deliver latest networking information
|
2015-07-24 14:11:55 +00:00
|
|
|
* @wq_obj: object that holds data for our deferred work to do
|
|
|
|
*
|
|
|
|
* This retrieves the network interface status of the USB INIC
|
|
|
|
*/
|
|
|
|
static void wq_netinfo(struct work_struct *wq_obj)
|
|
|
|
{
|
2016-08-19 09:12:59 +00:00
|
|
|
struct most_dev *mdev = to_mdev_from_work(wq_obj);
|
2016-10-04 15:10:19 +00:00
|
|
|
struct usb_device *usb_device = mdev->usb_device;
|
|
|
|
struct device *dev = &usb_device->dev;
|
|
|
|
u16 hi, mi, lo, link;
|
|
|
|
u8 hw_addr[6];
|
|
|
|
|
|
|
|
if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_HI, &hi) < 0) {
|
|
|
|
dev_err(dev, "Vendor request 'hw_addr_hi' failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-10-04 15:10:19 +00:00
|
|
|
if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_MI, &mi) < 0) {
|
|
|
|
dev_err(dev, "Vendor request 'hw_addr_mid' failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_LO, &lo) < 0) {
|
|
|
|
dev_err(dev, "Vendor request 'hw_addr_low' failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-10-04 15:10:19 +00:00
|
|
|
if (drci_rd_reg(usb_device, DRCI_REG_NI_STATE, &link) < 0) {
|
|
|
|
dev_err(dev, "Vendor request 'link status' failed\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
return;
|
2016-10-04 15:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-05-12 10:59:54 +00:00
|
|
|
if (mdev->on_netinfo)
|
|
|
|
mdev->on_netinfo(&mdev->iface, link, hw_addr);
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wq_clear_halt - work queue function
|
|
|
|
* @wq_obj: work_struct object to execute
|
|
|
|
*
|
|
|
|
* This sends a clear_halt to the given USB pipe.
|
|
|
|
*/
|
|
|
|
static void wq_clear_halt(struct work_struct *wq_obj)
|
|
|
|
{
|
2016-08-19 09:12:47 +00:00
|
|
|
struct clear_hold_work *clear_work = to_clear_hold_work(wq_obj);
|
|
|
|
struct most_dev *mdev = clear_work->mdev;
|
|
|
|
unsigned int channel = clear_work->channel;
|
|
|
|
int pipe = clear_work->pipe;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-08-19 09:12:47 +00:00
|
|
|
mutex_lock(&mdev->io_mutex);
|
2016-08-19 09:12:54 +00:00
|
|
|
most_stop_enqueue(&mdev->iface, channel);
|
2016-10-04 15:10:21 +00:00
|
|
|
usb_kill_anchored_urbs(&mdev->busy_urbs[channel]);
|
2016-08-19 09:12:47 +00:00
|
|
|
if (usb_clear_halt(mdev->usb_device, pipe))
|
2015-07-30 16:19:41 +00:00
|
|
|
dev_warn(&mdev->usb_device->dev, "Failed to reset endpoint.\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2017-11-21 14:05:15 +00:00
|
|
|
/* 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) {
|
|
|
|
int peer = 1 - channel;
|
|
|
|
int snd_pipe = usb_sndbulkpipe(mdev->usb_device,
|
|
|
|
mdev->ep_address[peer]);
|
|
|
|
usb_clear_halt(mdev->usb_device, snd_pipe);
|
|
|
|
}
|
2016-08-19 09:12:51 +00:00
|
|
|
mdev->is_channel_healthy[channel] = true;
|
2016-08-19 09:12:48 +00:00
|
|
|
most_resume_enqueue(&mdev->iface, channel);
|
2016-08-19 09:12:47 +00:00
|
|
|
mutex_unlock(&mdev->io_mutex);
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hdm_usb_fops - file operation table for USB driver
|
|
|
|
*/
|
|
|
|
static const struct file_operations hdm_usb_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_device_id - ID table for HCD device probing
|
|
|
|
*/
|
2017-08-08 17:23:13 +00:00
|
|
|
static const struct usb_device_id usbid[] = {
|
2015-07-24 14:11:55 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_BRDG), },
|
2016-08-19 09:12:50 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81118), },
|
2016-08-19 09:12:49 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81119), },
|
2016-08-19 09:13:01 +00:00
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81210), },
|
2015-07-24 14:11:55 +00:00
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
2016-09-09 13:25:38 +00:00
|
|
|
struct regs {
|
|
|
|
const char *name;
|
|
|
|
u16 reg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regs ro_regs[] = {
|
|
|
|
{ "ni_state", DRCI_REG_NI_STATE },
|
|
|
|
{ "packet_bandwidth", DRCI_REG_PACKET_BW },
|
|
|
|
{ "node_address", DRCI_REG_NODE_ADDR },
|
|
|
|
{ "node_position", DRCI_REG_NODE_POS },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regs rw_regs[] = {
|
|
|
|
{ "mep_filter", DRCI_REG_MEP_FILTER },
|
|
|
|
{ "mep_hash0", DRCI_REG_HASH_TBL0 },
|
|
|
|
{ "mep_hash1", DRCI_REG_HASH_TBL1 },
|
|
|
|
{ "mep_hash2", DRCI_REG_HASH_TBL2 },
|
|
|
|
{ "mep_hash3", DRCI_REG_HASH_TBL3 },
|
|
|
|
{ "mep_eui48_hi", DRCI_REG_HW_ADDR_HI },
|
|
|
|
{ "mep_eui48_mi", DRCI_REG_HW_ADDR_MI },
|
|
|
|
{ "mep_eui48_lo", DRCI_REG_HW_ADDR_LO },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int get_stat_reg_addr(const struct regs *regs, int size,
|
|
|
|
const char *name, u16 *reg_addr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
if (!strcmp(name, regs[i].name)) {
|
|
|
|
*reg_addr = regs[i].reg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define get_static_reg_addr(regs, name, reg_addr) \
|
|
|
|
get_stat_reg_addr(regs, ARRAY_SIZE(regs), name, reg_addr)
|
|
|
|
|
2017-11-21 14:05:24 +00:00
|
|
|
static ssize_t value_show(struct device *dev, struct device_attribute *attr,
|
2017-11-21 14:04:43 +00:00
|
|
|
char *buf)
|
2015-07-24 14:11:55 +00:00
|
|
|
{
|
2016-09-09 13:25:43 +00:00
|
|
|
const char *name = attr->attr.name;
|
2017-11-21 14:04:43 +00:00
|
|
|
struct most_dci_obj *dci_obj = to_dci_obj(dev);
|
2016-09-09 13:25:40 +00:00
|
|
|
u16 val;
|
2015-07-24 14:11:55 +00:00
|
|
|
u16 reg_addr;
|
|
|
|
int err;
|
|
|
|
|
2016-09-09 13:25:43 +00:00
|
|
|
if (!strcmp(name, "arb_address"))
|
2016-09-09 13:25:35 +00:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%04x\n", dci_obj->reg_addr);
|
2016-09-09 13:25:43 +00:00
|
|
|
|
|
|
|
if (!strcmp(name, "arb_value"))
|
2016-09-09 13:25:35 +00:00
|
|
|
reg_addr = dci_obj->reg_addr;
|
2016-09-09 13:25:43 +00:00
|
|
|
else if (get_static_reg_addr(ro_regs, name, ®_addr) &&
|
|
|
|
get_static_reg_addr(rw_regs, name, ®_addr))
|
2016-09-09 13:25:39 +00:00
|
|
|
return -EFAULT;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-09-09 13:25:40 +00:00
|
|
|
err = drci_rd_reg(dci_obj->usb_device, reg_addr, &val);
|
2015-07-24 14:11:55 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2016-09-09 13:25:40 +00:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%04x\n", val);
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 14:05:24 +00:00
|
|
|
static ssize_t value_store(struct device *dev, struct device_attribute *attr,
|
2015-07-24 14:11:55 +00:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
2015-09-28 15:18:39 +00:00
|
|
|
u16 val;
|
2015-07-24 14:11:55 +00:00
|
|
|
u16 reg_addr;
|
2016-09-09 13:25:43 +00:00
|
|
|
const char *name = attr->attr.name;
|
2017-11-21 14:04:43 +00:00
|
|
|
struct most_dci_obj *dci_obj = to_dci_obj(dev);
|
2016-10-25 15:44:21 +00:00
|
|
|
struct usb_device *usb_dev = dci_obj->usb_device;
|
2016-09-09 13:25:41 +00:00
|
|
|
int err = kstrtou16(buf, 16, &val);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-09-09 13:25:35 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2016-09-09 13:25:43 +00:00
|
|
|
if (!strcmp(name, "arb_address")) {
|
2016-09-09 13:25:35 +00:00
|
|
|
dci_obj->reg_addr = val;
|
|
|
|
return count;
|
|
|
|
}
|
2016-09-09 13:25:43 +00:00
|
|
|
|
2016-10-25 15:44:21 +00:00
|
|
|
if (!strcmp(name, "arb_value"))
|
|
|
|
err = drci_wr_reg(usb_dev, dci_obj->reg_addr, val);
|
|
|
|
else if (!strcmp(name, "sync_ep"))
|
|
|
|
err = start_sync_ep(usb_dev, val);
|
2017-04-07 13:38:40 +00:00
|
|
|
else if (!get_static_reg_addr(rw_regs, name, ®_addr))
|
2016-10-25 15:44:21 +00:00
|
|
|
err = drci_wr_reg(usb_dev, reg_addr, val);
|
|
|
|
else
|
2016-09-09 13:25:36 +00:00
|
|
|
return -EFAULT;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-11-27 14:20:06 +00:00
|
|
|
static DEVICE_ATTR(ni_state, 0444, value_show, NULL);
|
|
|
|
static DEVICE_ATTR(packet_bandwidth, 0444, value_show, NULL);
|
|
|
|
static DEVICE_ATTR(node_address, 0444, value_show, NULL);
|
|
|
|
static DEVICE_ATTR(node_position, 0444, value_show, NULL);
|
|
|
|
static DEVICE_ATTR(sync_ep, 0200, NULL, value_store);
|
|
|
|
static DEVICE_ATTR(mep_filter, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(mep_hash0, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(mep_hash1, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(mep_hash2, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(mep_hash3, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(mep_eui48_hi, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(mep_eui48_mi, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(mep_eui48_lo, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(arb_address, 0644, value_show, value_store);
|
|
|
|
static DEVICE_ATTR(arb_value, 0644, value_show, value_store);
|
2017-11-21 14:04:43 +00:00
|
|
|
|
|
|
|
static struct attribute *dci_attrs[] = {
|
|
|
|
&dev_attr_ni_state.attr,
|
|
|
|
&dev_attr_packet_bandwidth.attr,
|
|
|
|
&dev_attr_node_address.attr,
|
|
|
|
&dev_attr_node_position.attr,
|
|
|
|
&dev_attr_sync_ep.attr,
|
|
|
|
&dev_attr_mep_filter.attr,
|
|
|
|
&dev_attr_mep_hash0.attr,
|
|
|
|
&dev_attr_mep_hash1.attr,
|
|
|
|
&dev_attr_mep_hash2.attr,
|
|
|
|
&dev_attr_mep_hash3.attr,
|
|
|
|
&dev_attr_mep_eui48_hi.attr,
|
|
|
|
&dev_attr_mep_eui48_mi.attr,
|
|
|
|
&dev_attr_mep_eui48_lo.attr,
|
|
|
|
&dev_attr_arb_address.attr,
|
|
|
|
&dev_attr_arb_value.attr,
|
2015-07-24 14:11:55 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-11-21 14:04:43 +00:00
|
|
|
static struct attribute_group dci_attr_group = {
|
|
|
|
.attrs = dci_attrs,
|
2015-07-24 14:11:55 +00:00
|
|
|
};
|
|
|
|
|
2017-11-21 14:04:43 +00:00
|
|
|
static const struct attribute_group *dci_attr_groups[] = {
|
|
|
|
&dci_attr_group,
|
|
|
|
NULL,
|
|
|
|
};
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2018-09-28 21:37:19 +00:00
|
|
|
static void release_dci(struct device *dev)
|
|
|
|
{
|
|
|
|
struct most_dci_obj *dci = to_dci_obj(dev);
|
|
|
|
|
|
|
|
kfree(dci);
|
|
|
|
}
|
|
|
|
|
2020-01-23 15:38:17 +00:00
|
|
|
static void release_mdev(struct device *dev)
|
|
|
|
{
|
|
|
|
struct most_dev *mdev = to_mdev_from_dev(dev);
|
|
|
|
|
|
|
|
kfree(mdev);
|
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
|
|
|
|
{
|
2016-08-19 09:12:59 +00:00
|
|
|
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 = kzalloc(sizeof(*mdev), GFP_KERNEL);
|
2015-07-24 14:11:55 +00:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int num_endpoints;
|
|
|
|
struct most_channel_capability *tmp_cap;
|
|
|
|
struct usb_endpoint_descriptor *ep_desc;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!mdev)
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_out_of_memory;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
usb_set_intfdata(interface, mdev);
|
|
|
|
num_endpoints = usb_iface_desc->desc.bNumEndpoints;
|
|
|
|
mutex_init(&mdev->io_mutex);
|
|
|
|
INIT_WORK(&mdev->poll_work_obj, wq_netinfo);
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
timer_setup(&mdev->link_stat_timer, link_stat_timer_handler, 0);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
mdev->usb_device = usb_dev;
|
|
|
|
mdev->link_stat_timer.expires = jiffies + (2 * HZ);
|
|
|
|
|
|
|
|
mdev->iface.mod = hdm_usb_fops.owner;
|
2020-01-23 15:38:17 +00:00
|
|
|
mdev->iface.dev = &mdev->dev;
|
2018-05-08 09:45:04 +00:00
|
|
|
mdev->iface.driver_dev = &interface->dev;
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->iface.interface = ITYPE_USB;
|
|
|
|
mdev->iface.configure = hdm_configure_channel;
|
|
|
|
mdev->iface.request_netinfo = hdm_request_netinfo;
|
|
|
|
mdev->iface.enqueue = hdm_enqueue;
|
|
|
|
mdev->iface.poison_channel = hdm_poison_channel;
|
2018-05-08 09:45:03 +00:00
|
|
|
mdev->iface.dma_alloc = hdm_dma_alloc;
|
|
|
|
mdev->iface.dma_free = hdm_dma_free;
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->iface.description = mdev->description;
|
|
|
|
mdev->iface.num_channels = num_endpoints;
|
|
|
|
|
|
|
|
snprintf(mdev->description, sizeof(mdev->description),
|
2019-04-03 13:19:50 +00:00
|
|
|
"%d-%s:%d.%d",
|
2015-07-24 14:11:55 +00:00
|
|
|
usb_dev->bus->busnum,
|
|
|
|
usb_dev->devpath,
|
|
|
|
usb_dev->config->desc.bConfigurationValue,
|
|
|
|
usb_iface_desc->desc.bInterfaceNumber);
|
|
|
|
|
2020-01-23 15:38:17 +00:00
|
|
|
mdev->dev.init_name = mdev->description;
|
|
|
|
mdev->dev.parent = &interface->dev;
|
|
|
|
mdev->dev.release = release_mdev;
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->conf = kcalloc(num_endpoints, sizeof(*mdev->conf), GFP_KERNEL);
|
|
|
|
if (!mdev->conf)
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_free_mdev;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
mdev->cap = kcalloc(num_endpoints, sizeof(*mdev->cap), GFP_KERNEL);
|
|
|
|
if (!mdev->cap)
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_free_conf;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
mdev->iface.channel_vector = mdev->cap;
|
|
|
|
mdev->ep_address =
|
|
|
|
kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL);
|
|
|
|
if (!mdev->ep_address)
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_free_cap;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2016-09-19 15:40:22 +00:00
|
|
|
mdev->busy_urbs =
|
|
|
|
kcalloc(num_endpoints, sizeof(*mdev->busy_urbs), GFP_KERNEL);
|
|
|
|
if (!mdev->busy_urbs)
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_free_ep_address;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
tmp_cap = mdev->cap;
|
|
|
|
for (i = 0; i < num_endpoints; i++) {
|
|
|
|
ep_desc = &usb_iface_desc->endpoint[i].desc;
|
|
|
|
mdev->ep_address[i] = ep_desc->bEndpointAddress;
|
|
|
|
mdev->padding_active[i] = false;
|
|
|
|
mdev->is_channel_healthy[i] = true;
|
|
|
|
|
|
|
|
snprintf(&mdev->suffix[i][0], MAX_SUFFIX_LEN, "ep%02x",
|
|
|
|
mdev->ep_address[i]);
|
|
|
|
|
|
|
|
tmp_cap->name_suffix = &mdev->suffix[i][0];
|
|
|
|
tmp_cap->buffer_size_packet = MAX_BUF_SIZE;
|
|
|
|
tmp_cap->buffer_size_streaming = MAX_BUF_SIZE;
|
|
|
|
tmp_cap->num_buffers_packet = BUF_CHAIN_SIZE;
|
|
|
|
tmp_cap->num_buffers_streaming = BUF_CHAIN_SIZE;
|
|
|
|
tmp_cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC |
|
2016-09-21 12:49:10 +00:00
|
|
|
MOST_CH_ISOC | MOST_CH_SYNC;
|
2016-03-06 10:20:35 +00:00
|
|
|
if (usb_endpoint_dir_in(ep_desc))
|
2015-07-24 14:11:55 +00:00
|
|
|
tmp_cap->direction = MOST_CH_RX;
|
|
|
|
else
|
|
|
|
tmp_cap->direction = MOST_CH_TX;
|
|
|
|
tmp_cap++;
|
2016-09-19 15:40:22 +00:00
|
|
|
init_usb_anchor(&mdev->busy_urbs[i]);
|
2016-09-19 15:40:25 +00:00
|
|
|
spin_lock_init(&mdev->channel_lock[i]);
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
2015-07-30 16:19:41 +00:00
|
|
|
dev_notice(dev, "claimed gadget: Vendor=%4.4x ProdID=%4.4x Bus=%02x Device=%02x\n",
|
|
|
|
le16_to_cpu(usb_dev->descriptor.idVendor),
|
|
|
|
le16_to_cpu(usb_dev->descriptor.idProduct),
|
|
|
|
usb_dev->bus->busnum,
|
|
|
|
usb_dev->devnum);
|
|
|
|
|
|
|
|
dev_notice(dev, "device path: /sys/bus/usb/devices/%d-%s:%d.%d\n",
|
|
|
|
usb_dev->bus->busnum,
|
|
|
|
usb_dev->devpath,
|
|
|
|
usb_dev->config->desc.bConfigurationValue,
|
|
|
|
usb_iface_desc->desc.bInterfaceNumber);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
2017-11-21 14:04:43 +00:00
|
|
|
ret = most_register_interface(&mdev->iface);
|
|
|
|
if (ret)
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_free_busy_urbs;
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
mutex_lock(&mdev->io_mutex);
|
2016-08-19 09:12:50 +00:00
|
|
|
if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81118 ||
|
2016-08-19 09:13:01 +00:00
|
|
|
le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81119 ||
|
|
|
|
le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81210) {
|
2017-11-21 14:04:43 +00:00
|
|
|
mdev->dci = kzalloc(sizeof(*mdev->dci), GFP_KERNEL);
|
2015-07-24 14:11:55 +00:00
|
|
|
if (!mdev->dci) {
|
|
|
|
mutex_unlock(&mdev->io_mutex);
|
|
|
|
most_deregister_interface(&mdev->iface);
|
|
|
|
ret = -ENOMEM;
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_free_busy_urbs;
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 14:04:43 +00:00
|
|
|
mdev->dci->dev.init_name = "dci";
|
2020-01-23 15:38:17 +00:00
|
|
|
mdev->dci->dev.parent = get_device(mdev->iface.dev);
|
2017-11-21 14:04:43 +00:00
|
|
|
mdev->dci->dev.groups = dci_attr_groups;
|
2018-09-28 21:37:19 +00:00
|
|
|
mdev->dci->dev.release = release_dci;
|
2017-11-21 14:04:43 +00:00
|
|
|
if (device_register(&mdev->dci->dev)) {
|
|
|
|
mutex_unlock(&mdev->io_mutex);
|
|
|
|
most_deregister_interface(&mdev->iface);
|
|
|
|
ret = -ENOMEM;
|
2018-09-21 09:28:51 +00:00
|
|
|
goto err_free_dci;
|
2017-11-21 14:04:43 +00:00
|
|
|
}
|
2015-07-24 14:11:55 +00:00
|
|
|
mdev->dci->usb_device = mdev->usb_device;
|
|
|
|
}
|
|
|
|
mutex_unlock(&mdev->io_mutex);
|
|
|
|
return 0;
|
2018-09-21 09:28:51 +00:00
|
|
|
err_free_dci:
|
2020-01-23 15:38:17 +00:00
|
|
|
put_device(&mdev->dci->dev);
|
2018-09-21 09:28:51 +00:00
|
|
|
err_free_busy_urbs:
|
2016-09-19 15:40:22 +00:00
|
|
|
kfree(mdev->busy_urbs);
|
2018-09-21 09:28:51 +00:00
|
|
|
err_free_ep_address:
|
2015-07-24 14:11:55 +00:00
|
|
|
kfree(mdev->ep_address);
|
2018-09-21 09:28:51 +00:00
|
|
|
err_free_cap:
|
2015-07-24 14:11:55 +00:00
|
|
|
kfree(mdev->cap);
|
2018-09-21 09:28:51 +00:00
|
|
|
err_free_conf:
|
2015-07-24 14:11:55 +00:00
|
|
|
kfree(mdev->conf);
|
2018-09-21 09:28:51 +00:00
|
|
|
err_free_mdev:
|
2020-01-23 15:38:17 +00:00
|
|
|
put_device(&mdev->dev);
|
2018-09-21 09:28:51 +00:00
|
|
|
err_out_of_memory:
|
2015-07-24 14:11:55 +00:00
|
|
|
if (ret == 0 || ret == -ENOMEM) {
|
|
|
|
ret = -ENOMEM;
|
2015-07-30 16:19:41 +00:00
|
|
|
dev_err(dev, "out of memory\n");
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
static void hdm_disconnect(struct usb_interface *interface)
|
|
|
|
{
|
2016-08-19 09:12:59 +00:00
|
|
|
struct most_dev *mdev = usb_get_intfdata(interface);
|
2015-07-24 14:11:55 +00:00
|
|
|
|
|
|
|
mutex_lock(&mdev->io_mutex);
|
|
|
|
usb_set_intfdata(interface, NULL);
|
|
|
|
mdev->usb_device = NULL;
|
|
|
|
mutex_unlock(&mdev->io_mutex);
|
|
|
|
|
|
|
|
del_timer_sync(&mdev->link_stat_timer);
|
|
|
|
cancel_work_sync(&mdev->poll_work_obj);
|
|
|
|
|
2020-01-23 15:38:23 +00:00
|
|
|
if (mdev->dci)
|
|
|
|
device_unregister(&mdev->dci->dev);
|
2015-07-24 14:11:55 +00:00
|
|
|
most_deregister_interface(&mdev->iface);
|
|
|
|
|
2016-09-19 15:40:22 +00:00
|
|
|
kfree(mdev->busy_urbs);
|
2015-07-24 14:11:55 +00:00
|
|
|
kfree(mdev->cap);
|
|
|
|
kfree(mdev->conf);
|
|
|
|
kfree(mdev->ep_address);
|
2020-01-23 15:38:17 +00:00
|
|
|
put_device(&mdev->dev);
|
2015-07-24 14:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_driver hdm_usb = {
|
|
|
|
.name = "hdm_usb",
|
|
|
|
.id_table = usbid,
|
|
|
|
.probe = hdm_probe,
|
|
|
|
.disconnect = hdm_disconnect,
|
|
|
|
};
|
|
|
|
|
2017-08-27 05:22:10 +00:00
|
|
|
module_usb_driver(hdm_usb);
|
2015-07-24 14:11:55 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
|
|
|
|
MODULE_DESCRIPTION("HDM_4_USB");
|