Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
0003  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
0004  * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
0005  *
0006  * This software is available to you under a choice of one of two
0007  * licenses.  You may choose to be licensed under the terms of the GNU
0008  * General Public License (GPL) Version 2, available from the file
0009  * COPYING in the main directory of this source tree, or the
0010  * OpenIB.org BSD license below:
0011  *
0012  *     Redistribution and use in source and binary forms, with or
0013  *     without modification, are permitted provided that the following
0014  *     conditions are met:
0015  *
0016  *      - Redistributions of source code must retain the above
0017  *        copyright notice, this list of conditions and the following
0018  *        disclaimer.
0019  *
0020  *      - Redistributions in binary form must reproduce the above
0021  *        copyright notice, this list of conditions and the following
0022  *        disclaimer in the documentation and/or other materials
0023  *        provided with the distribution.
0024  *
0025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0026  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0027  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0028  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0029  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0030  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0031  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0032  * SOFTWARE.
0033  */
0034 
0035 #include <linux/types.h>
0036 
0037 #define MTHCA_RD_DOORBELL      0x00
0038 #define MTHCA_SEND_DOORBELL    0x10
0039 #define MTHCA_RECEIVE_DOORBELL 0x18
0040 #define MTHCA_CQ_DOORBELL      0x20
0041 #define MTHCA_EQ_DOORBELL      0x28
0042 
0043 #if BITS_PER_LONG == 64
0044 /*
0045  * Assume that we can just write a 64-bit doorbell atomically.  s390
0046  * actually doesn't have writeq() but S/390 systems don't even have
0047  * PCI so we won't worry about it.
0048  */
0049 
0050 #define MTHCA_DECLARE_DOORBELL_LOCK(name)
0051 #define MTHCA_INIT_DOORBELL_LOCK(ptr)    do { } while (0)
0052 #define MTHCA_GET_DOORBELL_LOCK(ptr)      (NULL)
0053 
0054 static inline void mthca_write64_raw(__be64 val, void __iomem *dest)
0055 {
0056     __raw_writeq((__force u64) val, dest);
0057 }
0058 
0059 static inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest,
0060                  spinlock_t *doorbell_lock)
0061 {
0062     __raw_writeq((__force u64) cpu_to_be64((u64) hi << 32 | lo), dest);
0063 }
0064 
0065 static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)
0066 {
0067     *(u64 *) db = *(u64 *) val;
0068 }
0069 
0070 #else
0071 
0072 /*
0073  * Just fall back to a spinlock to protect the doorbell if
0074  * BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit
0075  * MMIO writes.
0076  */
0077 
0078 #define MTHCA_DECLARE_DOORBELL_LOCK(name) spinlock_t name;
0079 #define MTHCA_INIT_DOORBELL_LOCK(ptr)     spin_lock_init(ptr)
0080 #define MTHCA_GET_DOORBELL_LOCK(ptr)      (ptr)
0081 
0082 static inline void mthca_write64_raw(__be64 val, void __iomem *dest)
0083 {
0084     __raw_writel(((__force u32 *) &val)[0], dest);
0085     __raw_writel(((__force u32 *) &val)[1], dest + 4);
0086 }
0087 
0088 static inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest,
0089                  spinlock_t *doorbell_lock)
0090 {
0091     unsigned long flags;
0092 
0093     hi = (__force u32) cpu_to_be32(hi);
0094     lo = (__force u32) cpu_to_be32(lo);
0095 
0096     spin_lock_irqsave(doorbell_lock, flags);
0097     __raw_writel(hi, dest);
0098     __raw_writel(lo, dest + 4);
0099     spin_unlock_irqrestore(doorbell_lock, flags);
0100 }
0101 
0102 static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)
0103 {
0104     db[0] = val[0];
0105     wmb();
0106     db[1] = val[1];
0107 }
0108 
0109 #endif