Lines Matching refs:ic

134 icl_conn_fail(struct icl_conn *ic)
136 if (ic->ic_socket == NULL)
142 ic->ic_socket->so_error = EDOOFUS;
143 (ic->ic_error)(ic);
147 icl_conn_receive(struct icl_conn *ic, size_t len)
154 so = ic->ic_socket;
175 icl_conn_receive_buf(struct icl_conn *ic, void *buf, size_t len)
182 so = ic->ic_socket;
209 icl_soft_conn_pdu_free(struct icl_conn *ic, struct icl_pdu *ip)
217 refcount_release(&ic->ic_outstanding_pdus);
225 icl_soft_conn_new_pdu(struct icl_conn *ic, int flags)
230 refcount_acquire(&ic->ic_outstanding_pdus);
236 refcount_release(&ic->ic_outstanding_pdus);
240 ip->ip_conn = ic;
246 icl_soft_conn_pdu_free(ic, ip);
278 icl_soft_conn_pdu_data_segment_length(struct icl_conn *ic,
454 struct icl_conn *ic;
458 ic = request->ip_conn;
461 ic->ic_receive_len = 0;
513 ic->ic_receive_len =
558 icl_conn_receive_pdu(struct icl_conn *ic, size_t *availablep)
566 so = ic->ic_socket;
568 if (ic->ic_receive_state == ICL_CONN_STATE_BHS) {
569 KASSERT(ic->ic_receive_pdu == NULL,
570 ("ic->ic_receive_pdu != NULL"));
571 request = icl_soft_conn_new_pdu(ic, M_NOWAIT);
575 icl_conn_fail(ic);
578 ic->ic_receive_pdu = request;
580 KASSERT(ic->ic_receive_pdu != NULL,
581 ("ic->ic_receive_pdu == NULL"));
582 request = ic->ic_receive_pdu;
585 if (*availablep < ic->ic_receive_len) {
588 "have %zd", ic->ic_receive_len, *availablep);
593 switch (ic->ic_receive_state) {
609 if (len > ic->ic_max_data_segment_length) {
614 len, ic->ic_max_data_segment_length);
619 ic->ic_receive_state = ICL_CONN_STATE_AHS;
620 ic->ic_receive_len = icl_pdu_ahs_length(request);
631 ic->ic_receive_state = ICL_CONN_STATE_HEADER_DIGEST;
632 if (ic->ic_header_crc32c == false)
633 ic->ic_receive_len = 0;
635 ic->ic_receive_len = ISCSI_HEADER_DIGEST_SIZE;
647 ic->ic_receive_state = ICL_CONN_STATE_DATA;
648 ic->ic_receive_len =
665 ic->ic_receive_state = ICL_CONN_STATE_DATA_DIGEST;
666 if (request->ip_data_len == 0 || ic->ic_data_crc32c == false)
667 ic->ic_receive_len = 0;
669 ic->ic_receive_len = ISCSI_DATA_DIGEST_SIZE;
685 ic->ic_receive_state = ICL_CONN_STATE_BHS;
686 ic->ic_receive_len = sizeof(struct iscsi_bhs);
687 ic->ic_receive_pdu = NULL;
691 panic("invalid ic_receive_state %d\n", ic->ic_receive_state);
696 * Don't free the PDU; it's pointed to by ic->ic_receive_pdu
699 icl_conn_fail(ic);
706 icl_conn_receive_pdus(struct icl_conn *ic, size_t available)
711 so = ic->ic_socket;
714 * This can never happen; we're careful to only mess with ic->ic_socket
720 if (ic->ic_disconnecting)
726 icl_conn_fail(ic);
734 if (available < ic->ic_receive_len) {
738 ic->ic_receive_len);
743 response = icl_conn_receive_pdu(ic, &available);
751 icl_soft_conn_pdu_free(ic, response);
752 icl_conn_fail(ic);
756 (ic->ic_receive)(response);
763 struct icl_conn *ic;
767 ic = arg;
768 so = ic->ic_socket;
771 if (ic->ic_disconnecting) {
784 if (available < ic->ic_receive_len) {
785 so->so_rcv.sb_lowat = ic->ic_receive_len;
786 cv_wait(&ic->ic_receive_cv, &so->so_rcv.sb_mtx);
791 icl_conn_receive_pdus(ic, available);
794 ICL_CONN_LOCK(ic);
795 ic->ic_receive_running = false;
796 cv_signal(&ic->ic_send_cv);
797 ICL_CONN_UNLOCK(ic);
804 struct icl_conn *ic;
809 ic = arg;
810 cv_signal(&ic->ic_receive_cv);
820 struct icl_conn *ic;
822 ic = request->ip_conn;
828 if (ic->ic_header_crc32c) {
849 if (ic->ic_data_crc32c) {
870 icl_conn_send_pdus(struct icl_conn *ic, struct icl_pdu_stailq *queue)
877 ICL_CONN_LOCK_ASSERT_NOT(ic);
879 so = ic->ic_socket;
928 icl_soft_conn_pdu_free(ic, request);
929 icl_conn_fail(ic);
946 icl_soft_conn_pdu_free(ic, request);
947 icl_soft_conn_pdu_free(ic, request2);
948 icl_conn_fail(ic);
956 icl_soft_conn_pdu_free(ic, request2);
973 icl_soft_conn_pdu_free(ic, request);
974 icl_conn_fail(ic);
977 icl_soft_conn_pdu_free(ic, request);
984 struct icl_conn *ic;
987 ic = arg;
991 ICL_CONN_LOCK(ic);
1001 STAILQ_SWAP(&ic->ic_to_send, &queue, icl_pdu);
1003 ic->ic_check_send_space = false;
1004 ICL_CONN_UNLOCK(ic);
1005 icl_conn_send_pdus(ic, &queue);
1006 ICL_CONN_LOCK(ic);
1012 if (ic->ic_check_send_space)
1020 !STAILQ_EMPTY(&ic->ic_to_send))
1031 if (ic->ic_disconnecting) {
1036 cv_wait(&ic->ic_send_cv, ic->ic_lock);
1043 STAILQ_CONCAT(&ic->ic_to_send, &queue);
1045 ic->ic_send_running = false;
1046 cv_signal(&ic->ic_send_cv);
1047 ICL_CONN_UNLOCK(ic);
1054 struct icl_conn *ic;
1059 ic = arg;
1061 ICL_CONN_LOCK(ic);
1062 ic->ic_check_send_space = true;
1063 ICL_CONN_UNLOCK(ic);
1065 cv_signal(&ic->ic_send_cv);
1071 icl_soft_conn_pdu_append_data(struct icl_conn *ic, struct icl_pdu *request,
1105 icl_soft_conn_pdu_get_data(struct icl_conn *ic, struct icl_pdu *ip,
1115 struct icl_conn *ic;
1117 ic = ip->ip_conn;
1119 ICL_CONN_LOCK_ASSERT(ic);
1121 if (ic->ic_disconnecting || ic->ic_socket == NULL) {
1123 icl_soft_conn_pdu_free(ic, ip);
1127 if (!STAILQ_EMPTY(&ic->ic_to_send)) {
1128 STAILQ_INSERT_TAIL(&ic->ic_to_send, ip, ip_next);
1137 STAILQ_INSERT_TAIL(&ic->ic_to_send, ip, ip_next);
1138 cv_signal(&ic->ic_send_cv);
1142 icl_soft_conn_pdu_queue(struct icl_conn *ic, struct icl_pdu *ip)
1151 struct icl_conn *ic;
1155 ic = (struct icl_conn *)kobj_create(&icl_soft_class, M_ICL_SOFT, M_WAITOK | M_ZERO);
1157 STAILQ_INIT(&ic->ic_to_send);
1158 ic->ic_lock = lock;
1159 cv_init(&ic->ic_send_cv, "icl_tx");
1160 cv_init(&ic->ic_receive_cv, "icl_rx");
1162 refcount_init(&ic->ic_outstanding_pdus, 0);
1164 ic->ic_max_data_segment_length = ICL_MAX_DATA_SEGMENT_LENGTH;
1165 ic->ic_name = name;
1166 ic->ic_offload = "None";
1167 ic->ic_unmapped = false;
1169 return (ic);
1173 icl_soft_conn_free(struct icl_conn *ic)
1177 KASSERT(ic->ic_outstanding_pdus == 0,
1179 ic->ic_outstanding_pdus));
1181 cv_destroy(&ic->ic_send_cv);
1182 cv_destroy(&ic->ic_receive_cv);
1183 kobj_delete((struct kobj *)ic, M_ICL_SOFT);
1188 icl_conn_start(struct icl_conn *ic)
1194 ICL_CONN_LOCK(ic);
1199 if (ic->ic_socket == NULL) {
1200 ICL_CONN_UNLOCK(ic);
1204 ic->ic_receive_state = ICL_CONN_STATE_BHS;
1205 ic->ic_receive_len = sizeof(struct iscsi_bhs);
1206 ic->ic_disconnecting = false;
1208 ICL_CONN_UNLOCK(ic);
1219 minspace = sizeof(struct iscsi_bhs) + ic->ic_max_data_segment_length +
1232 error = soreserve(ic->ic_socket, sendspace, recvspace);
1235 icl_soft_conn_close(ic);
1238 ic->ic_socket->so_snd.sb_flags |= SB_AUTOSIZE;
1239 ic->ic_socket->so_rcv.sb_flags |= SB_AUTOSIZE;
1250 error = sosetopt(ic->ic_socket, &opt);
1253 icl_soft_conn_close(ic);
1261 SOCKBUF_LOCK(&ic->ic_socket->so_snd);
1262 soupcall_set(ic->ic_socket, SO_SND, icl_soupcall_send, ic);
1263 SOCKBUF_UNLOCK(&ic->ic_socket->so_snd);
1264 SOCKBUF_LOCK(&ic->ic_socket->so_rcv);
1265 soupcall_set(ic->ic_socket, SO_RCV, icl_soupcall_receive, ic);
1266 SOCKBUF_UNLOCK(&ic->ic_socket->so_rcv);
1271 ICL_CONN_LOCK(ic);
1272 ic->ic_send_running = ic->ic_receive_running = true;
1273 ICL_CONN_UNLOCK(ic);
1274 error = kthread_add(icl_send_thread, ic, NULL, NULL, 0, 0, "%stx",
1275 ic->ic_name);
1278 ICL_CONN_LOCK(ic);
1279 ic->ic_send_running = ic->ic_receive_running = false;
1280 cv_signal(&ic->ic_send_cv);
1281 ICL_CONN_UNLOCK(ic);
1282 icl_soft_conn_close(ic);
1285 error = kthread_add(icl_receive_thread, ic, NULL, NULL, 0, 0, "%srx",
1286 ic->ic_name);
1289 ICL_CONN_LOCK(ic);
1290 ic->ic_receive_running = false;
1291 cv_signal(&ic->ic_send_cv);
1292 ICL_CONN_UNLOCK(ic);
1293 icl_soft_conn_close(ic);
1301 icl_soft_conn_handoff(struct icl_conn *ic, int fd)
1308 ICL_CONN_LOCK_ASSERT_NOT(ic);
1316 ICL_CONN_LOCK(ic);
1317 if (ic->ic_socket == NULL) {
1318 ICL_CONN_UNLOCK(ic);
1322 ICL_CONN_UNLOCK(ic);
1344 ICL_CONN_LOCK(ic);
1346 if (ic->ic_socket != NULL) {
1347 ICL_CONN_UNLOCK(ic);
1352 ic->ic_socket = fp->f_data;
1356 ICL_CONN_UNLOCK(ic);
1358 error = icl_conn_start(ic);
1364 icl_soft_conn_close(struct icl_conn *ic)
1369 ICL_CONN_LOCK(ic);
1374 ic->ic_disconnecting = true;
1375 while (ic->ic_receive_running || ic->ic_send_running) {
1376 cv_signal(&ic->ic_receive_cv);
1377 cv_signal(&ic->ic_send_cv);
1378 cv_wait(&ic->ic_send_cv, ic->ic_lock);
1382 so = ic->ic_socket;
1384 ICL_CONN_UNLOCK(ic);
1387 ic->ic_socket = NULL;
1392 ICL_CONN_UNLOCK(ic);
1402 ICL_CONN_LOCK(ic);
1404 if (ic->ic_receive_pdu != NULL) {
1406 icl_soft_conn_pdu_free(ic, ic->ic_receive_pdu);
1407 ic->ic_receive_pdu = NULL;
1413 while (!STAILQ_EMPTY(&ic->ic_to_send)) {
1414 pdu = STAILQ_FIRST(&ic->ic_to_send);
1415 STAILQ_REMOVE_HEAD(&ic->ic_to_send, ip_next);
1416 icl_soft_conn_pdu_free(ic, pdu);
1419 KASSERT(STAILQ_EMPTY(&ic->ic_to_send),
1421 ICL_CONN_UNLOCK(ic);
1425 icl_soft_conn_task_setup(struct icl_conn *ic, struct icl_pdu *ip,
1433 icl_soft_conn_task_done(struct icl_conn *ic, void *prv)
1438 icl_soft_conn_transfer_setup(struct icl_conn *ic, union ctl_io *io,
1446 icl_soft_conn_transfer_done(struct icl_conn *ic, void *prv)
1461 icl_soft_conn_connect(struct icl_conn *ic, int domain, int socktype,
1465 return (icl_soft_proxy_connect(ic, domain, socktype, protocol,
1470 icl_soft_handoff_sock(struct icl_conn *ic, struct socket *so)
1474 ICL_CONN_LOCK_ASSERT_NOT(ic);
1479 ICL_CONN_LOCK(ic);
1480 if (ic->ic_socket != NULL) {
1481 ICL_CONN_UNLOCK(ic);
1484 ic->ic_socket = so;
1485 ICL_CONN_UNLOCK(ic);
1487 error = icl_conn_start(ic);