Re: MCLGETI support for xl(4)

2010-09-19 Thread Claudio Jeker
On Thu, Sep 16, 2010 at 03:44:02PM -0400, Loganaden Velvindron wrote:
 Greetings,
 
 From brad, remove superfluous braces.
 

The direction of this diff is OK. The mclgeti() usage seems OK.
What made my alarmbells go off was the removal of xl_rx_resync(). Now that
function in itself is dumb but it made me realize that xl(4) is missing
many if not most bus_dma operations. Especially bus_dmamap_sync() are
missing at various places and xl_rx_resync() was probably a workaround for
it. So I have the feeling that this diff may make xl(4) worse on systems
that require the syncs.

It is best to test drivers not only on i386 or amd64 but also on sparc64
which is a very good system to verify proper bus_dma operation.

 Index: src/sys/dev/ic/xl.c
 ===
 RCS file: /cvs/src/sys/dev/ic/xl.c,v
 retrieving revision 1.96
 diff -u -p -r1.96 xl.c
 --- src/sys/dev/ic/xl.c   7 Sep 2010 16:21:43 -   1.96
 +++ src/sys/dev/ic/xl.c   16 Sep 2010 19:36:53 -
 @@ -153,7 +153,6 @@ void xl_stats_update(void *);
  int xl_encap(struct xl_softc *, struct xl_chain *,
  struct mbuf * );
  void xl_rxeof(struct xl_softc *);
 -int xl_rx_resync(struct xl_softc *);
  void xl_txeof(struct xl_softc *);
  void xl_txeof_90xB(struct xl_softc *);
  void xl_txeoc(struct xl_softc *);
 @@ -180,6 +179,7 @@ void xl_iff(struct xl_softc *);
  void xl_iff_90x(struct xl_softc *);
  void xl_iff_905b(struct xl_softc *);
  int xl_list_rx_init(struct xl_softc *);
 +void xl_fill_rx_ring(struct xl_softc *);
  int xl_list_tx_init(struct xl_softc *);
  int xl_list_tx_init_90xB(struct xl_softc *);
  void xl_wait(struct xl_softc *);
 @@ -1076,8 +1076,6 @@ xl_list_rx_init(struct xl_softc *sc)
   for (i = 0; i  XL_RX_LIST_CNT; i++) {
   cd-xl_rx_chain[i].xl_ptr =
   (struct xl_list_onefrag *)ld-xl_rx_list[i];
 - if (xl_newbuf(sc, cd-xl_rx_chain[i]) == ENOBUFS)
 - return(ENOBUFS);
   if (i == (XL_RX_LIST_CNT - 1))
   n = 0;
   else
 @@ -1088,11 +1086,30 @@ xl_list_rx_init(struct xl_softc *sc)
   ld-xl_rx_list[i].xl_next = htole32(next);
   }
  
 - cd-xl_rx_head = cd-xl_rx_chain[0];
 -
 + cd-xl_rx_prod = cd-xl_rx_cons = cd-xl_rx_chain[0];
 + cd-xl_rx_cnt = 0;
 + xl_fill_rx_ring(sc);
   return (0);
  }
  
 +void
 +xl_fill_rx_ring(struct xl_softc *sc)
 +{  
 + struct xl_chain_data*cd;
 + struct xl_list_data *ld;
 +
 + cd = sc-xl_cdata;
 + ld = sc-xl_ldata;
 +
 + while (cd-xl_rx_cnt  XL_RX_LIST_CNT) {
 + if (xl_newbuf(sc, cd-xl_rx_prod) == ENOBUFS)
 + break;
 + cd-xl_rx_prod = cd-xl_rx_prod-xl_next;
 + cd-xl_rx_cnt++;
 + }
 +}
 +
 +
  /*
   * Initialize an RX descriptor and attach an MBUF cluster.
   */
 @@ -1102,15 +1119,10 @@ xl_newbuf(struct xl_softc *sc, struct xl
   struct mbuf *m_new = NULL;
   bus_dmamap_tmap;
  
 - MGETHDR(m_new, M_DONTWAIT, MT_DATA);
 - if (m_new == NULL)
 - return (ENOBUFS);
 -
 - MCLGET(m_new, M_DONTWAIT);
 - if (!(m_new-m_flags  M_EXT)) {
 - m_freem(m_new);
 + m_new = MCLGETI(NULL, M_DONTWAIT, sc-sc_arpcom.ac_if, MCLBYTES);
 + 
 + if (!m_new)
   return (ENOBUFS);
 - }
  
   m_new-m_len = m_new-m_pkthdr.len = MCLBYTES;
   if (bus_dmamap_load(sc-sc_dmat, sc-sc_rx_sparemap,
 @@ -1150,32 +1162,6 @@ xl_newbuf(struct xl_softc *sc, struct xl
   return (0);
  }
  
 -int
 -xl_rx_resync(struct xl_softc *sc)
 -{
 - struct xl_chain_onefrag *pos;
 - int i;
 -
 - pos = sc-xl_cdata.xl_rx_head;
 -
 - for (i = 0; i  XL_RX_LIST_CNT; i++) {
 - bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
 - ((caddr_t)pos-xl_ptr - sc-sc_listkva),
 - sizeof(struct xl_list),
 - BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
 -
 - if (pos-xl_ptr-xl_status)
 - break;
 - pos = pos-xl_next;
 - }
 -
 - if (i == XL_RX_LIST_CNT)
 - return (0);
 -
 - sc-xl_cdata.xl_rx_head = pos;
 -
 - return (EAGAIN);
 -}
  
  /*
   * A frame has been uploaded: pass the resulting mbuf chain up to
 @@ -1195,12 +1181,14 @@ xl_rxeof(struct xl_softc *sc)
  
  again:
  
 - while ((rxstat = letoh32(sc-xl_cdata.xl_rx_head-xl_ptr-xl_status))
 - != 0) {
 - cur_rx = sc-xl_cdata.xl_rx_head;
 - sc-xl_cdata.xl_rx_head = cur_rx-xl_next;
 + while ((rxstat = letoh32(sc-xl_cdata.xl_rx_cons-xl_ptr-xl_status))
 + != 0  sc-xl_cdata.xl_rx_cnt  0) {
 + cur_rx = sc-xl_cdata.xl_rx_cons;
 + m = cur_rx-xl_mbuf;  
 + cur_rx-xl_mbuf = NULL;
 + sc-xl_cdata.xl_rx_cons = cur_rx-xl_next;
 + sc-xl_cdata.xl_rx_cnt--;
   total_len = rxstat  XL_RXSTAT_LENMASK;
 -
  

Re: MCLGETI support for xl(4)

2010-09-18 Thread Tobias Ulmer
Works for me on

xl0 at pci0 dev 13 function 0 3Com 3c905C 100Base-TX rev 0x78: apic 2
int 16 (irq 10), address 00:04:75:b1:00:7d
xl1 at pci0 dev 17 function 0 3Com 3c905B 100Base-TX rev 0x24: apic 2
int 17 (irq 5), address 00:c0:4f:79:4d:d8



MCLGETI support for xl(4)

2010-09-16 Thread Loganaden Velvindron
Greetings,

I've cleaned the diff a bit based on feedback from sthen@  b...@.
Here it is:

? xl.diff
Index: xl.c
===
RCS file: /cvs/src/sys/dev/ic/xl.c,v
retrieving revision 1.96
diff -u -p -r1.96 xl.c
--- xl.c7 Sep 2010 16:21:43 -   1.96
+++ xl.c16 Sep 2010 09:59:41 -
@@ -153,7 +153,6 @@ void xl_stats_update(void *);
 int xl_encap(struct xl_softc *, struct xl_chain *,
 struct mbuf * );
 void xl_rxeof(struct xl_softc *);
-int xl_rx_resync(struct xl_softc *);
 void xl_txeof(struct xl_softc *);
 void xl_txeof_90xB(struct xl_softc *);
 void xl_txeoc(struct xl_softc *);
@@ -180,6 +179,7 @@ void xl_iff(struct xl_softc *);
 void xl_iff_90x(struct xl_softc *);
 void xl_iff_905b(struct xl_softc *);
 int xl_list_rx_init(struct xl_softc *);
+void xl_fill_rx_ring(struct xl_softc *);
 int xl_list_tx_init(struct xl_softc *);
 int xl_list_tx_init_90xB(struct xl_softc *);
 void xl_wait(struct xl_softc *);
@@ -1076,8 +1076,6 @@ xl_list_rx_init(struct xl_softc *sc)
for (i = 0; i  XL_RX_LIST_CNT; i++) {
cd-xl_rx_chain[i].xl_ptr =
(struct xl_list_onefrag *)ld-xl_rx_list[i];
-   if (xl_newbuf(sc, cd-xl_rx_chain[i]) == ENOBUFS)
-   return(ENOBUFS);
if (i == (XL_RX_LIST_CNT - 1))
n = 0;
else
@@ -1088,11 +1086,30 @@ xl_list_rx_init(struct xl_softc *sc)
ld-xl_rx_list[i].xl_next = htole32(next);
}
 
-   cd-xl_rx_head = cd-xl_rx_chain[0];
-
+   cd-xl_rx_prod = cd-xl_rx_cons = cd-xl_rx_chain[0];
+   cd-xl_rx_cnt = 0;
+   xl_fill_rx_ring(sc);
return (0);
 }
 
+void
+xl_fill_rx_ring(struct xl_softc *sc)
+{  
+struct xl_chain_data*cd;
+struct xl_list_data *ld;
+
+cd = sc-xl_cdata;
+ld = sc-xl_ldata;
+
+while (cd-xl_rx_cnt  XL_RX_LIST_CNT) {
+if (xl_newbuf(sc, cd-xl_rx_prod) == ENOBUFS)
+break;
+   cd-xl_rx_prod = cd-xl_rx_prod-xl_next;
+cd-xl_rx_cnt++;
+}
+}
+
+
 /*
  * Initialize an RX descriptor and attach an MBUF cluster.
  */
@@ -1102,13 +1119,9 @@ xl_newbuf(struct xl_softc *sc, struct xl
struct mbuf *m_new = NULL;
bus_dmamap_tmap;
 
-   MGETHDR(m_new, M_DONTWAIT, MT_DATA);
-   if (m_new == NULL)
-   return (ENOBUFS);
-
-   MCLGET(m_new, M_DONTWAIT);
-   if (!(m_new-m_flags  M_EXT)) {
-   m_freem(m_new);
+   m_new = MCLGETI(NULL, M_DONTWAIT, sc-sc_arpcom.ac_if, MCLBYTES);
+   
+   if (!m_new){
return (ENOBUFS);
}
 
@@ -1125,11 +1138,11 @@ xl_newbuf(struct xl_softc *sc, struct xl
0, c-map-dm_mapsize, BUS_DMASYNC_POSTREAD);
bus_dmamap_unload(sc-sc_dmat, c-map);
}
-
+   
map = c-map;
c-map = sc-sc_rx_sparemap;
sc-sc_rx_sparemap = map;
-
+   
/* Force longword alignment for packet payload. */
m_adj(m_new, ETHER_ALIGN);
 
@@ -1150,32 +1163,6 @@ xl_newbuf(struct xl_softc *sc, struct xl
return (0);
 }
 
-int
-xl_rx_resync(struct xl_softc *sc)
-{
-   struct xl_chain_onefrag *pos;
-   int i;
-
-   pos = sc-xl_cdata.xl_rx_head;
-
-   for (i = 0; i  XL_RX_LIST_CNT; i++) {
-   bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
-   ((caddr_t)pos-xl_ptr - sc-sc_listkva),
-   sizeof(struct xl_list),
-   BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
-
-   if (pos-xl_ptr-xl_status)
-   break;
-   pos = pos-xl_next;
-   }
-
-   if (i == XL_RX_LIST_CNT)
-   return (0);
-
-   sc-xl_cdata.xl_rx_head = pos;
-
-   return (EAGAIN);
-}
 
 /*
  * A frame has been uploaded: pass the resulting mbuf chain up to
@@ -1195,12 +1182,14 @@ xl_rxeof(struct xl_softc *sc)
 
 again:
 
-   while ((rxstat = letoh32(sc-xl_cdata.xl_rx_head-xl_ptr-xl_status))
-   != 0) {
-   cur_rx = sc-xl_cdata.xl_rx_head;
-   sc-xl_cdata.xl_rx_head = cur_rx-xl_next;
+   while ((rxstat = letoh32(sc-xl_cdata.xl_rx_cons-xl_ptr-xl_status))
+   != 0  sc-xl_cdata.xl_rx_cnt  0) {
+   cur_rx = sc-xl_cdata.xl_rx_cons;
+m = cur_rx-xl_mbuf;  
+cur_rx-xl_mbuf = NULL;
+   sc-xl_cdata.xl_rx_cons = cur_rx-xl_next;
+   sc-xl_cdata.xl_rx_cnt--;
total_len = rxstat  XL_RXSTAT_LENMASK;
-
bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
((caddr_t)cur_rx-xl_ptr - sc-sc_listkva),
sizeof(struct xl_list),
@@ -1224,6 +1213,7 @@ again:
if (rxstat  XL_RXSTAT_UP_ERROR) {
ifp-if_ierrors++;
cur_rx-xl_ptr-xl_status = htole32(0);
+  

Re: MCLGETI support for xl(4)

2010-09-16 Thread Brynet
This is nice, there are some minor issues with the diff.

* The xl_fill_rx_ring function body uses spaces instead of tabs.
* Around -1125,11 +1138,11, you insert a few tabs unnecessarily.
* ..and around -1195,12 +1182,14, within the while loop, spaces.
* For the header patch, more spaces.

I am seeing some neat 'netstat -m' values when using this patch on an
older P3 system, memory utilization goes down to 7/8%, reaching only 20%
when transferring a file over SSH. :-)

Without the patch it goes immediately to 25% after 'ifconfig xl0 address'.

Actually seems to perform better even, although perhaps that's my mind
playing tricks on me.

Thanks,
-Bryan.



MCLGETI support for xl(4)

2010-09-16 Thread Loganaden Velvindron
Greetings,
Thanks bryan for testing it !
I've applied the necessary changes.

Here it is:

Index: src/sys/dev/ic/xl.c
===
RCS file: /cvs/src/sys/dev/ic/xl.c,v
retrieving revision 1.96
diff -u -p -r1.96 xl.c
--- src/sys/dev/ic/xl.c 7 Sep 2010 16:21:43 -   1.96
+++ src/sys/dev/ic/xl.c 16 Sep 2010 18:09:28 -
@@ -153,7 +153,6 @@ void xl_stats_update(void *);
 int xl_encap(struct xl_softc *, struct xl_chain *,
 struct mbuf * );
 void xl_rxeof(struct xl_softc *);
-int xl_rx_resync(struct xl_softc *);
 void xl_txeof(struct xl_softc *);
 void xl_txeof_90xB(struct xl_softc *);
 void xl_txeoc(struct xl_softc *);
@@ -180,6 +179,7 @@ void xl_iff(struct xl_softc *);
 void xl_iff_90x(struct xl_softc *);
 void xl_iff_905b(struct xl_softc *);
 int xl_list_rx_init(struct xl_softc *);
+void xl_fill_rx_ring(struct xl_softc *);
 int xl_list_tx_init(struct xl_softc *);
 int xl_list_tx_init_90xB(struct xl_softc *);
 void xl_wait(struct xl_softc *);
@@ -1076,8 +1076,6 @@ xl_list_rx_init(struct xl_softc *sc)
for (i = 0; i  XL_RX_LIST_CNT; i++) {
cd-xl_rx_chain[i].xl_ptr =
(struct xl_list_onefrag *)ld-xl_rx_list[i];
-   if (xl_newbuf(sc, cd-xl_rx_chain[i]) == ENOBUFS)
-   return(ENOBUFS);
if (i == (XL_RX_LIST_CNT - 1))
n = 0;
else
@@ -1088,11 +1086,30 @@ xl_list_rx_init(struct xl_softc *sc)
ld-xl_rx_list[i].xl_next = htole32(next);
}
 
-   cd-xl_rx_head = cd-xl_rx_chain[0];
-
+   cd-xl_rx_prod = cd-xl_rx_cons = cd-xl_rx_chain[0];
+   cd-xl_rx_cnt = 0;
+   xl_fill_rx_ring(sc);
return (0);
 }
 
+void
+xl_fill_rx_ring(struct xl_softc *sc)
+{  
+   struct xl_chain_data*cd;
+   struct xl_list_data *ld;
+
+   cd = sc-xl_cdata;
+   ld = sc-xl_ldata;
+
+   while (cd-xl_rx_cnt  XL_RX_LIST_CNT) {
+   if (xl_newbuf(sc, cd-xl_rx_prod) == ENOBUFS)
+   break;
+   cd-xl_rx_prod = cd-xl_rx_prod-xl_next;
+   cd-xl_rx_cnt++;
+   }
+}
+
+
 /*
  * Initialize an RX descriptor and attach an MBUF cluster.
  */
@@ -1102,13 +1119,9 @@ xl_newbuf(struct xl_softc *sc, struct xl
struct mbuf *m_new = NULL;
bus_dmamap_tmap;
 
-   MGETHDR(m_new, M_DONTWAIT, MT_DATA);
-   if (m_new == NULL)
-   return (ENOBUFS);
-
-   MCLGET(m_new, M_DONTWAIT);
-   if (!(m_new-m_flags  M_EXT)) {
-   m_freem(m_new);
+   m_new = MCLGETI(NULL, M_DONTWAIT, sc-sc_arpcom.ac_if, MCLBYTES);
+   
+   if (!m_new){
return (ENOBUFS);
}
 
@@ -1150,32 +1163,6 @@ xl_newbuf(struct xl_softc *sc, struct xl
return (0);
 }
 
-int
-xl_rx_resync(struct xl_softc *sc)
-{
-   struct xl_chain_onefrag *pos;
-   int i;
-
-   pos = sc-xl_cdata.xl_rx_head;
-
-   for (i = 0; i  XL_RX_LIST_CNT; i++) {
-   bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
-   ((caddr_t)pos-xl_ptr - sc-sc_listkva),
-   sizeof(struct xl_list),
-   BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
-
-   if (pos-xl_ptr-xl_status)
-   break;
-   pos = pos-xl_next;
-   }
-
-   if (i == XL_RX_LIST_CNT)
-   return (0);
-
-   sc-xl_cdata.xl_rx_head = pos;
-
-   return (EAGAIN);
-}
 
 /*
  * A frame has been uploaded: pass the resulting mbuf chain up to
@@ -1195,12 +1182,14 @@ xl_rxeof(struct xl_softc *sc)
 
 again:
 
-   while ((rxstat = letoh32(sc-xl_cdata.xl_rx_head-xl_ptr-xl_status))
-   != 0) {
-   cur_rx = sc-xl_cdata.xl_rx_head;
-   sc-xl_cdata.xl_rx_head = cur_rx-xl_next;
+   while ((rxstat = letoh32(sc-xl_cdata.xl_rx_cons-xl_ptr-xl_status))
+   != 0  sc-xl_cdata.xl_rx_cnt  0) {
+   cur_rx = sc-xl_cdata.xl_rx_cons;
+   m = cur_rx-xl_mbuf;  
+   cur_rx-xl_mbuf = NULL;
+   sc-xl_cdata.xl_rx_cons = cur_rx-xl_next;
+   sc-xl_cdata.xl_rx_cnt--;
total_len = rxstat  XL_RXSTAT_LENMASK;
-
bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
((caddr_t)cur_rx-xl_ptr - sc-sc_listkva),
sizeof(struct xl_list),
@@ -1224,6 +1213,7 @@ again:
if (rxstat  XL_RXSTAT_UP_ERROR) {
ifp-if_ierrors++;
cur_rx-xl_ptr-xl_status = htole32(0);
+   m_freem(m);
continue;
}
 
@@ -1237,22 +1227,7 @@ again:
packet dropped\n, sc-sc_dev.dv_xname);
ifp-if_ierrors++;
cur_rx-xl_ptr-xl_status = htole32(0);
-   continue;
-   }
-
-   /* No errors; receive the packet. */
-   m = cur_rx-xl_mbuf;
-

MCLGETI support for xl(4)

2010-09-16 Thread Loganaden Velvindron
Greetings,

From bryan, fix tabs around while loop.

Index: src/sys/dev/ic/xl.c
===
RCS file: /cvs/src/sys/dev/ic/xl.c,v
retrieving revision 1.96
diff -u -p -r1.96 xl.c
--- src/sys/dev/ic/xl.c 7 Sep 2010 16:21:43 -   1.96
+++ src/sys/dev/ic/xl.c 16 Sep 2010 19:12:18 -
@@ -153,7 +153,6 @@ void xl_stats_update(void *);
 int xl_encap(struct xl_softc *, struct xl_chain *,
 struct mbuf * );
 void xl_rxeof(struct xl_softc *);
-int xl_rx_resync(struct xl_softc *);
 void xl_txeof(struct xl_softc *);
 void xl_txeof_90xB(struct xl_softc *);
 void xl_txeoc(struct xl_softc *);
@@ -180,6 +179,7 @@ void xl_iff(struct xl_softc *);
 void xl_iff_90x(struct xl_softc *);
 void xl_iff_905b(struct xl_softc *);
 int xl_list_rx_init(struct xl_softc *);
+void xl_fill_rx_ring(struct xl_softc *);
 int xl_list_tx_init(struct xl_softc *);
 int xl_list_tx_init_90xB(struct xl_softc *);
 void xl_wait(struct xl_softc *);
@@ -1076,8 +1076,6 @@ xl_list_rx_init(struct xl_softc *sc)
for (i = 0; i  XL_RX_LIST_CNT; i++) {
cd-xl_rx_chain[i].xl_ptr =
(struct xl_list_onefrag *)ld-xl_rx_list[i];
-   if (xl_newbuf(sc, cd-xl_rx_chain[i]) == ENOBUFS)
-   return(ENOBUFS);
if (i == (XL_RX_LIST_CNT - 1))
n = 0;
else
@@ -1088,11 +1086,30 @@ xl_list_rx_init(struct xl_softc *sc)
ld-xl_rx_list[i].xl_next = htole32(next);
}
 
-   cd-xl_rx_head = cd-xl_rx_chain[0];
-
+   cd-xl_rx_prod = cd-xl_rx_cons = cd-xl_rx_chain[0];
+   cd-xl_rx_cnt = 0;
+   xl_fill_rx_ring(sc);
return (0);
 }
 
+void
+xl_fill_rx_ring(struct xl_softc *sc)
+{  
+   struct xl_chain_data*cd;
+   struct xl_list_data *ld;
+
+   cd = sc-xl_cdata;
+   ld = sc-xl_ldata;
+
+   while (cd-xl_rx_cnt  XL_RX_LIST_CNT) {
+   if (xl_newbuf(sc, cd-xl_rx_prod) == ENOBUFS)
+   break;
+   cd-xl_rx_prod = cd-xl_rx_prod-xl_next;
+   cd-xl_rx_cnt++;
+   }
+}
+
+
 /*
  * Initialize an RX descriptor and attach an MBUF cluster.
  */
@@ -1102,13 +1119,9 @@ xl_newbuf(struct xl_softc *sc, struct xl
struct mbuf *m_new = NULL;
bus_dmamap_tmap;
 
-   MGETHDR(m_new, M_DONTWAIT, MT_DATA);
-   if (m_new == NULL)
-   return (ENOBUFS);
-
-   MCLGET(m_new, M_DONTWAIT);
-   if (!(m_new-m_flags  M_EXT)) {
-   m_freem(m_new);
+   m_new = MCLGETI(NULL, M_DONTWAIT, sc-sc_arpcom.ac_if, MCLBYTES);
+   
+   if (!m_new){
return (ENOBUFS);
}
 
@@ -1150,32 +1163,6 @@ xl_newbuf(struct xl_softc *sc, struct xl
return (0);
 }
 
-int
-xl_rx_resync(struct xl_softc *sc)
-{
-   struct xl_chain_onefrag *pos;
-   int i;
-
-   pos = sc-xl_cdata.xl_rx_head;
-
-   for (i = 0; i  XL_RX_LIST_CNT; i++) {
-   bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
-   ((caddr_t)pos-xl_ptr - sc-sc_listkva),
-   sizeof(struct xl_list),
-   BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
-
-   if (pos-xl_ptr-xl_status)
-   break;
-   pos = pos-xl_next;
-   }
-
-   if (i == XL_RX_LIST_CNT)
-   return (0);
-
-   sc-xl_cdata.xl_rx_head = pos;
-
-   return (EAGAIN);
-}
 
 /*
  * A frame has been uploaded: pass the resulting mbuf chain up to
@@ -1195,12 +1182,14 @@ xl_rxeof(struct xl_softc *sc)
 
 again:
 
-   while ((rxstat = letoh32(sc-xl_cdata.xl_rx_head-xl_ptr-xl_status))
-   != 0) {
-   cur_rx = sc-xl_cdata.xl_rx_head;
-   sc-xl_cdata.xl_rx_head = cur_rx-xl_next;
+   while ((rxstat = letoh32(sc-xl_cdata.xl_rx_cons-xl_ptr-xl_status))
+   != 0  sc-xl_cdata.xl_rx_cnt  0) {
+   cur_rx = sc-xl_cdata.xl_rx_cons;
+   m = cur_rx-xl_mbuf;  
+   cur_rx-xl_mbuf = NULL;
+   sc-xl_cdata.xl_rx_cons = cur_rx-xl_next;
+   sc-xl_cdata.xl_rx_cnt--;
total_len = rxstat  XL_RXSTAT_LENMASK;
-
bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
((caddr_t)cur_rx-xl_ptr - sc-sc_listkva),
sizeof(struct xl_list),
@@ -1224,6 +1213,7 @@ again:
if (rxstat  XL_RXSTAT_UP_ERROR) {
ifp-if_ierrors++;
cur_rx-xl_ptr-xl_status = htole32(0);
+   m_freem(m);
continue;
}
 
@@ -1237,22 +1227,7 @@ again:
packet dropped\n, sc-sc_dev.dv_xname);
ifp-if_ierrors++;
cur_rx-xl_ptr-xl_status = htole32(0);
-   continue;
-   }
-
-   /* No errors; receive the packet. */
-   m = cur_rx-xl_mbuf;
-
-  

MCLGETI support for xl(4)

2010-09-16 Thread Loganaden Velvindron
Greetings,

From brad, remove superfluous braces.

Index: src/sys/dev/ic/xl.c
===
RCS file: /cvs/src/sys/dev/ic/xl.c,v
retrieving revision 1.96
diff -u -p -r1.96 xl.c
--- src/sys/dev/ic/xl.c 7 Sep 2010 16:21:43 -   1.96
+++ src/sys/dev/ic/xl.c 16 Sep 2010 19:36:53 -
@@ -153,7 +153,6 @@ void xl_stats_update(void *);
 int xl_encap(struct xl_softc *, struct xl_chain *,
 struct mbuf * );
 void xl_rxeof(struct xl_softc *);
-int xl_rx_resync(struct xl_softc *);
 void xl_txeof(struct xl_softc *);
 void xl_txeof_90xB(struct xl_softc *);
 void xl_txeoc(struct xl_softc *);
@@ -180,6 +179,7 @@ void xl_iff(struct xl_softc *);
 void xl_iff_90x(struct xl_softc *);
 void xl_iff_905b(struct xl_softc *);
 int xl_list_rx_init(struct xl_softc *);
+void xl_fill_rx_ring(struct xl_softc *);
 int xl_list_tx_init(struct xl_softc *);
 int xl_list_tx_init_90xB(struct xl_softc *);
 void xl_wait(struct xl_softc *);
@@ -1076,8 +1076,6 @@ xl_list_rx_init(struct xl_softc *sc)
for (i = 0; i  XL_RX_LIST_CNT; i++) {
cd-xl_rx_chain[i].xl_ptr =
(struct xl_list_onefrag *)ld-xl_rx_list[i];
-   if (xl_newbuf(sc, cd-xl_rx_chain[i]) == ENOBUFS)
-   return(ENOBUFS);
if (i == (XL_RX_LIST_CNT - 1))
n = 0;
else
@@ -1088,11 +1086,30 @@ xl_list_rx_init(struct xl_softc *sc)
ld-xl_rx_list[i].xl_next = htole32(next);
}
 
-   cd-xl_rx_head = cd-xl_rx_chain[0];
-
+   cd-xl_rx_prod = cd-xl_rx_cons = cd-xl_rx_chain[0];
+   cd-xl_rx_cnt = 0;
+   xl_fill_rx_ring(sc);
return (0);
 }
 
+void
+xl_fill_rx_ring(struct xl_softc *sc)
+{  
+   struct xl_chain_data*cd;
+   struct xl_list_data *ld;
+
+   cd = sc-xl_cdata;
+   ld = sc-xl_ldata;
+
+   while (cd-xl_rx_cnt  XL_RX_LIST_CNT) {
+   if (xl_newbuf(sc, cd-xl_rx_prod) == ENOBUFS)
+   break;
+   cd-xl_rx_prod = cd-xl_rx_prod-xl_next;
+   cd-xl_rx_cnt++;
+   }
+}
+
+
 /*
  * Initialize an RX descriptor and attach an MBUF cluster.
  */
@@ -1102,15 +1119,10 @@ xl_newbuf(struct xl_softc *sc, struct xl
struct mbuf *m_new = NULL;
bus_dmamap_tmap;
 
-   MGETHDR(m_new, M_DONTWAIT, MT_DATA);
-   if (m_new == NULL)
-   return (ENOBUFS);
-
-   MCLGET(m_new, M_DONTWAIT);
-   if (!(m_new-m_flags  M_EXT)) {
-   m_freem(m_new);
+   m_new = MCLGETI(NULL, M_DONTWAIT, sc-sc_arpcom.ac_if, MCLBYTES);
+   
+   if (!m_new)
return (ENOBUFS);
-   }
 
m_new-m_len = m_new-m_pkthdr.len = MCLBYTES;
if (bus_dmamap_load(sc-sc_dmat, sc-sc_rx_sparemap,
@@ -1150,32 +1162,6 @@ xl_newbuf(struct xl_softc *sc, struct xl
return (0);
 }
 
-int
-xl_rx_resync(struct xl_softc *sc)
-{
-   struct xl_chain_onefrag *pos;
-   int i;
-
-   pos = sc-xl_cdata.xl_rx_head;
-
-   for (i = 0; i  XL_RX_LIST_CNT; i++) {
-   bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
-   ((caddr_t)pos-xl_ptr - sc-sc_listkva),
-   sizeof(struct xl_list),
-   BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
-
-   if (pos-xl_ptr-xl_status)
-   break;
-   pos = pos-xl_next;
-   }
-
-   if (i == XL_RX_LIST_CNT)
-   return (0);
-
-   sc-xl_cdata.xl_rx_head = pos;
-
-   return (EAGAIN);
-}
 
 /*
  * A frame has been uploaded: pass the resulting mbuf chain up to
@@ -1195,12 +1181,14 @@ xl_rxeof(struct xl_softc *sc)
 
 again:
 
-   while ((rxstat = letoh32(sc-xl_cdata.xl_rx_head-xl_ptr-xl_status))
-   != 0) {
-   cur_rx = sc-xl_cdata.xl_rx_head;
-   sc-xl_cdata.xl_rx_head = cur_rx-xl_next;
+   while ((rxstat = letoh32(sc-xl_cdata.xl_rx_cons-xl_ptr-xl_status))
+   != 0  sc-xl_cdata.xl_rx_cnt  0) {
+   cur_rx = sc-xl_cdata.xl_rx_cons;
+   m = cur_rx-xl_mbuf;  
+   cur_rx-xl_mbuf = NULL;
+   sc-xl_cdata.xl_rx_cons = cur_rx-xl_next;
+   sc-xl_cdata.xl_rx_cnt--;
total_len = rxstat  XL_RXSTAT_LENMASK;
-
bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
((caddr_t)cur_rx-xl_ptr - sc-sc_listkva),
sizeof(struct xl_list),
@@ -1224,6 +1212,7 @@ again:
if (rxstat  XL_RXSTAT_UP_ERROR) {
ifp-if_ierrors++;
cur_rx-xl_ptr-xl_status = htole32(0);
+   m_freem(m);
continue;
}
 
@@ -1237,22 +1226,7 @@ again:
packet dropped\n, sc-sc_dev.dv_xname);
ifp-if_ierrors++;
cur_rx-xl_ptr-xl_status = htole32(0);
-   continue;
-   

MCLGETI support for xl(4)

2010-09-13 Thread Loganaden Velvindron

Greetings,

With help from dlg@, claudio@, oga@, miod@  @weerd, I've been trying to 
write

to get mclgeti support for xl(4).

It's been working fine on -current for quite some time.

I've tried flooding it with tcpbench, ping -f, and siege.

I'm looking for feedback on how I can improve it.

Here's the diff:

xlreg.h

Index: src/sys/dev/ic/xlreg.h
===
RCS file: /cvs/src/sys/dev/ic/xlreg.h,v
retrieving revision 1.24
diff -u -p -r1.24 xlreg.h
--- src/sys/dev/ic/xlreg.h  7 Sep 2010 16:21:43 -   1.24
+++ src/sys/dev/ic/xlreg.h  12 Sep 2010 06:33:39 -
@@ -480,7 +480,10 @@ struct xl_chain_data {
   struct xl_chain_onefrag xl_rx_chain[XL_RX_LIST_CNT];
   struct xl_chain xl_tx_chain[XL_TX_LIST_CNT];

-   struct xl_chain_onefrag *xl_rx_head;
+   struct xl_chain_onefrag *xl_rx_cons;
+struct xl_chain_onefrag *xl_rx_prod;
+int  xl_rx_cnt;
+

   /* 3c90x boomerang queuing stuff */
   struct xl_chain *xl_tx_head;

xl.c

Index: src/sys/dev/ic/xl.c
===
RCS file: /cvs/src/sys/dev/ic/xl.c,v
retrieving revision 1.96
diff -u -p -r1.96 xl.c
--- src/sys/dev/ic/xl.c 7 Sep 2010 16:21:43 -   1.96
+++ src/sys/dev/ic/xl.c 12 Sep 2010 10:49:32 -
@@ -180,6 +180,7 @@ void xl_iff(struct xl_softc *);
void xl_iff_90x(struct xl_softc *);
void xl_iff_905b(struct xl_softc *);
int xl_list_rx_init(struct xl_softc *);
+void xl_fill_rx_ring(struct xl_softc *);
int xl_list_tx_init(struct xl_softc *);
int xl_list_tx_init_90xB(struct xl_softc *);
void xl_wait(struct xl_softc *);
@@ -1076,8 +1077,8 @@ xl_list_rx_init(struct xl_softc *sc)
   for (i = 0; i  XL_RX_LIST_CNT; i++) {
   cd-xl_rx_chain[i].xl_ptr =
   (struct xl_list_onefrag *)ld-xl_rx_list[i];
-   if (xl_newbuf(sc, cd-xl_rx_chain[i]) == ENOBUFS)
-   return(ENOBUFS);
+   /*if (xl_newbuf(sc, cd-xl_rx_chain[i]) == ENOBUFS)
+   return(ENOBUFS);*/
   if (i == (XL_RX_LIST_CNT - 1))
   n = 0;
   else
@@ -1088,11 +1089,33 @@ xl_list_rx_init(struct xl_softc *sc)
   ld-xl_rx_list[i].xl_next = htole32(next);
   }

-   cd-xl_rx_head = cd-xl_rx_chain[0];
-
+   cd-xl_rx_prod = cd-xl_rx_cons = cd-xl_rx_chain[0];
+   cd-xl_rx_cnt = 0;
+   xl_fill_rx_ring(sc);
   return (0);
}

+void
+xl_fill_rx_ring(struct xl_softc *sc)
+{ 
+struct xl_chain_data*cd;

+struct xl_list_data *ld;
+
+cd = sc-xl_cdata;
+ld = sc-xl_ldata;
+
+while (cd-xl_rx_cnt  XL_RX_LIST_CNT) {
+if (xl_newbuf(sc, cd-xl_rx_prod) == ENOBUFS){
+/*printf(Not filling);*/
+break;
+}
+cd-xl_rx_prod = cd-xl_rx_prod-xl_next;
+cd-xl_rx_cnt++;
+/*printf(filling works %d,cd-xl_rx_cnt);*/
+}
+}
+
+
/*
 * Initialize an RX descriptor and attach an MBUF cluster.
 */
@@ -1102,7 +1125,7 @@ xl_newbuf(struct xl_softc *sc, struct xl
   struct mbuf *m_new = NULL;
   bus_dmamap_tmap;

-   MGETHDR(m_new, M_DONTWAIT, MT_DATA);
+   /*MGETHDR(m_new, M_DONTWAIT, MT_DATA);
   if (m_new == NULL)
   return (ENOBUFS);

@@ -1110,6 +1133,13 @@ xl_newbuf(struct xl_softc *sc, struct xl
   if (!(m_new-m_flags  M_EXT)) {
   m_freem(m_new);
   return (ENOBUFS);
+   }*/
+
+   m_new = MCLGETI(NULL, M_DONTWAIT, sc-sc_arpcom.ac_if, MCLBYTES);
+  
+   if (!m_new){

+   /*printf(\n no mbufs);*/
+   return (ENOBUFS);
   }

   m_new-m_len = m_new-m_pkthdr.len = MCLBYTES;
@@ -1119,17 +1149,24 @@ xl_newbuf(struct xl_softc *sc, struct xl
   return (ENOBUFS);
   }

+
+/*if (bus_dmamap_load_mbuf(sc-sc_dmat, c-map, m_new, 
BUS_DMA_NOWAIT)){

+m_free(m_new);
+return (ENOBUFS);
+}*/
+  
+

   /* sync the old map, and unload it (if necessary) */
   if (c-map-dm_nsegs != 0) {
   bus_dmamap_sync(sc-sc_dmat, c-map,
   0, c-map-dm_mapsize, BUS_DMASYNC_POSTREAD);
   bus_dmamap_unload(sc-sc_dmat, c-map);
   }
-
+  
   map = c-map;

   c-map = sc-sc_rx_sparemap;
   sc-sc_rx_sparemap = map;
-
+  
   /* Force longword alignment for packet payload. */

   m_adj(m_new, ETHER_ALIGN);

@@ -1156,8 +1193,8 @@ xl_rx_resync(struct xl_softc *sc)
   struct xl_chain_onefrag *pos;
   int i;

-   pos = sc-xl_cdata.xl_rx_head;
-
+   pos = sc-xl_cdata.xl_rx_cons;
+   printf(\n resync);  
   for (i = 0; i  XL_RX_LIST_CNT; i++) {

   bus_dmamap_sync(sc-sc_dmat, sc-sc_listmap,
   ((caddr_t)pos-xl_ptr - sc-sc_listkva

Re: MCLGETI support for xl(4)

2010-09-13 Thread Stuart Henderson
On 2010/09/15 00:31, Loganaden Velvindron wrote:
 Here's the diff:

Diff doesn't apply; both due to whitespace issues (xclip might
help with this) and if you're using thunderbird to send then
please disable format=flowed.