aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/benet/cq.c
blob: 6504586454331a79e62ce18edc5d0b923f61ad34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * Copyright (C) 2005 - 2008 ServerEngines
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.  The full GNU General
 * Public License is included in this distribution in the file called COPYING.
 *
 * Contact Information:
 * linux-drivers@serverengines.com
 *
 * ServerEngines
 * 209 N. Fair Oaks Ave
 * Sunnyvale, CA 94085
 */
#include "hwlib.h"
#include "bestatus.h"

/*
 * Completion Queue Objects
 */
/*
 *============================================================================
 *                  P U B L I C  R O U T I N E S
 *============================================================================
 */

/*
    This routine creates a completion queue based on the client completion
    queue configuration information.


    FunctionObject      - Handle to a function object
    CqBaseVa            - Base VA for a the CQ ring
    NumEntries          - CEV_CQ_CNT_* values
    solEventEnable      - 0 = All CQEs can generate Events if CQ is eventable
			1 = only CQEs with solicited bit set are eventable
    eventable           - Eventable CQ, generates interrupts.
    nodelay             - 1 = Force interrupt, relevent if CQ eventable.
			Interrupt is asserted immediately after EQE
			write is confirmed, regardless of EQ Timer
			or watermark settings.
    wme                 - Enable watermark based coalescing
    wmThresh            - High watermark(CQ fullness at which event
			or interrupt should be asserted).  These are the
			CEV_WATERMARK encoded values.
    EqObject            - EQ Handle to assign to this CQ
    ppCqObject          - Internal CQ Handle returned.

    Returns BE_SUCCESS if successfull, otherwise a useful error code is
	returned.

    IRQL < DISPATCH_LEVEL

*/
int be_cq_create(struct be_function_object *pfob,
	struct ring_desc *rd, u32 length, bool solicited_eventable,
	bool no_delay, u32 wm_thresh,
	struct be_eq_object *eq_object, struct be_cq_object *cq_object)
{
	int status = BE_SUCCESS;
	u32 num_entries_encoding;
	u32 num_entries = length / sizeof(struct MCC_CQ_ENTRY_AMAP);
	struct FWCMD_COMMON_CQ_CREATE *fwcmd = NULL;
	struct MCC_WRB_AMAP *wrb = NULL;
	u32 n;
	unsigned long irql;

	ASSERT(rd);
	ASSERT(cq_object);
	ASSERT(length % sizeof(struct MCC_CQ_ENTRY_AMAP) == 0);

	switch (num_entries) {
	case 256:
		num_entries_encoding = CEV_CQ_CNT_256;
		break;
	case 512:
		num_entries_encoding = CEV_CQ_CNT_512;
		break;
	case 1024:
		num_entries_encoding = CEV_CQ_CNT_1024;
		break;
	default:
		ASSERT(0);
		return BE_STATUS_INVALID_PARAMETER;
	}

	/*
	 * All cq entries all the same size.  Use iSCSI version
	 * as a test for the proper rd length.
	 */
	memset(cq_object, 0, sizeof(*cq_object));

	atomic_set(&cq_object->ref_count, 0);
	cq_object->parent_function = pfob;
	cq_object->eq_object = eq_object;
	cq_object->num_entries = num_entries;
	/* save for MCC cq processing */
	cq_object->va = rd->va;

	/* map into UT. */
	length = num_entries * sizeof(struct MCC_CQ_ENTRY_AMAP);

	spin_lock_irqsave(&pfob->post_lock, irql);

	wrb = be_function_peek_mcc_wrb(pfob);
	if (!wrb) {
		ASSERT(wrb);
		TRACE(DL_ERR, "No free MCC WRBs in create EQ.");
		status = BE_STATUS_NO_MCC_WRB;
		goto Error;
	}
	/* Prepares an embedded fwcmd, including request/response sizes. */
	fwcmd = BE_PREPARE_EMBEDDED_FWCMD(pfob, wrb, COMMON_CQ_CREATE);

