void ipoib_event(struct ib_event_handler *handler,
struct ib_event *record);
-int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey);
-int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey);
+int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey,
+ unsigned char scope);
+int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey,
+ unsigned char scope);
void ipoib_pkey_poll(struct work_struct *work);
int ipoib_pkey_dev_delay_open(struct net_device *dev);
void ipoib_drain_cq(struct net_device *dev);
+int ipoib_pkey_scope_in_use(struct net_device *dev, unsigned short pkey,
+ unsigned char scope);
+
+static inline unsigned char ipoib_get_scope(struct net_device *dev)
+{
+ return dev->broadcast[5] & 0xF;
+}
+
+static inline void ipoib_set_scope(struct net_device *dev, unsigned char scope)
+{
+ dev->broadcast[5] &= ~0xF;
+ dev->broadcast[5] |= scope;
+}
+
#ifdef CONFIG_INFINIBAND_IPOIB_CM
#define IPOIB_FLAGS_RC 0x80
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
};
+static const u8 default_scope = 2; /* link local */
+
struct workqueue_struct *ipoib_workqueue;
struct ib_sa_client ipoib_sa_client;
static ssize_t show_bcast_scope(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev));
+ return sprintf(buf, "0x%x\n", (int) ipoib_get_scope(to_net_dev(dev)));
+}
- return sprintf(buf, "0x%x\n", priv->dev->broadcast[5] & 0xF);
+static int valid_scope(unsigned char scope)
+{
+ switch (scope) {
+ case 0x2: /* link-local */
+ case 0x5: /* site-local */
+ case 0x8: /* organization-local */
+ case 0xE: /* global */
+ return 1;
+ default:
+ return 0;
+ }
}
static ssize_t set_bcast_scope(struct device *dev,
if (priv->dev->flags & IFF_UP)
return -EBUSY;
- if (sscanf(buf, "%i", &scope) != 1)
+ if (sscanf(buf, "%i", &scope) != 1 || !valid_scope(scope))
return -EINVAL;
- switch (scope) {
- case 0x2: /* link-local */
- case 0x5: /* site-local */
- case 0x8: /* organization-local */
- case 0xE: /* global */
- break;
- default:
- return -EINVAL;
- }
+ if (ipoib_get_scope(priv->dev) == scope) /* no change */
+ return count;
- priv->dev->broadcast[5] &= ~0xF;
- priv->dev->broadcast[5] |= scope;
+ if (ipoib_pkey_scope_in_use(priv->dev, priv->pkey, scope))
+ return -ENOTUNIQ;
+
+ ipoib_set_scope(priv->dev, scope);
return count;
}
static DEVICE_ATTR(broadcast_scope, S_IWUSR | S_IRUGO, show_bcast_scope, set_bcast_scope);
const char *buf, size_t count)
{
int pkey;
+ int scope = default_scope;
int ret;
- if (sscanf(buf, "%i", &pkey) != 1)
+ if (sscanf(buf, "%i %i", &pkey, &scope) < 1)
return -EINVAL;
if (pkey < 0 || pkey > 0xffff)
return -EINVAL;
+ if (!valid_scope(scope))
+ return -EINVAL;
+
/*
* Set the full membership bit, so that we join the right
* broadcast group, etc.
*/
pkey |= 0x8000;
- ret = ipoib_vlan_add(to_net_dev(dev), pkey);
+ ret = ipoib_vlan_add(to_net_dev(dev), pkey, scope);
return ret ? ret : count;
}
const char *buf, size_t count)
{
int pkey;
+ int scope = default_scope;
int ret;
- if (sscanf(buf, "%i", &pkey) != 1)
+ if (sscanf(buf, "%i %i", &pkey, &scope) < 1)
return -EINVAL;
if (pkey < 0 || pkey > 0xffff)
return -EINVAL;
- ret = ipoib_vlan_delete(to_net_dev(dev), pkey);
+ if (!valid_scope(scope))
+ return -EINVAL;
+
+ ret = ipoib_vlan_delete(to_net_dev(dev), pkey, scope);
return ret ? ret : count;
}
static DEVICE_ATTR(delete_child, S_IWUGO, NULL, delete_child);
+int ipoib_pkey_scope_in_use(struct net_device *dev, unsigned short pkey, unsigned char scope)
+{
+ struct ipoib_dev_priv *ppriv, *priv;
+
+ ppriv = netdev_priv(dev);
+ /*
+ * We check the parent device and then all of the child interfaces to make sure
+ * the Pkey and scope don't match.
+ */
+ if (ppriv->pkey == pkey && ipoib_get_scope(dev) == scope)
+ return 1;
+
+ list_for_each_entry(priv, &ppriv->child_intfs, list)
+ if (priv->pkey == pkey && ipoib_get_scope(priv->dev) == scope)
+ return 1;
+
+ return 0;
+}
+
int ipoib_add_pkey_attr(struct net_device *dev)
{
return device_create_file(&dev->dev, &dev_attr_pkey);
}
static DEVICE_ATTR(parent, S_IRUGO, show_parent, NULL);
-int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
+int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey,
+ unsigned char scope)
{
struct ipoib_dev_priv *ppriv, *priv;
char intf_name[IFNAMSIZ];
mutex_lock(&ppriv->vlan_mutex);
- /*
- * First ensure this isn't a duplicate. We check the parent device and
- * then all of the child interfaces to make sure the Pkey doesn't match.
- */
- if (ppriv->pkey == pkey) {
+ if (ipoib_pkey_scope_in_use(pdev, pkey, scope)) {
result = -ENOTUNIQ;
goto err;
}
- list_for_each_entry(priv, &ppriv->child_intfs, list) {
- if (priv->pkey == pkey) {
- result = -ENOTUNIQ;
- goto err;
- }
- }
-
snprintf(intf_name, sizeof intf_name, "%s.%04x",
ppriv->dev->name, pkey);
priv = ipoib_intf_alloc(intf_name);
priv->dev->broadcast[8] = pkey >> 8;
priv->dev->broadcast[9] = pkey & 0xff;
+ ipoib_set_scope(priv->dev, scope);
+
result = ipoib_dev_init(priv->dev, ppriv->ca, ppriv->port);
if (result < 0) {
ipoib_warn(ppriv, "failed to initialize subinterface: "
return result;
}
-int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
+int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey,
+ unsigned char scope)
{
struct ipoib_dev_priv *ppriv, *priv, *tpriv;
int ret = -ENOENT;
mutex_lock(&ppriv->vlan_mutex);
list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) {
- if (priv->pkey == pkey) {
+ if (priv->pkey == pkey && ipoib_get_scope(priv->dev) == scope) {
unregister_netdev(priv->dev);
ipoib_dev_cleanup(priv->dev);
list_del(&priv->list);