@@ -795,6 +795,44 @@ static int igc_set_mac(struct net_device *netdev, void *p)
795795 return 0 ;
796796}
797797
798+ /**
799+ * igc_write_mc_addr_list - write multicast addresses to MTA
800+ * @netdev: network interface device structure
801+ *
802+ * Writes multicast address list to the MTA hash table.
803+ * Returns: -ENOMEM on failure
804+ * 0 on no addresses written
805+ * X on writing X addresses to MTA
806+ **/
807+ static int igc_write_mc_addr_list (struct net_device * netdev )
808+ {
809+ struct igc_adapter * adapter = netdev_priv (netdev );
810+ struct igc_hw * hw = & adapter -> hw ;
811+ struct netdev_hw_addr * ha ;
812+ u8 * mta_list ;
813+ int i ;
814+
815+ if (netdev_mc_empty (netdev )) {
816+ /* nothing to program, so clear mc list */
817+ igc_update_mc_addr_list (hw , NULL , 0 );
818+ return 0 ;
819+ }
820+
821+ mta_list = kcalloc (netdev_mc_count (netdev ), 6 , GFP_ATOMIC );
822+ if (!mta_list )
823+ return - ENOMEM ;
824+
825+ /* The shared function expects a packed array of only addresses. */
826+ i = 0 ;
827+ netdev_for_each_mc_addr (ha , netdev )
828+ memcpy (mta_list + (i ++ * ETH_ALEN ), ha -> addr , ETH_ALEN );
829+
830+ igc_update_mc_addr_list (hw , mta_list , i );
831+ kfree (mta_list );
832+
833+ return netdev_mc_count (netdev );
834+ }
835+
798836static void igc_tx_ctxtdesc (struct igc_ring * tx_ring ,
799837 struct igc_tx_buffer * first ,
800838 u32 vlan_macip_lens , u32 type_tucmd ,
@@ -2518,6 +2556,110 @@ int igc_del_mac_steering_filter(struct igc_adapter *adapter,
25182556 IGC_MAC_STATE_QUEUE_STEERING | flags );
25192557}
25202558
2559+ /* Add a MAC filter for 'addr' directing matching traffic to 'queue',
2560+ * 'flags' is used to indicate what kind of match is made, match is by
2561+ * default for the destination address, if matching by source address
2562+ * is desired the flag IGC_MAC_STATE_SRC_ADDR can be used.
2563+ */
2564+ static int igc_add_mac_filter (struct igc_adapter * adapter ,
2565+ const u8 * addr , const u8 queue )
2566+ {
2567+ struct igc_hw * hw = & adapter -> hw ;
2568+ int rar_entries = hw -> mac .rar_entry_count ;
2569+ int i ;
2570+
2571+ if (is_zero_ether_addr (addr ))
2572+ return - EINVAL ;
2573+
2574+ /* Search for the first empty entry in the MAC table.
2575+ * Do not touch entries at the end of the table reserved for the VF MAC
2576+ * addresses.
2577+ */
2578+ for (i = 0 ; i < rar_entries ; i ++ ) {
2579+ if (!igc_mac_entry_can_be_used (& adapter -> mac_table [i ],
2580+ addr , 0 ))
2581+ continue ;
2582+
2583+ ether_addr_copy (adapter -> mac_table [i ].addr , addr );
2584+ adapter -> mac_table [i ].queue = queue ;
2585+ adapter -> mac_table [i ].state |= IGC_MAC_STATE_IN_USE ;
2586+
2587+ igc_rar_set_index (adapter , i );
2588+ return i ;
2589+ }
2590+
2591+ return - ENOSPC ;
2592+ }
2593+
2594+ /* Remove a MAC filter for 'addr' directing matching traffic to
2595+ * 'queue', 'flags' is used to indicate what kind of match need to be
2596+ * removed, match is by default for the destination address, if
2597+ * matching by source address is to be removed the flag
2598+ * IGC_MAC_STATE_SRC_ADDR can be used.
2599+ */
2600+ static int igc_del_mac_filter (struct igc_adapter * adapter ,
2601+ const u8 * addr , const u8 queue )
2602+ {
2603+ struct igc_hw * hw = & adapter -> hw ;
2604+ int rar_entries = hw -> mac .rar_entry_count ;
2605+ int i ;
2606+
2607+ if (is_zero_ether_addr (addr ))
2608+ return - EINVAL ;
2609+
2610+ /* Search for matching entry in the MAC table based on given address
2611+ * and queue. Do not touch entries at the end of the table reserved
2612+ * for the VF MAC addresses.
2613+ */
2614+ for (i = 0 ; i < rar_entries ; i ++ ) {
2615+ if (!(adapter -> mac_table [i ].state & IGC_MAC_STATE_IN_USE ))
2616+ continue ;
2617+ if (adapter -> mac_table [i ].state != 0 )
2618+ continue ;
2619+ if (adapter -> mac_table [i ].queue != queue )
2620+ continue ;
2621+ if (!ether_addr_equal (adapter -> mac_table [i ].addr , addr ))
2622+ continue ;
2623+
2624+ /* When a filter for the default address is "deleted",
2625+ * we return it to its initial configuration
2626+ */
2627+ if (adapter -> mac_table [i ].state & IGC_MAC_STATE_DEFAULT ) {
2628+ adapter -> mac_table [i ].state =
2629+ IGC_MAC_STATE_DEFAULT | IGC_MAC_STATE_IN_USE ;
2630+ adapter -> mac_table [i ].queue = 0 ;
2631+ } else {
2632+ adapter -> mac_table [i ].state = 0 ;
2633+ adapter -> mac_table [i ].queue = 0 ;
2634+ memset (adapter -> mac_table [i ].addr , 0 , ETH_ALEN );
2635+ }
2636+
2637+ igc_rar_set_index (adapter , i );
2638+ return 0 ;
2639+ }
2640+
2641+ return - ENOENT ;
2642+ }
2643+
2644+ static int igc_uc_sync (struct net_device * netdev , const unsigned char * addr )
2645+ {
2646+ struct igc_adapter * adapter = netdev_priv (netdev );
2647+ int ret ;
2648+
2649+ ret = igc_add_mac_filter (adapter , addr , adapter -> num_rx_queues );
2650+
2651+ return min_t (int , ret , 0 );
2652+ }
2653+
2654+ static int igc_uc_unsync (struct net_device * netdev , const unsigned char * addr )
2655+ {
2656+ struct igc_adapter * adapter = netdev_priv (netdev );
2657+
2658+ igc_del_mac_filter (adapter , addr , adapter -> num_rx_queues );
2659+
2660+ return 0 ;
2661+ }
2662+
25212663/**
25222664 * igc_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
25232665 * @netdev: network interface device structure
@@ -2529,6 +2671,44 @@ int igc_del_mac_steering_filter(struct igc_adapter *adapter,
25292671 */
25302672static void igc_set_rx_mode (struct net_device * netdev )
25312673{
2674+ struct igc_adapter * adapter = netdev_priv (netdev );
2675+ struct igc_hw * hw = & adapter -> hw ;
2676+ u32 rctl = 0 , rlpml = MAX_JUMBO_FRAME_SIZE ;
2677+ int count ;
2678+
2679+ /* Check for Promiscuous and All Multicast modes */
2680+ if (netdev -> flags & IFF_PROMISC ) {
2681+ rctl |= IGC_RCTL_UPE | IGC_RCTL_MPE ;
2682+ } else {
2683+ if (netdev -> flags & IFF_ALLMULTI ) {
2684+ rctl |= IGC_RCTL_MPE ;
2685+ } else {
2686+ /* Write addresses to the MTA, if the attempt fails
2687+ * then we should just turn on promiscuous mode so
2688+ * that we can at least receive multicast traffic
2689+ */
2690+ count = igc_write_mc_addr_list (netdev );
2691+ if (count < 0 )
2692+ rctl |= IGC_RCTL_MPE ;
2693+ }
2694+ }
2695+
2696+ /* Write addresses to available RAR registers, if there is not
2697+ * sufficient space to store all the addresses then enable
2698+ * unicast promiscuous mode
2699+ */
2700+ if (__dev_uc_sync (netdev , igc_uc_sync , igc_uc_unsync ))
2701+ rctl |= IGC_RCTL_UPE ;
2702+
2703+ /* update state of unicast and multicast */
2704+ rctl |= rd32 (IGC_RCTL ) & ~(IGC_RCTL_UPE | IGC_RCTL_MPE );
2705+ wr32 (IGC_RCTL , rctl );
2706+
2707+ #if (PAGE_SIZE < 8192 )
2708+ if (adapter -> max_frame_size <= IGC_MAX_FRAME_BUILD_SKB )
2709+ rlpml = IGC_MAX_FRAME_BUILD_SKB ;
2710+ #endif
2711+ wr32 (IGC_RLPML , rlpml );
25322712}
25332713
25342714/**
@@ -3982,6 +4162,7 @@ static const struct net_device_ops igc_netdev_ops = {
39824162 .ndo_open = igc_open ,
39834163 .ndo_stop = igc_close ,
39844164 .ndo_start_xmit = igc_xmit_frame ,
4165+ .ndo_set_rx_mode = igc_set_rx_mode ,
39854166 .ndo_set_mac_address = igc_set_mac ,
39864167 .ndo_change_mtu = igc_change_mtu ,
39874168 .ndo_get_stats = igc_get_stats ,
0 commit comments