1 /* cxgb3i_iscsi.c: Chelsio S3xx iSCSI driver.
3 * Copyright (c) 2008 Chelsio Communications, Inc.
4 * Copyright (c) 2008 Mike Christie
5 * Copyright (c) 2008 Red Hat, Inc. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation.
11 * Written by: Karen Xie (kxie@chelsio.com)
14 #include <linux/inet.h>
15 #include <linux/crypto.h>
17 #include <scsi/scsi_cmnd.h>
18 #include <scsi/scsi_device.h>
19 #include <scsi/scsi_eh.h>
20 #include <scsi/scsi_host.h>
21 #include <scsi/scsi.h>
22 #include <scsi/iscsi_proto.h>
23 #include <scsi/libiscsi.h>
24 #include <scsi/scsi_transport_iscsi.h>
27 #include "cxgb3i_pdu.h"
29 #ifdef __DEBUG_CXGB3I_TAG__
30 #define cxgb3i_tag_debug cxgb3i_log_debug
32 #define cxgb3i_tag_debug(fmt...)
35 #ifdef __DEBUG_CXGB3I_API__
36 #define cxgb3i_api_debug cxgb3i_log_debug
38 #define cxgb3i_api_debug(fmt...)
42 * align pdu size to multiple of 512 for better performance
44 #define align_pdu_size(n) do { n = (n) & (~511); } while (0)
46 static struct scsi_transport_template *cxgb3i_scsi_transport;
47 static struct scsi_host_template cxgb3i_host_template;
48 static struct iscsi_transport cxgb3i_iscsi_transport;
49 static unsigned char sw_tag_idx_bits;
50 static unsigned char sw_tag_age_bits;
52 static LIST_HEAD(cxgb3i_snic_list);
53 static DEFINE_RWLOCK(cxgb3i_snic_rwlock);
56 * cxgb3i_adapter_add - init a s3 adapter structure and any h/w settings
57 * @t3dev: t3cdev adapter
58 * return the resulting cxgb3i_adapter struct
60 struct cxgb3i_adapter *cxgb3i_adapter_add(struct t3cdev *t3dev)
62 struct cxgb3i_adapter *snic;
63 struct adapter *adapter = tdev2adap(t3dev);
66 snic = kzalloc(sizeof(*snic), GFP_KERNEL);
68 cxgb3i_api_debug("cxgb3 %s, OOM.\n", t3dev->name);
71 spin_lock_init(&snic->lock);
74 snic->pdev = adapter->pdev;
75 snic->tag_format.sw_bits = sw_tag_idx_bits + sw_tag_age_bits;
77 if (cxgb3i_adapter_ddp_init(t3dev, &snic->tag_format,
79 &snic->rx_max_size) < 0)
82 for_each_port(adapter, i) {
83 snic->hba[i] = cxgb3i_hba_host_add(snic, adapter->port[i]);
87 snic->hba_cnt = adapter->params.nports;
90 write_lock(&cxgb3i_snic_rwlock);
91 list_add_tail(&snic->list_head, &cxgb3i_snic_list);
92 write_unlock(&cxgb3i_snic_rwlock);
97 cxgb3i_adapter_ddp_cleanup(t3dev);
104 * cxgb3i_adapter_remove - release all the resources held and cleanup any
106 * @t3dev: t3cdev adapter
108 void cxgb3i_adapter_remove(struct t3cdev *t3dev)
111 struct cxgb3i_adapter *snic;
113 /* remove from the list */
114 write_lock(&cxgb3i_snic_rwlock);
115 list_for_each_entry(snic, &cxgb3i_snic_list, list_head) {
116 if (snic->tdev == t3dev) {
117 list_del(&snic->list_head);
121 write_unlock(&cxgb3i_snic_rwlock);
124 for (i = 0; i < snic->hba_cnt; i++) {
126 cxgb3i_hba_host_remove(snic->hba[i]);
131 /* release ddp resources */
132 cxgb3i_adapter_ddp_cleanup(snic->tdev);
138 * cxgb3i_hba_find_by_netdev - find the cxgb3i_hba structure with a given
140 * @t3dev: t3cdev adapter
142 struct cxgb3i_hba *cxgb3i_hba_find_by_netdev(struct net_device *ndev)
144 struct cxgb3i_adapter *snic;
147 read_lock(&cxgb3i_snic_rwlock);
148 list_for_each_entry(snic, &cxgb3i_snic_list, list_head) {
149 for (i = 0; i < snic->hba_cnt; i++) {
150 if (snic->hba[i]->ndev == ndev) {
151 read_unlock(&cxgb3i_snic_rwlock);
156 read_unlock(&cxgb3i_snic_rwlock);
161 * cxgb3i_hba_host_add - register a new host with scsi/iscsi
162 * @snic: the cxgb3i adapter
163 * @ndev: associated net_device
165 struct cxgb3i_hba *cxgb3i_hba_host_add(struct cxgb3i_adapter *snic,
166 struct net_device *ndev)
168 struct cxgb3i_hba *hba;
169 struct Scsi_Host *shost;
172 shost = iscsi_host_alloc(&cxgb3i_host_template,
173 sizeof(struct cxgb3i_hba),
174 CXGB3I_SCSI_QDEPTH_DFLT);
176 cxgb3i_log_info("iscsi_host_alloc failed.\n");
180 shost->transportt = cxgb3i_scsi_transport;
181 shost->max_lun = CXGB3I_MAX_LUN;
182 shost->max_id = CXGB3I_MAX_TARGET;
183 shost->max_channel = 0;
184 shost->max_cmd_len = 16;
186 hba = iscsi_host_priv(shost);
191 pci_dev_get(snic->pdev);
192 err = iscsi_host_add(shost, &snic->pdev->dev);
194 cxgb3i_log_info("iscsi_host_add failed.\n");
198 cxgb3i_api_debug("shost 0x%p, hba 0x%p, no %u.\n",
199 shost, hba, shost->host_no);
204 pci_dev_put(snic->pdev);
205 scsi_host_put(shost);
210 * cxgb3i_hba_host_remove - de-register the host with scsi/iscsi
211 * @hba: the cxgb3i hba
213 void cxgb3i_hba_host_remove(struct cxgb3i_hba *hba)
215 cxgb3i_api_debug("shost 0x%p, hba 0x%p, no %u.\n",
216 hba->shost, hba, hba->shost->host_no);
217 iscsi_host_remove(hba->shost);
218 pci_dev_put(hba->snic->pdev);
219 iscsi_host_free(hba->shost);
223 * cxgb3i_ep_connect - establish TCP connection to target portal
224 * @dst_addr: target IP address
225 * @non_blocking: blocking or non-blocking call
227 * Initiates a TCP/IP connection to the dst_addr
229 static struct iscsi_endpoint *cxgb3i_ep_connect(struct sockaddr *dst_addr,
232 struct iscsi_endpoint *ep;
233 struct cxgb3i_endpoint *cep;
234 struct cxgb3i_hba *hba;
235 struct s3_conn *c3cn = NULL;
238 c3cn = cxgb3i_c3cn_create();
240 cxgb3i_log_info("ep connect OOM.\n");
245 err = cxgb3i_c3cn_connect(c3cn, (struct sockaddr_in *)dst_addr);
247 cxgb3i_log_info("ep connect failed.\n");
250 hba = cxgb3i_hba_find_by_netdev(c3cn->dst_cache->dev);
253 cxgb3i_log_info("NOT going through cxgbi device.\n");
256 if (c3cn_is_closing(c3cn)) {
258 cxgb3i_log_info("ep connect unable to connect.\n");
262 ep = iscsi_create_endpoint(sizeof(*cep));
265 cxgb3i_log_info("iscsi alloc ep, OOM.\n");
272 cxgb3i_api_debug("ep 0x%p, 0x%p, c3cn 0x%p, hba 0x%p.\n",
277 cxgb3i_api_debug("conn 0x%p failed, release.\n", c3cn);
279 cxgb3i_c3cn_release(c3cn);
284 * cxgb3i_ep_poll - polls for TCP connection establishement
285 * @ep: TCP connection (endpoint) handle
286 * @timeout_ms: timeout value in milli secs
288 * polls for TCP connect request to complete
290 static int cxgb3i_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
292 struct cxgb3i_endpoint *cep = ep->dd_data;
293 struct s3_conn *c3cn = cep->c3cn;
295 if (!c3cn_is_established(c3cn))
297 cxgb3i_api_debug("ep 0x%p, c3cn 0x%p established.\n", ep, c3cn);
302 * cxgb3i_ep_disconnect - teardown TCP connection
303 * @ep: TCP connection (endpoint) handle
305 * teardown TCP connection
307 static void cxgb3i_ep_disconnect(struct iscsi_endpoint *ep)
309 struct cxgb3i_endpoint *cep = ep->dd_data;
310 struct cxgb3i_conn *cconn = cep->cconn;
312 cxgb3i_api_debug("ep 0x%p, cep 0x%p.\n", ep, cep);
314 if (cconn && cconn->conn) {
316 * stop the xmit path so the xmit_pdu function is
319 iscsi_suspend_tx(cconn->conn);
321 write_lock_bh(&cep->c3cn->callback_lock);
322 cep->c3cn->user_data = NULL;
324 write_unlock_bh(&cep->c3cn->callback_lock);
327 cxgb3i_api_debug("ep 0x%p, cep 0x%p, release c3cn 0x%p.\n",
329 cxgb3i_c3cn_release(cep->c3cn);
330 iscsi_destroy_endpoint(ep);
334 * cxgb3i_session_create - create a new iscsi session
335 * @cmds_max: max # of commands
336 * @qdepth: scsi queue depth
337 * @initial_cmdsn: initial iscsi CMDSN for this session
338 * @host_no: pointer to return host no
340 * Creates a new iSCSI session
342 static struct iscsi_cls_session *
343 cxgb3i_session_create(struct iscsi_endpoint *ep, u16 cmds_max, u16 qdepth,
344 u32 initial_cmdsn, u32 *host_no)
346 struct cxgb3i_endpoint *cep;
347 struct cxgb3i_hba *hba;
348 struct Scsi_Host *shost;
349 struct iscsi_cls_session *cls_session;
350 struct iscsi_session *session;
353 cxgb3i_log_error("%s, missing endpoint.\n", __func__);
360 cxgb3i_api_debug("ep 0x%p, cep 0x%p, hba 0x%p.\n", ep, cep, hba);
361 BUG_ON(hba != iscsi_host_priv(shost));
363 *host_no = shost->host_no;
365 cls_session = iscsi_session_setup(&cxgb3i_iscsi_transport, shost,
367 sizeof(struct iscsi_tcp_task) +
368 sizeof(struct cxgb3i_task_data),
369 initial_cmdsn, ISCSI_MAX_TARGET);
372 session = cls_session->dd_data;
373 if (iscsi_tcp_r2tpool_alloc(session))
379 iscsi_session_teardown(cls_session);
384 * cxgb3i_session_destroy - destroys iscsi session
385 * @cls_session: pointer to iscsi cls session
387 * Destroys an iSCSI session instance and releases its all resources held
389 static void cxgb3i_session_destroy(struct iscsi_cls_session *cls_session)
391 cxgb3i_api_debug("sess 0x%p.\n", cls_session);
392 iscsi_tcp_r2tpool_free(cls_session->dd_data);
393 iscsi_session_teardown(cls_session);
397 * cxgb3i_conn_max_xmit_dlength -- check the max. xmit pdu segment size,
398 * reduce it to be within the hardware limit if needed
399 * @conn: iscsi connection
401 static inline int cxgb3i_conn_max_xmit_dlength(struct iscsi_conn *conn)
404 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
405 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
406 unsigned int max = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
407 cconn->hba->snic->tx_max_size -
408 ISCSI_PDU_NONPAYLOAD_MAX);
410 if (conn->max_xmit_dlength)
411 conn->max_xmit_dlength = min_t(unsigned int,
412 conn->max_xmit_dlength, max);
414 conn->max_xmit_dlength = max;
415 align_pdu_size(conn->max_xmit_dlength);
416 cxgb3i_log_info("conn 0x%p, max xmit %u.\n",
417 conn, conn->max_xmit_dlength);
422 * cxgb3i_conn_max_recv_dlength -- check the max. recv pdu segment size against
424 * @conn: iscsi connection
425 * return 0 if the value is valid, < 0 otherwise.
427 static inline int cxgb3i_conn_max_recv_dlength(struct iscsi_conn *conn)
429 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
430 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
431 unsigned int max = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
432 cconn->hba->snic->rx_max_size -
433 ISCSI_PDU_NONPAYLOAD_MAX);
436 if (conn->max_recv_dlength) {
437 if (conn->max_recv_dlength > max) {
438 cxgb3i_log_error("MaxRecvDataSegmentLength %u too big."
439 " Need to be <= %u.\n",
440 conn->max_recv_dlength, max);
443 conn->max_recv_dlength = min_t(unsigned int,
444 conn->max_recv_dlength, max);
445 align_pdu_size(conn->max_recv_dlength);
447 conn->max_recv_dlength = max;
448 cxgb3i_api_debug("conn 0x%p, max recv %u.\n",
449 conn, conn->max_recv_dlength);
454 * cxgb3i_conn_create - create iscsi connection instance
455 * @cls_session: pointer to iscsi cls session
458 * Creates a new iSCSI connection instance for a given session
460 static struct iscsi_cls_conn *cxgb3i_conn_create(struct iscsi_cls_session
461 *cls_session, u32 cid)
463 struct iscsi_cls_conn *cls_conn;
464 struct iscsi_conn *conn;
465 struct iscsi_tcp_conn *tcp_conn;
466 struct cxgb3i_conn *cconn;
468 cxgb3i_api_debug("sess 0x%p, cid %u.\n", cls_session, cid);
470 cls_conn = iscsi_tcp_conn_setup(cls_session, sizeof(*cconn), cid);
473 conn = cls_conn->dd_data;
474 tcp_conn = conn->dd_data;
475 cconn = tcp_conn->dd_data;
482 * cxgb3i_conn_bind - binds iscsi sess, conn and endpoint together
483 * @cls_session: pointer to iscsi cls session
484 * @cls_conn: pointer to iscsi cls conn
485 * @transport_eph: 64-bit EP handle
486 * @is_leading: leading connection on this session?
488 * Binds together an iSCSI session, an iSCSI connection and a
489 * TCP connection. This routine returns error code if the TCP
490 * connection does not belong on the device iSCSI sess/conn is bound
493 static int cxgb3i_conn_bind(struct iscsi_cls_session *cls_session,
494 struct iscsi_cls_conn *cls_conn,
495 u64 transport_eph, int is_leading)
497 struct iscsi_conn *conn = cls_conn->dd_data;
498 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
499 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
500 struct cxgb3i_adapter *snic;
501 struct iscsi_endpoint *ep;
502 struct cxgb3i_endpoint *cep;
503 struct s3_conn *c3cn;
506 ep = iscsi_lookup_endpoint(transport_eph);
510 /* setup ddp pagesize */
513 snic = cep->hba->snic;
514 err = cxgb3i_setup_conn_host_pagesize(snic->tdev, c3cn->tid, 0);
518 cxgb3i_api_debug("ep 0x%p, cls sess 0x%p, cls conn 0x%p.\n",
519 ep, cls_session, cls_conn);
521 err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
525 /* calculate the tag idx bits needed for this conn based on cmds_max */
526 cconn->task_idx_bits = (__ilog2_u32(conn->session->cmds_max - 1)) + 1;
527 cxgb3i_api_debug("session cmds_max 0x%x, bits %u.\n",
528 conn->session->cmds_max, cconn->task_idx_bits);
530 read_lock(&c3cn->callback_lock);
531 c3cn->user_data = conn;
532 cconn->hba = cep->hba;
535 read_unlock(&c3cn->callback_lock);
537 cxgb3i_conn_max_xmit_dlength(conn);
538 cxgb3i_conn_max_recv_dlength(conn);
540 spin_lock_bh(&conn->session->lock);
541 sprintf(conn->portal_address, NIPQUAD_FMT,
542 NIPQUAD(c3cn->daddr.sin_addr.s_addr));
543 conn->portal_port = ntohs(c3cn->daddr.sin_port);
544 spin_unlock_bh(&conn->session->lock);
546 /* init recv engine */
547 iscsi_tcp_hdr_recv_prep(tcp_conn);
553 * cxgb3i_conn_get_param - return iscsi connection parameter to caller
554 * @cls_conn: pointer to iscsi cls conn
555 * @param: parameter type identifier
556 * @buf: buffer pointer
558 * returns iSCSI connection parameters
560 static int cxgb3i_conn_get_param(struct iscsi_cls_conn *cls_conn,
561 enum iscsi_param param, char *buf)
563 struct iscsi_conn *conn = cls_conn->dd_data;
566 cxgb3i_api_debug("cls_conn 0x%p, param %d.\n", cls_conn, param);
569 case ISCSI_PARAM_CONN_PORT:
570 spin_lock_bh(&conn->session->lock);
571 len = sprintf(buf, "%hu\n", conn->portal_port);
572 spin_unlock_bh(&conn->session->lock);
574 case ISCSI_PARAM_CONN_ADDRESS:
575 spin_lock_bh(&conn->session->lock);
576 len = sprintf(buf, "%s\n", conn->portal_address);
577 spin_unlock_bh(&conn->session->lock);
580 return iscsi_conn_get_param(cls_conn, param, buf);
587 * cxgb3i_conn_set_param - set iscsi connection parameter
588 * @cls_conn: pointer to iscsi cls conn
589 * @param: parameter type identifier
590 * @buf: buffer pointer
591 * @buflen: buffer length
593 * set iSCSI connection parameters
595 static int cxgb3i_conn_set_param(struct iscsi_cls_conn *cls_conn,
596 enum iscsi_param param, char *buf, int buflen)
598 struct iscsi_conn *conn = cls_conn->dd_data;
599 struct iscsi_session *session = conn->session;
600 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
601 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
602 struct cxgb3i_adapter *snic = cconn->hba->snic;
603 struct s3_conn *c3cn = cconn->cep->c3cn;
607 case ISCSI_PARAM_HDRDGST_EN:
608 err = iscsi_set_param(cls_conn, param, buf, buflen);
609 if (!err && conn->hdrdgst_en)
610 err = cxgb3i_setup_conn_digest(snic->tdev, c3cn->tid,
612 conn->datadgst_en, 0);
614 case ISCSI_PARAM_DATADGST_EN:
615 err = iscsi_set_param(cls_conn, param, buf, buflen);
616 if (!err && conn->datadgst_en)
617 err = cxgb3i_setup_conn_digest(snic->tdev, c3cn->tid,
619 conn->datadgst_en, 0);
621 case ISCSI_PARAM_MAX_R2T:
622 sscanf(buf, "%d", &value);
623 if (value <= 0 || !is_power_of_2(value))
625 if (session->max_r2t == value)
627 iscsi_tcp_r2tpool_free(session);
628 err = iscsi_set_param(cls_conn, param, buf, buflen);
629 if (!err && iscsi_tcp_r2tpool_alloc(session))
631 case ISCSI_PARAM_MAX_RECV_DLENGTH:
632 err = iscsi_set_param(cls_conn, param, buf, buflen);
634 err = cxgb3i_conn_max_recv_dlength(conn);
636 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
637 err = iscsi_set_param(cls_conn, param, buf, buflen);
639 err = cxgb3i_conn_max_xmit_dlength(conn);
642 return iscsi_set_param(cls_conn, param, buf, buflen);
648 * cxgb3i_host_set_param - configure host (adapter) related parameters
649 * @shost: scsi host pointer
650 * @param: parameter type identifier
651 * @buf: buffer pointer
653 static int cxgb3i_host_set_param(struct Scsi_Host *shost,
654 enum iscsi_host_param param,
655 char *buf, int buflen)
657 struct cxgb3i_hba *hba = iscsi_host_priv(shost);
659 cxgb3i_api_debug("param %d, buf %s.\n", param, buf);
662 case ISCSI_HOST_PARAM_IPADDRESS:
664 __be32 addr = in_aton(buf);
665 cxgb3i_set_private_ipv4addr(hba->ndev, addr);
668 case ISCSI_HOST_PARAM_HWADDRESS:
669 case ISCSI_HOST_PARAM_NETDEV_NAME:
673 return iscsi_host_set_param(shost, param, buf, buflen);
678 * cxgb3i_host_get_param - returns host (adapter) related parameters
679 * @shost: scsi host pointer
680 * @param: parameter type identifier
681 * @buf: buffer pointer
683 static int cxgb3i_host_get_param(struct Scsi_Host *shost,
684 enum iscsi_host_param param, char *buf)
686 struct cxgb3i_hba *hba = iscsi_host_priv(shost);
689 cxgb3i_api_debug("hba %s, param %d.\n", hba->ndev->name, param);
692 case ISCSI_HOST_PARAM_HWADDRESS:
693 len = sysfs_format_mac(buf, hba->ndev->dev_addr, 6);
695 case ISCSI_HOST_PARAM_NETDEV_NAME:
696 len = sprintf(buf, "%s\n", hba->ndev->name);
698 case ISCSI_HOST_PARAM_IPADDRESS:
702 addr = cxgb3i_get_private_ipv4addr(hba->ndev);
703 len = sprintf(buf, NIPQUAD_FMT, NIPQUAD(addr));
707 return iscsi_host_get_param(shost, param, buf);
713 * cxgb3i_conn_get_stats - returns iSCSI stats
714 * @cls_conn: pointer to iscsi cls conn
715 * @stats: pointer to iscsi statistic struct
717 static void cxgb3i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
718 struct iscsi_stats *stats)
720 struct iscsi_conn *conn = cls_conn->dd_data;
722 stats->txdata_octets = conn->txdata_octets;
723 stats->rxdata_octets = conn->rxdata_octets;
724 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
725 stats->dataout_pdus = conn->dataout_pdus_cnt;
726 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
727 stats->datain_pdus = conn->datain_pdus_cnt;
728 stats->r2t_pdus = conn->r2t_pdus_cnt;
729 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
730 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
731 stats->digest_err = 0;
732 stats->timeout_err = 0;
733 stats->custom_length = 1;
734 strcpy(stats->custom[0].desc, "eh_abort_cnt");
735 stats->custom[0].value = conn->eh_abort_cnt;
739 * cxgb3i_parse_itt - get the idx and age bits from a given tag
740 * @conn: iscsi connection
742 * @idx: task index, filled in by this function
743 * @age: session age, filled in by this function
745 static void cxgb3i_parse_itt(struct iscsi_conn *conn, itt_t itt,
748 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
749 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
750 struct cxgb3i_adapter *snic = cconn->hba->snic;
751 u32 tag = ntohl((__force u32) itt);
754 sw_bits = cxgb3i_tag_nonrsvd_bits(&snic->tag_format, tag);
756 *idx = sw_bits & ((1 << cconn->task_idx_bits) - 1);
758 *age = (sw_bits >> cconn->task_idx_bits) & ISCSI_AGE_MASK;
760 cxgb3i_tag_debug("parse tag 0x%x/0x%x, sw 0x%x, itt 0x%x, age 0x%x.\n",
761 tag, itt, sw_bits, idx ? *idx : 0xFFFFF,
766 * cxgb3i_reserve_itt - generate tag for a give task
767 * Try to set up ddp for a scsi read task.
769 * @hdr_itt: tag, filled in by this function
771 int cxgb3i_reserve_itt(struct iscsi_task *task, itt_t *hdr_itt)
773 struct scsi_cmnd *sc = task->sc;
774 struct iscsi_conn *conn = task->conn;
775 struct iscsi_session *sess = conn->session;
776 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
777 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
778 struct cxgb3i_adapter *snic = cconn->hba->snic;
779 struct cxgb3i_tag_format *tformat = &snic->tag_format;
780 u32 sw_tag = (sess->age << cconn->task_idx_bits) | task->itt;
785 (scsi_bidi_cmnd(sc) || sc->sc_data_direction == DMA_FROM_DEVICE) &&
786 cxgb3i_sw_tag_usable(tformat, sw_tag)) {
787 struct s3_conn *c3cn = cconn->cep->c3cn;
788 struct cxgb3i_gather_list *gl;
790 gl = cxgb3i_ddp_make_gl(scsi_in(sc)->length,
791 scsi_in(sc)->table.sgl,
792 scsi_in(sc)->table.nents,
797 err = cxgb3i_ddp_tag_reserve(snic->tdev, c3cn->tid,
801 cxgb3i_ddp_release_gl(gl, snic->pdev);
806 tag = cxgb3i_set_non_ddp_tag(tformat, sw_tag);
807 /* the itt need to sent in big-endian order */
808 *hdr_itt = (__force itt_t)htonl(tag);
810 cxgb3i_tag_debug("new tag 0x%x/0x%x (itt 0x%x, age 0x%x).\n",
811 tag, *hdr_itt, task->itt, sess->age);
816 * cxgb3i_release_itt - release the tag for a given task
817 * if the tag is a ddp tag, release the ddp setup
821 void cxgb3i_release_itt(struct iscsi_task *task, itt_t hdr_itt)
823 struct scsi_cmnd *sc = task->sc;
824 struct iscsi_tcp_conn *tcp_conn = task->conn->dd_data;
825 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
826 struct cxgb3i_adapter *snic = cconn->hba->snic;
827 struct cxgb3i_tag_format *tformat = &snic->tag_format;
828 u32 tag = ntohl((__force u32)hdr_itt);
830 cxgb3i_tag_debug("release tag 0x%x.\n", tag);
833 (scsi_bidi_cmnd(sc) || sc->sc_data_direction == DMA_FROM_DEVICE) &&
834 cxgb3i_is_ddp_tag(tformat, tag))
835 cxgb3i_ddp_tag_release(snic->tdev, tag);
839 * cxgb3i_host_template -- Scsi_Host_Template structure
840 * used when registering with the scsi mid layer
842 static struct scsi_host_template cxgb3i_host_template = {
843 .module = THIS_MODULE,
844 .name = "Chelsio S3xx iSCSI Initiator",
845 .proc_name = "cxgb3i",
846 .queuecommand = iscsi_queuecommand,
847 .change_queue_depth = iscsi_change_queue_depth,
848 .can_queue = CXGB3I_SCSI_QDEPTH_DFLT - 1,
849 .sg_tablesize = SG_ALL,
850 .max_sectors = 0xFFFF,
851 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
852 .eh_abort_handler = iscsi_eh_abort,
853 .eh_device_reset_handler = iscsi_eh_device_reset,
854 .eh_target_reset_handler = iscsi_eh_target_reset,
855 .use_clustering = DISABLE_CLUSTERING,
859 static struct iscsi_transport cxgb3i_iscsi_transport = {
860 .owner = THIS_MODULE,
862 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
863 | CAP_DATADGST | CAP_DIGEST_OFFLOAD |
865 .param_mask = ISCSI_MAX_RECV_DLENGTH |
866 ISCSI_MAX_XMIT_DLENGTH |
869 ISCSI_INITIAL_R2T_EN |
874 ISCSI_PDU_INORDER_EN |
875 ISCSI_DATASEQ_INORDER_EN |
880 ISCSI_PERSISTENT_PORT |
881 ISCSI_PERSISTENT_ADDRESS |
882 ISCSI_TARGET_NAME | ISCSI_TPGT |
883 ISCSI_USERNAME | ISCSI_PASSWORD |
884 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
885 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
887 ISCSI_PING_TMO | ISCSI_RECV_TMO |
888 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
889 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
890 ISCSI_HOST_INITIATOR_NAME | ISCSI_HOST_NETDEV_NAME,
891 .get_host_param = cxgb3i_host_get_param,
892 .set_host_param = cxgb3i_host_set_param,
893 /* session management */
894 .create_session = cxgb3i_session_create,
895 .destroy_session = cxgb3i_session_destroy,
896 .get_session_param = iscsi_session_get_param,
897 /* connection management */
898 .create_conn = cxgb3i_conn_create,
899 .bind_conn = cxgb3i_conn_bind,
900 .destroy_conn = iscsi_tcp_conn_teardown,
901 .start_conn = iscsi_conn_start,
902 .stop_conn = iscsi_conn_stop,
903 .get_conn_param = cxgb3i_conn_get_param,
904 .set_param = cxgb3i_conn_set_param,
905 .get_stats = cxgb3i_conn_get_stats,
906 /* pdu xmit req. from user space */
907 .send_pdu = iscsi_conn_send_pdu,
909 .init_task = iscsi_tcp_task_init,
910 .xmit_task = iscsi_tcp_task_xmit,
911 .cleanup_task = cxgb3i_conn_cleanup_task,
914 .alloc_pdu = cxgb3i_conn_alloc_pdu,
915 .init_pdu = cxgb3i_conn_init_pdu,
916 .xmit_pdu = cxgb3i_conn_xmit_pdu,
917 .parse_pdu_itt = cxgb3i_parse_itt,
919 /* TCP connect/disconnect */
920 .ep_connect = cxgb3i_ep_connect,
921 .ep_poll = cxgb3i_ep_poll,
922 .ep_disconnect = cxgb3i_ep_disconnect,
923 /* Error recovery timeout call */
924 .session_recovery_timedout = iscsi_session_recovery_timedout,
927 int cxgb3i_iscsi_init(void)
929 sw_tag_idx_bits = (__ilog2_u32(ISCSI_ITT_MASK)) + 1;
930 sw_tag_age_bits = (__ilog2_u32(ISCSI_AGE_MASK)) + 1;
931 cxgb3i_log_info("tag itt 0x%x, %u bits, age 0x%x, %u bits.\n",
932 ISCSI_ITT_MASK, sw_tag_idx_bits,
933 ISCSI_AGE_MASK, sw_tag_age_bits);
935 cxgb3i_scsi_transport =
936 iscsi_register_transport(&cxgb3i_iscsi_transport);
937 if (!cxgb3i_scsi_transport) {
938 cxgb3i_log_error("Could not register cxgb3i transport.\n");
941 cxgb3i_api_debug("cxgb3i transport 0x%p.\n", cxgb3i_scsi_transport);
945 void cxgb3i_iscsi_cleanup(void)
947 if (cxgb3i_scsi_transport) {
948 cxgb3i_api_debug("cxgb3i transport 0x%p.\n",
949 cxgb3i_scsi_transport);
950 iscsi_unregister_transport(&cxgb3i_iscsi_transport);