@@ -1002,9 +1002,9 @@ static void ice_get_itr_intrl_gran(struct ice_hw *hw)
10021002 */
10031003int ice_init_hw (struct ice_hw * hw )
10041004{
1005- struct ice_aqc_get_phy_caps_data * pcaps ;
1005+ struct ice_aqc_get_phy_caps_data * pcaps __free (kfree );
1006+ void * mac_buf __free (kfree );
10061007 u16 mac_buf_len ;
1007- void * mac_buf ;
10081008 int status ;
10091009
10101010 /* Set MAC type based on DeviceID */
@@ -1082,7 +1082,7 @@ int ice_init_hw(struct ice_hw *hw)
10821082 if (status )
10831083 goto err_unroll_sched ;
10841084
1085- pcaps = devm_kzalloc ( ice_hw_to_dev ( hw ), sizeof (* pcaps ), GFP_KERNEL );
1085+ pcaps = kzalloc ( sizeof (* pcaps ), GFP_KERNEL );
10861086 if (!pcaps ) {
10871087 status = - ENOMEM ;
10881088 goto err_unroll_sched ;
@@ -1092,7 +1092,6 @@ int ice_init_hw(struct ice_hw *hw)
10921092 status = ice_aq_get_phy_caps (hw -> port_info , false,
10931093 ICE_AQC_REPORT_TOPO_CAP_MEDIA , pcaps ,
10941094 NULL );
1095- devm_kfree (ice_hw_to_dev (hw ), pcaps );
10961095 if (status )
10971096 dev_warn (ice_hw_to_dev (hw ), "Get PHY capabilities failed status = %d, continuing anyway\n" ,
10981097 status );
@@ -1119,18 +1118,15 @@ int ice_init_hw(struct ice_hw *hw)
11191118
11201119 /* Get MAC information */
11211120 /* A single port can report up to two (LAN and WoL) addresses */
1122- mac_buf = devm_kcalloc (ice_hw_to_dev (hw ), 2 ,
1123- sizeof (struct ice_aqc_manage_mac_read_resp ),
1124- GFP_KERNEL );
1125- mac_buf_len = 2 * sizeof (struct ice_aqc_manage_mac_read_resp );
1126-
1121+ mac_buf = kcalloc (2 , sizeof (struct ice_aqc_manage_mac_read_resp ),
1122+ GFP_KERNEL );
11271123 if (!mac_buf ) {
11281124 status = - ENOMEM ;
11291125 goto err_unroll_fltr_mgmt_struct ;
11301126 }
11311127
1128+ mac_buf_len = 2 * sizeof (struct ice_aqc_manage_mac_read_resp );
11321129 status = ice_aq_manage_mac_read (hw , mac_buf , mac_buf_len , NULL );
1133- devm_kfree (ice_hw_to_dev (hw ), mac_buf );
11341130
11351131 if (status )
11361132 goto err_unroll_fltr_mgmt_struct ;
@@ -1399,9 +1395,8 @@ static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
13991395 * it to HW register space and enables the hardware to prefetch descriptors
14001396 * instead of only fetching them on demand
14011397 */
1402- int
1403- ice_write_rxq_ctx (struct ice_hw * hw , struct ice_rlan_ctx * rlan_ctx ,
1404- u32 rxq_index )
1398+ int ice_write_rxq_ctx (struct ice_hw * hw , struct ice_rlan_ctx * rlan_ctx ,
1399+ u32 rxq_index )
14051400{
14061401 u8 ctx_buf [ICE_RXQ_CTX_SZ ] = { 0 };
14071402
@@ -3277,19 +3272,14 @@ int ice_update_link_info(struct ice_port_info *pi)
32773272 return status ;
32783273
32793274 if (li -> link_info & ICE_AQ_MEDIA_AVAILABLE ) {
3280- struct ice_aqc_get_phy_caps_data * pcaps ;
3281- struct ice_hw * hw ;
3275+ struct ice_aqc_get_phy_caps_data * pcaps __free (kfree );
32823276
3283- hw = pi -> hw ;
3284- pcaps = devm_kzalloc (ice_hw_to_dev (hw ), sizeof (* pcaps ),
3285- GFP_KERNEL );
3277+ pcaps = kzalloc (sizeof (* pcaps ), GFP_KERNEL );
32863278 if (!pcaps )
32873279 return - ENOMEM ;
32883280
32893281 status = ice_aq_get_phy_caps (pi , false, ICE_AQC_REPORT_TOPO_CAP_MEDIA ,
32903282 pcaps , NULL );
3291-
3292- devm_kfree (ice_hw_to_dev (hw ), pcaps );
32933283 }
32943284
32953285 return status ;
@@ -3430,8 +3420,8 @@ ice_cfg_phy_fc(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
34303420int
34313421ice_set_fc (struct ice_port_info * pi , u8 * aq_failures , bool ena_auto_link_update )
34323422{
3423+ struct ice_aqc_get_phy_caps_data * pcaps __free (kfree );
34333424 struct ice_aqc_set_phy_cfg_data cfg = { 0 };
3434- struct ice_aqc_get_phy_caps_data * pcaps ;
34353425 struct ice_hw * hw ;
34363426 int status ;
34373427
@@ -3441,7 +3431,7 @@ ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
34413431 * aq_failures = 0 ;
34423432 hw = pi -> hw ;
34433433
3444- pcaps = devm_kzalloc ( ice_hw_to_dev ( hw ), sizeof (* pcaps ), GFP_KERNEL );
3434+ pcaps = kzalloc ( sizeof (* pcaps ), GFP_KERNEL );
34453435 if (!pcaps )
34463436 return - ENOMEM ;
34473437
@@ -3493,7 +3483,6 @@ ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
34933483 }
34943484
34953485out :
3496- devm_kfree (ice_hw_to_dev (hw ), pcaps );
34973486 return status ;
34983487}
34993488
@@ -3572,7 +3561,7 @@ int
35723561ice_cfg_phy_fec (struct ice_port_info * pi , struct ice_aqc_set_phy_cfg_data * cfg ,
35733562 enum ice_fec_mode fec )
35743563{
3575- struct ice_aqc_get_phy_caps_data * pcaps ;
3564+ struct ice_aqc_get_phy_caps_data * pcaps __free ( kfree ) ;
35763565 struct ice_hw * hw ;
35773566 int status ;
35783567
@@ -3641,8 +3630,6 @@ ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
36413630 }
36423631
36433632out :
3644- kfree (pcaps );
3645-
36463633 return status ;
36473634}
36483635
@@ -4362,13 +4349,13 @@ ice_aq_add_rdma_qsets(struct ice_hw *hw, u8 num_qset_grps,
43624349/* End of FW Admin Queue command wrappers */
43634350
43644351/**
4365- * ice_write_byte - write a byte to a packed context structure
4366- * @src_ctx: the context structure to read from
4367- * @dest_ctx: the context to be written to
4368- * @ce_info: a description of the struct to be filled
4352+ * ice_pack_ctx_byte - write a byte to a packed context structure
4353+ * @src_ctx: unpacked source context structure
4354+ * @dest_ctx: packed destination context data
4355+ * @ce_info: context element description
43694356 */
4370- static void
4371- ice_write_byte ( u8 * src_ctx , u8 * dest_ctx , const struct ice_ctx_ele * ce_info )
4357+ static void ice_pack_ctx_byte ( u8 * src_ctx , u8 * dest_ctx ,
4358+ const struct ice_ctx_ele * ce_info )
43724359{
43734360 u8 src_byte , dest_byte , mask ;
43744361 u8 * from , * dest ;
@@ -4379,14 +4366,11 @@ ice_write_byte(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
43794366
43804367 /* prepare the bits and mask */
43814368 shift_width = ce_info -> lsb % 8 ;
4382- mask = ( u8 )( BIT ( ce_info -> width ) - 1 );
4369+ mask = GENMASK ( ce_info -> width - 1 + shift_width , shift_width );
43834370
43844371 src_byte = * from ;
4385- src_byte &= mask ;
4386-
4387- /* shift to correct alignment */
4388- mask <<= shift_width ;
43894372 src_byte <<= shift_width ;
4373+ src_byte &= mask ;
43904374
43914375 /* get the current bits from the target bit string */
43924376 dest = dest_ctx + (ce_info -> lsb / 8 );
@@ -4401,13 +4385,13 @@ ice_write_byte(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
44014385}
44024386
44034387/**
4404- * ice_write_word - write a word to a packed context structure
4405- * @src_ctx: the context structure to read from
4406- * @dest_ctx: the context to be written to
4407- * @ce_info: a description of the struct to be filled
4388+ * ice_pack_ctx_word - write a word to a packed context structure
4389+ * @src_ctx: unpacked source context structure
4390+ * @dest_ctx: packed destination context data
4391+ * @ce_info: context element description
44084392 */
4409- static void
4410- ice_write_word ( u8 * src_ctx , u8 * dest_ctx , const struct ice_ctx_ele * ce_info )
4393+ static void ice_pack_ctx_word ( u8 * src_ctx , u8 * dest_ctx ,
4394+ const struct ice_ctx_ele * ce_info )
44114395{
44124396 u16 src_word , mask ;
44134397 __le16 dest_word ;
@@ -4419,17 +4403,14 @@ ice_write_word(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
44194403
44204404 /* prepare the bits and mask */
44214405 shift_width = ce_info -> lsb % 8 ;
4422- mask = BIT (ce_info -> width ) - 1 ;
4406+ mask = GENMASK (ce_info -> width - 1 + shift_width , shift_width ) ;
44234407
44244408 /* don't swizzle the bits until after the mask because the mask bits
44254409 * will be in a different bit position on big endian machines
44264410 */
44274411 src_word = * (u16 * )from ;
4428- src_word &= mask ;
4429-
4430- /* shift to correct alignment */
4431- mask <<= shift_width ;
44324412 src_word <<= shift_width ;
4413+ src_word &= mask ;
44334414
44344415 /* get the current bits from the target bit string */
44354416 dest = dest_ctx + (ce_info -> lsb / 8 );
@@ -4444,13 +4425,13 @@ ice_write_word(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
44444425}
44454426
44464427/**
4447- * ice_write_dword - write a dword to a packed context structure
4448- * @src_ctx: the context structure to read from
4449- * @dest_ctx: the context to be written to
4450- * @ce_info: a description of the struct to be filled
4428+ * ice_pack_ctx_dword - write a dword to a packed context structure
4429+ * @src_ctx: unpacked source context structure
4430+ * @dest_ctx: packed destination context data
4431+ * @ce_info: context element description
44514432 */
4452- static void
4453- ice_write_dword ( u8 * src_ctx , u8 * dest_ctx , const struct ice_ctx_ele * ce_info )
4433+ static void ice_pack_ctx_dword ( u8 * src_ctx , u8 * dest_ctx ,
4434+ const struct ice_ctx_ele * ce_info )
44544435{
44554436 u32 src_dword , mask ;
44564437 __le32 dest_dword ;
@@ -4462,25 +4443,14 @@ ice_write_dword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
44624443
44634444 /* prepare the bits and mask */
44644445 shift_width = ce_info -> lsb % 8 ;
4465-
4466- /* if the field width is exactly 32 on an x86 machine, then the shift
4467- * operation will not work because the SHL instructions count is masked
4468- * to 5 bits so the shift will do nothing
4469- */
4470- if (ce_info -> width < 32 )
4471- mask = BIT (ce_info -> width ) - 1 ;
4472- else
4473- mask = (u32 )~0 ;
4446+ mask = GENMASK (ce_info -> width - 1 + shift_width , shift_width );
44744447
44754448 /* don't swizzle the bits until after the mask because the mask bits
44764449 * will be in a different bit position on big endian machines
44774450 */
44784451 src_dword = * (u32 * )from ;
4479- src_dword &= mask ;
4480-
4481- /* shift to correct alignment */
4482- mask <<= shift_width ;
44834452 src_dword <<= shift_width ;
4453+ src_dword &= mask ;
44844454
44854455 /* get the current bits from the target bit string */
44864456 dest = dest_ctx + (ce_info -> lsb / 8 );
@@ -4495,13 +4465,13 @@ ice_write_dword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
44954465}
44964466
44974467/**
4498- * ice_write_qword - write a qword to a packed context structure
4499- * @src_ctx: the context structure to read from
4500- * @dest_ctx: the context to be written to
4501- * @ce_info: a description of the struct to be filled
4468+ * ice_pack_ctx_qword - write a qword to a packed context structure
4469+ * @src_ctx: unpacked source context structure
4470+ * @dest_ctx: packed destination context data
4471+ * @ce_info: context element description
45024472 */
4503- static void
4504- ice_write_qword ( u8 * src_ctx , u8 * dest_ctx , const struct ice_ctx_ele * ce_info )
4473+ static void ice_pack_ctx_qword ( u8 * src_ctx , u8 * dest_ctx ,
4474+ const struct ice_ctx_ele * ce_info )
45054475{
45064476 u64 src_qword , mask ;
45074477 __le64 dest_qword ;
@@ -4513,25 +4483,14 @@ ice_write_qword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
45134483
45144484 /* prepare the bits and mask */
45154485 shift_width = ce_info -> lsb % 8 ;
4516-
4517- /* if the field width is exactly 64 on an x86 machine, then the shift
4518- * operation will not work because the SHL instructions count is masked
4519- * to 6 bits so the shift will do nothing
4520- */
4521- if (ce_info -> width < 64 )
4522- mask = BIT_ULL (ce_info -> width ) - 1 ;
4523- else
4524- mask = (u64 )~0 ;
4486+ mask = GENMASK_ULL (ce_info -> width - 1 + shift_width , shift_width );
45254487
45264488 /* don't swizzle the bits until after the mask because the mask bits
45274489 * will be in a different bit position on big endian machines
45284490 */
45294491 src_qword = * (u64 * )from ;
4530- src_qword &= mask ;
4531-
4532- /* shift to correct alignment */
4533- mask <<= shift_width ;
45344492 src_qword <<= shift_width ;
4493+ src_qword &= mask ;
45354494
45364495 /* get the current bits from the target bit string */
45374496 dest = dest_ctx + (ce_info -> lsb / 8 );
@@ -4550,11 +4509,10 @@ ice_write_qword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
45504509 * @hw: pointer to the hardware structure
45514510 * @src_ctx: pointer to a generic non-packed context structure
45524511 * @dest_ctx: pointer to memory for the packed structure
4553- * @ce_info: a description of the structure to be transformed
4512+ * @ce_info: List of Rx context elements
45544513 */
4555- int
4556- ice_set_ctx (struct ice_hw * hw , u8 * src_ctx , u8 * dest_ctx ,
4557- const struct ice_ctx_ele * ce_info )
4514+ int ice_set_ctx (struct ice_hw * hw , u8 * src_ctx , u8 * dest_ctx ,
4515+ const struct ice_ctx_ele * ce_info )
45584516{
45594517 int f ;
45604518
@@ -4570,16 +4528,16 @@ ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx,
45704528 }
45714529 switch (ce_info [f ].size_of ) {
45724530 case sizeof (u8 ):
4573- ice_write_byte (src_ctx , dest_ctx , & ce_info [f ]);
4531+ ice_pack_ctx_byte (src_ctx , dest_ctx , & ce_info [f ]);
45744532 break ;
45754533 case sizeof (u16 ):
4576- ice_write_word (src_ctx , dest_ctx , & ce_info [f ]);
4534+ ice_pack_ctx_word (src_ctx , dest_ctx , & ce_info [f ]);
45774535 break ;
45784536 case sizeof (u32 ):
4579- ice_write_dword (src_ctx , dest_ctx , & ce_info [f ]);
4537+ ice_pack_ctx_dword (src_ctx , dest_ctx , & ce_info [f ]);
45804538 break ;
45814539 case sizeof (u64 ):
4582- ice_write_qword (src_ctx , dest_ctx , & ce_info [f ]);
4540+ ice_pack_ctx_qword (src_ctx , dest_ctx , & ce_info [f ]);
45834541 break ;
45844542 default :
45854543 return - EINVAL ;
0 commit comments