1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. 4 * Copyright (C) 2018-2020 Linaro Ltd. 5 */ 6 #ifndef _GSI_PRIVATE_H_ 7 #define _GSI_PRIVATE_H_ 8 9 /* === Only "gsi.c" and "gsi_trans.c" should include this file === */ 10 11 #include <linux/types.h> 12 13 struct gsi_trans; 14 struct gsi_ring; 15 struct gsi_channel; 16 17 #define GSI_RING_ELEMENT_SIZE 16 /* bytes; must be a power of 2 */ 18 19 /** 20 * list_last_entry_or_null - get the last element from a list 21 * @ptr: the list head to take the element from. 22 * @type: the type of the struct this is embedded in. 23 * @member: the name of the list_head within the struct. 24 * 25 * Note that if the list is empty, it returns NULL. 26 */ 27 #define list_last_entry_or_null(ptr, type, member) ({ \ 28 struct list_head *head__ = (ptr); \ 29 struct list_head *pos__ = READ_ONCE(head__->prev); \ 30 pos__ != head__ ? list_entry(pos__, type, member) : NULL; \ 31 }) 32 33 /** 34 * gsi_trans_move_complete() - Mark a GSI transaction completed 35 * @trans: Transaction to commit 36 */ 37 void gsi_trans_move_complete(struct gsi_trans *trans); 38 39 /** 40 * gsi_trans_move_polled() - Mark a transaction polled 41 * @trans: Transaction to update 42 */ 43 void gsi_trans_move_polled(struct gsi_trans *trans); 44 45 /** 46 * gsi_trans_complete() - Complete a GSI transaction 47 * @trans: Transaction to complete 48 * 49 * Marks a transaction complete (including freeing it). 50 */ 51 void gsi_trans_complete(struct gsi_trans *trans); 52 53 /** 54 * gsi_channel_trans_mapped() - Return a transaction mapped to a TRE index 55 * @channel: Channel associated with the transaction 56 * @index: Index of the TRE having a transaction 57 * 58 * Return: The GSI transaction pointer associated with the TRE index 59 */ 60 struct gsi_trans *gsi_channel_trans_mapped(struct gsi_channel *channel, 61 u32 index); 62 63 /** 64 * gsi_channel_trans_complete() - Return a channel's next completed transaction 65 * @channel: Channel whose next transaction is to be returned 66 * 67 * Return: The next completed transaction, or NULL if nothing new 68 */ 69 struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel); 70 71 /** 72 * gsi_channel_trans_cancel_pending() - Cancel pending transactions 73 * @channel: Channel whose pending transactions should be cancelled 74 * 75 * Cancel all pending transactions on a channel. These are transactions 76 * that have been committed but not yet completed. This is required when 77 * the channel gets reset. At that time all pending transactions will be 78 * marked as cancelled. 79 * 80 * NOTE: Transactions already complete at the time of this call are 81 * unaffected. 82 */ 83 void gsi_channel_trans_cancel_pending(struct gsi_channel *channel); 84 85 /** 86 * gsi_channel_trans_init() - Initialize a channel's GSI transaction info 87 * @gsi: GSI pointer 88 * @channel_id: Channel number 89 * 90 * Return: 0 if successful, or -ENOMEM on allocation failure 91 * 92 * Creates and sets up information for managing transactions on a channel 93 */ 94 int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id); 95 96 /** 97 * gsi_channel_trans_exit() - Inverse of gsi_channel_trans_init() 98 * @channel: Channel whose transaction information is to be cleaned up 99 */ 100 void gsi_channel_trans_exit(struct gsi_channel *channel); 101 102 /** 103 * gsi_channel_doorbell() - Ring a channel's doorbell 104 * @channel: Channel whose doorbell should be rung 105 * 106 * Rings a channel's doorbell to inform the GSI hardware that new 107 * transactions (TREs, really) are available for it to process. 108 */ 109 void gsi_channel_doorbell(struct gsi_channel *channel); 110 111 /** 112 * gsi_ring_virt() - Return virtual address for a ring entry 113 * @ring: Ring whose address is to be translated 114 * @index: Index (slot number) of entry 115 */ 116 void *gsi_ring_virt(struct gsi_ring *ring, u32 index); 117 118 /** 119 * gsi_trans_tx_committed() - Record bytes committed for transmit 120 * @trans: TX endpoint transaction being committed 121 * 122 * Report that a TX transaction has been committed. It updates some 123 * statistics used to manage transmit rates. 124 */ 125 void gsi_trans_tx_committed(struct gsi_trans *trans); 126 127 /** 128 * gsi_trans_tx_queued() - Report a queued TX channel transaction 129 * @trans: Transaction being passed to hardware 130 * 131 * Report to the network stack that a TX transaction is being supplied 132 * to the hardware. 133 */ 134 void gsi_trans_tx_queued(struct gsi_trans *trans); 135 136 #endif /* _GSI_PRIVATE_H_ */ 137