]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Try various possible SNP receive filters
authorCurtis Larsen <larsen@dixie.edu>
Tue, 5 Aug 2014 18:27:10 +0000 (19:27 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 5 Aug 2014 22:10:34 +0000 (23:10 +0100)
The behavior observed in the Apple EFI (1.10) RecieveFilters() call
is:

  - failure if any of the PROMISCUOUS or MULTICAST filters are
    included

  - success if only UNICAST is included, however the result is
    UNICAST|BROADCAST

  - success if only UNICAST and BROADCAST are included

  - if UNICAST, or UNICAST|BROADCAST are used, but the previous call
    tried (and failed) to set UNICAST|BROADCAST|MULTICAST, then the
    result is UNICAST|BROADCAST|MULTICAST

Work around this apparently broken SNP implementation by trying
RecieveFilterMask, then falling back to UNICAST|BROADCAST|MULTICAST,
then UNICAST|BROADCAST, and finally UNICAST.

Modified-by: Michael Brown <mcb30@ipxe.org>
Tested-by: Curtis Larsen <larsen@dixie.edu>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/drivers/net/efi/snpnet.c

index 79b4946c4297723cc41f7df4da1ef4bc3ff190e7..0348e7d1a1d96b1f6aa0dcf72b972b15c4771ff5 100644 (file)
@@ -283,6 +283,42 @@ static void snpnet_poll ( struct net_device *netdev ) {
        snpnet_check_link ( netdev );
 }
 
+/**
+ * Set receive filters
+ *
+ * @v netdev           Network device
+ * @ret rc             Return status code
+ */
+static int snpnet_rx_filters ( struct net_device *netdev ) {
+       struct snp_nic *snp = netdev->priv;
+       UINT32 filters[] = {
+               snp->snp->Mode->ReceiveFilterMask,
+               ( EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |
+                 EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST |
+                 EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST ),
+               ( EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |
+                 EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST ),
+               ( EFI_SIMPLE_NETWORK_RECEIVE_UNICAST ),
+       };
+       unsigned int i;
+       EFI_STATUS efirc;
+       int rc;
+
+       /* Try possible receive filters in turn */
+       for ( i = 0; i < ( sizeof ( filters ) / sizeof ( filters[0] ) ); i++ ) {
+               efirc = snp->snp->ReceiveFilters ( snp->snp, filters[i],
+                                                  0, TRUE, 0, NULL );
+               if ( efirc == 0 )
+                       return 0;
+               rc = -EEFI ( efirc );
+               DBGC ( snp, "SNP %s could not set receive filters %#02x (have "
+                      "%#02x): %s\n", netdev->name, filters[i],
+                      snp->snp->Mode->ReceiveFilterSetting, strerror ( rc ) );
+       }
+
+       return rc;
+}
+
 /**
  * Open network device
  *
@@ -292,7 +328,6 @@ static void snpnet_poll ( struct net_device *netdev ) {
 static int snpnet_open ( struct net_device *netdev ) {
        struct snp_nic *snp = netdev->priv;
        EFI_MAC_ADDRESS *mac = ( ( void * ) netdev->ll_addr );
-       UINT32 filters;
        EFI_STATUS efirc;
        int rc;
 
@@ -322,16 +357,7 @@ static int snpnet_open ( struct net_device *netdev ) {
        }
 
        /* Set receive filters */
-       filters = ( EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |
-                   EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST |
-                   EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST |
-                   EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS |
-                   EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST );
-       if ( ( efirc = snp->snp->ReceiveFilters ( snp->snp, filters, 0, TRUE,
-                                                 0, NULL ) ) != 0 ) {
-               rc = -EEFI ( efirc );
-               DBGC ( snp, "SNP %s could not set receive filters: %s\n",
-                      netdev->name, strerror ( rc ) );
+       if ( ( rc = snpnet_rx_filters ( netdev ) ) != 0 ) {
                /* Ignore error */
        }