Commit 4c530d1979418a636bec73a2f945e8d469e47a47
1 parent
487875a832
Exists in
smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga
and in
4 other branches
MLK-21168 imx: Set timeout of virtual driver service connection to 2s
The normal ready time of M4 side is less than 1s, so we can use 2s as the timeout of connection. The current value is 10s, which seems a little long if M4 SRTM service does not run. Signed-off-by: Ye Li <ye.li@nxp.com> Acked-by: Peng Fan <peng.fan@nxp.com> (cherry picked from commit 4792d8967d3c631d055c133303bb6385b822a3ca)
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
arch/arm/mach-imx/imx_vservice.c
1 | // SPDX-License-Identifier: GPL-2.0 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* | 2 | /* |
3 | * Copyright 2019 NXP | 3 | * Copyright 2019 NXP |
4 | * | 4 | * |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <common.h> | 7 | #include <common.h> |
8 | #include <asm/io.h> | 8 | #include <asm/io.h> |
9 | #include <dm.h> | 9 | #include <dm.h> |
10 | #include <dm/lists.h> | 10 | #include <dm/lists.h> |
11 | #include <dm/root.h> | 11 | #include <dm/root.h> |
12 | #include <dm/device-internal.h> | 12 | #include <dm/device-internal.h> |
13 | #include <dm/uclass-internal.h> | 13 | #include <dm/uclass-internal.h> |
14 | #include <misc.h> | 14 | #include <misc.h> |
15 | #include <asm/mach-imx/imx_vservice.h> | 15 | #include <asm/mach-imx/imx_vservice.h> |
16 | #include <imx_m4_mu.h> | 16 | #include <imx_m4_mu.h> |
17 | 17 | ||
18 | static LIST_HEAD(vservice_channels); | 18 | static LIST_HEAD(vservice_channels); |
19 | 19 | ||
20 | void * __weak board_imx_vservice_get_buffer(struct imx_vservice_channel *node, u32 size) | 20 | void * __weak board_imx_vservice_get_buffer(struct imx_vservice_channel *node, u32 size) |
21 | { | 21 | { |
22 | if (size <= CONFIG_IMX_VSERVICE_SHARED_BUFFER_SIZE) | 22 | if (size <= CONFIG_IMX_VSERVICE_SHARED_BUFFER_SIZE) |
23 | return (void * )CONFIG_IMX_VSERVICE_SHARED_BUFFER; | 23 | return (void * )CONFIG_IMX_VSERVICE_SHARED_BUFFER; |
24 | 24 | ||
25 | return NULL; | 25 | return NULL; |
26 | } | 26 | } |
27 | 27 | ||
28 | void * imx_vservice_get_buffer(struct imx_vservice_channel *node, u32 size) | 28 | void * imx_vservice_get_buffer(struct imx_vservice_channel *node, u32 size) |
29 | { | 29 | { |
30 | return board_imx_vservice_get_buffer(node, size); | 30 | return board_imx_vservice_get_buffer(node, size); |
31 | } | 31 | } |
32 | 32 | ||
33 | int imx_vservice_blocking_request(struct imx_vservice_channel *node, u8 *buf, u32* size) | 33 | int imx_vservice_blocking_request(struct imx_vservice_channel *node, u8 *buf, u32* size) |
34 | { | 34 | { |
35 | int ret = 0; | 35 | int ret = 0; |
36 | union imx_m4_msg msg; | 36 | union imx_m4_msg msg; |
37 | 37 | ||
38 | msg.format.seq = node->msg_seq; | 38 | msg.format.seq = node->msg_seq; |
39 | msg.format.type = MU_MSG_REQ; | 39 | msg.format.type = MU_MSG_REQ; |
40 | msg.format.buffer = (u32)(ulong)buf; | 40 | msg.format.buffer = (u32)(ulong)buf; |
41 | msg.format.size = *size; | 41 | msg.format.size = *size; |
42 | 42 | ||
43 | ret = misc_call(node->mu_dev, 1000000, &msg, 4, &msg, 4); | 43 | ret = misc_call(node->mu_dev, 1000000, &msg, 4, &msg, 4); |
44 | if (ret) { | 44 | if (ret) { |
45 | printf("%s: Send request MU message failed, ret %d\n", __func__, ret); | 45 | printf("%s: Send request MU message failed, ret %d\n", __func__, ret); |
46 | goto MU_ERR; | 46 | goto MU_ERR; |
47 | } | 47 | } |
48 | 48 | ||
49 | if (msg.format.type != MU_MSG_RESP|| msg.format.seq != node->msg_seq) { | 49 | if (msg.format.type != MU_MSG_RESP|| msg.format.seq != node->msg_seq) { |
50 | printf("%s: wrong msg response: type %d, seq %d, expect seq %d\n", | 50 | printf("%s: wrong msg response: type %d, seq %d, expect seq %d\n", |
51 | __func__, msg.format.type, msg.format.seq, node->msg_seq); | 51 | __func__, msg.format.type, msg.format.seq, node->msg_seq); |
52 | ret = -EIO; | 52 | ret = -EIO; |
53 | goto MU_ERR; | 53 | goto MU_ERR; |
54 | } | 54 | } |
55 | 55 | ||
56 | *size = msg.format.size; | 56 | *size = msg.format.size; |
57 | 57 | ||
58 | MU_ERR: | 58 | MU_ERR: |
59 | node->msg_seq++; | 59 | node->msg_seq++; |
60 | 60 | ||
61 | return ret; | 61 | return ret; |
62 | } | 62 | } |
63 | 63 | ||
64 | static int imx_vservice_connect(struct imx_vservice_channel *node) | 64 | static int imx_vservice_connect(struct imx_vservice_channel *node) |
65 | { | 65 | { |
66 | int ret = 0; | 66 | int ret = 0; |
67 | union imx_m4_msg msg; | 67 | union imx_m4_msg msg; |
68 | 68 | ||
69 | unsigned long timeout = timer_get_us() + 10000000; /* 10s timeout */ | 69 | unsigned long timeout = timer_get_us() + 2000000; /* 2s timeout */ |
70 | 70 | ||
71 | for (;;) { | 71 | for (;;) { |
72 | msg.format.seq = 0; | 72 | msg.format.seq = 0; |
73 | msg.format.type = MU_MSG_READY_A; | 73 | msg.format.type = MU_MSG_READY_A; |
74 | msg.format.buffer = 0; | 74 | msg.format.buffer = 0; |
75 | msg.format.size = 0; | 75 | msg.format.size = 0; |
76 | 76 | ||
77 | ret = misc_call(node->mu_dev, 100000, &msg, 4, &msg, 4); | 77 | ret = misc_call(node->mu_dev, 100000, &msg, 4, &msg, 4); |
78 | if (!ret && msg.format.type == MU_MSG_READY_B) | 78 | if (!ret && msg.format.type == MU_MSG_READY_B) |
79 | return 0; | 79 | return 0; |
80 | 80 | ||
81 | if (time_after(timer_get_us(), timeout)) { | 81 | if (time_after(timer_get_us(), timeout)) { |
82 | printf("%s: Timeout to connect peer, %d\n", __func__, ret); | 82 | printf("%s: Timeout to connect peer, %d\n", __func__, ret); |
83 | return -ETIMEDOUT; | 83 | return -ETIMEDOUT; |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | return -EIO; | 87 | return -EIO; |
88 | } | 88 | } |
89 | 89 | ||
90 | struct udevice * __weak board_imx_vservice_find_mu(struct udevice *virt_dev) | 90 | struct udevice * __weak board_imx_vservice_find_mu(struct udevice *virt_dev) |
91 | { | 91 | { |
92 | int ret; | 92 | int ret; |
93 | struct ofnode_phandle_args args; | 93 | struct ofnode_phandle_args args; |
94 | struct udevice *mu_dev; | 94 | struct udevice *mu_dev; |
95 | 95 | ||
96 | /* Default get mu from "fsl,vservice-mu" property*/ | 96 | /* Default get mu from "fsl,vservice-mu" property*/ |
97 | ret = dev_read_phandle_with_args(virt_dev, "fsl,vservice-mu", | 97 | ret = dev_read_phandle_with_args(virt_dev, "fsl,vservice-mu", |
98 | NULL, 0, 0, &args); | 98 | NULL, 0, 0, &args); |
99 | if (ret) { | 99 | if (ret) { |
100 | printf("Can't find \"fsl,vservice-mu\" property\n"); | 100 | printf("Can't find \"fsl,vservice-mu\" property\n"); |
101 | return NULL; | 101 | return NULL; |
102 | } | 102 | } |
103 | 103 | ||
104 | ret = uclass_find_device_by_ofnode(UCLASS_MISC, args.node, &mu_dev); | 104 | ret = uclass_find_device_by_ofnode(UCLASS_MISC, args.node, &mu_dev); |
105 | if (ret) { | 105 | if (ret) { |
106 | printf("Can't find MU device, err %d\n", ret); | 106 | printf("Can't find MU device, err %d\n", ret); |
107 | return NULL; | 107 | return NULL; |
108 | } | 108 | } |
109 | 109 | ||
110 | return mu_dev; | 110 | return mu_dev; |
111 | } | 111 | } |
112 | 112 | ||
113 | static struct udevice * imx_vservice_find_mu(struct udevice *virt_dev) | 113 | static struct udevice * imx_vservice_find_mu(struct udevice *virt_dev) |
114 | { | 114 | { |
115 | return board_imx_vservice_find_mu(virt_dev); | 115 | return board_imx_vservice_find_mu(virt_dev); |
116 | } | 116 | } |
117 | 117 | ||
118 | struct imx_vservice_channel * imx_vservice_setup(struct udevice *virt_dev) | 118 | struct imx_vservice_channel * imx_vservice_setup(struct udevice *virt_dev) |
119 | { | 119 | { |
120 | int ret; | 120 | int ret; |
121 | struct udevice *mu_dev; | 121 | struct udevice *mu_dev; |
122 | struct imx_vservice_channel *channel; | 122 | struct imx_vservice_channel *channel; |
123 | 123 | ||
124 | mu_dev = imx_vservice_find_mu(virt_dev); | 124 | mu_dev = imx_vservice_find_mu(virt_dev); |
125 | if (mu_dev == NULL) { | 125 | if (mu_dev == NULL) { |
126 | printf("No MU device for virtual service %s connection\n", virt_dev->name); | 126 | printf("No MU device for virtual service %s connection\n", virt_dev->name); |
127 | return NULL; | 127 | return NULL; |
128 | } | 128 | } |
129 | 129 | ||
130 | ret = device_probe(mu_dev); | 130 | ret = device_probe(mu_dev); |
131 | if (ret) { | 131 | if (ret) { |
132 | printf("Probe MU device failed\n"); | 132 | printf("Probe MU device failed\n"); |
133 | return NULL; | 133 | return NULL; |
134 | } | 134 | } |
135 | 135 | ||
136 | list_for_each_entry(channel, &vservice_channels, channel_head) { | 136 | list_for_each_entry(channel, &vservice_channels, channel_head) { |
137 | if (channel->mu_dev == mu_dev) | 137 | if (channel->mu_dev == mu_dev) |
138 | return channel; | 138 | return channel; |
139 | } | 139 | } |
140 | 140 | ||
141 | channel = malloc(sizeof(struct imx_vservice_channel)); | 141 | channel = malloc(sizeof(struct imx_vservice_channel)); |
142 | if (!channel) { | 142 | if (!channel) { |
143 | printf("Malloc vservice channel is failed\n"); | 143 | printf("Malloc vservice channel is failed\n"); |
144 | return NULL; | 144 | return NULL; |
145 | } | 145 | } |
146 | 146 | ||
147 | channel->msg_seq = 0; | 147 | channel->msg_seq = 0; |
148 | channel->mu_dev = mu_dev; | 148 | channel->mu_dev = mu_dev; |
149 | INIT_LIST_HEAD(&channel->channel_head); | 149 | INIT_LIST_HEAD(&channel->channel_head); |
150 | 150 | ||
151 | ret = imx_vservice_connect(channel); | 151 | ret = imx_vservice_connect(channel); |
152 | if (ret) { | 152 | if (ret) { |
153 | printf("VService: Connection is failed, ret %d\n", ret); | 153 | printf("VService: Connection is failed, ret %d\n", ret); |
154 | free(channel); | 154 | free(channel); |
155 | return NULL; | 155 | return NULL; |
156 | } | 156 | } |
157 | 157 | ||
158 | list_add_tail(&channel->channel_head, &vservice_channels); | 158 | list_add_tail(&channel->channel_head, &vservice_channels); |
159 | 159 | ||
160 | printf("VService: Connection is ok on MU %s\n", mu_dev->name); | 160 | printf("VService: Connection is ok on MU %s\n", mu_dev->name); |
161 | 161 | ||
162 | return channel; | 162 | return channel; |
163 | } | 163 | } |
164 | 164 |