be2net: cleanup multicast_set cmd to avoid mc_list copy
authorSathya Perla <sathyap@serverengines.com>
Thu, 18 Jun 2009 00:09:25 +0000 (00:09 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 19 Jun 2009 07:18:41 +0000 (00:18 -0700)
Cleanup multicast_set method to avoid an extra copy of mc_list
 and unwanted promiscuos sets to BE.

Signed-off-by: Sathya Perla <sathyap@serverengines.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/benet/be.h
drivers/net/benet/be_cmds.c
drivers/net/benet/be_cmds.h
drivers/net/benet/be_main.c

index ef5be133ce68ffbfd329356ccdc099740bca2027..94b75cb072f7b53bffa2049773ba157e42051de2 100644 (file)
@@ -274,6 +274,7 @@ struct be_adapter {
 
        struct be_link_info link;
        u32 port_num;
+       bool promiscuous;
 };
 
 extern struct ethtool_ops be_ethtool_ops;
index e4ad5e67fde7c92cb8c4234ecfd00129015b4b8b..4a2e1f518f78b6123365a8a410278c6086c12b31 100644 (file)
@@ -927,8 +927,8 @@ int be_cmd_promiscuous_config(struct be_ctrl_info *ctrl, u8 port_num, bool en)
  * Use MCC for this command as it may be called in BH context
  * (mc == NULL) => multicast promiscous
  */
-int be_cmd_mcast_mac_set(struct be_ctrl_info *ctrl, u32 if_id, u8 *mac_table,
-                       u32 num, bool promiscuous)
+int be_cmd_multicast_set(struct be_ctrl_info *ctrl, u32 if_id,
+               struct dev_mc_list *mc_list, u32 mc_count)
 {
 #define BE_MAX_MC              32 /* set mcast promisc if > 32 */
        struct be_mcc_wrb *wrb;
@@ -947,11 +947,16 @@ int be_cmd_mcast_mac_set(struct be_ctrl_info *ctrl, u32 if_id, u8 *mac_table,
                OPCODE_COMMON_NTWK_MULTICAST_SET, sizeof(*req));
 
        req->interface_id = if_id;
-       req->promiscuous = promiscuous;
-       if (!promiscuous) {
-               req->num_mac = cpu_to_le16(num);
-               if (num)
-                       memcpy(req->mac, mac_table, ETH_ALEN * num);
+       if (mc_list && mc_count <= BE_MAX_MC) {
+               int i;
+               struct dev_mc_list *mc;
+
+               req->num_mac = cpu_to_le16(mc_count);
+
+               for (mc = mc_list, i = 0; mc; mc = mc->next, i++)
+                       memcpy(req->mac[i].byte, mc->dmi_addr, ETH_ALEN);
+       } else {
+               req->promiscuous = 1;
        }
 
        be_mcc_notify_wait(ctrl);
index 0a9189defc2a4cc678a640394d9a0246c404c03c..a567aa437ec9101dfab5df9105ec60c7aa85841b 100644 (file)
@@ -716,8 +716,8 @@ extern int be_cmd_vlan_config(struct be_ctrl_info *ctrl, u32 if_id,
                        bool promiscuous);
 extern int be_cmd_promiscuous_config(struct be_ctrl_info *ctrl,
                        u8 port_num, bool en);
-extern int be_cmd_mcast_mac_set(struct be_ctrl_info *ctrl, u32 if_id,
-                       u8 *mac_table, u32 num, bool promiscuous);
+extern int be_cmd_multicast_set(struct be_ctrl_info *ctrl, u32 if_id,
+                       struct dev_mc_list *mc_list, u32 mc_count);
 extern int be_cmd_set_flow_control(struct be_ctrl_info *ctrl,
                        u32 tx_fc, u32 rx_fc);
 extern int be_cmd_get_flow_control(struct be_ctrl_info *ctrl,
index a4ce80e776b65c7e07f5fdd5fe864aaae4696164..3dc68034c21d485dca632b8040b00a49eeadeade 100644 (file)
@@ -549,47 +549,32 @@ static void be_vlan_rem_vid(struct net_device *netdev, u16 vid)
        be_vid_config(netdev);
 }
 
-static void be_set_multicast_filter(struct net_device *netdev)
+static void be_set_multicast_list(struct net_device *netdev)
 {
        struct be_adapter *adapter = netdev_priv(netdev);
-       struct dev_mc_list *mc_ptr;
-       u8 mac_addr[32][ETH_ALEN];
-       int i = 0;
+       struct be_ctrl_info *ctrl = &adapter->ctrl;
 
-       if (netdev->flags & IFF_ALLMULTI) {
-               /* set BE in Multicast promiscuous */
-               be_cmd_mcast_mac_set(&adapter->ctrl,
-                                       adapter->if_handle, NULL, 0, true);
-               return;
+       if (netdev->flags & IFF_PROMISC) {
+               be_cmd_promiscuous_config(ctrl, adapter->port_num, 1);
+               adapter->promiscuous = true;
+               goto done;
        }
 
-       for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) {
-               memcpy(&mac_addr[i][0], mc_ptr->dmi_addr, ETH_ALEN);
-               if (++i >= 32) {
-                       be_cmd_mcast_mac_set(&adapter->ctrl,
-                               adapter->if_handle, &mac_addr[0][0], i, false);
-                       i = 0;
-               }
-
+       /* BE was previously in promiscous mode; disable it */
+       if (adapter->promiscuous) {
+               adapter->promiscuous = false;
+               be_cmd_promiscuous_config(ctrl, adapter->port_num, 0);
        }
 
-       if (i) {
-               /* reset the promiscuous mode also. */
-               be_cmd_mcast_mac_set(&adapter->ctrl,
-                       adapter->if_handle, &mac_addr[0][0], i, false);
+       if (netdev->flags & IFF_ALLMULTI) {
+               be_cmd_multicast_set(ctrl, adapter->if_handle, NULL, 0);
+               goto done;
        }
-}
-
-static void be_set_multicast_list(struct net_device *netdev)
-{
-       struct be_adapter *adapter = netdev_priv(netdev);
 
-       if (netdev->flags & IFF_PROMISC) {
-               be_cmd_promiscuous_config(&adapter->ctrl, adapter->port_num, 1);
-       } else {
-               be_cmd_promiscuous_config(&adapter->ctrl, adapter->port_num, 0);
-               be_set_multicast_filter(netdev);
-       }
+       be_cmd_multicast_set(ctrl, adapter->if_handle, netdev->mc_list,
+               netdev->mc_count);
+done:
+       return;
 }
 
 static void be_rx_rate_update(struct be_adapter *adapter)