Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _SPARC64_LDC_H
0003 #define _SPARC64_LDC_H
0004 
0005 #include <asm/hypervisor.h>
0006 
0007 extern int ldom_domaining_enabled;
0008 void ldom_set_var(const char *var, const char *value);
0009 void ldom_reboot(const char *boot_command);
0010 void ldom_power_off(void);
0011 
0012 /* The event handler will be evoked when link state changes
0013  * or data becomes available on the receive side.
0014  *
0015  * For non-RAW links, if the LDC_EVENT_RESET event arrives the
0016  * driver should reset all of it's internal state and reinvoke
0017  * ldc_connect() to try and bring the link up again.
0018  *
0019  * For RAW links, ldc_connect() is not used.  Instead the driver
0020  * just waits for the LDC_EVENT_UP event.
0021  */
0022 struct ldc_channel_config {
0023     void (*event)(void *arg, int event);
0024 
0025     u32         mtu;
0026     unsigned int        rx_irq;
0027     unsigned int        tx_irq;
0028     u8          mode;
0029 #define LDC_MODE_RAW        0x00
0030 #define LDC_MODE_UNRELIABLE 0x01
0031 #define LDC_MODE_RESERVED   0x02
0032 #define LDC_MODE_STREAM     0x03
0033 
0034     u8          debug;
0035 #define LDC_DEBUG_HS        0x01
0036 #define LDC_DEBUG_STATE     0x02
0037 #define LDC_DEBUG_RX        0x04
0038 #define LDC_DEBUG_TX        0x08
0039 #define LDC_DEBUG_DATA      0x10
0040 };
0041 
0042 #define LDC_EVENT_RESET     0x01
0043 #define LDC_EVENT_UP        0x02
0044 #define LDC_EVENT_DATA_READY    0x04
0045 
0046 #define LDC_STATE_INVALID   0x00
0047 #define LDC_STATE_INIT      0x01
0048 #define LDC_STATE_BOUND     0x02
0049 #define LDC_STATE_READY     0x03
0050 #define LDC_STATE_CONNECTED 0x04
0051 
0052 #define LDC_PACKET_SIZE     64
0053 
0054 struct ldc_channel;
0055 
0056 /* Allocate state for a channel.  */
0057 struct ldc_channel *ldc_alloc(unsigned long id,
0058                   const struct ldc_channel_config *cfgp,
0059                   void *event_arg,
0060                   const char *name);
0061 
0062 /* Shut down and free state for a channel.  */
0063 void ldc_free(struct ldc_channel *lp);
0064 
0065 /* Register TX and RX queues of the link with the hypervisor.  */
0066 int ldc_bind(struct ldc_channel *lp);
0067 void ldc_unbind(struct ldc_channel *lp);
0068 
0069 /* For non-RAW protocols we need to complete a handshake before
0070  * communication can proceed.  ldc_connect() does that, if the
0071  * handshake completes successfully, an LDC_EVENT_UP event will
0072  * be sent up to the driver.
0073  */
0074 int ldc_connect(struct ldc_channel *lp);
0075 int ldc_disconnect(struct ldc_channel *lp);
0076 
0077 int ldc_state(struct ldc_channel *lp);
0078 void ldc_set_state(struct ldc_channel *lp, u8 state);
0079 int ldc_mode(struct ldc_channel *lp);
0080 void __ldc_print(struct ldc_channel *lp, const char *caller);
0081 int ldc_rx_reset(struct ldc_channel *lp);
0082 
0083 #define ldc_print(chan) __ldc_print(chan, __func__)
0084 
0085 /* Read and write operations.  Only valid when the link is up.  */
0086 int ldc_write(struct ldc_channel *lp, const void *buf,
0087           unsigned int size);
0088 int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size);
0089 
0090 #define LDC_MAP_SHADOW  0x01
0091 #define LDC_MAP_DIRECT  0x02
0092 #define LDC_MAP_IO  0x04
0093 #define LDC_MAP_R   0x08
0094 #define LDC_MAP_W   0x10
0095 #define LDC_MAP_X   0x20
0096 #define LDC_MAP_RW  (LDC_MAP_R | LDC_MAP_W)
0097 #define LDC_MAP_RWX (LDC_MAP_R | LDC_MAP_W | LDC_MAP_X)
0098 #define LDC_MAP_ALL 0x03f
0099 
0100 struct ldc_trans_cookie {
0101     u64         cookie_addr;
0102     u64         cookie_size;
0103 };
0104 
0105 struct scatterlist;
0106 int ldc_map_sg(struct ldc_channel *lp,
0107            struct scatterlist *sg, int num_sg,
0108            struct ldc_trans_cookie *cookies, int ncookies,
0109            unsigned int map_perm);
0110 
0111 int ldc_map_single(struct ldc_channel *lp,
0112            void *buf, unsigned int len,
0113            struct ldc_trans_cookie *cookies, int ncookies,
0114            unsigned int map_perm);
0115 
0116 void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies,
0117            int ncookies);
0118 
0119 int ldc_copy(struct ldc_channel *lp, int copy_dir,
0120          void *buf, unsigned int len, unsigned long offset,
0121          struct ldc_trans_cookie *cookies, int ncookies);
0122 
0123 static inline int ldc_get_dring_entry(struct ldc_channel *lp,
0124                       void *buf, unsigned int len,
0125                       unsigned long offset,
0126                       struct ldc_trans_cookie *cookies,
0127                       int ncookies)
0128 {
0129     return ldc_copy(lp, LDC_COPY_IN, buf, len, offset, cookies, ncookies);
0130 }
0131 
0132 static inline int ldc_put_dring_entry(struct ldc_channel *lp,
0133                       void *buf, unsigned int len,
0134                       unsigned long offset,
0135                       struct ldc_trans_cookie *cookies,
0136                       int ncookies)
0137 {
0138     return ldc_copy(lp, LDC_COPY_OUT, buf, len, offset, cookies, ncookies);
0139 }
0140 
0141 void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len,
0142               struct ldc_trans_cookie *cookies,
0143               int *ncookies, unsigned int map_perm);
0144 
0145 void ldc_free_exp_dring(struct ldc_channel *lp, void *buf,
0146                 unsigned int len,
0147                 struct ldc_trans_cookie *cookies, int ncookies);
0148 
0149 #endif /* _SPARC64_LDC_H */