commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10675 - in gnuradio/branches/releases/3.2: . usrp2/fi


From: jcorgan
Subject: [Commit-gnuradio] r10675 - in gnuradio/branches/releases/3.2: . usrp2/firmware/lib usrp2/host/lib
Date: Tue, 24 Mar 2009 09:11:47 -0600 (MDT)

Author: jcorgan
Date: 2009-03-24 09:11:47 -0600 (Tue, 24 Mar 2009)
New Revision: 10675

Modified:
   gnuradio/branches/releases/3.2/
   gnuradio/branches/releases/3.2/usrp2/firmware/lib/ethernet.c
   gnuradio/branches/releases/3.2/usrp2/firmware/lib/ethernet.h
   gnuradio/branches/releases/3.2/usrp2/host/lib/pktfilter.cc
   gnuradio/branches/releases/3.2/usrp2/host/lib/pktfilter.h
   gnuradio/branches/releases/3.2/usrp2/host/lib/usrp2_impl.cc
Log:
Applied changesets r10634, r10645 to release 3.2 branch


Property changes on: gnuradio/branches/releases/3.2
___________________________________________________________________
Modified: svn:mergeinfo
   - /gnuradio/branches/developers/michaelld/am_swig_4:10555-10595
/gnuradio/branches/developers/michaelld/two_mods:10540-10546
/gnuradio/trunk:10356-10359,10481-10482,10497-10499,10506-10507,10511,10514,10521,10523-10524,10529,10531,10535,10537-10538,10550-10551,10556,10558-10560,10562-10563,10565,10574-10576,10578-10579,10581-10582,10585,10587,10596-10600,10623-10624,10629,10632-10633
   + /gnuradio/branches/developers/michaelld/am_swig_4:10555-10595
/gnuradio/branches/developers/michaelld/two_mods:10540-10546
/gnuradio/trunk:10356-10359,10481-10482,10497-10499,10506-10507,10511,10514,10521,10523-10524,10529,10531,10535,10537-10538,10550-10551,10556,10558-10560,10562-10563,10565,10574-10576,10578-10579,10581-10582,10585,10587,10596-10600,10623-10624,10629,10632-10634,10645

Modified: gnuradio/branches/releases/3.2/usrp2/firmware/lib/ethernet.c
===================================================================
--- gnuradio/branches/releases/3.2/usrp2/firmware/lib/ethernet.c        
2009-03-24 15:07:22 UTC (rev 10674)
+++ gnuradio/branches/releases/3.2/usrp2/firmware/lib/ethernet.c        
2009-03-24 15:11:47 UTC (rev 10675)
@@ -86,6 +86,36 @@
   ed_link_up(speed);
 }
 
+static void
+print_flow_control(int flow_control)
+{
+  static const char *flow_control_msg[4] = {
+    "NONE", "WE_TX", "WE_RX", "SYMMETRIC"
+  };
+  putstr("ethernet flow control: ");
+  puts(flow_control_msg[flow_control & 0x3]);
+}
+
+static void
+check_flow_control_resolution(void)
+{
+  static const unsigned char table[16] = {
+    // index = {local_asm, local_pause, partner_asm, partner_pause}
+    FC_NONE,  FC_NONE,  FC_NONE,  FC_NONE,
+    FC_NONE,  FC_SYMM,  FC_NONE,  FC_SYMM,
+    FC_NONE,  FC_NONE,  FC_NONE,  FC_WE_TX,
+    FC_NONE,  FC_SYMM,  FC_WE_RX, FC_SYMM
+  };
+
+  int us = eth_mac_miim_read(PHY_AUTONEG_ADV);
+  int lp = eth_mac_miim_read(PHY_LP_ABILITY);
+  int index = (((us >> 10) & 0x3) << 2) | ((lp >> 10) & 0x3);
+  ed_state.flow_control = table[index];
+
+  if (1)
+    print_flow_control(ed_state.flow_control);
+}
+
 /*
  * Read the PHY state register to determine link state and speed
  */
@@ -123,6 +153,8 @@
       new_speed = S_UNKNOWN;
       break;
     }
