@@ -1261,6 +1261,201 @@ void ice_clear_pxe_mode(struct ice_hw *hw)
12611261 ice_aq_clear_pxe_mode (hw );
12621262}
12631263
1264+ /**
1265+ * ice_aq_set_phy_cfg
1266+ * @hw: pointer to the hw struct
1267+ * @lport: logical port number
1268+ * @cfg: structure with PHY configuration data to be set
1269+ * @cd: pointer to command details structure or NULL
1270+ *
1271+ * Set the various PHY configuration parameters supported on the Port.
1272+ * One or more of the Set PHY config parameters may be ignored in an MFP
1273+ * mode as the PF may not have the privilege to set some of the PHY Config
1274+ * parameters. This status will be indicated by the command response (0x0601).
1275+ */
1276+ static enum ice_status
1277+ ice_aq_set_phy_cfg (struct ice_hw * hw , u8 lport ,
1278+ struct ice_aqc_set_phy_cfg_data * cfg , struct ice_sq_cd * cd )
1279+ {
1280+ struct ice_aqc_set_phy_cfg * cmd ;
1281+ struct ice_aq_desc desc ;
1282+
1283+ if (!cfg )
1284+ return ICE_ERR_PARAM ;
1285+
1286+ cmd = & desc .params .set_phy ;
1287+ ice_fill_dflt_direct_cmd_desc (& desc , ice_aqc_opc_set_phy_cfg );
1288+ cmd -> lport_num = lport ;
1289+
1290+ return ice_aq_send_cmd (hw , & desc , cfg , sizeof (* cfg ), cd );
1291+ }
1292+
1293+ /**
1294+ * ice_update_link_info - update status of the HW network link
1295+ * @pi: port info structure of the interested logical port
1296+ */
1297+ static enum ice_status
1298+ ice_update_link_info (struct ice_port_info * pi )
1299+ {
1300+ struct ice_aqc_get_phy_caps_data * pcaps ;
1301+ struct ice_phy_info * phy_info ;
1302+ enum ice_status status ;
1303+ struct ice_hw * hw ;
1304+
1305+ if (!pi )
1306+ return ICE_ERR_PARAM ;
1307+
1308+ hw = pi -> hw ;
1309+
1310+ pcaps = devm_kzalloc (ice_hw_to_dev (hw ), sizeof (* pcaps ), GFP_KERNEL );
1311+ if (!pcaps )
1312+ return ICE_ERR_NO_MEMORY ;
1313+
1314+ phy_info = & pi -> phy ;
1315+ status = ice_aq_get_link_info (pi , true, NULL , NULL );
1316+ if (status )
1317+ goto out ;
1318+
1319+ if (phy_info -> link_info .link_info & ICE_AQ_MEDIA_AVAILABLE ) {
1320+ status = ice_aq_get_phy_caps (pi , false, ICE_AQC_REPORT_SW_CFG ,
1321+ pcaps , NULL );
1322+ if (status )
1323+ goto out ;
1324+
1325+ memcpy (phy_info -> link_info .module_type , & pcaps -> module_type ,
1326+ sizeof (phy_info -> link_info .module_type ));
1327+ }
1328+ out :
1329+ devm_kfree (ice_hw_to_dev (hw ), pcaps );
1330+ return status ;
1331+ }
1332+
1333+ /**
1334+ * ice_set_fc
1335+ * @pi: port information structure
1336+ * @aq_failures: pointer to status code, specific to ice_set_fc routine
1337+ * @atomic_restart: enable automatic link update
1338+ *
1339+ * Set the requested flow control mode.
1340+ */
1341+ enum ice_status
1342+ ice_set_fc (struct ice_port_info * pi , u8 * aq_failures , bool atomic_restart )
1343+ {
1344+ struct ice_aqc_set_phy_cfg_data cfg = { 0 };
1345+ struct ice_aqc_get_phy_caps_data * pcaps ;
1346+ enum ice_status status ;
1347+ u8 pause_mask = 0x0 ;
1348+ struct ice_hw * hw ;
1349+
1350+ if (!pi )
1351+ return ICE_ERR_PARAM ;
1352+ hw = pi -> hw ;
1353+ * aq_failures = ICE_SET_FC_AQ_FAIL_NONE ;
1354+
1355+ switch (pi -> fc .req_mode ) {
1356+ case ICE_FC_FULL :
1357+ pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE ;
1358+ pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE ;
1359+ break ;
1360+ case ICE_FC_RX_PAUSE :
1361+ pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE ;
1362+ break ;
1363+ case ICE_FC_TX_PAUSE :
1364+ pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE ;
1365+ break ;
1366+ default :
1367+ break ;
1368+ }
1369+
1370+ pcaps = devm_kzalloc (ice_hw_to_dev (hw ), sizeof (* pcaps ), GFP_KERNEL );
1371+ if (!pcaps )
1372+ return ICE_ERR_NO_MEMORY ;
1373+
1374+ /* Get the current phy config */
1375+ status = ice_aq_get_phy_caps (pi , false, ICE_AQC_REPORT_SW_CFG , pcaps ,
1376+ NULL );
1377+ if (status ) {
1378+ * aq_failures = ICE_SET_FC_AQ_FAIL_GET ;
1379+ goto out ;
1380+ }
1381+
1382+ /* clear the old pause settings */
1383+ cfg .caps = pcaps -> caps & ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
1384+ ICE_AQC_PHY_EN_RX_LINK_PAUSE );
1385+ /* set the new capabilities */
1386+ cfg .caps |= pause_mask ;
1387+ /* If the capabilities have changed, then set the new config */
1388+ if (cfg .caps != pcaps -> caps ) {
1389+ int retry_count , retry_max = 10 ;
1390+
1391+ /* Auto restart link so settings take effect */
1392+ if (atomic_restart )
1393+ cfg .caps |= ICE_AQ_PHY_ENA_ATOMIC_LINK ;
1394+ /* Copy over all the old settings */
1395+ cfg .phy_type_low = pcaps -> phy_type_low ;
1396+ cfg .low_power_ctrl = pcaps -> low_power_ctrl ;
1397+ cfg .eee_cap = pcaps -> eee_cap ;
1398+ cfg .eeer_value = pcaps -> eeer_value ;
1399+ cfg .link_fec_opt = pcaps -> link_fec_options ;
1400+
1401+ status = ice_aq_set_phy_cfg (hw , pi -> lport , & cfg , NULL );
1402+ if (status ) {
1403+ * aq_failures = ICE_SET_FC_AQ_FAIL_SET ;
1404+ goto out ;
1405+ }
1406+
1407+ /* Update the link info
1408+ * It sometimes takes a really long time for link to
1409+ * come back from the atomic reset. Thus, we wait a
1410+ * little bit.
1411+ */
1412+ for (retry_count = 0 ; retry_count < retry_max ; retry_count ++ ) {
1413+ status = ice_update_link_info (pi );
1414+
1415+ if (!status )
1416+ break ;
1417+
1418+ mdelay (100 );
1419+ }
1420+
1421+ if (status )
1422+ * aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE ;
1423+ }
1424+
1425+ out :
1426+ devm_kfree (ice_hw_to_dev (hw ), pcaps );
1427+ return status ;
1428+ }
1429+
1430+ /**
1431+ * ice_aq_set_link_restart_an
1432+ * @pi: pointer to the port information structure
1433+ * @ena_link: if true: enable link, if false: disable link
1434+ * @cd: pointer to command details structure or NULL
1435+ *
1436+ * Sets up the link and restarts the Auto-Negotiation over the link.
1437+ */
1438+ enum ice_status
1439+ ice_aq_set_link_restart_an (struct ice_port_info * pi , bool ena_link ,
1440+ struct ice_sq_cd * cd )
1441+ {
1442+ struct ice_aqc_restart_an * cmd ;
1443+ struct ice_aq_desc desc ;
1444+
1445+ cmd = & desc .params .restart_an ;
1446+
1447+ ice_fill_dflt_direct_cmd_desc (& desc , ice_aqc_opc_restart_an );
1448+
1449+ cmd -> cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART ;
1450+ cmd -> lport_num = pi -> lport ;
1451+ if (ena_link )
1452+ cmd -> cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE ;
1453+ else
1454+ cmd -> cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE ;
1455+
1456+ return ice_aq_send_cmd (pi -> hw , & desc , NULL , 0 , cd );
1457+ }
1458+
12641459/**
12651460 * __ice_aq_get_set_rss_lut
12661461 * @hw: pointer to the hardware structure
0 commit comments