Skip to contentSkip to conversation

BE NIC driver - beclib functions

PATCH In review Subbu Seetharaman 1 participant 1 message Jun 3, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 8/12 BE NIC driver - beclib functions

---
 drivers/message/beclib/cq_ll.c    |  400 +++++++++++++++++++++++
 drivers/message/beclib/ethrx_ll.c |  379 ++++++++++++++++++++++
 drivers/message/beclib/ethtx_ll.c |  503 +++++++++++++++++++++++++++++
 drivers/message/beclib/rxf_ll.c   |  639 +++++++++++++++++++++++++++++++++++++
 4 files changed, 1921 insertions(+), 0 deletions(-)
 create mode 100644 drivers/message/beclib/cq_ll.c
 create mode 100644 drivers/message/beclib/ethrx_ll.c
 create mode 100644 drivers/message/beclib/ethtx_ll.c
 create mode 100644 drivers/message/beclib/rxf_ll.c
drivers/message/beclib/cq_ll.c new file +400 -0
new file mode 100644
index 0000000..a80130f
@@ -0,0 +1,400 @@
+/*
+ * 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:
+ * [email protected]
+ *
+ * ServerEngines
+ * 209 N. Fair Oaks Ave
+ * Sunnyvale, CA 94085
+ */
+#include "pch.h"
+
+/*
+ * Completion Queue Objects
+ */
+
+/*!
+@brief
+    This routines searches for a CqId that is bound to a
+    specified function object.
+@param
+    pfob  - function object the CQ should be bound to.
+    cq_id            - cq_id to find
+@return
+    A pointer to the CQ_OBJECT that represents this CqId. NULL if not found
+@note
+    IRQL: <= DISPATCH_LEVEL
+*/
+static inline struct be_cq_object *
+be_cq_id_to_object(struct be_function_object *pfob, u32 cq_id)
+{
+	struct be_cq_object *cq_cur;
+	struct be_cq_object *cq_ret = NULL;
+	u32 cid;
+
+	_be_function_lock(pfob);
+
+	list_for_each_entry(cq_cur, &pfob->links.cq_list_head, cq_list) {
+		cid = be_cq_get_id(cq_cur);
+		if (cid == cq_id) {
+			cq_ret = cq_cur;
+			break;
+		}
+	}
+
+	_be_function_unlock(pfob);
+
+	if (!cq_ret) {
+		TRACE(DL_ERR, "Failed to locate cq_id:%d for processing.",
+		      cq_id);
+	}
+
+	return cq_ret;
+}
+
+/*
+ *============================================================================
+ *                  P U B L I C  R O U T I N E S
+ *============================================================================
+ */
+
+/*!
+
+@brief
+    This routine creates a completion queue based on the client completion
+    queue configuration information.
+
+
+@param
+    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.
+
+@return
+    BE_SUCCESS if successfull, otherwise a useful error code is returned.
+
+@note
+    IRQL < DISPATCH_LEVEL
+
+*/
+BESTATUS be_cq_create(struct be_function_object *pfob,
+	struct sa_sgl *sgl, u32 length, bool solicited_eventable,
+	bool no_delay, u32 wm_thresh,
+	struct be_eq_object *eq_object, struct be_cq_object *cq_object)
+{
+	BESTATUS 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;
+
+	ASSERT(sgl);
+	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 sgl 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 = sa_sgl_get_base_va(sgl);
+
+	/* map into UT. */
+	length = num_entries * sizeof(struct MCC_CQ_ENTRY_AMAP);
+
+	be_lock_wrb_post(pfob);
+
+	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 =
+	    SA_PAGES_SPANNED(sa_sgl_get_offset(sgl), length);
+
+	AMAP_SET_BITS_PTR(CQ_CONTEXT, valid, &fwcmd->params.request.context, 1);
+	n = be_function_get_function_number(pfob);
+	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 = be_function_get_pd_number(pfob);
+	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_sgl_to_pa_list(sgl, fwcmd->params.request.pages,
+			  ARRAY_SIZE(fwcmd->params.request.pages));
+
+	/* Post the Ioctl */
+	status = be_function_post_mcc_wrb(pfob, wrb, NULL, NULL, fwcmd);
+	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)
+		_be_eq_add_cq(eq_object, cq_object);
+
+	/* insert this cq into function_object */
+	_be_function_add_cq(pfob, cq_object);
+	TRACE(DL_INFO,
+	      "cq created. function:%d pd:%d cqid:%d bytes:%d eqid:%d"
+	      " se:%d nd:%d wm:%d",
+	      be_function_get_function_number(pfob),
+	      be_function_get_pd_number(pfob), cq_object->cq_id,
+	      num_entries * sizeof(struct MCC_CQ_ENTRY_AMAP),
+	      eq_object ? be_eq_get_id(eq_object) : -1,
+	      (u32) solicited_eventable, (u32) no_delay, wm_thresh);
+Error:
+	be_unlock_wrb_post(pfob);
+	return status;
+}
+
+/*!
+
+@brief
+    Returns the CQ ID for CQ. This is the ID the chip references the queue as.
+
+@param
+    cq_object            - CQ handle returned from cq_object_create.
+
+@return
+    CQ ID
+@note
+    IRQL: any
+
+*/
+u32 be_cq_get_id(struct be_cq_object *cq_object)
+{
+	return cq_object->cq_id;
+}
+
+/*!
+
+@brief
+    Sets the current callback to be invoked when a CQ entry is made available.
+    This need only be set if the owner of this CQ does not recieve the CQ
+    completions directly. i.e. it does not service interrupts.
+
+@param
+    cq_object            - CQ handle returned from cq_object_create.
+
+    callback            - function to invoke when the CQ needs processing.
+
+    context             - opaque context to pass to callback.
+
+@return
+    ptr to the previous callback.
+
+@note
+    IRQL: any
+
+    this routine is currently not synchronized w/ the DPC that may run the CQ.
+    therefore it is the callers responsibility to ensure the CQ will not
+    interrupt while this routine is executing.
+*/
+CQ_CALLBACK
+be_cq_object_set_callback(struct be_cq_object *cq_object,
+			  CQ_CALLBACK callback, void *context)
+{
+	CQ_CALLBACK old_callback;
+
+	old_callback = cq_object->callback;
+
+	cq_object->callback = callback;
+	cq_object->callback_context = context;
+
+	return old_callback;
+}
+
+/*!
+
+@brief
+    This routine handles CQ processing on CQs that were 'unrecognized' by upper
+    level drivers.  The only CQs that should be processed by this routine are
+    MCC CQ and iWARP CQ and of these, only the MCC CQ will be processed
+    in this routine. The iWARP CQ will be delegated further for handling
+    by the iWARP device driver
+
+@param
+    pfob      - handle to a function object
+    cq_id                - the cq that has just completed processing
+
+@note
+    IRQL: DISPATCH_LEVEL only
+
+    this routine should be called immediately when a CQ from a ULD is not
+    recognized.
+*/
+void
+be_cq_object_delegate_processing(struct be_function_object *pfob, u32 cq_id)
+{
+	struct be_cq_object *cq_object;
+
+	cq_object = be_cq_id_to_object(pfob, cq_id);
+
+	if (cq_object) {
+
+		ASSERT(cq_object->callback);
+		cq_object->callback(pfob, cq_object,
+				    cq_object->callback_context);
+
+	} else {
+
+		TRACE(DL_WARN, "cq_id %d not found for delegation", cq_id);
+	}
+
+}
+
+/*!
+
+@brief
+    References the given object. The object is guaranteed to remain active until
+    the reference count drops to zero.
+
+@param
+    cq_object            - CQ handle returned from cq_object_create.
+
+@return
+    returns the current reference count on the object
+
+@note
+    IRQL: any
+
+*/
+void be_cq_object_reference(struct be_cq_object *cq_object)
+{
+	atomic_inc(&cq_object->ref_count);
+}
+
+/*!
+
+@brief
+    Dereferences the given object. The object is guaranteed to
+    remain active until the reference count drops to zero.
+
+@param
+    cq_object            - CQ handle returned from cq_object_create.
+
+@return
+    returns the current reference count on the object
+
+@note
+    IRQL: any
+
+*/
+void be_cq_object_dereference(struct be_cq_object *cq_object)
+{
+	atomic_dec(&cq_object->ref_count);
+}
+
+/*!
+
+@brief
+    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.
+
+@param
+    cq_object            - CQ handle returned from cq_object_create.
+
+@return
+    returns the current reference count on the object
+
+@note
+    IRQL: IRQL < DISPATCH_LEVEL
+*/
+BESTATUS be_cq_destroy(struct be_cq_object *cq_object)
+{
+	BESTATUS status = 0;
+
+	/* Nothing should reference this CQ at this point. */
+	ASSERT(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);
+	ASSERT(status == 0);
+
+	/* Remove reference if this is an eventable CQ. */
+	if (cq_object->eq_object)
+		_be_eq_remove_cq(cq_object->eq_object, cq_object);
+
+	/* Remove from the function object. */
+	_be_function_remove_cq(cq_object->parent_function, cq_object);
+
+	/* Zero the software tracking object. */
+	memset(cq_object, 0, sizeof(*cq_object));
+
+	return BE_SUCCESS;
+}
drivers/message/beclib/ethrx_ll.c new file +379 -0

379 lines not on this page · raw message

drivers/message/beclib/ethtx_ll.c new file +503 -0

503 lines not on this page · raw message

drivers/message/beclib/rxf_ll.c new file +639 -0

639 lines not on this page · raw message

Signature · 8 lines
1.5.5

___________________________________________________________________________________
This message, together with any attachment(s), contains confidential and proprietary information of
ServerEngines Corporation and is intended only for the designated recipient(s) named above. Any unauthorized
review, printing, retention, copying, disclosure or distribution is strictly prohibited.  If you are not the
intended recipient of this message, please immediately advise the sender by reply email message and
delete all copies of this message and any attachment(s). Thank you.