+
+    check_flow_control_resolution();
   }
   else {                               // link's down
     if (VERBOSE)
@@ -194,10 +226,37 @@
 
   pic_register_handler(IRQ_PHY, eth_phy_irq_handler);
 
-  // Advertise that we handle PAUSE frames and asymmetric pause direction.
+  // Advertise our flow control configuation.
+  //
+  // We and the link partner each specify two bits in the base page
+  // related to autoconfiguration: NWAY_AR_PAUSE and NWAY_AR_ASM_DIR.
+  // The bits say what a device is "willing" to do, not what may actually
+  // happen as a result of the negotiation.  There are 4 cases:
+  //
+  // PAUSE  ASM_DIR
+  //
+  //  0        0        I have no flow control capability.
+  //
+  //  1        0        I both assert and respond to flow control.
+  //
+  //  0        1        I assert flow control, but cannot respond.  That is,
+  //                    I want to be able to send PAUSE frames, but will 
ignore any
+  //                   you send to me.  (This is our configuration.)
+  //
+  //  1        1        I can both assert and respond to flow control AND I am 
willing
+  //                    to operate symmetrically OR asymmetrically in EITHER 
direction.
+  //                    (We hope the link partner advertises this, otherwise 
we don't
+  //                   get what we want.)
+
   int t = eth_mac_miim_read(PHY_AUTONEG_ADV);
-  eth_mac_miim_write(PHY_AUTONEG_ADV, t | NWAY_AR_PAUSE | NWAY_AR_ASM_DIR);
+  t &= ~(NWAY_AR_PAUSE | NWAY_AR_ASM_DIR);
+  t |= NWAY_AR_ASM_DIR;
 
+  // Say we can't to 10BASE-T or 100BASE-TX, half or full duplex
+  t &= ~(NWAY_AR_10T_HD_CAPS | NWAY_AR_10T_FD_CAPS | NWAY_AR_100TX_HD_CAPS | 
NWAY_AR_100TX_FD_CAPS);
+
+  eth_mac_miim_write(PHY_AUTONEG_ADV, t);
+
   // Restart autonegotation.  
   // We want to ensure that we're advertising our PAUSE capabilities.
   t = eth_mac_miim_read(PHY_CTRL);

Modified: gnuradio/branches/releases/3.2/usrp2/firmware/lib/ethernet.h
===================================================================
--- gnuradio/branches/releases/3.2/usrp2/firmware/lib/ethernet.h        
2009-03-24 15:07:22 UTC (rev 10674)
+++ gnuradio/branches/releases/3.2/usrp2/firmware/lib/ethernet.h        
2009-03-24 15:11:47 UTC (rev 10675)
@@ -65,11 +65,18 @@
 
 typedef enum { LS_UNKNOWN, LS_DOWN, LS_UP } eth_link_state_t;
 
+// flow control bitmasks
+#define        FC_NONE         0x0
+#define        FC_WE_TX        0x1                     // we send PAUSE frames
+#define        FC_WE_RX        0x2                     // we honor received 
PAUSE frames
+#define        FC_SYMM         (FC_WE_TX | FC_WE_RX)
+
 #define S_UNKNOWN (-1)                 // unknown link speed
 
 typedef struct {
   eth_link_state_t     link_state;
   int                  link_speed;     // in Mb/s
+  int                  flow_control;
 } ethernet_t;
 
 #endif /* INCLUDED_ETHERNET_H */

Modified: gnuradio/branches/releases/3.2/usrp2/host/lib/pktfilter.cc
===================================================================
--- gnuradio/branches/releases/3.2/usrp2/host/lib/pktfilter.cc  2009-03-24 
15:07:22 UTC (rev 10674)
+++ gnuradio/branches/releases/3.2/usrp2/host/lib/pktfilter.cc  2009-03-24 
15:11:47 UTC (rev 10675)
@@ -148,5 +148,40 @@
     
     return pf;
   }
