.. | .. |
---|
5 | 5 | #include "hclgevf_main.h" |
---|
6 | 6 | #include "hnae3.h" |
---|
7 | 7 | |
---|
| 8 | +#define CREATE_TRACE_POINTS |
---|
| 9 | +#include "hclgevf_trace.h" |
---|
| 10 | + |
---|
| 11 | +static int hclgevf_resp_to_errno(u16 resp_code) |
---|
| 12 | +{ |
---|
| 13 | + return resp_code ? -resp_code : 0; |
---|
| 14 | +} |
---|
| 15 | + |
---|
8 | 16 | static void hclgevf_reset_mbx_resp_status(struct hclgevf_dev *hdev) |
---|
9 | 17 | { |
---|
10 | 18 | /* this function should be called with mbx_resp.mbx_mutex held |
---|
.. | .. |
---|
26 | 34 | u8 *resp_data, u16 resp_len) |
---|
27 | 35 | { |
---|
28 | 36 | #define HCLGEVF_MAX_TRY_TIMES 500 |
---|
29 | | -#define HCLGEVF_SLEEP_USCOEND 1000 |
---|
| 37 | +#define HCLGEVF_SLEEP_USECOND 1000 |
---|
30 | 38 | struct hclgevf_mbx_resp_status *mbx_resp; |
---|
31 | 39 | u16 r_code0, r_code1; |
---|
32 | 40 | int i = 0; |
---|
33 | 41 | |
---|
34 | 42 | if (resp_len > HCLGE_MBX_MAX_RESP_DATA_SIZE) { |
---|
35 | 43 | dev_err(&hdev->pdev->dev, |
---|
36 | | - "VF mbx response len(=%d) exceeds maximum(=%d)\n", |
---|
| 44 | + "VF mbx response len(=%u) exceeds maximum(=%u)\n", |
---|
37 | 45 | resp_len, |
---|
38 | 46 | HCLGE_MBX_MAX_RESP_DATA_SIZE); |
---|
39 | 47 | return -EINVAL; |
---|
40 | 48 | } |
---|
41 | 49 | |
---|
42 | 50 | while ((!hdev->mbx_resp.received_resp) && (i < HCLGEVF_MAX_TRY_TIMES)) { |
---|
43 | | - udelay(HCLGEVF_SLEEP_USCOEND); |
---|
| 51 | + if (test_bit(HCLGEVF_STATE_CMD_DISABLE, &hdev->state)) |
---|
| 52 | + return -EIO; |
---|
| 53 | + |
---|
| 54 | + usleep_range(HCLGEVF_SLEEP_USECOND, HCLGEVF_SLEEP_USECOND * 2); |
---|
44 | 55 | i++; |
---|
45 | 56 | } |
---|
46 | 57 | |
---|
47 | 58 | if (i >= HCLGEVF_MAX_TRY_TIMES) { |
---|
48 | 59 | dev_err(&hdev->pdev->dev, |
---|
49 | | - "VF could not get mbx resp(=%d) from PF in %d tries\n", |
---|
50 | | - hdev->mbx_resp.received_resp, i); |
---|
| 60 | + "VF could not get mbx(%u,%u) resp(=%d) from PF in %d tries\n", |
---|
| 61 | + code0, code1, hdev->mbx_resp.received_resp, i); |
---|
51 | 62 | return -EIO; |
---|
52 | 63 | } |
---|
53 | 64 | |
---|
.. | .. |
---|
65 | 76 | |
---|
66 | 77 | if (!(r_code0 == code0 && r_code1 == code1 && !mbx_resp->resp_status)) { |
---|
67 | 78 | dev_err(&hdev->pdev->dev, |
---|
68 | | - "VF could not match resp code(code0=%d,code1=%d), %d", |
---|
| 79 | + "VF could not match resp code(code0=%u,code1=%u), %d\n", |
---|
69 | 80 | code0, code1, mbx_resp->resp_status); |
---|
| 81 | + dev_err(&hdev->pdev->dev, |
---|
| 82 | + "VF could not match resp r_code(r_code0=%u,r_code1=%u)\n", |
---|
| 83 | + r_code0, r_code1); |
---|
70 | 84 | return -EIO; |
---|
71 | 85 | } |
---|
72 | 86 | |
---|
73 | 87 | return 0; |
---|
74 | 88 | } |
---|
75 | 89 | |
---|
76 | | -int hclgevf_send_mbx_msg(struct hclgevf_dev *hdev, u16 code, u16 subcode, |
---|
77 | | - const u8 *msg_data, u8 msg_len, bool need_resp, |
---|
| 90 | +int hclgevf_send_mbx_msg(struct hclgevf_dev *hdev, |
---|
| 91 | + struct hclge_vf_to_pf_msg *send_msg, bool need_resp, |
---|
78 | 92 | u8 *resp_data, u16 resp_len) |
---|
79 | 93 | { |
---|
80 | 94 | struct hclge_mbx_vf_to_pf_cmd *req; |
---|
.. | .. |
---|
83 | 97 | |
---|
84 | 98 | req = (struct hclge_mbx_vf_to_pf_cmd *)desc.data; |
---|
85 | 99 | |
---|
86 | | - /* first two bytes are reserved for code & subcode */ |
---|
87 | | - if (msg_len > (HCLGE_MBX_MAX_MSG_SIZE - 2)) { |
---|
| 100 | + if (!send_msg) { |
---|
88 | 101 | dev_err(&hdev->pdev->dev, |
---|
89 | | - "VF send mbx msg fail, msg len %d exceeds max len %d\n", |
---|
90 | | - msg_len, HCLGE_MBX_MAX_MSG_SIZE); |
---|
| 102 | + "failed to send mbx, msg is NULL\n"); |
---|
91 | 103 | return -EINVAL; |
---|
92 | 104 | } |
---|
93 | 105 | |
---|
94 | 106 | hclgevf_cmd_setup_basic_desc(&desc, HCLGEVF_OPC_MBX_VF_TO_PF, false); |
---|
95 | | - req->msg[0] = code; |
---|
96 | | - req->msg[1] = subcode; |
---|
97 | | - memcpy(&req->msg[2], msg_data, msg_len); |
---|
| 107 | + if (need_resp) |
---|
| 108 | + hnae3_set_bit(req->mbx_need_resp, HCLGE_MBX_NEED_RESP_B, 1); |
---|
| 109 | + |
---|
| 110 | + memcpy(&req->msg, send_msg, sizeof(struct hclge_vf_to_pf_msg)); |
---|
| 111 | + |
---|
| 112 | + if (test_bit(HCLGEVF_STATE_NIC_REGISTERED, &hdev->state)) |
---|
| 113 | + trace_hclge_vf_mbx_send(hdev, req); |
---|
98 | 114 | |
---|
99 | 115 | /* synchronous send */ |
---|
100 | 116 | if (need_resp) { |
---|
.. | .. |
---|
109 | 125 | return status; |
---|
110 | 126 | } |
---|
111 | 127 | |
---|
112 | | - status = hclgevf_get_mbx_resp(hdev, code, subcode, resp_data, |
---|
| 128 | + status = hclgevf_get_mbx_resp(hdev, send_msg->code, |
---|
| 129 | + send_msg->subcode, resp_data, |
---|
113 | 130 | resp_len); |
---|
114 | 131 | mutex_unlock(&hdev->mbx_resp.mbx_mutex); |
---|
115 | 132 | } else { |
---|
.. | .. |
---|
148 | 165 | crq = &hdev->hw.cmq.crq; |
---|
149 | 166 | |
---|
150 | 167 | while (!hclgevf_cmd_crq_empty(&hdev->hw)) { |
---|
| 168 | + if (test_bit(HCLGEVF_STATE_CMD_DISABLE, &hdev->state)) { |
---|
| 169 | + dev_info(&hdev->pdev->dev, "vf crq need init\n"); |
---|
| 170 | + return; |
---|
| 171 | + } |
---|
| 172 | + |
---|
151 | 173 | desc = &crq->desc[crq->next_to_use]; |
---|
152 | 174 | req = (struct hclge_mbx_pf_to_vf_cmd *)desc->data; |
---|
153 | 175 | |
---|
154 | 176 | flag = le16_to_cpu(crq->desc[crq->next_to_use].flag); |
---|
155 | 177 | if (unlikely(!hnae3_get_bit(flag, HCLGEVF_CMDQ_RX_OUTVLD_B))) { |
---|
156 | 178 | dev_warn(&hdev->pdev->dev, |
---|
157 | | - "dropped invalid mailbox message, code = %d\n", |
---|
158 | | - req->msg[0]); |
---|
| 179 | + "dropped invalid mailbox message, code = %u\n", |
---|
| 180 | + req->msg.code); |
---|
159 | 181 | |
---|
160 | 182 | /* dropping/not processing this invalid message */ |
---|
161 | 183 | crq->desc[crq->next_to_use].flag = 0; |
---|
.. | .. |
---|
163 | 185 | continue; |
---|
164 | 186 | } |
---|
165 | 187 | |
---|
| 188 | + trace_hclge_vf_mbx_get(hdev, req); |
---|
| 189 | + |
---|
166 | 190 | /* synchronous messages are time critical and need preferential |
---|
167 | 191 | * treatment. Therefore, we need to acknowledge all the sync |
---|
168 | 192 | * responses as quickly as possible so that waiting tasks do not |
---|
169 | 193 | * timeout and simultaneously queue the async messages for later |
---|
170 | 194 | * prcessing in context of mailbox task i.e. the slow path. |
---|
171 | 195 | */ |
---|
172 | | - switch (req->msg[0]) { |
---|
| 196 | + switch (req->msg.code) { |
---|
173 | 197 | case HCLGE_MBX_PF_VF_RESP: |
---|
174 | 198 | if (resp->received_resp) |
---|
175 | 199 | dev_warn(&hdev->pdev->dev, |
---|
176 | | - "VF mbx resp flag not clear(%d)\n", |
---|
177 | | - req->msg[1]); |
---|
| 200 | + "VF mbx resp flag not clear(%u)\n", |
---|
| 201 | + req->msg.vf_mbx_msg_code); |
---|
178 | 202 | resp->received_resp = true; |
---|
179 | 203 | |
---|
180 | | - resp->origin_mbx_msg = (req->msg[1] << 16); |
---|
181 | | - resp->origin_mbx_msg |= req->msg[2]; |
---|
182 | | - resp->resp_status = req->msg[3]; |
---|
| 204 | + resp->origin_mbx_msg = |
---|
| 205 | + (req->msg.vf_mbx_msg_code << 16); |
---|
| 206 | + resp->origin_mbx_msg |= req->msg.vf_mbx_msg_subcode; |
---|
| 207 | + resp->resp_status = |
---|
| 208 | + hclgevf_resp_to_errno(req->msg.resp_status); |
---|
183 | 209 | |
---|
184 | | - temp = (u8 *)&req->msg[4]; |
---|
| 210 | + temp = (u8 *)req->msg.resp_data; |
---|
185 | 211 | for (i = 0; i < HCLGE_MBX_MAX_RESP_DATA_SIZE; i++) { |
---|
186 | 212 | resp->additional_info[i] = *temp; |
---|
187 | 213 | temp++; |
---|
.. | .. |
---|
189 | 215 | break; |
---|
190 | 216 | case HCLGE_MBX_LINK_STAT_CHANGE: |
---|
191 | 217 | case HCLGE_MBX_ASSERTING_RESET: |
---|
| 218 | + case HCLGE_MBX_LINK_STAT_MODE: |
---|
| 219 | + case HCLGE_MBX_PUSH_VLAN_INFO: |
---|
| 220 | + case HCLGE_MBX_PUSH_PROMISC_INFO: |
---|
192 | 221 | /* set this mbx event as pending. This is required as we |
---|
193 | 222 | * might loose interrupt event when mbx task is busy |
---|
194 | 223 | * handling. This shall be cleared when mbx task just |
---|
.. | .. |
---|
199 | 228 | /* we will drop the async msg if we find ARQ as full |
---|
200 | 229 | * and continue with next message |
---|
201 | 230 | */ |
---|
202 | | - if (hdev->arq.count >= HCLGE_MBX_MAX_ARQ_MSG_NUM) { |
---|
| 231 | + if (atomic_read(&hdev->arq.count) >= |
---|
| 232 | + HCLGE_MBX_MAX_ARQ_MSG_NUM) { |
---|
203 | 233 | dev_warn(&hdev->pdev->dev, |
---|
204 | | - "Async Q full, dropping msg(%d)\n", |
---|
205 | | - req->msg[1]); |
---|
| 234 | + "Async Q full, dropping msg(%u)\n", |
---|
| 235 | + req->msg.code); |
---|
206 | 236 | break; |
---|
207 | 237 | } |
---|
208 | 238 | |
---|
209 | 239 | /* tail the async message in arq */ |
---|
210 | 240 | msg_q = hdev->arq.msg_q[hdev->arq.tail]; |
---|
211 | | - memcpy(&msg_q[0], req->msg, |
---|
| 241 | + memcpy(&msg_q[0], &req->msg, |
---|
212 | 242 | HCLGE_MBX_MAX_ARQ_MSG_SIZE * sizeof(u16)); |
---|
213 | 243 | hclge_mbx_tail_ptr_move_arq(hdev->arq); |
---|
214 | | - hdev->arq.count++; |
---|
| 244 | + atomic_inc(&hdev->arq.count); |
---|
215 | 245 | |
---|
216 | 246 | hclgevf_mbx_task_schedule(hdev); |
---|
217 | 247 | |
---|
218 | 248 | break; |
---|
219 | 249 | default: |
---|
220 | 250 | dev_err(&hdev->pdev->dev, |
---|
221 | | - "VF received unsupported(%d) mbx msg from PF\n", |
---|
222 | | - req->msg[0]); |
---|
| 251 | + "VF received unsupported(%u) mbx msg from PF\n", |
---|
| 252 | + req->msg.code); |
---|
223 | 253 | break; |
---|
224 | 254 | } |
---|
225 | 255 | crq->desc[crq->next_to_use].flag = 0; |
---|
.. | .. |
---|
231 | 261 | crq->next_to_use); |
---|
232 | 262 | } |
---|
233 | 263 | |
---|
| 264 | +static void hclgevf_parse_promisc_info(struct hclgevf_dev *hdev, |
---|
| 265 | + u16 promisc_info) |
---|
| 266 | +{ |
---|
| 267 | + if (!promisc_info) |
---|
| 268 | + dev_info(&hdev->pdev->dev, |
---|
| 269 | + "Promisc mode is closed by host for being untrusted.\n"); |
---|
| 270 | +} |
---|
| 271 | + |
---|
234 | 272 | void hclgevf_mbx_async_handler(struct hclgevf_dev *hdev) |
---|
235 | 273 | { |
---|
236 | | - u16 link_status; |
---|
237 | | - u16 *msg_q; |
---|
| 274 | + enum hnae3_reset_type reset_type; |
---|
| 275 | + u16 link_status, state; |
---|
| 276 | + u16 *msg_q, *vlan_info; |
---|
238 | 277 | u8 duplex; |
---|
239 | 278 | u32 speed; |
---|
240 | 279 | u32 tail; |
---|
| 280 | + u8 idx; |
---|
241 | 281 | |
---|
242 | 282 | /* we can safely clear it now as we are at start of the async message |
---|
243 | 283 | * processing |
---|
.. | .. |
---|
248 | 288 | |
---|
249 | 289 | /* process all the async queue messages */ |
---|
250 | 290 | while (tail != hdev->arq.head) { |
---|
| 291 | + if (test_bit(HCLGEVF_STATE_CMD_DISABLE, &hdev->state)) { |
---|
| 292 | + dev_info(&hdev->pdev->dev, |
---|
| 293 | + "vf crq need init in async\n"); |
---|
| 294 | + return; |
---|
| 295 | + } |
---|
| 296 | + |
---|
251 | 297 | msg_q = hdev->arq.msg_q[hdev->arq.head]; |
---|
252 | 298 | |
---|
253 | 299 | switch (msg_q[0]) { |
---|
254 | 300 | case HCLGE_MBX_LINK_STAT_CHANGE: |
---|
255 | | - link_status = le16_to_cpu(msg_q[1]); |
---|
| 301 | + link_status = msg_q[1]; |
---|
256 | 302 | memcpy(&speed, &msg_q[2], sizeof(speed)); |
---|
257 | | - duplex = (u8)le16_to_cpu(msg_q[4]); |
---|
| 303 | + duplex = (u8)msg_q[4]; |
---|
258 | 304 | |
---|
259 | 305 | /* update upper layer with new link link status */ |
---|
260 | 306 | hclgevf_update_link_status(hdev, link_status); |
---|
261 | 307 | hclgevf_update_speed_duplex(hdev, speed, duplex); |
---|
262 | 308 | |
---|
| 309 | + break; |
---|
| 310 | + case HCLGE_MBX_LINK_STAT_MODE: |
---|
| 311 | + idx = (u8)msg_q[1]; |
---|
| 312 | + if (idx) |
---|
| 313 | + memcpy(&hdev->hw.mac.supported, &msg_q[2], |
---|
| 314 | + sizeof(unsigned long)); |
---|
| 315 | + else |
---|
| 316 | + memcpy(&hdev->hw.mac.advertising, &msg_q[2], |
---|
| 317 | + sizeof(unsigned long)); |
---|
263 | 318 | break; |
---|
264 | 319 | case HCLGE_MBX_ASSERTING_RESET: |
---|
265 | 320 | /* PF has asserted reset hence VF should go in pending |
---|
.. | .. |
---|
267 | 322 | * has been completely reset. After this stack should |
---|
268 | 323 | * eventually be re-initialized. |
---|
269 | 324 | */ |
---|
270 | | - hdev->nic.reset_level = HNAE3_VF_RESET; |
---|
| 325 | + reset_type = (enum hnae3_reset_type)msg_q[1]; |
---|
| 326 | + set_bit(reset_type, &hdev->reset_pending); |
---|
271 | 327 | set_bit(HCLGEVF_RESET_PENDING, &hdev->reset_state); |
---|
272 | 328 | hclgevf_reset_task_schedule(hdev); |
---|
273 | 329 | |
---|
274 | 330 | break; |
---|
| 331 | + case HCLGE_MBX_PUSH_VLAN_INFO: |
---|
| 332 | + state = msg_q[1]; |
---|
| 333 | + vlan_info = &msg_q[1]; |
---|
| 334 | + hclgevf_update_port_base_vlan_info(hdev, state, |
---|
| 335 | + (u8 *)vlan_info, 8); |
---|
| 336 | + break; |
---|
| 337 | + case HCLGE_MBX_PUSH_PROMISC_INFO: |
---|
| 338 | + hclgevf_parse_promisc_info(hdev, msg_q[1]); |
---|
| 339 | + break; |
---|
275 | 340 | default: |
---|
276 | 341 | dev_err(&hdev->pdev->dev, |
---|
277 | | - "fetched unsupported(%d) message from arq\n", |
---|
| 342 | + "fetched unsupported(%u) message from arq\n", |
---|
278 | 343 | msg_q[0]); |
---|
279 | 344 | break; |
---|
280 | 345 | } |
---|
281 | 346 | |
---|
282 | 347 | hclge_mbx_head_ptr_move_arq(hdev->arq); |
---|
283 | | - hdev->arq.count--; |
---|
| 348 | + atomic_dec(&hdev->arq.count); |
---|
284 | 349 | msg_q = hdev->arq.msg_q[hdev->arq.head]; |
---|
285 | 350 | } |
---|
286 | 351 | } |
---|