Lines Matching refs:ch

228 static int riocm_ch_close(struct rio_channel *ch);
250 static int riocm_cmp(struct rio_channel *ch, enum rio_cm_state cmp)
254 spin_lock_bh(&ch->lock);
255 ret = (ch->state == cmp);
256 spin_unlock_bh(&ch->lock);
260 static int riocm_cmp_exch(struct rio_channel *ch,
265 spin_lock_bh(&ch->lock);
266 ret = (ch->state == cmp);
268 ch->state = exch;
269 spin_unlock_bh(&ch->lock);
273 static enum rio_cm_state riocm_exch(struct rio_channel *ch,
278 spin_lock_bh(&ch->lock);
279 old = ch->state;
280 ch->state = exch;
281 spin_unlock_bh(&ch->lock);
287 struct rio_channel *ch;
290 ch = idr_find(&ch_idr, nr);
291 if (ch)
292 kref_get(&ch->ref);
294 return ch;
297 static void riocm_put_channel(struct rio_channel *ch)
299 kref_put(&ch->ref, riocm_ch_free);
380 struct rio_channel *ch;
387 ch = riocm_get_channel(chnum);
389 if (!ch)
392 if (ch->state != RIO_CM_LISTEN) {
394 riocm_put_channel(ch);
400 riocm_put_channel(ch);
408 spin_lock_bh(&ch->lock);
409 list_add_tail(&req->node, &ch->accept_queue);
410 spin_unlock_bh(&ch->lock);
411 complete(&ch->comp);
412 riocm_put_channel(ch);
427 struct rio_channel *ch;
432 ch = riocm_get_channel(chnum);
433 if (!ch)
436 if (ch->state != RIO_CM_CONNECT) {
437 riocm_put_channel(ch);
441 riocm_exch(ch, RIO_CM_CONNECTED);
442 ch->rem_channel = ntohs(hh->src_ch);
443 complete(&ch->comp);
444 riocm_put_channel(ch);
459 struct rio_channel *ch;
463 riocm_debug(RX_CMD, "for ch=%d", ntohs(hh->dst_ch));
466 ch = idr_find(&ch_idr, ntohs(hh->dst_ch));
467 if (!ch) {
471 idr_remove(&ch_idr, ch->id);
474 riocm_exch(ch, RIO_CM_DISCONNECT);
476 ret = riocm_ch_close(ch);
497 riocm_debug(RX_CMD, "OP=%x for ch=%d from %d",
531 struct rio_channel *ch;
535 riocm_debug(RX_DATA, "for ch=%d", ntohs(hdr->dst_ch));
537 ch = riocm_get_channel(ntohs(hdr->dst_ch));
538 if (!ch) {
545 spin_lock(&ch->lock);
547 if (ch->state != RIO_CM_CONNECTED) {
549 riocm_debug(RX_DATA, "ch=%d is in wrong state=%d",
550 ch->id, ch->state);
551 spin_unlock(&ch->lock);
553 riocm_put_channel(ch);
557 if (ch->rx_ring.count == RIOCM_RX_RING_SIZE) {
559 riocm_debug(RX_DATA, "ch=%d is full", ch->id);
560 spin_unlock(&ch->lock);
562 riocm_put_channel(ch);
566 ch->rx_ring.buf[ch->rx_ring.head] = buf;
567 ch->rx_ring.head++;
568 ch->rx_ring.count++;
569 ch->rx_ring.head %= RIOCM_RX_RING_SIZE;
571 complete(&ch->comp);
573 spin_unlock(&ch->lock);
574 riocm_put_channel(ch);
785 struct rio_channel *ch;
792 ch = riocm_get_channel(ch_id);
793 if (!ch) {
799 if (!riocm_cmp(ch, RIO_CM_CONNECTED)) {
809 hdr->bhdr.src_id = htonl(ch->loc_destid);
810 hdr->bhdr.dst_id = htonl(ch->rem_destid);
815 hdr->dst_ch = htons(ch->rem_channel);
816 hdr->src_ch = htons(ch->id);
825 ret = riocm_post_send(ch->cmdev, ch->rdev, buf, len);
827 riocm_debug(TX, "ch %d send_err=%d", ch->id, ret);
829 riocm_put_channel(ch);
833 static int riocm_ch_free_rxbuf(struct rio_channel *ch, void *buf)
837 spin_lock_bh(&ch->lock);
840 if (ch->rx_ring.inuse[i] == buf) {
841 ch->rx_ring.inuse[i] = NULL;
842 ch->rx_ring.inuse_cnt--;
848 spin_unlock_bh(&ch->lock);
858 * @ch: local channel ID
868 static int riocm_ch_receive(struct rio_channel *ch, void **buf, long timeout)
874 if (!riocm_cmp(ch, RIO_CM_CONNECTED)) {
879 if (ch->rx_ring.inuse_cnt == RIOCM_RX_RING_SIZE) {
887 wret = wait_for_completion_interruptible_timeout(&ch->comp, timeout);
889 riocm_debug(WAIT, "wait on %d returned %ld", ch->id, wret);
896 ret = riocm_cmp(ch, RIO_CM_CONNECTED) ? 0 : -ECONNRESET;
901 spin_lock_bh(&ch->lock);
903 rxmsg = ch->rx_ring.buf[ch->rx_ring.tail];
904 ch->rx_ring.buf[ch->rx_ring.tail] = NULL;
905 ch->rx_ring.count--;
906 ch->rx_ring.tail++;
907 ch->rx_ring.tail %= RIOCM_RX_RING_SIZE;
911 if (ch->rx_ring.inuse[i] == NULL) {
912 ch->rx_ring.inuse[i] = rxmsg;
913 ch->rx_ring.inuse_cnt++;
925 spin_unlock_bh(&ch->lock);
947 struct rio_channel *ch = NULL;
952 ch = riocm_get_channel(loc_ch);
953 if (!ch)
956 if (!riocm_cmp_exch(ch, RIO_CM_IDLE, RIO_CM_CONNECT)) {
961 ch->cmdev = cm;
962 ch->rdev = peer->rdev;
963 ch->context = NULL;
964 ch->loc_destid = cm->mport->host_deviceid;
965 ch->rem_channel = rem_ch;
977 hdr->bhdr.src_id = htonl(ch->loc_destid);
1002 riocm_cmp_exch(ch, RIO_CM_CONNECT, RIO_CM_IDLE);
1007 wret = wait_for_completion_interruptible_timeout(&ch->comp,
1009 riocm_debug(WAIT, "wait on %d returns %ld", ch->id, wret);
1016 ret = riocm_cmp(ch, RIO_CM_CONNECTED) ? 0 : -1;
1019 riocm_put_channel(ch);
1023 static int riocm_send_ack(struct rio_channel *ch)
1032 hdr->bhdr.src_id = htonl(ch->loc_destid);
1033 hdr->bhdr.dst_id = htonl(ch->rem_destid);
1034 hdr->dst_ch = htons(ch->rem_channel);
1035 hdr->src_ch = htons(ch->id);
1045 ret = riocm_post_send(ch->cmdev, ch->rdev, hdr, sizeof(*hdr));
1047 if (ret == -EBUSY && !riocm_queue_req(ch->cmdev,
1048 ch->rdev, hdr, sizeof(*hdr)))
1054 ch->id, rio_name(ch->rdev), ret);
1076 struct rio_channel *ch;
1084 ch = riocm_get_channel(ch_id);
1085 if (!ch)
1088 if (!riocm_cmp(ch, RIO_CM_LISTEN)) {
1095 if (!try_wait_for_completion(&ch->comp)) {
1100 riocm_debug(WAIT, "on %d", ch->id);
1102 wret = wait_for_completion_interruptible_timeout(&ch->comp,
1113 spin_lock_bh(&ch->lock);
1115 if (ch->state != RIO_CM_LISTEN) {
1117 } else if (list_empty(&ch->accept_queue)) {
1119 ch->id);
1123 spin_unlock_bh(&ch->lock);
1126 riocm_debug(WAIT, "on %d returns %d", ch->id, err);
1140 spin_lock_bh(&ch->lock);
1142 req = list_first_entry(&ch->accept_queue, struct conn_req, node);
1144 new_ch->cmdev = ch->cmdev;
1145 new_ch->loc_destid = ch->loc_destid;
1149 spin_unlock_bh(&ch->lock);
1150 riocm_put_channel(ch);
1151 ch = NULL;
1189 if (ch)
1190 riocm_put_channel(ch);
1205 struct rio_channel *ch = NULL;
1210 ch = riocm_get_channel(ch_id);
1211 if (!ch)
1213 if (!riocm_cmp_exch(ch, RIO_CM_CHAN_BOUND, RIO_CM_LISTEN))
1215 riocm_put_channel(ch);
1232 struct rio_channel *ch = NULL;
1251 ch = riocm_get_channel(ch_id);
1252 if (!ch) {
1257 spin_lock_bh(&ch->lock);
1258 if (ch->state != RIO_CM_IDLE) {
1259 spin_unlock_bh(&ch->lock);
1264 ch->cmdev = cm;
1265 ch->loc_destid = cm->mport->host_deviceid;
1266 ch->context = context;
1267 ch->state = RIO_CM_CHAN_BOUND;
1268 spin_unlock_bh(&ch->lock);
1270 riocm_put_channel(ch);
1287 struct rio_channel *ch;
1289 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
1290 if (!ch)
1305 id = idr_alloc_cyclic(&ch_idr, ch, start, end, GFP_NOWAIT);
1310 kfree(ch);
1314 ch->id = (u16)id;
1315 ch->state = RIO_CM_IDLE;
1316 spin_lock_init(&ch->lock);
1317 INIT_LIST_HEAD(&ch->accept_queue);
1318 INIT_LIST_HEAD(&ch->ch_node);
1319 init_completion(&ch->comp);
1320 init_completion(&ch->comp_close);
1321 kref_init(&ch->ref);
1322 ch->rx_ring.head = 0;
1323 ch->rx_ring.tail = 0;
1324 ch->rx_ring.count = 0;
1325 ch->rx_ring.inuse_cnt = 0;
1327 return ch;
1348 struct rio_channel *ch = NULL;
1350 ch = riocm_ch_alloc(*ch_num);
1352 if (IS_ERR(ch))
1354 *ch_num, PTR_ERR(ch));
1356 *ch_num = ch->id;
1358 return ch;
1367 struct rio_channel *ch = container_of(ref, struct rio_channel, ref);
1370 riocm_debug(CHOP, "(ch_%d)", ch->id);
1372 if (ch->rx_ring.inuse_cnt) {
1374 i < RIOCM_RX_RING_SIZE && ch->rx_ring.inuse_cnt; i++) {
1375 if (ch->rx_ring.inuse[i] != NULL) {
1376 kfree(ch->rx_ring.inuse[i]);
1377 ch->rx_ring.inuse_cnt--;
1382 if (ch->rx_ring.count)
1383 for (i = 0; i < RIOCM_RX_RING_SIZE && ch->rx_ring.count; i++) {
1384 if (ch->rx_ring.buf[i] != NULL) {
1385 kfree(ch->rx_ring.buf[i]);
1386 ch->rx_ring.count--;
1390 complete(&ch->comp_close);
1393 static int riocm_send_close(struct rio_channel *ch)
1406 hdr->bhdr.src_id = htonl(ch->loc_destid);
1407 hdr->bhdr.dst_id = htonl(ch->rem_destid);
1412 hdr->dst_ch = htons(ch->rem_channel);
1413 hdr->src_ch = htons(ch->id);
1419 ret = riocm_post_send(ch->cmdev, ch->rdev, hdr, sizeof(*hdr));
1421 if (ret == -EBUSY && !riocm_queue_req(ch->cmdev, ch->rdev,
1427 riocm_error("ch(%d) send CLOSE failed (ret=%d)", ch->id, ret);
1434 * @ch: channel to be closed
1436 static int riocm_ch_close(struct rio_channel *ch)
1444 ch->id, current->comm, task_pid_nr(current));
1446 state = riocm_exch(ch, RIO_CM_DESTROYING);
1448 riocm_send_close(ch);
1450 complete_all(&ch->comp);
1452 riocm_put_channel(ch);
1453 wret = wait_for_completion_interruptible_timeout(&ch->comp_close, tmo);
1455 riocm_debug(WAIT, "wait on %d returns %ld", ch->id, wret);
1459 riocm_debug(CHOP, "%s(%d) timed out waiting for ch %d",
1460 current->comm, task_pid_nr(current), ch->id);
1464 riocm_debug(CHOP, "%s(%d) wait for ch %d was interrupted",
1465 current->comm, task_pid_nr(current), ch->id);
1470 riocm_debug(CHOP, "ch_%d resources released", ch->id);
1471 kfree(ch);
1473 riocm_debug(CHOP, "failed to release ch_%d resources", ch->id);
1498 struct rio_channel *ch, *_c;
1507 idr_for_each_entry(&ch_idr, ch, i) {
1508 if (ch && ch->filp == filp) {
1510 ch->id, current->comm,
1512 idr_remove(&ch_idr, ch->id);
1513 list_add(&ch->ch_node, &list);
1519 list_for_each_entry_safe(ch, _c, &list, ch_node) {
1520 list_del(&ch->ch_node);
1521 riocm_ch_close(ch);
1662 struct rio_channel *ch;
1669 ch = riocm_ch_create(&ch_num);
1670 if (IS_ERR(ch))
1671 return PTR_ERR(ch);
1673 ch->filp = filp;
1688 struct rio_channel *ch;
1697 ch = idr_find(&ch_idr, ch_num);
1698 if (!ch) {
1702 if (ch->filp != filp) {
1706 idr_remove(&ch_idr, ch->id);
1709 return riocm_ch_close(ch);
1752 struct rio_channel *ch;
1763 ch = riocm_ch_accept(param.ch_num, &param.ch_num, accept_to);
1764 if (IS_ERR(ch))
1765 return PTR_ERR(ch);
1766 ch->filp = filp;
1769 ch->id, current->comm, task_pid_nr(current));
1863 struct rio_channel *ch;
1874 ch = riocm_get_channel(msg.ch_num);
1875 if (!ch)
1880 ret = riocm_ch_receive(ch, &buf, rxto);
1889 riocm_ch_free_rxbuf(ch, buf);
1891 riocm_put_channel(ch);
1995 struct rio_channel *ch, *_c;
2043 idr_for_each_entry(&ch_idr, ch, i) {
2044 if (ch && ch->rdev == rdev) {
2046 riocm_exch(ch, RIO_CM_DISCONNECT);
2047 idr_remove(&ch_idr, ch->id);
2048 list_add(&ch->ch_node, &list);
2054 list_for_each_entry_safe(ch, _c, &list, ch_node) {
2055 list_del(&ch->ch_node);
2056 riocm_ch_close(ch);
2179 struct rio_channel *ch, *_c;
2204 idr_for_each_entry(&ch_idr, ch, i) {
2205 if (ch->cmdev == cm) {
2207 mport->name, ch->id);
2208 idr_remove(&ch_idr, ch->id);
2209 list_add(&ch->ch_node, &list);
2215 list_for_each_entry_safe(ch, _c, &list, ch_node) {
2216 list_del(&ch->ch_node);
2217 riocm_ch_close(ch);
2241 struct rio_channel *ch;
2255 idr_for_each_entry(&ch_idr, ch, i) {
2256 if (ch->state == RIO_CM_CONNECTED) {
2257 riocm_debug(EXIT, "close ch %d", ch->id);
2258 idr_remove(&ch_idr, ch->id);
2259 list_add(&ch->ch_node, &list);
2264 list_for_each_entry(ch, &list, ch_node)
2265 riocm_send_close(ch);