197549c34SHans Petter Selasky /*
297549c34SHans Petter Selasky * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
397549c34SHans Petter Selasky *
497549c34SHans Petter Selasky * This software is available to you under a choice of one of two
597549c34SHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU
697549c34SHans Petter Selasky * General Public License (GPL) Version 2, available from the file
797549c34SHans Petter Selasky * COPYING in the main directory of this source tree, or the
897549c34SHans Petter Selasky * OpenIB.org BSD license below:
997549c34SHans Petter Selasky *
1097549c34SHans Petter Selasky * Redistribution and use in source and binary forms, with or
1197549c34SHans Petter Selasky * without modification, are permitted provided that the following
1297549c34SHans Petter Selasky * conditions are met:
1397549c34SHans Petter Selasky *
1497549c34SHans Petter Selasky * - Redistributions of source code must retain the above
1597549c34SHans Petter Selasky * copyright notice, this list of conditions and the following
1697549c34SHans Petter Selasky * disclaimer.
1797549c34SHans Petter Selasky *
1897549c34SHans Petter Selasky * - Redistributions in binary form must reproduce the above
1997549c34SHans Petter Selasky * copyright notice, this list of conditions and the following
2097549c34SHans Petter Selasky * disclaimer in the documentation and/or other materials
2197549c34SHans Petter Selasky * provided with the distribution.
2297549c34SHans Petter Selasky *
2397549c34SHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2497549c34SHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2597549c34SHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2697549c34SHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2797549c34SHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2897549c34SHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2997549c34SHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3097549c34SHans Petter Selasky * SOFTWARE.
3197549c34SHans Petter Selasky */
3297549c34SHans Petter Selasky
3397549c34SHans Petter Selasky #ifndef MLX4_CQ_H
3497549c34SHans Petter Selasky #define MLX4_CQ_H
3597549c34SHans Petter Selasky
3697549c34SHans Petter Selasky #include <linux/types.h>
3797549c34SHans Petter Selasky
3897549c34SHans Petter Selasky #include <dev/mlx4/device.h>
3997549c34SHans Petter Selasky #include <dev/mlx4/doorbell.h>
4097549c34SHans Petter Selasky
4197549c34SHans Petter Selasky struct mlx4_cqe {
4297549c34SHans Petter Selasky __be32 vlan_my_qpn;
4397549c34SHans Petter Selasky __be32 immed_rss_invalid;
4497549c34SHans Petter Selasky __be32 g_mlpath_rqpn;
4597549c34SHans Petter Selasky __be16 sl_vid;
46c3191c2eSHans Petter Selasky union {
47c3191c2eSHans Petter Selasky struct {
4897549c34SHans Petter Selasky __be16 rlid;
4997549c34SHans Petter Selasky __be16 status;
5097549c34SHans Petter Selasky u8 ipv6_ext_mask;
5197549c34SHans Petter Selasky u8 badfcs_enc;
5297549c34SHans Petter Selasky };
53c3191c2eSHans Petter Selasky u8 smac[ETH_ALEN];
5497549c34SHans Petter Selasky };
5597549c34SHans Petter Selasky __be32 byte_cnt;
5697549c34SHans Petter Selasky __be16 wqe_index;
5797549c34SHans Petter Selasky __be16 checksum;
58c3191c2eSHans Petter Selasky u8 reserved[3];
5997549c34SHans Petter Selasky u8 owner_sr_opcode;
60c3191c2eSHans Petter Selasky };
6197549c34SHans Petter Selasky
6297549c34SHans Petter Selasky struct mlx4_err_cqe {
6397549c34SHans Petter Selasky __be32 my_qpn;
6497549c34SHans Petter Selasky u32 reserved1[5];
6597549c34SHans Petter Selasky __be16 wqe_index;
6697549c34SHans Petter Selasky u8 vendor_err_syndrome;
6797549c34SHans Petter Selasky u8 syndrome;
6897549c34SHans Petter Selasky u8 reserved2[3];
6997549c34SHans Petter Selasky u8 owner_sr_opcode;
7097549c34SHans Petter Selasky };
7197549c34SHans Petter Selasky
7297549c34SHans Petter Selasky struct mlx4_ts_cqe {
7397549c34SHans Petter Selasky __be32 vlan_my_qpn;
7497549c34SHans Petter Selasky __be32 immed_rss_invalid;
7597549c34SHans Petter Selasky __be32 g_mlpath_rqpn;
7697549c34SHans Petter Selasky __be32 timestamp_hi;
7797549c34SHans Petter Selasky __be16 status;
7897549c34SHans Petter Selasky u8 ipv6_ext_mask;
7997549c34SHans Petter Selasky u8 badfcs_enc;
8097549c34SHans Petter Selasky __be32 byte_cnt;
8197549c34SHans Petter Selasky __be16 wqe_index;
8297549c34SHans Petter Selasky __be16 checksum;
8397549c34SHans Petter Selasky u8 reserved;
8497549c34SHans Petter Selasky __be16 timestamp_lo;
8597549c34SHans Petter Selasky u8 owner_sr_opcode;
8697549c34SHans Petter Selasky } __packed;
8797549c34SHans Petter Selasky
8897549c34SHans Petter Selasky enum {
89*02ca39cfSEitan Adler MLX4_CQE_L2_TUNNEL_IPOK = 1U << 31,
90c3191c2eSHans Petter Selasky MLX4_CQE_CVLAN_PRESENT_MASK = 1 << 29,
91c3191c2eSHans Petter Selasky MLX4_CQE_SVLAN_PRESENT_MASK = 1 << 30,
92c3191c2eSHans Petter Selasky MLX4_CQE_L2_TUNNEL = 1 << 27,
93c3191c2eSHans Petter Selasky MLX4_CQE_L2_TUNNEL_CSUM = 1 << 26,
94c3191c2eSHans Petter Selasky MLX4_CQE_L2_TUNNEL_IPV4 = 1 << 25,
95c3191c2eSHans Petter Selasky
9697549c34SHans Petter Selasky MLX4_CQE_QPN_MASK = 0xffffff,
9797549c34SHans Petter Selasky MLX4_CQE_VID_MASK = 0xfff,
9897549c34SHans Petter Selasky };
9997549c34SHans Petter Selasky
10097549c34SHans Petter Selasky enum {
10197549c34SHans Petter Selasky MLX4_CQE_OWNER_MASK = 0x80,
10297549c34SHans Petter Selasky MLX4_CQE_IS_SEND_MASK = 0x40,
10397549c34SHans Petter Selasky MLX4_CQE_OPCODE_MASK = 0x1f
10497549c34SHans Petter Selasky };
10597549c34SHans Petter Selasky
10697549c34SHans Petter Selasky enum {
10797549c34SHans Petter Selasky MLX4_CQE_SYNDROME_LOCAL_LENGTH_ERR = 0x01,
10897549c34SHans Petter Selasky MLX4_CQE_SYNDROME_LOCAL_QP_OP_ERR = 0x02,
10997549c34SHans Petter Selasky MLX4_CQE_SYNDROME_LOCAL_PROT_ERR = 0x04,
11097549c34SHans Petter Selasky MLX4_CQE_SYNDROME_WR_FLUSH_ERR = 0x05,
11197549c34SHans Petter Selasky MLX4_CQE_SYNDROME_MW_BIND_ERR = 0x06,
11297549c34SHans Petter Selasky MLX4_CQE_SYNDROME_BAD_RESP_ERR = 0x10,
11397549c34SHans Petter Selasky MLX4_CQE_SYNDROME_LOCAL_ACCESS_ERR = 0x11,
11497549c34SHans Petter Selasky MLX4_CQE_SYNDROME_REMOTE_INVAL_REQ_ERR = 0x12,
11597549c34SHans Petter Selasky MLX4_CQE_SYNDROME_REMOTE_ACCESS_ERR = 0x13,
11697549c34SHans Petter Selasky MLX4_CQE_SYNDROME_REMOTE_OP_ERR = 0x14,
11797549c34SHans Petter Selasky MLX4_CQE_SYNDROME_TRANSPORT_RETRY_EXC_ERR = 0x15,
11897549c34SHans Petter Selasky MLX4_CQE_SYNDROME_RNR_RETRY_EXC_ERR = 0x16,
11997549c34SHans Petter Selasky MLX4_CQE_SYNDROME_REMOTE_ABORTED_ERR = 0x22,
12097549c34SHans Petter Selasky };
12197549c34SHans Petter Selasky
12297549c34SHans Petter Selasky enum {
12397549c34SHans Petter Selasky MLX4_CQE_STATUS_IPV4 = 1 << 6,
12497549c34SHans Petter Selasky MLX4_CQE_STATUS_IPV4F = 1 << 7,
12597549c34SHans Petter Selasky MLX4_CQE_STATUS_IPV6 = 1 << 8,
12697549c34SHans Petter Selasky MLX4_CQE_STATUS_IPV4OPT = 1 << 9,
12797549c34SHans Petter Selasky MLX4_CQE_STATUS_TCP = 1 << 10,
12897549c34SHans Petter Selasky MLX4_CQE_STATUS_UDP = 1 << 11,
12997549c34SHans Petter Selasky MLX4_CQE_STATUS_IPOK = 1 << 12,
13097549c34SHans Petter Selasky };
13197549c34SHans Petter Selasky
13297549c34SHans Petter Selasky enum {
13397549c34SHans Petter Selasky MLX4_CQE_LLC = 1,
13497549c34SHans Petter Selasky MLX4_CQE_SNAP = 1 << 1,
13597549c34SHans Petter Selasky MLX4_CQE_BAD_FCS = 1 << 4,
13697549c34SHans Petter Selasky };
13797549c34SHans Petter Selasky
mlx4_cq_arm(struct mlx4_cq * cq,u32 cmd,u8 __iomem * uar_page,spinlock_t * doorbell_lock)13897549c34SHans Petter Selasky static inline void mlx4_cq_arm(struct mlx4_cq *cq, u32 cmd,
13997549c34SHans Petter Selasky u8 __iomem *uar_page,
14097549c34SHans Petter Selasky spinlock_t *doorbell_lock)
14197549c34SHans Petter Selasky {
14297549c34SHans Petter Selasky __be32 doorbell[2];
14397549c34SHans Petter Selasky u32 sn;
14497549c34SHans Petter Selasky u32 ci;
14597549c34SHans Petter Selasky
14697549c34SHans Petter Selasky sn = cq->arm_sn & 3;
14797549c34SHans Petter Selasky ci = cq->cons_index & 0xffffff;
14897549c34SHans Petter Selasky
14997549c34SHans Petter Selasky *cq->arm_db = cpu_to_be32(sn << 28 | cmd | ci);
15097549c34SHans Petter Selasky
15197549c34SHans Petter Selasky /*
15297549c34SHans Petter Selasky * Make sure that the doorbell record in host memory is
15397549c34SHans Petter Selasky * written before ringing the doorbell via PCI MMIO.
15497549c34SHans Petter Selasky */
15597549c34SHans Petter Selasky wmb();
15697549c34SHans Petter Selasky
15797549c34SHans Petter Selasky doorbell[0] = cpu_to_be32(sn << 28 | cmd | cq->cqn);
15897549c34SHans Petter Selasky doorbell[1] = cpu_to_be32(ci);
15997549c34SHans Petter Selasky
16097549c34SHans Petter Selasky mlx4_write64(doorbell, uar_page + MLX4_CQ_DOORBELL, doorbell_lock);
16197549c34SHans Petter Selasky }
16297549c34SHans Petter Selasky
mlx4_cq_set_ci(struct mlx4_cq * cq)16397549c34SHans Petter Selasky static inline void mlx4_cq_set_ci(struct mlx4_cq *cq)
16497549c34SHans Petter Selasky {
16597549c34SHans Petter Selasky *cq->set_ci_db = cpu_to_be32(cq->cons_index & 0xffffff);
16697549c34SHans Petter Selasky }
16797549c34SHans Petter Selasky
16897549c34SHans Petter Selasky enum {
16997549c34SHans Petter Selasky MLX4_CQ_DB_REQ_NOT_SOL = 1 << 24,
17097549c34SHans Petter Selasky MLX4_CQ_DB_REQ_NOT = 2 << 24
17197549c34SHans Petter Selasky };
17297549c34SHans Petter Selasky
17397549c34SHans Petter Selasky int mlx4_cq_modify(struct mlx4_dev *dev, struct mlx4_cq *cq,
17497549c34SHans Petter Selasky u16 count, u16 period);
17597549c34SHans Petter Selasky int mlx4_cq_resize(struct mlx4_dev *dev, struct mlx4_cq *cq,
17697549c34SHans Petter Selasky int entries, struct mlx4_mtt *mtt);
177c3191c2eSHans Petter Selasky
17897549c34SHans Petter Selasky #endif /* MLX4_CQ_H */
179