Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2023 Intel Corporation
3 : : */
4 : :
5 : : #include "ice_ddp.h"
6 : : #include "ice_type.h"
7 : : #include "ice_common.h"
8 : : #include "ice_sched.h"
9 : :
10 : : /**
11 : : * ice_aq_download_pkg
12 : : * @hw: pointer to the hardware structure
13 : : * @pkg_buf: the package buffer to transfer
14 : : * @buf_size: the size of the package buffer
15 : : * @last_buf: last buffer indicator
16 : : * @error_offset: returns error offset
17 : : * @error_info: returns error information
18 : : * @cd: pointer to command details structure or NULL
19 : : *
20 : : * Download Package (0x0C40)
21 : : */
22 : : static enum ice_status
23 : 0 : ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
24 : : u16 buf_size, bool last_buf, u32 *error_offset,
25 : : u32 *error_info, struct ice_sq_cd *cd)
26 : : {
27 : : struct ice_aqc_download_pkg *cmd;
28 : : struct ice_aq_desc desc;
29 : : enum ice_status status;
30 : :
31 [ # # ]: 0 : if (error_offset)
32 : 0 : *error_offset = 0;
33 [ # # ]: 0 : if (error_info)
34 : 0 : *error_info = 0;
35 : :
36 : : cmd = &desc.params.download_pkg;
37 : 0 : ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
38 : 0 : desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
39 : :
40 [ # # ]: 0 : if (last_buf)
41 : 0 : cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
42 : :
43 : 0 : status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
44 [ # # ]: 0 : if (status == ICE_ERR_AQ_ERROR) {
45 : : /* Read error from buffer only when the FW returned an error */
46 : : struct ice_aqc_download_pkg_resp *resp;
47 : :
48 : : resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
49 [ # # ]: 0 : if (error_offset)
50 : 0 : *error_offset = LE32_TO_CPU(resp->error_offset);
51 [ # # ]: 0 : if (error_info)
52 : 0 : *error_info = LE32_TO_CPU(resp->error_info);
53 : : }
54 : :
55 : 0 : return status;
56 : : }
57 : :
58 : : /**
59 : : * ice_aq_upload_section
60 : : * @hw: pointer to the hardware structure
61 : : * @pkg_buf: the package buffer which will receive the section
62 : : * @buf_size: the size of the package buffer
63 : : * @cd: pointer to command details structure or NULL
64 : : *
65 : : * Upload Section (0x0C41)
66 : : */
67 : : enum ice_status
68 : 0 : ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
69 : : u16 buf_size, struct ice_sq_cd *cd)
70 : : {
71 : : struct ice_aq_desc desc;
72 : :
73 : 0 : ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_upload_section);
74 : 0 : desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
75 : :
76 : 0 : return ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
77 : : }
78 : :
79 : : /**
80 : : * ice_aq_update_pkg
81 : : * @hw: pointer to the hardware structure
82 : : * @pkg_buf: the package cmd buffer
83 : : * @buf_size: the size of the package cmd buffer
84 : : * @last_buf: last buffer indicator
85 : : * @error_offset: returns error offset
86 : : * @error_info: returns error information
87 : : * @cd: pointer to command details structure or NULL
88 : : *
89 : : * Update Package (0x0C42)
90 : : */
91 : : static enum ice_status
92 : 0 : ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
93 : : bool last_buf, u32 *error_offset, u32 *error_info,
94 : : struct ice_sq_cd *cd)
95 : : {
96 : : struct ice_aqc_download_pkg *cmd;
97 : : struct ice_aq_desc desc;
98 : : enum ice_status status;
99 : :
100 [ # # ]: 0 : if (error_offset)
101 : 0 : *error_offset = 0;
102 [ # # ]: 0 : if (error_info)
103 : 0 : *error_info = 0;
104 : :
105 : : cmd = &desc.params.download_pkg;
106 : 0 : ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
107 : 0 : desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
108 : :
109 [ # # ]: 0 : if (last_buf)
110 : 0 : cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
111 : :
112 : 0 : status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
113 [ # # ]: 0 : if (status == ICE_ERR_AQ_ERROR) {
114 : : /* Read error from buffer only when the FW returned an error */
115 : : struct ice_aqc_download_pkg_resp *resp;
116 : :
117 : : resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
118 [ # # ]: 0 : if (error_offset)
119 : 0 : *error_offset = LE32_TO_CPU(resp->error_offset);
120 [ # # ]: 0 : if (error_info)
121 : 0 : *error_info = LE32_TO_CPU(resp->error_info);
122 : : }
123 : :
124 : 0 : return status;
125 : : }
126 : :
127 : : /**
128 : : * ice_find_seg_in_pkg
129 : : * @hw: pointer to the hardware structure
130 : : * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
131 : : * @pkg_hdr: pointer to the package header to be searched
132 : : *
133 : : * This function searches a package file for a particular segment type. On
134 : : * success it returns a pointer to the segment header, otherwise it will
135 : : * return NULL.
136 : : */
137 : : struct ice_generic_seg_hdr *
138 : 0 : ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
139 : : struct ice_pkg_hdr *pkg_hdr)
140 : : {
141 : : u32 i;
142 : :
143 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n",
144 : : pkg_hdr->pkg_format_ver.major, pkg_hdr->pkg_format_ver.minor,
145 : : pkg_hdr->pkg_format_ver.update,
146 : : pkg_hdr->pkg_format_ver.draft);
147 : :
148 : : /* Search all package segments for the requested segment type */
149 [ # # ]: 0 : for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
150 : : struct ice_generic_seg_hdr *seg;
151 : :
152 : 0 : seg = (struct ice_generic_seg_hdr *)
153 : 0 : ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
154 : :
155 [ # # ]: 0 : if (LE32_TO_CPU(seg->seg_type) == seg_type)
156 : 0 : return seg;
157 : : }
158 : :
159 : : return NULL;
160 : : }
161 : :
162 : : /**
163 : : * ice_get_pkg_seg_by_idx
164 : : * @pkg_hdr: pointer to the package header to be searched
165 : : * @idx: index of segment
166 : : */
167 : : static struct ice_generic_seg_hdr *
168 : : ice_get_pkg_seg_by_idx(struct ice_pkg_hdr *pkg_hdr, u32 idx)
169 : : {
170 : : struct ice_generic_seg_hdr *seg = NULL;
171 : :
172 : 0 : if (idx < LE32_TO_CPU(pkg_hdr->seg_count))
173 : 0 : seg = (struct ice_generic_seg_hdr *)
174 : : ((u8 *)pkg_hdr +
175 : 0 : LE32_TO_CPU(pkg_hdr->seg_offset[idx]));
176 : :
177 : : return seg;
178 : : }
179 : :
180 : : /**
181 : : * ice_is_signing_seg_at_idx - determine if segment is a signing segment
182 : : * @pkg_hdr: pointer to package header
183 : : * @idx: segment index
184 : : */
185 : : static bool ice_is_signing_seg_at_idx(struct ice_pkg_hdr *pkg_hdr, u32 idx)
186 : : {
187 : : struct ice_generic_seg_hdr *seg;
188 : : bool retval = false;
189 : :
190 : : seg = ice_get_pkg_seg_by_idx(pkg_hdr, idx);
191 : : if (seg)
192 : 0 : retval = LE32_TO_CPU(seg->seg_type) == SEGMENT_TYPE_SIGNING;
193 : :
194 : : return retval;
195 : : }
196 : :
197 : : /**
198 : : * ice_is_signing_seg_type_at_idx
199 : : * @pkg_hdr: pointer to package header
200 : : * @idx: segment index
201 : : * @seg_id: segment id that is expected
202 : : * @sign_type: signing type
203 : : *
204 : : * Determine if a segment is a signing segment of the correct type
205 : : */
206 : : static bool
207 : : ice_is_signing_seg_type_at_idx(struct ice_pkg_hdr *pkg_hdr, u32 idx,
208 : : u32 seg_id, u32 sign_type)
209 : : {
210 : : bool result = false;
211 : :
212 [ # # ]: 0 : if (ice_is_signing_seg_at_idx(pkg_hdr, idx)) {
213 : : struct ice_sign_seg *seg;
214 : :
215 : : seg = (struct ice_sign_seg *)ice_get_pkg_seg_by_idx(pkg_hdr,
216 : : idx);
217 [ # # # # ]: 0 : if (seg && LE32_TO_CPU(seg->seg_id) == seg_id &&
218 [ # # # # ]: 0 : LE32_TO_CPU(seg->sign_type) == sign_type)
219 : : result = true;
220 : : }
221 : :
222 : : return result;
223 : : }
224 : :
225 : : /**
226 : : * ice_update_pkg_no_lock
227 : : * @hw: pointer to the hardware structure
228 : : * @bufs: pointer to an array of buffers
229 : : * @count: the number of buffers in the array
230 : : */
231 : : enum ice_status
232 : 0 : ice_update_pkg_no_lock(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
233 : : {
234 : : enum ice_status status = ICE_SUCCESS;
235 : : u32 i;
236 : :
237 [ # # ]: 0 : for (i = 0; i < count; i++) {
238 : 0 : struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
239 : 0 : bool last = ((i + 1) == count);
240 : : u32 offset, info;
241 : :
242 : 0 : status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
243 : : last, &offset, &info, NULL);
244 : :
245 [ # # ]: 0 : if (status) {
246 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Update pkg failed: err %d off %d inf %d\n",
247 : : status, offset, info);
248 : 0 : break;
249 : : }
250 : : }
251 : :
252 : 0 : return status;
253 : : }
254 : :
255 : : /**
256 : : * ice_update_pkg
257 : : * @hw: pointer to the hardware structure
258 : : * @bufs: pointer to an array of buffers
259 : : * @count: the number of buffers in the array
260 : : *
261 : : * Obtains change lock and updates package.
262 : : */
263 : : enum ice_status
264 : 0 : ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
265 : : {
266 : : enum ice_status status;
267 : :
268 : 0 : status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
269 [ # # ]: 0 : if (status)
270 : : return status;
271 : :
272 : 0 : status = ice_update_pkg_no_lock(hw, bufs, count);
273 : :
274 : 0 : ice_release_change_lock(hw);
275 : :
276 : 0 : return status;
277 : : }
278 : :
279 : : static enum ice_ddp_state
280 : : ice_map_aq_err_to_ddp_state(enum ice_aq_err aq_err)
281 : : {
282 : : switch (aq_err) {
283 : : case ICE_AQ_RC_ENOSEC:
284 : : return ICE_DDP_PKG_NO_SEC_MANIFEST;
285 : : case ICE_AQ_RC_EBADSIG:
286 : : return ICE_DDP_PKG_FILE_SIGNATURE_INVALID;
287 : : case ICE_AQ_RC_ESVN:
288 : : return ICE_DDP_PKG_SECURE_VERSION_NBR_TOO_LOW;
289 : : case ICE_AQ_RC_EBADMAN:
290 : : return ICE_DDP_PKG_MANIFEST_INVALID;
291 : : case ICE_AQ_RC_EBADBUF:
292 : : return ICE_DDP_PKG_BUFFER_INVALID;
293 : : default:
294 : : return ICE_DDP_PKG_ERR;
295 : : }
296 : : }
297 : :
298 : : /**
299 : : * ice_is_buffer_metadata - determine if package buffer is a metadata buffer
300 : : * @buf: pointer to buffer header
301 : : */
302 : : static bool ice_is_buffer_metadata(struct ice_buf_hdr *buf)
303 : : {
304 : : bool metadata = false;
305 : :
306 [ # # ]: 0 : if (LE32_TO_CPU(buf->section_entry[0].type) & ICE_METADATA_BUF)
307 : : metadata = true;
308 : :
309 : : return metadata;
310 : : }
311 : :
312 : : /**
313 : : * ice_is_last_download_buffer
314 : : * @buf: pointer to current buffer header
315 : : * @idx: index of the buffer in the current sequence
316 : : * @count: the buffer count in the current sequence
317 : : *
318 : : * Note: this routine should only be called if the buffer is not the last buffer
319 : : */
320 : : static bool
321 : : ice_is_last_download_buffer(struct ice_buf_hdr *buf, u32 idx, u32 count)
322 : : {
323 : 0 : bool last = ((idx + 1) == count);
324 : :
325 : : /* A set metadata flag in the next buffer will signal that the current
326 : : * buffer will be the last buffer downloaded
327 : : */
328 [ # # ]: 0 : if (!last) {
329 : : struct ice_buf *next_buf = ((struct ice_buf *)buf) + 1;
330 : :
331 : : last = ice_is_buffer_metadata((struct ice_buf_hdr *)next_buf);
332 : : }
333 : :
334 : : return last;
335 : : }
336 : :
337 : : /**
338 : : * ice_dwnld_cfg_bufs_no_lock
339 : : * @hw: pointer to the hardware structure
340 : : * @bufs: pointer to an array of buffers
341 : : * @start: buffer index of first buffer to download
342 : : * @count: the number of buffers to download
343 : : * @indicate_last: if true, then set last buffer flag on last buffer download
344 : : *
345 : : * Downloads package configuration buffers to the firmware. Metadata buffers
346 : : * are skipped, and the first metadata buffer found indicates that the rest
347 : : * of the buffers are all metadata buffers.
348 : : */
349 : : static enum ice_ddp_state
350 : 0 : ice_dwnld_cfg_bufs_no_lock(struct ice_hw *hw, struct ice_buf *bufs, u32 start,
351 : : u32 count, bool indicate_last)
352 : : {
353 : : enum ice_ddp_state state = ICE_DDP_PKG_SUCCESS;
354 : : struct ice_buf_hdr *bh;
355 : : enum ice_aq_err err;
356 : : u32 offset, info, i;
357 : :
358 [ # # ]: 0 : if (!bufs || !count)
359 : : return ICE_DDP_PKG_ERR;
360 : :
361 : : /* If the first buffer's first section has its metadata bit set
362 : : * then there are no buffers to be downloaded, and the operation is
363 : : * considered a success.
364 : : */
365 : 0 : bh = (struct ice_buf_hdr *)(bufs + start);
366 [ # # ]: 0 : if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
367 : : return ICE_DDP_PKG_SUCCESS;
368 : :
369 [ # # ]: 0 : for (i = 0; i < count; i++) {
370 : : enum ice_status status;
371 : : bool last = false;
372 : :
373 : 0 : bh = (struct ice_buf_hdr *)(bufs + start + i);
374 : :
375 [ # # ]: 0 : if (indicate_last)
376 : : last = ice_is_last_download_buffer(bh, i, count);
377 : :
378 : 0 : status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
379 : : &offset, &info, NULL);
380 : :
381 : : /* Save AQ status from download package */
382 [ # # ]: 0 : if (status) {
383 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Pkg download failed: err %d off %d inf %d\n",
384 : : status, offset, info);
385 [ # # ]: 0 : err = hw->adminq.sq_last_status;
386 : : state = ice_map_aq_err_to_ddp_state(err);
387 : : break;
388 : : }
389 : :
390 [ # # ]: 0 : if (last)
391 : : break;
392 : : }
393 : :
394 : : return state;
395 : : }
396 : :
397 : : /**
398 : : * ice_aq_get_pkg_info_list
399 : : * @hw: pointer to the hardware structure
400 : : * @pkg_info: the buffer which will receive the information list
401 : : * @buf_size: the size of the pkg_info information buffer
402 : : * @cd: pointer to command details structure or NULL
403 : : *
404 : : * Get Package Info List (0x0C43)
405 : : */
406 : : static enum ice_status
407 : : ice_aq_get_pkg_info_list(struct ice_hw *hw,
408 : : struct ice_aqc_get_pkg_info_resp *pkg_info,
409 : : u16 buf_size, struct ice_sq_cd *cd)
410 : : {
411 : : struct ice_aq_desc desc;
412 : :
413 : 0 : ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
414 : :
415 : 0 : return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
416 : : }
417 : :
418 : : /**
419 : : * ice_has_signing_seg - determine if package has a signing segment
420 : : * @hw: pointer to the hardware structure
421 : : * @pkg_hdr: pointer to the driver's package hdr
422 : : */
423 : : static bool ice_has_signing_seg(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
424 : : {
425 : : struct ice_generic_seg_hdr *seg_hdr;
426 : :
427 : 0 : seg_hdr = (struct ice_generic_seg_hdr *)
428 : : ice_find_seg_in_pkg(hw, SEGMENT_TYPE_SIGNING, pkg_hdr);
429 : :
430 : 0 : return seg_hdr ? true : false;
431 : : }
432 : :
433 : : /**
434 : : * ice_get_pkg_segment_id - get correct package segment id, based on device
435 : : * @mac_type: MAC type of the device
436 : : */
437 : : static u32 ice_get_pkg_segment_id(enum ice_mac_type mac_type)
438 : : {
439 : : u32 seg_id;
440 : :
441 : : switch (mac_type) {
442 : : case ICE_MAC_GENERIC:
443 : : case ICE_MAC_GENERIC_3K:
444 : : case ICE_MAC_GENERIC_3K_E825:
445 : : default:
446 : : seg_id = SEGMENT_TYPE_ICE_E810;
447 : : break;
448 : : }
449 : :
450 : : return seg_id;
451 : : }
452 : :
453 : : /**
454 : : * ice_get_pkg_sign_type - get package segment sign type, based on device
455 : : * @mac_type: MAC type of the device
456 : : */
457 : : static u32 ice_get_pkg_sign_type(enum ice_mac_type mac_type)
458 : : {
459 : : u32 sign_type;
460 : :
461 : 0 : switch (mac_type) {
462 : : case ICE_MAC_GENERIC_3K:
463 : : sign_type = SEGMENT_SIGN_TYPE_RSA3K;
464 : : break;
465 : 0 : case ICE_MAC_GENERIC_3K_E825:
466 : : sign_type = SEGMENT_SIGN_TYPE_RSA3K_E825;
467 : 0 : break;
468 : 0 : case ICE_MAC_GENERIC:
469 : : default:
470 : : sign_type = SEGMENT_SIGN_TYPE_RSA2K;
471 : 0 : break;
472 : : }
473 : :
474 : : return sign_type;
475 : : }
476 : :
477 : : /**
478 : : * ice_get_signing_req - get correct package requirements, based on device
479 : : * @hw: pointer to the hardware structure
480 : : */
481 : : static void ice_get_signing_req(struct ice_hw *hw)
482 : : {
483 : 0 : hw->pkg_seg_id = ice_get_pkg_segment_id(hw->mac_type);
484 : 0 : hw->pkg_sign_type = ice_get_pkg_sign_type(hw->mac_type);
485 : : }
486 : :
487 : : /**
488 : : * ice_download_pkg_sig_seg - download a signature segment
489 : : * @hw: pointer to the hardware structure
490 : : * @seg: pointer to signature segment
491 : : */
492 : : static enum ice_ddp_state
493 : : ice_download_pkg_sig_seg(struct ice_hw *hw, struct ice_sign_seg *seg)
494 : : {
495 : : enum ice_ddp_state state;
496 : :
497 : 0 : state = ice_dwnld_cfg_bufs_no_lock(hw, seg->buf_tbl.buf_array, 0,
498 : : LE32_TO_CPU(seg->buf_tbl.buf_count),
499 : : false);
500 : :
501 : : return state;
502 : : }
503 : :
504 : : /**
505 : : * ice_download_pkg_config_seg - download a config segment
506 : : * @hw: pointer to the hardware structure
507 : : * @pkg_hdr: pointer to package header
508 : : * @idx: segment index
509 : : * @start: starting buffer
510 : : * @count: buffer count
511 : : *
512 : : * Note: idx must reference a ICE segment
513 : : */
514 : : static enum ice_ddp_state
515 [ # # ]: 0 : ice_download_pkg_config_seg(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr,
516 : : u32 idx, u32 start, u32 count)
517 : : {
518 : : struct ice_buf_table *bufs;
519 : : enum ice_ddp_state state;
520 : : struct ice_seg *seg;
521 : : u32 buf_count;
522 : :
523 : : seg = (struct ice_seg *)ice_get_pkg_seg_by_idx(pkg_hdr, idx);
524 : : if (!seg)
525 : : return ICE_DDP_PKG_ERR;
526 : :
527 : 0 : bufs = ice_find_buf_table(seg);
528 : 0 : buf_count = LE32_TO_CPU(bufs->buf_count);
529 : :
530 [ # # # # ]: 0 : if (start >= buf_count || start + count > buf_count)
531 : : return ICE_DDP_PKG_ERR;
532 : :
533 : 0 : state = ice_dwnld_cfg_bufs_no_lock(hw, bufs->buf_array, start, count,
534 : : true);
535 : :
536 : 0 : return state;
537 : : }
538 : :
539 : : /**
540 : : * ice_dwnld_sign_and_cfg_segs - download a signing segment and config segment
541 : : * @hw: pointer to the hardware structure
542 : : * @pkg_hdr: pointer to package header
543 : : * @idx: segment index (must be a signature segment)
544 : : *
545 : : * Note: idx must reference a signature segment
546 : : */
547 : : static enum ice_ddp_state
548 [ # # ]: 0 : ice_dwnld_sign_and_cfg_segs(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr,
549 : : u32 idx)
550 : : {
551 : : enum ice_ddp_state state;
552 : : struct ice_sign_seg *seg;
553 : : u32 conf_idx;
554 : : u32 start;
555 : : u32 count;
556 : :
557 : : seg = (struct ice_sign_seg *)ice_get_pkg_seg_by_idx(pkg_hdr, idx);
558 : : if (!seg) {
559 : : state = ICE_DDP_PKG_ERR;
560 : 0 : goto exit;
561 : : }
562 : :
563 : 0 : conf_idx = LE32_TO_CPU(seg->signed_seg_idx);
564 : 0 : start = LE32_TO_CPU(seg->signed_buf_start);
565 : 0 : count = LE32_TO_CPU(seg->signed_buf_count);
566 : :
567 : : state = ice_download_pkg_sig_seg(hw, seg);
568 [ # # ]: 0 : if (state)
569 : 0 : goto exit;
570 : :
571 : 0 : state = ice_download_pkg_config_seg(hw, pkg_hdr, conf_idx, start,
572 : : count);
573 : :
574 : 0 : exit:
575 : 0 : return state;
576 : : }
577 : :
578 : : /**
579 : : * ice_match_signing_seg - determine if a matching signing segment exists
580 : : * @pkg_hdr: pointer to package header
581 : : * @seg_id: segment id that is expected
582 : : * @sign_type: signing type
583 : : */
584 : : static bool
585 : : ice_match_signing_seg(struct ice_pkg_hdr *pkg_hdr, u32 seg_id, u32 sign_type)
586 : : {
587 : : bool match = false;
588 : : u32 i;
589 : :
590 [ # # ]: 0 : for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
591 : : if (ice_is_signing_seg_type_at_idx(pkg_hdr, i, seg_id,
592 : : sign_type)) {
593 : : match = true;
594 : : break;
595 : : }
596 : : }
597 : :
598 : : return match;
599 : : }
600 : :
601 : : /**
602 : : * ice_post_dwnld_pkg_actions - perform post download package actions
603 : : * @hw: pointer to the hardware structure
604 : : */
605 : : static enum ice_ddp_state
606 : 0 : ice_post_dwnld_pkg_actions(struct ice_hw *hw)
607 : : {
608 : : enum ice_ddp_state state = ICE_DDP_PKG_SUCCESS;
609 : : enum ice_status status;
610 : :
611 : 0 : status = ice_set_vlan_mode(hw);
612 [ # # ]: 0 : if (status) {
613 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Failed to set VLAN mode: err %d\n",
614 : : status);
615 : : state = ICE_DDP_PKG_ERR;
616 : : }
617 : :
618 : 0 : return state;
619 : : }
620 : :
621 : : /**
622 : : * ice_download_pkg_with_sig_seg - download package using signature segments
623 : : * @hw: pointer to the hardware structure
624 : : * @pkg_hdr: pointer to package header
625 : : */
626 : : static enum ice_ddp_state
627 : 0 : ice_download_pkg_with_sig_seg(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
628 : : {
629 : 0 : enum ice_aq_err aq_err = hw->adminq.sq_last_status;
630 : : enum ice_ddp_state state = ICE_DDP_PKG_ERR;
631 : : enum ice_status status;
632 : : u32 i;
633 : :
634 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Segment ID %d\n", hw->pkg_seg_id);
635 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Signature type %d\n", hw->pkg_sign_type);
636 : :
637 : 0 : status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
638 [ # # ]: 0 : if (status) {
639 [ # # ]: 0 : if (status == ICE_ERR_AQ_NO_WORK)
640 : : state = ICE_DDP_PKG_ALREADY_LOADED;
641 : : else
642 : : state = ice_map_aq_err_to_ddp_state(aq_err);
643 : 0 : return state;
644 : : }
645 : :
646 [ # # ]: 0 : for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
647 [ # # ]: 0 : if (!ice_is_signing_seg_type_at_idx(pkg_hdr, i, hw->pkg_seg_id,
648 : : hw->pkg_sign_type))
649 : 0 : continue;
650 : :
651 : 0 : state = ice_dwnld_sign_and_cfg_segs(hw, pkg_hdr, i);
652 [ # # ]: 0 : if (state)
653 : : break;
654 : : }
655 : :
656 [ # # ]: 0 : if (!state)
657 : 0 : state = ice_post_dwnld_pkg_actions(hw);
658 : :
659 : 0 : ice_release_global_cfg_lock(hw);
660 : :
661 : 0 : return state;
662 : : }
663 : :
664 : : /**
665 : : * ice_dwnld_cfg_bufs
666 : : * @hw: pointer to the hardware structure
667 : : * @bufs: pointer to an array of buffers
668 : : * @count: the number of buffers in the array
669 : : *
670 : : * Obtains global config lock and downloads the package configuration buffers
671 : : * to the firmware.
672 : : */
673 : : static enum ice_ddp_state
674 : 0 : ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
675 : : {
676 : : enum ice_ddp_state state = ICE_DDP_PKG_SUCCESS;
677 : : enum ice_status status;
678 : : struct ice_buf_hdr *bh;
679 : :
680 [ # # ]: 0 : if (!bufs || !count)
681 : : return ICE_DDP_PKG_ERR;
682 : :
683 : : /* If the first buffer's first section has its metadata bit set
684 : : * then there are no buffers to be downloaded, and the operation is
685 : : * considered a success.
686 : : */
687 : : bh = (struct ice_buf_hdr *)bufs;
688 [ # # ]: 0 : if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
689 : : return ICE_DDP_PKG_SUCCESS;
690 : :
691 : 0 : status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
692 [ # # ]: 0 : if (status) {
693 [ # # ]: 0 : if (status == ICE_ERR_AQ_NO_WORK)
694 : : return ICE_DDP_PKG_ALREADY_LOADED;
695 [ # # ]: 0 : return ice_map_aq_err_to_ddp_state(hw->adminq.sq_last_status);
696 : : }
697 : :
698 : 0 : state = ice_dwnld_cfg_bufs_no_lock(hw, bufs, 0, count, true);
699 [ # # ]: 0 : if (!state)
700 : 0 : state = ice_post_dwnld_pkg_actions(hw);
701 : :
702 : 0 : ice_release_global_cfg_lock(hw);
703 : :
704 : 0 : return state;
705 : : }
706 : :
707 : : /**
708 : : * ice_download_pkg_without_sig_seg
709 : : * @hw: pointer to the hardware structure
710 : : * @ice_seg: pointer to the segment of the package to be downloaded
711 : : *
712 : : * Handles the download of a complete package without signature segment.
713 : : */
714 : : static enum ice_ddp_state
715 : 0 : ice_download_pkg_without_sig_seg(struct ice_hw *hw, struct ice_seg *ice_seg)
716 : : {
717 : : struct ice_buf_table *ice_buf_tbl;
718 : : enum ice_ddp_state state;
719 : :
720 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Segment format version: %d.%d.%d.%d\n",
721 : : ice_seg->hdr.seg_format_ver.major,
722 : : ice_seg->hdr.seg_format_ver.minor,
723 : : ice_seg->hdr.seg_format_ver.update,
724 : : ice_seg->hdr.seg_format_ver.draft);
725 : :
726 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
727 : : LE32_TO_CPU(ice_seg->hdr.seg_type),
728 : : LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_id);
729 : :
730 : 0 : ice_buf_tbl = ice_find_buf_table(ice_seg);
731 : :
732 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
733 : : LE32_TO_CPU(ice_buf_tbl->buf_count));
734 : :
735 : 0 : state = ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
736 : : LE32_TO_CPU(ice_buf_tbl->buf_count));
737 : :
738 : 0 : return state;
739 : : }
740 : :
741 : : /**
742 : : * ice_download_pkg
743 : : * @hw: pointer to the hardware structure
744 : : * @pkg_hdr: pointer to package header
745 : : * @ice_seg: pointer to the segment of the package to be downloaded
746 : : *
747 : : * Handles the download of a complete package.
748 : : */
749 : : static enum ice_ddp_state
750 : 0 : ice_download_pkg(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr,
751 : : struct ice_seg *ice_seg)
752 : : {
753 : : enum ice_ddp_state state;
754 : :
755 [ # # ]: 0 : if (hw->pkg_has_signing_seg)
756 : 0 : state = ice_download_pkg_with_sig_seg(hw, pkg_hdr);
757 : : else
758 : 0 : state = ice_download_pkg_without_sig_seg(hw, ice_seg);
759 : :
760 : 0 : ice_post_pkg_dwnld_vlan_mode_cfg(hw);
761 : :
762 : 0 : return state;
763 : : }
764 : :
765 : : /**
766 : : * ice_init_pkg_info
767 : : * @hw: pointer to the hardware structure
768 : : * @pkg_hdr: pointer to the driver's package hdr
769 : : *
770 : : * Saves off the package details into the HW structure.
771 : : */
772 : : static enum ice_ddp_state
773 : 0 : ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
774 : : {
775 : : struct ice_generic_seg_hdr *seg_hdr;
776 : :
777 [ # # ]: 0 : if (!pkg_hdr)
778 : : return ICE_DDP_PKG_ERR;
779 : :
780 [ # # # ]: 0 : hw->pkg_has_signing_seg = ice_has_signing_seg(hw, pkg_hdr);
781 : : ice_get_signing_req(hw);
782 : :
783 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Pkg using segment id: 0x%08X\n",
784 : : hw->pkg_seg_id);
785 : :
786 : 0 : seg_hdr = (struct ice_generic_seg_hdr *)
787 : : ice_find_seg_in_pkg(hw, hw->pkg_seg_id, pkg_hdr);
788 [ # # ]: 0 : if (seg_hdr) {
789 : : struct ice_meta_sect *meta;
790 : : struct ice_pkg_enum state;
791 : :
792 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
793 : :
794 : : /* Get package information from the Metadata Section */
795 : : meta = (struct ice_meta_sect *)
796 : 0 : ice_pkg_enum_section((struct ice_seg *)seg_hdr, &state,
797 : : ICE_SID_METADATA);
798 [ # # ]: 0 : if (!meta) {
799 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Did not find ice metadata section in package\n");
800 : 0 : return ICE_DDP_PKG_INVALID_FILE;
801 : : }
802 : :
803 : 0 : hw->pkg_ver = meta->ver;
804 [ # # ]: 0 : ice_memcpy(hw->pkg_name, meta->name, sizeof(meta->name),
805 : : ICE_NONDMA_TO_NONDMA);
806 : :
807 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
808 : : meta->ver.major, meta->ver.minor, meta->ver.update,
809 : : meta->ver.draft, meta->name);
810 : :
811 : 0 : hw->ice_seg_fmt_ver = seg_hdr->seg_format_ver;
812 [ # # ]: 0 : ice_memcpy(hw->ice_seg_id, seg_hdr->seg_id,
813 : : sizeof(hw->ice_seg_id), ICE_NONDMA_TO_NONDMA);
814 : :
815 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Ice Seg: %d.%d.%d.%d, %s\n",
816 : : seg_hdr->seg_format_ver.major,
817 : : seg_hdr->seg_format_ver.minor,
818 : : seg_hdr->seg_format_ver.update,
819 : : seg_hdr->seg_format_ver.draft,
820 : : seg_hdr->seg_id);
821 : : } else {
822 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Did not find ice segment in driver package\n");
823 : 0 : return ICE_DDP_PKG_INVALID_FILE;
824 : : }
825 : :
826 : 0 : return ICE_DDP_PKG_SUCCESS;
827 : : }
828 : :
829 : : /**
830 : : * ice_get_pkg_info
831 : : * @hw: pointer to the hardware structure
832 : : *
833 : : * Store details of the package currently loaded in HW into the HW structure.
834 : : */
835 : 0 : enum ice_ddp_state ice_get_pkg_info(struct ice_hw *hw)
836 : : {
837 : : enum ice_ddp_state state = ICE_DDP_PKG_SUCCESS;
838 : : struct ice_aqc_get_pkg_info_resp *pkg_info;
839 : : u16 size;
840 : : u32 i;
841 : :
842 : : size = ice_struct_size(pkg_info, pkg_info, ICE_PKG_CNT);
843 : 0 : pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
844 [ # # ]: 0 : if (!pkg_info)
845 : : return ICE_DDP_PKG_ERR;
846 : :
847 [ # # ]: 0 : if (ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL)) {
848 : : state = ICE_DDP_PKG_ERR;
849 : 0 : goto init_pkg_free_alloc;
850 : : }
851 : :
852 [ # # ]: 0 : for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
853 : : #define ICE_PKG_FLAG_COUNT 4
854 : 0 : char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
855 : : u8 place = 0;
856 : :
857 [ # # ]: 0 : if (pkg_info->pkg_info[i].is_active) {
858 : 0 : flags[place++] = 'A';
859 : 0 : hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
860 : 0 : hw->active_track_id =
861 : 0 : LE32_TO_CPU(pkg_info->pkg_info[i].track_id);
862 [ # # ]: 0 : ice_memcpy(hw->active_pkg_name,
863 : : pkg_info->pkg_info[i].name,
864 : : sizeof(pkg_info->pkg_info[i].name),
865 : : ICE_NONDMA_TO_NONDMA);
866 : 0 : hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
867 : : }
868 [ # # ]: 0 : if (pkg_info->pkg_info[i].is_active_at_boot)
869 : 0 : flags[place++] = 'B';
870 [ # # ]: 0 : if (pkg_info->pkg_info[i].is_modified)
871 : 0 : flags[place++] = 'M';
872 [ # # ]: 0 : if (pkg_info->pkg_info[i].is_in_nvm)
873 : 0 : flags[place++] = 'N';
874 : :
875 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
876 : : i, pkg_info->pkg_info[i].ver.major,
877 : : pkg_info->pkg_info[i].ver.minor,
878 : : pkg_info->pkg_info[i].ver.update,
879 : : pkg_info->pkg_info[i].ver.draft,
880 : : pkg_info->pkg_info[i].name, flags);
881 : : }
882 : :
883 : 0 : init_pkg_free_alloc:
884 : 0 : ice_free(hw, pkg_info);
885 : :
886 : 0 : return state;
887 : : }
888 : :
889 : : /**
890 : : * ice_label_enum_handler
891 : : * @sect_type: section type
892 : : * @section: pointer to section
893 : : * @index: index of the label entry to be returned
894 : : * @offset: pointer to receive absolute offset, always zero for label sections
895 : : *
896 : : * This is a callback function that can be passed to ice_pkg_enum_entry.
897 : : * Handles enumeration of individual label entries.
898 : : */
899 : : static void *
900 : 0 : ice_label_enum_handler(u32 __ALWAYS_UNUSED sect_type, void *section, u32 index,
901 : : u32 *offset)
902 : : {
903 : : struct ice_label_section *labels;
904 : :
905 [ # # ]: 0 : if (!section)
906 : : return NULL;
907 : :
908 [ # # ]: 0 : if (index > ICE_MAX_LABELS_IN_BUF)
909 : : return NULL;
910 : :
911 [ # # ]: 0 : if (offset)
912 : 0 : *offset = 0;
913 : :
914 : : labels = (struct ice_label_section *)section;
915 [ # # ]: 0 : if (index >= LE16_TO_CPU(labels->count))
916 : : return NULL;
917 : :
918 : 0 : return labels->label + index;
919 : : }
920 : :
921 : : /**
922 : : * ice_enum_labels
923 : : * @ice_seg: pointer to the ice segment (NULL on subsequent calls)
924 : : * @type: the section type that will contain the label (0 on subsequent calls)
925 : : * @state: ice_pkg_enum structure that will hold the state of the enumeration
926 : : * @value: pointer to a value that will return the label's value if found
927 : : *
928 : : * Enumerates a list of labels in the package. The caller will call
929 : : * ice_enum_labels(ice_seg, type, ...) to start the enumeration, then call
930 : : * ice_enum_labels(NULL, 0, ...) to continue. When the function returns a NULL
931 : : * the end of the list has been reached.
932 : : */
933 : : static char *
934 : : ice_enum_labels(struct ice_seg *ice_seg, u32 type, struct ice_pkg_enum *state,
935 : : u16 *value)
936 : : {
937 : : struct ice_label *label;
938 : :
939 : : /* Check for valid label section on first call */
940 : : if (type && !(type >= ICE_SID_LBL_FIRST && type <= ICE_SID_LBL_LAST))
941 : : return NULL;
942 : :
943 : 0 : label = (struct ice_label *)ice_pkg_enum_entry(ice_seg, state, type,
944 : : NULL,
945 : : ice_label_enum_handler);
946 [ # # # # ]: 0 : if (!label)
947 : : return NULL;
948 : :
949 : 0 : *value = LE16_TO_CPU(label->value);
950 : 0 : return label->name;
951 : : }
952 : :
953 : : /**
954 : : * ice_verify_pkg - verify package
955 : : * @pkg: pointer to the package buffer
956 : : * @len: size of the package buffer
957 : : *
958 : : * Verifies various attributes of the package file, including length, format
959 : : * version, and the requirement of at least one segment.
960 : : */
961 : 0 : enum ice_ddp_state ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
962 : : {
963 : : u32 seg_count;
964 : : u32 i;
965 : :
966 [ # # ]: 0 : if (len < ice_struct_size(pkg, seg_offset, 1))
967 : : return ICE_DDP_PKG_INVALID_FILE;
968 : :
969 : 0 : if (pkg->pkg_format_ver.major != ICE_PKG_FMT_VER_MAJ ||
970 [ # # ]: 0 : pkg->pkg_format_ver.minor != ICE_PKG_FMT_VER_MNR ||
971 : 0 : pkg->pkg_format_ver.update != ICE_PKG_FMT_VER_UPD ||
972 [ # # ]: 0 : pkg->pkg_format_ver.draft != ICE_PKG_FMT_VER_DFT)
973 : : return ICE_DDP_PKG_INVALID_FILE;
974 : :
975 : : /* pkg must have at least one segment */
976 : 0 : seg_count = LE32_TO_CPU(pkg->seg_count);
977 [ # # ]: 0 : if (seg_count < 1)
978 : : return ICE_DDP_PKG_INVALID_FILE;
979 : :
980 : : /* make sure segment array fits in package length */
981 [ # # ]: 0 : if (len < ice_struct_size(pkg, seg_offset, seg_count))
982 : : return ICE_DDP_PKG_INVALID_FILE;
983 : :
984 : : /* all segments must fit within length */
985 [ # # ]: 0 : for (i = 0; i < seg_count; i++) {
986 : 0 : u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
987 : : struct ice_generic_seg_hdr *seg;
988 : :
989 : : /* segment header must fit */
990 [ # # ]: 0 : if (len < off + sizeof(*seg))
991 : : return ICE_DDP_PKG_INVALID_FILE;
992 : :
993 : 0 : seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
994 : :
995 : : /* segment body must fit */
996 [ # # ]: 0 : if (len < off + LE32_TO_CPU(seg->seg_size))
997 : : return ICE_DDP_PKG_INVALID_FILE;
998 : : }
999 : :
1000 : : return ICE_DDP_PKG_SUCCESS;
1001 : : }
1002 : :
1003 : : /**
1004 : : * ice_free_seg - free package segment pointer
1005 : : * @hw: pointer to the hardware structure
1006 : : *
1007 : : * Frees the package segment pointer in the proper manner, depending on if the
1008 : : * segment was allocated or just the passed in pointer was stored.
1009 : : */
1010 : 0 : void ice_free_seg(struct ice_hw *hw)
1011 : : {
1012 [ # # ]: 0 : if (hw->pkg_copy) {
1013 : 0 : ice_free(hw, hw->pkg_copy);
1014 : 0 : hw->pkg_copy = NULL;
1015 : 0 : hw->pkg_size = 0;
1016 : : }
1017 : 0 : hw->seg = NULL;
1018 : 0 : }
1019 : :
1020 : : /**
1021 : : * ice_chk_pkg_version - check package version for compatibility with driver
1022 : : * @pkg_ver: pointer to a version structure to check
1023 : : *
1024 : : * Check to make sure that the package about to be downloaded is compatible with
1025 : : * the driver. To be compatible, the major and minor components of the package
1026 : : * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1027 : : * definitions.
1028 : : */
1029 : : static enum ice_ddp_state ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver)
1030 : : {
1031 [ # # ]: 0 : if (pkg_ver->major > ICE_PKG_SUPP_VER_MAJ ||
1032 : 0 : (pkg_ver->major == ICE_PKG_SUPP_VER_MAJ &&
1033 [ # # ]: 0 : pkg_ver->minor > ICE_PKG_SUPP_VER_MNR))
1034 : : return ICE_DDP_PKG_FILE_VERSION_TOO_HIGH;
1035 [ # # ]: 0 : else if (pkg_ver->major < ICE_PKG_SUPP_VER_MAJ ||
1036 : 0 : (pkg_ver->major == ICE_PKG_SUPP_VER_MAJ &&
1037 [ # # ]: 0 : pkg_ver->minor < ICE_PKG_SUPP_VER_MNR))
1038 : : return ICE_DDP_PKG_FILE_VERSION_TOO_LOW;
1039 : :
1040 : : return ICE_DDP_PKG_SUCCESS;
1041 : : }
1042 : :
1043 : : /**
1044 : : * ice_chk_pkg_compat
1045 : : * @hw: pointer to the hardware structure
1046 : : * @ospkg: pointer to the package hdr
1047 : : * @seg: pointer to the package segment hdr
1048 : : *
1049 : : * This function checks the package version compatibility with driver and NVM
1050 : : */
1051 : : static enum ice_ddp_state
1052 [ # # ]: 0 : ice_chk_pkg_compat(struct ice_hw *hw, struct ice_pkg_hdr *ospkg,
1053 : : struct ice_seg **seg)
1054 : : {
1055 : : struct ice_aqc_get_pkg_info_resp *pkg;
1056 : : enum ice_ddp_state state;
1057 : : u16 size;
1058 : : u32 i;
1059 : :
1060 : : /* Check package version compatibility */
1061 : : state = ice_chk_pkg_version(&hw->pkg_ver);
1062 : : if (state) {
1063 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Package version check failed.\n");
1064 : 0 : return state;
1065 : : }
1066 : :
1067 : : /* find ICE segment in given package */
1068 : 0 : *seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, hw->pkg_seg_id,
1069 : : ospkg);
1070 [ # # ]: 0 : if (!*seg) {
1071 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1072 : 0 : return ICE_DDP_PKG_INVALID_FILE;
1073 : : }
1074 : :
1075 : : /* Check if FW is compatible with the OS package */
1076 : : size = ice_struct_size(pkg, pkg_info, ICE_PKG_CNT);
1077 : 0 : pkg = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1078 [ # # ]: 0 : if (!pkg)
1079 : : return ICE_DDP_PKG_ERR;
1080 : :
1081 [ # # ]: 0 : if (ice_aq_get_pkg_info_list(hw, pkg, size, NULL)) {
1082 : : state = ICE_DDP_PKG_ERR;
1083 : 0 : goto fw_ddp_compat_free_alloc;
1084 : : }
1085 : :
1086 [ # # ]: 0 : for (i = 0; i < LE32_TO_CPU(pkg->count); i++) {
1087 : : /* loop till we find the NVM package */
1088 [ # # ]: 0 : if (!pkg->pkg_info[i].is_in_nvm)
1089 : : continue;
1090 : 0 : if ((*seg)->hdr.seg_format_ver.major !=
1091 [ # # ]: 0 : pkg->pkg_info[i].ver.major ||
1092 : 0 : (*seg)->hdr.seg_format_ver.minor >
1093 [ # # ]: 0 : pkg->pkg_info[i].ver.minor) {
1094 : : state = ICE_DDP_PKG_FW_MISMATCH;
1095 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "OS package is not compatible with NVM.\n");
1096 : : }
1097 : : /* done processing NVM package so break */
1098 : : break;
1099 : : }
1100 : 0 : fw_ddp_compat_free_alloc:
1101 : 0 : ice_free(hw, pkg);
1102 : 0 : return state;
1103 : : }
1104 : :
1105 : : /**
1106 : : * ice_sw_fv_handler
1107 : : * @sect_type: section type
1108 : : * @section: pointer to section
1109 : : * @index: index of the field vector entry to be returned
1110 : : * @offset: ptr to variable that receives the offset in the field vector table
1111 : : *
1112 : : * This is a callback function that can be passed to ice_pkg_enum_entry.
1113 : : * This function treats the given section as of type ice_sw_fv_section and
1114 : : * enumerates offset field. "offset" is an index into the field vector table.
1115 : : */
1116 : : static void *
1117 : 0 : ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1118 : : {
1119 : : struct ice_sw_fv_section *fv_section =
1120 : : (struct ice_sw_fv_section *)section;
1121 : :
1122 [ # # ]: 0 : if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1123 : : return NULL;
1124 [ # # ]: 0 : if (index >= LE16_TO_CPU(fv_section->count))
1125 : : return NULL;
1126 [ # # ]: 0 : if (offset)
1127 : : /* "index" passed in to this function is relative to a given
1128 : : * 4k block. To get to the true index into the field vector
1129 : : * table need to add the relative index to the base_offset
1130 : : * field of this section
1131 : : */
1132 : 0 : *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1133 : 0 : return fv_section->fv + index;
1134 : : }
1135 : :
1136 : : /**
1137 : : * ice_get_prof_index_max - get the max profile index for used profile
1138 : : * @hw: pointer to the HW struct
1139 : : *
1140 : : * Calling this function will get the max profile index for used profile
1141 : : * and store the index number in struct ice_switch_info *switch_info
1142 : : * in hw for following use.
1143 : : */
1144 [ # # ]: 0 : static int ice_get_prof_index_max(struct ice_hw *hw)
1145 : : {
1146 : : u16 prof_index = 0, j, max_prof_index = 0;
1147 : : struct ice_pkg_enum state;
1148 : : struct ice_seg *ice_seg;
1149 : : bool flag = false;
1150 : : struct ice_fv *fv;
1151 : : u32 offset;
1152 : :
1153 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1154 : :
1155 [ # # ]: 0 : if (!hw->seg)
1156 : : return ICE_ERR_PARAM;
1157 : :
1158 : : ice_seg = hw->seg;
1159 : :
1160 : : do {
1161 : : fv = (struct ice_fv *)
1162 : 0 : ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1163 : : &offset, ice_sw_fv_handler);
1164 [ # # ]: 0 : if (!fv)
1165 : : break;
1166 : : ice_seg = NULL;
1167 : :
1168 : : /* in the profile that not be used, the prot_id is set to 0xff
1169 : : * and the off is set to 0x1ff for all the field vectors.
1170 : : */
1171 [ # # ]: 0 : for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1172 [ # # ]: 0 : if (fv->ew[j].prot_id != ICE_PROT_INVALID ||
1173 [ # # ]: 0 : fv->ew[j].off != ICE_FV_OFFSET_INVAL)
1174 : : flag = true;
1175 [ # # ]: 0 : if (flag && prof_index > max_prof_index)
1176 : : max_prof_index = prof_index;
1177 : :
1178 : 0 : prof_index++;
1179 : : flag = false;
1180 : : } while (fv);
1181 : :
1182 : 0 : hw->switch_info->max_used_prof_index = max_prof_index;
1183 : :
1184 : 0 : return ICE_SUCCESS;
1185 : : }
1186 : :
1187 : : /**
1188 : : * ice_get_ddp_pkg_state - get DDP pkg state after download
1189 : : * @hw: pointer to the HW struct
1190 : : * @already_loaded: indicates if pkg was already loaded onto the device
1191 : : *
1192 : : */
1193 : : static enum ice_ddp_state
1194 : 0 : ice_get_ddp_pkg_state(struct ice_hw *hw, bool already_loaded)
1195 : : {
1196 : 0 : if (hw->pkg_ver.major == hw->active_pkg_ver.major &&
1197 [ # # ]: 0 : hw->pkg_ver.minor == hw->active_pkg_ver.minor &&
1198 : 0 : hw->pkg_ver.update == hw->active_pkg_ver.update &&
1199 [ # # ]: 0 : hw->pkg_ver.draft == hw->active_pkg_ver.draft &&
1200 [ # # ]: 0 : !memcmp(hw->pkg_name, hw->active_pkg_name, sizeof(hw->pkg_name))) {
1201 [ # # ]: 0 : if (already_loaded)
1202 : : return ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED;
1203 : : else
1204 : 0 : return ICE_DDP_PKG_SUCCESS;
1205 [ # # ]: 0 : } else if (hw->active_pkg_ver.major != ICE_PKG_SUPP_VER_MAJ ||
1206 : : hw->active_pkg_ver.minor != ICE_PKG_SUPP_VER_MNR) {
1207 : : return ICE_DDP_PKG_ALREADY_LOADED_NOT_SUPPORTED;
1208 : : } else if (hw->active_pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
1209 : : hw->active_pkg_ver.minor == ICE_PKG_SUPP_VER_MNR) {
1210 : 0 : return ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED;
1211 : : } else {
1212 : : return ICE_DDP_PKG_ERR;
1213 : : }
1214 : : }
1215 : :
1216 : : /**
1217 : : * ice_init_pkg_regs - initialize additional package registers
1218 : : * @hw: pointer to the hardware structure
1219 : : */
1220 : : static void ice_init_pkg_regs(struct ice_hw *hw)
1221 : : {
1222 : : #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1223 : : #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1224 : : #define ICE_SW_BLK_IDX 0
1225 : 0 : if (hw->dcf_enabled)
1226 : : return;
1227 : :
1228 : : /* setup Switch block input mask, which is 48-bits in two parts */
1229 : 0 : wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1230 : 0 : wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1231 : : }
1232 : :
1233 : : /**
1234 : : * ice_hw_ptype_ena - check if the PTYPE is enabled or not
1235 : : * @hw: pointer to the HW structure
1236 : : * @ptype: the hardware PTYPE
1237 : : */
1238 : 0 : bool ice_hw_ptype_ena(struct ice_hw *hw, u16 ptype)
1239 : : {
1240 [ # # # # ]: 0 : return ptype < ICE_FLOW_PTYPE_MAX &&
1241 [ # # ]: 0 : ice_is_bit_set(hw->hw_ptype, ptype);
1242 : : }
1243 : :
1244 : : /**
1245 : : * ice_marker_ptype_tcam_handler
1246 : : * @sect_type: section type
1247 : : * @section: pointer to section
1248 : : * @index: index of the Marker PType TCAM entry to be returned
1249 : : * @offset: pointer to receive absolute offset, always 0 for ptype TCAM sections
1250 : : *
1251 : : * This is a callback function that can be passed to ice_pkg_enum_entry.
1252 : : * Handles enumeration of individual Marker PType TCAM entries.
1253 : : */
1254 : : static void *
1255 : 0 : ice_marker_ptype_tcam_handler(u32 sect_type, void *section, u32 index,
1256 : : u32 *offset)
1257 : : {
1258 : : struct ice_marker_ptype_tcam_section *marker_ptype;
1259 : :
1260 [ # # ]: 0 : if (!section)
1261 : : return NULL;
1262 : :
1263 [ # # ]: 0 : if (sect_type != ICE_SID_RXPARSER_MARKER_PTYPE)
1264 : : return NULL;
1265 : :
1266 [ # # ]: 0 : if (index > ICE_MAX_MARKER_PTYPE_TCAMS_IN_BUF)
1267 : : return NULL;
1268 : :
1269 [ # # ]: 0 : if (offset)
1270 : 0 : *offset = 0;
1271 : :
1272 : : marker_ptype = (struct ice_marker_ptype_tcam_section *)section;
1273 [ # # ]: 0 : if (index >= LE16_TO_CPU(marker_ptype->count))
1274 : : return NULL;
1275 : :
1276 : 0 : return marker_ptype->tcam + index;
1277 : : }
1278 : :
1279 : : /**
1280 : : * ice_fill_hw_ptype - fill the enabled PTYPE bit information
1281 : : * @hw: pointer to the HW structure
1282 : : */
1283 : : static void
1284 : 0 : ice_fill_hw_ptype(struct ice_hw *hw)
1285 : : {
1286 : : struct ice_marker_ptype_tcam_entry *tcam;
1287 : 0 : struct ice_seg *seg = hw->seg;
1288 : : struct ice_pkg_enum state;
1289 : :
1290 [ # # ]: 0 : ice_zero_bitmap(hw->hw_ptype, ICE_FLOW_PTYPE_MAX);
1291 [ # # ]: 0 : if (!seg)
1292 : 0 : return;
1293 : :
1294 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1295 : :
1296 : : do {
1297 : : tcam = (struct ice_marker_ptype_tcam_entry *)
1298 : 0 : ice_pkg_enum_entry(seg, &state,
1299 : : ICE_SID_RXPARSER_MARKER_PTYPE, NULL,
1300 : : ice_marker_ptype_tcam_handler);
1301 [ # # ]: 0 : if (tcam &&
1302 [ # # ]: 0 : LE16_TO_CPU(tcam->addr) < ICE_MARKER_PTYPE_TCAM_ADDR_MAX &&
1303 [ # # ]: 0 : LE16_TO_CPU(tcam->ptype) < ICE_FLOW_PTYPE_MAX)
1304 : : ice_set_bit(LE16_TO_CPU(tcam->ptype), hw->hw_ptype);
1305 : :
1306 : : seg = NULL;
1307 [ # # ]: 0 : } while (tcam);
1308 : : }
1309 : :
1310 : : /**
1311 : : * ice_init_pkg - initialize/download package
1312 : : * @hw: pointer to the hardware structure
1313 : : * @buf: pointer to the package buffer
1314 : : * @len: size of the package buffer
1315 : : *
1316 : : * This function initializes a package. The package contains HW tables
1317 : : * required to do packet processing. First, the function extracts package
1318 : : * information such as version. Then it finds the ice configuration segment
1319 : : * within the package; this function then saves a copy of the segment pointer
1320 : : * within the supplied package buffer. Next, the function will cache any hints
1321 : : * from the package, followed by downloading the package itself. Note, that if
1322 : : * a previous PF driver has already downloaded the package successfully, then
1323 : : * the current driver will not have to download the package again.
1324 : : *
1325 : : * The local package contents will be used to query default behavior and to
1326 : : * update specific sections of the HW's version of the package (e.g. to update
1327 : : * the parse graph to understand new protocols).
1328 : : *
1329 : : * This function stores a pointer to the package buffer memory, and it is
1330 : : * expected that the supplied buffer will not be freed immediately. If the
1331 : : * package buffer needs to be freed, such as when read from a file, use
1332 : : * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1333 : : * case.
1334 : : */
1335 : 0 : enum ice_ddp_state ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1336 : : {
1337 : : bool already_loaded = false;
1338 : : enum ice_ddp_state state;
1339 : : struct ice_pkg_hdr *pkg;
1340 : : struct ice_seg *seg;
1341 : :
1342 [ # # ]: 0 : if (!buf || !len)
1343 : : return ICE_DDP_PKG_ERR;
1344 : :
1345 : : pkg = (struct ice_pkg_hdr *)buf;
1346 : 0 : state = ice_verify_pkg(pkg, len);
1347 [ # # ]: 0 : if (state) {
1348 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1349 : : state);
1350 : 0 : return state;
1351 : : }
1352 : :
1353 : : /* initialize package info */
1354 : 0 : state = ice_init_pkg_info(hw, pkg);
1355 [ # # ]: 0 : if (state)
1356 : : return state;
1357 : :
1358 : : /* For packages with signing segments, must be a matching segment */
1359 [ # # ]: 0 : if (hw->pkg_has_signing_seg)
1360 [ # # ]: 0 : if (!ice_match_signing_seg(pkg, hw->pkg_seg_id,
1361 : : hw->pkg_sign_type))
1362 : : return ICE_DDP_PKG_ERR;
1363 : :
1364 : : /* before downloading the package, check package version for
1365 : : * compatibility with driver
1366 : : */
1367 : 0 : state = ice_chk_pkg_compat(hw, pkg, &seg);
1368 [ # # ]: 0 : if (state)
1369 : : return state;
1370 : :
1371 : : /* initialize package hints and then download package */
1372 : 0 : ice_init_pkg_hints(hw, seg);
1373 : 0 : state = ice_download_pkg(hw, pkg, seg);
1374 : :
1375 [ # # ]: 0 : if (state == ICE_DDP_PKG_ALREADY_LOADED) {
1376 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "package previously loaded - no work.\n");
1377 : : already_loaded = true;
1378 : : }
1379 : :
1380 : : /* Get information on the package currently loaded in HW, then make sure
1381 : : * the driver is compatible with this version.
1382 : : */
1383 [ # # ]: 0 : if (!state || state == ICE_DDP_PKG_ALREADY_LOADED) {
1384 : 0 : state = ice_get_pkg_info(hw);
1385 [ # # ]: 0 : if (!state)
1386 : 0 : state = ice_get_ddp_pkg_state(hw, already_loaded);
1387 : : }
1388 : :
1389 [ # # ]: 0 : if (ice_is_init_pkg_successful(state)) {
1390 [ # # ]: 0 : hw->seg = seg;
1391 : : /* on successful package download update other required
1392 : : * registers to support the package and fill HW tables
1393 : : * with package content.
1394 : : */
1395 : : ice_init_pkg_regs(hw);
1396 : 0 : ice_fill_blk_tbls(hw);
1397 : 0 : ice_fill_hw_ptype(hw);
1398 : 0 : ice_get_prof_index_max(hw);
1399 : : } else {
1400 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1401 : : state);
1402 : : }
1403 : :
1404 : : return state;
1405 : : }
1406 : :
1407 : : /**
1408 : : * ice_copy_and_init_pkg - initialize/download a copy of the package
1409 : : * @hw: pointer to the hardware structure
1410 : : * @buf: pointer to the package buffer
1411 : : * @len: size of the package buffer
1412 : : *
1413 : : * This function copies the package buffer, and then calls ice_init_pkg() to
1414 : : * initialize the copied package contents.
1415 : : *
1416 : : * The copying is necessary if the package buffer supplied is constant, or if
1417 : : * the memory may disappear shortly after calling this function.
1418 : : *
1419 : : * If the package buffer resides in the data segment and can be modified, the
1420 : : * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1421 : : *
1422 : : * However, if the package buffer needs to be copied first, such as when being
1423 : : * read from a file, the caller should use ice_copy_and_init_pkg().
1424 : : *
1425 : : * This function will first copy the package buffer, before calling
1426 : : * ice_init_pkg(). The caller is free to immediately destroy the original
1427 : : * package buffer, as the new copy will be managed by this function and
1428 : : * related routines.
1429 : : */
1430 : : enum ice_ddp_state
1431 : 0 : ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1432 : : {
1433 : : enum ice_ddp_state state;
1434 : : u8 *buf_copy;
1435 : :
1436 [ # # ]: 0 : if (!buf || !len)
1437 : : return ICE_DDP_PKG_ERR;
1438 : :
1439 : 0 : buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1440 : :
1441 : 0 : state = ice_init_pkg(hw, buf_copy, len);
1442 [ # # ]: 0 : if (!ice_is_init_pkg_successful(state)) {
1443 : : /* Free the copy, since we failed to initialize the package */
1444 : 0 : ice_free(hw, buf_copy);
1445 : : } else {
1446 : : /* Track the copied pkg so we can free it later */
1447 : 0 : hw->pkg_copy = buf_copy;
1448 : 0 : hw->pkg_size = len;
1449 : : }
1450 : :
1451 : : return state;
1452 : : }
1453 : :
1454 : : /**
1455 : : * ice_is_init_pkg_successful - check if DDP init was successful
1456 : : * @state: state of the DDP pkg after download
1457 : : */
1458 : 0 : bool ice_is_init_pkg_successful(enum ice_ddp_state state)
1459 : : {
1460 [ # # ]: 0 : switch (state) {
1461 : : case ICE_DDP_PKG_SUCCESS:
1462 : : case ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED:
1463 : : case ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED:
1464 : : return true;
1465 : 0 : default:
1466 : 0 : return false;
1467 : : }
1468 : : }
1469 : :
1470 : : /**
1471 : : * ice_pkg_buf_alloc
1472 : : * @hw: pointer to the HW structure
1473 : : *
1474 : : * Allocates a package buffer and returns a pointer to the buffer header.
1475 : : * Note: all package contents must be in Little Endian form.
1476 : : */
1477 : 0 : struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1478 : : {
1479 : : struct ice_buf_build *bld;
1480 : : struct ice_buf_hdr *buf;
1481 : :
1482 : 0 : bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1483 [ # # ]: 0 : if (!bld)
1484 : : return NULL;
1485 : :
1486 : : buf = (struct ice_buf_hdr *)bld;
1487 : 0 : buf->data_end = CPU_TO_LE16(offsetof(struct ice_buf_hdr,
1488 : : section_entry));
1489 : 0 : return bld;
1490 : : }
1491 : :
1492 : : /**
1493 : : * ice_get_sw_prof_type - determine switch profile type
1494 : : * @hw: pointer to the HW structure
1495 : : * @fv: pointer to the switch field vector
1496 : : */
1497 : : static enum ice_prof_type
1498 : : ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
1499 : : {
1500 : : bool valid_prof = false;
1501 : : u16 i;
1502 : :
1503 [ # # ]: 0 : for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
1504 [ # # ]: 0 : if (fv->ew[i].off != ICE_NAN_OFFSET)
1505 : : valid_prof = true;
1506 : :
1507 : : /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
1508 [ # # # # ]: 0 : if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
1509 : : fv->ew[i].off == ICE_VNI_OFFSET)
1510 : : return ICE_PROF_TUN_UDP;
1511 : :
1512 : : /* GRE tunnel will have GRE protocol */
1513 [ # # ]: 0 : if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF)
1514 : : return ICE_PROF_TUN_GRE;
1515 : :
1516 : : /* PPPOE tunnel will have PPPOE protocol */
1517 [ # # ]: 0 : if (fv->ew[i].prot_id == (u8)ICE_PROT_PPPOE)
1518 : : return ICE_PROF_TUN_PPPOE;
1519 : : }
1520 : :
1521 : 0 : return valid_prof ? ICE_PROF_NON_TUN : ICE_PROF_INVALID;
1522 : : }
1523 : :
1524 : : /**
1525 : : * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type
1526 : : * @hw: pointer to hardware structure
1527 : : * @req_profs: type of profiles requested
1528 : : * @bm: pointer to memory for returning the bitmap of field vectors
1529 : : */
1530 : : void
1531 : 0 : ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs,
1532 : : ice_bitmap_t *bm)
1533 : : {
1534 : : struct ice_pkg_enum state;
1535 : : struct ice_seg *ice_seg;
1536 : : struct ice_fv *fv;
1537 : :
1538 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1539 : : ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
1540 : 0 : ice_seg = hw->seg;
1541 : : do {
1542 : : enum ice_prof_type prof_type;
1543 : : u32 offset;
1544 : :
1545 : : fv = (struct ice_fv *)
1546 : 0 : ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1547 : : &offset, ice_sw_fv_handler);
1548 : : ice_seg = NULL;
1549 : :
1550 [ # # ]: 0 : if (fv) {
1551 : : /* Determine field vector type */
1552 : : prof_type = ice_get_sw_prof_type(hw, fv);
1553 : :
1554 [ # # ]: 0 : if (req_profs & prof_type)
1555 : 0 : ice_set_bit((u16)offset, bm);
1556 : : }
1557 [ # # ]: 0 : } while (fv);
1558 : 0 : }
1559 : :
1560 : : /**
1561 : : * ice_get_sw_fv_list
1562 : : * @hw: pointer to the HW structure
1563 : : * @lkups: lookup elements or match criteria for the advanced recipe, one
1564 : : * structure per protocol header
1565 : : * @bm: bitmap of field vectors to consider
1566 : : * @fv_list: Head of a list
1567 : : *
1568 : : * Finds all the field vector entries from switch block that contain
1569 : : * a given protocol ID and offset and returns a list of structures of type
1570 : : * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1571 : : * definition and profile ID information
1572 : : * NOTE: The caller of the function is responsible for freeing the memory
1573 : : * allocated for every list entry.
1574 : : */
1575 : : enum ice_status
1576 : 0 : ice_get_sw_fv_list(struct ice_hw *hw, struct ice_prot_lkup_ext *lkups,
1577 : : ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list)
1578 : : {
1579 : : struct ice_sw_fv_list_entry *fvl;
1580 : : struct ice_sw_fv_list_entry *tmp;
1581 : : struct ice_pkg_enum state;
1582 : : struct ice_seg *ice_seg;
1583 : : struct ice_fv *fv;
1584 : : u32 offset;
1585 : :
1586 [ # # ]: 0 : if (!lkups->n_val_words)
1587 : : return ICE_SUCCESS;
1588 : :
1589 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1590 : :
1591 [ # # ]: 0 : if (!lkups->n_val_words || !hw->seg)
1592 : : return ICE_ERR_PARAM;
1593 : :
1594 : : ice_seg = hw->seg;
1595 : : do {
1596 : : u16 i;
1597 : :
1598 : : fv = (struct ice_fv *)
1599 : 0 : ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1600 : : &offset, ice_sw_fv_handler);
1601 [ # # ]: 0 : if (!fv)
1602 : : break;
1603 : : ice_seg = NULL;
1604 : :
1605 : : /* If field vector is not in the bitmap list, then skip this
1606 : : * profile.
1607 : : */
1608 [ # # ]: 0 : if (!ice_is_bit_set(bm, (u16)offset))
1609 : 0 : continue;
1610 : :
1611 [ # # ]: 0 : for (i = 0; i < lkups->n_val_words; i++) {
1612 : : int j;
1613 : :
1614 [ # # ]: 0 : for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1615 : 0 : if (fv->ew[j].prot_id ==
1616 [ # # ]: 0 : lkups->fv_words[i].prot_id &&
1617 [ # # ]: 0 : fv->ew[j].off == lkups->fv_words[i].off)
1618 : : break;
1619 [ # # ]: 0 : if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1620 : : break;
1621 [ # # ]: 0 : if (i + 1 == lkups->n_val_words) {
1622 : : fvl = (struct ice_sw_fv_list_entry *)
1623 : 0 : ice_malloc(hw, sizeof(*fvl));
1624 [ # # ]: 0 : if (!fvl)
1625 : 0 : goto err;
1626 : 0 : fvl->fv_ptr = fv;
1627 : 0 : fvl->profile_id = offset;
1628 [ # # ]: 0 : LIST_ADD(&fvl->list_entry, fv_list);
1629 : 0 : break;
1630 : : }
1631 : : }
1632 : : } while (fv);
1633 [ # # ]: 0 : if (LIST_EMPTY(fv_list)) {
1634 [ # # ]: 0 : ice_warn(hw, "Required profiles not found in currently loaded DDP package");
1635 : 0 : return ICE_ERR_CFG;
1636 : : }
1637 : : return ICE_SUCCESS;
1638 : :
1639 : : err:
1640 [ # # # # : 0 : LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
# # # # #
# ]
1641 : : list_entry) {
1642 [ # # ]: 0 : LIST_DEL(&fvl->list_entry);
1643 : 0 : ice_free(hw, fvl);
1644 : : }
1645 : :
1646 : : return ICE_ERR_NO_MEMORY;
1647 : : }
1648 : :
1649 : : /**
1650 : : * ice_init_prof_result_bm - Initialize the profile result index bitmap
1651 : : * @hw: pointer to hardware structure
1652 : : */
1653 [ # # ]: 0 : void ice_init_prof_result_bm(struct ice_hw *hw)
1654 : : {
1655 : : struct ice_pkg_enum state;
1656 : : struct ice_seg *ice_seg;
1657 : : struct ice_fv *fv;
1658 : :
1659 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1660 : :
1661 [ # # ]: 0 : if (!hw->seg)
1662 : 0 : return;
1663 : :
1664 : : ice_seg = hw->seg;
1665 : : do {
1666 : : u32 off;
1667 : : u16 i;
1668 : :
1669 : : fv = (struct ice_fv *)
1670 : 0 : ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1671 : : &off, ice_sw_fv_handler);
1672 : : ice_seg = NULL;
1673 [ # # ]: 0 : if (!fv)
1674 : : break;
1675 : :
1676 : 0 : ice_zero_bitmap(hw->switch_info->prof_res_bm[off],
1677 : : ICE_MAX_FV_WORDS);
1678 : :
1679 : : /* Determine empty field vector indices, these can be
1680 : : * used for recipe results. Skip index 0, since it is
1681 : : * always used for Switch ID.
1682 : : */
1683 [ # # ]: 0 : for (i = 1; i < ICE_MAX_FV_WORDS; i++)
1684 [ # # ]: 0 : if (fv->ew[i].prot_id == ICE_PROT_INVALID &&
1685 [ # # ]: 0 : fv->ew[i].off == ICE_FV_OFFSET_INVAL)
1686 : : ice_set_bit(i,
1687 : 0 : hw->switch_info->prof_res_bm[off]);
1688 : : } while (fv);
1689 : : }
1690 : :
1691 : : /**
1692 : : * ice_pkg_buf_free
1693 : : * @hw: pointer to the HW structure
1694 : : * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1695 : : *
1696 : : * Frees a package buffer
1697 : : */
1698 : 0 : void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1699 : : {
1700 : 0 : ice_free(hw, bld);
1701 : 0 : }
1702 : :
1703 : : /**
1704 : : * ice_pkg_buf_reserve_section
1705 : : * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1706 : : * @count: the number of sections to reserve
1707 : : *
1708 : : * Reserves one or more section table entries in a package buffer. This routine
1709 : : * can be called multiple times as long as they are made before calling
1710 : : * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1711 : : * is called once, the number of sections that can be allocated will not be able
1712 : : * to be increased; not using all reserved sections is fine, but this will
1713 : : * result in some wasted space in the buffer.
1714 : : * Note: all package contents must be in Little Endian form.
1715 : : */
1716 : : enum ice_status
1717 : 0 : ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1718 : : {
1719 : : struct ice_buf_hdr *buf;
1720 : : u16 section_count;
1721 : : u16 data_end;
1722 : :
1723 [ # # ]: 0 : if (!bld)
1724 : : return ICE_ERR_PARAM;
1725 : :
1726 : : buf = (struct ice_buf_hdr *)&bld->buf;
1727 : :
1728 : : /* already an active section, can't increase table size */
1729 : 0 : section_count = LE16_TO_CPU(buf->section_count);
1730 [ # # ]: 0 : if (section_count > 0)
1731 : : return ICE_ERR_CFG;
1732 : :
1733 [ # # ]: 0 : if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1734 : : return ICE_ERR_CFG;
1735 : 0 : bld->reserved_section_table_entries += count;
1736 : :
1737 : 0 : data_end = LE16_TO_CPU(buf->data_end) +
1738 : 0 : FLEX_ARRAY_SIZE(buf, section_entry, count);
1739 : 0 : buf->data_end = CPU_TO_LE16(data_end);
1740 : :
1741 : 0 : return ICE_SUCCESS;
1742 : : }
1743 : :
1744 : : /**
1745 : : * ice_pkg_buf_alloc_section
1746 : : * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1747 : : * @type: the section type value
1748 : : * @size: the size of the section to reserve (in bytes)
1749 : : *
1750 : : * Reserves memory in the buffer for a section's content and updates the
1751 : : * buffers' status accordingly. This routine returns a pointer to the first
1752 : : * byte of the section start within the buffer, which is used to fill in the
1753 : : * section contents.
1754 : : * Note: all package contents must be in Little Endian form.
1755 : : */
1756 : : void *
1757 : 0 : ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1758 : : {
1759 : : struct ice_buf_hdr *buf;
1760 : : u16 sect_count;
1761 : : u16 data_end;
1762 : :
1763 [ # # # # ]: 0 : if (!bld || !type || !size)
1764 : : return NULL;
1765 : :
1766 : 0 : buf = (struct ice_buf_hdr *)&bld->buf;
1767 : :
1768 : : /* check for enough space left in buffer */
1769 : 0 : data_end = LE16_TO_CPU(buf->data_end);
1770 : :
1771 : : /* section start must align on 4 byte boundary */
1772 : 0 : data_end = ICE_ALIGN(data_end, 4);
1773 : :
1774 [ # # ]: 0 : if ((data_end + size) > ICE_MAX_S_DATA_END)
1775 : : return NULL;
1776 : :
1777 : : /* check for more available section table entries */
1778 : 0 : sect_count = LE16_TO_CPU(buf->section_count);
1779 [ # # ]: 0 : if (sect_count < bld->reserved_section_table_entries) {
1780 : 0 : void *section_ptr = ((u8 *)buf) + data_end;
1781 : :
1782 : 0 : buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1783 : 0 : buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1784 : 0 : buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1785 : :
1786 : 0 : data_end += size;
1787 : 0 : buf->data_end = CPU_TO_LE16(data_end);
1788 : :
1789 : 0 : buf->section_count = CPU_TO_LE16(sect_count + 1);
1790 : 0 : return section_ptr;
1791 : : }
1792 : :
1793 : : /* no free section table entries */
1794 : : return NULL;
1795 : : }
1796 : :
1797 : : /**
1798 : : * ice_pkg_buf_alloc_single_section
1799 : : * @hw: pointer to the HW structure
1800 : : * @type: the section type value
1801 : : * @size: the size of the section to reserve (in bytes)
1802 : : * @section: returns pointer to the section
1803 : : *
1804 : : * Allocates a package buffer with a single section.
1805 : : * Note: all package contents must be in Little Endian form.
1806 : : */
1807 : : struct ice_buf_build *
1808 : 0 : ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size,
1809 : : void **section)
1810 : : {
1811 : : struct ice_buf_build *buf;
1812 : :
1813 [ # # ]: 0 : if (!section)
1814 : : return NULL;
1815 : :
1816 : 0 : buf = ice_pkg_buf_alloc(hw);
1817 [ # # ]: 0 : if (!buf)
1818 : : return NULL;
1819 : :
1820 [ # # ]: 0 : if (ice_pkg_buf_reserve_section(buf, 1))
1821 : 0 : goto ice_pkg_buf_alloc_single_section_err;
1822 : :
1823 : 0 : *section = ice_pkg_buf_alloc_section(buf, type, size);
1824 [ # # ]: 0 : if (!*section)
1825 : 0 : goto ice_pkg_buf_alloc_single_section_err;
1826 : :
1827 : : return buf;
1828 : :
1829 : 0 : ice_pkg_buf_alloc_single_section_err:
1830 : 0 : ice_pkg_buf_free(hw, buf);
1831 : 0 : return NULL;
1832 : : }
1833 : :
1834 : : /**
1835 : : * ice_pkg_buf_get_active_sections
1836 : : * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1837 : : *
1838 : : * Returns the number of active sections. Before using the package buffer
1839 : : * in an update package command, the caller should make sure that there is at
1840 : : * least one active section - otherwise, the buffer is not legal and should
1841 : : * not be used.
1842 : : * Note: all package contents must be in Little Endian form.
1843 : : */
1844 : 0 : u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
1845 : : {
1846 : : struct ice_buf_hdr *buf;
1847 : :
1848 [ # # ]: 0 : if (!bld)
1849 : : return 0;
1850 : :
1851 : : buf = (struct ice_buf_hdr *)&bld->buf;
1852 : 0 : return LE16_TO_CPU(buf->section_count);
1853 : : }
1854 : :
1855 : : /**
1856 : : * ice_pkg_buf
1857 : : * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1858 : : *
1859 : : * Return a pointer to the buffer's header
1860 : : */
1861 : 0 : struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
1862 : : {
1863 [ # # ]: 0 : if (bld)
1864 : 0 : return &bld->buf;
1865 : :
1866 : : return NULL;
1867 : : }
1868 : :
1869 : : /**
1870 : : * ice_find_buf_table
1871 : : * @ice_seg: pointer to the ice segment
1872 : : *
1873 : : * Returns the address of the buffer table within the ice segment.
1874 : : */
1875 : 0 : struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg)
1876 : : {
1877 : : struct ice_nvm_table *nvms;
1878 : :
1879 : 0 : nvms = (struct ice_nvm_table *)
1880 : 0 : (ice_seg->device_table +
1881 : 0 : LE32_TO_CPU(ice_seg->device_table_count));
1882 : :
1883 : 0 : return (_FORCE_ struct ice_buf_table *)
1884 : 0 : (nvms->vers + LE32_TO_CPU(nvms->table_count));
1885 : : }
1886 : :
1887 : : /**
1888 : : * ice_pkg_val_buf
1889 : : * @buf: pointer to the ice buffer
1890 : : *
1891 : : * This helper function validates a buffer's header.
1892 : : */
1893 : : static struct ice_buf_hdr *ice_pkg_val_buf(struct ice_buf *buf)
1894 : : {
1895 : : struct ice_buf_hdr *hdr;
1896 : : u16 section_count;
1897 : : u16 data_end;
1898 : :
1899 : 0 : hdr = (struct ice_buf_hdr *)buf->buf;
1900 : : /* verify data */
1901 : 0 : section_count = LE16_TO_CPU(hdr->section_count);
1902 [ # # ]: 0 : if (section_count < ICE_MIN_S_COUNT || section_count > ICE_MAX_S_COUNT)
1903 : : return NULL;
1904 : :
1905 : 0 : data_end = LE16_TO_CPU(hdr->data_end);
1906 [ # # # # : 0 : if (data_end < ICE_MIN_S_DATA_END || data_end > ICE_MAX_S_DATA_END)
# # ]
1907 : 0 : return NULL;
1908 : :
1909 : : return hdr;
1910 : : }
1911 : :
1912 : : /**
1913 : : * ice_pkg_enum_buf
1914 : : * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
1915 : : * @state: pointer to the enum state
1916 : : *
1917 : : * This function will enumerate all the buffers in the ice segment. The first
1918 : : * call is made with the ice_seg parameter non-NULL; on subsequent calls,
1919 : : * ice_seg is set to NULL which continues the enumeration. When the function
1920 : : * returns a NULL pointer, then the end of the buffers has been reached, or an
1921 : : * unexpected value has been detected (for example an invalid section count or
1922 : : * an invalid buffer end value).
1923 : : */
1924 : : struct ice_buf_hdr *
1925 : 0 : ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
1926 : : {
1927 [ # # ]: 0 : if (ice_seg) {
1928 : 0 : state->buf_table = ice_find_buf_table(ice_seg);
1929 [ # # ]: 0 : if (!state->buf_table)
1930 : : return NULL;
1931 : :
1932 [ # # ]: 0 : state->buf_idx = 0;
1933 : 0 : return ice_pkg_val_buf(state->buf_table->buf_array);
1934 : : }
1935 : :
1936 [ # # ]: 0 : if (++state->buf_idx < LE32_TO_CPU(state->buf_table->buf_count))
1937 : 0 : return ice_pkg_val_buf(state->buf_table->buf_array +
1938 [ # # ]: 0 : state->buf_idx);
1939 : : else
1940 : : return NULL;
1941 : : }
1942 : :
1943 : : /**
1944 : : * ice_pkg_advance_sect
1945 : : * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
1946 : : * @state: pointer to the enum state
1947 : : *
1948 : : * This helper function will advance the section within the ice segment,
1949 : : * also advancing the buffer if needed.
1950 : : */
1951 : : bool
1952 : 0 : ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
1953 : : {
1954 [ # # # # ]: 0 : if (!ice_seg && !state->buf)
1955 : : return false;
1956 : :
1957 [ # # # # ]: 0 : if (!ice_seg && state->buf)
1958 [ # # ]: 0 : if (++state->sect_idx < LE16_TO_CPU(state->buf->section_count))
1959 : : return true;
1960 : :
1961 : 0 : state->buf = ice_pkg_enum_buf(ice_seg, state);
1962 [ # # ]: 0 : if (!state->buf)
1963 : : return false;
1964 : :
1965 : : /* start of new buffer, reset section index */
1966 : 0 : state->sect_idx = 0;
1967 : 0 : return true;
1968 : : }
1969 : :
1970 : : /**
1971 : : * ice_pkg_enum_section
1972 : : * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
1973 : : * @state: pointer to the enum state
1974 : : * @sect_type: section type to enumerate
1975 : : *
1976 : : * This function will enumerate all the sections of a particular type in the
1977 : : * ice segment. The first call is made with the ice_seg parameter non-NULL;
1978 : : * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
1979 : : * When the function returns a NULL pointer, then the end of the matching
1980 : : * sections has been reached.
1981 : : */
1982 : : void *
1983 : 0 : ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
1984 : : u32 sect_type)
1985 : : {
1986 : : u16 offset, size;
1987 : :
1988 [ # # ]: 0 : if (ice_seg)
1989 : 0 : state->type = sect_type;
1990 : :
1991 [ # # ]: 0 : if (!ice_pkg_advance_sect(ice_seg, state))
1992 : : return NULL;
1993 : :
1994 : : /* scan for next matching section */
1995 : 0 : while (state->buf->section_entry[state->sect_idx].type !=
1996 [ # # ]: 0 : CPU_TO_LE32(state->type))
1997 [ # # ]: 0 : if (!ice_pkg_advance_sect(NULL, state))
1998 : : return NULL;
1999 : :
2000 : : /* validate section */
2001 : 0 : offset = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
2002 [ # # ]: 0 : if (offset < ICE_MIN_S_OFF || offset > ICE_MAX_S_OFF)
2003 : : return NULL;
2004 : :
2005 : 0 : size = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].size);
2006 [ # # ]: 0 : if (size < ICE_MIN_S_SZ || size > ICE_MAX_S_SZ)
2007 : : return NULL;
2008 : :
2009 : : /* make sure the section fits in the buffer */
2010 [ # # ]: 0 : if (offset + size > ICE_PKG_BUF_SIZE)
2011 : : return NULL;
2012 : :
2013 : 0 : state->sect_type =
2014 : : LE32_TO_CPU(state->buf->section_entry[state->sect_idx].type);
2015 : :
2016 : : /* calc pointer to this section */
2017 : 0 : state->sect = ((u8 *)state->buf) +
2018 : 0 : LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
2019 : :
2020 : 0 : return state->sect;
2021 : : }
2022 : :
2023 : : /**
2024 : : * ice_pkg_enum_entry
2025 : : * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
2026 : : * @state: pointer to the enum state
2027 : : * @sect_type: section type to enumerate
2028 : : * @offset: pointer to variable that receives the offset in the table (optional)
2029 : : * @handler: function that handles access to the entries into the section type
2030 : : *
2031 : : * This function will enumerate all the entries in particular section type in
2032 : : * the ice segment. The first call is made with the ice_seg parameter non-NULL;
2033 : : * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
2034 : : * When the function returns a NULL pointer, then the end of the entries has
2035 : : * been reached.
2036 : : *
2037 : : * Since each section may have a different header and entry size, the handler
2038 : : * function is needed to determine the number and location entries in each
2039 : : * section.
2040 : : *
2041 : : * The offset parameter is optional, but should be used for sections that
2042 : : * contain an offset for each section table. For such cases, the section handler
2043 : : * function must return the appropriate offset + index to give the absolution
2044 : : * offset for each entry. For example, if the base for a section's header
2045 : : * indicates a base offset of 10, and the index for the entry is 2, then
2046 : : * section handler function should set the offset to 10 + 2 = 12.
2047 : : */
2048 : : void *
2049 : 0 : ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
2050 : : u32 sect_type, u32 *offset,
2051 : : void *(*handler)(u32 sect_type, void *section,
2052 : : u32 index, u32 *offset))
2053 : : {
2054 : : void *entry;
2055 : :
2056 [ # # ]: 0 : if (ice_seg) {
2057 [ # # ]: 0 : if (!handler)
2058 : : return NULL;
2059 : :
2060 [ # # ]: 0 : if (!ice_pkg_enum_section(ice_seg, state, sect_type))
2061 : : return NULL;
2062 : :
2063 : 0 : state->entry_idx = 0;
2064 : 0 : state->handler = handler;
2065 : : } else {
2066 : 0 : state->entry_idx++;
2067 : : }
2068 : :
2069 [ # # ]: 0 : if (!state->handler)
2070 : : return NULL;
2071 : :
2072 : : /* get entry */
2073 : 0 : entry = state->handler(state->sect_type, state->sect, state->entry_idx,
2074 : : offset);
2075 [ # # ]: 0 : if (!entry) {
2076 : : /* end of a section, look for another section of this type */
2077 [ # # ]: 0 : if (!ice_pkg_enum_section(NULL, state, 0))
2078 : : return NULL;
2079 : :
2080 : 0 : state->entry_idx = 0;
2081 : 0 : entry = state->handler(state->sect_type, state->sect,
2082 : : state->entry_idx, offset);
2083 : : }
2084 : :
2085 : : return entry;
2086 : : }
2087 : :
2088 : : /**
2089 : : * ice_boost_tcam_handler
2090 : : * @sect_type: section type
2091 : : * @section: pointer to section
2092 : : * @index: index of the boost TCAM entry to be returned
2093 : : * @offset: pointer to receive absolute offset, always 0 for boost TCAM sections
2094 : : *
2095 : : * This is a callback function that can be passed to ice_pkg_enum_entry.
2096 : : * Handles enumeration of individual boost TCAM entries.
2097 : : */
2098 : : static void *
2099 : 0 : ice_boost_tcam_handler(u32 sect_type, void *section, u32 index, u32 *offset)
2100 : : {
2101 : : struct ice_boost_tcam_section *boost;
2102 : :
2103 [ # # ]: 0 : if (!section)
2104 : : return NULL;
2105 : :
2106 [ # # ]: 0 : if (sect_type != ICE_SID_RXPARSER_BOOST_TCAM)
2107 : : return NULL;
2108 : :
2109 [ # # ]: 0 : if (index > ICE_MAX_BST_TCAMS_IN_BUF)
2110 : : return NULL;
2111 : :
2112 [ # # ]: 0 : if (offset)
2113 : 0 : *offset = 0;
2114 : :
2115 : : boost = (struct ice_boost_tcam_section *)section;
2116 [ # # ]: 0 : if (index >= LE16_TO_CPU(boost->count))
2117 : : return NULL;
2118 : :
2119 : 0 : return boost->tcam + index;
2120 : : }
2121 : :
2122 : : /**
2123 : : * ice_find_boost_entry
2124 : : * @ice_seg: pointer to the ice segment (non-NULL)
2125 : : * @addr: Boost TCAM address of entry to search for
2126 : : * @entry: returns pointer to the entry
2127 : : *
2128 : : * Finds a particular Boost TCAM entry and returns a pointer to that entry
2129 : : * if it is found. The ice_seg parameter must not be NULL since the first call
2130 : : * to ice_pkg_enum_entry requires a pointer to an actual ice_segment structure.
2131 : : */
2132 : : static enum ice_status
2133 [ # # ]: 0 : ice_find_boost_entry(struct ice_seg *ice_seg, u16 addr,
2134 : : struct ice_boost_tcam_entry **entry)
2135 : : {
2136 : : struct ice_boost_tcam_entry *tcam;
2137 : : struct ice_pkg_enum state;
2138 : :
2139 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
2140 : :
2141 [ # # ]: 0 : if (!ice_seg)
2142 : : return ICE_ERR_PARAM;
2143 : :
2144 : : do {
2145 : : tcam = (struct ice_boost_tcam_entry *)
2146 : 0 : ice_pkg_enum_entry(ice_seg, &state,
2147 : : ICE_SID_RXPARSER_BOOST_TCAM, NULL,
2148 : : ice_boost_tcam_handler);
2149 [ # # # # ]: 0 : if (tcam && LE16_TO_CPU(tcam->addr) == addr) {
2150 : 0 : *entry = tcam;
2151 : 0 : return ICE_SUCCESS;
2152 : : }
2153 : :
2154 : : ice_seg = NULL;
2155 [ # # ]: 0 : } while (tcam);
2156 : :
2157 : 0 : *entry = NULL;
2158 : 0 : return ICE_ERR_CFG;
2159 : : }
2160 : :
2161 : : /**
2162 : : * ice_init_pkg_hints
2163 : : * @hw: pointer to the HW structure
2164 : : * @ice_seg: pointer to the segment of the package scan (non-NULL)
2165 : : *
2166 : : * This function will scan the package and save off relevant information
2167 : : * (hints or metadata) for driver use. The ice_seg parameter must not be NULL
2168 : : * since the first call to ice_enum_labels requires a pointer to an actual
2169 : : * ice_seg structure.
2170 : : */
2171 : 0 : void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
2172 : : {
2173 : : struct ice_pkg_enum state;
2174 : : char *label_name;
2175 : : u16 val;
2176 : : int i;
2177 : :
2178 [ # # ]: 0 : ice_memset(&hw->tnl, 0, sizeof(hw->tnl), ICE_NONDMA_MEM);
2179 : : ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
2180 : :
2181 [ # # ]: 0 : if (!ice_seg)
2182 : 0 : return;
2183 : :
2184 : : label_name = ice_enum_labels(ice_seg, ICE_SID_LBL_RXPARSER_TMEM, &state,
2185 : : &val);
2186 : :
2187 [ # # ]: 0 : while (label_name) {
2188 : : /* TODO: Replace !strnsmp() with wrappers like match_some_pre() */
2189 [ # # ]: 0 : if (!strncmp(label_name, ICE_TNL_PRE, strlen(ICE_TNL_PRE)))
2190 : : /* check for a tunnel entry */
2191 : 0 : ice_add_tunnel_hint(hw, label_name, val);
2192 : :
2193 : : /* check for a dvm mode entry */
2194 [ # # ]: 0 : else if (!strncmp(label_name, ICE_DVM_PRE, strlen(ICE_DVM_PRE)))
2195 : 0 : ice_add_dvm_hint(hw, val, true);
2196 : :
2197 : : /* check for a svm mode entry */
2198 [ # # ]: 0 : else if (!strncmp(label_name, ICE_SVM_PRE, strlen(ICE_SVM_PRE)))
2199 : 0 : ice_add_dvm_hint(hw, val, false);
2200 : :
2201 : : label_name = ice_enum_labels(NULL, 0, &state, &val);
2202 : : }
2203 : :
2204 : : /* Cache the appropriate boost TCAM entry pointers for tunnels */
2205 [ # # ]: 0 : for (i = 0; i < hw->tnl.count; i++) {
2206 : 0 : ice_find_boost_entry(ice_seg, hw->tnl.tbl[i].boost_addr,
2207 : : &hw->tnl.tbl[i].boost_entry);
2208 [ # # ]: 0 : if (hw->tnl.tbl[i].boost_entry)
2209 : 0 : hw->tnl.tbl[i].valid = true;
2210 : : }
2211 : :
2212 : : /* Cache the appropriate boost TCAM entry pointers for DVM and SVM */
2213 [ # # ]: 0 : for (i = 0; i < hw->dvm_upd.count; i++)
2214 : 0 : ice_find_boost_entry(ice_seg, hw->dvm_upd.tbl[i].boost_addr,
2215 : : &hw->dvm_upd.tbl[i].boost_entry);
2216 : : }
2217 : :
2218 : : /**
2219 : : * ice_acquire_global_cfg_lock
2220 : : * @hw: pointer to the HW structure
2221 : : * @access: access type (read or write)
2222 : : *
2223 : : * This function will request ownership of the global config lock for reading
2224 : : * or writing of the package. When attempting to obtain write access, the
2225 : : * caller must check for the following two return values:
2226 : : *
2227 : : * ICE_SUCCESS - Means the caller has acquired the global config lock
2228 : : * and can perform writing of the package.
2229 : : * ICE_ERR_AQ_NO_WORK - Indicates another driver has already written the
2230 : : * package or has found that no update was necessary; in
2231 : : * this case, the caller can just skip performing any
2232 : : * update of the package.
2233 : : */
2234 : : enum ice_status
2235 : 0 : ice_acquire_global_cfg_lock(struct ice_hw *hw,
2236 : : enum ice_aq_res_access_type access)
2237 : : {
2238 : : enum ice_status status;
2239 : :
2240 : 0 : status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, access,
2241 : : ICE_GLOBAL_CFG_LOCK_TIMEOUT);
2242 : :
2243 [ # # ]: 0 : if (status == ICE_ERR_AQ_NO_WORK)
2244 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PKG, "Global config lock: No work to do\n");
2245 : :
2246 : 0 : return status;
2247 : : }
2248 : :
2249 : : /**
2250 : : * ice_release_global_cfg_lock
2251 : : * @hw: pointer to the HW structure
2252 : : *
2253 : : * This function will release the global config lock.
2254 : : */
2255 : 0 : void ice_release_global_cfg_lock(struct ice_hw *hw)
2256 : : {
2257 : 0 : ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
2258 : 0 : }
2259 : :
2260 : : /**
2261 : : * ice_acquire_change_lock
2262 : : * @hw: pointer to the HW structure
2263 : : * @access: access type (read or write)
2264 : : *
2265 : : * This function will request ownership of the change lock.
2266 : : */
2267 : : enum ice_status
2268 : 0 : ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
2269 : : {
2270 : 0 : return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
2271 : : ICE_CHANGE_LOCK_TIMEOUT);
2272 : : }
2273 : :
2274 : : /**
2275 : : * ice_release_change_lock
2276 : : * @hw: pointer to the HW structure
2277 : : *
2278 : : * This function will release the change lock using the proper Admin Command.
2279 : : */
2280 : 0 : void ice_release_change_lock(struct ice_hw *hw)
2281 : : {
2282 : 0 : ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
2283 : 0 : }
2284 : :
2285 : : /**
2286 : : * ice_get_set_tx_topo - get or set tx topology
2287 : : * @hw: pointer to the HW struct
2288 : : * @buf: pointer to tx topology buffer
2289 : : * @buf_size: buffer size
2290 : : * @cd: pointer to command details structure or NULL
2291 : : * @flags: pointer to descriptor flags
2292 : : * @set: 0-get, 1-set topology
2293 : : *
2294 : : * The function will get or set tx topology
2295 : : */
2296 : : static enum ice_status
2297 : 0 : ice_get_set_tx_topo(struct ice_hw *hw, u8 *buf, u16 buf_size,
2298 : : struct ice_sq_cd *cd, u8 *flags, bool set)
2299 : : {
2300 : : struct ice_aqc_get_set_tx_topo *cmd;
2301 : : struct ice_aq_desc desc;
2302 : : enum ice_status status;
2303 : :
2304 : : cmd = &desc.params.get_set_tx_topo;
2305 [ # # ]: 0 : if (set) {
2306 : 0 : ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_tx_topo);
2307 : 0 : cmd->set_flags = ICE_AQC_TX_TOPO_FLAGS_ISSUED;
2308 : : /* requested to update a new topology, not a default topolgy */
2309 [ # # ]: 0 : if (buf)
2310 : 0 : cmd->set_flags |= ICE_AQC_TX_TOPO_FLAGS_SRC_RAM |
2311 : : ICE_AQC_TX_TOPO_FLAGS_LOAD_NEW;
2312 : : } else {
2313 : 0 : ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_tx_topo);
2314 : 0 : cmd->get_flags = ICE_AQC_TX_TOPO_GET_RAM;
2315 : : }
2316 : 0 : desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
2317 : 0 : status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2318 [ # # ]: 0 : if (status)
2319 : : return status;
2320 : : /* read the return flag values (first byte) for get operation */
2321 [ # # ]: 0 : if (!set && flags)
2322 : 0 : *flags = desc.params.get_set_tx_topo.set_flags;
2323 : :
2324 : : return ICE_SUCCESS;
2325 : : }
2326 : :
2327 : : /**
2328 : : * ice_cfg_tx_topo - Initialize new tx topology if available
2329 : : * @hw: pointer to the HW struct
2330 : : * @buf: pointer to Tx topology buffer
2331 : : * @len: buffer size
2332 : : *
2333 : : * The function will apply the new Tx topology from the package buffer
2334 : : * if available.
2335 : : */
2336 : 0 : enum ice_status ice_cfg_tx_topo(struct ice_hw *hw, u8 *buf, u32 len)
2337 : : {
2338 : : u8 *current_topo, *new_topo = NULL;
2339 : : struct ice_run_time_cfg_seg *seg;
2340 : : struct ice_buf_hdr *section;
2341 : : struct ice_pkg_hdr *pkg_hdr;
2342 : : enum ice_ddp_state state;
2343 : : u16 i, size = 0, offset;
2344 : : enum ice_status status;
2345 : : u32 reg = 0;
2346 : : u8 flags;
2347 : :
2348 [ # # ]: 0 : if (!buf || !len)
2349 : : return ICE_ERR_PARAM;
2350 : :
2351 : : /* Does FW support new Tx topology mode ? */
2352 [ # # ]: 0 : if (!hw->func_caps.common_cap.tx_sched_topo_comp_mode_en) {
2353 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "FW doesn't support compatibility mode\n");
2354 : 0 : return ICE_ERR_NOT_SUPPORTED;
2355 : : }
2356 : :
2357 : 0 : current_topo = (u8 *)ice_malloc(hw, ICE_AQ_MAX_BUF_LEN);
2358 [ # # ]: 0 : if (!current_topo)
2359 : : return ICE_ERR_NO_MEMORY;
2360 : :
2361 : : /* get the current Tx topology */
2362 : 0 : status = ice_get_set_tx_topo(hw, current_topo, ICE_AQ_MAX_BUF_LEN, NULL,
2363 : : &flags, false);
2364 : 0 : ice_free(hw, current_topo);
2365 : :
2366 [ # # ]: 0 : if (status) {
2367 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Get current topology is failed\n");
2368 : 0 : return status;
2369 : : }
2370 : :
2371 : : /* Is default topology already applied ? */
2372 [ # # ]: 0 : if (!(flags & ICE_AQC_TX_TOPO_FLAGS_LOAD_NEW) &&
2373 [ # # ]: 0 : hw->num_tx_sched_layers == 9) {
2374 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Loaded default topology\n");
2375 : : /* Already default topology is loaded */
2376 : 0 : return ICE_ERR_ALREADY_EXISTS;
2377 : : }
2378 : :
2379 : : /* Is new topology already applied ? */
2380 [ # # ]: 0 : if ((flags & ICE_AQC_TX_TOPO_FLAGS_LOAD_NEW) &&
2381 [ # # ]: 0 : hw->num_tx_sched_layers == 5) {
2382 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Loaded new topology\n");
2383 : : /* Already new topology is loaded */
2384 : 0 : return ICE_ERR_ALREADY_EXISTS;
2385 : : }
2386 : :
2387 : : /* Is set topology issued already ? */
2388 [ # # ]: 0 : if (flags & ICE_AQC_TX_TOPO_FLAGS_ISSUED) {
2389 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Update tx topology was done by another PF\n");
2390 : : /* add a small delay before exiting */
2391 [ # # ]: 0 : for (i = 0; i < 20; i++)
2392 : 0 : ice_msec_delay(100, true);
2393 : : return ICE_ERR_ALREADY_EXISTS;
2394 : : }
2395 : :
2396 : : /* Change the topology from new to default (5 to 9) */
2397 [ # # ]: 0 : if (!(flags & ICE_AQC_TX_TOPO_FLAGS_LOAD_NEW) &&
2398 [ # # ]: 0 : hw->num_tx_sched_layers == 5) {
2399 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Change topology from 5 to 9 layers\n");
2400 : 0 : goto update_topo;
2401 : : }
2402 : :
2403 : : pkg_hdr = (struct ice_pkg_hdr *)buf;
2404 : 0 : state = ice_verify_pkg(pkg_hdr, len);
2405 [ # # ]: 0 : if (state) {
2406 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
2407 : : state);
2408 : 0 : return ICE_ERR_CFG;
2409 : : }
2410 : :
2411 : : /* find run time configuration segment */
2412 : : seg = (struct ice_run_time_cfg_seg *)
2413 : 0 : ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE_RUN_TIME_CFG, pkg_hdr);
2414 [ # # ]: 0 : if (!seg) {
2415 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "5 layer topology segment is missing\n");
2416 : 0 : return ICE_ERR_CFG;
2417 : : }
2418 : :
2419 [ # # ]: 0 : if (LE32_TO_CPU(seg->buf_table.buf_count) < ICE_MIN_S_COUNT) {
2420 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "5 layer topology segment count(%d) is wrong\n",
2421 : : seg->buf_table.buf_count);
2422 : 0 : return ICE_ERR_CFG;
2423 : : }
2424 : :
2425 : : section = ice_pkg_val_buf(seg->buf_table.buf_array);
2426 : :
2427 [ # # ]: 0 : if (!section || LE32_TO_CPU(section->section_entry[0].type) !=
2428 : : ICE_SID_TX_5_LAYER_TOPO) {
2429 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "5 layer topology section type is wrong\n");
2430 : 0 : return ICE_ERR_CFG;
2431 : : }
2432 : :
2433 : 0 : size = LE16_TO_CPU(section->section_entry[0].size);
2434 : 0 : offset = LE16_TO_CPU(section->section_entry[0].offset);
2435 [ # # ]: 0 : if (size < ICE_MIN_S_SZ || size > ICE_MAX_S_SZ) {
2436 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "5 layer topology section size is wrong\n");
2437 : 0 : return ICE_ERR_CFG;
2438 : : }
2439 : :
2440 : : /* make sure the section fits in the buffer */
2441 [ # # ]: 0 : if (offset + size > ICE_PKG_BUF_SIZE) {
2442 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "5 layer topology buffer > 4K\n");
2443 : 0 : return ICE_ERR_CFG;
2444 : : }
2445 : :
2446 : : /* Get the new topology buffer */
2447 : 0 : new_topo = ((u8 *)section) + offset;
2448 : :
2449 : 0 : update_topo:
2450 : : /* acquire global lock to make sure that set topology issued
2451 : : * by one PF
2452 : : */
2453 : 0 : status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, ICE_RES_WRITE,
2454 : : ICE_GLOBAL_CFG_LOCK_TIMEOUT);
2455 [ # # ]: 0 : if (status) {
2456 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Failed to acquire global lock\n");
2457 : 0 : return status;
2458 : : }
2459 : :
2460 : : /* check reset was triggered already or not */
2461 : 0 : reg = rd32(hw, GLGEN_RSTAT);
2462 [ # # ]: 0 : if (reg & GLGEN_RSTAT_DEVSTATE_M) {
2463 : : /* Reset is in progress, re-init the hw again */
2464 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Reset is in progress. layer topology might be applied already\n");
2465 : 0 : ice_check_reset(hw);
2466 : 0 : return ICE_SUCCESS;
2467 : : }
2468 : :
2469 : : /* set new topology */
2470 : 0 : status = ice_get_set_tx_topo(hw, new_topo, size, NULL, NULL, true);
2471 [ # # ]: 0 : if (status) {
2472 [ # # ]: 0 : ice_debug(hw, ICE_DBG_INIT, "Set tx topology is failed\n");
2473 : 0 : return status;
2474 : : }
2475 : :
2476 : : /* new topology is updated, delay 1 second before issuing the CORRER */
2477 [ # # ]: 0 : for (i = 0; i < 10; i++)
2478 : 0 : ice_msec_delay(100, true);
2479 : 0 : ice_reset(hw, ICE_RESET_CORER);
2480 : : /* CORER will clear the global lock, so no explicit call
2481 : : * required for release
2482 : : */
2483 : 0 : return ICE_SUCCESS;
2484 : : }
|