Skip to content

Commit

Permalink
Merge branch 'for-5.14/intel-ish' into for-linus
Browse files Browse the repository at this point in the history
- support for ISH DMA on EHL platform from Even Xu
- various code style fixes and cleanups from Lee Jones and Uwe Kleine-König
  • Loading branch information
Jiri Kosina committed Jun 30, 2021
2 parents 7f1f380 + aa59d6b commit 33197bd
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 71 deletions.
1 change: 1 addition & 0 deletions drivers/hid/intel-ish-hid/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ menu "Intel ISH HID support"
config INTEL_ISH_HID
tristate "Intel Integrated Sensor Hub"
default n
depends on X86
select HID
help
The Integrated Sensor Hub (ISH) enables the ability to offload
Expand Down
28 changes: 26 additions & 2 deletions drivers/hid/intel-ish-hid/ipc/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ static int ish_fw_reset_handler(struct ishtp_device *dev)
#define TIMEOUT_FOR_HW_RDY_MS 300

/**
* ish_fw_reset_work_fn() - FW reset worker function
* fw_reset_work_fn() - FW reset worker function
* @unused: not used
*
* Call ish_fw_reset_handler to complete FW reset
Expand Down Expand Up @@ -889,6 +889,29 @@ static uint32_t ish_ipc_get_header(struct ishtp_device *dev, int length,
return drbl_val;
}

/**
* _dma_no_cache_snooping()
*
* Check on current platform, DMA supports cache snooping or not.
* This callback is used to notify uplayer driver if manully cache
* flush is needed when do DMA operation.
*
* Please pay attention to this callback implementation, if declare
* having cache snooping on a cache snooping not supported platform
* will cause uplayer driver receiving mismatched data; and if
* declare no cache snooping on a cache snooping supported platform
* will cause cache be flushed twice and performance hit.
*
* @dev: ishtp device pointer
*
* Return: false - has cache snooping capability
* true - no cache snooping, need manually cache flush
*/
static bool _dma_no_cache_snooping(struct ishtp_device *dev)
{
return dev->pdev->device == EHL_Ax_DEVICE_ID;
}

