···932932 return 0;933933}934934935935+/*936936+ * Takes whatever value which is in pkey index 0 and updates priv->pkey937937+ * returns 0 if the pkey value was changed.938938+ */939939+static inline int update_parent_pkey(struct ipoib_dev_priv *priv)940940+{941941+ int result;942942+ u16 prev_pkey;943943+944944+ prev_pkey = priv->pkey;945945+ result = ib_query_pkey(priv->ca, priv->port, 0, &priv->pkey);946946+ if (result) {947947+ ipoib_warn(priv, "ib_query_pkey port %d failed (ret = %d)\n",948948+ priv->port, result);949949+ return result;950950+ }951951+952952+ priv->pkey |= 0x8000;953953+954954+ if (prev_pkey != priv->pkey) {955955+ ipoib_dbg(priv, "pkey changed from 0x%x to 0x%x\n",956956+ prev_pkey, priv->pkey);957957+ /*958958+ * Update the pkey in the broadcast address, while making sure to set959959+ * the full membership bit, so that we join the right broadcast group.960960+ */961961+ priv->dev->broadcast[8] = priv->pkey >> 8;962962+ priv->dev->broadcast[9] = priv->pkey & 0xff;963963+ return 0;964964+ }965965+966966+ return 1;967967+}968968+935969static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv,936970 enum ipoib_flush_level level)937971{938972 struct ipoib_dev_priv *cpriv;939973 struct net_device *dev = priv->dev;940974 u16 new_index;975975+ int result;941976942977 mutex_lock(&priv->vlan_mutex);943978···986951 mutex_unlock(&priv->vlan_mutex);987952988953 if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) {954954+ /* for non-child devices must check/update the pkey value here */955955+ if (level == IPOIB_FLUSH_HEAVY &&956956+ !test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags))957957+ update_parent_pkey(priv);989958 ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n");990959 return;991960 }···1000961 }10019621002963 if (level == IPOIB_FLUSH_HEAVY) {10031003- if (ib_find_pkey(priv->ca, priv->port, priv->pkey, &new_index)) {10041004- clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);10051005- ipoib_ib_dev_down(dev, 0);10061006- ipoib_ib_dev_stop(dev, 0);10071007- if (ipoib_pkey_dev_delay_open(dev))964964+ /* child devices chase their origin pkey value, while non-child965965+ * (parent) devices should always takes what present in pkey index 0966966+ */967967+ if (test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {968968+ if (ib_find_pkey(priv->ca, priv->port, priv->pkey, &new_index)) {969969+ clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);970970+ ipoib_ib_dev_down(dev, 0);971971+ ipoib_ib_dev_stop(dev, 0);972972+ if (ipoib_pkey_dev_delay_open(dev))973973+ return;974974+ }975975+ /* restart QP only if P_Key index is changed */976976+ if (test_and_set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags) &&977977+ new_index == priv->pkey_index) {978978+ ipoib_dbg(priv, "Not flushing - P_Key index not changed.\n");1008979 return;980980+ }981981+ priv->pkey_index = new_index;982982+ } else {983983+ result = update_parent_pkey(priv);984984+ /* restart QP only if P_Key value changed */985985+ if (result) {986986+ ipoib_dbg(priv, "Not flushing - P_Key value not changed.\n");987987+ return;988988+ }1009989 }10101010-10111011- /* restart QP only if P_Key index is changed */10121012- if (test_and_set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags) &&10131013- new_index == priv->pkey_index) {10141014- ipoib_dbg(priv, "Not flushing - P_Key index not changed.\n");10151015- return;10161016- }10171017- priv->pkey_index = new_index;1018990 }10199911020992 if (level == IPOIB_FLUSH_LIGHT) {