Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*


  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * This file is part of the Chelsio T1 Ethernet driver.
  29  *
  30  * Copyright (C) 2003-2005 Chelsio Communications.  All rights reserved.
  31  */
  32 
  33 /*
  34  * Solaris Multithreaded STREAMS Chelsio PCI Ethernet Driver.
  35  * Interface code
  36  */
  37 
  38 #pragma ident   "%Z%%M% %I%     %E% SMI"
  39 
  40 #include <sys/types.h>
  41 #include <sys/systm.h>
  42 #include <sys/cmn_err.h>
  43 #include <sys/ddi.h>
  44 #include <sys/sunddi.h>
  45 #include <sys/byteorder.h>
  46 #include <sys/atomic.h>
  47 #include <sys/ethernet.h>
  48 #if PE_PROFILING_ENABLED
  49 #include <sys/time.h>
  50 #endif
  51 #include <sys/gld.h>
  52 #include "ostypes.h"
  53 #include "common.h"
  54 #include "oschtoe.h"
  55 #ifdef CONFIG_CHELSIO_T1_1G
  56 #include "fpga_defs.h"
  57 #endif
  58 #include "regs.h"
  59 #ifdef CONFIG_CHELSIO_T1_OFFLOAD


1373 
1374         if (rbp->cs_flag) {
1375                 uint32_t i;
1376                 /*
1377                  * free private buffer allocated in ch_alloc_esbbuf()
1378                  */
1379                 ch_free_dma_mem(rbp->cs_dh, rbp->cs_ah);
1380 
1381                 i = rbp->cs_index;
1382 
1383                 /*
1384                  * free descripter buffer
1385                  */
1386                 kmem_free(rbp, sizeof (ch_esb_t));
1387 
1388                 /*
1389                  * decrement count of receive buffers freed by callback
1390                  * We decrement here so anyone trying to do fini will
1391                  * only remove the driver once the counts go to 0.
1392                  */
1393                 atomic_add_32(&buffers_in_use[i], -1);
1394 
1395                 return;
1396         }
1397 
1398         mutex_enter(&sa->ch_small_esbl);
1399         rbp->cs_next = sa->ch_small_esb_free;
1400         sa->ch_small_esb_free = rbp;
1401         mutex_exit(&sa->ch_small_esbl);
1402 
1403         /*
1404          * decrement count of receive buffers freed by callback
1405          */
1406         atomic_add_32(&buffers_in_use[rbp->cs_index], -1);
1407 }
1408 
1409 /*
1410  * callback function from freeb() when esballoced mblk freed.
1411  */
1412 void
1413 ch_big_rbuf_recycle(ch_esb_t *rbp)
1414 {
1415         ch_t *sa = rbp->cs_sa;
1416 
1417         if (rbp->cs_flag) {
1418                 uint32_t i;
1419                 /*
1420                  * free private buffer allocated in ch_alloc_esbbuf()
1421                  */
1422                 ch_free_dma_mem(rbp->cs_dh, rbp->cs_ah);
1423 
1424                 i = rbp->cs_index;
1425 
1426                 /*
1427                  * free descripter buffer
1428                  */
1429                 kmem_free(rbp, sizeof (ch_esb_t));
1430 
1431                 /*
1432                  * decrement count of receive buffers freed by callback
1433                  * We decrement here so anyone trying to do fini will
1434                  * only remove the driver once the counts go to 0.
1435                  */
1436                 atomic_add_32(&buffers_in_use[i], -1);
1437 
1438                 return;
1439         }
1440 
1441         mutex_enter(&sa->ch_big_esbl);
1442         rbp->cs_next = sa->ch_big_esb_free;
1443         sa->ch_big_esb_free = rbp;
1444         mutex_exit(&sa->ch_big_esbl);
1445 
1446         /*
1447          * decrement count of receive buffers freed by callback
1448          */
1449         atomic_add_32(&buffers_in_use[rbp->cs_index], -1);
1450 }
1451 
1452 /*
1453  * get a pre-allocated, pre-mapped receive buffer from free list.
1454  * (used sge.c)
1455  */
1456 ch_esb_t *
1457 ch_get_small_rbuf(ch_t *sa)
1458 {
1459         ch_esb_t *rbp;
1460 
1461         mutex_enter(&sa->ch_small_esbl);
1462         rbp = sa->ch_small_esb_free;
1463         if (rbp) {
1464                 sa->ch_small_esb_free = rbp->cs_next;
1465         }
1466         mutex_exit(&sa->ch_small_esbl);
1467 
1468         return (rbp);
1469 }




  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * This file is part of the Chelsio T1 Ethernet driver.
  29  *
  30  * Copyright (C) 2003-2005 Chelsio Communications.  All rights reserved.
  31  */
  32 
  33 /*
  34  * Solaris Multithreaded STREAMS Chelsio PCI Ethernet Driver.
  35  * Interface code
  36  */
  37 


  38 #include <sys/types.h>
  39 #include <sys/systm.h>
  40 #include <sys/cmn_err.h>
  41 #include <sys/ddi.h>
  42 #include <sys/sunddi.h>
  43 #include <sys/byteorder.h>
  44 #include <sys/atomic.h>
  45 #include <sys/ethernet.h>
  46 #if PE_PROFILING_ENABLED
  47 #include <sys/time.h>
  48 #endif
  49 #include <sys/gld.h>
  50 #include "ostypes.h"
  51 #include "common.h"
  52 #include "oschtoe.h"
  53 #ifdef CONFIG_CHELSIO_T1_1G
  54 #include "fpga_defs.h"
  55 #endif
  56 #include "regs.h"
  57 #ifdef CONFIG_CHELSIO_T1_OFFLOAD