	fwcmd->params.request.num_pages = PAGES_SPANNED(OFFSET_IN_PAGE(rd->va),
									length);

	AMAP_SET_BITS_PTR(CQ_CONTEXT, valid, &fwcmd->params.request.context, 1);
	n = pfob->pci_function_number;
	AMAP_SET_BITS_PTR(CQ_CONTEXT, Func, &fwcmd->params.request.context, n);

	n = (eq_object != NULL);
	AMAP_SET_BITS_PTR(CQ_CONTEXT, Eventable,
				&fwcmd->params.request.context, n);
	AMAP_SET_BITS_PTR(CQ_CONTEXT, Armed, &fwcmd->params.request.context, 1);

	n = eq_object ? eq_object->eq_id : 0;
	AMAP_SET_BITS_PTR(CQ_CONTEXT, EQID, &fwcmd->params.request.context, n);
	AMAP_SET_BITS_PTR(CQ_CONTEXT, Count,
			&fwcmd->params.request.context, num_entries_encoding);

	n = 0; /* Protection Domain is always 0 in  Linux  driver */
	AMAP_SET_BITS_PTR(CQ_CONTEXT, PD, &fwcmd->params.request.context, n);
	AMAP_SET_BITS_PTR(CQ_CONTEXT, NoDelay,
				&fwcmd->params.request.context, no_delay);
	AMAP_SET_BITS_PTR(CQ_CONTEXT, SolEvent,
			&fwcmd->params.request.context, solicited_eventable);

	n = (wm_thresh != 0xFFFFFFFF);
	AMAP_SET_BITS_PTR(CQ_CONTEXT, WME, &fwcmd->params.request.context, n);

	n = (n ? wm_thresh : 0);
	AMAP_SET_BITS_PTR(CQ_CONTEXT, Watermark,
				&fwcmd->params.request.context, n);
	/* Create a page list for the FWCMD. */
	be_rd_to_pa_list(rd, fwcmd->params.request.pages,
			  ARRAY_SIZE(fwcmd->params.request.pages));

	/* Post the f/w command */
	status = be_function_post_mcc_wrb(pfob, wrb, NULL, NULL, NULL,
			NULL, NULL, fwcmd, NULL);
	if (status != BE_SUCCESS) {
		TRACE(DL_ERR, "MCC to create CQ failed.");
		goto Error;
	}
	/* Remember the CQ id. */
	cq_object->cq_id = fwcmd->params.response.cq_id;

	/* insert this cq into eq_object reference */
	if (eq_object) {
		atomic_inc(&eq_object->ref_count);
		list_add_tail(&cq_object->cqlist_for_eq,
					&eq_object->cq_list_head);
	}

Error:
	spin_unlock_irqrestore(&pfob->post_lock, irql);

	if (pfob->pend_queue_driving && pfob->mcc) {
		pfob->pend_queue_driving = 0;
		be_drive_mcc_wrb_queue(pfob->mcc);
	}
	return status;
}

/*

    Deferences the given object. Once the object's reference count drops to
    zero, the object is destroyed and all resources that are held by this object
    are released.  The on-chip context is also destroyed along with the queue
    ID, and any mappings made into the UT.

    cq_object            - CQ handle returned from cq_object_create.

    returns the current reference count on the object

    IRQL: IRQL < DISPATCH_LEVEL
*/
int be_cq_destroy(struct be_cq_object *cq_object)
{
	int status = 0;

	/* Nothing should reference this CQ at this point. */
	ASSERT(atomic_read(&cq_object->ref_count) == 0);

	/* Send fwcmd to destroy the CQ. */
	status = be_function_ring_destroy(cq_object->parent_function,
		     cq_object->cq_id, FWCMD_RING_TYPE_CQ,
					NULL, NULL, NULL, NULL);
	ASSERT(status == 0);

	/* Remove reference if this is an eventable CQ. */
	if (cq_object->eq_object) {
		atomic_dec(&cq_object->eq_object->ref_count);
		list_del(&cq_object->cqlist_for_eq);
	}
	return BE_SUCCESS;
}