1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Emulex. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* 28 * Source file containing the implementation of the MailBox queue handling 29 * and related helper functions 30 */ 31 32 #include <oce_impl.h> 33 34 /* 35 * function to drain a MCQ and process its CQEs 36 * 37 * dev - software handle to the device 38 * cq - pointer to the cq to drain 39 * 40 * return the number of CQEs processed 41 */ 42 uint16_t 43 oce_drain_mq_cq(void *arg) 44 { 45 struct oce_mq_cqe *cqe = NULL; 46 uint16_t num_cqe = 0; 47 link_state_t link_status; 48 struct oce_async_cqe_link_state *acqe; 49 struct oce_mq *mq; 50 struct oce_cq *cq; 51 struct oce_dev *dev; 52 53 /* do while we do not reach a cqe that is not valid */ 54 mq = (struct oce_mq *)arg; 55 cq = mq->cq; 56 dev = mq->parent; 57 mutex_enter(&mq->lock); 58 cqe = RING_GET_CONSUMER_ITEM_VA(cq->ring, struct oce_mq_cqe); 59 while (cqe->u0.dw[3]) { 60 DW_SWAP(u32ptr(cqe), sizeof (struct oce_mq_cqe)); 61 if (cqe->u0.s.async_event) { 62 acqe = (struct oce_async_cqe_link_state *)cqe; 63 if (acqe->u0.s.event_code == 64 ASYNC_EVENT_CODE_LINK_STATE) { 65 /* 66 * don't care logical or not, 67 * just check up down 68 */ 69 70 link_status = ((acqe->u0.s.link_status & 71 ~ASYNC_EVENT_LOGICAL) == 72 ASYNC_EVENT_LINK_UP) ? 73 LINK_STATE_UP: LINK_STATE_DOWN; 74 mac_link_update(dev->mac_handle, link_status); 75 dev->link_status = link_status; 76 dev->link_speed = -1; 77 } 78 } 79 cqe->u0.dw[3] = 0; 80 RING_GET(cq->ring, 1); 81 cqe = RING_GET_CONSUMER_ITEM_VA(cq->ring, struct oce_mq_cqe); 82 num_cqe++; 83 } /* for all valid CQE */ 84 mutex_exit(&mq->lock); 85 oce_arm_cq(dev, cq->cq_id, num_cqe, B_TRUE); 86 return (num_cqe); 87 } /* oce_drain_mq_cq */ 88 89 int 90 oce_start_mq(struct oce_mq *mq) 91 { 92 oce_arm_cq(mq->parent, mq->cq->cq_id, 0, B_TRUE); 93 return (0); 94 } 95 96 97 void 98 oce_clean_mq(struct oce_mq *mq) 99 { 100 struct oce_cq *cq; 101 struct oce_dev *dev; 102 uint16_t num_cqe = 0; 103 struct oce_mq_cqe *cqe = NULL; 104 105 cq = mq->cq; 106 dev = mq->parent; 107 cqe = RING_GET_CONSUMER_ITEM_VA(cq->ring, struct oce_mq_cqe); 108 while (cqe->u0.dw[3]) { 109 DW_SWAP(u32ptr(cqe), sizeof (struct oce_mq_cqe)); 110 cqe->u0.dw[3] = 0; 111 RING_GET(cq->ring, 1); 112 cqe = RING_GET_CONSUMER_ITEM_VA(cq->ring, struct oce_mq_cqe); 113 num_cqe++; 114 } /* for all valid CQE */ 115 if (num_cqe) 116 oce_arm_cq(dev, cq->cq_id, num_cqe, B_FALSE); 117 /* Drain the Event queue now */ 118 oce_drain_eq(mq->cq->eq); 119 } 120