18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2004 Topspin Communications. All rights reserved. 38c2ecf20Sopenharmony_ci * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 48c2ecf20Sopenharmony_ci * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 78c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the 108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below: 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or 138c2ecf20Sopenharmony_ci * without modification, are permitted provided that the following 148c2ecf20Sopenharmony_ci * conditions are met: 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above 178c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 188c2ecf20Sopenharmony_ci * disclaimer. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above 218c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 228c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials 238c2ecf20Sopenharmony_ci * provided with the distribution. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 328c2ecf20Sopenharmony_ci * SOFTWARE. 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include <linux/types.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define MTHCA_RD_DOORBELL 0x00 388c2ecf20Sopenharmony_ci#define MTHCA_SEND_DOORBELL 0x10 398c2ecf20Sopenharmony_ci#define MTHCA_RECEIVE_DOORBELL 0x18 408c2ecf20Sopenharmony_ci#define MTHCA_CQ_DOORBELL 0x20 418c2ecf20Sopenharmony_ci#define MTHCA_EQ_DOORBELL 0x28 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 64 448c2ecf20Sopenharmony_ci/* 458c2ecf20Sopenharmony_ci * Assume that we can just write a 64-bit doorbell atomically. s390 468c2ecf20Sopenharmony_ci * actually doesn't have writeq() but S/390 systems don't even have 478c2ecf20Sopenharmony_ci * PCI so we won't worry about it. 488c2ecf20Sopenharmony_ci */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define MTHCA_DECLARE_DOORBELL_LOCK(name) 518c2ecf20Sopenharmony_ci#define MTHCA_INIT_DOORBELL_LOCK(ptr) do { } while (0) 528c2ecf20Sopenharmony_ci#define MTHCA_GET_DOORBELL_LOCK(ptr) (NULL) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic inline void mthca_write64_raw(__be64 val, void __iomem *dest) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci __raw_writeq((__force u64) val, dest); 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest, 608c2ecf20Sopenharmony_ci spinlock_t *doorbell_lock) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci __raw_writeq((__force u64) cpu_to_be64((u64) hi << 32 | lo), dest); 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic inline void mthca_write_db_rec(__be32 val[2], __be32 *db) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci *(u64 *) db = *(u64 *) val; 688c2ecf20Sopenharmony_ci} 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#else 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* 738c2ecf20Sopenharmony_ci * Just fall back to a spinlock to protect the doorbell if 748c2ecf20Sopenharmony_ci * BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit 758c2ecf20Sopenharmony_ci * MMIO writes. 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define MTHCA_DECLARE_DOORBELL_LOCK(name) spinlock_t name; 798c2ecf20Sopenharmony_ci#define MTHCA_INIT_DOORBELL_LOCK(ptr) spin_lock_init(ptr) 808c2ecf20Sopenharmony_ci#define MTHCA_GET_DOORBELL_LOCK(ptr) (ptr) 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic inline void mthca_write64_raw(__be64 val, void __iomem *dest) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci __raw_writel(((__force u32 *) &val)[0], dest); 858c2ecf20Sopenharmony_ci __raw_writel(((__force u32 *) &val)[1], dest + 4); 868c2ecf20Sopenharmony_ci} 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest, 898c2ecf20Sopenharmony_ci spinlock_t *doorbell_lock) 908c2ecf20Sopenharmony_ci{ 918c2ecf20Sopenharmony_ci unsigned long flags; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci hi = (__force u32) cpu_to_be32(hi); 948c2ecf20Sopenharmony_ci lo = (__force u32) cpu_to_be32(lo); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci spin_lock_irqsave(doorbell_lock, flags); 978c2ecf20Sopenharmony_ci __raw_writel(hi, dest); 988c2ecf20Sopenharmony_ci __raw_writel(lo, dest + 4); 998c2ecf20Sopenharmony_ci spin_unlock_irqrestore(doorbell_lock, flags); 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline void mthca_write_db_rec(__be32 val[2], __be32 *db) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci db[0] = val[0]; 1058c2ecf20Sopenharmony_ci wmb(); 1068c2ecf20Sopenharmony_ci db[1] = val[1]; 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#endif 110