hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/hid/intel-ish-hid/ipc/ipc.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * H/W layer of ISHTP provider device (ISH)
34 *
45 * Copyright (c) 2014-2016, Intel Corporation.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms and conditions of the GNU General Public License,
8
- * version 2, as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope it will be useful, but WITHOUT
11
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- * more details.
146 */
157
168 #include <linux/sched.h>
....@@ -259,38 +251,27 @@
259251 int i;
260252 void (*ipc_send_compl)(void *);
261253 void *ipc_send_compl_prm;
262
- static int out_ipc_locked;
263
- unsigned long out_ipc_flags;
264254
265255 if (dev->dev_state == ISHTP_DEV_DISABLED)
266
- return -EINVAL;
267
-
268
- spin_lock_irqsave(&dev->out_ipc_spinlock, out_ipc_flags);
269
- if (out_ipc_locked) {
270
- spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags);
271
- return -EBUSY;
272
- }
273
- out_ipc_locked = 1;
274
- if (!ish_is_input_ready(dev)) {
275
- out_ipc_locked = 0;
276
- spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags);
277
- return -EBUSY;
278
- }
279
- spin_unlock_irqrestore(&dev->out_ipc_spinlock, out_ipc_flags);
256
+ return -EINVAL;
280257
281258 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
259
+ if (!ish_is_input_ready(dev)) {
260
+ spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
261
+ return -EBUSY;
262
+ }
263
+
282264 /*
283265 * if tx send list is empty - return 0;
284266 * may happen, as RX_COMPLETE handler doesn't check list emptiness.
285267 */
286
- if (list_empty(&dev->wr_processing_list_head.link)) {
268
+ if (list_empty(&dev->wr_processing_list)) {
287269 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
288
- out_ipc_locked = 0;
289270 return 0;
290271 }
291272
292
- ipc_link = list_entry(dev->wr_processing_list_head.link.next,
293
- struct wr_msg_ctl_info, link);
273
+ ipc_link = list_first_entry(&dev->wr_processing_list,
274
+ struct wr_msg_ctl_info, link);
294275 /* first 4 bytes of the data is the doorbell value (IPC header) */
295276 length = ipc_link->length - sizeof(uint32_t);
296277 doorbell_val = *(uint32_t *)ipc_link->inline_data;
....@@ -328,6 +309,8 @@
328309 memcpy(&reg, &r_buf[length >> 2], rem);
329310 ish_reg_write(dev, reg_addr, reg);
330311 }
312
+ ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, doorbell_val);
313
+
331314 /* Flush writes to msg registers and doorbell */
332315 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
333316
....@@ -335,13 +318,10 @@
335318 ++dev->ipc_tx_cnt;
336319 dev->ipc_tx_bytes_cnt += IPC_HEADER_GET_LENGTH(doorbell_val);
337320
338
- ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, doorbell_val);
339
- out_ipc_locked = 0;
340
-
341321 ipc_send_compl = ipc_link->ipc_send_compl;
342322 ipc_send_compl_prm = ipc_link->ipc_send_compl_prm;
343323 list_del_init(&ipc_link->link);
344
- list_add_tail(&ipc_link->link, &dev->wr_free_list_head.link);
324
+ list_add(&ipc_link->link, &dev->wr_free_list);
345325 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
346326
347327 /*
....@@ -375,18 +355,18 @@
375355 unsigned char *msg, int length)
376356 {
377357 struct wr_msg_ctl_info *ipc_link;
378
- unsigned long flags;
358
+ unsigned long flags;
379359
380360 if (length > IPC_FULL_MSG_SIZE)
381361 return -EMSGSIZE;
382362
383363 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
384
- if (list_empty(&dev->wr_free_list_head.link)) {
364
+ if (list_empty(&dev->wr_free_list)) {
385365 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
386366 return -ENOMEM;
387367 }
388
- ipc_link = list_entry(dev->wr_free_list_head.link.next,
389
- struct wr_msg_ctl_info, link);
368
+ ipc_link = list_first_entry(&dev->wr_free_list,
369
+ struct wr_msg_ctl_info, link);
390370 list_del_init(&ipc_link->link);
391371
392372 ipc_link->ipc_send_compl = ipc_send_compl;
....@@ -394,7 +374,7 @@
394374 ipc_link->length = length;
395375 memcpy(ipc_link->inline_data, msg, length);
396376
397
- list_add_tail(&ipc_link->link, &dev->wr_processing_list_head.link);
377
+ list_add_tail(&ipc_link->link, &dev->wr_processing_list);
398378 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
399379
400380 write_ipc_from_queue(dev);
....@@ -490,17 +470,13 @@
490470 {
491471 uint32_t reset_id;
492472 unsigned long flags;
493
- struct wr_msg_ctl_info *processing, *next;
494473
495474 /* Read reset ID */
496475 reset_id = ish_reg_read(dev, IPC_REG_ISH2HOST_MSG) & 0xFFFF;
497476
498477 /* Clear IPC output queue */
499478 spin_lock_irqsave(&dev->wr_processing_spinlock, flags);
500
- list_for_each_entry_safe(processing, next,
501
- &dev->wr_processing_list_head.link, link) {
502
- list_move_tail(&processing->link, &dev->wr_free_list_head.link);
503
- }
479
+ list_splice_init(&dev->wr_processing_list, &dev->wr_free_list);
504480 spin_unlock_irqrestore(&dev->wr_processing_spinlock, flags);
505481
506482 /* ISHTP notification in IPC_RESET */
....@@ -696,7 +672,7 @@
696672 *
697673 * Return: 0 for success else error code.
698674 */
699
-static int ish_disable_dma(struct ishtp_device *dev)
675
+int ish_disable_dma(struct ishtp_device *dev)
700676 {
701677 unsigned int dma_delay;
702678
....@@ -779,7 +755,7 @@
779755 csr |= PCI_D3hot;
780756 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr);
781757
782
- mdelay(pdev->d3_delay);
758
+ mdelay(pdev->d3hot_delay);
783759
784760 csr &= ~PCI_PM_CTRL_STATE_MASK;
785761 csr |= PCI_D0;
....@@ -921,12 +897,11 @@
921897 init_waitqueue_head(&dev->wait_hw_ready);
922898
923899 spin_lock_init(&dev->wr_processing_spinlock);
924
- spin_lock_init(&dev->out_ipc_spinlock);
925900
926901 /* Init IPC processing and free lists */
927
- INIT_LIST_HEAD(&dev->wr_processing_list_head.link);
928
- INIT_LIST_HEAD(&dev->wr_free_list_head.link);
929
- for (i = 0; i < IPC_TX_FIFO_SIZE; ++i) {
902
+ INIT_LIST_HEAD(&dev->wr_processing_list);
903
+ INIT_LIST_HEAD(&dev->wr_free_list);
904
+ for (i = 0; i < IPC_TX_FIFO_SIZE; i++) {
930905 struct wr_msg_ctl_info *tx_buf;
931906
932907 tx_buf = devm_kzalloc(&pdev->dev,
....@@ -942,7 +917,7 @@
942917 i);
943918 break;
944919 }
945
- list_add_tail(&tx_buf->link, &dev->wr_free_list_head.link);
920
+ list_add_tail(&tx_buf->link, &dev->wr_free_list);
946921 }
947922
948923 dev->ops = &ish_hw_ops;