1371 
1372         if (rbp->cs_flag) {
1373                 uint32_t i;
1374                 /*
1375                  * free private buffer allocated in ch_alloc_esbbuf()
1376                  */
1377                 ch_free_dma_mem(rbp->cs_dh, rbp->cs_ah);
1378 
1379                 i = rbp->cs_index;
1380 
1381                 /*
1382                  * free descripter buffer
1383                  */
1384                 kmem_free(rbp, sizeof (ch_esb_t));
1385 
1386                 /*
1387                  * decrement count of receive buffers freed by callback
1388                  * We decrement here so anyone trying to do fini will
1389                  * only remove the driver once the counts go to 0.
1390                  */
1391                 atomic_dec_32(&buffers_in_use[i]);
1392 
1393                 return;
1394         }
1395 
1396         mutex_enter(&sa->ch_small_esbl);
1397         rbp->cs_next = sa->ch_small_esb_free;
1398         sa->ch_small_esb_free = rbp;
1399         mutex_exit(&sa->ch_small_esbl);
1400 
1401         /*
1402          * decrement count of receive buffers freed by callback
1403          */
1404         atomic_dec_32(&buffers_in_use[rbp->cs_index]);
1405 }
1406 
1407 /*
1408  * callback function from freeb() when esballoced mblk freed.
1409  */
1410 void
1411 ch_big_rbuf_recycle(ch_esb_t *rbp)
1412 {
1413         ch_t *sa = rbp->cs_sa;
1414 
1415         if (rbp->cs_flag) {
1416                 uint32_t i;
1417                 /*
1418                  * free private buffer allocated in ch_alloc_esbbuf()
1419                  */
1420                 ch_free_dma_mem(rbp->cs_dh, rbp->cs_ah);
1421 
1422                 i = rbp->cs_index;
1423 
1424                 /*
1425                  * free descripter buffer
1426                  */
1427                 kmem_free(rbp, sizeof (ch_esb_t));
1428 
1429                 /*
1430                  * decrement count of receive buffers freed by callback
1431                  * We decrement here so anyone trying to do fini will
1432                  * only remove the driver once the counts go to 0.
1433                  */
1434                 atomic_dec_32(&buffers_in_use[i]);
1435 
1436                 return;
1437         }
1438 
1439         mutex_enter(&sa->ch_big_esbl);
1440         rbp->cs_next = sa->ch_big_esb_free;
1441         sa->ch_big_esb_free = rbp;
1442         mutex_exit(&sa->ch_big_esbl);
1443 
1444         /*
1445          * decrement count of receive buffers freed by callback
1446          */
1447         atomic_dec_32(&buffers_in_use[rbp->cs_index]);
1448 }
1449 
1450 /*
1451  * get a pre-allocated, pre-mapped receive buffer from free list.
1452  * (used sge.c)
1453  */
1454 ch_esb_t *
1455 ch_get_small_rbuf(ch_t *sa)
1456 {
1457         ch_esb_t *rbp;
1458 
1459         mutex_enter(&sa->ch_small_esbl);
1460         rbp = sa->ch_small_esb_free;
1461         if (rbp) {
1462                 sa->ch_small_esb_free = rbp->cs_next;
1463         }
1464         mutex_exit(&sa->ch_small_esbl);
1465 
1466         return (rbp);
1467 }