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 the resources held and cleanup h/w settings
105 * @t3dev: t3cdev adapter
107 void cxgb3i_adapter_remove(struct t3cdev *t3dev)
110 struct cxgb3i_adapter *snic;
112 /* remove from the list */
113 write_lock(&cxgb3i_snic_rwlock);
114 list_for_each_entry(snic, &cxgb3i_snic_list, list_head) {
115 if (snic->tdev == t3dev) {
116 list_del(&snic->list_head);
120 write_unlock(&cxgb3i_snic_rwlock);
123 for (i = 0; i < snic->hba_cnt; i++) {
125 cxgb3i_hba_host_remove(snic->hba[i]);
130 /* release ddp resources */
131 cxgb3i_adapter_ddp_cleanup(snic->tdev);
137 * cxgb3i_hba_find_by_netdev - find the cxgb3i_hba structure via net_device
138 * @t3dev: t3cdev adapter
140 struct cxgb3i_hba *cxgb3i_hba_find_by_netdev(struct net_device *ndev)
142 struct cxgb3i_adapter *snic;
145 read_lock(&cxgb3i_snic_rwlock);
146 list_for_each_entry(snic, &cxgb3i_snic_list, list_head) {
147 for (i = 0; i < snic->hba_cnt; i++) {
148 if (snic->hba[i]->ndev == ndev) {
149 read_unlock(&cxgb3i_snic_rwlock);
154 read_unlock(&cxgb3i_snic_rwlock);
159 * cxgb3i_hba_host_add - register a new host with scsi/iscsi
160 * @snic: the cxgb3i adapter
161 * @ndev: associated net_device
163 struct cxgb3i_hba *cxgb3i_hba_host_add(struct cxgb3i_adapter *snic,
164 struct net_device *ndev)
166 struct cxgb3i_hba *hba;
167 struct Scsi_Host *shost;
170 shost = iscsi_host_alloc(&cxgb3i_host_template,
171 sizeof(struct cxgb3i_hba), 1);
173 cxgb3i_log_info("iscsi_host_alloc failed.\n");
177 shost->transportt = cxgb3i_scsi_transport;
178 shost->max_lun = CXGB3I_MAX_LUN;
179 shost->max_id = CXGB3I_MAX_TARGET;
180 shost->max_channel = 0;
181 shost->max_cmd_len = 16;
183 hba = iscsi_host_priv(shost);
188 pci_dev_get(snic->pdev);
189 err = iscsi_host_add(shost, &snic->pdev->dev);
191 cxgb3i_log_info("iscsi_host_add failed.\n");
195 cxgb3i_api_debug("shost 0x%p, hba 0x%p, no %u.\n",
196 shost, hba, shost->host_no);
201 pci_dev_put(snic->pdev);
202 scsi_host_put(shost);
207 * cxgb3i_hba_host_remove - de-register the host with scsi/iscsi
208 * @hba: the cxgb3i hba
210 void cxgb3i_hba_host_remove(struct cxgb3i_hba *hba)
212 cxgb3i_api_debug("shost 0x%p, hba 0x%p, no %u.\n",
213 hba->shost, hba, hba->shost->host_no);
214 iscsi_host_remove(hba->shost);
215 pci_dev_put(hba->snic->pdev);
216 iscsi_host_free(hba->shost);
220 * cxgb3i_ep_connect - establish TCP connection to target portal
221 * @dst_addr: target IP address
222 * @non_blocking: blocking or non-blocking call
224 * Initiates a TCP/IP connection to the dst_addr
226 static struct iscsi_endpoint *cxgb3i_ep_connect(struct sockaddr *dst_addr,
229 struct iscsi_endpoint *ep;
230 struct cxgb3i_endpoint *cep;
231 struct cxgb3i_hba *hba;
232 struct s3_conn *c3cn = NULL;
235 c3cn = cxgb3i_c3cn_create();
237 cxgb3i_log_info("ep connect OOM.\n");
242 err = cxgb3i_c3cn_connect(c3cn, (struct sockaddr_in *)dst_addr);
244 cxgb3i_log_info("ep connect failed.\n");
247 hba = cxgb3i_hba_find_by_netdev(c3cn->dst_cache->dev);
250 cxgb3i_log_info("NOT going through cxgbi device.\n");
253 if (c3cn_is_closing(c3cn)) {
255 cxgb3i_log_info("ep connect unable to connect.\n");
259 ep = iscsi_create_endpoint(sizeof(*cep));
262 cxgb3i_log_info("iscsi alloc ep, OOM.\n");
269 cxgb3i_api_debug("ep 0x%p, 0x%p, c3cn 0x%p, hba 0x%p.\n",
274 cxgb3i_api_debug("conn 0x%p failed, release.\n", c3cn);
276 cxgb3i_c3cn_release(c3cn);
281 * cxgb3i_ep_poll - polls for TCP connection establishement
282 * @ep: TCP connection (endpoint) handle
283 * @timeout_ms: timeout value in milli secs
285 * polls for TCP connect request to complete
287 static int cxgb3i_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
289 struct cxgb3i_endpoint *cep = ep->dd_data;
290 struct s3_conn *c3cn = cep->c3cn;
292 if (!c3cn_is_established(c3cn))
294 cxgb3i_api_debug("ep 0x%p, c3cn 0x%p established.\n", ep, c3cn);
299 * cxgb3i_ep_disconnect - teardown TCP connection
300 * @ep: TCP connection (endpoint) handle
302 * teardown TCP connection
304 static void cxgb3i_ep_disconnect(struct iscsi_endpoint *ep)
306 struct cxgb3i_endpoint *cep = ep->dd_data;
307 struct cxgb3i_conn *cconn = cep->cconn;
309 cxgb3i_api_debug("ep 0x%p, cep 0x%p.\n", ep, cep);
311 if (cconn && cconn->conn) {
313 * stop the xmit path so the xmit_pdu function is
316 iscsi_suspend_tx(cconn->conn);
318 write_lock_bh(&cep->c3cn->callback_lock);
319 cep->c3cn->user_data = NULL;
321 write_unlock_bh(&cep->c3cn->callback_lock);
324 cxgb3i_api_debug("ep 0x%p, cep 0x%p, release c3cn 0x%p.\n",
326 cxgb3i_c3cn_release(cep->c3cn);
327 iscsi_destroy_endpoint(ep);
331 * cxgb3i_session_create - create a new iscsi session
332 * @cmds_max: max # of commands
333 * @qdepth: scsi queue depth
334 * @initial_cmdsn: initial iscsi CMDSN for this session
336 * Creates a new iSCSI session
338 static struct iscsi_cls_session *
339 cxgb3i_session_create(struct iscsi_endpoint *ep, u16 cmds_max, u16 qdepth,
342 struct cxgb3i_endpoint *cep;
343 struct cxgb3i_hba *hba;
344 struct Scsi_Host *shost;
345 struct iscsi_cls_session *cls_session;
346 struct iscsi_session *session;
349 cxgb3i_log_error("%s, missing endpoint.\n", __func__);
356 cxgb3i_api_debug("ep 0x%p, cep 0x%p, hba 0x%p.\n", ep, cep, hba);
357 BUG_ON(hba != iscsi_host_priv(shost));
359 cls_session = iscsi_session_setup(&cxgb3i_iscsi_transport, shost,
361 sizeof(struct iscsi_tcp_task) +
362 sizeof(struct cxgb3i_task_data),
363 initial_cmdsn, ISCSI_MAX_TARGET);
366 session = cls_session->dd_data;
367 if (iscsi_tcp_r2tpool_alloc(session))
373 iscsi_session_teardown(cls_session);
378 * cxgb3i_session_destroy - destroys iscsi session
379 * @cls_session: pointer to iscsi cls session
381 * Destroys an iSCSI session instance and releases its all resources held
383 static void cxgb3i_session_destroy(struct iscsi_cls_session *cls_session)
385 cxgb3i_api_debug("sess 0x%p.\n", cls_session);
386 iscsi_tcp_r2tpool_free(cls_session->dd_data);
387 iscsi_session_teardown(cls_session);
391 * cxgb3i_conn_max_xmit_dlength -- calc the max. xmit pdu segment size
392 * @conn: iscsi connection
393 * check the max. xmit pdu payload, reduce it if needed
395 static inline int cxgb3i_conn_max_xmit_dlength(struct iscsi_conn *conn)
398 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
399 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
400 unsigned int max = max(512 * MAX_SKB_FRAGS, SKB_TX_HEADROOM);
402 max = min(cconn->hba->snic->tx_max_size, max);
403 if (conn->max_xmit_dlength)
404 conn->max_xmit_dlength = min(conn->max_xmit_dlength, max);
406 conn->max_xmit_dlength = max;
407 align_pdu_size(conn->max_xmit_dlength);
408 cxgb3i_api_debug("conn 0x%p, max xmit %u.\n",
409 conn, conn->max_xmit_dlength);
414 * cxgb3i_conn_max_recv_dlength -- check the max. recv pdu segment size
415 * @conn: iscsi connection
416 * return 0 if the value is valid, < 0 otherwise.
418 static inline int cxgb3i_conn_max_recv_dlength(struct iscsi_conn *conn)
420 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
421 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
422 unsigned int max = cconn->hba->snic->rx_max_size;
425 if (conn->max_recv_dlength) {
426 if (conn->max_recv_dlength > max) {
427 cxgb3i_log_error("MaxRecvDataSegmentLength %u too big."
428 " Need to be <= %u.\n",
429 conn->max_recv_dlength, max);
432 conn->max_recv_dlength = min(conn->max_recv_dlength, max);
433 align_pdu_size(conn->max_recv_dlength);
435 conn->max_recv_dlength = max;
436 cxgb3i_api_debug("conn 0x%p, max recv %u.\n",
437 conn, conn->max_recv_dlength);
442 * cxgb3i_conn_create - create iscsi connection instance
443 * @cls_session: pointer to iscsi cls session
446 * Creates a new iSCSI connection instance for a given session
448 static struct iscsi_cls_conn *cxgb3i_conn_create(struct iscsi_cls_session
449 *cls_session, u32 cid)
451 struct iscsi_cls_conn *cls_conn;
452 struct iscsi_conn *conn;
453 struct iscsi_tcp_conn *tcp_conn;
454 struct cxgb3i_conn *cconn;
456 cxgb3i_api_debug("sess 0x%p, cid %u.\n", cls_session, cid);
458 cls_conn = iscsi_tcp_conn_setup(cls_session, sizeof(*cconn), cid);
461 conn = cls_conn->dd_data;
462 tcp_conn = conn->dd_data;
463 cconn = tcp_conn->dd_data;
470 * cxgb3i_conn_bind - binds iscsi sess, conn and endpoint together
471 * @cls_session: pointer to iscsi cls session
472 * @cls_conn: pointer to iscsi cls conn
473 * @transport_eph: 64-bit EP handle
474 * @is_leading: leading connection on this session?
476 * Binds together an iSCSI session, an iSCSI connection and a
477 * TCP connection. This routine returns error code if the TCP
478 * connection does not belong on the device iSCSI sess/conn is bound
481 static int cxgb3i_conn_bind(struct iscsi_cls_session *cls_session,
482 struct iscsi_cls_conn *cls_conn,
483 u64 transport_eph, int is_leading)
485 struct iscsi_conn *conn = cls_conn->dd_data;
486 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
487 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
488 struct cxgb3i_adapter *snic;
489 struct iscsi_endpoint *ep;
490 struct cxgb3i_endpoint *cep;
491 struct s3_conn *c3cn;
494 ep = iscsi_lookup_endpoint(transport_eph);
498 /* setup ddp pagesize */
501 snic = cep->hba->snic;
502 err = cxgb3i_setup_conn_host_pagesize(snic->tdev, c3cn->tid, 0);
506 cxgb3i_api_debug("ep 0x%p, cls sess 0x%p, cls conn 0x%p.\n",
507 ep, cls_session, cls_conn);
509 err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
513 /* calculate the tag idx bits needed for this conn based on cmds_max */
514 cconn->task_idx_bits = (__ilog2_u32(conn->session->cmds_max - 1)) + 1;
515 cxgb3i_api_debug("session cmds_max 0x%x, bits %u.\n",
516 conn->session->cmds_max, cconn->task_idx_bits);
518 read_lock(&c3cn->callback_lock);
519 c3cn->user_data = conn;
520 cconn->hba = cep->hba;
523 read_unlock(&c3cn->callback_lock);
525 cxgb3i_conn_max_xmit_dlength(conn);
526 cxgb3i_conn_max_recv_dlength(conn);
528 spin_lock_bh(&conn->session->lock);
529 sprintf(conn->portal_address, NIPQUAD_FMT,
530 NIPQUAD(c3cn->daddr.sin_addr.s_addr));
531 conn->portal_port = ntohs(c3cn->daddr.sin_port);
532 spin_unlock_bh(&conn->session->lock);
534 /* init recv engine */
535 iscsi_tcp_hdr_recv_prep(tcp_conn);
541 * cxgb3i_conn_get_param - return iscsi connection parameter to caller
542 * @cls_conn: pointer to iscsi cls conn
543 * @param: parameter type identifier
544 * @buf: buffer pointer
546 * returns iSCSI connection parameters
548 static int cxgb3i_conn_get_param(struct iscsi_cls_conn *cls_conn,
549 enum iscsi_param param, char *buf)
551 struct iscsi_conn *conn = cls_conn->dd_data;
554 cxgb3i_api_debug("cls_conn 0x%p, param %d.\n", cls_conn, param);
557 case ISCSI_PARAM_CONN_PORT:
558 spin_lock_bh(&conn->session->lock);
559 len = sprintf(buf, "%hu\n", conn->portal_port);
560 spin_unlock_bh(&conn->session->lock);
562 case ISCSI_PARAM_CONN_ADDRESS:
563 spin_lock_bh(&conn->session->lock);
564 len = sprintf(buf, "%s\n", conn->portal_address);
565 spin_unlock_bh(&conn->session->lock);
568 return iscsi_conn_get_param(cls_conn, param, buf);
575 * cxgb3i_conn_set_param - set iscsi connection parameter
576 * @cls_conn: pointer to iscsi cls conn
577 * @param: parameter type identifier
578 * @buf: buffer pointer
579 * @buflen: buffer length
581 * set iSCSI connection parameters
583 static int cxgb3i_conn_set_param(struct iscsi_cls_conn *cls_conn,
584 enum iscsi_param param, char *buf, int buflen)
586 struct iscsi_conn *conn = cls_conn->dd_data;
587 struct iscsi_session *session = conn->session;
588 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
589 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
590 struct cxgb3i_adapter *snic = cconn->hba->snic;
591 struct s3_conn *c3cn = cconn->cep->c3cn;
595 case ISCSI_PARAM_HDRDGST_EN:
596 err = iscsi_set_param(cls_conn, param, buf, buflen);
597 if (!err && conn->hdrdgst_en)
598 err = cxgb3i_setup_conn_digest(snic->tdev, c3cn->tid,
600 conn->datadgst_en, 0);
602 case ISCSI_PARAM_DATADGST_EN:
603 err = iscsi_set_param(cls_conn, param, buf, buflen);
604 if (!err && conn->datadgst_en)
605 err = cxgb3i_setup_conn_digest(snic->tdev, c3cn->tid,
607 conn->datadgst_en, 0);
609 case ISCSI_PARAM_MAX_R2T:
610 sscanf(buf, "%d", &value);
611 if (value <= 0 || !is_power_of_2(value))
613 if (session->max_r2t == value)
615 iscsi_tcp_r2tpool_free(session);
616 err = iscsi_set_param(cls_conn, param, buf, buflen);
617 if (!err && iscsi_tcp_r2tpool_alloc(session))
619 case ISCSI_PARAM_MAX_RECV_DLENGTH:
620 err = iscsi_set_param(cls_conn, param, buf, buflen);
622 err = cxgb3i_conn_max_recv_dlength(conn);
624 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
625 err = iscsi_set_param(cls_conn, param, buf, buflen);
627 err = cxgb3i_conn_max_xmit_dlength(conn);
630 return iscsi_set_param(cls_conn, param, buf, buflen);
636 * cxgb3i_host_set_param - configure host (adapter) related parameters
637 * @shost: scsi host pointer
638 * @param: parameter type identifier
639 * @buf: buffer pointer
641 static int cxgb3i_host_set_param(struct Scsi_Host *shost,
642 enum iscsi_host_param param,
643 char *buf, int buflen)
645 struct cxgb3i_hba *hba = iscsi_host_priv(shost);
647 cxgb3i_api_debug("param %d, buf %s.\n", param, buf);
650 case ISCSI_HOST_PARAM_IPADDRESS:
652 __be32 addr = in_aton(buf);
653 cxgb3i_set_private_ipv4addr(hba->ndev, addr);
656 case ISCSI_HOST_PARAM_HWADDRESS:
657 case ISCSI_HOST_PARAM_NETDEV_NAME:
661 return iscsi_host_set_param(shost, param, buf, buflen);
666 * cxgb3i_host_get_param - returns host (adapter) related parameters
667 * @shost: scsi host pointer
668 * @param: parameter type identifier
669 * @buf: buffer pointer
671 static int cxgb3i_host_get_param(struct Scsi_Host *shost,
672 enum iscsi_host_param param, char *buf)
674 struct cxgb3i_hba *hba = iscsi_host_priv(shost);
677 cxgb3i_api_debug("hba %s, param %d.\n", hba->ndev->name, param);
680 case ISCSI_HOST_PARAM_HWADDRESS:
681 len = sysfs_format_mac(buf, hba->ndev->dev_addr, 6);
683 case ISCSI_HOST_PARAM_NETDEV_NAME:
684 len = sprintf(buf, "%s\n", hba->ndev->name);
686 case ISCSI_HOST_PARAM_IPADDRESS:
690 addr = cxgb3i_get_private_ipv4addr(hba->ndev);
691 len = sprintf(buf, NIPQUAD_FMT, NIPQUAD(addr));
695 return iscsi_host_get_param(shost, param, buf);
701 * cxgb3i_conn_get_stats - returns iSCSI stats
702 * @cls_conn: pointer to iscsi cls conn
703 * @stats: pointer to iscsi statistic struct
705 static void cxgb3i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
706 struct iscsi_stats *stats)
708 struct iscsi_conn *conn = cls_conn->dd_data;
710 stats->txdata_octets = conn->txdata_octets;
711 stats->rxdata_octets = conn->rxdata_octets;
712 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
713 stats->dataout_pdus = conn->dataout_pdus_cnt;
714 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
715 stats->datain_pdus = conn->datain_pdus_cnt;
716 stats->r2t_pdus = conn->r2t_pdus_cnt;
717 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
718 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
719 stats->digest_err = 0;
720 stats->timeout_err = 0;
721 stats->custom_length = 1;
722 strcpy(stats->custom[0].desc, "eh_abort_cnt");
723 stats->custom[0].value = conn->eh_abort_cnt;
727 * cxgb3i_parse_itt - get the idx and age bits from a given tag
728 * @conn: iscsi connection
730 * @idx: task index, filled in by this function
731 * @age: session age, filled in by this function
733 static void cxgb3i_parse_itt(struct iscsi_conn *conn, itt_t itt,
736 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
737 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
738 struct cxgb3i_adapter *snic = cconn->hba->snic;
739 u32 tag = ntohl((__force u32) itt);
742 sw_bits = cxgb3i_tag_nonrsvd_bits(&snic->tag_format, tag);
744 *idx = sw_bits & ((1 << cconn->task_idx_bits) - 1);
746 *age = (sw_bits >> cconn->task_idx_bits) & ISCSI_AGE_MASK;
748 cxgb3i_tag_debug("parse tag 0x%x/0x%x, sw 0x%x, itt 0x%x, age 0x%x.\n",
749 tag, itt, sw_bits, idx ? *idx : 0xFFFFF,
754 * cxgb3i_reserve_itt - generate tag for a give task
756 * @hdr_itt: tag, filled in by this function
757 * Set up ddp for scsi read tasks if possible.
759 int cxgb3i_reserve_itt(struct iscsi_task *task, itt_t *hdr_itt)
761 struct scsi_cmnd *sc = task->sc;
762 struct iscsi_conn *conn = task->conn;
763 struct iscsi_session *sess = conn->session;
764 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
765 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
766 struct cxgb3i_adapter *snic = cconn->hba->snic;
767 struct cxgb3i_tag_format *tformat = &snic->tag_format;
768 u32 sw_tag = (sess->age << cconn->task_idx_bits) | task->itt;
773 (scsi_bidi_cmnd(sc) || sc->sc_data_direction == DMA_FROM_DEVICE) &&
774 cxgb3i_sw_tag_usable(tformat, sw_tag)) {
775 struct s3_conn *c3cn = cconn->cep->c3cn;
776 struct cxgb3i_gather_list *gl;
778 gl = cxgb3i_ddp_make_gl(scsi_in(sc)->length,
779 scsi_in(sc)->table.sgl,
780 scsi_in(sc)->table.nents,
785 err = cxgb3i_ddp_tag_reserve(snic->tdev, c3cn->tid,
789 cxgb3i_ddp_release_gl(gl, snic->pdev);
794 tag = cxgb3i_set_non_ddp_tag(tformat, sw_tag);
795 /* the itt need to sent in big-endian order */
796 *hdr_itt = (__force itt_t)htonl(tag);
798 cxgb3i_tag_debug("new tag 0x%x/0x%x (itt 0x%x, age 0x%x).\n",
799 tag, *hdr_itt, task->itt, sess->age);
804 * cxgb3i_release_itt - release the tag for a given task
807 * If the tag is a ddp tag, release the ddp setup
809 void cxgb3i_release_itt(struct iscsi_task *task, itt_t hdr_itt)
811 struct scsi_cmnd *sc = task->sc;
812 struct iscsi_tcp_conn *tcp_conn = task->conn->dd_data;
813 struct cxgb3i_conn *cconn = tcp_conn->dd_data;
814 struct cxgb3i_adapter *snic = cconn->hba->snic;
815 struct cxgb3i_tag_format *tformat = &snic->tag_format;
816 u32 tag = ntohl((__force u32)hdr_itt);
818 cxgb3i_tag_debug("release tag 0x%x.\n", tag);
821 (scsi_bidi_cmnd(sc) || sc->sc_data_direction == DMA_FROM_DEVICE) &&
822 cxgb3i_is_ddp_tag(tformat, tag))
823 cxgb3i_ddp_tag_release(snic->tdev, tag);
827 * cxgb3i_host_template -- Scsi_Host_Template structure
828 * used when registering with the scsi mid layer
830 static struct scsi_host_template cxgb3i_host_template = {
831 .module = THIS_MODULE,
832 .name = "Chelsio S3xx iSCSI Initiator",
833 .proc_name = "cxgb3i",
834 .queuecommand = iscsi_queuecommand,
835 .change_queue_depth = iscsi_change_queue_depth,
836 .can_queue = CXGB3I_SCSI_QDEPTH_DFLT - 1,
837 .sg_tablesize = SG_ALL,
838 .max_sectors = 0xFFFF,
839 .cmd_per_lun = CXGB3I_SCSI_QDEPTH_DFLT,
840 .eh_abort_handler = iscsi_eh_abort,
841 .eh_device_reset_handler = iscsi_eh_device_reset,
842 .eh_target_reset_handler = iscsi_eh_target_reset,
843 .use_clustering = DISABLE_CLUSTERING,
847 static struct iscsi_transport cxgb3i_iscsi_transport = {
848 .owner = THIS_MODULE,
850 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
851 | CAP_DATADGST | CAP_DIGEST_OFFLOAD |
853 .param_mask = ISCSI_MAX_RECV_DLENGTH |
854 ISCSI_MAX_XMIT_DLENGTH |
857 ISCSI_INITIAL_R2T_EN |
862 ISCSI_PDU_INORDER_EN |
863 ISCSI_DATASEQ_INORDER_EN |
868 ISCSI_PERSISTENT_PORT |
869 ISCSI_PERSISTENT_ADDRESS |
870 ISCSI_TARGET_NAME | ISCSI_TPGT |
871 ISCSI_USERNAME | ISCSI_PASSWORD |
872 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
873 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
875 ISCSI_PING_TMO | ISCSI_RECV_TMO |
876 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
877 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
878 ISCSI_HOST_INITIATOR_NAME | ISCSI_HOST_NETDEV_NAME,
879 .get_host_param = cxgb3i_host_get_param,
880 .set_host_param = cxgb3i_host_set_param,
881 /* session management */
882 .create_session = cxgb3i_session_create,
883 .destroy_session = cxgb3i_session_destroy,
884 .get_session_param = iscsi_session_get_param,
885 /* connection management */
886 .create_conn = cxgb3i_conn_create,
887 .bind_conn = cxgb3i_conn_bind,
888 .destroy_conn = iscsi_tcp_conn_teardown,
889 .start_conn = iscsi_conn_start,
890 .stop_conn = iscsi_conn_stop,
891 .get_conn_param = cxgb3i_conn_get_param,
892 .set_param = cxgb3i_conn_set_param,
893 .get_stats = cxgb3i_conn_get_stats,
894 /* pdu xmit req. from user space */
895 .send_pdu = iscsi_conn_send_pdu,
897 .init_task = iscsi_tcp_task_init,
898 .xmit_task = iscsi_tcp_task_xmit,
899 .cleanup_task = cxgb3i_conn_cleanup_task,
902 .alloc_pdu = cxgb3i_conn_alloc_pdu,
903 .init_pdu = cxgb3i_conn_init_pdu,
904 .xmit_pdu = cxgb3i_conn_xmit_pdu,
905 .parse_pdu_itt = cxgb3i_parse_itt,
907 /* TCP connect/disconnect */
908 .ep_connect = cxgb3i_ep_connect,
909 .ep_poll = cxgb3i_ep_poll,
910 .ep_disconnect = cxgb3i_ep_disconnect,
911 /* Error recovery timeout call */
912 .session_recovery_timedout = iscsi_session_recovery_timedout,
915 int cxgb3i_iscsi_init(void)
917 sw_tag_idx_bits = (__ilog2_u32(ISCSI_ITT_MASK)) + 1;
918 sw_tag_age_bits = (__ilog2_u32(ISCSI_AGE_MASK)) + 1;
919 cxgb3i_log_info("tag itt 0x%x, %u bits, age 0x%x, %u bits.\n",
920 ISCSI_ITT_MASK, sw_tag_idx_bits,
921 ISCSI_AGE_MASK, sw_tag_age_bits);
923 cxgb3i_scsi_transport =
924 iscsi_register_transport(&cxgb3i_iscsi_transport);
925 if (!cxgb3i_scsi_transport) {
926 cxgb3i_log_error("Could not register cxgb3i transport.\n");
929 cxgb3i_api_debug("cxgb3i transport 0x%p.\n", cxgb3i_scsi_transport);
933 void cxgb3i_iscsi_cleanup(void)
935 if (cxgb3i_scsi_transport) {
936 cxgb3i_api_debug("cxgb3i transport 0x%p.\n",
937 cxgb3i_scsi_transport);
938 iscsi_unregister_transport(&cxgb3i_iscsi_transport);