+  /*
+   * Return a filter that harvests inbound packets with the specified 
ethertype and target USRP2 MAC address.
+   * \param ethertype  the ethertype we're looking for
+   * \param usrp_mac    our target USRP2 MAC address
+   */
+  pktfilter *
+  pktfilter::make_ethertype_inbound_target (unsigned short ethertype, const 
unsigned char *usrp_mac)
+  {
+    static const int MAX_LEN = 20;
+    sock_filter        *inst = new sock_filter [MAX_LEN];
+    pktfilter  *pf = new pktfilter ();
+
+    __u16 tmac_hi = (usrp_mac[0] << 8) | usrp_mac[1];
+    __u32 tmac_lo = (usrp_mac[2] << 24) | (usrp_mac[3] << 16) | (usrp_mac[4] 
<< 8) | usrp_mac[5];
+    
+    // ignore packets that have a different ethertype
+    // and only return packets that have a source mac address == usrp_mac
+    
+    int i = 0;
+    inst[i++] = make_stmt (BPF_LD|BPF_H|BPF_ABS, 12);  // load ethertype
+    inst[i++] = make_jump (BPF_JMP|BPF_JEQ|BPF_K, ethertype, 0, 5);
+    inst[i++] = make_stmt (BPF_LD|BPF_W|BPF_ABS, 8);   // load low 32-bit of 
src mac
+    inst[i++] = make_jump (BPF_JMP|BPF_JEQ|BPF_K, tmac_lo, 0, 3);
+    inst[i++] = make_stmt (BPF_LD|BPF_H|BPF_ABS, 6);   // load high 16-bits of 
src mac
+    inst[i++] = make_jump (BPF_JMP|BPF_JEQ|BPF_K, tmac_hi, 0, 1);
+    inst[i++] = make_stmt (BPF_RET|BPF_K, (unsigned) -1);      // return whole 
packet
+    inst[i++] = make_stmt (BPF_RET|BPF_K, 0);          // return 0 (ignore 
packet)
+    
+    assert (i <= MAX_LEN);
+    
+    pf->d_inst = inst;
+    pf->d_len = i;
+    
+    return pf;
+  }
   
 } // namespace usrp2

Modified: gnuradio/branches/releases/3.2/usrp2/host/lib/pktfilter.h
===================================================================
--- gnuradio/branches/releases/3.2/usrp2/host/lib/pktfilter.h   2009-03-24 
15:07:22 UTC (rev 10674)
+++ gnuradio/branches/releases/3.2/usrp2/host/lib/pktfilter.h   2009-03-24 
15:11:47 UTC (rev 10675)
@@ -48,6 +48,15 @@
      */
     static pktfilter *make_ethertype_inbound (unsigned short ethertype,
                                              const unsigned char *our_mac);
+
+    /*!
+     * \brief Return a filter that harvests inbound packets with the specified 
ethertype
+     *        and source MAC address
+     * \param ethertype        the ethertype we're looking for
+     * \param usrp_mac         the source MAC address
+     */
+    static pktfilter *make_ethertype_inbound_target (unsigned short ethertype,
+                                                    const unsigned char 
*usrp_mac); 
   };
   
 } // namespace usrp2

Modified: gnuradio/branches/releases/3.2/usrp2/host/lib/usrp2_impl.cc
===================================================================
--- gnuradio/branches/releases/3.2/usrp2/host/lib/usrp2_impl.cc 2009-03-24 
15:07:22 UTC (rev 10674)
+++ gnuradio/branches/releases/3.2/usrp2/host/lib/usrp2_impl.cc 2009-03-24 
15:11:47 UTC (rev 10675)
@@ -138,12 +138,15 @@
     if (!d_eth_buf->open(ifc, htons(U2_ETHERTYPE)))
       throw std::runtime_error("Unable to register USRP2 protocol");
     
-    d_pf = pktfilter::make_ethertype_inbound(U2_ETHERTYPE, d_eth_buf->mac());
+    d_addr = p->addr;
+
+    // Create a packet filter for U2_ETHERTYPE packets sourced from target 
USRP2
+    u2_mac_addr_t usrp_mac;
+    parse_mac_addr(d_addr, &usrp_mac);
+    d_pf = pktfilter::make_ethertype_inbound_target(U2_ETHERTYPE, (const 
unsigned char*)&(usrp_mac.addr));
     if (!d_pf || !d_eth_buf->attach_pktfilter(d_pf))
       throw std::runtime_error("Unable to attach packet filter.");
     
-    d_addr = p->addr;
-    
     if (USRP2_IMPL_DEBUG)
       std::cerr << "usrp2 constructor: using USRP2 at " << d_addr << std::endl;
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]