static const struct ishtp_hw_ops ish_hw_ops = {
.hw_reset = _ish_hw_reset,
.ipc_reset = _ish_ipc_reset,
Expand All @@ -897,7 +920,8 @@ static const struct ishtp_hw_ops ish_hw_ops = {
.write = write_ipc_to_queue,
.get_fw_status = _ish_read_fw_sts_reg,
.sync_fw_clock = _ish_sync_fw_clock,
.ishtp_read_hdr = _ishtp_read_hdr
.ishtp_read_hdr = _ishtp_read_hdr,
.dma_no_cache_snooping = _dma_no_cache_snooping
};

/**
Expand Down
3 changes: 1 addition & 2 deletions drivers/hid/intel-ish-hid/ipc/pci-ish.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ static void __maybe_unused ish_resume_handler(struct work_struct *work)
struct pci_dev *pdev = to_pci_dev(ish_resume_device);
struct ishtp_device *dev = pci_get_drvdata(pdev);
uint32_t fwsts = dev->ops->get_fw_status(dev);
int ret;

if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag
&& IPC_IS_ISH_ILUP(fwsts)) {
Expand All @@ -275,7 +274,7 @@ static void __maybe_unused ish_resume_handler(struct work_struct *work)

/* Waiting to get resume response */
if (dev->resume_flag)
ret = wait_event_interruptible_timeout(dev->resume_wait,
wait_event_interruptible_timeout(dev->resume_wait,
!dev->resume_flag,
msecs_to_jiffies(WAIT_FOR_RESUME_ACK_MS));

Expand Down
49 changes: 24 additions & 25 deletions drivers/hid/intel-ish-hid/ishtp-fw-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

/**
* enum ish_loader_commands - ISH loader host commands.
* LOADER_CMD_XFER_QUERY Query the Shim firmware loader for
* @LOADER_CMD_XFER_QUERY: Query the Shim firmware loader for
* capabilities
* LOADER_CMD_XFER_FRAGMENT Transfer one firmware image fragment at a
* @LOADER_CMD_XFER_FRAGMENT: Transfer one firmware image fragment at a
* time. The command may be executed
* multiple times until the entire firmware
* image is downloaded to SRAM.
* LOADER_CMD_START Start executing the main firmware.
* @LOADER_CMD_START: Start executing the main firmware.
*/
enum ish_loader_commands {
LOADER_CMD_XFER_QUERY = 0,
Expand Down Expand Up @@ -95,6 +95,7 @@ static int dma_buf_size_limit = 4 * PAGE_SIZE;
/**
* struct loader_msg_hdr - Header for ISH Loader commands.
* @command: LOADER_CMD* commands. Bit 7 is the response.
* @reserved: Reserved space
* @status: Command response status. Non 0, is error
* condition.
*
Expand Down Expand Up @@ -173,16 +174,16 @@ struct loader_start {
* struct response_info - Encapsulate firmware response related
* information for passing between function
* loader_cl_send() and process_recv() callback.
* @data Copy the data received from firmware here.
* @max_size Max size allocated for the @data buffer. If the
* @data: Copy the data received from firmware here.
* @max_size: Max size allocated for the @data buffer. If the
* received data exceeds this value, we log an
* error.
* @size Actual size of data received from firmware.
* @error Returns 0 for success, negative error code for a
* @size: Actual size of data received from firmware.
* @error: Returns 0 for success, negative error code for a
* failure in function process_recv().
* @received Set to true on receiving a valid firmware
* @received: Set to true on receiving a valid firmware
* response to host command
* @wait_queue Wait queue for Host firmware loading where the
* @wait_queue: Wait queue for Host firmware loading where the
* client sends message to ISH firmware and waits
* for response
*/
Expand All @@ -195,13 +196,13 @@ struct response_info {
wait_queue_head_t wait_queue;
};

/**
/*
* struct ishtp_cl_data - Encapsulate per ISH-TP Client Data.
* @work_ishtp_reset: Work queue for reset handling.
* @work_fw_load: Work queue for host firmware loading.
* @flag_retry Flag for indicating host firmware loading should
* @flag_retry: Flag for indicating host firmware loading should
* be retried.
* @retry_count Count the number of retries.
* @retry_count: Count the number of retries.
*
* This structure is used to store data per client.
*/
Expand Down Expand Up @@ -240,8 +241,8 @@ struct ishtp_cl_data {
/**
* get_firmware_variant() - Gets the filename of firmware image to be
* loaded based on platform variant.
* @client_data Client data instance.
* @filename Returns firmware filename.
* @client_data: Client data instance.
* @filename: Returns firmware filename.
*
* Queries the firmware-name device property string.
*
Expand All @@ -266,11 +267,11 @@ static int get_firmware_variant(struct ishtp_cl_data *client_data,
/**
* loader_cl_send() Send message from host to firmware
* @client_data: Client data instance
* @out_msg Message buffer to be sent to firmware
* @out_size Size of out going message
* @in_msg Message buffer where the incoming data copied.
* @out_msg: Message buffer to be sent to firmware
* @out_size: Size of out going message
* @in_msg: Message buffer where the incoming data copied.
* This buffer is allocated by calling
* @in_size Max size of incoming message
* @in_size: Max size of incoming message
*
* Return: Number of bytes copied in the in_msg on success, negative
* error code on failure.
Expand Down Expand Up @@ -435,7 +436,7 @@ static void process_recv(struct ishtp_cl *loader_ishtp_cl,

/**
* loader_cl_event_cb() - bus driver callback for incoming message
* @device: Pointer to the ishtp client device for which this
* @cl_device: Pointer to the ishtp client device for which this
* message is targeted
*
* Remove the packet from the list and process the message by calling
Expand Down Expand Up @@ -536,7 +537,7 @@ static int ish_query_loader_prop(struct ishtp_cl_data *client_data,
}

/**
* ish_fw_xfer_ishtp() Loads ISH firmware using ishtp interface
* ish_fw_xfer_ishtp() - Loads ISH firmware using ishtp interface
* @client_data: Client data instance
* @fw: Pointer to firmware data struct in host memory
*
Expand Down Expand Up @@ -733,7 +734,7 @@ static int ish_fw_xfer_direct_dma(struct ishtp_cl_data *client_data,
}

/**
* ish_fw_start() Start executing ISH main firmware
* ish_fw_start() - Start executing ISH main firmware
* @client_data: client data instance
*
* This function sends message to Shim firmware loader to start
Expand All @@ -756,7 +757,7 @@ static int ish_fw_start(struct ishtp_cl_data *client_data)
}

/**
* load_fw_from_host() Loads ISH firmware from host
* load_fw_from_host() - Loads ISH firmware from host
* @client_data: Client data instance
*
* This function loads the ISH firmware to ISH SRAM and starts execution
Expand Down Expand Up @@ -1015,7 +1016,7 @@ static int loader_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
*
* Return: 0
*/
static int loader_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
static void loader_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
{
struct ishtp_cl_data *client_data;
struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device);
Expand All @@ -1032,8 +1033,6 @@ static int loader_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
cancel_work_sync(&client_data->work_ishtp_reset);
loader_deinit(loader_ishtp_cl);
ishtp_put_device(cl_device);

return 0;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions drivers/hid/intel-ish-hid/ishtp-hid-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
#include <linux/sched.h>
#include "ishtp-hid.h"

/* ISH Transport protocol (ISHTP in short) GUID */
static const guid_t hid_ishtp_guid =
GUID_INIT(0x33AECD58, 0xB679, 0x4E54,
0x9B, 0xD9, 0xA0, 0x4D, 0x34, 0xF0, 0xC2, 0x26);

/* Rx ring buffer pool size */
#define HID_CL_RX_RING_SIZE 32
#define HID_CL_TX_RING_SIZE 16

#define cl_data_to_dev(client_data) ishtp_device(client_data->cl_device)

/**
* report_bad_packets() - Report bad packets
* report_bad_packet() - Report bad packets
* @hid_ishtp_cl: Client instance to get stats
* @recv_buf: Raw received host interface message
* @cur_pos: Current position index in payload
Expand Down Expand Up @@ -779,7 +784,7 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work)
}
}

void (*hid_print_trace)(void *unused, const char *format, ...);
ishtp_print_log ishtp_hid_print_trace;

/**
* hid_ishtp_cl_probe() - ISHTP client driver probe
Expand Down Expand Up @@ -818,7 +823,7 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device)

INIT_WORK(&client_data->work, hid_ishtp_cl_reset_handler);

hid_print_trace = ishtp_trace_callback(cl_device);
ishtp_hid_print_trace = ishtp_trace_callback(cl_device);

rv = hid_ishtp_cl_init(hid_ishtp_cl, 0);
if (rv) {
Expand All @@ -838,7 +843,7 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
*
* Return: 0
*/
static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
static void hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
{
struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
Expand All @@ -856,8 +861,6 @@ static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
hid_ishtp_cl = NULL;

client_data->num_hid_devices = 0;

return 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/intel-ish-hid/ishtp-hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ int ishtp_hid_probe(unsigned int cur_hid_dev,
}

/**
* ishtp_hid_probe() - Remove registered hid device
* ishtp_hid_remove() - Remove registered hid device
* @client_data: client data pointer
*
* This function is used to destroy allocatd HID device.
Expand Down
9 changes: 2 additions & 7 deletions drivers/hid/intel-ish-hid/ishtp-hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
#define IS_RESPONSE 0x80

/* Used to dump to Linux trace buffer, if enabled */
extern void (*hid_print_trace)(void *unused, const char *format, ...);
extern ishtp_print_log ishtp_hid_print_trace;
#define hid_ishtp_trace(client, ...) \
(hid_print_trace)(NULL, __VA_ARGS__)

/* ISH Transport protocol (ISHTP in short) GUID */
static const guid_t hid_ishtp_guid =
GUID_INIT(0x33AECD58, 0xB679, 0x4E54,
0x9B, 0xD9, 0xA0, 0x4D, 0x34, 0xF0, 0xC2, 0x26);
(ishtp_hid_print_trace)(NULL, __VA_ARGS__)

/* ISH HID message structure */
struct hostif_msg_hdr {
Expand Down
24 changes: 11 additions & 13 deletions drivers/hid/intel-ish-hid/ishtp/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ EXPORT_SYMBOL(ishtp_fw_cl_get_client);

/**
* ishtp_get_fw_client_id() - Get fw client id
* @fw_client: firmware client used to fetch the ID
*
* This interface is used to reset HW get FW client id.
*
Expand Down Expand Up @@ -257,24 +258,17 @@ static int ishtp_cl_bus_match(struct device *dev, struct device_driver *drv)
static int ishtp_cl_device_remove(struct device *dev)
{
struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
struct ishtp_cl_driver *driver;

if (!device || !dev->driver)
return 0;
struct ishtp_cl_driver *driver = to_ishtp_cl_driver(dev->driver);

if (device->event_cb) {
device->event_cb = NULL;
cancel_work_sync(&device->event_work);
}

driver = to_ishtp_cl_driver(dev->driver);
if (!driver->remove) {
dev->driver = NULL;
if (driver->remove)
driver->remove(device);

return 0;
}

return driver->remove(device);
return 0;
}

/**
Expand Down Expand Up @@ -842,6 +836,7 @@ int ishtp_use_dma_transfer(void)

/**
* ishtp_device() - Return device pointer
* @device: ISH-TP client device instance
*
* This interface is used to return device pointer from ishtp_cl_device
* instance.
Expand All @@ -858,6 +853,7 @@ EXPORT_SYMBOL(ishtp_device);
* ishtp_get_pci_device() - Return PCI device dev pointer
* This interface is used to return PCI device pointer
* from ishtp_cl_device instance.
* @device: ISH-TP client device instance
*
* Return: device *.
*/
Expand All @@ -869,19 +865,21 @@ EXPORT_SYMBOL(ishtp_get_pci_device);

/**
* ishtp_trace_callback() - Return trace callback
* @cl_device: ISH-TP client device instance
*
* This interface is used to return trace callback function pointer.
*
* Return: void *.
* Return: *ishtp_print_log()
*/
void *ishtp_trace_callback(struct ishtp_cl_device *cl_device)
ishtp_print_log ishtp_trace_callback(struct ishtp_cl_device *cl_device)
{
return cl_device->ishtp_dev->print_log;
}
EXPORT_SYMBOL(ishtp_trace_callback);

/**
* ish_hw_reset() - Call HW reset IPC callback
* @dev: ISHTP device instance
*
* This interface is used to reset HW in case of error.
*
Expand Down
Loading

0 comments on commit 33197bd

Please sign in to comment.