aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-03-17 20:54:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-17 20:54:40 -0400
commitc55d267de274d308927b60c3e740c1a826832317 (patch)
tree21b53a8c725d9f9650f60d94b349459d5b8dae10
parent61ef46fd45c3c62dc7c880a45dd2aa841b9af8fb (diff)
parentbc898c97f7ba24def788d9f80786cf028a197122 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6: (170 commits) [SCSI] scsi_dh_rdac: Add MD36xxf into device list [SCSI] scsi_debug: add consecutive medium errors [SCSI] libsas: fix ata list corruption issue [SCSI] hpsa: export resettable host attribute [SCSI] hpsa: move device attributes to avoid forward declarations [SCSI] scsi_debug: Logical Block Provisioning (SBC3r26) [SCSI] sd: Logical Block Provisioning update [SCSI] Include protection operation in SCSI command trace [SCSI] hpsa: fix incorrect PCI IDs and add two new ones (2nd try) [SCSI] target: Fix volume size misreporting for volumes > 2TB [SCSI] bnx2fc: Broadcom FCoE offload driver [SCSI] fcoe: fix broken fcoe interface reset [SCSI] fcoe: precedence bug in fcoe_filter_frames() [SCSI] libfcoe: Remove stale fcoe-netdev entries [SCSI] libfcoe: Move FCOE_MTU definition from fcoe.h to libfcoe.h [SCSI] libfc: introduce __fc_fill_fc_hdr that accepts fc_hdr as an argument [SCSI] fcoe, libfc: initialize EM anchors list and then update npiv EMs [SCSI] Revert "[SCSI] libfc: fix exchange being deleted when the abort itself is timed out" [SCSI] libfc: Fixing a memory leak when destroying an interface [SCSI] megaraid_sas: Version and Changelog update ... Fix up trivial conflicts due to whitespace differences in drivers/scsi/libsas/{sas_ata.c,sas_scsi_host.c}
-rw-r--r--Documentation/scsi/ChangeLog.megaraid_sas23
-rw-r--r--Documentation/scsi/hpsa.txt23
-rw-r--r--Documentation/scsi/scsi_mid_low_api.txt14
-rw-r--r--MAINTAINERS3
-rw-r--r--block/blk-core.c23
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.c26
-rw-r--r--drivers/md/dm-mpath.c22
-rw-r--r--drivers/message/fusion/lsi/mpi_cnfg.h1
-rw-r--r--drivers/message/fusion/lsi/mpi_ioc.h1
-rw-r--r--drivers/message/fusion/mptbase.c7
-rw-r--r--drivers/message/fusion/mptctl.c4
-rw-r--r--drivers/message/fusion/mptsas.c7
-rw-r--r--drivers/net/bnx2x/bnx2x_main.c7
-rw-r--r--drivers/s390/scsi/zfcp_aux.c80
-rw-r--r--drivers/s390/scsi/zfcp_def.h15
-rw-r--r--drivers/s390/scsi/zfcp_erp.c4
-rw-r--r--drivers/s390/scsi/zfcp_ext.h9
-rw-r--r--drivers/s390/scsi/zfcp_fc.c333
-rw-r--r--drivers/s390/scsi/zfcp_fc.h124
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c27
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c71
-rw-r--r--drivers/scsi/Kconfig1
-rw-r--r--drivers/scsi/Makefile1
-rw-r--r--drivers/scsi/NCR5380.c3
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c4
-rw-r--r--drivers/scsi/be2iscsi/be_iscsi.c18
-rw-r--r--drivers/scsi/be2iscsi/be_iscsi.h4
-rw-r--r--drivers/scsi/be2iscsi/be_main.c3
-rw-r--r--drivers/scsi/bnx2fc/57xx_hsi_bnx2fc.h1080
-rw-r--r--drivers/scsi/bnx2fc/Kconfig11
-rw-r--r--drivers/scsi/bnx2fc/Makefile3
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc.h511
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_constants.h206
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_debug.h70
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_els.c515
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_fcoe.c2535
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_hwi.c1868
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c1833
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_tgt.c844
-rw-r--r--drivers/scsi/bnx2i/bnx2i.h4
-rw-r--r--drivers/scsi/bnx2i/bnx2i_hwi.c125
-rw-r--r--drivers/scsi/bnx2i/bnx2i_init.c29
-rw-r--r--drivers/scsi/bnx2i/bnx2i_iscsi.c53
-rw-r--r--drivers/scsi/cxgbi/cxgb3i/cxgb3i.c56
-rw-r--r--drivers/scsi/cxgbi/cxgb3i/cxgb3i.h19
-rw-r--r--drivers/scsi/cxgbi/cxgb4i/cxgb4i.c7
-rw-r--r--drivers/scsi/cxgbi/libcxgbi.c66
-rw-r--r--drivers/scsi/cxgbi/libcxgbi.h5
-rw-r--r--drivers/scsi/device_handler/scsi_dh.c112
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c18
-rw-r--r--drivers/scsi/device_handler/scsi_dh_emc.c2
-rw-r--r--drivers/scsi/device_handler/scsi_dh_hp_sw.c7
-rw-r--r--drivers/scsi/device_handler/scsi_dh_rdac.c26
-rw-r--r--drivers/scsi/fcoe/Makefile2
-rw-r--r--drivers/scsi/fcoe/fcoe.c621
-rw-r--r--drivers/scsi/fcoe/fcoe.h50
-rw-r--r--drivers/scsi/fcoe/fcoe_ctlr.c (renamed from drivers/scsi/fcoe/libfcoe.c)40
-rw-r--r--drivers/scsi/fcoe/fcoe_transport.c770
-rw-r--r--drivers/scsi/fcoe/libfcoe.h31
-rw-r--r--drivers/scsi/fnic/fnic.h2
-rw-r--r--drivers/scsi/fnic/vnic_dev.c2
-rw-r--r--drivers/scsi/hpsa.c579
-rw-r--r--drivers/scsi/hpsa.h9
-rw-r--r--drivers/scsi/hpsa_cmd.h4
-rw-r--r--drivers/scsi/ipr.c9
-rw-r--r--drivers/scsi/iscsi_tcp.c134
-rw-r--r--drivers/scsi/iscsi_tcp.h4
-rw-r--r--drivers/scsi/libfc/fc_exch.c111
-rw-r--r--drivers/scsi/libfc/fc_fcp.c39
-rw-r--r--drivers/scsi/libfc/fc_libfc.c120
-rw-r--r--drivers/scsi/libfc/fc_libfc.h14
-rw-r--r--drivers/scsi/libfc/fc_lport.c69
-rw-r--r--drivers/scsi/libfc/fc_npiv.c10
-rw-r--r--drivers/scsi/libfc/fc_rport.c191
-rw-r--r--drivers/scsi/libiscsi.c44
-rw-r--r--drivers/scsi/libsas/Kconfig8
-rw-r--r--drivers/scsi/libsas/Makefile4
-rw-r--r--drivers/scsi/libsas/sas_ata.c80
-rw-r--r--drivers/scsi/libsas/sas_dump.c4
-rw-r--r--drivers/scsi/libsas/sas_dump.h12
-rw-r--r--drivers/scsi/libsas/sas_expander.c5
-rw-r--r--drivers/scsi/libsas/sas_internal.h6
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c3
-rw-r--r--drivers/scsi/lpfc/lpfc.h15
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c123
-rw-r--r--drivers/scsi/lpfc/lpfc_crtn.h9
-rw-r--r--drivers/scsi/lpfc/lpfc_ct.c49
-rw-r--r--drivers/scsi/lpfc/lpfc_debugfs.c962
-rw-r--r--drivers/scsi/lpfc/lpfc_debugfs.h60
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c173
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c18
-rw-r--r--drivers/scsi/lpfc/lpfc_hw.h11
-rw-r--r--drivers/scsi/lpfc/lpfc_hw4.h104
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c134
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c19
-rw-r--r--drivers/scsi/lpfc/lpfc_nportdisc.c11
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c113
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c217
-rw-r--r--drivers/scsi/lpfc/lpfc_sli4.h8
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h4
-rw-r--r--drivers/scsi/lpfc/lpfc_vport.c4
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h10
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c147
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fusion.c19
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2.h5
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h6
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_history.txt384
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_sas.h7
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_tool.h8
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.c128
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.h40
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_scsih.c1
-rw-r--r--drivers/scsi/osd/osd_initiator.c20
-rw-r--r--drivers/scsi/pm8001/pm8001_hwi.c37
-rw-r--r--drivers/scsi/pm8001/pm8001_init.c27
-rw-r--r--drivers/scsi/pm8001/pm8001_sas.h10
-rw-r--r--drivers/scsi/pmcraid.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h9
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h1
-rw-r--r--drivers/scsi/qla2xxx/qla_gs.c21
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c41
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c52
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c45
-rw-r--r--drivers/scsi/qla2xxx/qla_nx.c191
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c57
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h4
-rw-r--r--drivers/scsi/scsi_debug.c192
-rw-r--r--drivers/scsi/scsi_devinfo.c85
-rw-r--r--drivers/scsi/scsi_error.c24
-rw-r--r--drivers/scsi/scsi_lib.c36
-rw-r--r--drivers/scsi/scsi_priv.h2
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c104
-rw-r--r--drivers/scsi/sd.c229
-rw-r--r--drivers/scsi/sd.h25
-rw-r--r--drivers/target/target_core_cdb.c8
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/scsi/fc/fc_ns.h11
-rw-r--r--include/scsi/fc_encode.h26
-rw-r--r--include/scsi/libfc.h74
-rw-r--r--include/scsi/libfcoe.h105
-rw-r--r--include/scsi/libiscsi.h8
-rw-r--r--include/scsi/scsi.h5
-rw-r--r--include/scsi/scsi_device.h1
-rw-r--r--include/scsi/scsi_transport_iscsi.h6
-rw-r--r--include/trace/events/scsi.h28
145 files changed, 15384 insertions, 2733 deletions
diff --git a/Documentation/scsi/ChangeLog.megaraid_sas b/Documentation/scsi/ChangeLog.megaraid_sas
index b64d10d221ec..4d9ce73ff730 100644
--- a/Documentation/scsi/ChangeLog.megaraid_sas
+++ b/Documentation/scsi/ChangeLog.megaraid_sas
@@ -1,3 +1,26 @@
1Release Date : Thu. Feb 24, 2011 17:00:00 PST 2010 -
2 (emaild-id:megaraidlinux@lsi.com)
3 Adam Radford
4Current Version : 00.00.05.34-rc1
5Old Version : 00.00.05.29-rc1
6 1. Fix some failure gotos from megasas_probe_one(), etc.
7 2. Add missing check_and_restore_queue_depth() call in
8 complete_cmd_fusion().
9 3. Enable MSI-X before calling megasas_init_fw().
10 4. Call tasklet_schedule() even if outbound_intr_status == 0 for MFI based
11 boards in MSI-X mode.
12 5. Fix megasas_probe_one() to clear PCI_MSIX_FLAGS_ENABLE in msi control
13 register in kdump kernel.
14 6. Fix megasas_get_cmd() to only print "Command pool empty" if
15 megasas_dbg_lvl is set.
16 7. Fix megasas_build_dcdb_fusion() to not filter by TYPE_DISK.
17 8. Fix megasas_build_dcdb_fusion() to use io_request->LUN[1] field.
18 9. Add MR_EVT_CFG_CLEARED to megasas_aen_polling().
19 10. Fix tasklet_init() in megasas_init_fw() to use instancet->tasklet.
20 11. Fix fault state handling in megasas_transition_to_ready().
21 12. Fix max_sectors setting for IEEE SGL's.
22 13. Fix iMR OCR support to work correctly.
23-------------------------------------------------------------------------------
1Release Date : Tues. Dec 14, 2010 17:00:00 PST 2010 - 24Release Date : Tues. Dec 14, 2010 17:00:00 PST 2010 -
2 (emaild-id:megaraidlinux@lsi.com) 25 (emaild-id:megaraidlinux@lsi.com)
3 Adam Radford 26 Adam Radford
diff --git a/Documentation/scsi/hpsa.txt b/Documentation/scsi/hpsa.txt
index dca658362cbf..891435a72fce 100644
--- a/Documentation/scsi/hpsa.txt
+++ b/Documentation/scsi/hpsa.txt
@@ -28,6 +28,12 @@ boot parameter "hpsa_allow_any=1" is specified, however these are not tested
28nor supported by HP with this driver. For older Smart Arrays, the cciss 28nor supported by HP with this driver. For older Smart Arrays, the cciss
29driver should still be used. 29driver should still be used.
30 30
31The "hpsa_simple_mode=1" boot parameter may be used to prevent the driver from
32putting the controller into "performant" mode. The difference is that with simple
33mode, each command completion requires an interrupt, while with "performant mode"
34(the default, and ordinarily better performing) it is possible to have multiple
35command completions indicated by a single interrupt.
36
31HPSA specific entries in /sys 37HPSA specific entries in /sys
32----------------------------- 38-----------------------------
33 39
@@ -39,6 +45,8 @@ HPSA specific entries in /sys
39 45
40 /sys/class/scsi_host/host*/rescan 46 /sys/class/scsi_host/host*/rescan
41 /sys/class/scsi_host/host*/firmware_revision 47 /sys/class/scsi_host/host*/firmware_revision
48 /sys/class/scsi_host/host*/resettable
49 /sys/class/scsi_host/host*/transport_mode
42 50
43 the host "rescan" attribute is a write only attribute. Writing to this 51 the host "rescan" attribute is a write only attribute. Writing to this
44 attribute will cause the driver to scan for new, changed, or removed devices 52 attribute will cause the driver to scan for new, changed, or removed devices
@@ -55,6 +63,21 @@ HPSA specific entries in /sys
55 root@host:/sys/class/scsi_host/host4# cat firmware_revision 63 root@host:/sys/class/scsi_host/host4# cat firmware_revision
56 7.14 64 7.14
57 65
66 The transport_mode indicates whether the controller is in "performant"
67 or "simple" mode. This is controlled by the "hpsa_simple_mode" module
68 parameter.
69
70 The "resettable" read-only attribute indicates whether a particular
71 controller is able to honor the "reset_devices" kernel parameter. If the
72 device is resettable, this file will contain a "1", otherwise, a "0". This
73 parameter is used by kdump, for example, to reset the controller at driver
74 load time to eliminate any outstanding commands on the controller and get the
75 controller into a known state so that the kdump initiated i/o will work right
76 and not be disrupted in any way by stale commands or other stale state
77 remaining on the controller from the previous kernel. This attribute enables
78 kexec tools to warn the user if they attempt to designate a device which is
79 unable to honor the reset_devices kernel parameter as a dump device.
80
58 HPSA specific disk attributes: 81 HPSA specific disk attributes:
59 ------------------------------ 82 ------------------------------
60 83
diff --git a/Documentation/scsi/scsi_mid_low_api.txt b/Documentation/scsi/scsi_mid_low_api.txt
index df322c103466..5f17d29c59b5 100644
--- a/Documentation/scsi/scsi_mid_low_api.txt
+++ b/Documentation/scsi/scsi_mid_low_api.txt
@@ -1343,7 +1343,7 @@ Members of interest:
1343 underruns (overruns should be rare). If possible an LLD 1343 underruns (overruns should be rare). If possible an LLD
1344 should set 'resid' prior to invoking 'done'. The most 1344 should set 'resid' prior to invoking 'done'. The most
1345 interesting case is data transfers from a SCSI target 1345 interesting case is data transfers from a SCSI target
1346 device device (i.e. READs) that underrun. 1346 device (e.g. READs) that underrun.
1347 underflow - LLD should place (DID_ERROR << 16) in 'result' if 1347 underflow - LLD should place (DID_ERROR << 16) in 'result' if
1348 actual number of bytes transferred is less than this 1348 actual number of bytes transferred is less than this
1349 figure. Not many LLDs implement this check and some that 1349 figure. Not many LLDs implement this check and some that
@@ -1351,6 +1351,18 @@ Members of interest:
1351 report a DID_ERROR. Better for an LLD to implement 1351 report a DID_ERROR. Better for an LLD to implement
1352 'resid'. 1352 'resid'.
1353 1353
1354It is recommended that a LLD set 'resid' on data transfers from a SCSI
1355target device (e.g. READs). It is especially important that 'resid' is set
1356when such data transfers have sense keys of MEDIUM ERROR and HARDWARE ERROR
1357(and possibly RECOVERED ERROR). In these cases if a LLD is in doubt how much
1358data has been received then the safest approach is to indicate no bytes have
1359been received. For example: to indicate that no valid data has been received
1360a LLD might use these helpers:
1361 scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
1362where 'SCpnt' is a pointer to a scsi_cmnd object. To indicate only three 512
1363bytes blocks has been received 'resid' could be set like this:
1364 scsi_set_resid(SCpnt, scsi_bufflen(SCpnt) - (3 * 512));
1365
1354The scsi_cmnd structure is defined in include/scsi/scsi_cmnd.h 1366The scsi_cmnd structure is defined in include/scsi/scsi_cmnd.h
1355 1367
1356 1368
diff --git a/MAINTAINERS b/MAINTAINERS
index c07b1d7bb02e..ab61fb44b4a3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5359,8 +5359,7 @@ S: Supported
5359F: drivers/s390/crypto/ 5359F: drivers/s390/crypto/
5360 5360
5361S390 ZFCP DRIVER 5361S390 ZFCP DRIVER
5362M: Christof Schmitt <christof.schmitt@de.ibm.com> 5362M: Steffen Maier <maier@linux.vnet.ibm.com>
5363M: Swen Schillig <swen@vnet.ibm.com>
5364M: linux390@de.ibm.com 5363M: linux390@de.ibm.com
5365L: linux-s390@vger.kernel.org 5364L: linux-s390@vger.kernel.org
5366W: http://www.ibm.com/developerworks/linux/linux390/ 5365W: http://www.ibm.com/developerworks/linux/linux390/
diff --git a/block/blk-core.c b/block/blk-core.c
index 518dd423a5fe..a63336d49f30 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -2045,9 +2045,26 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
2045 2045
2046 if (error && req->cmd_type == REQ_TYPE_FS && 2046 if (error && req->cmd_type == REQ_TYPE_FS &&
2047 !(req->cmd_flags & REQ_QUIET)) { 2047 !(req->cmd_flags & REQ_QUIET)) {
2048 printk(KERN_ERR "end_request: I/O error, dev %s, sector %llu\n", 2048 char *error_type;
2049 req->rq_disk ? req->rq_disk->disk_name : "?", 2049
2050 (unsigned long long)blk_rq_pos(req)); 2050 switch (error) {
2051 case -ENOLINK:
2052 error_type = "recoverable transport";
2053 break;
2054 case -EREMOTEIO:
2055 error_type = "critical target";
2056 break;
2057 case -EBADE:
2058 error_type = "critical nexus";
2059 break;
2060 case -EIO:
2061 default:
2062 error_type = "I/O";
2063 break;
2064 }
2065 printk(KERN_ERR "end_request: %s error, dev %s, sector %llu\n",
2066 error_type, req->rq_disk ? req->rq_disk->disk_name : "?",
2067 (unsigned long long)blk_rq_pos(req));
2051 } 2068 }
2052 2069
2053 blk_account_io_completion(req, nr_bytes); 2070 blk_account_io_completion(req, nr_bytes);
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index 7b2fc98e2f2b..8db008de5392 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -532,6 +532,29 @@ iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *s
532 stats->custom[3].value = conn->fmr_unalign_cnt; 532 stats->custom[3].value = conn->fmr_unalign_cnt;
533} 533}
534 534
535static int iscsi_iser_get_ep_param(struct iscsi_endpoint *ep,
536 enum iscsi_param param, char *buf)
537{
538 struct iser_conn *ib_conn = ep->dd_data;
539 int len;
540
541 switch (param) {
542 case ISCSI_PARAM_CONN_PORT:
543 case ISCSI_PARAM_CONN_ADDRESS:
544 if (!ib_conn || !ib_conn->cma_id)
545 return -ENOTCONN;
546
547 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
548 &ib_conn->cma_id->route.addr.dst_addr,
549 param, buf);
550 break;
551 default:
552 return -ENOSYS;
553 }
554
555 return len;
556}
557
535static struct iscsi_endpoint * 558static struct iscsi_endpoint *
536iscsi_iser_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, 559iscsi_iser_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
537 int non_blocking) 560 int non_blocking)
@@ -637,6 +660,8 @@ static struct iscsi_transport iscsi_iser_transport = {
637 ISCSI_MAX_BURST | 660 ISCSI_MAX_BURST |
638 ISCSI_PDU_INORDER_EN | 661 ISCSI_PDU_INORDER_EN |
639 ISCSI_DATASEQ_INORDER_EN | 662 ISCSI_DATASEQ_INORDER_EN |
663 ISCSI_CONN_PORT |
664 ISCSI_CONN_ADDRESS |
640 ISCSI_EXP_STATSN | 665 ISCSI_EXP_STATSN |
641 ISCSI_PERSISTENT_PORT | 666 ISCSI_PERSISTENT_PORT |
642 ISCSI_PERSISTENT_ADDRESS | 667 ISCSI_PERSISTENT_ADDRESS |
@@ -659,6 +684,7 @@ static struct iscsi_transport iscsi_iser_transport = {
659 .destroy_conn = iscsi_iser_conn_destroy, 684 .destroy_conn = iscsi_iser_conn_destroy,
660 .set_param = iscsi_iser_set_param, 685 .set_param = iscsi_iser_set_param,
661 .get_conn_param = iscsi_conn_get_param, 686 .get_conn_param = iscsi_conn_get_param,
687 .get_ep_param = iscsi_iser_get_ep_param,
662 .get_session_param = iscsi_session_get_param, 688 .get_session_param = iscsi_session_get_param,
663 .start_conn = iscsi_iser_conn_start, 689 .start_conn = iscsi_iser_conn_start,
664 .stop_conn = iscsi_iser_conn_stop, 690 .stop_conn = iscsi_iser_conn_stop,
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index b82d28819e2a..4b0b63c290a6 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1283,24 +1283,22 @@ static int do_end_io(struct multipath *m, struct request *clone,
1283 if (!error && !clone->errors) 1283 if (!error && !clone->errors)
1284 return 0; /* I/O complete */ 1284 return 0; /* I/O complete */
1285 1285
1286 if (error == -EOPNOTSUPP) 1286 if (error == -EOPNOTSUPP || error == -EREMOTEIO)
1287 return error;
1288
1289 if (clone->cmd_flags & REQ_DISCARD)
1290 /*
1291 * Pass all discard request failures up.
1292 * FIXME: only fail_path if the discard failed due to a
1293 * transport problem. This requires precise understanding
1294 * of the underlying failure (e.g. the SCSI sense).
1295 */
1296 return error; 1287 return error;
1297 1288
1298 if (mpio->pgpath) 1289 if (mpio->pgpath)
1299 fail_path(mpio->pgpath); 1290 fail_path(mpio->pgpath);
1300 1291
1301 spin_lock_irqsave(&m->lock, flags); 1292 spin_lock_irqsave(&m->lock, flags);
1302 if (!m->nr_valid_paths && !m->queue_if_no_path && !__must_push_back(m)) 1293 if (!m->nr_valid_paths) {
1303 r = -EIO; 1294 if (!m->queue_if_no_path) {
1295 if (!__must_push_back(m))
1296 r = -EIO;
1297 } else {
1298 if (error == -EBADE)
1299 r = error;
1300 }
1301 }
1304 spin_unlock_irqrestore(&m->lock, flags); 1302 spin_unlock_irqrestore(&m->lock, flags);
1305 1303
1306 return r; 1304 return r;
diff --git a/drivers/message/fusion/lsi/mpi_cnfg.h b/drivers/message/fusion/lsi/mpi_cnfg.h
index 013c7d881948..22027e7946f7 100644
--- a/drivers/message/fusion/lsi/mpi_cnfg.h
+++ b/drivers/message/fusion/lsi/mpi_cnfg.h
@@ -2593,6 +2593,7 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_0
2593#define MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE (0x03) 2593#define MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE (0x03)
2594#define MPI_SAS_IOUNIT0_RATE_1_5 (0x08) 2594#define MPI_SAS_IOUNIT0_RATE_1_5 (0x08)
2595#define MPI_SAS_IOUNIT0_RATE_3_0 (0x09) 2595#define MPI_SAS_IOUNIT0_RATE_3_0 (0x09)
2596#define MPI_SAS_IOUNIT0_RATE_6_0 (0x0A)
2596 2597
2597/* see mpi_sas.h for values for SAS IO Unit Page 0 ControllerPhyDeviceInfo values */ 2598/* see mpi_sas.h for values for SAS IO Unit Page 0 ControllerPhyDeviceInfo values */
2598 2599
diff --git a/drivers/message/fusion/lsi/mpi_ioc.h b/drivers/message/fusion/lsi/mpi_ioc.h
index 8faa4fab7b89..fd6222882a0e 100644
--- a/drivers/message/fusion/lsi/mpi_ioc.h
+++ b/drivers/message/fusion/lsi/mpi_ioc.h
@@ -841,6 +841,7 @@ typedef struct _EVENT_DATA_SAS_PHY_LINK_STATUS
841#define MPI_EVENT_SAS_PLS_LR_RATE_SATA_OOB_COMPLETE (0x03) 841#define MPI_EVENT_SAS_PLS_LR_RATE_SATA_OOB_COMPLETE (0x03)
842#define MPI_EVENT_SAS_PLS_LR_RATE_1_5 (0x08) 842#define MPI_EVENT_SAS_PLS_LR_RATE_1_5 (0x08)
843#define MPI_EVENT_SAS_PLS_LR_RATE_3_0 (0x09) 843#define MPI_EVENT_SAS_PLS_LR_RATE_3_0 (0x09)
844#define MPI_EVENT_SAS_PLS_LR_RATE_6_0 (0x0A)
844 845
845/* SAS Discovery Event data */ 846/* SAS Discovery Event data */
846 847
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 3358c0af3466..ec8080c98081 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -7418,7 +7418,12 @@ mpt_display_event_info(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply)
7418 case MPI_EVENT_SAS_PLS_LR_RATE_3_0: 7418 case MPI_EVENT_SAS_PLS_LR_RATE_3_0:
7419 snprintf(evStr, EVENT_DESCR_STR_SZ, 7419 snprintf(evStr, EVENT_DESCR_STR_SZ,
7420 "SAS PHY Link Status: Phy=%d:" 7420 "SAS PHY Link Status: Phy=%d:"
7421 " Rate 3.0 Gpbs",PhyNumber); 7421 " Rate 3.0 Gbps", PhyNumber);
7422 break;
7423 case MPI_EVENT_SAS_PLS_LR_RATE_6_0:
7424 snprintf(evStr, EVENT_DESCR_STR_SZ,
7425 "SAS PHY Link Status: Phy=%d:"
7426 " Rate 6.0 Gbps", PhyNumber);
7422 break; 7427 break;
7423 default: 7428 default:
7424 snprintf(evStr, EVENT_DESCR_STR_SZ, 7429 snprintf(evStr, EVENT_DESCR_STR_SZ,
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index e8deb8ed0499..878bda0cce70 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -1314,8 +1314,10 @@ mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1314 else 1314 else
1315 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI; 1315 karg->adapterType = MPT_IOCTL_INTERFACE_SCSI;
1316 1316
1317 if (karg->hdr.port > 1) 1317 if (karg->hdr.port > 1) {
1318 kfree(karg);
1318 return -EINVAL; 1319 return -EINVAL;
1320 }
1319 port = karg->hdr.port; 1321 port = karg->hdr.port;
1320 1322
1321 karg->port = port; 1323 karg->port = port;
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 8aefb1829fcd..f5a14afad2cd 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -1973,7 +1973,6 @@ static struct scsi_host_template mptsas_driver_template = {
1973 .change_queue_depth = mptscsih_change_queue_depth, 1973 .change_queue_depth = mptscsih_change_queue_depth,
1974 .eh_abort_handler = mptscsih_abort, 1974 .eh_abort_handler = mptscsih_abort,
1975 .eh_device_reset_handler = mptscsih_dev_reset, 1975 .eh_device_reset_handler = mptscsih_dev_reset,
1976 .eh_bus_reset_handler = mptscsih_bus_reset,
1977 .eh_host_reset_handler = mptscsih_host_reset, 1976 .eh_host_reset_handler = mptscsih_host_reset,
1978 .bios_param = mptscsih_bios_param, 1977 .bios_param = mptscsih_bios_param,
1979 .can_queue = MPT_SAS_CAN_QUEUE, 1978 .can_queue = MPT_SAS_CAN_QUEUE,
@@ -3063,6 +3062,9 @@ static int mptsas_probe_one_phy(struct device *dev,
3063 case MPI_SAS_IOUNIT0_RATE_3_0: 3062 case MPI_SAS_IOUNIT0_RATE_3_0:
3064 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS; 3063 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
3065 break; 3064 break;
3065 case MPI_SAS_IOUNIT0_RATE_6_0:
3066 phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
3067 break;
3066 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE: 3068 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
3067 case MPI_SAS_IOUNIT0_RATE_UNKNOWN: 3069 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
3068 default: 3070 default:
@@ -3691,7 +3693,8 @@ mptsas_send_link_status_event(struct fw_event_work *fw_event)
3691 } 3693 }
3692 3694
3693 if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 || 3695 if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 ||
3694 link_rate == MPI_SAS_IOUNIT0_RATE_3_0) { 3696 link_rate == MPI_SAS_IOUNIT0_RATE_3_0 ||
3697 link_rate == MPI_SAS_IOUNIT0_RATE_6_0) {
3695 3698
3696 if (!port_info) { 3699 if (!port_info) {
3697 if (ioc->old_sas_discovery_protocal) { 3700 if (ioc->old_sas_discovery_protocal) {
diff --git a/drivers/net/bnx2x/bnx2x_main.c b/drivers/net/bnx2x/bnx2x_main.c
index 9d48659e3b28..32e64cc85d2c 100644
--- a/drivers/net/bnx2x/bnx2x_main.c
+++ b/drivers/net/bnx2x/bnx2x_main.c
@@ -145,13 +145,6 @@ static struct {
145 { "Broadcom NetXtreme II BCM57712E XGb" } 145 { "Broadcom NetXtreme II BCM57712E XGb" }
146}; 146};
147 147
148#ifndef PCI_DEVICE_ID_NX2_57712
149#define PCI_DEVICE_ID_NX2_57712 0x1662
150#endif
151#ifndef PCI_DEVICE_ID_NX2_57712E
152#define PCI_DEVICE_ID_NX2_57712E 0x1663
153#endif
154
155static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = { 148static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
156 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 }, 149 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
157 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 }, 150 { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 51c666fb67a4..645b0fcbb370 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -122,36 +122,21 @@ static int __init zfcp_module_init(void)
122{ 122{
123 int retval = -ENOMEM; 123 int retval = -ENOMEM;
124 124
125 zfcp_data.gpn_ft_cache = zfcp_cache_hw_align("zfcp_gpn", 125 zfcp_fsf_qtcb_cache = zfcp_cache_hw_align("zfcp_fsf_qtcb",
126 sizeof(struct zfcp_fc_gpn_ft_req)); 126 sizeof(struct fsf_qtcb));
127 if (!zfcp_data.gpn_ft_cache) 127 if (!zfcp_fsf_qtcb_cache)
128 goto out;
129
130 zfcp_data.qtcb_cache = zfcp_cache_hw_align("zfcp_qtcb",
131 sizeof(struct fsf_qtcb));
132 if (!zfcp_data.qtcb_cache)
133 goto out_qtcb_cache; 128 goto out_qtcb_cache;
134 129
135 zfcp_data.sr_buffer_cache = zfcp_cache_hw_align("zfcp_sr", 130 zfcp_fc_req_cache = zfcp_cache_hw_align("zfcp_fc_req",
136 sizeof(struct fsf_status_read_buffer)); 131 sizeof(struct zfcp_fc_req));
137 if (!zfcp_data.sr_buffer_cache) 132 if (!zfcp_fc_req_cache)
138 goto out_sr_cache; 133 goto out_fc_cache;
139 134
140 zfcp_data.gid_pn_cache = zfcp_cache_hw_align("zfcp_gid", 135 zfcp_scsi_transport_template =
141 sizeof(struct zfcp_fc_gid_pn));
142 if (!zfcp_data.gid_pn_cache)
143 goto out_gid_cache;
144
145 zfcp_data.adisc_cache = zfcp_cache_hw_align("zfcp_adisc",
146 sizeof(struct zfcp_fc_els_adisc));
147 if (!zfcp_data.adisc_cache)
148 goto out_adisc_cache;
149
150 zfcp_data.scsi_transport_template =
151 fc_attach_transport(&zfcp_transport_functions); 136 fc_attach_transport(&zfcp_transport_functions);
152 if (!zfcp_data.scsi_transport_template) 137 if (!zfcp_scsi_transport_template)
153 goto out_transport; 138 goto out_transport;
154 scsi_transport_reserve_device(zfcp_data.scsi_transport_template, 139 scsi_transport_reserve_device(zfcp_scsi_transport_template,
155 sizeof(struct zfcp_scsi_dev)); 140 sizeof(struct zfcp_scsi_dev));
156 141
157 142
@@ -175,18 +160,12 @@ static int __init zfcp_module_init(void)
175out_ccw_register: 160out_ccw_register:
176 misc_deregister(&zfcp_cfdc_misc); 161 misc_deregister(&zfcp_cfdc_misc);
177out_misc: 162out_misc:
178 fc_release_transport(zfcp_data.scsi_transport_template); 163 fc_release_transport(zfcp_scsi_transport_template);
179out_transport: 164out_transport:
180 kmem_cache_destroy(zfcp_data.adisc_cache); 165 kmem_cache_destroy(zfcp_fc_req_cache);
181out_adisc_cache: 166out_fc_cache:
182 kmem_cache_destroy(zfcp_data.gid_pn_cache); 167 kmem_cache_destroy(zfcp_fsf_qtcb_cache);
183out_gid_cache:
184 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
185out_sr_cache:
186 kmem_cache_destroy(zfcp_data.qtcb_cache);
187out_qtcb_cache: 168out_qtcb_cache:
188 kmem_cache_destroy(zfcp_data.gpn_ft_cache);
189out:
190 return retval; 169 return retval;
191} 170}
192 171
@@ -196,12 +175,9 @@ static void __exit zfcp_module_exit(void)
196{ 175{
197 ccw_driver_unregister(&zfcp_ccw_driver); 176 ccw_driver_unregister(&zfcp_ccw_driver);
198 misc_deregister(&zfcp_cfdc_misc); 177 misc_deregister(&zfcp_cfdc_misc);
199 fc_release_transport(zfcp_data.scsi_transport_template); 178 fc_release_transport(zfcp_scsi_transport_template);
200 kmem_cache_destroy(zfcp_data.adisc_cache); 179 kmem_cache_destroy(zfcp_fc_req_cache);
201 kmem_cache_destroy(zfcp_data.gid_pn_cache); 180 kmem_cache_destroy(zfcp_fsf_qtcb_cache);
202 kmem_cache_destroy(zfcp_data.sr_buffer_cache);
203 kmem_cache_destroy(zfcp_data.qtcb_cache);
204 kmem_cache_destroy(zfcp_data.gpn_ft_cache);
205} 181}
206 182
207module_exit(zfcp_module_exit); 183module_exit(zfcp_module_exit);
@@ -260,18 +236,18 @@ static int zfcp_allocate_low_mem_buffers(struct zfcp_adapter *adapter)
260 return -ENOMEM; 236 return -ENOMEM;
261 237
262 adapter->pool.qtcb_pool = 238 adapter->pool.qtcb_pool =
263 mempool_create_slab_pool(4, zfcp_data.qtcb_cache); 239 mempool_create_slab_pool(4, zfcp_fsf_qtcb_cache);
264 if (!adapter->pool.qtcb_pool) 240 if (!adapter->pool.qtcb_pool)
265 return -ENOMEM; 241 return -ENOMEM;
266 242
267 adapter->pool.status_read_data = 243 BUILD_BUG_ON(sizeof(struct fsf_status_read_buffer) > PAGE_SIZE);
268 mempool_create_slab_pool(FSF_STATUS_READS_RECOM, 244 adapter->pool.sr_data =
269 zfcp_data.sr_buffer_cache); 245 mempool_create_page_pool(FSF_STATUS_READS_RECOM, 0);
270 if (!adapter->pool.status_read_data) 246 if (!adapter->pool.sr_data)
271 return -ENOMEM; 247 return -ENOMEM;
272 248
273 adapter->pool.gid_pn = 249 adapter->pool.gid_pn =
274 mempool_create_slab_pool(1, zfcp_data.gid_pn_cache); 250 mempool_create_slab_pool(1, zfcp_fc_req_cache);
275 if (!adapter->pool.gid_pn) 251 if (!adapter->pool.gid_pn)
276 return -ENOMEM; 252 return -ENOMEM;
277 253
@@ -290,8 +266,8 @@ static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
290 mempool_destroy(adapter->pool.qtcb_pool); 266 mempool_destroy(adapter->pool.qtcb_pool);
291 if (adapter->pool.status_read_req) 267 if (adapter->pool.status_read_req)
292 mempool_destroy(adapter->pool.status_read_req); 268 mempool_destroy(adapter->pool.status_read_req);
293 if (adapter->pool.status_read_data) 269 if (adapter->pool.sr_data)
294 mempool_destroy(adapter->pool.status_read_data); 270 mempool_destroy(adapter->pool.sr_data);
295 if (adapter->pool.gid_pn) 271 if (adapter->pool.gid_pn)
296 mempool_destroy(adapter->pool.gid_pn); 272 mempool_destroy(adapter->pool.gid_pn);
297} 273}
@@ -386,6 +362,7 @@ struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)
386 362
387 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler); 363 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
388 INIT_WORK(&adapter->scan_work, zfcp_fc_scan_ports); 364 INIT_WORK(&adapter->scan_work, zfcp_fc_scan_ports);
365 INIT_WORK(&adapter->ns_up_work, zfcp_fc_sym_name_update);
389 366
390 if (zfcp_qdio_setup(adapter)) 367 if (zfcp_qdio_setup(adapter))
391 goto failed; 368 goto failed;
@@ -437,7 +414,7 @@ struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)
437 adapter->dma_parms.max_segment_size = ZFCP_QDIO_SBALE_LEN; 414 adapter->dma_parms.max_segment_size = ZFCP_QDIO_SBALE_LEN;
438 adapter->ccw_device->dev.dma_parms = &adapter->dma_parms; 415 adapter->ccw_device->dev.dma_parms = &adapter->dma_parms;
439 416
440 if (!zfcp_adapter_scsi_register(adapter)) 417 if (!zfcp_scsi_adapter_register(adapter))
441 return adapter; 418 return adapter;
442 419
443failed: 420failed:
@@ -451,10 +428,11 @@ void zfcp_adapter_unregister(struct zfcp_adapter *adapter)
451 428
452 cancel_work_sync(&adapter->scan_work); 429 cancel_work_sync(&adapter->scan_work);
453 cancel_work_sync(&adapter->stat_work); 430 cancel_work_sync(&adapter->stat_work);
431 cancel_work_sync(&adapter->ns_up_work);
454 zfcp_destroy_adapter_work_queue(adapter); 432 zfcp_destroy_adapter_work_queue(adapter);
455 433
456 zfcp_fc_wka_ports_force_offline(adapter->gs); 434 zfcp_fc_wka_ports_force_offline(adapter->gs);
457 zfcp_adapter_scsi_unregister(adapter); 435 zfcp_scsi_adapter_unregister(adapter);
458 sysfs_remove_group(&cdev->dev.kobj, &zfcp_sysfs_adapter_attrs); 436 sysfs_remove_group(&cdev->dev.kobj, &zfcp_sysfs_adapter_attrs);
459 437
460 zfcp_erp_thread_kill(adapter); 438 zfcp_erp_thread_kill(adapter);
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index 9ae1d0a6f627..527ba48eea57 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -89,7 +89,6 @@ struct zfcp_reqlist;
89#define ZFCP_STATUS_LUN_READONLY 0x00000008 89#define ZFCP_STATUS_LUN_READONLY 0x00000008
90 90
91/* FSF request status (this does not have a common part) */ 91/* FSF request status (this does not have a common part) */
92#define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
93#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008 92#define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
94#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010 93#define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
95#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040 94#define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
@@ -108,7 +107,7 @@ struct zfcp_adapter_mempool {
108 mempool_t *scsi_req; 107 mempool_t *scsi_req;
109 mempool_t *scsi_abort; 108 mempool_t *scsi_abort;
110 mempool_t *status_read_req; 109 mempool_t *status_read_req;
111 mempool_t *status_read_data; 110 mempool_t *sr_data;
112 mempool_t *gid_pn; 111 mempool_t *gid_pn;
113 mempool_t *qtcb_pool; 112 mempool_t *qtcb_pool;
114}; 113};
@@ -190,6 +189,7 @@ struct zfcp_adapter {
190 struct fsf_qtcb_bottom_port *stats_reset_data; 189 struct fsf_qtcb_bottom_port *stats_reset_data;
191 unsigned long stats_reset; 190 unsigned long stats_reset;
192 struct work_struct scan_work; 191 struct work_struct scan_work;
192 struct work_struct ns_up_work;
193 struct service_level service_level; 193 struct service_level service_level;
194 struct workqueue_struct *work_queue; 194 struct workqueue_struct *work_queue;
195 struct device_dma_parameters dma_parms; 195 struct device_dma_parameters dma_parms;
@@ -314,15 +314,4 @@ struct zfcp_fsf_req {
314 void (*handler)(struct zfcp_fsf_req *); 314 void (*handler)(struct zfcp_fsf_req *);
315}; 315};
316 316
317/* driver data */
318struct zfcp_data {
319 struct scsi_host_template scsi_host_template;
320 struct scsi_transport_template *scsi_transport_template;
321 struct kmem_cache *gpn_ft_cache;
322 struct kmem_cache *qtcb_cache;
323 struct kmem_cache *sr_buffer_cache;
324 struct kmem_cache *gid_pn_cache;
325 struct kmem_cache *adisc_cache;
326};
327
328#endif /* ZFCP_DEF_H */ 317#endif /* ZFCP_DEF_H */
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index e003e306f870..e1b4f800e226 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -732,7 +732,7 @@ static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
732 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED) 732 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
733 return ZFCP_ERP_FAILED; 733 return ZFCP_ERP_FAILED;
734 734
735 if (mempool_resize(act->adapter->pool.status_read_data, 735 if (mempool_resize(act->adapter->pool.sr_data,
736 act->adapter->stat_read_buf_num, GFP_KERNEL)) 736 act->adapter->stat_read_buf_num, GFP_KERNEL))
737 return ZFCP_ERP_FAILED; 737 return ZFCP_ERP_FAILED;
738 738
@@ -1231,8 +1231,10 @@ static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
1231 if (result == ZFCP_ERP_SUCCEEDED) { 1231 if (result == ZFCP_ERP_SUCCEEDED) {
1232 register_service_level(&adapter->service_level); 1232 register_service_level(&adapter->service_level);
1233 queue_work(adapter->work_queue, &adapter->scan_work); 1233 queue_work(adapter->work_queue, &adapter->scan_work);
1234 queue_work(adapter->work_queue, &adapter->ns_up_work);
1234 } else 1235 } else
1235 unregister_service_level(&adapter->service_level); 1236 unregister_service_level(&adapter->service_level);
1237
1236 kref_put(&adapter->ref, zfcp_adapter_release); 1238 kref_put(&adapter->ref, zfcp_adapter_release);
1237 break; 1239 break;
1238 } 1240 }
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index 6e325284fbe7..03627cfd81cd 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -80,6 +80,7 @@ extern void zfcp_erp_notify(struct zfcp_erp_action *, unsigned long);
80extern void zfcp_erp_timeout_handler(unsigned long); 80extern void zfcp_erp_timeout_handler(unsigned long);
81 81
82/* zfcp_fc.c */ 82/* zfcp_fc.c */
83extern struct kmem_cache *zfcp_fc_req_cache;
83extern void zfcp_fc_enqueue_event(struct zfcp_adapter *, 84extern void zfcp_fc_enqueue_event(struct zfcp_adapter *,
84 enum fc_host_event_code event_code, u32); 85 enum fc_host_event_code event_code, u32);
85extern void zfcp_fc_post_event(struct work_struct *); 86extern void zfcp_fc_post_event(struct work_struct *);
@@ -95,8 +96,10 @@ extern int zfcp_fc_gs_setup(struct zfcp_adapter *);
95extern void zfcp_fc_gs_destroy(struct zfcp_adapter *); 96extern void zfcp_fc_gs_destroy(struct zfcp_adapter *);
96extern int zfcp_fc_exec_bsg_job(struct fc_bsg_job *); 97extern int zfcp_fc_exec_bsg_job(struct fc_bsg_job *);
97extern int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *); 98extern int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *);
99extern void zfcp_fc_sym_name_update(struct work_struct *);
98 100
99/* zfcp_fsf.c */ 101/* zfcp_fsf.c */
102extern struct kmem_cache *zfcp_fsf_qtcb_cache;
100extern int zfcp_fsf_open_port(struct zfcp_erp_action *); 103extern int zfcp_fsf_open_port(struct zfcp_erp_action *);
101extern int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *); 104extern int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *);
102extern int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *); 105extern int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *);
@@ -139,9 +142,9 @@ extern struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *,
139 struct qdio_buffer *); 142 struct qdio_buffer *);
140 143
141/* zfcp_scsi.c */ 144/* zfcp_scsi.c */
142extern struct zfcp_data zfcp_data; 145extern struct scsi_transport_template *zfcp_scsi_transport_template;
143extern int zfcp_adapter_scsi_register(struct zfcp_adapter *); 146extern int zfcp_scsi_adapter_register(struct zfcp_adapter *);
144extern void zfcp_adapter_scsi_unregister(struct zfcp_adapter *); 147extern void zfcp_scsi_adapter_unregister(struct zfcp_adapter *);
145extern struct fc_function_template zfcp_transport_functions; 148extern struct fc_function_template zfcp_transport_functions;
146extern void zfcp_scsi_rport_work(struct work_struct *); 149extern void zfcp_scsi_rport_work(struct work_struct *);
147extern void zfcp_scsi_schedule_rport_register(struct zfcp_port *); 150extern void zfcp_scsi_schedule_rport_register(struct zfcp_port *);
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 30cf91a787a3..297e6b71ce9c 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -11,11 +11,14 @@
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/utsname.h>
14#include <scsi/fc/fc_els.h> 15#include <scsi/fc/fc_els.h>
15#include <scsi/libfc.h> 16#include <scsi/libfc.h>
16#include "zfcp_ext.h" 17#include "zfcp_ext.h"
17#include "zfcp_fc.h" 18#include "zfcp_fc.h"
18 19
20struct kmem_cache *zfcp_fc_req_cache;
21
19static u32 zfcp_fc_rscn_range_mask[] = { 22static u32 zfcp_fc_rscn_range_mask[] = {
20 [ELS_ADDR_FMT_PORT] = 0xFFFFFF, 23 [ELS_ADDR_FMT_PORT] = 0xFFFFFF,
21 [ELS_ADDR_FMT_AREA] = 0xFFFF00, 24 [ELS_ADDR_FMT_AREA] = 0xFFFF00,
@@ -260,24 +263,18 @@ void zfcp_fc_incoming_els(struct zfcp_fsf_req *fsf_req)
260 zfcp_fc_incoming_rscn(fsf_req); 263 zfcp_fc_incoming_rscn(fsf_req);
261} 264}
262 265
263static void zfcp_fc_ns_gid_pn_eval(void *data) 266static void zfcp_fc_ns_gid_pn_eval(struct zfcp_fc_req *fc_req)
264{ 267{
265 struct zfcp_fc_gid_pn *gid_pn = data; 268 struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els;
266 struct zfcp_fsf_ct_els *ct = &gid_pn->ct; 269 struct zfcp_fc_gid_pn_rsp *gid_pn_rsp = &fc_req->u.gid_pn.rsp;
267 struct zfcp_fc_gid_pn_req *gid_pn_req = sg_virt(ct->req);
268 struct zfcp_fc_gid_pn_resp *gid_pn_resp = sg_virt(ct->resp);
269 struct zfcp_port *port = gid_pn->port;
270 270
271 if (ct->status) 271 if (ct_els->status)
272 return; 272 return;
273 if (gid_pn_resp->ct_hdr.ct_cmd != FC_FS_ACC) 273 if (gid_pn_rsp->ct_hdr.ct_cmd != FC_FS_ACC)
274 return; 274 return;
275 275
276 /* paranoia */
277 if (gid_pn_req->gid_pn.fn_wwpn != port->wwpn)
278 return;
279 /* looks like a valid d_id */ 276 /* looks like a valid d_id */
280 port->d_id = ntoh24(gid_pn_resp->gid_pn.fp_fid); 277 ct_els->port->d_id = ntoh24(gid_pn_rsp->gid_pn.fp_fid);
281} 278}
282 279
283static void zfcp_fc_complete(void *data) 280static void zfcp_fc_complete(void *data)
@@ -285,69 +282,73 @@ static void zfcp_fc_complete(void *data)
285 complete(data); 282 complete(data);
286} 283}
287 284
285static void zfcp_fc_ct_ns_init(struct fc_ct_hdr *ct_hdr, u16 cmd, u16 mr_size)
286{
287 ct_hdr->ct_rev = FC_CT_REV;
288 ct_hdr->ct_fs_type = FC_FST_DIR;
289 ct_hdr->ct_fs_subtype = FC_NS_SUBTYPE;
290 ct_hdr->ct_cmd = cmd;
291 ct_hdr->ct_mr_size = mr_size / 4;
292}
293
288static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port, 294static int zfcp_fc_ns_gid_pn_request(struct zfcp_port *port,
289 struct zfcp_fc_gid_pn *gid_pn) 295 struct zfcp_fc_req *fc_req)
290{ 296{
291 struct zfcp_adapter *adapter = port->adapter; 297 struct zfcp_adapter *adapter = port->adapter;
292 DECLARE_COMPLETION_ONSTACK(completion); 298 DECLARE_COMPLETION_ONSTACK(completion);
299 struct zfcp_fc_gid_pn_req *gid_pn_req = &fc_req->u.gid_pn.req;
300 struct zfcp_fc_gid_pn_rsp *gid_pn_rsp = &fc_req->u.gid_pn.rsp;
293 int ret; 301 int ret;
294 302
295 /* setup parameters for send generic command */ 303 /* setup parameters for send generic command */
296 gid_pn->port = port; 304 fc_req->ct_els.port = port;
297 gid_pn->ct.handler = zfcp_fc_complete; 305 fc_req->ct_els.handler = zfcp_fc_complete;
298 gid_pn->ct.handler_data = &completion; 306 fc_req->ct_els.handler_data = &completion;
299 gid_pn->ct.req = &gid_pn->sg_req; 307 fc_req->ct_els.req = &fc_req->sg_req;
300 gid_pn->ct.resp = &gid_pn->sg_resp; 308 fc_req->ct_els.resp = &fc_req->sg_rsp;
301 sg_init_one(&gid_pn->sg_req, &gid_pn->gid_pn_req, 309 sg_init_one(&fc_req->sg_req, gid_pn_req, sizeof(*gid_pn_req));
302 sizeof(struct zfcp_fc_gid_pn_req)); 310 sg_init_one(&fc_req->sg_rsp, gid_pn_rsp, sizeof(*gid_pn_rsp));
303 sg_init_one(&gid_pn->sg_resp, &gid_pn->gid_pn_resp, 311
304 sizeof(struct zfcp_fc_gid_pn_resp)); 312 zfcp_fc_ct_ns_init(&gid_pn_req->ct_hdr,
305 313 FC_NS_GID_PN, ZFCP_FC_CT_SIZE_PAGE);
306 /* setup nameserver request */ 314 gid_pn_req->gid_pn.fn_wwpn = port->wwpn;
307 gid_pn->gid_pn_req.ct_hdr.ct_rev = FC_CT_REV; 315
308 gid_pn->gid_pn_req.ct_hdr.ct_fs_type = FC_FST_DIR; 316 ret = zfcp_fsf_send_ct(&adapter->gs->ds, &fc_req->ct_els,
309 gid_pn->gid_pn_req.ct_hdr.ct_fs_subtype = FC_NS_SUBTYPE;
310 gid_pn->gid_pn_req.ct_hdr.ct_options = 0;
311 gid_pn->gid_pn_req.ct_hdr.ct_cmd = FC_NS_GID_PN;
312 gid_pn->gid_pn_req.ct_hdr.ct_mr_size = ZFCP_FC_CT_SIZE_PAGE / 4;
313 gid_pn->gid_pn_req.gid_pn.fn_wwpn = port->wwpn;
314
315 ret = zfcp_fsf_send_ct(&adapter->gs->ds, &gid_pn->ct,
316 adapter->pool.gid_pn_req, 317 adapter->pool.gid_pn_req,
317 ZFCP_FC_CTELS_TMO); 318 ZFCP_FC_CTELS_TMO);
318 if (!ret) { 319 if (!ret) {
319 wait_for_completion(&completion); 320 wait_for_completion(&completion);
320 zfcp_fc_ns_gid_pn_eval(gid_pn); 321 zfcp_fc_ns_gid_pn_eval(fc_req);
321 } 322 }
322 return ret; 323 return ret;
323} 324}
324 325
325/** 326/**
326 * zfcp_fc_ns_gid_pn_request - initiate GID_PN nameserver request 327 * zfcp_fc_ns_gid_pn - initiate GID_PN nameserver request
327 * @port: port where GID_PN request is needed 328 * @port: port where GID_PN request is needed
328 * return: -ENOMEM on error, 0 otherwise 329 * return: -ENOMEM on error, 0 otherwise
329 */ 330 */
330static int zfcp_fc_ns_gid_pn(struct zfcp_port *port) 331static int zfcp_fc_ns_gid_pn(struct zfcp_port *port)
331{ 332{
332 int ret; 333 int ret;
333 struct zfcp_fc_gid_pn *gid_pn; 334 struct zfcp_fc_req *fc_req;
334 struct zfcp_adapter *adapter = port->adapter; 335 struct zfcp_adapter *adapter = port->adapter;
335 336
336 gid_pn = mempool_alloc(adapter->pool.gid_pn, GFP_ATOMIC); 337 fc_req = mempool_alloc(adapter->pool.gid_pn, GFP_ATOMIC);
337 if (!gid_pn) 338 if (!fc_req)
338 return -ENOMEM; 339 return -ENOMEM;
339 340
340 memset(gid_pn, 0, sizeof(*gid_pn)); 341 memset(fc_req, 0, sizeof(*fc_req));
341 342
342 ret = zfcp_fc_wka_port_get(&adapter->gs->ds); 343 ret = zfcp_fc_wka_port_get(&adapter->gs->ds);
343 if (ret) 344 if (ret)
344 goto out; 345 goto out;
345 346
346 ret = zfcp_fc_ns_gid_pn_request(port, gid_pn); 347 ret = zfcp_fc_ns_gid_pn_request(port, fc_req);
347 348
348 zfcp_fc_wka_port_put(&adapter->gs->ds); 349 zfcp_fc_wka_port_put(&adapter->gs->ds);
349out: 350out:
350 mempool_free(gid_pn, adapter->pool.gid_pn); 351 mempool_free(fc_req, adapter->pool.gid_pn);
351 return ret; 352 return ret;
352} 353}
353 354
@@ -419,11 +420,11 @@ void zfcp_fc_plogi_evaluate(struct zfcp_port *port, struct fc_els_flogi *plogi)
419 420
420static void zfcp_fc_adisc_handler(void *data) 421static void zfcp_fc_adisc_handler(void *data)
421{ 422{
422 struct zfcp_fc_els_adisc *adisc = data; 423 struct zfcp_fc_req *fc_req = data;
423 struct zfcp_port *port = adisc->els.port; 424 struct zfcp_port *port = fc_req->ct_els.port;
424 struct fc_els_adisc *adisc_resp = &adisc->adisc_resp; 425 struct fc_els_adisc *adisc_resp = &fc_req->u.adisc.rsp;
425 426
426 if (adisc->els.status) { 427 if (fc_req->ct_els.status) {
427 /* request rejected or timed out */ 428 /* request rejected or timed out */
428 zfcp_erp_port_forced_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, 429 zfcp_erp_port_forced_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
429 "fcadh_1"); 430 "fcadh_1");
@@ -445,42 +446,42 @@ static void zfcp_fc_adisc_handler(void *data)
445 out: 446 out:
446 atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); 447 atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status);
447 put_device(&port->dev); 448 put_device(&port->dev);
448 kmem_cache_free(zfcp_data.adisc_cache, adisc); 449 kmem_cache_free(zfcp_fc_req_cache, fc_req);
449} 450}
450 451
451static int zfcp_fc_adisc(struct zfcp_port *port) 452static int zfcp_fc_adisc(struct zfcp_port *port)
452{ 453{
453 struct zfcp_fc_els_adisc *adisc; 454 struct zfcp_fc_req *fc_req;
454 struct zfcp_adapter *adapter = port->adapter; 455 struct zfcp_adapter *adapter = port->adapter;
456 struct Scsi_Host *shost = adapter->scsi_host;
455 int ret; 457 int ret;
456 458
457 adisc = kmem_cache_zalloc(zfcp_data.adisc_cache, GFP_ATOMIC); 459 fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_ATOMIC);
458 if (!adisc) 460 if (!fc_req)
459 return -ENOMEM; 461 return -ENOMEM;
460 462
461 adisc->els.port = port; 463 fc_req->ct_els.port = port;
462 adisc->els.req = &adisc->req; 464 fc_req->ct_els.req = &fc_req->sg_req;
463 adisc->els.resp = &adisc->resp; 465 fc_req->ct_els.resp = &fc_req->sg_rsp;
464 sg_init_one(adisc->els.req, &adisc->adisc_req, 466 sg_init_one(&fc_req->sg_req, &fc_req->u.adisc.req,
465 sizeof(struct fc_els_adisc)); 467 sizeof(struct fc_els_adisc));
466 sg_init_one(adisc->els.resp, &adisc->adisc_resp, 468 sg_init_one(&fc_req->sg_rsp, &fc_req->u.adisc.rsp,
467 sizeof(struct fc_els_adisc)); 469 sizeof(struct fc_els_adisc));
468 470
469 adisc->els.handler = zfcp_fc_adisc_handler; 471 fc_req->ct_els.handler = zfcp_fc_adisc_handler;
470 adisc->els.handler_data = adisc; 472 fc_req->ct_els.handler_data = fc_req;
471 473
472 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports 474 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
473 without FC-AL-2 capability, so we don't set it */ 475 without FC-AL-2 capability, so we don't set it */
474 adisc->adisc_req.adisc_wwpn = fc_host_port_name(adapter->scsi_host); 476 fc_req->u.adisc.req.adisc_wwpn = fc_host_port_name(shost);
475 adisc->adisc_req.adisc_wwnn = fc_host_node_name(adapter->scsi_host); 477 fc_req->u.adisc.req.adisc_wwnn = fc_host_node_name(shost);
476 adisc->adisc_req.adisc_cmd = ELS_ADISC; 478 fc_req->u.adisc.req.adisc_cmd = ELS_ADISC;
477 hton24(adisc->adisc_req.adisc_port_id, 479 hton24(fc_req->u.adisc.req.adisc_port_id, fc_host_port_id(shost));
478 fc_host_port_id(adapter->scsi_host));
479 480
480 ret = zfcp_fsf_send_els(adapter, port->d_id, &adisc->els, 481 ret = zfcp_fsf_send_els(adapter, port->d_id, &fc_req->ct_els,
481 ZFCP_FC_CTELS_TMO); 482 ZFCP_FC_CTELS_TMO);
482 if (ret) 483 if (ret)
483 kmem_cache_free(zfcp_data.adisc_cache, adisc); 484 kmem_cache_free(zfcp_fc_req_cache, fc_req);
484 485
485 return ret; 486 return ret;
486} 487}
@@ -528,68 +529,42 @@ void zfcp_fc_test_link(struct zfcp_port *port)
528 put_device(&port->dev); 529 put_device(&port->dev);
529} 530}
530 531
531static void zfcp_free_sg_env(struct zfcp_fc_gpn_ft *gpn_ft, int buf_num) 532static struct zfcp_fc_req *zfcp_alloc_sg_env(int buf_num)
532{ 533{
533 struct scatterlist *sg = &gpn_ft->sg_req; 534 struct zfcp_fc_req *fc_req;
534
535 kmem_cache_free(zfcp_data.gpn_ft_cache, sg_virt(sg));
536 zfcp_sg_free_table(gpn_ft->sg_resp, buf_num);
537
538 kfree(gpn_ft);
539}
540 535
541static struct zfcp_fc_gpn_ft *zfcp_alloc_sg_env(int buf_num) 536 fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_KERNEL);
542{ 537 if (!fc_req)
543 struct zfcp_fc_gpn_ft *gpn_ft;
544 struct zfcp_fc_gpn_ft_req *req;
545
546 gpn_ft = kzalloc(sizeof(*gpn_ft), GFP_KERNEL);
547 if (!gpn_ft)
548 return NULL; 538 return NULL;
549 539
550 req = kmem_cache_zalloc(zfcp_data.gpn_ft_cache, GFP_KERNEL); 540 if (zfcp_sg_setup_table(&fc_req->sg_rsp, buf_num)) {
551 if (!req) { 541 kmem_cache_free(zfcp_fc_req_cache, fc_req);
552 kfree(gpn_ft); 542 return NULL;
553 gpn_ft = NULL;
554 goto out;
555 } 543 }
556 sg_init_one(&gpn_ft->sg_req, req, sizeof(*req));
557 544
558 if (zfcp_sg_setup_table(gpn_ft->sg_resp, buf_num)) { 545 sg_init_one(&fc_req->sg_req, &fc_req->u.gpn_ft.req,
559 zfcp_free_sg_env(gpn_ft, buf_num); 546 sizeof(struct zfcp_fc_gpn_ft_req));
560 gpn_ft = NULL;
561 }
562out:
563 return gpn_ft;
564}
565 547
548 return fc_req;
549}
566 550
567static int zfcp_fc_send_gpn_ft(struct zfcp_fc_gpn_ft *gpn_ft, 551static int zfcp_fc_send_gpn_ft(struct zfcp_fc_req *fc_req,
568 struct zfcp_adapter *adapter, int max_bytes) 552 struct zfcp_adapter *adapter, int max_bytes)
569{ 553{
570 struct zfcp_fsf_ct_els *ct = &gpn_ft->ct; 554 struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els;
571 struct zfcp_fc_gpn_ft_req *req = sg_virt(&gpn_ft->sg_req); 555 struct zfcp_fc_gpn_ft_req *req = &fc_req->u.gpn_ft.req;
572 DECLARE_COMPLETION_ONSTACK(completion); 556 DECLARE_COMPLETION_ONSTACK(completion);
573 int ret; 557 int ret;
574 558
575 /* prepare CT IU for GPN_FT */ 559 zfcp_fc_ct_ns_init(&req->ct_hdr, FC_NS_GPN_FT, max_bytes);
576 req->ct_hdr.ct_rev = FC_CT_REV;
577 req->ct_hdr.ct_fs_type = FC_FST_DIR;
578 req->ct_hdr.ct_fs_subtype = FC_NS_SUBTYPE;
579 req->ct_hdr.ct_options = 0;
580 req->ct_hdr.ct_cmd = FC_NS_GPN_FT;
581 req->ct_hdr.ct_mr_size = max_bytes / 4;
582 req->gpn_ft.fn_domain_id_scope = 0;
583 req->gpn_ft.fn_area_id_scope = 0;
584 req->gpn_ft.fn_fc4_type = FC_TYPE_FCP; 560 req->gpn_ft.fn_fc4_type = FC_TYPE_FCP;
585 561
586 /* prepare zfcp_send_ct */ 562 ct_els->handler = zfcp_fc_complete;
587 ct->handler = zfcp_fc_complete; 563 ct_els->handler_data = &completion;
588 ct->handler_data = &completion; 564 ct_els->req = &fc_req->sg_req;
589 ct->req = &gpn_ft->sg_req; 565 ct_els->resp = &fc_req->sg_rsp;
590 ct->resp = gpn_ft->sg_resp;
591 566
592 ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct, NULL, 567 ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL,
593 ZFCP_FC_CTELS_TMO); 568 ZFCP_FC_CTELS_TMO);
594 if (!ret) 569 if (!ret)
595 wait_for_completion(&completion); 570 wait_for_completion(&completion);
@@ -610,11 +585,11 @@ static void zfcp_fc_validate_port(struct zfcp_port *port, struct list_head *lh)
610 list_move_tail(&port->list, lh); 585 list_move_tail(&port->list, lh);
611} 586}
612 587
613static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_gpn_ft *gpn_ft, 588static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_req *fc_req,
614 struct zfcp_adapter *adapter, int max_entries) 589 struct zfcp_adapter *adapter, int max_entries)
615{ 590{
616 struct zfcp_fsf_ct_els *ct = &gpn_ft->ct; 591 struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els;
617 struct scatterlist *sg = gpn_ft->sg_resp; 592 struct scatterlist *sg = &fc_req->sg_rsp;
618 struct fc_ct_hdr *hdr = sg_virt(sg); 593 struct fc_ct_hdr *hdr = sg_virt(sg);
619 struct fc_gpn_ft_resp *acc = sg_virt(sg); 594 struct fc_gpn_ft_resp *acc = sg_virt(sg);
620 struct zfcp_port *port, *tmp; 595 struct zfcp_port *port, *tmp;
@@ -623,7 +598,7 @@ static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_gpn_ft *gpn_ft,
623 u32 d_id; 598 u32 d_id;
624 int ret = 0, x, last = 0; 599 int ret = 0, x, last = 0;
625 600
626 if (ct->status) 601 if (ct_els->status)
627 return -EIO; 602 return -EIO;
628 603
629 if (hdr->ct_cmd != FC_FS_ACC) { 604 if (hdr->ct_cmd != FC_FS_ACC) {
@@ -687,7 +662,7 @@ void zfcp_fc_scan_ports(struct work_struct *work)
687 struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter, 662 struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter,
688 scan_work); 663 scan_work);
689 int ret, i; 664 int ret, i;
690 struct zfcp_fc_gpn_ft *gpn_ft; 665 struct zfcp_fc_req *fc_req;
691 int chain, max_entries, buf_num, max_bytes; 666 int chain, max_entries, buf_num, max_bytes;
692 667
693 chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS; 668 chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS;
@@ -702,25 +677,145 @@ void zfcp_fc_scan_ports(struct work_struct *work)
702 if (zfcp_fc_wka_port_get(&adapter->gs->ds)) 677 if (zfcp_fc_wka_port_get(&adapter->gs->ds))
703 return; 678 return;
704 679
705 gpn_ft = zfcp_alloc_sg_env(buf_num); 680 fc_req = zfcp_alloc_sg_env(buf_num);
706 if (!gpn_ft) 681 if (!fc_req)
707 goto out; 682 goto out;
708 683
709 for (i = 0; i < 3; i++) { 684 for (i = 0; i < 3; i++) {
710 ret = zfcp_fc_send_gpn_ft(gpn_ft, adapter, max_bytes); 685 ret = zfcp_fc_send_gpn_ft(fc_req, adapter, max_bytes);
711 if (!ret) { 686 if (!ret) {
712 ret = zfcp_fc_eval_gpn_ft(gpn_ft, adapter, max_entries); 687 ret = zfcp_fc_eval_gpn_ft(fc_req, adapter, max_entries);
713 if (ret == -EAGAIN) 688 if (ret == -EAGAIN)
714 ssleep(1); 689 ssleep(1);
715 else 690 else
716 break; 691 break;
717 } 692 }
718 } 693 }
719 zfcp_free_sg_env(gpn_ft, buf_num); 694 zfcp_sg_free_table(&fc_req->sg_rsp, buf_num);
695 kmem_cache_free(zfcp_fc_req_cache, fc_req);
720out: 696out:
721 zfcp_fc_wka_port_put(&adapter->gs->ds); 697 zfcp_fc_wka_port_put(&adapter->gs->ds);
722} 698}
723 699
700static int zfcp_fc_gspn(struct zfcp_adapter *adapter,
701 struct zfcp_fc_req *fc_req)
702{
703 DECLARE_COMPLETION_ONSTACK(completion);
704 char devno[] = "DEVNO:";
705 struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els;
706 struct zfcp_fc_gspn_req *gspn_req = &fc_req->u.gspn.req;
707 struct zfcp_fc_gspn_rsp *gspn_rsp = &fc_req->u.gspn.rsp;
708 int ret;
709
710 zfcp_fc_ct_ns_init(&gspn_req->ct_hdr, FC_NS_GSPN_ID,
711 FC_SYMBOLIC_NAME_SIZE);
712 hton24(gspn_req->gspn.fp_fid, fc_host_port_id(adapter->scsi_host));
713
714 sg_init_one(&fc_req->sg_req, gspn_req, sizeof(*gspn_req));
715 sg_init_one(&fc_req->sg_rsp, gspn_rsp, sizeof(*gspn_rsp));
716
717 ct_els->handler = zfcp_fc_complete;
718 ct_els->handler_data = &completion;
719 ct_els->req = &fc_req->sg_req;
720 ct_els->resp = &fc_req->sg_rsp;
721
722 ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL,
723 ZFCP_FC_CTELS_TMO);
724 if (ret)
725 return ret;
726
727 wait_for_completion(&completion);
728 if (ct_els->status)
729 return ct_els->status;
730
731 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_NPIV &&
732 !(strstr(gspn_rsp->gspn.fp_name, devno)))
733 snprintf(fc_host_symbolic_name(adapter->scsi_host),
734 FC_SYMBOLIC_NAME_SIZE, "%s%s %s NAME: %s",
735 gspn_rsp->gspn.fp_name, devno,
736 dev_name(&adapter->ccw_device->dev),
737 init_utsname()->nodename);
738 else
739 strlcpy(fc_host_symbolic_name(adapter->scsi_host),
740 gspn_rsp->gspn.fp_name, FC_SYMBOLIC_NAME_SIZE);
741
742 return 0;
743}
744
745static void zfcp_fc_rspn(struct zfcp_adapter *adapter,
746 struct zfcp_fc_req *fc_req)
747{
748 DECLARE_COMPLETION_ONSTACK(completion);
749 struct Scsi_Host *shost = adapter->scsi_host;
750 struct zfcp_fsf_ct_els *ct_els = &fc_req->ct_els;
751 struct zfcp_fc_rspn_req *rspn_req = &fc_req->u.rspn.req;
752 struct fc_ct_hdr *rspn_rsp = &fc_req->u.rspn.rsp;
753 int ret, len;
754
755 zfcp_fc_ct_ns_init(&rspn_req->ct_hdr, FC_NS_RSPN_ID,
756 FC_SYMBOLIC_NAME_SIZE);
757 hton24(rspn_req->rspn.fr_fid.fp_fid, fc_host_port_id(shost));
758 len = strlcpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost),
759 FC_SYMBOLIC_NAME_SIZE);
760 rspn_req->rspn.fr_name_len = len;
761
762 sg_init_one(&fc_req->sg_req, rspn_req, sizeof(*rspn_req));
763 sg_init_one(&fc_req->sg_rsp, rspn_rsp, sizeof(*rspn_rsp));
764
765 ct_els->handler = zfcp_fc_complete;
766 ct_els->handler_data = &completion;
767 ct_els->req = &fc_req->sg_req;
768 ct_els->resp = &fc_req->sg_rsp;
769
770 ret = zfcp_fsf_send_ct(&adapter->gs->ds, ct_els, NULL,
771 ZFCP_FC_CTELS_TMO);
772 if (!ret)
773 wait_for_completion(&completion);
774}
775
776/**
777 * zfcp_fc_sym_name_update - Retrieve and update the symbolic port name
778 * @work: ns_up_work of the adapter where to update the symbolic port name
779 *
780 * Retrieve the current symbolic port name that may have been set by
781 * the hardware using the GSPN request and update the fc_host
782 * symbolic_name sysfs attribute. When running in NPIV mode (and hence
783 * the port name is unique for this system), update the symbolic port
784 * name to add Linux specific information and update the FC nameserver
785 * using the RSPN request.
786 */
787void zfcp_fc_sym_name_update(struct work_struct *work)
788{
789 struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter,
790 ns_up_work);
791 int ret;
792 struct zfcp_fc_req *fc_req;
793
794 if (fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPORT &&
795 fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV)
796 return;
797
798 fc_req = kmem_cache_zalloc(zfcp_fc_req_cache, GFP_KERNEL);
799 if (!fc_req)
800 return;
801
802 ret = zfcp_fc_wka_port_get(&adapter->gs->ds);
803 if (ret)
804 goto out_free;
805
806 ret = zfcp_fc_gspn(adapter, fc_req);
807 if (ret || fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV)
808 goto out_ds_put;
809
810 memset(fc_req, 0, sizeof(*fc_req));
811 zfcp_fc_rspn(adapter, fc_req);
812
813out_ds_put:
814 zfcp_fc_wka_port_put(&adapter->gs->ds);
815out_free:
816 kmem_cache_free(zfcp_fc_req_cache, fc_req);
817}
818
724static void zfcp_fc_ct_els_job_handler(void *data) 819static void zfcp_fc_ct_els_job_handler(void *data)
725{ 820{
726 struct fc_bsg_job *job = data; 821 struct fc_bsg_job *job = data;
diff --git a/drivers/s390/scsi/zfcp_fc.h b/drivers/s390/scsi/zfcp_fc.h
index b464ae01086c..4561f3bf7300 100644
--- a/drivers/s390/scsi/zfcp_fc.h
+++ b/drivers/s390/scsi/zfcp_fc.h
@@ -64,33 +64,16 @@ struct zfcp_fc_gid_pn_req {
64} __packed; 64} __packed;
65 65
66/** 66/**
67 * struct zfcp_fc_gid_pn_resp - container for ct header plus gid_pn response 67 * struct zfcp_fc_gid_pn_rsp - container for ct header plus gid_pn response
68 * @ct_hdr: FC GS common transport header 68 * @ct_hdr: FC GS common transport header
69 * @gid_pn: GID_PN response 69 * @gid_pn: GID_PN response
70 */ 70 */
71struct zfcp_fc_gid_pn_resp { 71struct zfcp_fc_gid_pn_rsp {
72 struct fc_ct_hdr ct_hdr; 72 struct fc_ct_hdr ct_hdr;
73 struct fc_gid_pn_resp gid_pn; 73 struct fc_gid_pn_resp gid_pn;
74} __packed; 74} __packed;
75 75
76/** 76/**
77 * struct zfcp_fc_gid_pn - everything required in zfcp for gid_pn request
78 * @ct: data passed to zfcp_fsf for issuing fsf request
79 * @sg_req: scatterlist entry for request data
80 * @sg_resp: scatterlist entry for response data
81 * @gid_pn_req: GID_PN request data
82 * @gid_pn_resp: GID_PN response data
83 */
84struct zfcp_fc_gid_pn {
85 struct zfcp_fsf_ct_els ct;
86 struct scatterlist sg_req;
87 struct scatterlist sg_resp;
88 struct zfcp_fc_gid_pn_req gid_pn_req;
89 struct zfcp_fc_gid_pn_resp gid_pn_resp;
90 struct zfcp_port *port;
91};
92
93/**
94 * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request 77 * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request
95 * @ct_hdr: FC GS common transport header 78 * @ct_hdr: FC GS common transport header
96 * @gpn_ft: GPN_FT request 79 * @gpn_ft: GPN_FT request
@@ -101,41 +84,72 @@ struct zfcp_fc_gpn_ft_req {
101} __packed; 84} __packed;
102 85
103/** 86/**
104 * struct zfcp_fc_gpn_ft_resp - container for ct header plus gpn_ft response 87 * struct zfcp_fc_gspn_req - container for ct header plus GSPN_ID request
105 * @ct_hdr: FC GS common transport header 88 * @ct_hdr: FC GS common transport header
106 * @gpn_ft: Array of gpn_ft response data to fill one memory page 89 * @gspn: GSPN_ID request
107 */ 90 */
108struct zfcp_fc_gpn_ft_resp { 91struct zfcp_fc_gspn_req {
109 struct fc_ct_hdr ct_hdr; 92 struct fc_ct_hdr ct_hdr;
110 struct fc_gpn_ft_resp gpn_ft[ZFCP_FC_GPN_FT_ENT_PAGE]; 93 struct fc_gid_pn_resp gspn;
111} __packed; 94} __packed;
112 95
113/** 96/**
114 * struct zfcp_fc_gpn_ft - zfcp data for gpn_ft request 97 * struct zfcp_fc_gspn_rsp - container for ct header plus GSPN_ID response
115 * @ct: data passed to zfcp_fsf for issuing fsf request 98 * @ct_hdr: FC GS common transport header
116 * @sg_req: scatter list entry for gpn_ft request 99 * @gspn: GSPN_ID response
117 * @sg_resp: scatter list entries for gpn_ft responses (per memory page) 100 * @name: The name string of the GSPN_ID response
118 */ 101 */
119struct zfcp_fc_gpn_ft { 102struct zfcp_fc_gspn_rsp {
120 struct zfcp_fsf_ct_els ct; 103 struct fc_ct_hdr ct_hdr;
121 struct scatterlist sg_req; 104 struct fc_gspn_resp gspn;
122 struct scatterlist sg_resp[ZFCP_FC_GPN_FT_NUM_BUFS]; 105 char name[FC_SYMBOLIC_NAME_SIZE];
123}; 106} __packed;
124 107
125/** 108/**
126 * struct zfcp_fc_els_adisc - everything required in zfcp for issuing ELS ADISC 109 * struct zfcp_fc_rspn_req - container for ct header plus RSPN_ID request
127 * @els: data required for issuing els fsf command 110 * @ct_hdr: FC GS common transport header
128 * @req: scatterlist entry for ELS ADISC request 111 * @rspn: RSPN_ID request
129 * @resp: scatterlist entry for ELS ADISC response 112 * @name: The name string of the RSPN_ID request
130 * @adisc_req: ELS ADISC request data
131 * @adisc_resp: ELS ADISC response data
132 */ 113 */
133struct zfcp_fc_els_adisc { 114struct zfcp_fc_rspn_req {
134 struct zfcp_fsf_ct_els els; 115 struct fc_ct_hdr ct_hdr;
135 struct scatterlist req; 116 struct fc_ns_rspn rspn;
136 struct scatterlist resp; 117 char name[FC_SYMBOLIC_NAME_SIZE];
137 struct fc_els_adisc adisc_req; 118} __packed;
138 struct fc_els_adisc adisc_resp; 119
120/**
121 * struct zfcp_fc_req - Container for FC ELS and CT requests sent from zfcp
122 * @ct_els: data required for issuing fsf command
123 * @sg_req: scatterlist entry for request data
124 * @sg_rsp: scatterlist entry for response data
125 * @u: request specific data
126 */
127struct zfcp_fc_req {
128 struct zfcp_fsf_ct_els ct_els;
129 struct scatterlist sg_req;
130 struct scatterlist sg_rsp;
131 union {
132 struct {
133 struct fc_els_adisc req;
134 struct fc_els_adisc rsp;
135 } adisc;
136 struct {
137 struct zfcp_fc_gid_pn_req req;
138 struct zfcp_fc_gid_pn_rsp rsp;
139 } gid_pn;
140 struct {
141 struct scatterlist sg_rsp2[ZFCP_FC_GPN_FT_NUM_BUFS - 1];
142 struct zfcp_fc_gpn_ft_req req;
143 } gpn_ft;
144 struct {
145 struct zfcp_fc_gspn_req req;
146 struct zfcp_fc_gspn_rsp rsp;
147 } gspn;
148 struct {
149 struct zfcp_fc_rspn_req req;
150 struct fc_ct_hdr rsp;
151 } rspn;
152 } u;
139}; 153};
140 154
141/** 155/**
@@ -192,14 +206,21 @@ struct zfcp_fc_wka_ports {
192 * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd 206 * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
193 * @fcp: fcp_cmnd to setup 207 * @fcp: fcp_cmnd to setup
194 * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB 208 * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
209 * @tm: task management flags to setup task management command
195 */ 210 */
196static inline 211static inline
197void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi) 212void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi,
213 u8 tm_flags)
198{ 214{
199 char tag[2]; 215 char tag[2];
200 216
201 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun); 217 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
202 218
219 if (unlikely(tm_flags)) {
220 fcp->fc_tm_flags = tm_flags;
221 return;
222 }
223
203 if (scsi_populate_tag_msg(scsi, tag)) { 224 if (scsi_populate_tag_msg(scsi, tag)) {
204 switch (tag[0]) { 225 switch (tag[0]) {
205 case MSG_ORDERED_TAG: 226 case MSG_ORDERED_TAG:
@@ -226,19 +247,6 @@ void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
226} 247}
227 248
228/** 249/**
229 * zfcp_fc_fcp_tm - setup FCP command as task management command
230 * @fcp: fcp_cmnd to setup
231 * @dev: scsi_device where to send the task management command
232 * @tm: task management flags to setup tm command
233 */
234static inline
235void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
236{
237 int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
238 fcp->fc_tm_flags |= tm_flags;
239}
240
241/**
242 * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly 250 * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
243 * @fcp_rsp: FCP RSP IU to evaluate 251 * @fcp_rsp: FCP RSP IU to evaluate
244 * @scsi: SCSI command where to update status and sense buffer 252 * @scsi: SCSI command where to update status and sense buffer
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 60ff9d172c79..a0e05ef65924 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -18,6 +18,8 @@
18#include "zfcp_qdio.h" 18#include "zfcp_qdio.h"
19#include "zfcp_reqlist.h" 19#include "zfcp_reqlist.h"
20 20
21struct kmem_cache *zfcp_fsf_qtcb_cache;
22
21static void zfcp_fsf_request_timeout_handler(unsigned long data) 23static void zfcp_fsf_request_timeout_handler(unsigned long data)
22{ 24{
23 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data; 25 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
@@ -83,7 +85,7 @@ void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
83 } 85 }
84 86
85 if (likely(req->qtcb)) 87 if (likely(req->qtcb))
86 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb); 88 kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
87 kfree(req); 89 kfree(req);
88} 90}
89 91
@@ -212,7 +214,7 @@ static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
212 214
213 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { 215 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
214 zfcp_dbf_hba_fsf_uss("fssrh_1", req); 216 zfcp_dbf_hba_fsf_uss("fssrh_1", req);
215 mempool_free(sr_buf, adapter->pool.status_read_data); 217 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
216 zfcp_fsf_req_free(req); 218 zfcp_fsf_req_free(req);
217 return; 219 return;
218 } 220 }
@@ -265,7 +267,7 @@ static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
265 break; 267 break;
266 } 268 }
267 269
268 mempool_free(sr_buf, adapter->pool.status_read_data); 270 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
269 zfcp_fsf_req_free(req); 271 zfcp_fsf_req_free(req);
270 272
271 atomic_inc(&adapter->stat_miss); 273 atomic_inc(&adapter->stat_miss);
@@ -628,7 +630,7 @@ static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
628 if (likely(pool)) 630 if (likely(pool))
629 qtcb = mempool_alloc(pool, GFP_ATOMIC); 631 qtcb = mempool_alloc(pool, GFP_ATOMIC);
630 else 632 else
631 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC); 633 qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
632 634
633 if (unlikely(!qtcb)) 635 if (unlikely(!qtcb))
634 return NULL; 636 return NULL;
@@ -723,6 +725,7 @@ int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
723 struct zfcp_adapter *adapter = qdio->adapter; 725 struct zfcp_adapter *adapter = qdio->adapter;
724 struct zfcp_fsf_req *req; 726 struct zfcp_fsf_req *req;
725 struct fsf_status_read_buffer *sr_buf; 727 struct fsf_status_read_buffer *sr_buf;
728 struct page *page;
726 int retval = -EIO; 729 int retval = -EIO;
727 730
728 spin_lock_irq(&qdio->req_q_lock); 731 spin_lock_irq(&qdio->req_q_lock);
@@ -736,11 +739,12 @@ int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
736 goto out; 739 goto out;
737 } 740 }
738 741
739 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC); 742 page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
740 if (!sr_buf) { 743 if (!page) {
741 retval = -ENOMEM; 744 retval = -ENOMEM;
742 goto failed_buf; 745 goto failed_buf;
743 } 746 }
747 sr_buf = page_address(page);
744 memset(sr_buf, 0, sizeof(*sr_buf)); 748 memset(sr_buf, 0, sizeof(*sr_buf));
745 req->data = sr_buf; 749 req->data = sr_buf;
746 750
@@ -755,7 +759,7 @@ int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
755 759
756failed_req_send: 760failed_req_send:
757 req->data = NULL; 761 req->data = NULL;
758 mempool_free(sr_buf, adapter->pool.status_read_data); 762 mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
759failed_buf: 763failed_buf:
760 zfcp_dbf_hba_fsf_uss("fssr__1", req); 764 zfcp_dbf_hba_fsf_uss("fssr__1", req);
761 zfcp_fsf_req_free(req); 765 zfcp_fsf_req_free(req);
@@ -1552,7 +1556,7 @@ int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1552 SBAL_FLAGS0_TYPE_READ, 1556 SBAL_FLAGS0_TYPE_READ,
1553 qdio->adapter->pool.erp_req); 1557 qdio->adapter->pool.erp_req);
1554 1558
1555 if (unlikely(IS_ERR(req))) { 1559 if (IS_ERR(req)) {
1556 retval = PTR_ERR(req); 1560 retval = PTR_ERR(req);
1557 goto out; 1561 goto out;
1558 } 1562 }
@@ -1605,7 +1609,7 @@ int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1605 SBAL_FLAGS0_TYPE_READ, 1609 SBAL_FLAGS0_TYPE_READ,
1606 qdio->adapter->pool.erp_req); 1610 qdio->adapter->pool.erp_req);
1607 1611
1608 if (unlikely(IS_ERR(req))) { 1612 if (IS_ERR(req)) {
1609 retval = PTR_ERR(req); 1613 retval = PTR_ERR(req);
1610 goto out; 1614 goto out;
1611 } 1615 }
@@ -2206,7 +2210,7 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
2206 zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction); 2210 zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
2207 2211
2208 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd; 2212 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2209 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd); 2213 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
2210 2214
2211 if (scsi_prot_sg_count(scsi_cmnd)) { 2215 if (scsi_prot_sg_count(scsi_cmnd)) {
2212 zfcp_qdio_set_data_div(qdio, &req->qdio_req, 2216 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
@@ -2284,7 +2288,6 @@ struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2284 goto out; 2288 goto out;
2285 } 2289 }
2286 2290
2287 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2288 req->data = scmnd; 2291 req->data = scmnd;
2289 req->handler = zfcp_fsf_fcp_task_mgmt_handler; 2292 req->handler = zfcp_fsf_fcp_task_mgmt_handler;
2290 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle; 2293 req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
@@ -2296,7 +2299,7 @@ struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
2296 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req); 2299 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2297 2300
2298 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd; 2301 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2299 zfcp_fc_fcp_tm(fcp_cmnd, scmnd->device, tm_flags); 2302 zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
2300 2303
2301 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); 2304 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2302 if (!zfcp_fsf_req_send(req)) 2305 if (!zfcp_fsf_req_send(req))
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index ddb5800823a9..2a4991d6d4d5 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -292,7 +292,37 @@ static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
292 return SUCCESS; 292 return SUCCESS;
293} 293}
294 294
295int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter) 295struct scsi_transport_template *zfcp_scsi_transport_template;
296
297static struct scsi_host_template zfcp_scsi_host_template = {
298 .module = THIS_MODULE,
299 .name = "zfcp",
300 .queuecommand = zfcp_scsi_queuecommand,
301 .eh_abort_handler = zfcp_scsi_eh_abort_handler,
302 .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
303 .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
304 .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
305 .slave_alloc = zfcp_scsi_slave_alloc,
306 .slave_configure = zfcp_scsi_slave_configure,
307 .slave_destroy = zfcp_scsi_slave_destroy,
308 .change_queue_depth = zfcp_scsi_change_queue_depth,
309 .proc_name = "zfcp",
310 .can_queue = 4096,
311 .this_id = -1,
312 .sg_tablesize = ZFCP_QDIO_MAX_SBALES_PER_REQ,
313 .max_sectors = (ZFCP_QDIO_MAX_SBALES_PER_REQ * 8),
314 .dma_boundary = ZFCP_QDIO_SBALE_LEN - 1,
315 .cmd_per_lun = 1,
316 .use_clustering = 1,
317 .shost_attrs = zfcp_sysfs_shost_attrs,
318 .sdev_attrs = zfcp_sysfs_sdev_attrs,
319};
320
321/**
322 * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
323 * @adapter: The zfcp adapter to register with the SCSI midlayer
324 */
325int zfcp_scsi_adapter_register(struct zfcp_adapter *adapter)
296{ 326{
297 struct ccw_dev_id dev_id; 327 struct ccw_dev_id dev_id;
298 328
@@ -301,7 +331,7 @@ int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
301 331
302 ccw_device_get_id(adapter->ccw_device, &dev_id); 332 ccw_device_get_id(adapter->ccw_device, &dev_id);
303 /* register adapter as SCSI host with mid layer of SCSI stack */ 333 /* register adapter as SCSI host with mid layer of SCSI stack */
304 adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template, 334 adapter->scsi_host = scsi_host_alloc(&zfcp_scsi_host_template,
305 sizeof (struct zfcp_adapter *)); 335 sizeof (struct zfcp_adapter *));
306 if (!adapter->scsi_host) { 336 if (!adapter->scsi_host) {
307 dev_err(&adapter->ccw_device->dev, 337 dev_err(&adapter->ccw_device->dev,
@@ -316,7 +346,7 @@ int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
316 adapter->scsi_host->max_channel = 0; 346 adapter->scsi_host->max_channel = 0;
317 adapter->scsi_host->unique_id = dev_id.devno; 347 adapter->scsi_host->unique_id = dev_id.devno;
318 adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */ 348 adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */
319 adapter->scsi_host->transportt = zfcp_data.scsi_transport_template; 349 adapter->scsi_host->transportt = zfcp_scsi_transport_template;
320 350
321 adapter->scsi_host->hostdata[0] = (unsigned long) adapter; 351 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
322 352
@@ -328,7 +358,11 @@ int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
328 return 0; 358 return 0;
329} 359}
330 360
331void zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter) 361/**
362 * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
363 * @adapter: The zfcp adapter to unregister.
364 */
365void zfcp_scsi_adapter_unregister(struct zfcp_adapter *adapter)
332{ 366{
333 struct Scsi_Host *shost; 367 struct Scsi_Host *shost;
334 struct zfcp_port *port; 368 struct zfcp_port *port;
@@ -346,8 +380,6 @@ void zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
346 scsi_remove_host(shost); 380 scsi_remove_host(shost);
347 scsi_host_put(shost); 381 scsi_host_put(shost);
348 adapter->scsi_host = NULL; 382 adapter->scsi_host = NULL;
349
350 return;
351} 383}
352 384
353static struct fc_host_statistics* 385static struct fc_host_statistics*
@@ -688,33 +720,8 @@ struct fc_function_template zfcp_transport_functions = {
688 /* no functions registered for following dynamic attributes but 720 /* no functions registered for following dynamic attributes but
689 directly set by LLDD */ 721 directly set by LLDD */
690 .show_host_port_type = 1, 722 .show_host_port_type = 1,
723 .show_host_symbolic_name = 1,
691 .show_host_speed = 1, 724 .show_host_speed = 1,
692 .show_host_port_id = 1, 725 .show_host_port_id = 1,
693 .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els), 726 .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els),
694}; 727};
695
696struct zfcp_data zfcp_data = {
697 .scsi_host_template = {
698 .name = "zfcp",
699 .module = THIS_MODULE,
700 .proc_name = "zfcp",
701 .change_queue_depth = zfcp_scsi_change_queue_depth,
702 .slave_alloc = zfcp_scsi_slave_alloc,
703 .slave_configure = zfcp_scsi_slave_configure,
704 .slave_destroy = zfcp_scsi_slave_destroy,
705 .queuecommand = zfcp_scsi_queuecommand,
706 .eh_abort_handler = zfcp_scsi_eh_abort_handler,
707 .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
708 .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
709 .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
710 .can_queue = 4096,
711 .this_id = -1,
712 .sg_tablesize = ZFCP_QDIO_MAX_SBALES_PER_REQ,
713 .cmd_per_lun = 1,
714 .use_clustering = 1,
715 .sdev_attrs = zfcp_sysfs_sdev_attrs,
716 .max_sectors = (ZFCP_QDIO_MAX_SBALES_PER_REQ * 8),
717 .dma_boundary = ZFCP_QDIO_SBALE_LEN - 1,
718 .shost_attrs = zfcp_sysfs_shost_attrs,
719 },
720};
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 8616496ffc02..4a1f029c4fe9 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -381,6 +381,7 @@ config ISCSI_BOOT_SYSFS
381 381
382source "drivers/scsi/cxgbi/Kconfig" 382source "drivers/scsi/cxgbi/Kconfig"
383source "drivers/scsi/bnx2i/Kconfig" 383source "drivers/scsi/bnx2i/Kconfig"
384source "drivers/scsi/bnx2fc/Kconfig"
384source "drivers/scsi/be2iscsi/Kconfig" 385source "drivers/scsi/be2iscsi/Kconfig"
385 386
386config SGIWD93_SCSI 387config SGIWD93_SCSI
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index ef6de669424b..7ad0b8a79ae8 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_LIBFC) += libfc/
40obj-$(CONFIG_LIBFCOE) += fcoe/ 40obj-$(CONFIG_LIBFCOE) += fcoe/
41obj-$(CONFIG_FCOE) += fcoe/ 41obj-$(CONFIG_FCOE) += fcoe/
42obj-$(CONFIG_FCOE_FNIC) += fnic/ 42obj-$(CONFIG_FCOE_FNIC) += fnic/
43obj-$(CONFIG_SCSI_BNX2X_FCOE) += libfc/ fcoe/ bnx2fc/
43obj-$(CONFIG_ISCSI_TCP) += libiscsi.o libiscsi_tcp.o iscsi_tcp.o 44obj-$(CONFIG_ISCSI_TCP) += libiscsi.o libiscsi_tcp.o iscsi_tcp.o
44obj-$(CONFIG_INFINIBAND_ISER) += libiscsi.o 45obj-$(CONFIG_INFINIBAND_ISER) += libiscsi.o
45obj-$(CONFIG_ISCSI_BOOT_SYSFS) += iscsi_boot_sysfs.o 46obj-$(CONFIG_ISCSI_BOOT_SYSFS) += iscsi_boot_sysfs.o
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 9a5629f94f95..e7cd2fcbe036 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -936,8 +936,7 @@ static void NCR5380_exit(struct Scsi_Host *instance)
936{ 936{
937 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata; 937 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata;
938 938
939 cancel_delayed_work(&hostdata->coroutine); 939 cancel_delayed_work_sync(&hostdata->coroutine);
940 flush_scheduled_work();
941} 940}
942 941
943/** 942/**
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 984bd527c6c9..da7b9887ec48 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1020,7 +1020,7 @@ static void arcmsr_remove(struct pci_dev *pdev)
1020 int poll_count = 0; 1020 int poll_count = 0;
1021 arcmsr_free_sysfs_attr(acb); 1021 arcmsr_free_sysfs_attr(acb);
1022 scsi_remove_host(host); 1022 scsi_remove_host(host);
1023 flush_scheduled_work(); 1023 flush_work_sync(&acb->arcmsr_do_message_isr_bh);
1024 del_timer_sync(&acb->eternal_timer); 1024 del_timer_sync(&acb->eternal_timer);
1025 arcmsr_disable_outbound_ints(acb); 1025 arcmsr_disable_outbound_ints(acb);
1026 arcmsr_stop_adapter_bgrb(acb); 1026 arcmsr_stop_adapter_bgrb(acb);
@@ -1066,7 +1066,7 @@ static void arcmsr_shutdown(struct pci_dev *pdev)
1066 (struct AdapterControlBlock *)host->hostdata; 1066 (struct AdapterControlBlock *)host->hostdata;
1067 del_timer_sync(&acb->eternal_timer); 1067 del_timer_sync(&acb->eternal_timer);
1068 arcmsr_disable_outbound_ints(acb); 1068 arcmsr_disable_outbound_ints(acb);
1069 flush_scheduled_work(); 1069 flush_work_sync(&acb->arcmsr_do_message_isr_bh);
1070 arcmsr_stop_adapter_bgrb(acb); 1070 arcmsr_stop_adapter_bgrb(acb);
1071 arcmsr_flush_adapter_cache(acb); 1071 arcmsr_flush_adapter_cache(acb);
1072} 1072}
diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c
index eaaa8813067d..868cc5590145 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.c
+++ b/drivers/scsi/be2iscsi/be_iscsi.c
@@ -210,28 +210,20 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
210} 210}
211 211
212/** 212/**
213 * beiscsi_conn_get_param - get the iscsi parameter 213 * beiscsi_ep_get_param - get the iscsi parameter
214 * @cls_conn: pointer to iscsi cls conn 214 * @ep: pointer to iscsi ep
215 * @param: parameter type identifier 215 * @param: parameter type identifier
216 * @buf: buffer pointer 216 * @buf: buffer pointer
217 * 217 *
218 * returns iscsi parameter 218 * returns iscsi parameter
219 */ 219 */
220int beiscsi_conn_get_param(struct iscsi_cls_conn *cls_conn, 220int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
221 enum iscsi_param param, char *buf) 221 enum iscsi_param param, char *buf)
222{ 222{
223 struct beiscsi_endpoint *beiscsi_ep; 223 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
224 struct iscsi_conn *conn = cls_conn->dd_data;
225 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
226 int len = 0; 224 int len = 0;
227 225
228 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_param, param= %d\n", param); 226 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_param, param= %d\n", param);
229 beiscsi_ep = beiscsi_conn->ep;
230 if (!beiscsi_ep) {
231 SE_DEBUG(DBG_LVL_1,
232 "In beiscsi_conn_get_param , no beiscsi_ep\n");
233 return -ENODEV;
234 }
235 227
236 switch (param) { 228 switch (param) {
237 case ISCSI_PARAM_CONN_PORT: 229 case ISCSI_PARAM_CONN_PORT:
@@ -244,7 +236,7 @@ int beiscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
244 len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr); 236 len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
245 break; 237 break;
246 default: 238 default:
247 return iscsi_conn_get_param(cls_conn, param, buf); 239 return -ENOSYS;
248 } 240 }
249 return len; 241 return len;
250} 242}
diff --git a/drivers/scsi/be2iscsi/be_iscsi.h b/drivers/scsi/be2iscsi/be_iscsi.h
index 8950a702b9f4..9c532797c29e 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.h
+++ b/drivers/scsi/be2iscsi/be_iscsi.h
@@ -48,8 +48,8 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
48 struct iscsi_cls_conn *cls_conn, 48 struct iscsi_cls_conn *cls_conn,
49 uint64_t transport_fd, int is_leading); 49 uint64_t transport_fd, int is_leading);
50 50
51int beiscsi_conn_get_param(struct iscsi_cls_conn *cls_conn, 51int beiscsi_ep_get_param(struct iscsi_endpoint *ep, enum iscsi_param param,
52 enum iscsi_param param, char *buf); 52 char *buf);
53 53
54int beiscsi_get_host_param(struct Scsi_Host *shost, 54int beiscsi_get_host_param(struct Scsi_Host *shost,
55 enum iscsi_host_param param, char *buf); 55 enum iscsi_host_param param, char *buf);
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 638c72b7f94a..24e20ba9633c 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -4384,7 +4384,7 @@ struct iscsi_transport beiscsi_iscsi_transport = {
4384 .bind_conn = beiscsi_conn_bind, 4384 .bind_conn = beiscsi_conn_bind,
4385 .destroy_conn = iscsi_conn_teardown, 4385 .destroy_conn = iscsi_conn_teardown,
4386 .set_param = beiscsi_set_param, 4386 .set_param = beiscsi_set_param,
4387 .get_conn_param = beiscsi_conn_get_param, 4387 .get_conn_param = iscsi_conn_get_param,
4388 .get_session_param = iscsi_session_get_param, 4388 .get_session_param = iscsi_session_get_param,
4389 .get_host_param = beiscsi_get_host_param, 4389 .get_host_param = beiscsi_get_host_param,
4390 .start_conn = beiscsi_conn_start, 4390 .start_conn = beiscsi_conn_start,
@@ -4395,6 +4395,7 @@ struct iscsi_transport beiscsi_iscsi_transport = {
4395 .alloc_pdu = beiscsi_alloc_pdu, 4395 .alloc_pdu = beiscsi_alloc_pdu,
4396 .parse_pdu_itt = beiscsi_parse_pdu, 4396 .parse_pdu_itt = beiscsi_parse_pdu,
4397 .get_stats = beiscsi_conn_get_stats, 4397 .get_stats = beiscsi_conn_get_stats,
4398 .get_ep_param = beiscsi_ep_get_param,
4398 .ep_connect = beiscsi_ep_connect, 4399 .ep_connect = beiscsi_ep_connect,
4399 .ep_poll = beiscsi_ep_poll, 4400 .ep_poll = beiscsi_ep_poll,
4400 .ep_disconnect = beiscsi_ep_disconnect, 4401 .ep_disconnect = beiscsi_ep_disconnect,
diff --git a/drivers/scsi/bnx2fc/57xx_hsi_bnx2fc.h b/drivers/scsi/bnx2fc/57xx_hsi_bnx2fc.h
new file mode 100644
index 000000000000..69d031d98469
--- /dev/null
+++ b/drivers/scsi/bnx2fc/57xx_hsi_bnx2fc.h
@@ -0,0 +1,1080 @@
1#ifndef __57XX_FCOE_HSI_LINUX_LE__
2#define __57XX_FCOE_HSI_LINUX_LE__
3
4/*
5 * common data for all protocols
6 */
7struct b577xx_doorbell_hdr {
8 u8 header;
9#define B577XX_DOORBELL_HDR_RX (0x1<<0)
10#define B577XX_DOORBELL_HDR_RX_SHIFT 0
11#define B577XX_DOORBELL_HDR_DB_TYPE (0x1<<1)
12#define B577XX_DOORBELL_HDR_DB_TYPE_SHIFT 1
13#define B577XX_DOORBELL_HDR_DPM_SIZE (0x3<<2)
14#define B577XX_DOORBELL_HDR_DPM_SIZE_SHIFT 2
15#define B577XX_DOORBELL_HDR_CONN_TYPE (0xF<<4)
16#define B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT 4
17};
18
19/*
20 * doorbell message sent to the chip
21 */
22struct b577xx_doorbell_set_prod {
23#if defined(__BIG_ENDIAN)
24 u16 prod;
25 u8 zero_fill1;
26 struct b577xx_doorbell_hdr header;
27#elif defined(__LITTLE_ENDIAN)
28 struct b577xx_doorbell_hdr header;
29 u8 zero_fill1;
30 u16 prod;
31#endif
32};
33
34
35struct regpair {
36 __le32 lo;
37 __le32 hi;
38};
39
40
41/*
42 * Fixed size structure in order to plant it in Union structure
43 */
44struct fcoe_abts_rsp_union {
45 u32 r_ctl;
46 u32 abts_rsp_payload[7];
47};
48
49
50/*
51 * 4 regs size
52 */
53struct fcoe_bd_ctx {
54 u32 buf_addr_hi;
55 u32 buf_addr_lo;
56#if defined(__BIG_ENDIAN)
57 u16 rsrv0;
58 u16 buf_len;
59#elif defined(__LITTLE_ENDIAN)
60 u16 buf_len;
61 u16 rsrv0;
62#endif
63#if defined(__BIG_ENDIAN)
64 u16 rsrv1;
65 u16 flags;
66#elif defined(__LITTLE_ENDIAN)
67 u16 flags;
68 u16 rsrv1;
69#endif
70};
71
72
73struct fcoe_cleanup_flow_info {
74#if defined(__BIG_ENDIAN)
75 u16 reserved1;
76 u16 task_id;
77#elif defined(__LITTLE_ENDIAN)
78 u16 task_id;
79 u16 reserved1;
80#endif
81 u32 reserved2[7];
82};
83
84
85struct fcoe_fcp_cmd_payload {
86 u32 opaque[8];
87};
88
89struct fcoe_fc_hdr {
90#if defined(__BIG_ENDIAN)
91 u8 cs_ctl;
92 u8 s_id[3];
93#elif defined(__LITTLE_ENDIAN)
94 u8 s_id[3];
95 u8 cs_ctl;
96#endif
97#if defined(__BIG_ENDIAN)
98 u8 r_ctl;
99 u8 d_id[3];
100#elif defined(__LITTLE_ENDIAN)
101 u8 d_id[3];
102 u8 r_ctl;
103#endif
104#if defined(__BIG_ENDIAN)
105 u8 seq_id;
106 u8 df_ctl;
107 u16 seq_cnt;
108#elif defined(__LITTLE_ENDIAN)
109 u16 seq_cnt;
110 u8 df_ctl;
111 u8 seq_id;
112#endif
113#if defined(__BIG_ENDIAN)
114 u8 type;
115 u8 f_ctl[3];
116#elif defined(__LITTLE_ENDIAN)
117 u8 f_ctl[3];
118 u8 type;
119#endif
120 u32 parameters;
121#if defined(__BIG_ENDIAN)
122 u16 ox_id;
123 u16 rx_id;
124#elif defined(__LITTLE_ENDIAN)
125 u16 rx_id;
126 u16 ox_id;
127#endif
128};
129
130struct fcoe_fc_frame {
131 struct fcoe_fc_hdr fc_hdr;
132 u32 reserved0[2];
133};
134
135union fcoe_cmd_flow_info {
136 struct fcoe_fcp_cmd_payload fcp_cmd_payload;
137 struct fcoe_fc_frame mp_fc_frame;
138};
139
140
141
142struct fcoe_fcp_rsp_flags {
143 u8 flags;
144#define FCOE_FCP_RSP_FLAGS_FCP_RSP_LEN_VALID (0x1<<0)
145#define FCOE_FCP_RSP_FLAGS_FCP_RSP_LEN_VALID_SHIFT 0
146#define FCOE_FCP_RSP_FLAGS_FCP_SNS_LEN_VALID (0x1<<1)
147#define FCOE_FCP_RSP_FLAGS_FCP_SNS_LEN_VALID_SHIFT 1
148#define FCOE_FCP_RSP_FLAGS_FCP_RESID_OVER (0x1<<2)
149#define FCOE_FCP_RSP_FLAGS_FCP_RESID_OVER_SHIFT 2
150#define FCOE_FCP_RSP_FLAGS_FCP_RESID_UNDER (0x1<<3)
151#define FCOE_FCP_RSP_FLAGS_FCP_RESID_UNDER_SHIFT 3
152#define FCOE_FCP_RSP_FLAGS_FCP_CONF_REQ (0x1<<4)
153#define FCOE_FCP_RSP_FLAGS_FCP_CONF_REQ_SHIFT 4
154#define FCOE_FCP_RSP_FLAGS_FCP_BIDI_FLAGS (0x7<<5)
155#define FCOE_FCP_RSP_FLAGS_FCP_BIDI_FLAGS_SHIFT 5
156};
157
158
159struct fcoe_fcp_rsp_payload {
160 struct regpair reserved0;
161 u32 fcp_resid;
162#if defined(__BIG_ENDIAN)
163 u16 retry_delay_timer;
164 struct fcoe_fcp_rsp_flags fcp_flags;
165 u8 scsi_status_code;
166#elif defined(__LITTLE_ENDIAN)
167 u8 scsi_status_code;
168 struct fcoe_fcp_rsp_flags fcp_flags;
169 u16 retry_delay_timer;
170#endif
171 u32 fcp_rsp_len;
172 u32 fcp_sns_len;
173};
174
175
176/*
177 * Fixed size structure in order to plant it in Union structure
178 */
179struct fcoe_fcp_rsp_union {
180 struct fcoe_fcp_rsp_payload payload;
181 struct regpair reserved0;
182};
183
184
185struct fcoe_fcp_xfr_rdy_payload {
186 u32 burst_len;
187 u32 data_ro;
188};
189
190struct fcoe_read_flow_info {
191 struct fcoe_fc_hdr fc_data_in_hdr;
192 u32 reserved[2];
193};
194
195struct fcoe_write_flow_info {
196 struct fcoe_fc_hdr fc_data_out_hdr;
197 struct fcoe_fcp_xfr_rdy_payload fcp_xfr_payload;
198};
199
200union fcoe_rsp_flow_info {
201 struct fcoe_fcp_rsp_union fcp_rsp;
202 struct fcoe_abts_rsp_union abts_rsp;
203};
204
205/*
206 * 32 bytes used for general purposes
207 */
208union fcoe_general_task_ctx {
209 union fcoe_cmd_flow_info cmd_info;
210 struct fcoe_read_flow_info read_info;
211 struct fcoe_write_flow_info write_info;
212 union fcoe_rsp_flow_info rsp_info;
213 struct fcoe_cleanup_flow_info cleanup_info;
214 u32 comp_info[8];
215};
216
217
218/*
219 * FCoE KCQ CQE parameters
220 */
221union fcoe_kcqe_params {
222 u32 reserved0[4];
223};
224
225/*
226 * FCoE KCQ CQE
227 */
228struct fcoe_kcqe {
229 u32 fcoe_conn_id;
230 u32 completion_status;
231 u32 fcoe_conn_context_id;
232 union fcoe_kcqe_params params;
233#if defined(__BIG_ENDIAN)
234 u8 flags;
235#define FCOE_KCQE_RESERVED0 (0x7<<0)
236#define FCOE_KCQE_RESERVED0_SHIFT 0
237#define FCOE_KCQE_RAMROD_COMPLETION (0x1<<3)
238#define FCOE_KCQE_RAMROD_COMPLETION_SHIFT 3
239#define FCOE_KCQE_LAYER_CODE (0x7<<4)
240#define FCOE_KCQE_LAYER_CODE_SHIFT 4
241#define FCOE_KCQE_LINKED_WITH_NEXT (0x1<<7)
242#define FCOE_KCQE_LINKED_WITH_NEXT_SHIFT 7
243 u8 op_code;
244 u16 qe_self_seq;
245#elif defined(__LITTLE_ENDIAN)
246 u16 qe_self_seq;
247 u8 op_code;
248 u8 flags;
249#define FCOE_KCQE_RESERVED0 (0x7<<0)
250#define FCOE_KCQE_RESERVED0_SHIFT 0
251#define FCOE_KCQE_RAMROD_COMPLETION (0x1<<3)
252#define FCOE_KCQE_RAMROD_COMPLETION_SHIFT 3
253#define FCOE_KCQE_LAYER_CODE (0x7<<4)
254#define FCOE_KCQE_LAYER_CODE_SHIFT 4
255#define FCOE_KCQE_LINKED_WITH_NEXT (0x1<<7)
256#define FCOE_KCQE_LINKED_WITH_NEXT_SHIFT 7
257#endif
258};
259
260/*
261 * FCoE KWQE header
262 */
263struct fcoe_kwqe_header {
264#if defined(__BIG_ENDIAN)
265 u8 flags;
266#define FCOE_KWQE_HEADER_RESERVED0 (0xF<<0)
267#define FCOE_KWQE_HEADER_RESERVED0_SHIFT 0
268#define FCOE_KWQE_HEADER_LAYER_CODE (0x7<<4)
269#define FCOE_KWQE_HEADER_LAYER_CODE_SHIFT 4
270#define FCOE_KWQE_HEADER_RESERVED1 (0x1<<7)
271#define FCOE_KWQE_HEADER_RESERVED1_SHIFT 7
272 u8 op_code;
273#elif defined(__LITTLE_ENDIAN)
274 u8 op_code;
275 u8 flags;
276#define FCOE_KWQE_HEADER_RESERVED0 (0xF<<0)
277#define FCOE_KWQE_HEADER_RESERVED0_SHIFT 0
278#define FCOE_KWQE_HEADER_LAYER_CODE (0x7<<4)
279#define FCOE_KWQE_HEADER_LAYER_CODE_SHIFT 4
280#define FCOE_KWQE_HEADER_RESERVED1 (0x1<<7)
281#define FCOE_KWQE_HEADER_RESERVED1_SHIFT 7
282#endif
283};
284
285/*
286 * FCoE firmware init request 1
287 */
288struct fcoe_kwqe_init1 {
289#if defined(__BIG_ENDIAN)
290 struct fcoe_kwqe_header hdr;
291 u16 num_tasks;
292#elif defined(__LITTLE_ENDIAN)
293 u16 num_tasks;
294 struct fcoe_kwqe_header hdr;
295#endif
296 u32 task_list_pbl_addr_lo;
297 u32 task_list_pbl_addr_hi;
298 u32 dummy_buffer_addr_lo;
299 u32 dummy_buffer_addr_hi;
300#if defined(__BIG_ENDIAN)
301 u16 rq_num_wqes;
302 u16 sq_num_wqes;
303#elif defined(__LITTLE_ENDIAN)
304 u16 sq_num_wqes;
305 u16 rq_num_wqes;
306#endif
307#if defined(__BIG_ENDIAN)
308 u16 cq_num_wqes;
309 u16 rq_buffer_log_size;
310#elif defined(__LITTLE_ENDIAN)
311 u16 rq_buffer_log_size;
312 u16 cq_num_wqes;
313#endif
314#if defined(__BIG_ENDIAN)
315 u8 flags;
316#define FCOE_KWQE_INIT1_LOG_PAGE_SIZE (0xF<<0)
317#define FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT 0
318#define FCOE_KWQE_INIT1_LOG_CACHED_PBES_PER_FUNC (0x7<<4)
319#define FCOE_KWQE_INIT1_LOG_CACHED_PBES_PER_FUNC_SHIFT 4
320#define FCOE_KWQE_INIT1_RESERVED1 (0x1<<7)
321#define FCOE_KWQE_INIT1_RESERVED1_SHIFT 7
322 u8 num_sessions_log;
323 u16 mtu;
324#elif defined(__LITTLE_ENDIAN)
325 u16 mtu;
326 u8 num_sessions_log;
327 u8 flags;
328#define FCOE_KWQE_INIT1_LOG_PAGE_SIZE (0xF<<0)
329#define FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT 0
330#define FCOE_KWQE_INIT1_LOG_CACHED_PBES_PER_FUNC (0x7<<4)
331#define FCOE_KWQE_INIT1_LOG_CACHED_PBES_PER_FUNC_SHIFT 4
332#define FCOE_KWQE_INIT1_RESERVED1 (0x1<<7)
333#define FCOE_KWQE_INIT1_RESERVED1_SHIFT 7
334#endif
335};
336
337/*
338 * FCoE firmware init request 2
339 */
340struct fcoe_kwqe_init2 {
341#if defined(__BIG_ENDIAN)
342 struct fcoe_kwqe_header hdr;
343 u16 reserved0;
344#elif defined(__LITTLE_ENDIAN)
345 u16 reserved0;
346 struct fcoe_kwqe_header hdr;
347#endif
348 u32 hash_tbl_pbl_addr_lo;
349 u32 hash_tbl_pbl_addr_hi;
350 u32 t2_hash_tbl_addr_lo;
351 u32 t2_hash_tbl_addr_hi;
352 u32 t2_ptr_hash_tbl_addr_lo;
353 u32 t2_ptr_hash_tbl_addr_hi;
354 u32 free_list_count;
355};
356
357/*
358 * FCoE firmware init request 3
359 */
360struct fcoe_kwqe_init3 {
361#if defined(__BIG_ENDIAN)
362 struct fcoe_kwqe_header hdr;
363 u16 reserved0;
364#elif defined(__LITTLE_ENDIAN)
365 u16 reserved0;
366 struct fcoe_kwqe_header hdr;
367#endif
368 u32 error_bit_map_lo;
369 u32 error_bit_map_hi;
370#if defined(__BIG_ENDIAN)
371 u8 reserved21[3];
372 u8 cached_session_enable;
373#elif defined(__LITTLE_ENDIAN)
374 u8 cached_session_enable;
375 u8 reserved21[3];
376#endif
377 u32 reserved2[4];
378};
379
380/*
381 * FCoE connection offload request 1
382 */
383struct fcoe_kwqe_conn_offload1 {
384#if defined(__BIG_ENDIAN)
385 struct fcoe_kwqe_header hdr;
386 u16 fcoe_conn_id;
387#elif defined(__LITTLE_ENDIAN)
388 u16 fcoe_conn_id;
389 struct fcoe_kwqe_header hdr;
390#endif
391 u32 sq_addr_lo;
392 u32 sq_addr_hi;
393 u32 rq_pbl_addr_lo;
394 u32 rq_pbl_addr_hi;
395 u32 rq_first_pbe_addr_lo;
396 u32 rq_first_pbe_addr_hi;
397#if defined(__BIG_ENDIAN)
398 u16 reserved0;
399 u16 rq_prod;
400#elif defined(__LITTLE_ENDIAN)
401 u16 rq_prod;
402 u16 reserved0;
403#endif
404};
405
406/*
407 * FCoE connection offload request 2
408 */
409struct fcoe_kwqe_conn_offload2 {
410#if defined(__BIG_ENDIAN)
411 struct fcoe_kwqe_header hdr;
412 u16 tx_max_fc_pay_len;
413#elif defined(__LITTLE_ENDIAN)
414 u16 tx_max_fc_pay_len;
415 struct fcoe_kwqe_header hdr;
416#endif
417 u32 cq_addr_lo;
418 u32 cq_addr_hi;
419 u32 xferq_addr_lo;
420 u32 xferq_addr_hi;
421 u32 conn_db_addr_lo;
422 u32 conn_db_addr_hi;
423 u32 reserved1;
424};
425
426/*
427 * FCoE connection offload request 3
428 */
429struct fcoe_kwqe_conn_offload3 {
430#if defined(__BIG_ENDIAN)
431 struct fcoe_kwqe_header hdr;
432 u16 vlan_tag;
433#define FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID (0xFFF<<0)
434#define FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT 0
435#define FCOE_KWQE_CONN_OFFLOAD3_CFI (0x1<<12)
436#define FCOE_KWQE_CONN_OFFLOAD3_CFI_SHIFT 12
437#define FCOE_KWQE_CONN_OFFLOAD3_PRIORITY (0x7<<13)
438#define FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT 13
439#elif defined(__LITTLE_ENDIAN)
440 u16 vlan_tag;
441#define FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID (0xFFF<<0)
442#define FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT 0
443#define FCOE_KWQE_CONN_OFFLOAD3_CFI (0x1<<12)
444#define FCOE_KWQE_CONN_OFFLOAD3_CFI_SHIFT 12
445#define FCOE_KWQE_CONN_OFFLOAD3_PRIORITY (0x7<<13)
446#define FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT 13
447 struct fcoe_kwqe_header hdr;
448#endif
449#if defined(__BIG_ENDIAN)
450 u8 tx_max_conc_seqs_c3;
451 u8 s_id[3];
452#elif defined(__LITTLE_ENDIAN)
453 u8 s_id[3];
454 u8 tx_max_conc_seqs_c3;
455#endif
456#if defined(__BIG_ENDIAN)
457 u8 flags;
458#define FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS (0x1<<0)
459#define FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT 0
460#define FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES (0x1<<1)
461#define FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT 1
462#define FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT (0x1<<2)
463#define FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT 2
464#define FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ (0x1<<3)
465#define FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ_SHIFT 3
466#define FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID (0x1<<4)
467#define FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT 4
468#define FCOE_KWQE_CONN_OFFLOAD3_B_C2_VALID (0x1<<5)
469#define FCOE_KWQE_CONN_OFFLOAD3_B_C2_VALID_SHIFT 5
470#define FCOE_KWQE_CONN_OFFLOAD3_B_ACK_0 (0x1<<6)
471#define FCOE_KWQE_CONN_OFFLOAD3_B_ACK_0_SHIFT 6
472#define FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG (0x1<<7)
473#define FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT 7
474 u8 d_id[3];
475#elif defined(__LITTLE_ENDIAN)
476 u8 d_id[3];
477 u8 flags;
478#define FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS (0x1<<0)
479#define FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT 0
480#define FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES (0x1<<1)
481#define FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT 1
482#define FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT (0x1<<2)
483#define FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT 2
484#define FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ (0x1<<3)
485#define FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ_SHIFT 3
486#define FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID (0x1<<4)
487#define FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT 4
488#define FCOE_KWQE_CONN_OFFLOAD3_B_C2_VALID (0x1<<5)
489#define FCOE_KWQE_CONN_OFFLOAD3_B_C2_VALID_SHIFT 5
490#define FCOE_KWQE_CONN_OFFLOAD3_B_ACK_0 (0x1<<6)
491#define FCOE_KWQE_CONN_OFFLOAD3_B_ACK_0_SHIFT 6
492#define FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG (0x1<<7)
493#define FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT 7
494#endif
495 u32 reserved;
496 u32 confq_first_pbe_addr_lo;
497 u32 confq_first_pbe_addr_hi;
498#if defined(__BIG_ENDIAN)
499 u16 rx_max_fc_pay_len;
500 u16 tx_total_conc_seqs;
501#elif defined(__LITTLE_ENDIAN)
502 u16 tx_total_conc_seqs;
503 u16 rx_max_fc_pay_len;
504#endif
505#if defined(__BIG_ENDIAN)
506 u8 rx_open_seqs_exch_c3;
507 u8 rx_max_conc_seqs_c3;
508 u16 rx_total_conc_seqs;
509#elif defined(__LITTLE_ENDIAN)
510 u16 rx_total_conc_seqs;
511 u8 rx_max_conc_seqs_c3;
512 u8 rx_open_seqs_exch_c3;
513#endif
514};
515
516/*
517 * FCoE connection offload request 4
518 */
519struct fcoe_kwqe_conn_offload4 {
520#if defined(__BIG_ENDIAN)
521 struct fcoe_kwqe_header hdr;
522 u8 reserved2;
523 u8 e_d_tov_timer_val;
524#elif defined(__LITTLE_ENDIAN)
525 u8 e_d_tov_timer_val;
526 u8 reserved2;
527 struct fcoe_kwqe_header hdr;
528#endif
529 u8 src_mac_addr_lo32[4];
530#if defined(__BIG_ENDIAN)
531 u8 dst_mac_addr_hi16[2];
532 u8 src_mac_addr_hi16[2];
533#elif defined(__LITTLE_ENDIAN)
534 u8 src_mac_addr_hi16[2];
535 u8 dst_mac_addr_hi16[2];
536#endif
537 u8 dst_mac_addr_lo32[4];
538 u32 lcq_addr_lo;
539 u32 lcq_addr_hi;
540 u32 confq_pbl_base_addr_lo;
541 u32 confq_pbl_base_addr_hi;
542};
543
544/*
545 * FCoE connection enable request
546 */
547struct fcoe_kwqe_conn_enable_disable {
548#if defined(__BIG_ENDIAN)
549 struct fcoe_kwqe_header hdr;
550 u16 reserved0;
551#elif defined(__LITTLE_ENDIAN)
552 u16 reserved0;
553 struct fcoe_kwqe_header hdr;
554#endif
555 u8 src_mac_addr_lo32[4];
556#if defined(__BIG_ENDIAN)
557 u16 vlan_tag;
558#define FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID (0xFFF<<0)
559#define FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT 0
560#define FCOE_KWQE_CONN_ENABLE_DISABLE_CFI (0x1<<12)
561#define FCOE_KWQE_CONN_ENABLE_DISABLE_CFI_SHIFT 12
562#define FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY (0x7<<13)
563#define FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT 13
564 u8 src_mac_addr_hi16[2];
565#elif defined(__LITTLE_ENDIAN)
566 u8 src_mac_addr_hi16[2];
567 u16 vlan_tag;
568#define FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID (0xFFF<<0)
569#define FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT 0
570#define FCOE_KWQE_CONN_ENABLE_DISABLE_CFI (0x1<<12)
571#define FCOE_KWQE_CONN_ENABLE_DISABLE_CFI_SHIFT 12
572#define FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY (0x7<<13)
573#define FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT 13
574#endif
575 u8 dst_mac_addr_lo32[4];
576#if defined(__BIG_ENDIAN)
577 u16 reserved1;
578 u8 dst_mac_addr_hi16[2];
579#elif defined(__LITTLE_ENDIAN)
580 u8 dst_mac_addr_hi16[2];
581 u16 reserved1;
582#endif
583#if defined(__BIG_ENDIAN)
584 u8 vlan_flag;
585 u8 s_id[3];
586#elif defined(__LITTLE_ENDIAN)
587 u8 s_id[3];
588 u8 vlan_flag;
589#endif
590#if defined(__BIG_ENDIAN)
591 u8 reserved3;
592 u8 d_id[3];
593#elif defined(__LITTLE_ENDIAN)
594 u8 d_id[3];
595 u8 reserved3;
596#endif
597 u32 context_id;
598 u32 conn_id;
599 u32 reserved4;
600};
601
602/*
603 * FCoE connection destroy request
604 */
605struct fcoe_kwqe_conn_destroy {
606#if defined(__BIG_ENDIAN)
607 struct fcoe_kwqe_header hdr;
608 u16 reserved0;
609#elif defined(__LITTLE_ENDIAN)
610 u16 reserved0;
611 struct fcoe_kwqe_header hdr;
612#endif
613 u32 context_id;
614 u32 conn_id;
615 u32 reserved1[5];
616};
617
618/*
619 * FCoe destroy request
620 */
621struct fcoe_kwqe_destroy {
622#if defined(__BIG_ENDIAN)
623 struct fcoe_kwqe_header hdr;
624 u16 reserved0;
625#elif defined(__LITTLE_ENDIAN)
626 u16 reserved0;
627 struct fcoe_kwqe_header hdr;
628#endif
629 u32 reserved1[7];
630};
631
632/*
633 * FCoe statistics request
634 */
635struct fcoe_kwqe_stat {
636#if defined(__BIG_ENDIAN)
637 struct fcoe_kwqe_header hdr;
638 u16 reserved0;
639#elif defined(__LITTLE_ENDIAN)
640 u16 reserved0;
641 struct fcoe_kwqe_header hdr;
642#endif
643 u32 stat_params_addr_lo;
644 u32 stat_params_addr_hi;
645 u32 reserved1[5];
646};
647
648/*
649 * FCoE KWQ WQE
650 */
651union fcoe_kwqe {
652 struct fcoe_kwqe_init1 init1;
653 struct fcoe_kwqe_init2 init2;
654 struct fcoe_kwqe_init3 init3;
655 struct fcoe_kwqe_conn_offload1 conn_offload1;
656 struct fcoe_kwqe_conn_offload2 conn_offload2;
657 struct fcoe_kwqe_conn_offload3 conn_offload3;
658 struct fcoe_kwqe_conn_offload4 conn_offload4;
659 struct fcoe_kwqe_conn_enable_disable conn_enable_disable;
660 struct fcoe_kwqe_conn_destroy conn_destroy;
661 struct fcoe_kwqe_destroy destroy;
662 struct fcoe_kwqe_stat statistics;
663};
664
665struct fcoe_mul_sges_ctx {
666 struct regpair cur_sge_addr;
667#if defined(__BIG_ENDIAN)
668 u8 sgl_size;
669 u8 cur_sge_idx;
670 u16 cur_sge_off;
671#elif defined(__LITTLE_ENDIAN)
672 u16 cur_sge_off;
673 u8 cur_sge_idx;
674 u8 sgl_size;
675#endif
676};
677
678struct fcoe_s_stat_ctx {
679 u8 flags;
680#define FCOE_S_STAT_CTX_ACTIVE (0x1<<0)
681#define FCOE_S_STAT_CTX_ACTIVE_SHIFT 0
682#define FCOE_S_STAT_CTX_ACK_ABORT_SEQ_COND (0x1<<1)
683#define FCOE_S_STAT_CTX_ACK_ABORT_SEQ_COND_SHIFT 1
684#define FCOE_S_STAT_CTX_ABTS_PERFORMED (0x1<<2)
685#define FCOE_S_STAT_CTX_ABTS_PERFORMED_SHIFT 2
686#define FCOE_S_STAT_CTX_SEQ_TIMEOUT (0x1<<3)
687#define FCOE_S_STAT_CTX_SEQ_TIMEOUT_SHIFT 3
688#define FCOE_S_STAT_CTX_P_RJT (0x1<<4)
689#define FCOE_S_STAT_CTX_P_RJT_SHIFT 4
690#define FCOE_S_STAT_CTX_ACK_EOFT (0x1<<5)
691#define FCOE_S_STAT_CTX_ACK_EOFT_SHIFT 5
692#define FCOE_S_STAT_CTX_RSRV1 (0x3<<6)
693#define FCOE_S_STAT_CTX_RSRV1_SHIFT 6
694};
695
696struct fcoe_seq_ctx {
697#if defined(__BIG_ENDIAN)
698 u16 low_seq_cnt;
699 struct fcoe_s_stat_ctx s_stat;
700 u8 seq_id;
701#elif defined(__LITTLE_ENDIAN)
702 u8 seq_id;
703 struct fcoe_s_stat_ctx s_stat;
704 u16 low_seq_cnt;
705#endif
706#if defined(__BIG_ENDIAN)
707 u16 err_seq_cnt;
708 u16 high_seq_cnt;
709#elif defined(__LITTLE_ENDIAN)
710 u16 high_seq_cnt;
711 u16 err_seq_cnt;
712#endif
713 u32 low_exp_ro;
714 u32 high_exp_ro;
715};
716
717
718struct fcoe_single_sge_ctx {
719 struct regpair cur_buf_addr;
720#if defined(__BIG_ENDIAN)
721 u16 reserved0;
722 u16 cur_buf_rem;
723#elif defined(__LITTLE_ENDIAN)
724 u16 cur_buf_rem;
725 u16 reserved0;
726#endif
727};
728
729union fcoe_sgl_ctx {
730 struct fcoe_single_sge_ctx single_sge;
731 struct fcoe_mul_sges_ctx mul_sges;
732};
733
734
735
736/*
737 * FCoE SQ element
738 */
739struct fcoe_sqe {
740 u16 wqe;
741#define FCOE_SQE_TASK_ID (0x7FFF<<0)
742#define FCOE_SQE_TASK_ID_SHIFT 0
743#define FCOE_SQE_TOGGLE_BIT (0x1<<15)
744#define FCOE_SQE_TOGGLE_BIT_SHIFT 15
745};
746
747
748
749struct fcoe_task_ctx_entry_tx_only {
750 union fcoe_sgl_ctx sgl_ctx;
751};
752
753struct fcoe_task_ctx_entry_txwr_rxrd {
754#if defined(__BIG_ENDIAN)
755 u16 verify_tx_seq;
756 u8 init_flags;
757#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE (0x7<<0)
758#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT 0
759#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE (0x1<<3)
760#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE_SHIFT 3
761#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE (0x1<<4)
762#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT 4
763#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_SINGLE_SGE (0x1<<5)
764#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_SINGLE_SGE_SHIFT 5
765#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_RSRV5 (0x3<<6)
766#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_RSRV5_SHIFT 6
767 u8 tx_flags;
768#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE (0xF<<0)
769#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT 0
770#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_RSRV4 (0xF<<4)
771#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_RSRV4_SHIFT 4
772#elif defined(__LITTLE_ENDIAN)
773 u8 tx_flags;
774#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE (0xF<<0)
775#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT 0
776#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_RSRV4 (0xF<<4)
777#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_RSRV4_SHIFT 4
778 u8 init_flags;
779#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE (0x7<<0)
780#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT 0
781#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE (0x1<<3)
782#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE_SHIFT 3
783#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE (0x1<<4)
784#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT 4
785#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_SINGLE_SGE (0x1<<5)
786#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_SINGLE_SGE_SHIFT 5
787#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_RSRV5 (0x3<<6)
788#define FCOE_TASK_CTX_ENTRY_TXWR_RXRD_RSRV5_SHIFT 6
789 u16 verify_tx_seq;
790#endif
791};
792
793/*
794 * Common section. Both TX and RX processing might write and read from it in
795 * different flows
796 */
797struct fcoe_task_ctx_entry_tx_rx_cmn {
798 u32 data_2_trns;
799 union fcoe_general_task_ctx general;
800#if defined(__BIG_ENDIAN)
801 u16 tx_low_seq_cnt;
802 struct fcoe_s_stat_ctx tx_s_stat;
803 u8 tx_seq_id;
804#elif defined(__LITTLE_ENDIAN)
805 u8 tx_seq_id;
806 struct fcoe_s_stat_ctx tx_s_stat;
807 u16 tx_low_seq_cnt;
808#endif
809 u32 common_flags;
810#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID (0xFFFFFF<<0)
811#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT 0
812#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_VALID (0x1<<24)
813#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_VALID_SHIFT 24
814#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_SEQ_INIT (0x1<<25)
815#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_SEQ_INIT_SHIFT 25
816#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_PEND_XFER (0x1<<26)
817#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_PEND_XFER_SHIFT 26
818#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_PEND_CONF (0x1<<27)
819#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_PEND_CONF_SHIFT 27
820#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME (0x1<<28)
821#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME_SHIFT 28
822#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_RSRV (0x7<<29)
823#define FCOE_TASK_CTX_ENTRY_TX_RX_CMN_RSRV_SHIFT 29
824};
825
826struct fcoe_task_ctx_entry_rxwr_txrd {
827#if defined(__BIG_ENDIAN)
828 u16 rx_id;
829 u16 rx_flags;
830#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE (0xF<<0)
831#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE_SHIFT 0
832#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE (0x7<<4)
833#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE_SHIFT 4
834#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_CONF_REQ (0x1<<7)
835#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_CONF_REQ_SHIFT 7
836#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_MISS_FRAME (0x1<<8)
837#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_MISS_FRAME_SHIFT 8
838#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RESERVED0 (0x7F<<9)
839#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RESERVED0_SHIFT 9
840#elif defined(__LITTLE_ENDIAN)
841 u16 rx_flags;
842#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE (0xF<<0)
843#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE_SHIFT 0
844#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE (0x7<<4)
845#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE_SHIFT 4
846#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_CONF_REQ (0x1<<7)
847#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_CONF_REQ_SHIFT 7
848#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_MISS_FRAME (0x1<<8)
849#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_MISS_FRAME_SHIFT 8
850#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RESERVED0 (0x7F<<9)
851#define FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RESERVED0_SHIFT 9
852 u16 rx_id;
853#endif
854};
855
856struct fcoe_task_ctx_entry_rx_only {
857 struct fcoe_seq_ctx seq_ctx;
858 struct fcoe_seq_ctx ooo_seq_ctx;
859 u32 rsrv3;
860 union fcoe_sgl_ctx sgl_ctx;
861};
862
863struct fcoe_task_ctx_entry {
864 struct fcoe_task_ctx_entry_tx_only tx_wr_only;
865 struct fcoe_task_ctx_entry_txwr_rxrd tx_wr_rx_rd;
866 struct fcoe_task_ctx_entry_tx_rx_cmn cmn;
867 struct fcoe_task_ctx_entry_rxwr_txrd rx_wr_tx_rd;
868 struct fcoe_task_ctx_entry_rx_only rx_wr_only;
869 u32 reserved[4];
870};
871
872
873/*
874 * FCoE XFRQ element
875 */
876struct fcoe_xfrqe {
877 u16 wqe;
878#define FCOE_XFRQE_TASK_ID (0x7FFF<<0)
879#define FCOE_XFRQE_TASK_ID_SHIFT 0
880#define FCOE_XFRQE_TOGGLE_BIT (0x1<<15)
881#define FCOE_XFRQE_TOGGLE_BIT_SHIFT 15
882};
883
884
885/*
886 * FCoE CONFQ element
887 */
888struct fcoe_confqe {
889#if defined(__BIG_ENDIAN)
890 u16 rx_id;
891 u16 ox_id;
892#elif defined(__LITTLE_ENDIAN)
893 u16 ox_id;
894 u16 rx_id;
895#endif
896 u32 param;
897};
898
899
900/*
901 * FCoE conection data base
902 */
903struct fcoe_conn_db {
904#if defined(__BIG_ENDIAN)
905 u16 rsrv0;
906 u16 rq_prod;
907#elif defined(__LITTLE_ENDIAN)
908 u16 rq_prod;
909 u16 rsrv0;
910#endif
911 u32 rsrv1;
912 struct regpair cq_arm;
913};
914
915
916/*
917 * FCoE CQ element
918 */
919struct fcoe_cqe {
920 u16 wqe;
921#define FCOE_CQE_CQE_INFO (0x3FFF<<0)
922#define FCOE_CQE_CQE_INFO_SHIFT 0
923#define FCOE_CQE_CQE_TYPE (0x1<<14)
924#define FCOE_CQE_CQE_TYPE_SHIFT 14
925#define FCOE_CQE_TOGGLE_BIT (0x1<<15)
926#define FCOE_CQE_TOGGLE_BIT_SHIFT 15
927};
928
929
930/*
931 * FCoE error/warning resporting entry
932 */
933struct fcoe_err_report_entry {
934 u32 err_warn_bitmap_lo;
935 u32 err_warn_bitmap_hi;
936 u32 tx_buf_off;
937 u32 rx_buf_off;
938 struct fcoe_fc_hdr fc_hdr;
939};
940
941
942/*
943 * FCoE hash table entry (32 bytes)
944 */
945struct fcoe_hash_table_entry {
946#if defined(__BIG_ENDIAN)
947 u8 d_id_0;
948 u8 s_id_2;
949 u8 s_id_1;
950 u8 s_id_0;
951#elif defined(__LITTLE_ENDIAN)
952 u8 s_id_0;
953 u8 s_id_1;
954 u8 s_id_2;
955 u8 d_id_0;
956#endif
957#if defined(__BIG_ENDIAN)
958 u16 dst_mac_addr_hi;
959 u8 d_id_2;
960 u8 d_id_1;
961#elif defined(__LITTLE_ENDIAN)
962 u8 d_id_1;
963 u8 d_id_2;
964 u16 dst_mac_addr_hi;
965#endif
966 u32 dst_mac_addr_lo;
967#if defined(__BIG_ENDIAN)
968 u16 vlan_id;
969 u16 src_mac_addr_hi;
970#elif defined(__LITTLE_ENDIAN)
971 u16 src_mac_addr_hi;
972 u16 vlan_id;
973#endif
974 u32 src_mac_addr_lo;
975#if defined(__BIG_ENDIAN)
976 u16 reserved1;
977 u8 reserved0;
978 u8 vlan_flag;
979#elif defined(__LITTLE_ENDIAN)
980 u8 vlan_flag;
981 u8 reserved0;
982 u16 reserved1;
983#endif
984 u32 reserved2;
985 u32 field_id;
986#define FCOE_HASH_TABLE_ENTRY_CID (0xFFFFFF<<0)
987#define FCOE_HASH_TABLE_ENTRY_CID_SHIFT 0
988#define FCOE_HASH_TABLE_ENTRY_RESERVED3 (0x7F<<24)
989#define FCOE_HASH_TABLE_ENTRY_RESERVED3_SHIFT 24
990#define FCOE_HASH_TABLE_ENTRY_VALID (0x1<<31)
991#define FCOE_HASH_TABLE_ENTRY_VALID_SHIFT 31
992};
993
994/*
995 * FCoE pending work request CQE
996 */
997struct fcoe_pend_wq_cqe {
998 u16 wqe;
999#define FCOE_PEND_WQ_CQE_TASK_ID (0x3FFF<<0)
1000#define FCOE_PEND_WQ_CQE_TASK_ID_SHIFT 0
1001#define FCOE_PEND_WQ_CQE_CQE_TYPE (0x1<<14)
1002#define FCOE_PEND_WQ_CQE_CQE_TYPE_SHIFT 14
1003#define FCOE_PEND_WQ_CQE_TOGGLE_BIT (0x1<<15)
1004#define FCOE_PEND_WQ_CQE_TOGGLE_BIT_SHIFT 15
1005};
1006
1007
1008/*
1009 * FCoE RX statistics parameters section#0
1010 */
1011struct fcoe_rx_stat_params_section0 {
1012 u32 fcoe_ver_cnt;
1013 u32 fcoe_rx_pkt_cnt;
1014 u32 fcoe_rx_byte_cnt;
1015 u32 fcoe_rx_drop_pkt_cnt;
1016};
1017
1018
1019/*
1020 * FCoE RX statistics parameters section#1
1021 */
1022struct fcoe_rx_stat_params_section1 {
1023 u32 fc_crc_cnt;
1024 u32 eofa_del_cnt;
1025 u32 miss_frame_cnt;
1026 u32 seq_timeout_cnt;
1027 u32 drop_seq_cnt;
1028 u32 fcoe_rx_drop_pkt_cnt;
1029 u32 fcp_rx_pkt_cnt;
1030 u32 reserved0;
1031};
1032
1033
1034/*
1035 * FCoE TX statistics parameters
1036 */
1037struct fcoe_tx_stat_params {
1038 u32 fcoe_tx_pkt_cnt;
1039 u32 fcoe_tx_byte_cnt;
1040 u32 fcp_tx_pkt_cnt;
1041 u32 reserved0;
1042};
1043
1044/*
1045 * FCoE statistics parameters
1046 */
1047struct fcoe_statistics_params {
1048 struct fcoe_tx_stat_params tx_stat;
1049 struct fcoe_rx_stat_params_section0 rx_stat0;
1050 struct fcoe_rx_stat_params_section1 rx_stat1;
1051};
1052
1053
1054/*
1055 * FCoE t2 hash table entry (64 bytes)
1056 */
1057struct fcoe_t2_hash_table_entry {
1058 struct fcoe_hash_table_entry data;
1059 struct regpair next;
1060 struct regpair reserved0[3];
1061};
1062
1063/*
1064 * FCoE unsolicited CQE
1065 */
1066struct fcoe_unsolicited_cqe {
1067 u16 wqe;
1068#define FCOE_UNSOLICITED_CQE_SUBTYPE (0x3<<0)
1069#define FCOE_UNSOLICITED_CQE_SUBTYPE_SHIFT 0
1070#define FCOE_UNSOLICITED_CQE_PKT_LEN (0xFFF<<2)
1071#define FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT 2
1072#define FCOE_UNSOLICITED_CQE_CQE_TYPE (0x1<<14)
1073#define FCOE_UNSOLICITED_CQE_CQE_TYPE_SHIFT 14
1074#define FCOE_UNSOLICITED_CQE_TOGGLE_BIT (0x1<<15)
1075#define FCOE_UNSOLICITED_CQE_TOGGLE_BIT_SHIFT 15
1076};
1077
1078
1079
1080#endif /* __57XX_FCOE_HSI_LINUX_LE__ */
diff --git a/drivers/scsi/bnx2fc/Kconfig b/drivers/scsi/bnx2fc/Kconfig
new file mode 100644
index 000000000000..6a38080e35ed
--- /dev/null
+++ b/drivers/scsi/bnx2fc/Kconfig
@@ -0,0 +1,11 @@
1config SCSI_BNX2X_FCOE
2 tristate "Broadcom NetXtreme II FCoE support"
3 depends on PCI
4 select NETDEVICES
5 select NETDEV_1000
6 select LIBFC
7 select LIBFCOE
8 select CNIC
9 ---help---
10 This driver supports FCoE offload for the Broadcom NetXtreme II
11 devices.
diff --git a/drivers/scsi/bnx2fc/Makefile b/drivers/scsi/bnx2fc/Makefile
new file mode 100644
index 000000000000..a92695a25176
--- /dev/null
+++ b/drivers/scsi/bnx2fc/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_SCSI_BNX2X_FCOE) += bnx2fc.o
2
3bnx2fc-y := bnx2fc_els.o bnx2fc_fcoe.o bnx2fc_hwi.o bnx2fc_io.o bnx2fc_tgt.o
diff --git a/drivers/scsi/bnx2fc/bnx2fc.h b/drivers/scsi/bnx2fc/bnx2fc.h
new file mode 100644
index 000000000000..df2fc09ba479
--- /dev/null
+++ b/drivers/scsi/bnx2fc/bnx2fc.h
@@ -0,0 +1,511 @@
1#ifndef _BNX2FC_H_
2#define _BNX2FC_H_
3/* bnx2fc.h: Broadcom NetXtreme II Linux FCoE offload driver.
4 *
5 * Copyright (c) 2008 - 2010 Broadcom Corporation
6 *
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.
10 *
11 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/kernel.h>
17#include <linux/skbuff.h>
18#include <linux/netdevice.h>
19#include <linux/etherdevice.h>
20#include <linux/if_ether.h>
21#include <linux/if_vlan.h>
22#include <linux/kthread.h>
23#include <linux/crc32.h>
24#include <linux/cpu.h>
25#include <linux/types.h>
26#include <linux/list.h>
27#include <linux/delay.h>
28#include <linux/timer.h>
29#include <linux/errno.h>
30#include <linux/pci.h>
31#include <linux/init.h>
32#include <linux/dma-mapping.h>
33#include <linux/workqueue.h>
34#include <linux/mutex.h>
35#include <linux/spinlock.h>
36#include <linux/bitops.h>
37#include <linux/log2.h>
38#include <linux/interrupt.h>
39#include <linux/sched.h>
40#include <linux/io.h>
41
42#include <scsi/scsi.h>
43#include <scsi/scsi_host.h>
44#include <scsi/scsi_device.h>
45#include <scsi/scsi_cmnd.h>
46#include <scsi/scsi_eh.h>
47#include <scsi/scsi_tcq.h>
48#include <scsi/libfc.h>
49#include <scsi/libfcoe.h>
50#include <scsi/fc_encode.h>
51#include <scsi/scsi_transport.h>
52#include <scsi/scsi_transport_fc.h>
53#include <scsi/fc/fc_fip.h>
54#include <scsi/fc/fc_fc2.h>
55#include <scsi/fc_frame.h>
56#include <scsi/fc/fc_fcoe.h>
57#include <scsi/fc/fc_fcp.h>
58
59#include "57xx_hsi_bnx2fc.h"
60#include "bnx2fc_debug.h"
61#include "../../net/cnic_if.h"
62#include "bnx2fc_constants.h"
63
64#define BNX2FC_NAME "bnx2fc"
65#define BNX2FC_VERSION "1.0.0"
66
67#define PFX "bnx2fc: "
68
69#define BNX2X_DOORBELL_PCI_BAR 2
70
71#define BNX2FC_MAX_BD_LEN 0xffff
72#define BNX2FC_BD_SPLIT_SZ 0x8000
73#define BNX2FC_MAX_BDS_PER_CMD 256
74
75#define BNX2FC_SQ_WQES_MAX 256
76
77#define BNX2FC_SCSI_MAX_SQES ((3 * BNX2FC_SQ_WQES_MAX) / 8)
78#define BNX2FC_TM_MAX_SQES ((BNX2FC_SQ_WQES_MAX) / 2)
79#define BNX2FC_ELS_MAX_SQES (BNX2FC_TM_MAX_SQES - 1)
80
81#define BNX2FC_RQ_WQES_MAX 16
82#define BNX2FC_CQ_WQES_MAX (BNX2FC_SQ_WQES_MAX + BNX2FC_RQ_WQES_MAX)
83
84#define BNX2FC_NUM_MAX_SESS 128
85#define BNX2FC_NUM_MAX_SESS_LOG (ilog2(BNX2FC_NUM_MAX_SESS))
86
87#define BNX2FC_MAX_OUTSTANDING_CMNDS 4096
88#define BNX2FC_MIN_PAYLOAD 256
89#define BNX2FC_MAX_PAYLOAD 2048
90
91#define BNX2FC_RQ_BUF_SZ 256
92#define BNX2FC_RQ_BUF_LOG_SZ (ilog2(BNX2FC_RQ_BUF_SZ))
93
94#define BNX2FC_SQ_WQE_SIZE (sizeof(struct fcoe_sqe))
95#define BNX2FC_CQ_WQE_SIZE (sizeof(struct fcoe_cqe))
96#define BNX2FC_RQ_WQE_SIZE (BNX2FC_RQ_BUF_SZ)
97#define BNX2FC_XFERQ_WQE_SIZE (sizeof(struct fcoe_xfrqe))
98#define BNX2FC_CONFQ_WQE_SIZE (sizeof(struct fcoe_confqe))
99#define BNX2FC_5771X_DB_PAGE_SIZE 128
100
101#define BNX2FC_MAX_TASKS BNX2FC_MAX_OUTSTANDING_CMNDS
102#define BNX2FC_TASK_SIZE 128
103#define BNX2FC_TASKS_PER_PAGE (PAGE_SIZE/BNX2FC_TASK_SIZE)
104#define BNX2FC_TASK_CTX_ARR_SZ (BNX2FC_MAX_TASKS/BNX2FC_TASKS_PER_PAGE)
105
106#define BNX2FC_MAX_ROWS_IN_HASH_TBL 8
107#define BNX2FC_HASH_TBL_CHUNK_SIZE (16 * 1024)
108
109#define BNX2FC_MAX_SEQS 255
110
111#define BNX2FC_READ (1 << 1)
112#define BNX2FC_WRITE (1 << 0)
113
114#define BNX2FC_MIN_XID 0
115#define BNX2FC_MAX_XID (BNX2FC_MAX_OUTSTANDING_CMNDS - 1)
116#define FCOE_MIN_XID (BNX2FC_MAX_OUTSTANDING_CMNDS)
117#define FCOE_MAX_XID \
118 (BNX2FC_MAX_OUTSTANDING_CMNDS + (nr_cpu_ids * 256))
119#define BNX2FC_MAX_LUN 0xFFFF
120#define BNX2FC_MAX_FCP_TGT 256
121#define BNX2FC_MAX_CMD_LEN 16
122
123#define BNX2FC_TM_TIMEOUT 60 /* secs */
124#define BNX2FC_IO_TIMEOUT 20000UL /* msecs */
125
126#define BNX2FC_WAIT_CNT 120
127#define BNX2FC_FW_TIMEOUT (3 * HZ)
128
129#define PORT_MAX 2
130
131#define CMD_SCSI_STATUS(Cmnd) ((Cmnd)->SCp.Status)
132
133/* FC FCP Status */
134#define FC_GOOD 0
135
136#define BNX2FC_RNID_HBA 0x7
137
138/* bnx2fc driver uses only one instance of fcoe_percpu_s */
139extern struct fcoe_percpu_s bnx2fc_global;
140
141extern struct workqueue_struct *bnx2fc_wq;
142
143struct bnx2fc_percpu_s {
144 struct task_struct *iothread;
145 struct list_head work_list;
146 spinlock_t fp_work_lock;
147};
148
149
150struct bnx2fc_hba {
151 struct list_head link;
152 struct cnic_dev *cnic;
153 struct pci_dev *pcidev;
154 struct net_device *netdev;
155 struct net_device *phys_dev;
156 unsigned long reg_with_cnic;
157 #define BNX2FC_CNIC_REGISTERED 1
158 struct packet_type fcoe_packet_type;
159 struct packet_type fip_packet_type;
160 struct bnx2fc_cmd_mgr *cmd_mgr;
161 struct workqueue_struct *timer_work_queue;
162 struct kref kref;
163 spinlock_t hba_lock;
164 struct mutex hba_mutex;
165 unsigned long adapter_state;
166 #define ADAPTER_STATE_UP 0
167 #define ADAPTER_STATE_GOING_DOWN 1
168 #define ADAPTER_STATE_LINK_DOWN 2
169 #define ADAPTER_STATE_READY 3
170 u32 flags;
171 unsigned long init_done;
172 #define BNX2FC_FW_INIT_DONE 0
173 #define BNX2FC_CTLR_INIT_DONE 1
174 #define BNX2FC_CREATE_DONE 2
175 struct fcoe_ctlr ctlr;
176 u8 vlan_enabled;
177 int vlan_id;
178 u32 next_conn_id;
179 struct fcoe_task_ctx_entry **task_ctx;
180 dma_addr_t *task_ctx_dma;
181 struct regpair *task_ctx_bd_tbl;
182 dma_addr_t task_ctx_bd_dma;
183
184 int hash_tbl_segment_count;
185 void **hash_tbl_segments;
186 void *hash_tbl_pbl;
187 dma_addr_t hash_tbl_pbl_dma;
188 struct fcoe_t2_hash_table_entry *t2_hash_tbl;
189 dma_addr_t t2_hash_tbl_dma;
190 char *t2_hash_tbl_ptr;
191 dma_addr_t t2_hash_tbl_ptr_dma;
192
193 char *dummy_buffer;
194 dma_addr_t dummy_buf_dma;
195
196 struct fcoe_statistics_params *stats_buffer;
197 dma_addr_t stats_buf_dma;
198
199 /*
200 * PCI related info.
201 */
202 u16 pci_did;
203 u16 pci_vid;
204 u16 pci_sdid;
205 u16 pci_svid;
206 u16 pci_func;
207 u16 pci_devno;
208
209 struct task_struct *l2_thread;
210
211 /* linkdown handling */
212 wait_queue_head_t shutdown_wait;
213 int wait_for_link_down;
214
215 /*destroy handling */
216 struct timer_list destroy_timer;
217 wait_queue_head_t destroy_wait;
218
219 /* Active list of offloaded sessions */
220 struct bnx2fc_rport *tgt_ofld_list[BNX2FC_NUM_MAX_SESS];
221 int num_ofld_sess;
222
223 /* statistics */
224 struct completion stat_req_done;
225};
226
227#define bnx2fc_from_ctlr(fip) container_of(fip, struct bnx2fc_hba, ctlr)
228
229struct bnx2fc_cmd_mgr {
230 struct bnx2fc_hba *hba;
231 u16 next_idx;
232 struct list_head *free_list;
233 spinlock_t *free_list_lock;
234 struct io_bdt **io_bdt_pool;
235 struct bnx2fc_cmd **cmds;
236};
237
238struct bnx2fc_rport {
239 struct fcoe_port *port;
240 struct fc_rport *rport;
241 struct fc_rport_priv *rdata;
242 void __iomem *ctx_base;
243#define DPM_TRIGER_TYPE 0x40
244 u32 fcoe_conn_id;
245 u32 context_id;
246 u32 sid;
247
248 unsigned long flags;
249#define BNX2FC_FLAG_SESSION_READY 0x1
250#define BNX2FC_FLAG_OFFLOADED 0x2
251#define BNX2FC_FLAG_DISABLED 0x3
252#define BNX2FC_FLAG_DESTROYED 0x4
253#define BNX2FC_FLAG_OFLD_REQ_CMPL 0x5
254#define BNX2FC_FLAG_DESTROY_CMPL 0x6
255#define BNX2FC_FLAG_CTX_ALLOC_FAILURE 0x7
256#define BNX2FC_FLAG_UPLD_REQ_COMPL 0x8
257#define BNX2FC_FLAG_EXPL_LOGO 0x9
258
259 u32 max_sqes;
260 u32 max_rqes;
261 u32 max_cqes;
262
263 struct fcoe_sqe *sq;
264 dma_addr_t sq_dma;
265 u16 sq_prod_idx;
266 u8 sq_curr_toggle_bit;
267 u32 sq_mem_size;
268
269 struct fcoe_cqe *cq;
270 dma_addr_t cq_dma;
271 u32 cq_cons_idx;
272 u8 cq_curr_toggle_bit;
273 u32 cq_mem_size;
274
275 void *rq;
276 dma_addr_t rq_dma;
277 u32 rq_prod_idx;
278 u32 rq_cons_idx;
279 u32 rq_mem_size;
280
281 void *rq_pbl;
282 dma_addr_t rq_pbl_dma;
283 u32 rq_pbl_size;
284
285 struct fcoe_xfrqe *xferq;
286 dma_addr_t xferq_dma;
287 u32 xferq_mem_size;
288
289 struct fcoe_confqe *confq;
290 dma_addr_t confq_dma;
291 u32 confq_mem_size;
292
293 void *confq_pbl;
294 dma_addr_t confq_pbl_dma;
295 u32 confq_pbl_size;
296
297 struct fcoe_conn_db *conn_db;
298 dma_addr_t conn_db_dma;
299 u32 conn_db_mem_size;
300
301 struct fcoe_sqe *lcq;
302 dma_addr_t lcq_dma;
303 u32 lcq_mem_size;
304
305 void *ofld_req[4];
306 dma_addr_t ofld_req_dma[4];
307 void *enbl_req;
308 dma_addr_t enbl_req_dma;
309
310 spinlock_t tgt_lock;
311 spinlock_t cq_lock;
312 atomic_t num_active_ios;
313 u32 flush_in_prog;
314 unsigned long work_time_slice;
315 unsigned long timestamp;
316 struct list_head free_task_list;
317 struct bnx2fc_cmd *pending_queue[BNX2FC_SQ_WQES_MAX+1];
318 atomic_t pi;
319 atomic_t ci;
320 struct list_head active_cmd_queue;
321 struct list_head els_queue;
322 struct list_head io_retire_queue;
323 struct list_head active_tm_queue;
324
325 struct timer_list ofld_timer;
326 wait_queue_head_t ofld_wait;
327
328 struct timer_list upld_timer;
329 wait_queue_head_t upld_wait;
330};
331
332struct bnx2fc_mp_req {
333 u8 tm_flags;
334
335 u32 req_len;
336 void *req_buf;
337 dma_addr_t req_buf_dma;
338 struct fcoe_bd_ctx *mp_req_bd;
339 dma_addr_t mp_req_bd_dma;
340 struct fc_frame_header req_fc_hdr;
341
342 u32 resp_len;
343 void *resp_buf;
344 dma_addr_t resp_buf_dma;
345 struct fcoe_bd_ctx *mp_resp_bd;
346 dma_addr_t mp_resp_bd_dma;
347 struct fc_frame_header resp_fc_hdr;
348};
349
350struct bnx2fc_els_cb_arg {
351 struct bnx2fc_cmd *aborted_io_req;
352 struct bnx2fc_cmd *io_req;
353 u16 l2_oxid;
354};
355
356/* bnx2fc command structure */
357struct bnx2fc_cmd {
358 struct list_head link;
359 u8 on_active_queue;
360 u8 on_tmf_queue;
361 u8 cmd_type;
362#define BNX2FC_SCSI_CMD 1
363#define BNX2FC_TASK_MGMT_CMD 2
364#define BNX2FC_ABTS 3
365#define BNX2FC_ELS 4
366#define BNX2FC_CLEANUP 5
367 u8 io_req_flags;
368 struct kref refcount;
369 struct fcoe_port *port;
370 struct bnx2fc_rport *tgt;
371 struct scsi_cmnd *sc_cmd;
372 struct bnx2fc_cmd_mgr *cmd_mgr;
373 struct bnx2fc_mp_req mp_req;
374 void (*cb_func)(struct bnx2fc_els_cb_arg *cb_arg);
375 struct bnx2fc_els_cb_arg *cb_arg;
376 struct delayed_work timeout_work; /* timer for ULP timeouts */
377 struct completion tm_done;
378 int wait_for_comp;
379 u16 xid;
380 struct fcoe_task_ctx_entry *task;
381 struct io_bdt *bd_tbl;
382 struct fcp_rsp *rsp;
383 size_t data_xfer_len;
384 unsigned long req_flags;
385#define BNX2FC_FLAG_ISSUE_RRQ 0x1
386#define BNX2FC_FLAG_ISSUE_ABTS 0x2
387#define BNX2FC_FLAG_ABTS_DONE 0x3
388#define BNX2FC_FLAG_TM_COMPL 0x4
389#define BNX2FC_FLAG_TM_TIMEOUT 0x5
390#define BNX2FC_FLAG_IO_CLEANUP 0x6
391#define BNX2FC_FLAG_RETIRE_OXID 0x7
392#define BNX2FC_FLAG_EH_ABORT 0x8
393#define BNX2FC_FLAG_IO_COMPL 0x9
394#define BNX2FC_FLAG_ELS_DONE 0xa
395#define BNX2FC_FLAG_ELS_TIMEOUT 0xb
396 u32 fcp_resid;
397 u32 fcp_rsp_len;
398 u32 fcp_sns_len;
399 u8 cdb_status; /* SCSI IO status */
400 u8 fcp_status; /* FCP IO status */
401 u8 fcp_rsp_code;
402 u8 scsi_comp_flags;
403};
404
405struct io_bdt {
406 struct bnx2fc_cmd *io_req;
407 struct fcoe_bd_ctx *bd_tbl;
408 dma_addr_t bd_tbl_dma;
409 u16 bd_valid;
410};
411
412struct bnx2fc_work {
413 struct list_head list;
414 struct bnx2fc_rport *tgt;
415 u16 wqe;
416};
417struct bnx2fc_unsol_els {
418 struct fc_lport *lport;
419 struct fc_frame *fp;
420 struct work_struct unsol_els_work;
421};
422
423
424
425struct bnx2fc_cmd *bnx2fc_elstm_alloc(struct bnx2fc_rport *tgt, int type);
426void bnx2fc_cmd_release(struct kref *ref);
427int bnx2fc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc_cmd);
428int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba);
429int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba);
430int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
431 struct bnx2fc_rport *tgt);
432int bnx2fc_send_session_disable_req(struct fcoe_port *port,
433 struct bnx2fc_rport *tgt);
434int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
435 struct bnx2fc_rport *tgt);
436int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt);
437void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
438 u32 num_cqe);
439int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba);
440void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba);
441int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba);
442void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba);
443struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba,
444 u16 min_xid, u16 max_xid);
445void bnx2fc_cmd_mgr_free(struct bnx2fc_cmd_mgr *cmgr);
446void bnx2fc_get_link_state(struct bnx2fc_hba *hba);
447char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items);
448void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items);
449int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen);
450int bnx2fc_send_rrq(struct bnx2fc_cmd *aborted_io_req);
451int bnx2fc_send_adisc(struct bnx2fc_rport *tgt, struct fc_frame *fp);
452int bnx2fc_send_logo(struct bnx2fc_rport *tgt, struct fc_frame *fp);
453int bnx2fc_send_rls(struct bnx2fc_rport *tgt, struct fc_frame *fp);
454int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req);
455int bnx2fc_initiate_abts(struct bnx2fc_cmd *io_req);
456void bnx2fc_cmd_timer_set(struct bnx2fc_cmd *io_req,
457 unsigned int timer_msec);
458int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req);
459void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
460 struct fcoe_task_ctx_entry *task,
461 u16 orig_xid);
462void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
463 struct fcoe_task_ctx_entry *task);
464void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
465 struct fcoe_task_ctx_entry *task);
466void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid);
467void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt);
468int bnx2fc_eh_abort(struct scsi_cmnd *sc_cmd);
469int bnx2fc_eh_host_reset(struct scsi_cmnd *sc_cmd);
470int bnx2fc_eh_target_reset(struct scsi_cmnd *sc_cmd);
471int bnx2fc_eh_device_reset(struct scsi_cmnd *sc_cmd);
472void bnx2fc_rport_event_handler(struct fc_lport *lport,
473 struct fc_rport_priv *rport,
474 enum fc_rport_event event);
475void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
476 struct fcoe_task_ctx_entry *task,
477 u8 num_rq);
478void bnx2fc_process_cleanup_compl(struct bnx2fc_cmd *io_req,
479 struct fcoe_task_ctx_entry *task,
480 u8 num_rq);
481void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req,
482 struct fcoe_task_ctx_entry *task,
483 u8 num_rq);
484void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
485 struct fcoe_task_ctx_entry *task,
486 u8 num_rq);
487void bnx2fc_process_els_compl(struct bnx2fc_cmd *els_req,
488 struct fcoe_task_ctx_entry *task,
489 u8 num_rq);
490void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
491 struct fcp_cmnd *fcp_cmnd);
492
493
494
495void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt);
496struct fc_seq *bnx2fc_elsct_send(struct fc_lport *lport, u32 did,
497 struct fc_frame *fp, unsigned int op,
498 void (*resp)(struct fc_seq *,
499 struct fc_frame *,
500 void *),
501 void *arg, u32 timeout);
502int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt);
503void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe);
504struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port,
505 u32 port_id);
506void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
507 unsigned char *buf,
508 u32 frame_len, u16 l2_oxid);
509int bnx2fc_send_stat_req(struct bnx2fc_hba *hba);
510
511#endif
diff --git a/drivers/scsi/bnx2fc/bnx2fc_constants.h b/drivers/scsi/bnx2fc/bnx2fc_constants.h
new file mode 100644
index 000000000000..fe7769173c43
--- /dev/null
+++ b/drivers/scsi/bnx2fc/bnx2fc_constants.h
@@ -0,0 +1,206 @@
1#ifndef __BNX2FC_CONSTANTS_H_
2#define __BNX2FC_CONSTANTS_H_
3
4/**
5 * This file defines HSI constants for the FCoE flows
6 */
7
8/* KWQ/KCQ FCoE layer code */
9#define FCOE_KWQE_LAYER_CODE (7)
10
11/* KWQ (kernel work queue) request op codes */
12#define FCOE_KWQE_OPCODE_INIT1 (0)
13#define FCOE_KWQE_OPCODE_INIT2 (1)
14#define FCOE_KWQE_OPCODE_INIT3 (2)
15#define FCOE_KWQE_OPCODE_OFFLOAD_CONN1 (3)
16#define FCOE_KWQE_OPCODE_OFFLOAD_CONN2 (4)
17#define FCOE_KWQE_OPCODE_OFFLOAD_CONN3 (5)
18#define FCOE_KWQE_OPCODE_OFFLOAD_CONN4 (6)
19#define FCOE_KWQE_OPCODE_ENABLE_CONN (7)
20#define FCOE_KWQE_OPCODE_DISABLE_CONN (8)
21#define FCOE_KWQE_OPCODE_DESTROY_CONN (9)
22#define FCOE_KWQE_OPCODE_DESTROY (10)
23#define FCOE_KWQE_OPCODE_STAT (11)
24
25/* KCQ (kernel completion queue) response op codes */
26#define FCOE_KCQE_OPCODE_INIT_FUNC (0x10)
27#define FCOE_KCQE_OPCODE_DESTROY_FUNC (0x11)
28#define FCOE_KCQE_OPCODE_STAT_FUNC (0x12)
29#define FCOE_KCQE_OPCODE_OFFLOAD_CONN (0x15)
30#define FCOE_KCQE_OPCODE_ENABLE_CONN (0x16)
31#define FCOE_KCQE_OPCODE_DISABLE_CONN (0x17)
32#define FCOE_KCQE_OPCODE_DESTROY_CONN (0x18)
33#define FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION (0x20)
34#define FCOE_KCQE_OPCODE_FCOE_ERROR (0x21)
35
36/* KCQ (kernel completion queue) completion status */
37#define FCOE_KCQE_COMPLETION_STATUS_SUCCESS (0x0)
38#define FCOE_KCQE_COMPLETION_STATUS_ERROR (0x1)
39#define FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE (0x2)
40#define FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE (0x3)
41#define FCOE_KCQE_COMPLETION_STATUS_CTX_FREE_FAILURE (0x4)
42#define FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR (0x5)
43
44/* Unsolicited CQE type */
45#define FCOE_UNSOLICITED_FRAME_CQE_TYPE 0
46#define FCOE_ERROR_DETECTION_CQE_TYPE 1
47#define FCOE_WARNING_DETECTION_CQE_TYPE 2
48
49/* Task context constants */
50/* After driver has initialize the task in case timer services required */
51#define FCOE_TASK_TX_STATE_INIT 0
52/* In case timer services are required then shall be updated by Xstorm after
53 * start processing the task. In case no timer facilities are required then the
54 * driver would initialize the state to this value */
55#define FCOE_TASK_TX_STATE_NORMAL 1
56/* Task is under abort procedure. Updated in order to stop processing of
57 * pending WQEs on this task */
58#define FCOE_TASK_TX_STATE_ABORT 2
59/* For E_D_T_TOV timer expiration in Xstorm (Class 2 only) */
60#define FCOE_TASK_TX_STATE_ERROR 3
61/* For REC_TOV timer expiration indication received from Xstorm */
62#define FCOE_TASK_TX_STATE_WARNING 4
63/* For completed unsolicited task */
64#define FCOE_TASK_TX_STATE_UNSOLICITED_COMPLETED 5
65/* For exchange cleanup request task */
66#define FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP 6
67/* For sequence cleanup request task */
68#define FCOE_TASK_TX_STATE_SEQUENCE_CLEANUP 7
69/* Mark task as aborted and indicate that ABTS was not transmitted */
70#define FCOE_TASK_TX_STATE_BEFORE_ABTS_TX 8
71/* Mark task as aborted and indicate that ABTS was transmitted */
72#define FCOE_TASK_TX_STATE_AFTER_ABTS_TX 9
73/* For completion the ABTS task. */
74#define FCOE_TASK_TX_STATE_ABTS_TX_COMPLETED 10
75/* Mark task as aborted and indicate that Exchange cleanup was not transmitted
76 */
77#define FCOE_TASK_TX_STATE_BEFORE_EXCHANGE_CLEANUP_TX 11
78/* Mark task as aborted and indicate that Exchange cleanup was transmitted */
79#define FCOE_TASK_TX_STATE_AFTER_EXCHANGE_CLEANUP_TX 12
80
81#define FCOE_TASK_RX_STATE_NORMAL 0
82#define FCOE_TASK_RX_STATE_COMPLETED 1
83/* Obsolete: Intermediate completion (middle path with local completion) */
84#define FCOE_TASK_RX_STATE_INTER_COMP 2
85/* For REC_TOV timer expiration indication received from Xstorm */
86#define FCOE_TASK_RX_STATE_WARNING 3
87/* For E_D_T_TOV timer expiration in Ustorm */
88#define FCOE_TASK_RX_STATE_ERROR 4
89/* ABTS ACC arrived wait for local completion to finally complete the task. */
90#define FCOE_TASK_RX_STATE_ABTS_ACC_ARRIVED 5
91/* local completion arrived wait for ABTS ACC to finally complete the task. */
92#define FCOE_TASK_RX_STATE_ABTS_LOCAL_COMP_ARRIVED 6
93/* Special completion indication in case of task was aborted. */
94#define FCOE_TASK_RX_STATE_ABTS_COMPLETED 7
95/* Special completion indication in case of task was cleaned. */
96#define FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED 8
97/* Special completion indication (in task requested the exchange cleanup) in
98 * case cleaned task is in non-valid. */
99#define FCOE_TASK_RX_STATE_ABORT_CLEANUP_COMPLETED 9
100/* Special completion indication (in task requested the sequence cleanup) in
101 * case cleaned task was already returned to normal. */
102#define FCOE_TASK_RX_STATE_IGNORED_SEQUENCE_CLEANUP 10
103/* Exchange cleanup arrived wait until xfer will be handled to finally
104 * complete the task. */
105#define FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_ARRIVED 11
106/* Xfer handled, wait for exchange cleanup to finally complete the task. */
107#define FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_HANDLED_XFER 12
108
109#define FCOE_TASK_TYPE_WRITE 0
110#define FCOE_TASK_TYPE_READ 1
111#define FCOE_TASK_TYPE_MIDPATH 2
112#define FCOE_TASK_TYPE_UNSOLICITED 3
113#define FCOE_TASK_TYPE_ABTS 4
114#define FCOE_TASK_TYPE_EXCHANGE_CLEANUP 5
115#define FCOE_TASK_TYPE_SEQUENCE_CLEANUP 6
116
117#define FCOE_TASK_DEV_TYPE_DISK 0
118#define FCOE_TASK_DEV_TYPE_TAPE 1
119
120#define FCOE_TASK_CLASS_TYPE_3 0
121#define FCOE_TASK_CLASS_TYPE_2 1
122
123/* Everest FCoE connection type */
124#define B577XX_FCOE_CONNECTION_TYPE 4
125
126/* Error codes for Error Reporting in fast path flows */
127/* XFER error codes */
128#define FCOE_ERROR_CODE_XFER_OOO_RO 0
129#define FCOE_ERROR_CODE_XFER_RO_NOT_ALIGNED 1
130#define FCOE_ERROR_CODE_XFER_NULL_BURST_LEN 2
131#define FCOE_ERROR_CODE_XFER_RO_GREATER_THAN_DATA2TRNS 3
132#define FCOE_ERROR_CODE_XFER_INVALID_PAYLOAD_SIZE 4
133#define FCOE_ERROR_CODE_XFER_TASK_TYPE_NOT_WRITE 5
134#define FCOE_ERROR_CODE_XFER_PEND_XFER_SET 6
135#define FCOE_ERROR_CODE_XFER_OPENED_SEQ 7
136#define FCOE_ERROR_CODE_XFER_FCTL 8
137
138/* FCP RSP error codes */
139#define FCOE_ERROR_CODE_FCP_RSP_BIDI_FLAGS_SET 9
140#define FCOE_ERROR_CODE_FCP_RSP_UNDERFLOW 10
141#define FCOE_ERROR_CODE_FCP_RSP_OVERFLOW 11
142#define FCOE_ERROR_CODE_FCP_RSP_INVALID_LENGTH_FIELD 12
143#define FCOE_ERROR_CODE_FCP_RSP_INVALID_SNS_FIELD 13
144#define FCOE_ERROR_CODE_FCP_RSP_INVALID_PAYLOAD_SIZE 14
145#define FCOE_ERROR_CODE_FCP_RSP_PEND_XFER_SET 15
146#define FCOE_ERROR_CODE_FCP_RSP_OPENED_SEQ 16
147#define FCOE_ERROR_CODE_FCP_RSP_FCTL 17
148#define FCOE_ERROR_CODE_FCP_RSP_LAST_SEQ_RESET 18
149#define FCOE_ERROR_CODE_FCP_RSP_CONF_REQ_NOT_SUPPORTED_YET 19
150
151/* FCP DATA error codes */
152#define FCOE_ERROR_CODE_DATA_OOO_RO 20
153#define FCOE_ERROR_CODE_DATA_EXCEEDS_DEFINED_MAX_FRAME_SIZE 21
154#define FCOE_ERROR_CODE_DATA_EXCEEDS_DATA2TRNS 22
155#define FCOE_ERROR_CODE_DATA_SOFI3_SEQ_ACTIVE_SET 23
156#define FCOE_ERROR_CODE_DATA_SOFN_SEQ_ACTIVE_RESET 24
157#define FCOE_ERROR_CODE_DATA_EOFN_END_SEQ_SET 25
158#define FCOE_ERROR_CODE_DATA_EOFT_END_SEQ_RESET 26
159#define FCOE_ERROR_CODE_DATA_TASK_TYPE_NOT_READ 27
160#define FCOE_ERROR_CODE_DATA_FCTL 28
161
162/* Middle path error codes */
163#define FCOE_ERROR_CODE_MIDPATH_TYPE_NOT_ELS 29
164#define FCOE_ERROR_CODE_MIDPATH_SOFI3_SEQ_ACTIVE_SET 30
165#define FCOE_ERROR_CODE_MIDPATH_SOFN_SEQ_ACTIVE_RESET 31
166#define FCOE_ERROR_CODE_MIDPATH_EOFN_END_SEQ_SET 32
167#define FCOE_ERROR_CODE_MIDPATH_EOFT_END_SEQ_RESET 33
168#define FCOE_ERROR_CODE_MIDPATH_ELS_REPLY_FCTL 34
169#define FCOE_ERROR_CODE_MIDPATH_INVALID_REPLY 35
170#define FCOE_ERROR_CODE_MIDPATH_ELS_REPLY_RCTL 36
171
172/* ABTS error codes */
173#define FCOE_ERROR_CODE_ABTS_REPLY_F_CTL 37
174#define FCOE_ERROR_CODE_ABTS_REPLY_DDF_RCTL_FIELD 38
175#define FCOE_ERROR_CODE_ABTS_REPLY_INVALID_BLS_RCTL 39
176#define FCOE_ERROR_CODE_ABTS_REPLY_INVALID_RCTL 40
177#define FCOE_ERROR_CODE_ABTS_REPLY_RCTL_GENERAL_MISMATCH 41
178
179/* Common error codes */
180#define FCOE_ERROR_CODE_COMMON_MIDDLE_FRAME_WITH_PAD 42
181#define FCOE_ERROR_CODE_COMMON_SEQ_INIT_IN_TCE 43
182#define FCOE_ERROR_CODE_COMMON_FC_HDR_RX_ID_MISMATCH 44
183#define FCOE_ERROR_CODE_COMMON_INCORRECT_SEQ_CNT 45
184#define FCOE_ERROR_CODE_COMMON_DATA_FC_HDR_FCP_TYPE_MISMATCH 46
185#define FCOE_ERROR_CODE_COMMON_DATA_NO_MORE_SGES 47
186#define FCOE_ERROR_CODE_COMMON_OPTIONAL_FC_HDR 48
187#define FCOE_ERROR_CODE_COMMON_READ_TCE_OX_ID_TOO_BIG 49
188#define FCOE_ERROR_CODE_COMMON_DATA_WAS_NOT_TRANSMITTED 50
189
190/* Unsolicited Rx error codes */
191#define FCOE_ERROR_CODE_UNSOLICITED_TYPE_NOT_ELS 51
192#define FCOE_ERROR_CODE_UNSOLICITED_TYPE_NOT_BLS 52
193#define FCOE_ERROR_CODE_UNSOLICITED_FCTL_ELS 53
194#define FCOE_ERROR_CODE_UNSOLICITED_FCTL_BLS 54
195#define FCOE_ERROR_CODE_UNSOLICITED_R_CTL 55
196
197#define FCOE_ERROR_CODE_RW_TASK_DDF_RCTL_INFO_FIELD 56
198#define FCOE_ERROR_CODE_RW_TASK_INVALID_RCTL 57
199#define FCOE_ERROR_CODE_RW_TASK_RCTL_GENERAL_MISMATCH 58
200
201/* Timer error codes */
202#define FCOE_ERROR_CODE_E_D_TOV_TIMER_EXPIRATION 60
203#define FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION 61
204
205
206#endif /* BNX2FC_CONSTANTS_H_ */
diff --git a/drivers/scsi/bnx2fc/bnx2fc_debug.h b/drivers/scsi/bnx2fc/bnx2fc_debug.h
new file mode 100644
index 000000000000..7f6aff68cc53
--- /dev/null
+++ b/drivers/scsi/bnx2fc/bnx2fc_debug.h
@@ -0,0 +1,70 @@
1#ifndef __BNX2FC_DEBUG__
2#define __BNX2FC_DEBUG__
3
4/* Log level bit mask */
5#define LOG_IO 0x01 /* scsi cmd error, cleanup */
6#define LOG_TGT 0x02 /* Session setup, cleanup, etc' */
7#define LOG_HBA 0x04 /* lport events, link, mtu, etc' */
8#define LOG_ELS 0x08 /* ELS logs */
9#define LOG_MISC 0x10 /* fcoe L2 frame related logs*/
10#define LOG_ALL 0xff /* LOG all messages */
11
12extern unsigned int bnx2fc_debug_level;
13
14#define BNX2FC_CHK_LOGGING(LEVEL, CMD) \
15 do { \
16 if (unlikely(bnx2fc_debug_level & LEVEL)) \
17 do { \
18 CMD; \
19 } while (0); \
20 } while (0)
21
22#define BNX2FC_ELS_DBG(fmt, arg...) \
23 BNX2FC_CHK_LOGGING(LOG_ELS, \
24 printk(KERN_ALERT PFX fmt, ##arg))
25
26#define BNX2FC_MISC_DBG(fmt, arg...) \
27 BNX2FC_CHK_LOGGING(LOG_MISC, \
28 printk(KERN_ALERT PFX fmt, ##arg))
29
30#define BNX2FC_IO_DBG(io_req, fmt, arg...) \
31 do { \
32 if (!io_req || !io_req->port || !io_req->port->lport || \
33 !io_req->port->lport->host) \
34 BNX2FC_CHK_LOGGING(LOG_IO, \
35 printk(KERN_ALERT PFX "NULL " fmt, ##arg)); \
36 else \
37 BNX2FC_CHK_LOGGING(LOG_IO, \
38 shost_printk(KERN_ALERT, \
39 (io_req)->port->lport->host, \
40 PFX "xid:0x%x " fmt, \
41 (io_req)->xid, ##arg)); \
42 } while (0)
43
44#define BNX2FC_TGT_DBG(tgt, fmt, arg...) \
45 do { \
46 if (!tgt || !tgt->port || !tgt->port->lport || \
47 !tgt->port->lport->host || !tgt->rport) \
48 BNX2FC_CHK_LOGGING(LOG_TGT, \
49 printk(KERN_ALERT PFX "NULL " fmt, ##arg)); \
50 else \
51 BNX2FC_CHK_LOGGING(LOG_TGT, \
52 shost_printk(KERN_ALERT, \
53 (tgt)->port->lport->host, \
54 PFX "port:%x " fmt, \
55 (tgt)->rport->port_id, ##arg)); \
56 } while (0)
57
58
59#define BNX2FC_HBA_DBG(lport, fmt, arg...) \
60 do { \
61 if (!lport || !lport->host) \
62 BNX2FC_CHK_LOGGING(LOG_HBA, \
63 printk(KERN_ALERT PFX "NULL " fmt, ##arg)); \
64 else \
65 BNX2FC_CHK_LOGGING(LOG_HBA, \
66 shost_printk(KERN_ALERT, lport->host, \
67 PFX fmt, ##arg)); \
68 } while (0)
69
70#endif
diff --git a/drivers/scsi/bnx2fc/bnx2fc_els.c b/drivers/scsi/bnx2fc/bnx2fc_els.c
new file mode 100644
index 000000000000..7a11a255157f
--- /dev/null
+++ b/drivers/scsi/bnx2fc/bnx2fc_els.c
@@ -0,0 +1,515 @@
1/*
2 * bnx2fc_els.c: Broadcom NetXtreme II Linux FCoE offload driver.
3 * This file contains helper routines that handle ELS requests
4 * and responses.
5 *
6 * Copyright (c) 2008 - 2010 Broadcom Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation.
11 *
12 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
13 */
14
15#include "bnx2fc.h"
16
17static void bnx2fc_logo_resp(struct fc_seq *seq, struct fc_frame *fp,
18 void *arg);
19static void bnx2fc_flogi_resp(struct fc_seq *seq, struct fc_frame *fp,
20 void *arg);
21static int bnx2fc_initiate_els(struct bnx2fc_rport *tgt, unsigned int op,
22 void *data, u32 data_len,
23 void (*cb_func)(struct bnx2fc_els_cb_arg *cb_arg),
24 struct bnx2fc_els_cb_arg *cb_arg, u32 timer_msec);
25
26static void bnx2fc_rrq_compl(struct bnx2fc_els_cb_arg *cb_arg)
27{
28 struct bnx2fc_cmd *orig_io_req;
29 struct bnx2fc_cmd *rrq_req;
30 int rc = 0;
31
32 BUG_ON(!cb_arg);
33 rrq_req = cb_arg->io_req;
34 orig_io_req = cb_arg->aborted_io_req;
35 BUG_ON(!orig_io_req);
36 BNX2FC_ELS_DBG("rrq_compl: orig xid = 0x%x, rrq_xid = 0x%x\n",
37 orig_io_req->xid, rrq_req->xid);
38
39 kref_put(&orig_io_req->refcount, bnx2fc_cmd_release);
40
41 if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &rrq_req->req_flags)) {
42 /*
43 * els req is timed out. cleanup the IO with FW and
44 * drop the completion. Remove from active_cmd_queue.
45 */
46 BNX2FC_ELS_DBG("rrq xid - 0x%x timed out, clean it up\n",
47 rrq_req->xid);
48
49 if (rrq_req->on_active_queue) {
50 list_del_init(&rrq_req->link);
51 rrq_req->on_active_queue = 0;
52 rc = bnx2fc_initiate_cleanup(rrq_req);
53 BUG_ON(rc);
54 }
55 }
56 kfree(cb_arg);
57}
58int bnx2fc_send_rrq(struct bnx2fc_cmd *aborted_io_req)
59{
60
61 struct fc_els_rrq rrq;
62 struct bnx2fc_rport *tgt = aborted_io_req->tgt;
63 struct fc_lport *lport = tgt->rdata->local_port;
64 struct bnx2fc_els_cb_arg *cb_arg = NULL;
65 u32 sid = tgt->sid;
66 u32 r_a_tov = lport->r_a_tov;
67 unsigned long start = jiffies;
68 int rc;
69
70 BNX2FC_ELS_DBG("Sending RRQ orig_xid = 0x%x\n",
71 aborted_io_req->xid);
72 memset(&rrq, 0, sizeof(rrq));
73
74 cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_NOIO);
75 if (!cb_arg) {
76 printk(KERN_ERR PFX "Unable to allocate cb_arg for RRQ\n");
77 rc = -ENOMEM;
78 goto rrq_err;
79 }
80
81 cb_arg->aborted_io_req = aborted_io_req;
82
83 rrq.rrq_cmd = ELS_RRQ;
84 hton24(rrq.rrq_s_id, sid);
85 rrq.rrq_ox_id = htons(aborted_io_req->xid);
86 rrq.rrq_rx_id = htons(aborted_io_req->task->rx_wr_tx_rd.rx_id);
87
88retry_rrq:
89 rc = bnx2fc_initiate_els(tgt, ELS_RRQ, &rrq, sizeof(rrq),
90 bnx2fc_rrq_compl, cb_arg,
91 r_a_tov);
92 if (rc == -ENOMEM) {
93 if (time_after(jiffies, start + (10 * HZ))) {
94 BNX2FC_ELS_DBG("rrq Failed\n");
95 rc = FAILED;
96 goto rrq_err;
97 }
98 msleep(20);
99 goto retry_rrq;
100 }
101rrq_err:
102 if (rc) {
103 BNX2FC_ELS_DBG("RRQ failed - release orig io req 0x%x\n",
104 aborted_io_req->xid);
105 kfree(cb_arg);
106 spin_lock_bh(&tgt->tgt_lock);
107 kref_put(&aborted_io_req->refcount, bnx2fc_cmd_release);
108 spin_unlock_bh(&tgt->tgt_lock);
109 }
110 return rc;
111}
112
113static void bnx2fc_l2_els_compl(struct bnx2fc_els_cb_arg *cb_arg)
114{
115 struct bnx2fc_cmd *els_req;
116 struct bnx2fc_rport *tgt;
117 struct bnx2fc_mp_req *mp_req;
118 struct fc_frame_header *fc_hdr;
119 unsigned char *buf;
120 void *resp_buf;
121 u32 resp_len, hdr_len;
122 u16 l2_oxid;
123 int frame_len;
124 int rc = 0;
125
126 l2_oxid = cb_arg->l2_oxid;
127 BNX2FC_ELS_DBG("ELS COMPL - l2_oxid = 0x%x\n", l2_oxid);
128
129 els_req = cb_arg->io_req;
130 if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &els_req->req_flags)) {
131 /*
132 * els req is timed out. cleanup the IO with FW and
133 * drop the completion. libfc will handle the els timeout
134 */
135 if (els_req->on_active_queue) {
136 list_del_init(&els_req->link);
137 els_req->on_active_queue = 0;
138 rc = bnx2fc_initiate_cleanup(els_req);
139 BUG_ON(rc);
140 }
141 goto free_arg;
142 }
143
144 tgt = els_req->tgt;
145 mp_req = &(els_req->mp_req);
146 fc_hdr = &(mp_req->resp_fc_hdr);
147 resp_len = mp_req->resp_len;
148 resp_buf = mp_req->resp_buf;
149
150 buf = kzalloc(PAGE_SIZE, GFP_ATOMIC);
151 if (!buf) {
152 printk(KERN_ERR PFX "Unable to alloc mp buf\n");
153 goto free_arg;
154 }
155 hdr_len = sizeof(*fc_hdr);
156 if (hdr_len + resp_len > PAGE_SIZE) {
157 printk(KERN_ERR PFX "l2_els_compl: resp len is "
158 "beyond page size\n");
159 goto free_buf;
160 }
161 memcpy(buf, fc_hdr, hdr_len);
162 memcpy(buf + hdr_len, resp_buf, resp_len);
163 frame_len = hdr_len + resp_len;
164
165 bnx2fc_process_l2_frame_compl(tgt, buf, frame_len, l2_oxid);
166
167free_buf:
168 kfree(buf);
169free_arg:
170 kfree(cb_arg);
171}
172
173int bnx2fc_send_adisc(struct bnx2fc_rport *tgt, struct fc_frame *fp)
174{
175 struct fc_els_adisc *adisc;
176 struct fc_frame_header *fh;
177 struct bnx2fc_els_cb_arg *cb_arg;
178 struct fc_lport *lport = tgt->rdata->local_port;
179 u32 r_a_tov = lport->r_a_tov;
180 int rc;
181
182 fh = fc_frame_header_get(fp);
183 cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
184 if (!cb_arg) {
185 printk(KERN_ERR PFX "Unable to allocate cb_arg for ADISC\n");
186 return -ENOMEM;
187 }
188
189 cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
190
191 BNX2FC_ELS_DBG("send ADISC: l2_oxid = 0x%x\n", cb_arg->l2_oxid);
192 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
193 /* adisc is initialized by libfc */
194 rc = bnx2fc_initiate_els(tgt, ELS_ADISC, adisc, sizeof(*adisc),
195 bnx2fc_l2_els_compl, cb_arg, 2 * r_a_tov);
196 if (rc)
197 kfree(cb_arg);
198 return rc;
199}
200
201int bnx2fc_send_logo(struct bnx2fc_rport *tgt, struct fc_frame *fp)
202{
203 struct fc_els_logo *logo;
204 struct fc_frame_header *fh;
205 struct bnx2fc_els_cb_arg *cb_arg;
206 struct fc_lport *lport = tgt->rdata->local_port;
207 u32 r_a_tov = lport->r_a_tov;
208 int rc;
209
210 fh = fc_frame_header_get(fp);
211 cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
212 if (!cb_arg) {
213 printk(KERN_ERR PFX "Unable to allocate cb_arg for LOGO\n");
214 return -ENOMEM;
215 }
216
217 cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
218
219 BNX2FC_ELS_DBG("Send LOGO: l2_oxid = 0x%x\n", cb_arg->l2_oxid);
220 logo = fc_frame_payload_get(fp, sizeof(*logo));
221 /* logo is initialized by libfc */
222 rc = bnx2fc_initiate_els(tgt, ELS_LOGO, logo, sizeof(*logo),
223 bnx2fc_l2_els_compl, cb_arg, 2 * r_a_tov);
224 if (rc)
225 kfree(cb_arg);
226 return rc;
227}
228
229int bnx2fc_send_rls(struct bnx2fc_rport *tgt, struct fc_frame *fp)
230{
231 struct fc_els_rls *rls;
232 struct fc_frame_header *fh;
233 struct bnx2fc_els_cb_arg *cb_arg;
234 struct fc_lport *lport = tgt->rdata->local_port;
235 u32 r_a_tov = lport->r_a_tov;
236 int rc;
237
238 fh = fc_frame_header_get(fp);
239 cb_arg = kzalloc(sizeof(struct bnx2fc_els_cb_arg), GFP_ATOMIC);
240 if (!cb_arg) {
241 printk(KERN_ERR PFX "Unable to allocate cb_arg for LOGO\n");
242 return -ENOMEM;
243 }
244
245 cb_arg->l2_oxid = ntohs(fh->fh_ox_id);
246
247 rls = fc_frame_payload_get(fp, sizeof(*rls));
248 /* rls is initialized by libfc */
249 rc = bnx2fc_initiate_els(tgt, ELS_RLS, rls, sizeof(*rls),
250 bnx2fc_l2_els_compl, cb_arg, 2 * r_a_tov);
251 if (rc)
252 kfree(cb_arg);
253 return rc;
254}
255
256static int bnx2fc_initiate_els(struct bnx2fc_rport *tgt, unsigned int op,
257 void *data, u32 data_len,
258 void (*cb_func)(struct bnx2fc_els_cb_arg *cb_arg),
259 struct bnx2fc_els_cb_arg *cb_arg, u32 timer_msec)
260{
261 struct fcoe_port *port = tgt->port;
262 struct bnx2fc_hba *hba = port->priv;
263 struct fc_rport *rport = tgt->rport;
264 struct fc_lport *lport = port->lport;
265 struct bnx2fc_cmd *els_req;
266 struct bnx2fc_mp_req *mp_req;
267 struct fc_frame_header *fc_hdr;
268 struct fcoe_task_ctx_entry *task;
269 struct fcoe_task_ctx_entry *task_page;
270 int rc = 0;
271 int task_idx, index;
272 u32 did, sid;
273 u16 xid;
274
275 rc = fc_remote_port_chkready(rport);
276 if (rc) {
277 printk(KERN_ALERT PFX "els 0x%x: rport not ready\n", op);
278 rc = -EINVAL;
279 goto els_err;
280 }
281 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
282 printk(KERN_ALERT PFX "els 0x%x: link is not ready\n", op);
283 rc = -EINVAL;
284 goto els_err;
285 }
286 if (!(test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) ||
287 (test_bit(BNX2FC_FLAG_EXPL_LOGO, &tgt->flags))) {
288 printk(KERN_ERR PFX "els 0x%x: tgt not ready\n", op);
289 rc = -EINVAL;
290 goto els_err;
291 }
292 els_req = bnx2fc_elstm_alloc(tgt, BNX2FC_ELS);
293 if (!els_req) {
294 rc = -ENOMEM;
295 goto els_err;
296 }
297
298 els_req->sc_cmd = NULL;
299 els_req->port = port;
300 els_req->tgt = tgt;
301 els_req->cb_func = cb_func;
302 cb_arg->io_req = els_req;
303 els_req->cb_arg = cb_arg;
304
305 mp_req = (struct bnx2fc_mp_req *)&(els_req->mp_req);
306 rc = bnx2fc_init_mp_req(els_req);
307 if (rc == FAILED) {
308 printk(KERN_ALERT PFX "ELS MP request init failed\n");
309 spin_lock_bh(&tgt->tgt_lock);
310 kref_put(&els_req->refcount, bnx2fc_cmd_release);
311 spin_unlock_bh(&tgt->tgt_lock);
312 rc = -ENOMEM;
313 goto els_err;
314 } else {
315 /* rc SUCCESS */
316 rc = 0;
317 }
318
319 /* Set the data_xfer_len to the size of ELS payload */
320 mp_req->req_len = data_len;
321 els_req->data_xfer_len = mp_req->req_len;
322
323 /* Fill ELS Payload */
324 if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) {
325 memcpy(mp_req->req_buf, data, data_len);
326 } else {
327 printk(KERN_ALERT PFX "Invalid ELS op 0x%x\n", op);
328 els_req->cb_func = NULL;
329 els_req->cb_arg = NULL;
330 spin_lock_bh(&tgt->tgt_lock);
331 kref_put(&els_req->refcount, bnx2fc_cmd_release);
332 spin_unlock_bh(&tgt->tgt_lock);
333 rc = -EINVAL;
334 }
335
336 if (rc)
337 goto els_err;
338
339 /* Fill FC header */
340 fc_hdr = &(mp_req->req_fc_hdr);
341
342 did = tgt->rport->port_id;
343 sid = tgt->sid;
344
345 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_ELS_REQ, did, sid,
346 FC_TYPE_ELS, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
347 FC_FC_SEQ_INIT, 0);
348
349 /* Obtain exchange id */
350 xid = els_req->xid;
351 task_idx = xid/BNX2FC_TASKS_PER_PAGE;
352 index = xid % BNX2FC_TASKS_PER_PAGE;
353
354 /* Initialize task context for this IO request */
355 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx];
356 task = &(task_page[index]);
357 bnx2fc_init_mp_task(els_req, task);
358
359 spin_lock_bh(&tgt->tgt_lock);
360
361 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
362 printk(KERN_ERR PFX "initiate_els.. session not ready\n");
363 els_req->cb_func = NULL;
364 els_req->cb_arg = NULL;
365 kref_put(&els_req->refcount, bnx2fc_cmd_release);
366 spin_unlock_bh(&tgt->tgt_lock);
367 return -EINVAL;
368 }
369
370 if (timer_msec)
371 bnx2fc_cmd_timer_set(els_req, timer_msec);
372 bnx2fc_add_2_sq(tgt, xid);
373
374 els_req->on_active_queue = 1;
375 list_add_tail(&els_req->link, &tgt->els_queue);
376
377 /* Ring doorbell */
378 bnx2fc_ring_doorbell(tgt);
379 spin_unlock_bh(&tgt->tgt_lock);
380
381els_err:
382 return rc;
383}
384
385void bnx2fc_process_els_compl(struct bnx2fc_cmd *els_req,
386 struct fcoe_task_ctx_entry *task, u8 num_rq)
387{
388 struct bnx2fc_mp_req *mp_req;
389 struct fc_frame_header *fc_hdr;
390 u64 *hdr;
391 u64 *temp_hdr;
392
393 BNX2FC_ELS_DBG("Entered process_els_compl xid = 0x%x"
394 "cmd_type = %d\n", els_req->xid, els_req->cmd_type);
395
396 if (test_and_set_bit(BNX2FC_FLAG_ELS_DONE,
397 &els_req->req_flags)) {
398 BNX2FC_ELS_DBG("Timer context finished processing this "
399 "els - 0x%x\n", els_req->xid);
400 /* This IO doesnt receive cleanup completion */
401 kref_put(&els_req->refcount, bnx2fc_cmd_release);
402 return;
403 }
404
405 /* Cancel the timeout_work, as we received the response */
406 if (cancel_delayed_work(&els_req->timeout_work))
407 kref_put(&els_req->refcount,
408 bnx2fc_cmd_release); /* drop timer hold */
409
410 if (els_req->on_active_queue) {
411 list_del_init(&els_req->link);
412 els_req->on_active_queue = 0;
413 }
414
415 mp_req = &(els_req->mp_req);
416 fc_hdr = &(mp_req->resp_fc_hdr);
417
418 hdr = (u64 *)fc_hdr;
419 temp_hdr = (u64 *)
420 &task->cmn.general.cmd_info.mp_fc_frame.fc_hdr;
421 hdr[0] = cpu_to_be64(temp_hdr[0]);
422 hdr[1] = cpu_to_be64(temp_hdr[1]);
423 hdr[2] = cpu_to_be64(temp_hdr[2]);
424
425 mp_req->resp_len = task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_off;
426
427 /* Parse ELS response */
428 if ((els_req->cb_func) && (els_req->cb_arg)) {
429 els_req->cb_func(els_req->cb_arg);
430 els_req->cb_arg = NULL;
431 }
432
433 kref_put(&els_req->refcount, bnx2fc_cmd_release);
434}
435
436static void bnx2fc_flogi_resp(struct fc_seq *seq, struct fc_frame *fp,
437 void *arg)
438{
439 struct fcoe_ctlr *fip = arg;
440 struct fc_exch *exch = fc_seq_exch(seq);
441 struct fc_lport *lport = exch->lp;
442 u8 *mac;
443 struct fc_frame_header *fh;
444 u8 op;
445
446 if (IS_ERR(fp))
447 goto done;
448
449 mac = fr_cb(fp)->granted_mac;
450 if (is_zero_ether_addr(mac)) {
451 fh = fc_frame_header_get(fp);
452 if (fh->fh_type != FC_TYPE_ELS) {
453 printk(KERN_ERR PFX "bnx2fc_flogi_resp:"
454 "fh_type != FC_TYPE_ELS\n");
455 fc_frame_free(fp);
456 return;
457 }
458 op = fc_frame_payload_op(fp);
459 if (lport->vport) {
460 if (op == ELS_LS_RJT) {
461 printk(KERN_ERR PFX "bnx2fc_flogi_resp is LS_RJT\n");
462 fc_vport_terminate(lport->vport);
463 fc_frame_free(fp);
464 return;
465 }
466 }
467 if (fcoe_ctlr_recv_flogi(fip, lport, fp)) {
468 fc_frame_free(fp);
469 return;
470 }
471 }
472 fip->update_mac(lport, mac);
473done:
474 fc_lport_flogi_resp(seq, fp, lport);
475}
476
477static void bnx2fc_logo_resp(struct fc_seq *seq, struct fc_frame *fp,
478 void *arg)
479{
480 struct fcoe_ctlr *fip = arg;
481 struct fc_exch *exch = fc_seq_exch(seq);
482 struct fc_lport *lport = exch->lp;
483 static u8 zero_mac[ETH_ALEN] = { 0 };
484
485 if (!IS_ERR(fp))
486 fip->update_mac(lport, zero_mac);
487 fc_lport_logo_resp(seq, fp, lport);
488}
489
490struct fc_seq *bnx2fc_elsct_send(struct fc_lport *lport, u32 did,
491 struct fc_frame *fp, unsigned int op,
492 void (*resp)(struct fc_seq *,
493 struct fc_frame *,
494 void *),
495 void *arg, u32 timeout)
496{
497 struct fcoe_port *port = lport_priv(lport);
498 struct bnx2fc_hba *hba = port->priv;
499 struct fcoe_ctlr *fip = &hba->ctlr;
500 struct fc_frame_header *fh = fc_frame_header_get(fp);
501
502 switch (op) {
503 case ELS_FLOGI:
504 case ELS_FDISC:
505 return fc_elsct_send(lport, did, fp, op, bnx2fc_flogi_resp,
506 fip, timeout);
507 case ELS_LOGO:
508 /* only hook onto fabric logouts, not port logouts */
509 if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI)
510 break;
511 return fc_elsct_send(lport, did, fp, op, bnx2fc_logo_resp,
512 fip, timeout);
513 }
514 return fc_elsct_send(lport, did, fp, op, resp, arg, timeout);
515}
diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
new file mode 100644
index 000000000000..e476e8753079
--- /dev/null
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -0,0 +1,2535 @@
1/* bnx2fc_fcoe.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * This file contains the code that interacts with libfc, libfcoe,
3 * cnic modules to create FCoE instances, send/receive non-offloaded
4 * FIP/FCoE packets, listen to link events etc.
5 *
6 * Copyright (c) 2008 - 2010 Broadcom Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation.
11 *
12 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
13 */
14
15#include "bnx2fc.h"
16
17static struct list_head adapter_list;
18static u32 adapter_count;
19static DEFINE_MUTEX(bnx2fc_dev_lock);
20DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
21
22#define DRV_MODULE_NAME "bnx2fc"
23#define DRV_MODULE_VERSION BNX2FC_VERSION
24#define DRV_MODULE_RELDATE "Jan 25, 2011"
25
26
27static char version[] __devinitdata =
28 "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
29 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
30
31
32MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
33MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
34MODULE_LICENSE("GPL");
35MODULE_VERSION(DRV_MODULE_VERSION);
36
37#define BNX2FC_MAX_QUEUE_DEPTH 256
38#define BNX2FC_MIN_QUEUE_DEPTH 32
39#define FCOE_WORD_TO_BYTE 4
40
41static struct scsi_transport_template *bnx2fc_transport_template;
42static struct scsi_transport_template *bnx2fc_vport_xport_template;
43
44struct workqueue_struct *bnx2fc_wq;
45
46/* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
47 * Here the io threads are per cpu but the l2 thread is just one
48 */
49struct fcoe_percpu_s bnx2fc_global;
50DEFINE_SPINLOCK(bnx2fc_global_lock);
51
52static struct cnic_ulp_ops bnx2fc_cnic_cb;
53static struct libfc_function_template bnx2fc_libfc_fcn_templ;
54static struct scsi_host_template bnx2fc_shost_template;
55static struct fc_function_template bnx2fc_transport_function;
56static struct fc_function_template bnx2fc_vport_xport_function;
57static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
58static int bnx2fc_destroy(struct net_device *net_device);
59static int bnx2fc_enable(struct net_device *netdev);
60static int bnx2fc_disable(struct net_device *netdev);
61
62static void bnx2fc_recv_frame(struct sk_buff *skb);
63
64static void bnx2fc_start_disc(struct bnx2fc_hba *hba);
65static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
66static int bnx2fc_net_config(struct fc_lport *lp);
67static int bnx2fc_lport_config(struct fc_lport *lport);
68static int bnx2fc_em_config(struct fc_lport *lport);
69static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
70static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
71static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
72static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
73static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
74 struct device *parent, int npiv);
75static void bnx2fc_destroy_work(struct work_struct *work);
76
77static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
78static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
79
80static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
81static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
82
83static void bnx2fc_port_shutdown(struct fc_lport *lport);
84static void bnx2fc_stop(struct bnx2fc_hba *hba);
85static int __init bnx2fc_mod_init(void);
86static void __exit bnx2fc_mod_exit(void);
87
88unsigned int bnx2fc_debug_level;
89module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
90
91static int bnx2fc_cpu_callback(struct notifier_block *nfb,
92 unsigned long action, void *hcpu);
93/* notification function for CPU hotplug events */
94static struct notifier_block bnx2fc_cpu_notifier = {
95 .notifier_call = bnx2fc_cpu_callback,
96};
97
98static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
99{
100 struct fcoe_percpu_s *bg;
101 struct fcoe_rcv_info *fr;
102 struct sk_buff_head *list;
103 struct sk_buff *skb, *next;
104 struct sk_buff *head;
105
106 bg = &bnx2fc_global;
107 spin_lock_bh(&bg->fcoe_rx_list.lock);
108 list = &bg->fcoe_rx_list;
109 head = list->next;
110 for (skb = head; skb != (struct sk_buff *)list;
111 skb = next) {
112 next = skb->next;
113 fr = fcoe_dev_from_skb(skb);
114 if (fr->fr_dev == lp) {
115 __skb_unlink(skb, list);
116 kfree_skb(skb);
117 }
118 }
119 spin_unlock_bh(&bg->fcoe_rx_list.lock);
120}
121
122int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
123{
124 int rc;
125 spin_lock(&bnx2fc_global_lock);
126 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
127 spin_unlock(&bnx2fc_global_lock);
128
129 return rc;
130}
131
132static void bnx2fc_abort_io(struct fc_lport *lport)
133{
134 /*
135 * This function is no-op for bnx2fc, but we do
136 * not want to leave it as NULL either, as libfc
137 * can call the default function which is
138 * fc_fcp_abort_io.
139 */
140}
141
142static void bnx2fc_cleanup(struct fc_lport *lport)
143{
144 struct fcoe_port *port = lport_priv(lport);
145 struct bnx2fc_hba *hba = port->priv;
146 struct bnx2fc_rport *tgt;
147 int i;
148
149 BNX2FC_MISC_DBG("Entered %s\n", __func__);
150 mutex_lock(&hba->hba_mutex);
151 spin_lock_bh(&hba->hba_lock);
152 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
153 tgt = hba->tgt_ofld_list[i];
154 if (tgt) {
155 /* Cleanup IOs belonging to requested vport */
156 if (tgt->port == port) {
157 spin_unlock_bh(&hba->hba_lock);
158 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
159 bnx2fc_flush_active_ios(tgt);
160 spin_lock_bh(&hba->hba_lock);
161 }
162 }
163 }
164 spin_unlock_bh(&hba->hba_lock);
165 mutex_unlock(&hba->hba_mutex);
166}
167
168static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
169 struct fc_frame *fp)
170{
171 struct fc_rport_priv *rdata = tgt->rdata;
172 struct fc_frame_header *fh;
173 int rc = 0;
174
175 fh = fc_frame_header_get(fp);
176 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
177 "r_ctl = 0x%x\n", rdata->ids.port_id,
178 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
179 if ((fh->fh_type == FC_TYPE_ELS) &&
180 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
181
182 switch (fc_frame_payload_op(fp)) {
183 case ELS_ADISC:
184 rc = bnx2fc_send_adisc(tgt, fp);
185 break;
186 case ELS_LOGO:
187 rc = bnx2fc_send_logo(tgt, fp);
188 break;
189 case ELS_RLS:
190 rc = bnx2fc_send_rls(tgt, fp);
191 break;
192 default:
193 break;
194 }
195 } else if ((fh->fh_type == FC_TYPE_BLS) &&
196 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
197 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
198 else {
199 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
200 "rctl 0x%x thru non-offload path\n",
201 fh->fh_type, fh->fh_r_ctl);
202 return -ENODEV;
203 }
204 if (rc)
205 return -ENOMEM;
206 else
207 return 0;
208}
209
210/**
211 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
212 *
213 * @lport: the associated local port
214 * @fp: the fc_frame to be transmitted
215 */
216static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
217{
218 struct ethhdr *eh;
219 struct fcoe_crc_eof *cp;
220 struct sk_buff *skb;
221 struct fc_frame_header *fh;
222 struct bnx2fc_hba *hba;
223 struct fcoe_port *port;
224 struct fcoe_hdr *hp;
225 struct bnx2fc_rport *tgt;
226 struct fcoe_dev_stats *stats;
227 u8 sof, eof;
228 u32 crc;
229 unsigned int hlen, tlen, elen;
230 int wlen, rc = 0;
231
232 port = (struct fcoe_port *)lport_priv(lport);
233 hba = port->priv;
234
235 fh = fc_frame_header_get(fp);
236
237 skb = fp_skb(fp);
238 if (!lport->link_up) {
239 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
240 kfree_skb(skb);
241 return 0;
242 }
243
244 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
245 if (!hba->ctlr.sel_fcf) {
246 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
247 kfree_skb(skb);
248 return -EINVAL;
249 }
250 if (fcoe_ctlr_els_send(&hba->ctlr, lport, skb))
251 return 0;
252 }
253
254 sof = fr_sof(fp);
255 eof = fr_eof(fp);
256
257 /*
258 * Snoop the frame header to check if the frame is for
259 * an offloaded session
260 */
261 /*
262 * tgt_ofld_list access is synchronized using
263 * both hba mutex and hba lock. Atleast hba mutex or
264 * hba lock needs to be held for read access.
265 */
266
267 spin_lock_bh(&hba->hba_lock);
268 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
269 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
270 /* This frame is for offloaded session */
271 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
272 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
273 spin_unlock_bh(&hba->hba_lock);
274 rc = bnx2fc_xmit_l2_frame(tgt, fp);
275 if (rc != -ENODEV) {
276 kfree_skb(skb);
277 return rc;
278 }
279 } else {
280 spin_unlock_bh(&hba->hba_lock);
281 }
282
283 elen = sizeof(struct ethhdr);
284 hlen = sizeof(struct fcoe_hdr);
285 tlen = sizeof(struct fcoe_crc_eof);
286 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
287
288 skb->ip_summed = CHECKSUM_NONE;
289 crc = fcoe_fc_crc(fp);
290
291 /* copy port crc and eof to the skb buff */
292 if (skb_is_nonlinear(skb)) {
293 skb_frag_t *frag;
294 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
295 kfree_skb(skb);
296 return -ENOMEM;
297 }
298 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
299 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
300 + frag->page_offset;
301 } else {
302 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
303 }
304
305 memset(cp, 0, sizeof(*cp));
306 cp->fcoe_eof = eof;
307 cp->fcoe_crc32 = cpu_to_le32(~crc);
308 if (skb_is_nonlinear(skb)) {
309 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
310 cp = NULL;
311 }
312
313 /* adjust skb network/transport offsets to match mac/fcoe/port */
314 skb_push(skb, elen + hlen);
315 skb_reset_mac_header(skb);
316 skb_reset_network_header(skb);
317 skb->mac_len = elen;
318 skb->protocol = htons(ETH_P_FCOE);
319 skb->dev = hba->netdev;
320
321 /* fill up mac and fcoe headers */
322 eh = eth_hdr(skb);
323 eh->h_proto = htons(ETH_P_FCOE);
324 if (hba->ctlr.map_dest)
325 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
326 else
327 /* insert GW address */
328 memcpy(eh->h_dest, hba->ctlr.dest_addr, ETH_ALEN);
329
330 if (unlikely(hba->ctlr.flogi_oxid != FC_XID_UNKNOWN))
331 memcpy(eh->h_source, hba->ctlr.ctl_src_addr, ETH_ALEN);
332 else
333 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
334
335 hp = (struct fcoe_hdr *)(eh + 1);
336 memset(hp, 0, sizeof(*hp));
337 if (FC_FCOE_VER)
338 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
339 hp->fcoe_sof = sof;
340
341 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
342 if (lport->seq_offload && fr_max_payload(fp)) {
343 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
344 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
345 } else {
346 skb_shinfo(skb)->gso_type = 0;
347 skb_shinfo(skb)->gso_size = 0;
348 }
349
350 /*update tx stats */
351 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
352 stats->TxFrames++;
353 stats->TxWords += wlen;
354 put_cpu();
355
356 /* send down to lld */
357 fr_dev(fp) = lport;
358 if (port->fcoe_pending_queue.qlen)
359 fcoe_check_wait_queue(lport, skb);
360 else if (fcoe_start_io(skb))
361 fcoe_check_wait_queue(lport, skb);
362
363 return 0;
364}
365
366/**
367 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
368 *
369 * @skb: the receive socket buffer
370 * @dev: associated net device
371 * @ptype: context
372 * @olddev: last device
373 *
374 * This function receives the packet and builds FC frame and passes it up
375 */
376static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
377 struct packet_type *ptype, struct net_device *olddev)
378{
379 struct fc_lport *lport;
380 struct bnx2fc_hba *hba;
381 struct fc_frame_header *fh;
382 struct fcoe_rcv_info *fr;
383 struct fcoe_percpu_s *bg;
384 unsigned short oxid;
385
386 hba = container_of(ptype, struct bnx2fc_hba, fcoe_packet_type);
387 lport = hba->ctlr.lp;
388
389 if (unlikely(lport == NULL)) {
390 printk(KERN_ALERT PFX "bnx2fc_rcv: lport is NULL\n");
391 goto err;
392 }
393
394 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
395 printk(KERN_ALERT PFX "bnx2fc_rcv: Wrong FC type frame\n");
396 goto err;
397 }
398
399 /*
400 * Check for minimum frame length, and make sure required FCoE
401 * and FC headers are pulled into the linear data area.
402 */
403 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
404 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
405 goto err;
406
407 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
408 fh = (struct fc_frame_header *) skb_transport_header(skb);
409
410 oxid = ntohs(fh->fh_ox_id);
411
412 fr = fcoe_dev_from_skb(skb);
413 fr->fr_dev = lport;
414 fr->ptype = ptype;
415
416 bg = &bnx2fc_global;
417 spin_lock_bh(&bg->fcoe_rx_list.lock);
418
419 __skb_queue_tail(&bg->fcoe_rx_list, skb);
420 if (bg->fcoe_rx_list.qlen == 1)
421 wake_up_process(bg->thread);
422
423 spin_unlock_bh(&bg->fcoe_rx_list.lock);
424
425 return 0;
426err:
427 kfree_skb(skb);
428 return -1;
429}
430
431static int bnx2fc_l2_rcv_thread(void *arg)
432{
433 struct fcoe_percpu_s *bg = arg;
434 struct sk_buff *skb;
435
436 set_user_nice(current, -20);
437 set_current_state(TASK_INTERRUPTIBLE);
438 while (!kthread_should_stop()) {
439 schedule();
440 set_current_state(TASK_RUNNING);
441 spin_lock_bh(&bg->fcoe_rx_list.lock);
442 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
443 spin_unlock_bh(&bg->fcoe_rx_list.lock);
444 bnx2fc_recv_frame(skb);
445 spin_lock_bh(&bg->fcoe_rx_list.lock);
446 }
447 spin_unlock_bh(&bg->fcoe_rx_list.lock);
448 set_current_state(TASK_INTERRUPTIBLE);
449 }
450 set_current_state(TASK_RUNNING);
451 return 0;
452}
453
454
455static void bnx2fc_recv_frame(struct sk_buff *skb)
456{
457 u32 fr_len;
458 struct fc_lport *lport;
459 struct fcoe_rcv_info *fr;
460 struct fcoe_dev_stats *stats;
461 struct fc_frame_header *fh;
462 struct fcoe_crc_eof crc_eof;
463 struct fc_frame *fp;
464 struct fc_lport *vn_port;
465 struct fcoe_port *port;
466 u8 *mac = NULL;
467 u8 *dest_mac = NULL;
468 struct fcoe_hdr *hp;
469
470 fr = fcoe_dev_from_skb(skb);
471 lport = fr->fr_dev;
472 if (unlikely(lport == NULL)) {
473 printk(KERN_ALERT PFX "Invalid lport struct\n");
474 kfree_skb(skb);
475 return;
476 }
477
478 if (skb_is_nonlinear(skb))
479 skb_linearize(skb);
480 mac = eth_hdr(skb)->h_source;
481 dest_mac = eth_hdr(skb)->h_dest;
482
483 /* Pull the header */
484 hp = (struct fcoe_hdr *) skb_network_header(skb);
485 fh = (struct fc_frame_header *) skb_transport_header(skb);
486 skb_pull(skb, sizeof(struct fcoe_hdr));
487 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
488
489 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
490 stats->RxFrames++;
491 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
492
493 fp = (struct fc_frame *)skb;
494 fc_frame_init(fp);
495 fr_dev(fp) = lport;
496 fr_sof(fp) = hp->fcoe_sof;
497 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
498 put_cpu();
499 kfree_skb(skb);
500 return;
501 }
502 fr_eof(fp) = crc_eof.fcoe_eof;
503 fr_crc(fp) = crc_eof.fcoe_crc32;
504 if (pskb_trim(skb, fr_len)) {
505 put_cpu();
506 kfree_skb(skb);
507 return;
508 }
509
510 fh = fc_frame_header_get(fp);
511
512 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
513 if (vn_port) {
514 port = lport_priv(vn_port);
515 if (compare_ether_addr(port->data_src_addr, dest_mac)
516 != 0) {
517 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
518 put_cpu();
519 kfree_skb(skb);
520 return;
521 }
522 }
523 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
524 fh->fh_type == FC_TYPE_FCP) {
525 /* Drop FCP data. We dont this in L2 path */
526 put_cpu();
527 kfree_skb(skb);
528 return;
529 }
530 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
531 fh->fh_type == FC_TYPE_ELS) {
532 switch (fc_frame_payload_op(fp)) {
533 case ELS_LOGO:
534 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
535 /* drop non-FIP LOGO */
536 put_cpu();
537 kfree_skb(skb);
538 return;
539 }
540 break;
541 }
542 }
543 if (le32_to_cpu(fr_crc(fp)) !=
544 ~crc32(~0, skb->data, fr_len)) {
545 if (stats->InvalidCRCCount < 5)
546 printk(KERN_WARNING PFX "dropping frame with "
547 "CRC error\n");
548 stats->InvalidCRCCount++;
549 put_cpu();
550 kfree_skb(skb);
551 return;
552 }
553 put_cpu();
554 fc_exch_recv(lport, fp);
555}
556
557/**
558 * bnx2fc_percpu_io_thread - thread per cpu for ios
559 *
560 * @arg: ptr to bnx2fc_percpu_info structure
561 */
562int bnx2fc_percpu_io_thread(void *arg)
563{
564 struct bnx2fc_percpu_s *p = arg;
565 struct bnx2fc_work *work, *tmp;
566 LIST_HEAD(work_list);
567
568 set_user_nice(current, -20);
569 set_current_state(TASK_INTERRUPTIBLE);
570 while (!kthread_should_stop()) {
571 schedule();
572 set_current_state(TASK_RUNNING);
573 spin_lock_bh(&p->fp_work_lock);
574 while (!list_empty(&p->work_list)) {
575 list_splice_init(&p->work_list, &work_list);
576 spin_unlock_bh(&p->fp_work_lock);
577
578 list_for_each_entry_safe(work, tmp, &work_list, list) {
579 list_del_init(&work->list);
580 bnx2fc_process_cq_compl(work->tgt, work->wqe);
581 kfree(work);
582 }
583
584 spin_lock_bh(&p->fp_work_lock);
585 }
586 spin_unlock_bh(&p->fp_work_lock);
587 set_current_state(TASK_INTERRUPTIBLE);
588 }
589 set_current_state(TASK_RUNNING);
590
591 return 0;
592}
593
594static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
595{
596 struct fc_host_statistics *bnx2fc_stats;
597 struct fc_lport *lport = shost_priv(shost);
598 struct fcoe_port *port = lport_priv(lport);
599 struct bnx2fc_hba *hba = port->priv;
600 struct fcoe_statistics_params *fw_stats;
601 int rc = 0;
602
603 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
604 if (!fw_stats)
605 return NULL;
606
607 bnx2fc_stats = fc_get_host_stats(shost);
608
609 init_completion(&hba->stat_req_done);
610 if (bnx2fc_send_stat_req(hba))
611 return bnx2fc_stats;
612 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
613 if (!rc) {
614 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
615 return bnx2fc_stats;
616 }
617 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat1.fc_crc_cnt;
618 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
619 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
620 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
621 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
622
623 bnx2fc_stats->dumped_frames = 0;
624 bnx2fc_stats->lip_count = 0;
625 bnx2fc_stats->nos_count = 0;
626 bnx2fc_stats->loss_of_sync_count = 0;
627 bnx2fc_stats->loss_of_signal_count = 0;
628 bnx2fc_stats->prim_seq_protocol_err_count = 0;
629
630 return bnx2fc_stats;
631}
632
633static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
634{
635 struct fcoe_port *port = lport_priv(lport);
636 struct bnx2fc_hba *hba = port->priv;
637 struct Scsi_Host *shost = lport->host;
638 int rc = 0;
639
640 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
641 shost->max_lun = BNX2FC_MAX_LUN;
642 shost->max_id = BNX2FC_MAX_FCP_TGT;
643 shost->max_channel = 0;
644 if (lport->vport)
645 shost->transportt = bnx2fc_vport_xport_template;
646 else
647 shost->transportt = bnx2fc_transport_template;
648
649 /* Add the new host to SCSI-ml */
650 rc = scsi_add_host(lport->host, dev);
651 if (rc) {
652 printk(KERN_ERR PFX "Error on scsi_add_host\n");
653 return rc;
654 }
655 if (!lport->vport)
656 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
657 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
658 BNX2FC_NAME, BNX2FC_VERSION,
659 hba->netdev->name);
660
661 return 0;
662}
663
664static int bnx2fc_mfs_update(struct fc_lport *lport)
665{
666 struct fcoe_port *port = lport_priv(lport);
667 struct bnx2fc_hba *hba = port->priv;
668 struct net_device *netdev = hba->netdev;
669 u32 mfs;
670 u32 max_mfs;
671
672 mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
673 sizeof(struct fcoe_crc_eof));
674 max_mfs = BNX2FC_MAX_PAYLOAD + sizeof(struct fc_frame_header);
675 BNX2FC_HBA_DBG(lport, "mfs = %d, max_mfs = %d\n", mfs, max_mfs);
676 if (mfs > max_mfs)
677 mfs = max_mfs;
678
679 /* Adjust mfs to be a multiple of 256 bytes */
680 mfs = (((mfs - sizeof(struct fc_frame_header)) / BNX2FC_MIN_PAYLOAD) *
681 BNX2FC_MIN_PAYLOAD);
682 mfs = mfs + sizeof(struct fc_frame_header);
683
684 BNX2FC_HBA_DBG(lport, "Set MFS = %d\n", mfs);
685 if (fc_set_mfs(lport, mfs))
686 return -EINVAL;
687 return 0;
688}
689static void bnx2fc_link_speed_update(struct fc_lport *lport)
690{
691 struct fcoe_port *port = lport_priv(lport);
692 struct bnx2fc_hba *hba = port->priv;
693 struct net_device *netdev = hba->netdev;
694 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
695
696 if (!dev_ethtool_get_settings(netdev, &ecmd)) {
697 lport->link_supported_speeds &=
698 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
699 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
700 SUPPORTED_1000baseT_Full))
701 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
702 if (ecmd.supported & SUPPORTED_10000baseT_Full)
703 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
704
705 if (ecmd.speed == SPEED_1000)
706 lport->link_speed = FC_PORTSPEED_1GBIT;
707 if (ecmd.speed == SPEED_10000)
708 lport->link_speed = FC_PORTSPEED_10GBIT;
709 }
710 return;
711}
712static int bnx2fc_link_ok(struct fc_lport *lport)
713{
714 struct fcoe_port *port = lport_priv(lport);
715 struct bnx2fc_hba *hba = port->priv;
716 struct net_device *dev = hba->phys_dev;
717 int rc = 0;
718
719 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
720 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
721 else {
722 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
723 rc = -1;
724 }
725 return rc;
726}
727
728/**
729 * bnx2fc_get_link_state - get network link state
730 *
731 * @hba: adapter instance pointer
732 *
733 * updates adapter structure flag based on netdev state
734 */
735void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
736{
737 if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
738 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
739 else
740 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
741}
742
743static int bnx2fc_net_config(struct fc_lport *lport)
744{
745 struct bnx2fc_hba *hba;
746 struct fcoe_port *port;
747 u64 wwnn, wwpn;
748
749 port = lport_priv(lport);
750 hba = port->priv;
751
752 /* require support for get_pauseparam ethtool op. */
753 if (!hba->phys_dev->ethtool_ops ||
754 !hba->phys_dev->ethtool_ops->get_pauseparam)
755 return -EOPNOTSUPP;
756
757 if (bnx2fc_mfs_update(lport))
758 return -EINVAL;
759
760 skb_queue_head_init(&port->fcoe_pending_queue);
761 port->fcoe_pending_queue_active = 0;
762 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
763
764 bnx2fc_link_speed_update(lport);
765
766 if (!lport->vport) {
767 wwnn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 1, 0);
768 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
769 fc_set_wwnn(lport, wwnn);
770
771 wwpn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 2, 0);
772 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
773 fc_set_wwpn(lport, wwpn);
774 }
775
776 return 0;
777}
778
779static void bnx2fc_destroy_timer(unsigned long data)
780{
781 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
782
783 BNX2FC_HBA_DBG(hba->ctlr.lp, "ERROR:bnx2fc_destroy_timer - "
784 "Destroy compl not received!!\n");
785 hba->flags |= BNX2FC_FLAG_DESTROY_CMPL;
786 wake_up_interruptible(&hba->destroy_wait);
787}
788
789/**
790 * bnx2fc_indicate_netevent - Generic netdev event handler
791 *
792 * @context: adapter structure pointer
793 * @event: event type
794 *
795 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
796 * NETDEV_CHANGE_MTU events
797 */
798static void bnx2fc_indicate_netevent(void *context, unsigned long event)
799{
800 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
801 struct fc_lport *lport = hba->ctlr.lp;
802 struct fc_lport *vport;
803 u32 link_possible = 1;
804
805 if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
806 BNX2FC_MISC_DBG("driver not ready. event=%s %ld\n",
807 hba->netdev->name, event);
808 return;
809 }
810
811 /*
812 * ASSUMPTION:
813 * indicate_netevent cannot be called from cnic unless bnx2fc
814 * does register_device
815 */
816 BUG_ON(!lport);
817
818 BNX2FC_HBA_DBG(lport, "enter netevent handler - event=%s %ld\n",
819 hba->netdev->name, event);
820
821 switch (event) {
822 case NETDEV_UP:
823 BNX2FC_HBA_DBG(lport, "Port up, adapter_state = %ld\n",
824 hba->adapter_state);
825 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
826 printk(KERN_ERR "indicate_netevent: "\
827 "adapter is not UP!!\n");
828 /* fall thru to update mfs if MTU has changed */
829 case NETDEV_CHANGEMTU:
830 BNX2FC_HBA_DBG(lport, "NETDEV_CHANGEMTU event\n");
831 bnx2fc_mfs_update(lport);
832 mutex_lock(&lport->lp_mutex);
833 list_for_each_entry(vport, &lport->vports, list)
834 bnx2fc_mfs_update(vport);
835 mutex_unlock(&lport->lp_mutex);
836 break;
837
838 case NETDEV_DOWN:
839 BNX2FC_HBA_DBG(lport, "Port down\n");
840 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
841 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
842 link_possible = 0;
843 break;
844
845 case NETDEV_GOING_DOWN:
846 BNX2FC_HBA_DBG(lport, "Port going down\n");
847 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
848 link_possible = 0;
849 break;
850
851 case NETDEV_CHANGE:
852 BNX2FC_HBA_DBG(lport, "NETDEV_CHANGE\n");
853 break;
854
855 default:
856 printk(KERN_ERR PFX "Unkonwn netevent %ld", event);
857 return;
858 }
859
860 bnx2fc_link_speed_update(lport);
861
862 if (link_possible && !bnx2fc_link_ok(lport)) {
863 printk(KERN_ERR "indicate_netevent: call ctlr_link_up\n");
864 fcoe_ctlr_link_up(&hba->ctlr);
865 } else {
866 printk(KERN_ERR "indicate_netevent: call ctlr_link_down\n");
867 if (fcoe_ctlr_link_down(&hba->ctlr)) {
868 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
869 mutex_lock(&lport->lp_mutex);
870 list_for_each_entry(vport, &lport->vports, list)
871 fc_host_port_type(vport->host) =
872 FC_PORTTYPE_UNKNOWN;
873 mutex_unlock(&lport->lp_mutex);
874 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
875 per_cpu_ptr(lport->dev_stats,
876 get_cpu())->LinkFailureCount++;
877 put_cpu();
878 fcoe_clean_pending_queue(lport);
879
880 init_waitqueue_head(&hba->shutdown_wait);
881 BNX2FC_HBA_DBG(lport, "indicate_netevent "
882 "num_ofld_sess = %d\n",
883 hba->num_ofld_sess);
884 hba->wait_for_link_down = 1;
885 BNX2FC_HBA_DBG(lport, "waiting for uploads to "
886 "compl proc = %s\n",
887 current->comm);
888 wait_event_interruptible(hba->shutdown_wait,
889 (hba->num_ofld_sess == 0));
890 BNX2FC_HBA_DBG(lport, "wakeup - num_ofld_sess = %d\n",
891 hba->num_ofld_sess);
892 hba->wait_for_link_down = 0;
893
894 if (signal_pending(current))
895 flush_signals(current);
896 }
897 }
898}
899
900static int bnx2fc_libfc_config(struct fc_lport *lport)
901{
902
903 /* Set the function pointers set by bnx2fc driver */
904 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
905 sizeof(struct libfc_function_template));
906 fc_elsct_init(lport);
907 fc_exch_init(lport);
908 fc_rport_init(lport);
909 fc_disc_init(lport);
910 return 0;
911}
912
913static int bnx2fc_em_config(struct fc_lport *lport)
914{
915 struct fcoe_port *port = lport_priv(lport);
916 struct bnx2fc_hba *hba = port->priv;
917
918 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
919 FCOE_MAX_XID, NULL)) {
920 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
921 return -ENOMEM;
922 }
923
924 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
925 BNX2FC_MAX_XID);
926
927 if (!hba->cmd_mgr) {
928 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
929 fc_exch_mgr_free(lport);
930 return -ENOMEM;
931 }
932 return 0;
933}
934
935static int bnx2fc_lport_config(struct fc_lport *lport)
936{
937 lport->link_up = 0;
938 lport->qfull = 0;
939 lport->max_retry_count = 3;
940 lport->max_rport_retry_count = 3;
941 lport->e_d_tov = 2 * 1000;
942 lport->r_a_tov = 10 * 1000;
943
944 /* REVISIT: enable when supporting tape devices
945 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
946 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
947 */
948 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS);
949 lport->does_npiv = 1;
950
951 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
952 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
953
954 /* alloc stats structure */
955 if (fc_lport_init_stats(lport))
956 return -ENOMEM;
957
958 /* Finish fc_lport configuration */
959 fc_lport_config(lport);
960
961 return 0;
962}
963
964/**
965 * bnx2fc_fip_recv - handle a received FIP frame.
966 *
967 * @skb: the received skb
968 * @dev: associated &net_device
969 * @ptype: the &packet_type structure which was used to register this handler.
970 * @orig_dev: original receive &net_device, in case @ dev is a bond.
971 *
972 * Returns: 0 for success
973 */
974static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
975 struct packet_type *ptype,
976 struct net_device *orig_dev)
977{
978 struct bnx2fc_hba *hba;
979 hba = container_of(ptype, struct bnx2fc_hba, fip_packet_type);
980 fcoe_ctlr_recv(&hba->ctlr, skb);
981 return 0;
982}
983
984/**
985 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
986 *
987 * @fip: FCoE controller.
988 * @old: Unicast MAC address to delete if the MAC is non-zero.
989 * @new: Unicast MAC address to add.
990 *
991 * Remove any previously-set unicast MAC filter.
992 * Add secondary FCoE MAC address filter for our OUI.
993 */
994static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
995{
996 struct fcoe_port *port = lport_priv(lport);
997
998 memcpy(port->data_src_addr, addr, ETH_ALEN);
999}
1000
1001/**
1002 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1003 *
1004 * @lport: libfc port
1005 */
1006static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1007{
1008 struct fcoe_port *port;
1009
1010 port = (struct fcoe_port *)lport_priv(lport);
1011 return port->data_src_addr;
1012}
1013
1014/**
1015 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1016 *
1017 * @fip: FCoE controller.
1018 * @skb: FIP Packet.
1019 */
1020static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1021{
1022 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1023 dev_queue_xmit(skb);
1024}
1025
1026static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1027{
1028 struct Scsi_Host *shost = vport_to_shost(vport);
1029 struct fc_lport *n_port = shost_priv(shost);
1030 struct fcoe_port *port = lport_priv(n_port);
1031 struct bnx2fc_hba *hba = port->priv;
1032 struct net_device *netdev = hba->netdev;
1033 struct fc_lport *vn_port;
1034
1035 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1036 printk(KERN_ERR PFX "vn ports cannot be created on"
1037 "this hba\n");
1038 return -EIO;
1039 }
1040 mutex_lock(&bnx2fc_dev_lock);
1041 vn_port = bnx2fc_if_create(hba, &vport->dev, 1);
1042 mutex_unlock(&bnx2fc_dev_lock);
1043
1044 if (IS_ERR(vn_port)) {
1045 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1046 netdev->name);
1047 return -EIO;
1048 }
1049
1050 if (disabled) {
1051 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1052 } else {
1053 vn_port->boot_time = jiffies;
1054 fc_lport_init(vn_port);
1055 fc_fabric_login(vn_port);
1056 fc_vport_setlink(vn_port);
1057 }
1058 return 0;
1059}
1060
1061static int bnx2fc_vport_destroy(struct fc_vport *vport)
1062{
1063 struct Scsi_Host *shost = vport_to_shost(vport);
1064 struct fc_lport *n_port = shost_priv(shost);
1065 struct fc_lport *vn_port = vport->dd_data;
1066 struct fcoe_port *port = lport_priv(vn_port);
1067
1068 mutex_lock(&n_port->lp_mutex);
1069 list_del(&vn_port->list);
1070 mutex_unlock(&n_port->lp_mutex);
1071 queue_work(bnx2fc_wq, &port->destroy_work);
1072 return 0;
1073}
1074
1075static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1076{
1077 struct fc_lport *lport = vport->dd_data;
1078
1079 if (disable) {
1080 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1081 fc_fabric_logoff(lport);
1082 } else {
1083 lport->boot_time = jiffies;
1084 fc_fabric_login(lport);
1085 fc_vport_setlink(lport);
1086 }
1087 return 0;
1088}
1089
1090
1091static int bnx2fc_netdev_setup(struct bnx2fc_hba *hba)
1092{
1093 struct net_device *netdev = hba->netdev;
1094 struct net_device *physdev = hba->phys_dev;
1095 struct netdev_hw_addr *ha;
1096 int sel_san_mac = 0;
1097
1098 /* Do not support for bonding device */
1099 if ((netdev->priv_flags & IFF_MASTER_ALB) ||
1100 (netdev->priv_flags & IFF_SLAVE_INACTIVE) ||
1101 (netdev->priv_flags & IFF_MASTER_8023AD)) {
1102 return -EOPNOTSUPP;
1103 }
1104
1105 /* setup Source MAC Address */
1106 rcu_read_lock();
1107 for_each_dev_addr(physdev, ha) {
1108 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1109 ha->type);
1110 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1111 ha->addr[1], ha->addr[2], ha->addr[3],
1112 ha->addr[4], ha->addr[5]);
1113
1114 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1115 (is_valid_ether_addr(ha->addr))) {
1116 memcpy(hba->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
1117 sel_san_mac = 1;
1118 BNX2FC_MISC_DBG("Found SAN MAC\n");
1119 }
1120 }
1121 rcu_read_unlock();
1122
1123 if (!sel_san_mac)
1124 return -ENODEV;
1125
1126 hba->fip_packet_type.func = bnx2fc_fip_recv;
1127 hba->fip_packet_type.type = htons(ETH_P_FIP);
1128 hba->fip_packet_type.dev = netdev;
1129 dev_add_pack(&hba->fip_packet_type);
1130
1131 hba->fcoe_packet_type.func = bnx2fc_rcv;
1132 hba->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1133 hba->fcoe_packet_type.dev = netdev;
1134 dev_add_pack(&hba->fcoe_packet_type);
1135
1136 return 0;
1137}
1138
1139static int bnx2fc_attach_transport(void)
1140{
1141 bnx2fc_transport_template =
1142 fc_attach_transport(&bnx2fc_transport_function);
1143
1144 if (bnx2fc_transport_template == NULL) {
1145 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1146 return -ENODEV;
1147 }
1148
1149 bnx2fc_vport_xport_template =
1150 fc_attach_transport(&bnx2fc_vport_xport_function);
1151 if (bnx2fc_vport_xport_template == NULL) {
1152 printk(KERN_ERR PFX
1153 "Failed to attach FC transport for vport\n");
1154 fc_release_transport(bnx2fc_transport_template);
1155 bnx2fc_transport_template = NULL;
1156 return -ENODEV;
1157 }
1158 return 0;
1159}
1160static void bnx2fc_release_transport(void)
1161{
1162 fc_release_transport(bnx2fc_transport_template);
1163 fc_release_transport(bnx2fc_vport_xport_template);
1164 bnx2fc_transport_template = NULL;
1165 bnx2fc_vport_xport_template = NULL;
1166}
1167
1168static void bnx2fc_interface_release(struct kref *kref)
1169{
1170 struct bnx2fc_hba *hba;
1171 struct net_device *netdev;
1172 struct net_device *phys_dev;
1173
1174 hba = container_of(kref, struct bnx2fc_hba, kref);
1175 BNX2FC_HBA_DBG(hba->ctlr.lp, "Interface is being released\n");
1176
1177 netdev = hba->netdev;
1178 phys_dev = hba->phys_dev;
1179
1180 /* tear-down FIP controller */
1181 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done))
1182 fcoe_ctlr_destroy(&hba->ctlr);
1183
1184 /* Free the command manager */
1185 if (hba->cmd_mgr) {
1186 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1187 hba->cmd_mgr = NULL;
1188 }
1189 dev_put(netdev);
1190 module_put(THIS_MODULE);
1191}
1192
1193static inline void bnx2fc_interface_get(struct bnx2fc_hba *hba)
1194{
1195 kref_get(&hba->kref);
1196}
1197
1198static inline void bnx2fc_interface_put(struct bnx2fc_hba *hba)
1199{
1200 kref_put(&hba->kref, bnx2fc_interface_release);
1201}
1202static void bnx2fc_interface_destroy(struct bnx2fc_hba *hba)
1203{
1204 bnx2fc_unbind_pcidev(hba);
1205 kfree(hba);
1206}
1207
1208/**
1209 * bnx2fc_interface_create - create a new fcoe instance
1210 *
1211 * @cnic: pointer to cnic device
1212 *
1213 * Creates a new FCoE instance on the given device which include allocating
1214 * hba structure, scsi_host and lport structures.
1215 */
1216static struct bnx2fc_hba *bnx2fc_interface_create(struct cnic_dev *cnic)
1217{
1218 struct bnx2fc_hba *hba;
1219 int rc;
1220
1221 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1222 if (!hba) {
1223 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1224 return NULL;
1225 }
1226 spin_lock_init(&hba->hba_lock);
1227 mutex_init(&hba->hba_mutex);
1228
1229 hba->cnic = cnic;
1230 rc = bnx2fc_bind_pcidev(hba);
1231 if (rc)
1232 goto bind_err;
1233 hba->phys_dev = cnic->netdev;
1234 /* will get overwritten after we do vlan discovery */
1235 hba->netdev = hba->phys_dev;
1236
1237 init_waitqueue_head(&hba->shutdown_wait);
1238 init_waitqueue_head(&hba->destroy_wait);
1239
1240 return hba;
1241bind_err:
1242 printk(KERN_ERR PFX "create_interface: bind error\n");
1243 kfree(hba);
1244 return NULL;
1245}
1246
1247static int bnx2fc_interface_setup(struct bnx2fc_hba *hba,
1248 enum fip_state fip_mode)
1249{
1250 int rc = 0;
1251 struct net_device *netdev = hba->netdev;
1252 struct fcoe_ctlr *fip = &hba->ctlr;
1253
1254 dev_hold(netdev);
1255 kref_init(&hba->kref);
1256
1257 hba->flags = 0;
1258
1259 /* Initialize FIP */
1260 memset(fip, 0, sizeof(*fip));
1261 fcoe_ctlr_init(fip, fip_mode);
1262 hba->ctlr.send = bnx2fc_fip_send;
1263 hba->ctlr.update_mac = bnx2fc_update_src_mac;
1264 hba->ctlr.get_src_addr = bnx2fc_get_src_mac;
1265 set_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done);
1266
1267 rc = bnx2fc_netdev_setup(hba);
1268 if (rc)
1269 goto setup_err;
1270
1271 hba->next_conn_id = 0;
1272
1273 memset(hba->tgt_ofld_list, 0, sizeof(hba->tgt_ofld_list));
1274 hba->num_ofld_sess = 0;
1275
1276 return 0;
1277
1278setup_err:
1279 fcoe_ctlr_destroy(&hba->ctlr);
1280 dev_put(netdev);
1281 bnx2fc_interface_put(hba);
1282 return rc;
1283}
1284
1285/**
1286 * bnx2fc_if_create - Create FCoE instance on a given interface
1287 *
1288 * @hba: FCoE interface to create a local port on
1289 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1290 * @npiv: Indicates if the port is vport or not
1291 *
1292 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1293 *
1294 * Returns: Allocated fc_lport or an error pointer
1295 */
1296static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
1297 struct device *parent, int npiv)
1298{
1299 struct fc_lport *lport = NULL;
1300 struct fcoe_port *port;
1301 struct Scsi_Host *shost;
1302 struct fc_vport *vport = dev_to_vport(parent);
1303 int rc = 0;
1304
1305 /* Allocate Scsi_Host structure */
1306 if (!npiv) {
1307 lport = libfc_host_alloc(&bnx2fc_shost_template,
1308 sizeof(struct fcoe_port));
1309 } else {
1310 lport = libfc_vport_create(vport,
1311 sizeof(struct fcoe_port));
1312 }
1313
1314 if (!lport) {
1315 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1316 return NULL;
1317 }
1318 shost = lport->host;
1319 port = lport_priv(lport);
1320 port->lport = lport;
1321 port->priv = hba;
1322 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1323
1324 /* Configure fcoe_port */
1325 rc = bnx2fc_lport_config(lport);
1326 if (rc)
1327 goto lp_config_err;
1328
1329 if (npiv) {
1330 vport = dev_to_vport(parent);
1331 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1332 vport->node_name, vport->port_name);
1333 fc_set_wwnn(lport, vport->node_name);
1334 fc_set_wwpn(lport, vport->port_name);
1335 }
1336 /* Configure netdev and networking properties of the lport */
1337 rc = bnx2fc_net_config(lport);
1338 if (rc) {
1339 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1340 goto lp_config_err;
1341 }
1342
1343 rc = bnx2fc_shost_config(lport, parent);
1344 if (rc) {
1345 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
1346 hba->netdev->name);
1347 goto lp_config_err;
1348 }
1349
1350 /* Initialize the libfc library */
1351 rc = bnx2fc_libfc_config(lport);
1352 if (rc) {
1353 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1354 goto shost_err;
1355 }
1356 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1357
1358 /* Allocate exchange manager */
1359 if (!npiv) {
1360 rc = bnx2fc_em_config(lport);
1361 if (rc) {
1362 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1363 goto shost_err;
1364 }
1365 }
1366
1367 bnx2fc_interface_get(hba);
1368 return lport;
1369
1370shost_err:
1371 scsi_remove_host(shost);
1372lp_config_err:
1373 scsi_host_put(lport->host);
1374 return NULL;
1375}
1376
1377static void bnx2fc_netdev_cleanup(struct bnx2fc_hba *hba)
1378{
1379 /* Dont listen for Ethernet packets anymore */
1380 __dev_remove_pack(&hba->fcoe_packet_type);
1381 __dev_remove_pack(&hba->fip_packet_type);
1382 synchronize_net();
1383}
1384
1385static void bnx2fc_if_destroy(struct fc_lport *lport)
1386{
1387 struct fcoe_port *port = lport_priv(lport);
1388 struct bnx2fc_hba *hba = port->priv;
1389
1390 BNX2FC_HBA_DBG(hba->ctlr.lp, "ENTERED bnx2fc_if_destroy\n");
1391 /* Stop the transmit retry timer */
1392 del_timer_sync(&port->timer);
1393
1394 /* Free existing transmit skbs */
1395 fcoe_clean_pending_queue(lport);
1396
1397 bnx2fc_interface_put(hba);
1398
1399 /* Free queued packets for the receive thread */
1400 bnx2fc_clean_rx_queue(lport);
1401
1402 /* Detach from scsi-ml */
1403 fc_remove_host(lport->host);
1404 scsi_remove_host(lport->host);
1405
1406 /*
1407 * Note that only the physical lport will have the exchange manager.
1408 * for vports, this function is NOP
1409 */
1410 fc_exch_mgr_free(lport);
1411
1412 /* Free memory used by statistical counters */
1413 fc_lport_free_stats(lport);
1414
1415 /* Release Scsi_Host */
1416 scsi_host_put(lport->host);
1417}
1418
1419/**
1420 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1421 *
1422 * @buffer: The name of the Ethernet interface to be destroyed
1423 * @kp: The associated kernel parameter
1424 *
1425 * Called from sysfs.
1426 *
1427 * Returns: 0 for success
1428 */
1429static int bnx2fc_destroy(struct net_device *netdev)
1430{
1431 struct bnx2fc_hba *hba = NULL;
1432 struct net_device *phys_dev;
1433 int rc = 0;
1434
1435 if (!rtnl_trylock())
1436 return restart_syscall();
1437
1438 mutex_lock(&bnx2fc_dev_lock);
1439#ifdef CONFIG_SCSI_BNX2X_FCOE_MODULE
1440 if (THIS_MODULE->state != MODULE_STATE_LIVE) {
1441 rc = -ENODEV;
1442 goto netdev_err;
1443 }
1444#endif
1445 /* obtain physical netdev */
1446 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1447 phys_dev = vlan_dev_real_dev(netdev);
1448 else {
1449 printk(KERN_ERR PFX "Not a vlan device\n");
1450 rc = -ENODEV;
1451 goto netdev_err;
1452 }
1453
1454 hba = bnx2fc_hba_lookup(phys_dev);
1455 if (!hba || !hba->ctlr.lp) {
1456 rc = -ENODEV;
1457 printk(KERN_ERR PFX "bnx2fc_destroy: hba or lport not found\n");
1458 goto netdev_err;
1459 }
1460
1461 if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1462 printk(KERN_ERR PFX "bnx2fc_destroy: Create not called\n");
1463 goto netdev_err;
1464 }
1465
1466 bnx2fc_netdev_cleanup(hba);
1467
1468 bnx2fc_stop(hba);
1469
1470 bnx2fc_if_destroy(hba->ctlr.lp);
1471
1472 destroy_workqueue(hba->timer_work_queue);
1473
1474 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done))
1475 bnx2fc_fw_destroy(hba);
1476
1477 clear_bit(BNX2FC_CREATE_DONE, &hba->init_done);
1478netdev_err:
1479 mutex_unlock(&bnx2fc_dev_lock);
1480 rtnl_unlock();
1481 return rc;
1482}
1483
1484static void bnx2fc_destroy_work(struct work_struct *work)
1485{
1486 struct fcoe_port *port;
1487 struct fc_lport *lport;
1488
1489 port = container_of(work, struct fcoe_port, destroy_work);
1490 lport = port->lport;
1491
1492 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1493
1494 bnx2fc_port_shutdown(lport);
1495 rtnl_lock();
1496 mutex_lock(&bnx2fc_dev_lock);
1497 bnx2fc_if_destroy(lport);
1498 mutex_unlock(&bnx2fc_dev_lock);
1499 rtnl_unlock();
1500}
1501
1502static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1503{
1504 bnx2fc_free_fw_resc(hba);
1505 bnx2fc_free_task_ctx(hba);
1506}
1507
1508/**
1509 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1510 * pci structure
1511 *
1512 * @hba: Adapter instance
1513 */
1514static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1515{
1516 if (bnx2fc_setup_task_ctx(hba))
1517 goto mem_err;
1518
1519 if (bnx2fc_setup_fw_resc(hba))
1520 goto mem_err;
1521
1522 return 0;
1523mem_err:
1524 bnx2fc_unbind_adapter_devices(hba);
1525 return -ENOMEM;
1526}
1527
1528static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1529{
1530 struct cnic_dev *cnic;
1531
1532 if (!hba->cnic) {
1533 printk(KERN_ERR PFX "cnic is NULL\n");
1534 return -ENODEV;
1535 }
1536 cnic = hba->cnic;
1537 hba->pcidev = cnic->pcidev;
1538 if (hba->pcidev)
1539 pci_dev_get(hba->pcidev);
1540
1541 return 0;
1542}
1543
1544static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1545{
1546 if (hba->pcidev)
1547 pci_dev_put(hba->pcidev);
1548 hba->pcidev = NULL;
1549}
1550
1551
1552
1553/**
1554 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1555 *
1556 * @handle: transport handle pointing to adapter struture
1557 *
1558 * This function maps adapter structure to pcidev structure and initiates
1559 * firmware handshake to enable/initialize on-chip FCoE components.
1560 * This bnx2fc - cnic interface api callback is used after following
1561 * conditions are met -
1562 * a) underlying network interface is up (marked by event NETDEV_UP
1563 * from netdev
1564 * b) bnx2fc adatper structure is registered.
1565 */
1566static void bnx2fc_ulp_start(void *handle)
1567{
1568 struct bnx2fc_hba *hba = handle;
1569 struct fc_lport *lport = hba->ctlr.lp;
1570
1571 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1572 mutex_lock(&bnx2fc_dev_lock);
1573
1574 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done))
1575 goto start_disc;
1576
1577 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done))
1578 bnx2fc_fw_init(hba);
1579
1580start_disc:
1581 mutex_unlock(&bnx2fc_dev_lock);
1582
1583 BNX2FC_MISC_DBG("bnx2fc started.\n");
1584
1585 /* Kick off Fabric discovery*/
1586 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1587 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1588 lport->tt.frame_send = bnx2fc_xmit;
1589 bnx2fc_start_disc(hba);
1590 }
1591}
1592
1593static void bnx2fc_port_shutdown(struct fc_lport *lport)
1594{
1595 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1596 fc_fabric_logoff(lport);
1597 fc_lport_destroy(lport);
1598}
1599
1600static void bnx2fc_stop(struct bnx2fc_hba *hba)
1601{
1602 struct fc_lport *lport;
1603 struct fc_lport *vport;
1604
1605 BNX2FC_MISC_DBG("ENTERED %s - init_done = %ld\n", __func__,
1606 hba->init_done);
1607 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done) &&
1608 test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1609 lport = hba->ctlr.lp;
1610 bnx2fc_port_shutdown(lport);
1611 BNX2FC_HBA_DBG(lport, "bnx2fc_stop: waiting for %d "
1612 "offloaded sessions\n",
1613 hba->num_ofld_sess);
1614 wait_event_interruptible(hba->shutdown_wait,
1615 (hba->num_ofld_sess == 0));
1616 mutex_lock(&lport->lp_mutex);
1617 list_for_each_entry(vport, &lport->vports, list)
1618 fc_host_port_type(vport->host) = FC_PORTTYPE_UNKNOWN;
1619 mutex_unlock(&lport->lp_mutex);
1620 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1621 fcoe_ctlr_link_down(&hba->ctlr);
1622 fcoe_clean_pending_queue(lport);
1623
1624 mutex_lock(&hba->hba_mutex);
1625 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1626 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
1627
1628 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1629 mutex_unlock(&hba->hba_mutex);
1630 }
1631}
1632
1633static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1634{
1635#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1636 int rc = -1;
1637 int i = HZ;
1638
1639 rc = bnx2fc_bind_adapter_devices(hba);
1640 if (rc) {
1641 printk(KERN_ALERT PFX
1642 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1643 goto err_out;
1644 }
1645
1646 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1647 if (rc) {
1648 printk(KERN_ALERT PFX
1649 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1650 goto err_unbind;
1651 }
1652
1653 /*
1654 * Wait until the adapter init message is complete, and adapter
1655 * state is UP.
1656 */
1657 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1658 msleep(BNX2FC_INIT_POLL_TIME);
1659
1660 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1661 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1662 "Ignoring...\n",
1663 hba->cnic->netdev->name);
1664 rc = -1;
1665 goto err_unbind;
1666 }
1667
1668
1669 /* Mark HBA to indicate that the FW INIT is done */
1670 set_bit(BNX2FC_FW_INIT_DONE, &hba->init_done);
1671 return 0;
1672
1673err_unbind:
1674 bnx2fc_unbind_adapter_devices(hba);
1675err_out:
1676 return rc;
1677}
1678
1679static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1680{
1681 if (test_and_clear_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1682 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1683 init_timer(&hba->destroy_timer);
1684 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1685 jiffies;
1686 hba->destroy_timer.function = bnx2fc_destroy_timer;
1687 hba->destroy_timer.data = (unsigned long)hba;
1688 add_timer(&hba->destroy_timer);
1689 wait_event_interruptible(hba->destroy_wait,
1690 (hba->flags &
1691 BNX2FC_FLAG_DESTROY_CMPL));
1692 /* This should never happen */
1693 if (signal_pending(current))
1694 flush_signals(current);
1695
1696 del_timer_sync(&hba->destroy_timer);
1697 }
1698 bnx2fc_unbind_adapter_devices(hba);
1699 }
1700}
1701
1702/**
1703 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1704 *
1705 * @handle: transport handle pointing to adapter structure
1706 *
1707 * Driver checks if adapter is already in shutdown mode, if not start
1708 * the shutdown process.
1709 */
1710static void bnx2fc_ulp_stop(void *handle)
1711{
1712 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)handle;
1713
1714 printk(KERN_ERR "ULP_STOP\n");
1715
1716 mutex_lock(&bnx2fc_dev_lock);
1717 bnx2fc_stop(hba);
1718 bnx2fc_fw_destroy(hba);
1719 mutex_unlock(&bnx2fc_dev_lock);
1720}
1721
1722static void bnx2fc_start_disc(struct bnx2fc_hba *hba)
1723{
1724 struct fc_lport *lport;
1725 int wait_cnt = 0;
1726
1727 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1728 /* Kick off FIP/FLOGI */
1729 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1730 printk(KERN_ERR PFX "Init not done yet\n");
1731 return;
1732 }
1733
1734 lport = hba->ctlr.lp;
1735 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1736
1737 if (!bnx2fc_link_ok(lport)) {
1738 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
1739 fcoe_ctlr_link_up(&hba->ctlr);
1740 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
1741 set_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1742 }
1743
1744 /* wait for the FCF to be selected before issuing FLOGI */
1745 while (!hba->ctlr.sel_fcf) {
1746 msleep(250);
1747 /* give up after 3 secs */
1748 if (++wait_cnt > 12)
1749 break;
1750 }
1751 fc_lport_init(lport);
1752 fc_fabric_login(lport);
1753}
1754
1755
1756/**
1757 * bnx2fc_ulp_init - Initialize an adapter instance
1758 *
1759 * @dev : cnic device handle
1760 * Called from cnic_register_driver() context to initialize all
1761 * enumerated cnic devices. This routine allocates adapter structure
1762 * and other device specific resources.
1763 */
1764static void bnx2fc_ulp_init(struct cnic_dev *dev)
1765{
1766 struct bnx2fc_hba *hba;
1767 int rc = 0;
1768
1769 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1770 /* bnx2fc works only when bnx2x is loaded */
1771 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
1772 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
1773 " flags: %lx\n",
1774 dev->netdev->name, dev->flags);
1775 return;
1776 }
1777
1778 /* Configure FCoE interface */
1779 hba = bnx2fc_interface_create(dev);
1780 if (!hba) {
1781 printk(KERN_ERR PFX "hba initialization failed\n");
1782 return;
1783 }
1784
1785 /* Add HBA to the adapter list */
1786 mutex_lock(&bnx2fc_dev_lock);
1787 list_add_tail(&hba->link, &adapter_list);
1788 adapter_count++;
1789 mutex_unlock(&bnx2fc_dev_lock);
1790
1791 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1792 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1793 (void *) hba);
1794 if (rc)
1795 printk(KERN_ALERT PFX "register_device failed, rc = %d\n", rc);
1796 else
1797 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1798}
1799
1800
1801static int bnx2fc_disable(struct net_device *netdev)
1802{
1803 struct bnx2fc_hba *hba;
1804 struct net_device *phys_dev;
1805 struct ethtool_drvinfo drvinfo;
1806 int rc = 0;
1807
1808 if (!rtnl_trylock()) {
1809 printk(KERN_ERR PFX "retrying for rtnl_lock\n");
1810 return -EIO;
1811 }
1812
1813 mutex_lock(&bnx2fc_dev_lock);
1814
1815 if (THIS_MODULE->state != MODULE_STATE_LIVE) {
1816 rc = -ENODEV;
1817 goto nodev;
1818 }
1819
1820 /* obtain physical netdev */
1821 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1822 phys_dev = vlan_dev_real_dev(netdev);
1823 else {
1824 printk(KERN_ERR PFX "Not a vlan device\n");
1825 rc = -ENODEV;
1826 goto nodev;
1827 }
1828
1829 /* verify if the physical device is a netxtreme2 device */
1830 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1831 memset(&drvinfo, 0, sizeof(drvinfo));
1832 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1833 if (strcmp(drvinfo.driver, "bnx2x")) {
1834 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1835 rc = -ENODEV;
1836 goto nodev;
1837 }
1838 } else {
1839 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1840 rc = -ENODEV;
1841 goto nodev;
1842 }
1843
1844 printk(KERN_ERR PFX "phys_dev is netxtreme2 device\n");
1845
1846 /* obtain hba and initialize rest of the structure */
1847 hba = bnx2fc_hba_lookup(phys_dev);
1848 if (!hba || !hba->ctlr.lp) {
1849 rc = -ENODEV;
1850 printk(KERN_ERR PFX "bnx2fc_disable: hba or lport not found\n");
1851 } else {
1852 fcoe_ctlr_link_down(&hba->ctlr);
1853 fcoe_clean_pending_queue(hba->ctlr.lp);
1854 }
1855
1856nodev:
1857 mutex_unlock(&bnx2fc_dev_lock);
1858 rtnl_unlock();
1859 return rc;
1860}
1861
1862
1863static int bnx2fc_enable(struct net_device *netdev)
1864{
1865 struct bnx2fc_hba *hba;
1866 struct net_device *phys_dev;
1867 struct ethtool_drvinfo drvinfo;
1868 int rc = 0;
1869
1870 if (!rtnl_trylock()) {
1871 printk(KERN_ERR PFX "retrying for rtnl_lock\n");
1872 return -EIO;
1873 }
1874
1875 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1876 mutex_lock(&bnx2fc_dev_lock);
1877
1878 if (THIS_MODULE->state != MODULE_STATE_LIVE) {
1879 rc = -ENODEV;
1880 goto nodev;
1881 }
1882
1883 /* obtain physical netdev */
1884 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1885 phys_dev = vlan_dev_real_dev(netdev);
1886 else {
1887 printk(KERN_ERR PFX "Not a vlan device\n");
1888 rc = -ENODEV;
1889 goto nodev;
1890 }
1891 /* verify if the physical device is a netxtreme2 device */
1892 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1893 memset(&drvinfo, 0, sizeof(drvinfo));
1894 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1895 if (strcmp(drvinfo.driver, "bnx2x")) {
1896 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1897 rc = -ENODEV;
1898 goto nodev;
1899 }
1900 } else {
1901 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1902 rc = -ENODEV;
1903 goto nodev;
1904 }
1905
1906 /* obtain hba and initialize rest of the structure */
1907 hba = bnx2fc_hba_lookup(phys_dev);
1908 if (!hba || !hba->ctlr.lp) {
1909 rc = -ENODEV;
1910 printk(KERN_ERR PFX "bnx2fc_enable: hba or lport not found\n");
1911 } else if (!bnx2fc_link_ok(hba->ctlr.lp))
1912 fcoe_ctlr_link_up(&hba->ctlr);
1913
1914nodev:
1915 mutex_unlock(&bnx2fc_dev_lock);
1916 rtnl_unlock();
1917 return rc;
1918}
1919
1920/**
1921 * bnx2fc_create - Create bnx2fc FCoE interface
1922 *
1923 * @buffer: The name of Ethernet interface to create on
1924 * @kp: The associated kernel param
1925 *
1926 * Called from sysfs.
1927 *
1928 * Returns: 0 for success
1929 */
1930static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1931{
1932 struct bnx2fc_hba *hba;
1933 struct net_device *phys_dev;
1934 struct fc_lport *lport;
1935 struct ethtool_drvinfo drvinfo;
1936 int rc = 0;
1937 int vlan_id;
1938
1939 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1940 if (fip_mode != FIP_MODE_FABRIC) {
1941 printk(KERN_ERR "fip mode not FABRIC\n");
1942 return -EIO;
1943 }
1944
1945 if (!rtnl_trylock()) {
1946 printk(KERN_ERR "trying for rtnl_lock\n");
1947 return -EIO;
1948 }
1949 mutex_lock(&bnx2fc_dev_lock);
1950
1951#ifdef CONFIG_SCSI_BNX2X_FCOE_MODULE
1952 if (THIS_MODULE->state != MODULE_STATE_LIVE) {
1953 rc = -ENODEV;
1954 goto mod_err;
1955 }
1956#endif
1957
1958 if (!try_module_get(THIS_MODULE)) {
1959 rc = -EINVAL;
1960 goto mod_err;
1961 }
1962
1963 /* obtain physical netdev */
1964 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
1965 phys_dev = vlan_dev_real_dev(netdev);
1966 vlan_id = vlan_dev_vlan_id(netdev);
1967 } else {
1968 printk(KERN_ERR PFX "Not a vlan device\n");
1969 rc = -EINVAL;
1970 goto netdev_err;
1971 }
1972 /* verify if the physical device is a netxtreme2 device */
1973 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1974 memset(&drvinfo, 0, sizeof(drvinfo));
1975 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1976 if (strcmp(drvinfo.driver, "bnx2x")) {
1977 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1978 rc = -EINVAL;
1979 goto netdev_err;
1980 }
1981 } else {
1982 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1983 rc = -EINVAL;
1984 goto netdev_err;
1985 }
1986
1987 /* obtain hba and initialize rest of the structure */
1988 hba = bnx2fc_hba_lookup(phys_dev);
1989 if (!hba) {
1990 rc = -ENODEV;
1991 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
1992 goto netdev_err;
1993 }
1994
1995 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1996 rc = bnx2fc_fw_init(hba);
1997 if (rc)
1998 goto netdev_err;
1999 }
2000
2001 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
2002 rc = -EEXIST;
2003 goto netdev_err;
2004 }
2005
2006 /* update netdev with vlan netdev */
2007 hba->netdev = netdev;
2008 hba->vlan_id = vlan_id;
2009 hba->vlan_enabled = 1;
2010
2011 rc = bnx2fc_interface_setup(hba, fip_mode);
2012 if (rc) {
2013 printk(KERN_ERR PFX "bnx2fc_interface_setup failed\n");
2014 goto ifput_err;
2015 }
2016
2017 hba->timer_work_queue =
2018 create_singlethread_workqueue("bnx2fc_timer_wq");
2019 if (!hba->timer_work_queue) {
2020 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2021 rc = -EINVAL;
2022 goto ifput_err;
2023 }
2024
2025 lport = bnx2fc_if_create(hba, &hba->pcidev->dev, 0);
2026 if (!lport) {
2027 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2028 netdev->name);
2029 bnx2fc_netdev_cleanup(hba);
2030 rc = -EINVAL;
2031 goto if_create_err;
2032 }
2033
2034 lport->boot_time = jiffies;
2035
2036 /* Make this master N_port */
2037 hba->ctlr.lp = lport;
2038
2039 set_bit(BNX2FC_CREATE_DONE, &hba->init_done);
2040 printk(KERN_ERR PFX "create: START DISC\n");
2041 bnx2fc_start_disc(hba);
2042 /*
2043 * Release from kref_init in bnx2fc_interface_setup, on success
2044 * lport should be holding a reference taken in bnx2fc_if_create
2045 */
2046 bnx2fc_interface_put(hba);
2047 /* put netdev that was held while calling dev_get_by_name */
2048 mutex_unlock(&bnx2fc_dev_lock);
2049 rtnl_unlock();
2050 return 0;
2051
2052if_create_err:
2053 destroy_workqueue(hba->timer_work_queue);
2054ifput_err:
2055 bnx2fc_interface_put(hba);
2056netdev_err:
2057 module_put(THIS_MODULE);
2058mod_err:
2059 mutex_unlock(&bnx2fc_dev_lock);
2060 rtnl_unlock();
2061 return rc;
2062}
2063
2064/**
2065 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc adapter instance
2066 *
2067 * @cnic: Pointer to cnic device instance
2068 *
2069 **/
2070static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2071{
2072 struct list_head *list;
2073 struct list_head *temp;
2074 struct bnx2fc_hba *hba;
2075
2076 /* Called with bnx2fc_dev_lock held */
2077 list_for_each_safe(list, temp, &adapter_list) {
2078 hba = (struct bnx2fc_hba *)list;
2079 if (hba->cnic == cnic)
2080 return hba;
2081 }
2082 return NULL;
2083}
2084
2085static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev)
2086{
2087 struct list_head *list;
2088 struct list_head *temp;
2089 struct bnx2fc_hba *hba;
2090
2091 /* Called with bnx2fc_dev_lock held */
2092 list_for_each_safe(list, temp, &adapter_list) {
2093 hba = (struct bnx2fc_hba *)list;
2094 if (hba->phys_dev == phys_dev)
2095 return hba;
2096 }
2097 printk(KERN_ERR PFX "hba_lookup: hba NULL\n");
2098 return NULL;
2099}
2100
2101/**
2102 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2103 *
2104 * @dev cnic device handle
2105 */
2106static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2107{
2108 struct bnx2fc_hba *hba;
2109
2110 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2111
2112 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2113 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2114 dev->netdev->name, dev->flags);
2115 return;
2116 }
2117
2118 mutex_lock(&bnx2fc_dev_lock);
2119 hba = bnx2fc_find_hba_for_cnic(dev);
2120 if (!hba) {
2121 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2122 dev);
2123 mutex_unlock(&bnx2fc_dev_lock);
2124 return;
2125 }
2126
2127 list_del_init(&hba->link);
2128 adapter_count--;
2129
2130 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
2131 /* destroy not called yet, move to quiesced list */
2132 bnx2fc_netdev_cleanup(hba);
2133 bnx2fc_if_destroy(hba->ctlr.lp);
2134 }
2135 mutex_unlock(&bnx2fc_dev_lock);
2136
2137 bnx2fc_ulp_stop(hba);
2138 /* unregister cnic device */
2139 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2140 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2141 bnx2fc_interface_destroy(hba);
2142}
2143
2144/**
2145 * bnx2fc_fcoe_reset - Resets the fcoe
2146 *
2147 * @shost: shost the reset is from
2148 *
2149 * Returns: always 0
2150 */
2151static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2152{
2153 struct fc_lport *lport = shost_priv(shost);
2154 fc_lport_reset(lport);
2155 return 0;
2156}
2157
2158
2159static bool bnx2fc_match(struct net_device *netdev)
2160{
2161 mutex_lock(&bnx2fc_dev_lock);
2162 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2163 struct net_device *phys_dev = vlan_dev_real_dev(netdev);
2164
2165 if (bnx2fc_hba_lookup(phys_dev)) {
2166 mutex_unlock(&bnx2fc_dev_lock);
2167 return true;
2168 }
2169 }
2170 mutex_unlock(&bnx2fc_dev_lock);
2171 return false;
2172}
2173
2174
2175static struct fcoe_transport bnx2fc_transport = {
2176 .name = {"bnx2fc"},
2177 .attached = false,
2178 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2179 .match = bnx2fc_match,
2180 .create = bnx2fc_create,
2181 .destroy = bnx2fc_destroy,
2182 .enable = bnx2fc_enable,
2183 .disable = bnx2fc_disable,
2184};
2185
2186/**
2187 * bnx2fc_percpu_thread_create - Create a receive thread for an
2188 * online CPU
2189 *
2190 * @cpu: cpu index for the online cpu
2191 */
2192static void bnx2fc_percpu_thread_create(unsigned int cpu)
2193{
2194 struct bnx2fc_percpu_s *p;
2195 struct task_struct *thread;
2196
2197 p = &per_cpu(bnx2fc_percpu, cpu);
2198
2199 thread = kthread_create(bnx2fc_percpu_io_thread,
2200 (void *)p,
2201 "bnx2fc_thread/%d", cpu);
2202 /* bind thread to the cpu */
2203 if (likely(!IS_ERR(p->iothread))) {
2204 kthread_bind(thread, cpu);
2205 p->iothread = thread;
2206 wake_up_process(thread);
2207 }
2208}
2209
2210static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2211{
2212 struct bnx2fc_percpu_s *p;
2213 struct task_struct *thread;
2214 struct bnx2fc_work *work, *tmp;
2215 LIST_HEAD(work_list);
2216
2217 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2218
2219 /* Prevent any new work from being queued for this CPU */
2220 p = &per_cpu(bnx2fc_percpu, cpu);
2221 spin_lock_bh(&p->fp_work_lock);
2222 thread = p->iothread;
2223 p->iothread = NULL;
2224
2225
2226 /* Free all work in the list */
2227 list_for_each_entry_safe(work, tmp, &work_list, list) {
2228 list_del_init(&work->list);
2229 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2230 kfree(work);
2231 }
2232
2233 spin_unlock_bh(&p->fp_work_lock);
2234
2235 if (thread)
2236 kthread_stop(thread);
2237}
2238
2239/**
2240 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2241 *
2242 * @nfb: The callback data block
2243 * @action: The event triggering the callback
2244 * @hcpu: The index of the CPU that the event is for
2245 *
2246 * This creates or destroys per-CPU data for fcoe
2247 *
2248 * Returns NOTIFY_OK always.
2249 */
2250static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2251 unsigned long action, void *hcpu)
2252{
2253 unsigned cpu = (unsigned long)hcpu;
2254
2255 switch (action) {
2256 case CPU_ONLINE:
2257 case CPU_ONLINE_FROZEN:
2258 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2259 bnx2fc_percpu_thread_create(cpu);
2260 break;
2261 case CPU_DEAD:
2262 case CPU_DEAD_FROZEN:
2263 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2264 bnx2fc_percpu_thread_destroy(cpu);
2265 break;
2266 default:
2267 break;
2268 }
2269 return NOTIFY_OK;
2270}
2271
2272/**
2273 * bnx2fc_mod_init - module init entry point
2274 *
2275 * Initialize driver wide global data structures, and register
2276 * with cnic module
2277 **/
2278static int __init bnx2fc_mod_init(void)
2279{
2280 struct fcoe_percpu_s *bg;
2281 struct task_struct *l2_thread;
2282 int rc = 0;
2283 unsigned int cpu = 0;
2284 struct bnx2fc_percpu_s *p;
2285
2286 printk(KERN_INFO PFX "%s", version);
2287
2288 /* register as a fcoe transport */
2289 rc = fcoe_transport_attach(&bnx2fc_transport);
2290 if (rc) {
2291 printk(KERN_ERR "failed to register an fcoe transport, check "
2292 "if libfcoe is loaded\n");
2293 goto out;
2294 }
2295
2296 INIT_LIST_HEAD(&adapter_list);
2297 mutex_init(&bnx2fc_dev_lock);
2298 adapter_count = 0;
2299
2300 /* Attach FC transport template */
2301 rc = bnx2fc_attach_transport();
2302 if (rc)
2303 goto detach_ft;
2304
2305 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2306 if (!bnx2fc_wq) {
2307 rc = -ENOMEM;
2308 goto release_bt;
2309 }
2310
2311 bg = &bnx2fc_global;
2312 skb_queue_head_init(&bg->fcoe_rx_list);
2313 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2314 (void *)bg,
2315 "bnx2fc_l2_thread");
2316 if (IS_ERR(l2_thread)) {
2317 rc = PTR_ERR(l2_thread);
2318 goto free_wq;
2319 }
2320 wake_up_process(l2_thread);
2321 spin_lock_bh(&bg->fcoe_rx_list.lock);
2322 bg->thread = l2_thread;
2323 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2324
2325 for_each_possible_cpu(cpu) {
2326 p = &per_cpu(bnx2fc_percpu, cpu);
2327 INIT_LIST_HEAD(&p->work_list);
2328 spin_lock_init(&p->fp_work_lock);
2329 }
2330
2331 for_each_online_cpu(cpu) {
2332 bnx2fc_percpu_thread_create(cpu);
2333 }
2334
2335 /* Initialize per CPU interrupt thread */
2336 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2337
2338 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2339
2340 return 0;
2341
2342free_wq:
2343 destroy_workqueue(bnx2fc_wq);
2344release_bt:
2345 bnx2fc_release_transport();
2346detach_ft:
2347 fcoe_transport_detach(&bnx2fc_transport);
2348out:
2349 return rc;
2350}
2351
2352static void __exit bnx2fc_mod_exit(void)
2353{
2354 LIST_HEAD(to_be_deleted);
2355 struct bnx2fc_hba *hba, *next;
2356 struct fcoe_percpu_s *bg;
2357 struct task_struct *l2_thread;
2358 struct sk_buff *skb;
2359 unsigned int cpu = 0;
2360
2361 /*
2362 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2363 * it will have higher precedence than bnx2fc_dev_lock.
2364 * unregister_device() cannot be called with bnx2fc_dev_lock
2365 * held.
2366 */
2367 mutex_lock(&bnx2fc_dev_lock);
2368 list_splice(&adapter_list, &to_be_deleted);
2369 INIT_LIST_HEAD(&adapter_list);
2370 adapter_count = 0;
2371 mutex_unlock(&bnx2fc_dev_lock);
2372
2373 /* Unregister with cnic */
2374 list_for_each_entry_safe(hba, next, &to_be_deleted, link) {
2375 list_del_init(&hba->link);
2376 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p, kref = %d\n",
2377 hba, atomic_read(&hba->kref.refcount));
2378 bnx2fc_ulp_stop(hba);
2379 /* unregister cnic device */
2380 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2381 &hba->reg_with_cnic))
2382 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2383 bnx2fc_interface_destroy(hba);
2384 }
2385 cnic_unregister_driver(CNIC_ULP_FCOE);
2386
2387 /* Destroy global thread */
2388 bg = &bnx2fc_global;
2389 spin_lock_bh(&bg->fcoe_rx_list.lock);
2390 l2_thread = bg->thread;
2391 bg->thread = NULL;
2392 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2393 kfree_skb(skb);
2394
2395 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2396
2397 if (l2_thread)
2398 kthread_stop(l2_thread);
2399
2400 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2401
2402 /* Destroy per cpu threads */
2403 for_each_online_cpu(cpu) {
2404 bnx2fc_percpu_thread_destroy(cpu);
2405 }
2406
2407 destroy_workqueue(bnx2fc_wq);
2408 /*
2409 * detach from scsi transport
2410 * must happen after all destroys are done
2411 */
2412 bnx2fc_release_transport();
2413
2414 /* detach from fcoe transport */
2415 fcoe_transport_detach(&bnx2fc_transport);
2416}
2417
2418module_init(bnx2fc_mod_init);
2419module_exit(bnx2fc_mod_exit);
2420
2421static struct fc_function_template bnx2fc_transport_function = {
2422 .show_host_node_name = 1,
2423 .show_host_port_name = 1,
2424 .show_host_supported_classes = 1,
2425 .show_host_supported_fc4s = 1,
2426 .show_host_active_fc4s = 1,
2427 .show_host_maxframe_size = 1,
2428
2429 .show_host_port_id = 1,
2430 .show_host_supported_speeds = 1,
2431 .get_host_speed = fc_get_host_speed,
2432 .show_host_speed = 1,
2433 .show_host_port_type = 1,
2434 .get_host_port_state = fc_get_host_port_state,
2435 .show_host_port_state = 1,
2436 .show_host_symbolic_name = 1,
2437
2438 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2439 sizeof(struct bnx2fc_rport)),
2440 .show_rport_maxframe_size = 1,
2441 .show_rport_supported_classes = 1,
2442
2443 .show_host_fabric_name = 1,
2444 .show_starget_node_name = 1,
2445 .show_starget_port_name = 1,
2446 .show_starget_port_id = 1,
2447 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2448 .show_rport_dev_loss_tmo = 1,
2449 .get_fc_host_stats = bnx2fc_get_host_stats,
2450
2451 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2452
2453 .terminate_rport_io = fc_rport_terminate_io,
2454
2455 .vport_create = bnx2fc_vport_create,
2456 .vport_delete = bnx2fc_vport_destroy,
2457 .vport_disable = bnx2fc_vport_disable,
2458};
2459
2460static struct fc_function_template bnx2fc_vport_xport_function = {
2461 .show_host_node_name = 1,
2462 .show_host_port_name = 1,
2463 .show_host_supported_classes = 1,
2464 .show_host_supported_fc4s = 1,
2465 .show_host_active_fc4s = 1,
2466 .show_host_maxframe_size = 1,
2467
2468 .show_host_port_id = 1,
2469 .show_host_supported_speeds = 1,
2470 .get_host_speed = fc_get_host_speed,
2471 .show_host_speed = 1,
2472 .show_host_port_type = 1,
2473 .get_host_port_state = fc_get_host_port_state,
2474 .show_host_port_state = 1,
2475 .show_host_symbolic_name = 1,
2476
2477 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2478 sizeof(struct bnx2fc_rport)),
2479 .show_rport_maxframe_size = 1,
2480 .show_rport_supported_classes = 1,
2481
2482 .show_host_fabric_name = 1,
2483 .show_starget_node_name = 1,
2484 .show_starget_port_name = 1,
2485 .show_starget_port_id = 1,
2486 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2487 .show_rport_dev_loss_tmo = 1,
2488 .get_fc_host_stats = fc_get_host_stats,
2489 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2490 .terminate_rport_io = fc_rport_terminate_io,
2491};
2492
2493/**
2494 * scsi_host_template structure used while registering with SCSI-ml
2495 */
2496static struct scsi_host_template bnx2fc_shost_template = {
2497 .module = THIS_MODULE,
2498 .name = "Broadcom Offload FCoE Initiator",
2499 .queuecommand = bnx2fc_queuecommand,
2500 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2501 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2502 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2503 .eh_host_reset_handler = fc_eh_host_reset,
2504 .slave_alloc = fc_slave_alloc,
2505 .change_queue_depth = fc_change_queue_depth,
2506 .change_queue_type = fc_change_queue_type,
2507 .this_id = -1,
2508 .cmd_per_lun = 3,
2509 .can_queue = (BNX2FC_MAX_OUTSTANDING_CMNDS/2),
2510 .use_clustering = ENABLE_CLUSTERING,
2511 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2512 .max_sectors = 512,
2513};
2514
2515static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2516 .frame_send = bnx2fc_xmit,
2517 .elsct_send = bnx2fc_elsct_send,
2518 .fcp_abort_io = bnx2fc_abort_io,
2519 .fcp_cleanup = bnx2fc_cleanup,
2520 .rport_event_callback = bnx2fc_rport_event_handler,
2521};
2522
2523/**
2524 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2525 * structure carrying callback function pointers
2526 */
2527static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2528 .owner = THIS_MODULE,
2529 .cnic_init = bnx2fc_ulp_init,
2530 .cnic_exit = bnx2fc_ulp_exit,
2531 .cnic_start = bnx2fc_ulp_start,
2532 .cnic_stop = bnx2fc_ulp_stop,
2533 .indicate_kcqes = bnx2fc_indicate_kcqe,
2534 .indicate_netevent = bnx2fc_indicate_netevent,
2535};
diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
new file mode 100644
index 000000000000..4f4096836742
--- /dev/null
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -0,0 +1,1868 @@
1/* bnx2fc_hwi.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * This file contains the code that low level functions that interact
3 * with 57712 FCoE firmware.
4 *
5 * Copyright (c) 2008 - 2010 Broadcom Corporation
6 *
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.
10 *
11 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
12 */
13
14#include "bnx2fc.h"
15
16DECLARE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
17
18static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
19 struct fcoe_kcqe *new_cqe_kcqe);
20static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
21 struct fcoe_kcqe *ofld_kcqe);
22static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
23 struct fcoe_kcqe *ofld_kcqe);
24static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code);
25static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
26 struct fcoe_kcqe *conn_destroy);
27
28int bnx2fc_send_stat_req(struct bnx2fc_hba *hba)
29{
30 struct fcoe_kwqe_stat stat_req;
31 struct kwqe *kwqe_arr[2];
32 int num_kwqes = 1;
33 int rc = 0;
34
35 memset(&stat_req, 0x00, sizeof(struct fcoe_kwqe_stat));
36 stat_req.hdr.op_code = FCOE_KWQE_OPCODE_STAT;
37 stat_req.hdr.flags =
38 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
39
40 stat_req.stat_params_addr_lo = (u32) hba->stats_buf_dma;
41 stat_req.stat_params_addr_hi = (u32) ((u64)hba->stats_buf_dma >> 32);
42
43 kwqe_arr[0] = (struct kwqe *) &stat_req;
44
45 if (hba->cnic && hba->cnic->submit_kwqes)
46 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
47
48 return rc;
49}
50
51/**
52 * bnx2fc_send_fw_fcoe_init_msg - initiates initial handshake with FCoE f/w
53 *
54 * @hba: adapter structure pointer
55 *
56 * Send down FCoE firmware init KWQEs which initiates the initial handshake
57 * with the f/w.
58 *
59 */
60int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba)
61{
62 struct fcoe_kwqe_init1 fcoe_init1;
63 struct fcoe_kwqe_init2 fcoe_init2;
64 struct fcoe_kwqe_init3 fcoe_init3;
65 struct kwqe *kwqe_arr[3];
66 int num_kwqes = 3;
67 int rc = 0;
68
69 if (!hba->cnic) {
70 printk(KERN_ALERT PFX "hba->cnic NULL during fcoe fw init\n");
71 return -ENODEV;
72 }
73
74 /* fill init1 KWQE */
75 memset(&fcoe_init1, 0x00, sizeof(struct fcoe_kwqe_init1));
76 fcoe_init1.hdr.op_code = FCOE_KWQE_OPCODE_INIT1;
77 fcoe_init1.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
78 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
79
80 fcoe_init1.num_tasks = BNX2FC_MAX_TASKS;
81 fcoe_init1.sq_num_wqes = BNX2FC_SQ_WQES_MAX;
82 fcoe_init1.rq_num_wqes = BNX2FC_RQ_WQES_MAX;
83 fcoe_init1.rq_buffer_log_size = BNX2FC_RQ_BUF_LOG_SZ;
84 fcoe_init1.cq_num_wqes = BNX2FC_CQ_WQES_MAX;
85 fcoe_init1.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
86 fcoe_init1.dummy_buffer_addr_hi = (u32) ((u64)hba->dummy_buf_dma >> 32);
87 fcoe_init1.task_list_pbl_addr_lo = (u32) hba->task_ctx_bd_dma;
88 fcoe_init1.task_list_pbl_addr_hi =
89 (u32) ((u64) hba->task_ctx_bd_dma >> 32);
90 fcoe_init1.mtu = hba->netdev->mtu;
91
92 fcoe_init1.flags = (PAGE_SHIFT <<
93 FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT);
94
95 fcoe_init1.num_sessions_log = BNX2FC_NUM_MAX_SESS_LOG;
96
97 /* fill init2 KWQE */
98 memset(&fcoe_init2, 0x00, sizeof(struct fcoe_kwqe_init2));
99 fcoe_init2.hdr.op_code = FCOE_KWQE_OPCODE_INIT2;
100 fcoe_init2.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
101 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
102
103 fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma;
104 fcoe_init2.hash_tbl_pbl_addr_hi = (u32)
105 ((u64) hba->hash_tbl_pbl_dma >> 32);
106
107 fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma;
108 fcoe_init2.t2_hash_tbl_addr_hi = (u32)
109 ((u64) hba->t2_hash_tbl_dma >> 32);
110
111 fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma;
112 fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32)
113 ((u64) hba->t2_hash_tbl_ptr_dma >> 32);
114
115 fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS;
116
117 /* fill init3 KWQE */
118 memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3));
119 fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3;
120 fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
121 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
122 fcoe_init3.error_bit_map_lo = 0xffffffff;
123 fcoe_init3.error_bit_map_hi = 0xffffffff;
124
125
126 kwqe_arr[0] = (struct kwqe *) &fcoe_init1;
127 kwqe_arr[1] = (struct kwqe *) &fcoe_init2;
128 kwqe_arr[2] = (struct kwqe *) &fcoe_init3;
129
130 if (hba->cnic && hba->cnic->submit_kwqes)
131 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
132
133 return rc;
134}
135int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba)
136{
137 struct fcoe_kwqe_destroy fcoe_destroy;
138 struct kwqe *kwqe_arr[2];
139 int num_kwqes = 1;
140 int rc = -1;
141
142 /* fill destroy KWQE */
143 memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy));
144 fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY;
145 fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
146 FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
147 kwqe_arr[0] = (struct kwqe *) &fcoe_destroy;
148
149 if (hba->cnic && hba->cnic->submit_kwqes)
150 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
151 return rc;
152}
153
154/**
155 * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process
156 *
157 * @port: port structure pointer
158 * @tgt: bnx2fc_rport structure pointer
159 */
160int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
161 struct bnx2fc_rport *tgt)
162{
163 struct fc_lport *lport = port->lport;
164 struct bnx2fc_hba *hba = port->priv;
165 struct kwqe *kwqe_arr[4];
166 struct fcoe_kwqe_conn_offload1 ofld_req1;
167 struct fcoe_kwqe_conn_offload2 ofld_req2;
168 struct fcoe_kwqe_conn_offload3 ofld_req3;
169 struct fcoe_kwqe_conn_offload4 ofld_req4;
170 struct fc_rport_priv *rdata = tgt->rdata;
171 struct fc_rport *rport = tgt->rport;
172 int num_kwqes = 4;
173 u32 port_id;
174 int rc = 0;
175 u16 conn_id;
176
177 /* Initialize offload request 1 structure */
178 memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1));
179
180 ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1;
181 ofld_req1.hdr.flags =
182 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
183
184
185 conn_id = (u16)tgt->fcoe_conn_id;
186 ofld_req1.fcoe_conn_id = conn_id;
187
188
189 ofld_req1.sq_addr_lo = (u32) tgt->sq_dma;
190 ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32);
191
192 ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma;
193 ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32);
194
195 ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma;
196 ofld_req1.rq_first_pbe_addr_hi =
197 (u32)((u64) tgt->rq_dma >> 32);
198
199 ofld_req1.rq_prod = 0x8000;
200
201 /* Initialize offload request 2 structure */
202 memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2));
203
204 ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2;
205 ofld_req2.hdr.flags =
206 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
207
208 ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size;
209
210 ofld_req2.cq_addr_lo = (u32) tgt->cq_dma;
211 ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32);
212
213 ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma;
214 ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32);
215
216 ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma;
217 ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32);
218
219 /* Initialize offload request 3 structure */
220 memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3));
221
222 ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3;
223 ofld_req3.hdr.flags =
224 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
225
226 ofld_req3.vlan_tag = hba->vlan_id <<
227 FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
228 ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
229
230 port_id = fc_host_port_id(lport->host);
231 if (port_id == 0) {
232 BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n");
233 return -EINVAL;
234 }
235
236 /*
237 * Store s_id of the initiator for further reference. This will
238 * be used during disable/destroy during linkdown processing as
239 * when the lport is reset, the port_id also is reset to 0
240 */
241 tgt->sid = port_id;
242 ofld_req3.s_id[0] = (port_id & 0x000000FF);
243 ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8;
244 ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16;
245
246 port_id = rport->port_id;
247 ofld_req3.d_id[0] = (port_id & 0x000000FF);
248 ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8;
249 ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16;
250
251 ofld_req3.tx_total_conc_seqs = rdata->max_seq;
252
253 ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq;
254 ofld_req3.rx_max_fc_pay_len = lport->mfs;
255
256 ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS;
257 ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS;
258 ofld_req3.rx_open_seqs_exch_c3 = 1;
259
260 ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma;
261 ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32);
262
263 /* set mul_n_port_ids supported flag to 0, until it is supported */
264 ofld_req3.flags = 0;
265 /*
266 ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) <<
267 FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT);
268 */
269 /* Info from PLOGI response */
270 ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) <<
271 FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT);
272
273 ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) <<
274 FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
275
276 /* vlan flag */
277 ofld_req3.flags |= (hba->vlan_enabled <<
278 FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
279
280 /* C2_VALID and ACK flags are not set as they are not suppported */
281
282
283 /* Initialize offload request 4 structure */
284 memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4));
285 ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4;
286 ofld_req4.hdr.flags =
287 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
288
289 ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20;
290
291
292 ofld_req4.src_mac_addr_lo32[0] = port->data_src_addr[5];
293 /* local mac */
294 ofld_req4.src_mac_addr_lo32[1] = port->data_src_addr[4];
295 ofld_req4.src_mac_addr_lo32[2] = port->data_src_addr[3];
296 ofld_req4.src_mac_addr_lo32[3] = port->data_src_addr[2];
297 ofld_req4.src_mac_addr_hi16[0] = port->data_src_addr[1];
298 ofld_req4.src_mac_addr_hi16[1] = port->data_src_addr[0];
299 ofld_req4.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */
300 ofld_req4.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4];
301 ofld_req4.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3];
302 ofld_req4.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2];
303 ofld_req4.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1];
304 ofld_req4.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0];
305
306 ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
307 ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
308
309 ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma;
310 ofld_req4.confq_pbl_base_addr_hi =
311 (u32)((u64) tgt->confq_pbl_dma >> 32);
312
313 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
314 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
315 kwqe_arr[2] = (struct kwqe *) &ofld_req3;
316 kwqe_arr[3] = (struct kwqe *) &ofld_req4;
317
318 if (hba->cnic && hba->cnic->submit_kwqes)
319 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
320
321 return rc;
322}
323
324/**
325 * bnx2fc_send_session_enable_req - initiates FCoE Session enablement
326 *
327 * @port: port structure pointer
328 * @tgt: bnx2fc_rport structure pointer
329 */
330static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
331 struct bnx2fc_rport *tgt)
332{
333 struct kwqe *kwqe_arr[2];
334 struct bnx2fc_hba *hba = port->priv;
335 struct fcoe_kwqe_conn_enable_disable enbl_req;
336 struct fc_lport *lport = port->lport;
337 struct fc_rport *rport = tgt->rport;
338 int num_kwqes = 1;
339 int rc = 0;
340 u32 port_id;
341
342 memset(&enbl_req, 0x00,
343 sizeof(struct fcoe_kwqe_conn_enable_disable));
344 enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN;
345 enbl_req.hdr.flags =
346 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
347
348 enbl_req.src_mac_addr_lo32[0] = port->data_src_addr[5];
349 /* local mac */
350 enbl_req.src_mac_addr_lo32[1] = port->data_src_addr[4];
351 enbl_req.src_mac_addr_lo32[2] = port->data_src_addr[3];
352 enbl_req.src_mac_addr_lo32[3] = port->data_src_addr[2];
353 enbl_req.src_mac_addr_hi16[0] = port->data_src_addr[1];
354 enbl_req.src_mac_addr_hi16[1] = port->data_src_addr[0];
355
356 enbl_req.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */
357 enbl_req.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4];
358 enbl_req.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3];
359 enbl_req.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2];
360 enbl_req.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1];
361 enbl_req.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0];
362
363 port_id = fc_host_port_id(lport->host);
364 if (port_id != tgt->sid) {
365 printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x,"
366 "sid = 0x%x\n", port_id, tgt->sid);
367 port_id = tgt->sid;
368 }
369 enbl_req.s_id[0] = (port_id & 0x000000FF);
370 enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
371 enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
372
373 port_id = rport->port_id;
374 enbl_req.d_id[0] = (port_id & 0x000000FF);
375 enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
376 enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
377 enbl_req.vlan_tag = hba->vlan_id <<
378 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
379 enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
380 enbl_req.vlan_flag = hba->vlan_enabled;
381 enbl_req.context_id = tgt->context_id;
382 enbl_req.conn_id = tgt->fcoe_conn_id;
383
384 kwqe_arr[0] = (struct kwqe *) &enbl_req;
385
386 if (hba->cnic && hba->cnic->submit_kwqes)
387 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
388 return rc;
389}
390
391/**
392 * bnx2fc_send_session_disable_req - initiates FCoE Session disable
393 *
394 * @port: port structure pointer
395 * @tgt: bnx2fc_rport structure pointer
396 */
397int bnx2fc_send_session_disable_req(struct fcoe_port *port,
398 struct bnx2fc_rport *tgt)
399{
400 struct bnx2fc_hba *hba = port->priv;
401 struct fcoe_kwqe_conn_enable_disable disable_req;
402 struct kwqe *kwqe_arr[2];
403 struct fc_rport *rport = tgt->rport;
404 int num_kwqes = 1;
405 int rc = 0;
406 u32 port_id;
407
408 memset(&disable_req, 0x00,
409 sizeof(struct fcoe_kwqe_conn_enable_disable));
410 disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN;
411 disable_req.hdr.flags =
412 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
413
414 disable_req.src_mac_addr_lo32[0] = port->data_src_addr[5];
415 disable_req.src_mac_addr_lo32[2] = port->data_src_addr[3];
416 disable_req.src_mac_addr_lo32[3] = port->data_src_addr[2];
417 disable_req.src_mac_addr_hi16[0] = port->data_src_addr[1];
418 disable_req.src_mac_addr_hi16[1] = port->data_src_addr[0];
419
420 disable_req.dst_mac_addr_lo32[0] = hba->ctlr.dest_addr[5];/* fcf mac */
421 disable_req.dst_mac_addr_lo32[1] = hba->ctlr.dest_addr[4];
422 disable_req.dst_mac_addr_lo32[2] = hba->ctlr.dest_addr[3];
423 disable_req.dst_mac_addr_lo32[3] = hba->ctlr.dest_addr[2];
424 disable_req.dst_mac_addr_hi16[0] = hba->ctlr.dest_addr[1];
425 disable_req.dst_mac_addr_hi16[1] = hba->ctlr.dest_addr[0];
426
427 port_id = tgt->sid;
428 disable_req.s_id[0] = (port_id & 0x000000FF);
429 disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
430 disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
431
432
433 port_id = rport->port_id;
434 disable_req.d_id[0] = (port_id & 0x000000FF);
435 disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
436 disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
437 disable_req.context_id = tgt->context_id;
438 disable_req.conn_id = tgt->fcoe_conn_id;
439 disable_req.vlan_tag = hba->vlan_id <<
440 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
441 disable_req.vlan_tag |=
442 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
443 disable_req.vlan_flag = hba->vlan_enabled;
444
445 kwqe_arr[0] = (struct kwqe *) &disable_req;
446
447 if (hba->cnic && hba->cnic->submit_kwqes)
448 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
449
450 return rc;
451}
452
453/**
454 * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy
455 *
456 * @port: port structure pointer
457 * @tgt: bnx2fc_rport structure pointer
458 */
459int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
460 struct bnx2fc_rport *tgt)
461{
462 struct fcoe_kwqe_conn_destroy destroy_req;
463 struct kwqe *kwqe_arr[2];
464 int num_kwqes = 1;
465 int rc = 0;
466
467 memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy));
468 destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN;
469 destroy_req.hdr.flags =
470 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
471
472 destroy_req.context_id = tgt->context_id;
473 destroy_req.conn_id = tgt->fcoe_conn_id;
474
475 kwqe_arr[0] = (struct kwqe *) &destroy_req;
476
477 if (hba->cnic && hba->cnic->submit_kwqes)
478 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
479
480 return rc;
481}
482
483static void bnx2fc_unsol_els_work(struct work_struct *work)
484{
485 struct bnx2fc_unsol_els *unsol_els;
486 struct fc_lport *lport;
487 struct fc_frame *fp;
488
489 unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work);
490 lport = unsol_els->lport;
491 fp = unsol_els->fp;
492 fc_exch_recv(lport, fp);
493 kfree(unsol_els);
494}
495
496void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
497 unsigned char *buf,
498 u32 frame_len, u16 l2_oxid)
499{
500 struct fcoe_port *port = tgt->port;
501 struct fc_lport *lport = port->lport;
502 struct bnx2fc_unsol_els *unsol_els;
503 struct fc_frame_header *fh;
504 struct fc_frame *fp;
505 struct sk_buff *skb;
506 u32 payload_len;
507 u32 crc;
508 u8 op;
509
510
511 unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC);
512 if (!unsol_els) {
513 BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n");
514 return;
515 }
516
517 BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
518 l2_oxid, frame_len);
519
520 payload_len = frame_len - sizeof(struct fc_frame_header);
521
522 fp = fc_frame_alloc(lport, payload_len);
523 if (!fp) {
524 printk(KERN_ERR PFX "fc_frame_alloc failure\n");
525 return;
526 }
527
528 fh = (struct fc_frame_header *) fc_frame_header_get(fp);
529 /* Copy FC Frame header and payload into the frame */
530 memcpy(fh, buf, frame_len);
531
532 if (l2_oxid != FC_XID_UNKNOWN)
533 fh->fh_ox_id = htons(l2_oxid);
534
535 skb = fp_skb(fp);
536
537 if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) ||
538 (fh->fh_r_ctl == FC_RCTL_ELS_REP)) {
539
540 if (fh->fh_type == FC_TYPE_ELS) {
541 op = fc_frame_payload_op(fp);
542 if ((op == ELS_TEST) || (op == ELS_ESTC) ||
543 (op == ELS_FAN) || (op == ELS_CSU)) {
544 /*
545 * No need to reply for these
546 * ELS requests
547 */
548 printk(KERN_ERR PFX "dropping ELS 0x%x\n", op);
549 kfree_skb(skb);
550 return;
551 }
552 }
553 crc = fcoe_fc_crc(fp);
554 fc_frame_init(fp);
555 fr_dev(fp) = lport;
556 fr_sof(fp) = FC_SOF_I3;
557 fr_eof(fp) = FC_EOF_T;
558 fr_crc(fp) = cpu_to_le32(~crc);
559 unsol_els->lport = lport;
560 unsol_els->fp = fp;
561 INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
562 queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
563 } else {
564 BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl);
565 kfree_skb(skb);
566 }
567}
568
569static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
570{
571 u8 num_rq;
572 struct fcoe_err_report_entry *err_entry;
573 unsigned char *rq_data;
574 unsigned char *buf = NULL, *buf1;
575 int i;
576 u16 xid;
577 u32 frame_len, len;
578 struct bnx2fc_cmd *io_req = NULL;
579 struct fcoe_task_ctx_entry *task, *task_page;
580 struct bnx2fc_hba *hba = tgt->port->priv;
581 int task_idx, index;
582 int rc = 0;
583
584
585 BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe);
586 switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) {
587 case FCOE_UNSOLICITED_FRAME_CQE_TYPE:
588 frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >>
589 FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT;
590
591 num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ;
592
593 rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq);
594 if (rq_data) {
595 buf = rq_data;
596 } else {
597 buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ),
598 GFP_ATOMIC);
599
600 if (!buf1) {
601 BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n");
602 break;
603 }
604
605 for (i = 0; i < num_rq; i++) {
606 rq_data = (unsigned char *)
607 bnx2fc_get_next_rqe(tgt, 1);
608 len = BNX2FC_RQ_BUF_SZ;
609 memcpy(buf1, rq_data, len);
610 buf1 += len;
611 }
612 }
613 bnx2fc_process_l2_frame_compl(tgt, buf, frame_len,
614 FC_XID_UNKNOWN);
615
616 if (buf != rq_data)
617 kfree(buf);
618 bnx2fc_return_rqe(tgt, num_rq);
619 break;
620
621 case FCOE_ERROR_DETECTION_CQE_TYPE:
622 /*
623 *In case of error reporting CQE a single RQ entry
624 * is consumes.
625 */
626 spin_lock_bh(&tgt->tgt_lock);
627 num_rq = 1;
628 err_entry = (struct fcoe_err_report_entry *)
629 bnx2fc_get_next_rqe(tgt, 1);
630 xid = err_entry->fc_hdr.ox_id;
631 BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid);
632 BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n",
633 err_entry->err_warn_bitmap_hi,
634 err_entry->err_warn_bitmap_lo);
635 BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n",
636 err_entry->tx_buf_off, err_entry->rx_buf_off);
637
638 bnx2fc_return_rqe(tgt, 1);
639
640 if (xid > BNX2FC_MAX_XID) {
641 BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n",
642 xid);
643 spin_unlock_bh(&tgt->tgt_lock);
644 break;
645 }
646
647 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
648 index = xid % BNX2FC_TASKS_PER_PAGE;
649 task_page = (struct fcoe_task_ctx_entry *)
650 hba->task_ctx[task_idx];
651 task = &(task_page[index]);
652
653 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
654 if (!io_req) {
655 spin_unlock_bh(&tgt->tgt_lock);
656 break;
657 }
658
659 if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
660 printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
661 spin_unlock_bh(&tgt->tgt_lock);
662 break;
663 }
664
665 if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
666 &io_req->req_flags)) {
667 BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in "
668 "progress.. ignore unsol err\n");
669 spin_unlock_bh(&tgt->tgt_lock);
670 break;
671 }
672
673 /*
674 * If ABTS is already in progress, and FW error is
675 * received after that, do not cancel the timeout_work
676 * and let the error recovery continue by explicitly
677 * logging out the target, when the ABTS eventually
678 * times out.
679 */
680 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
681 &io_req->req_flags)) {
682 /*
683 * Cancel the timeout_work, as we received IO
684 * completion with FW error.
685 */
686 if (cancel_delayed_work(&io_req->timeout_work))
687 kref_put(&io_req->refcount,
688 bnx2fc_cmd_release); /* timer hold */
689
690 rc = bnx2fc_initiate_abts(io_req);
691 if (rc != SUCCESS) {
692 BNX2FC_IO_DBG(io_req, "err_warn: initiate_abts "
693 "failed. issue cleanup\n");
694 rc = bnx2fc_initiate_cleanup(io_req);
695 BUG_ON(rc);
696 }
697 } else
698 printk(KERN_ERR PFX "err_warn: io_req (0x%x) already "
699 "in ABTS processing\n", xid);
700 spin_unlock_bh(&tgt->tgt_lock);
701 break;
702
703 case FCOE_WARNING_DETECTION_CQE_TYPE:
704 /*
705 *In case of warning reporting CQE a single RQ entry
706 * is consumes.
707 */
708 num_rq = 1;
709 err_entry = (struct fcoe_err_report_entry *)
710 bnx2fc_get_next_rqe(tgt, 1);
711 xid = cpu_to_be16(err_entry->fc_hdr.ox_id);
712 BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid);
713 BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x",
714 err_entry->err_warn_bitmap_hi,
715 err_entry->err_warn_bitmap_lo);
716 BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x",
717 err_entry->tx_buf_off, err_entry->rx_buf_off);
718
719 bnx2fc_return_rqe(tgt, 1);
720 break;
721
722 default:
723 printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n");
724 break;
725 }
726}
727
728void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe)
729{
730 struct fcoe_task_ctx_entry *task;
731 struct fcoe_task_ctx_entry *task_page;
732 struct fcoe_port *port = tgt->port;
733 struct bnx2fc_hba *hba = port->priv;
734 struct bnx2fc_cmd *io_req;
735 int task_idx, index;
736 u16 xid;
737 u8 cmd_type;
738 u8 rx_state = 0;
739 u8 num_rq;
740
741 spin_lock_bh(&tgt->tgt_lock);
742 xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
743 if (xid >= BNX2FC_MAX_TASKS) {
744 printk(KERN_ALERT PFX "ERROR:xid out of range\n");
745 spin_unlock_bh(&tgt->tgt_lock);
746 return;
747 }
748 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
749 index = xid % BNX2FC_TASKS_PER_PAGE;
750 task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx];
751 task = &(task_page[index]);
752
753 num_rq = ((task->rx_wr_tx_rd.rx_flags &
754 FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE) >>
755 FCOE_TASK_CTX_ENTRY_RXWR_TXRD_NUM_RQ_WQE_SHIFT);
756
757 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
758
759 if (io_req == NULL) {
760 printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n");
761 spin_unlock_bh(&tgt->tgt_lock);
762 return;
763 }
764
765 /* Timestamp IO completion time */
766 cmd_type = io_req->cmd_type;
767
768 /* optimized completion path */
769 if (cmd_type == BNX2FC_SCSI_CMD) {
770 rx_state = ((task->rx_wr_tx_rd.rx_flags &
771 FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE) >>
772 FCOE_TASK_CTX_ENTRY_RXWR_TXRD_RX_STATE_SHIFT);
773
774 if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) {
775 bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq);
776 spin_unlock_bh(&tgt->tgt_lock);
777 return;
778 }
779 }
780
781 /* Process other IO completion types */
782 switch (cmd_type) {
783 case BNX2FC_SCSI_CMD:
784 if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
785 bnx2fc_process_abts_compl(io_req, task, num_rq);
786 else if (rx_state ==
787 FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
788 bnx2fc_process_cleanup_compl(io_req, task, num_rq);
789 else
790 printk(KERN_ERR PFX "Invalid rx state - %d\n",
791 rx_state);
792 break;
793
794 case BNX2FC_TASK_MGMT_CMD:
795 BNX2FC_IO_DBG(io_req, "Processing TM complete\n");
796 bnx2fc_process_tm_compl(io_req, task, num_rq);
797 break;
798
799 case BNX2FC_ABTS:
800 /*
801 * ABTS request received by firmware. ABTS response
802 * will be delivered to the task belonging to the IO
803 * that was aborted
804 */
805 BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n");
806 kref_put(&io_req->refcount, bnx2fc_cmd_release);
807 break;
808
809 case BNX2FC_ELS:
810 BNX2FC_IO_DBG(io_req, "cq_compl - call process_els_compl\n");
811 bnx2fc_process_els_compl(io_req, task, num_rq);
812 break;
813
814 case BNX2FC_CLEANUP:
815 BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n");
816 kref_put(&io_req->refcount, bnx2fc_cmd_release);
817 break;
818
819 default:
820 printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type);
821 break;
822 }
823 spin_unlock_bh(&tgt->tgt_lock);
824}
825
826struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe)
827{
828 struct bnx2fc_work *work;
829 work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC);
830 if (!work)
831 return NULL;
832
833 INIT_LIST_HEAD(&work->list);
834 work->tgt = tgt;
835 work->wqe = wqe;
836 return work;
837}
838
839int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
840{
841 struct fcoe_cqe *cq;
842 u32 cq_cons;
843 struct fcoe_cqe *cqe;
844 u16 wqe;
845 bool more_cqes_found = false;
846
847 /*
848 * cq_lock is a low contention lock used to protect
849 * the CQ data structure from being freed up during
850 * the upload operation
851 */
852 spin_lock_bh(&tgt->cq_lock);
853
854 if (!tgt->cq) {
855 printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n");
856 spin_unlock_bh(&tgt->cq_lock);
857 return 0;
858 }
859 cq = tgt->cq;
860 cq_cons = tgt->cq_cons_idx;
861 cqe = &cq[cq_cons];
862
863 do {
864 more_cqes_found ^= true;
865
866 while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) ==
867 (tgt->cq_curr_toggle_bit <<
868 FCOE_CQE_TOGGLE_BIT_SHIFT)) {
869
870 /* new entry on the cq */
871 if (wqe & FCOE_CQE_CQE_TYPE) {
872 /* Unsolicited event notification */
873 bnx2fc_process_unsol_compl(tgt, wqe);
874 } else {
875 struct bnx2fc_work *work = NULL;
876 struct bnx2fc_percpu_s *fps = NULL;
877 unsigned int cpu = wqe % num_possible_cpus();
878
879 fps = &per_cpu(bnx2fc_percpu, cpu);
880 spin_lock_bh(&fps->fp_work_lock);
881 if (unlikely(!fps->iothread))
882 goto unlock;
883
884 work = bnx2fc_alloc_work(tgt, wqe);
885 if (work)
886 list_add_tail(&work->list,
887 &fps->work_list);
888unlock:
889 spin_unlock_bh(&fps->fp_work_lock);
890
891 /* Pending work request completion */
892 if (fps->iothread && work)
893 wake_up_process(fps->iothread);
894 else
895 bnx2fc_process_cq_compl(tgt, wqe);
896 }
897 cqe++;
898 tgt->cq_cons_idx++;
899
900 if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
901 tgt->cq_cons_idx = 0;
902 cqe = cq;
903 tgt->cq_curr_toggle_bit =
904 1 - tgt->cq_curr_toggle_bit;
905 }
906 }
907 /* Re-arm CQ */
908 if (more_cqes_found) {
909 tgt->conn_db->cq_arm.lo = -1;
910 wmb();
911 }
912 } while (more_cqes_found);
913
914 /*
915 * Commit tgt->cq_cons_idx change to the memory
916 * spin_lock implies full memory barrier, no need to smp_wmb
917 */
918
919 spin_unlock_bh(&tgt->cq_lock);
920 return 0;
921}
922
923/**
924 * bnx2fc_fastpath_notification - process global event queue (KCQ)
925 *
926 * @hba: adapter structure pointer
927 * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry
928 *
929 * Fast path event notification handler
930 */
931static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
932 struct fcoe_kcqe *new_cqe_kcqe)
933{
934 u32 conn_id = new_cqe_kcqe->fcoe_conn_id;
935 struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id];
936
937 if (!tgt) {
938 printk(KERN_ALERT PFX "conn_id 0x%x not valid\n", conn_id);
939 return;
940 }
941
942 bnx2fc_process_new_cqes(tgt);
943}
944
945/**
946 * bnx2fc_process_ofld_cmpl - process FCoE session offload completion
947 *
948 * @hba: adapter structure pointer
949 * @ofld_kcqe: connection offload kcqe pointer
950 *
951 * handle session offload completion, enable the session if offload is
952 * successful.
953 */
954static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
955 struct fcoe_kcqe *ofld_kcqe)
956{
957 struct bnx2fc_rport *tgt;
958 struct fcoe_port *port;
959 u32 conn_id;
960 u32 context_id;
961 int rc;
962
963 conn_id = ofld_kcqe->fcoe_conn_id;
964 context_id = ofld_kcqe->fcoe_conn_context_id;
965 tgt = hba->tgt_ofld_list[conn_id];
966 if (!tgt) {
967 printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
968 return;
969 }
970 BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
971 ofld_kcqe->fcoe_conn_context_id);
972 port = tgt->port;
973 if (hba != tgt->port->priv) {
974 printk(KERN_ALERT PFX "ERROR:ofld_cmpl: HBA mis-match\n");
975 goto ofld_cmpl_err;
976 }
977 /*
978 * cnic has allocated a context_id for this session; use this
979 * while enabling the session.
980 */
981 tgt->context_id = context_id;
982 if (ofld_kcqe->completion_status) {
983 if (ofld_kcqe->completion_status ==
984 FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) {
985 printk(KERN_ERR PFX "unable to allocate FCoE context "
986 "resources\n");
987 set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags);
988 }
989 goto ofld_cmpl_err;
990 } else {
991
992 /* now enable the session */
993 rc = bnx2fc_send_session_enable_req(port, tgt);
994 if (rc) {
995 printk(KERN_ALERT PFX "enable session failed\n");
996 goto ofld_cmpl_err;
997 }
998 }
999 return;
1000ofld_cmpl_err:
1001 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1002 wake_up_interruptible(&tgt->ofld_wait);
1003}
1004
1005/**
1006 * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion
1007 *
1008 * @hba: adapter structure pointer
1009 * @ofld_kcqe: connection offload kcqe pointer
1010 *
1011 * handle session enable completion, mark the rport as ready
1012 */
1013
1014static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
1015 struct fcoe_kcqe *ofld_kcqe)
1016{
1017 struct bnx2fc_rport *tgt;
1018 u32 conn_id;
1019 u32 context_id;
1020
1021 context_id = ofld_kcqe->fcoe_conn_context_id;
1022 conn_id = ofld_kcqe->fcoe_conn_id;
1023 tgt = hba->tgt_ofld_list[conn_id];
1024 if (!tgt) {
1025 printk(KERN_ALERT PFX "ERROR:enbl_cmpl: No pending ofld req\n");
1026 return;
1027 }
1028
1029 BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n",
1030 ofld_kcqe->fcoe_conn_context_id);
1031
1032 /*
1033 * context_id should be the same for this target during offload
1034 * and enable
1035 */
1036 if (tgt->context_id != context_id) {
1037 printk(KERN_ALERT PFX "context id mis-match\n");
1038 return;
1039 }
1040 if (hba != tgt->port->priv) {
1041 printk(KERN_ALERT PFX "bnx2fc-enbl_cmpl: HBA mis-match\n");
1042 goto enbl_cmpl_err;
1043 }
1044 if (ofld_kcqe->completion_status) {
1045 goto enbl_cmpl_err;
1046 } else {
1047 /* enable successful - rport ready for issuing IOs */
1048 set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1049 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1050 wake_up_interruptible(&tgt->ofld_wait);
1051 }
1052 return;
1053
1054enbl_cmpl_err:
1055 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
1056 wake_up_interruptible(&tgt->ofld_wait);
1057}
1058
1059static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba,
1060 struct fcoe_kcqe *disable_kcqe)
1061{
1062
1063 struct bnx2fc_rport *tgt;
1064 u32 conn_id;
1065
1066 conn_id = disable_kcqe->fcoe_conn_id;
1067 tgt = hba->tgt_ofld_list[conn_id];
1068 if (!tgt) {
1069 printk(KERN_ALERT PFX "ERROR: disable_cmpl: No disable req\n");
1070 return;
1071 }
1072
1073 BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id);
1074
1075 if (disable_kcqe->completion_status) {
1076 printk(KERN_ALERT PFX "ERROR: Disable failed with cmpl status %d\n",
1077 disable_kcqe->completion_status);
1078 return;
1079 } else {
1080 /* disable successful */
1081 BNX2FC_TGT_DBG(tgt, "disable successful\n");
1082 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1083 set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1084 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1085 wake_up_interruptible(&tgt->upld_wait);
1086 }
1087}
1088
1089static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
1090 struct fcoe_kcqe *destroy_kcqe)
1091{
1092 struct bnx2fc_rport *tgt;
1093 u32 conn_id;
1094
1095 conn_id = destroy_kcqe->fcoe_conn_id;
1096 tgt = hba->tgt_ofld_list[conn_id];
1097 if (!tgt) {
1098 printk(KERN_ALERT PFX "destroy_cmpl: No destroy req\n");
1099 return;
1100 }
1101
1102 BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id);
1103
1104 if (destroy_kcqe->completion_status) {
1105 printk(KERN_ALERT PFX "Destroy conn failed, cmpl status %d\n",
1106 destroy_kcqe->completion_status);
1107 return;
1108 } else {
1109 /* destroy successful */
1110 BNX2FC_TGT_DBG(tgt, "upload successful\n");
1111 clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
1112 set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags);
1113 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
1114 wake_up_interruptible(&tgt->upld_wait);
1115 }
1116}
1117
1118static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code)
1119{
1120 switch (err_code) {
1121 case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE:
1122 printk(KERN_ERR PFX "init_failure due to invalid opcode\n");
1123 break;
1124
1125 case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE:
1126 printk(KERN_ERR PFX "init failed due to ctx alloc failure\n");
1127 break;
1128
1129 case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR:
1130 printk(KERN_ERR PFX "init_failure due to NIC error\n");
1131 break;
1132
1133 default:
1134 printk(KERN_ERR PFX "Unknown Error code %d\n", err_code);
1135 }
1136}
1137
1138/**
1139 * bnx2fc_indicae_kcqe - process KCQE
1140 *
1141 * @hba: adapter structure pointer
1142 * @kcqe: kcqe pointer
1143 * @num_cqe: Number of completion queue elements
1144 *
1145 * Generic KCQ event handler
1146 */
1147void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
1148 u32 num_cqe)
1149{
1150 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
1151 int i = 0;
1152 struct fcoe_kcqe *kcqe = NULL;
1153
1154 while (i < num_cqe) {
1155 kcqe = (struct fcoe_kcqe *) kcq[i++];
1156
1157 switch (kcqe->op_code) {
1158 case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION:
1159 bnx2fc_fastpath_notification(hba, kcqe);
1160 break;
1161
1162 case FCOE_KCQE_OPCODE_OFFLOAD_CONN:
1163 bnx2fc_process_ofld_cmpl(hba, kcqe);
1164 break;
1165
1166 case FCOE_KCQE_OPCODE_ENABLE_CONN:
1167 bnx2fc_process_enable_conn_cmpl(hba, kcqe);
1168 break;
1169
1170 case FCOE_KCQE_OPCODE_INIT_FUNC:
1171 if (kcqe->completion_status !=
1172 FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1173 bnx2fc_init_failure(hba,
1174 kcqe->completion_status);
1175 } else {
1176 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1177 bnx2fc_get_link_state(hba);
1178 printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n",
1179 (u8)hba->pcidev->bus->number);
1180 }
1181 break;
1182
1183 case FCOE_KCQE_OPCODE_DESTROY_FUNC:
1184 if (kcqe->completion_status !=
1185 FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
1186
1187 printk(KERN_ERR PFX "DESTROY failed\n");
1188 } else {
1189 printk(KERN_ERR PFX "DESTROY success\n");
1190 }
1191 hba->flags |= BNX2FC_FLAG_DESTROY_CMPL;
1192 wake_up_interruptible(&hba->destroy_wait);
1193 break;
1194
1195 case FCOE_KCQE_OPCODE_DISABLE_CONN:
1196 bnx2fc_process_conn_disable_cmpl(hba, kcqe);
1197 break;
1198
1199 case FCOE_KCQE_OPCODE_DESTROY_CONN:
1200 bnx2fc_process_conn_destroy_cmpl(hba, kcqe);
1201 break;
1202
1203 case FCOE_KCQE_OPCODE_STAT_FUNC:
1204 if (kcqe->completion_status !=
1205 FCOE_KCQE_COMPLETION_STATUS_SUCCESS)
1206 printk(KERN_ERR PFX "STAT failed\n");
1207 complete(&hba->stat_req_done);
1208 break;
1209
1210 case FCOE_KCQE_OPCODE_FCOE_ERROR:
1211 /* fall thru */
1212 default:
1213 printk(KERN_ALERT PFX "unknown opcode 0x%x\n",
1214 kcqe->op_code);
1215 }
1216 }
1217}
1218
1219void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid)
1220{
1221 struct fcoe_sqe *sqe;
1222
1223 sqe = &tgt->sq[tgt->sq_prod_idx];
1224
1225 /* Fill SQ WQE */
1226 sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT;
1227 sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT;
1228
1229 /* Advance SQ Prod Idx */
1230 if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) {
1231 tgt->sq_prod_idx = 0;
1232 tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit;
1233 }
1234}
1235
1236void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt)
1237{
1238 struct b577xx_doorbell_set_prod ev_doorbell;
1239 u32 msg;
1240
1241 wmb();
1242
1243 memset(&ev_doorbell, 0, sizeof(struct b577xx_doorbell_set_prod));
1244 ev_doorbell.header.header = B577XX_DOORBELL_HDR_DB_TYPE;
1245
1246 ev_doorbell.prod = tgt->sq_prod_idx |
1247 (tgt->sq_curr_toggle_bit << 15);
1248 ev_doorbell.header.header |= B577XX_FCOE_CONNECTION_TYPE <<
1249 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT;
1250 msg = *((u32 *)&ev_doorbell);
1251 writel(cpu_to_le32(msg), tgt->ctx_base);
1252
1253 mmiowb();
1254
1255}
1256
1257int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
1258{
1259 u32 context_id = tgt->context_id;
1260 struct fcoe_port *port = tgt->port;
1261 u32 reg_off;
1262 resource_size_t reg_base;
1263 struct bnx2fc_hba *hba = port->priv;
1264
1265 reg_base = pci_resource_start(hba->pcidev,
1266 BNX2X_DOORBELL_PCI_BAR);
1267 reg_off = BNX2FC_5771X_DB_PAGE_SIZE *
1268 (context_id & 0x1FFFF) + DPM_TRIGER_TYPE;
1269 tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4);
1270 if (!tgt->ctx_base)
1271 return -ENOMEM;
1272 return 0;
1273}
1274
1275char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1276{
1277 char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ);
1278
1279 if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX)
1280 return NULL;
1281
1282 tgt->rq_cons_idx += num_items;
1283
1284 if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX)
1285 tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX;
1286
1287 return buf;
1288}
1289
1290void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items)
1291{
1292 /* return the rq buffer */
1293 u32 next_prod_idx = tgt->rq_prod_idx + num_items;
1294 if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) {
1295 /* Wrap around RQ */
1296 next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX;
1297 }
1298 tgt->rq_prod_idx = next_prod_idx;
1299 tgt->conn_db->rq_prod = tgt->rq_prod_idx;
1300}
1301
1302void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
1303 struct fcoe_task_ctx_entry *task,
1304 u16 orig_xid)
1305{
1306 u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP;
1307 struct bnx2fc_rport *tgt = io_req->tgt;
1308 u32 context_id = tgt->context_id;
1309
1310 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1311
1312 /* Tx Write Rx Read */
1313 task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP <<
1314 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT;
1315 task->tx_wr_rx_rd.init_flags = task_type <<
1316 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT;
1317 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1318 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT;
1319 /* Common */
1320 task->cmn.common_flags = context_id <<
1321 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT;
1322 task->cmn.general.cleanup_info.task_id = orig_xid;
1323
1324
1325}
1326
1327void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
1328 struct fcoe_task_ctx_entry *task)
1329{
1330 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
1331 struct bnx2fc_rport *tgt = io_req->tgt;
1332 struct fc_frame_header *fc_hdr;
1333 u8 task_type = 0;
1334 u64 *hdr;
1335 u64 temp_hdr[3];
1336 u32 context_id;
1337
1338
1339 /* Obtain task_type */
1340 if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) ||
1341 (io_req->cmd_type == BNX2FC_ELS)) {
1342 task_type = FCOE_TASK_TYPE_MIDPATH;
1343 } else if (io_req->cmd_type == BNX2FC_ABTS) {
1344 task_type = FCOE_TASK_TYPE_ABTS;
1345 }
1346
1347 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1348
1349 /* Setup the task from io_req for easy reference */
1350 io_req->task = task;
1351
1352 BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n",
1353 io_req->cmd_type, task_type);
1354
1355 /* Tx only */
1356 if ((task_type == FCOE_TASK_TYPE_MIDPATH) ||
1357 (task_type == FCOE_TASK_TYPE_UNSOLICITED)) {
1358 task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo =
1359 (u32)mp_req->mp_req_bd_dma;
1360 task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi =
1361 (u32)((u64)mp_req->mp_req_bd_dma >> 32);
1362 task->tx_wr_only.sgl_ctx.mul_sges.sgl_size = 1;
1363 BNX2FC_IO_DBG(io_req, "init_mp_task - bd_dma = 0x%llx\n",
1364 (unsigned long long)mp_req->mp_req_bd_dma);
1365 }
1366
1367 /* Tx Write Rx Read */
1368 task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_INIT <<
1369 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT;
1370 task->tx_wr_rx_rd.init_flags = task_type <<
1371 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT;
1372 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_DEV_TYPE_DISK <<
1373 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE_SHIFT;
1374 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1375 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT;
1376
1377 /* Common */
1378 task->cmn.data_2_trns = io_req->data_xfer_len;
1379 context_id = tgt->context_id;
1380 task->cmn.common_flags = context_id <<
1381 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT;
1382 task->cmn.common_flags |= 1 <<
1383 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_VALID_SHIFT;
1384 task->cmn.common_flags |= 1 <<
1385 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME_SHIFT;
1386
1387 /* Rx Write Tx Read */
1388 fc_hdr = &(mp_req->req_fc_hdr);
1389 if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1390 fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid);
1391 fc_hdr->fh_rx_id = htons(0xffff);
1392 task->rx_wr_tx_rd.rx_id = 0xffff;
1393 } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) {
1394 fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid);
1395 }
1396
1397 /* Fill FC Header into middle path buffer */
1398 hdr = (u64 *) &task->cmn.general.cmd_info.mp_fc_frame.fc_hdr;
1399 memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr));
1400 hdr[0] = cpu_to_be64(temp_hdr[0]);
1401 hdr[1] = cpu_to_be64(temp_hdr[1]);
1402 hdr[2] = cpu_to_be64(temp_hdr[2]);
1403
1404 /* Rx Only */
1405 if (task_type == FCOE_TASK_TYPE_MIDPATH) {
1406
1407 task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo =
1408 (u32)mp_req->mp_resp_bd_dma;
1409 task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi =
1410 (u32)((u64)mp_req->mp_resp_bd_dma >> 32);
1411 task->rx_wr_only.sgl_ctx.mul_sges.sgl_size = 1;
1412 }
1413}
1414
1415void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
1416 struct fcoe_task_ctx_entry *task)
1417{
1418 u8 task_type;
1419 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1420 struct io_bdt *bd_tbl = io_req->bd_tbl;
1421 struct bnx2fc_rport *tgt = io_req->tgt;
1422 u64 *fcp_cmnd;
1423 u64 tmp_fcp_cmnd[4];
1424 u32 context_id;
1425 int cnt, i;
1426 int bd_count;
1427
1428 memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
1429
1430 /* Setup the task from io_req for easy reference */
1431 io_req->task = task;
1432
1433 if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
1434 task_type = FCOE_TASK_TYPE_WRITE;
1435 else
1436 task_type = FCOE_TASK_TYPE_READ;
1437
1438 /* Tx only */
1439 if (task_type == FCOE_TASK_TYPE_WRITE) {
1440 task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo =
1441 (u32)bd_tbl->bd_tbl_dma;
1442 task->tx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi =
1443 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1444 task->tx_wr_only.sgl_ctx.mul_sges.sgl_size =
1445 bd_tbl->bd_valid;
1446 }
1447
1448 /*Tx Write Rx Read */
1449 /* Init state to NORMAL */
1450 task->tx_wr_rx_rd.tx_flags = FCOE_TASK_TX_STATE_NORMAL <<
1451 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TX_STATE_SHIFT;
1452 task->tx_wr_rx_rd.init_flags = task_type <<
1453 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_TASK_TYPE_SHIFT;
1454 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_DEV_TYPE_DISK <<
1455 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_DEV_TYPE_SHIFT;
1456 task->tx_wr_rx_rd.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
1457 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_CLASS_TYPE_SHIFT;
1458
1459 /* Common */
1460 task->cmn.data_2_trns = io_req->data_xfer_len;
1461 context_id = tgt->context_id;
1462 task->cmn.common_flags = context_id <<
1463 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_CID_SHIFT;
1464 task->cmn.common_flags |= 1 <<
1465 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_VALID_SHIFT;
1466 task->cmn.common_flags |= 1 <<
1467 FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME_SHIFT;
1468
1469 /* Set initiative ownership */
1470 task->cmn.common_flags |= FCOE_TASK_CTX_ENTRY_TX_RX_CMN_SEQ_INIT;
1471
1472 /* Set initial seq counter */
1473 task->cmn.tx_low_seq_cnt = 1;
1474
1475 /* Set state to "waiting for the first packet" */
1476 task->cmn.common_flags |= FCOE_TASK_CTX_ENTRY_TX_RX_CMN_EXP_FIRST_FRAME;
1477
1478 /* Fill FCP_CMND IU */
1479 fcp_cmnd = (u64 *)
1480 task->cmn.general.cmd_info.fcp_cmd_payload.opaque;
1481 bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
1482
1483 /* swap fcp_cmnd */
1484 cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
1485
1486 for (i = 0; i < cnt; i++) {
1487 *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
1488 fcp_cmnd++;
1489 }
1490
1491 /* Rx Write Tx Read */
1492 task->rx_wr_tx_rd.rx_id = 0xffff;
1493
1494 /* Rx Only */
1495 if (task_type == FCOE_TASK_TYPE_READ) {
1496
1497 bd_count = bd_tbl->bd_valid;
1498 if (bd_count == 1) {
1499
1500 struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
1501
1502 task->rx_wr_only.sgl_ctx.single_sge.cur_buf_addr.lo =
1503 fcoe_bd_tbl->buf_addr_lo;
1504 task->rx_wr_only.sgl_ctx.single_sge.cur_buf_addr.hi =
1505 fcoe_bd_tbl->buf_addr_hi;
1506 task->rx_wr_only.sgl_ctx.single_sge.cur_buf_rem =
1507 fcoe_bd_tbl->buf_len;
1508 task->tx_wr_rx_rd.init_flags |= 1 <<
1509 FCOE_TASK_CTX_ENTRY_TXWR_RXRD_SINGLE_SGE_SHIFT;
1510 } else {
1511
1512 task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.lo =
1513 (u32)bd_tbl->bd_tbl_dma;
1514 task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_addr.hi =
1515 (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
1516 task->rx_wr_only.sgl_ctx.mul_sges.sgl_size =
1517 bd_tbl->bd_valid;
1518 }
1519 }
1520}
1521
1522/**
1523 * bnx2fc_setup_task_ctx - allocate and map task context
1524 *
1525 * @hba: pointer to adapter structure
1526 *
1527 * allocate memory for task context, and associated BD table to be used
1528 * by firmware
1529 *
1530 */
1531int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
1532{
1533 int rc = 0;
1534 struct regpair *task_ctx_bdt;
1535 dma_addr_t addr;
1536 int i;
1537
1538 /*
1539 * Allocate task context bd table. A page size of bd table
1540 * can map 256 buffers. Each buffer contains 32 task context
1541 * entries. Hence the limit with one page is 8192 task context
1542 * entries.
1543 */
1544 hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
1545 PAGE_SIZE,
1546 &hba->task_ctx_bd_dma,
1547 GFP_KERNEL);
1548 if (!hba->task_ctx_bd_tbl) {
1549 printk(KERN_ERR PFX "unable to allocate task context BDT\n");
1550 rc = -1;
1551 goto out;
1552 }
1553 memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
1554
1555 /*
1556 * Allocate task_ctx which is an array of pointers pointing to
1557 * a page containing 32 task contexts
1558 */
1559 hba->task_ctx = kzalloc((BNX2FC_TASK_CTX_ARR_SZ * sizeof(void *)),
1560 GFP_KERNEL);
1561 if (!hba->task_ctx) {
1562 printk(KERN_ERR PFX "unable to allocate task context array\n");
1563 rc = -1;
1564 goto out1;
1565 }
1566
1567 /*
1568 * Allocate task_ctx_dma which is an array of dma addresses
1569 */
1570 hba->task_ctx_dma = kmalloc((BNX2FC_TASK_CTX_ARR_SZ *
1571 sizeof(dma_addr_t)), GFP_KERNEL);
1572 if (!hba->task_ctx_dma) {
1573 printk(KERN_ERR PFX "unable to alloc context mapping array\n");
1574 rc = -1;
1575 goto out2;
1576 }
1577
1578 task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
1579 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1580
1581 hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev,
1582 PAGE_SIZE,
1583 &hba->task_ctx_dma[i],
1584 GFP_KERNEL);
1585 if (!hba->task_ctx[i]) {
1586 printk(KERN_ERR PFX "unable to alloc task context\n");
1587 rc = -1;
1588 goto out3;
1589 }
1590 memset(hba->task_ctx[i], 0, PAGE_SIZE);
1591 addr = (u64)hba->task_ctx_dma[i];
1592 task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
1593 task_ctx_bdt->lo = cpu_to_le32((u32)addr);
1594 task_ctx_bdt++;
1595 }
1596 return 0;
1597
1598out3:
1599 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1600 if (hba->task_ctx[i]) {
1601
1602 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1603 hba->task_ctx[i], hba->task_ctx_dma[i]);
1604 hba->task_ctx[i] = NULL;
1605 }
1606 }
1607
1608 kfree(hba->task_ctx_dma);
1609 hba->task_ctx_dma = NULL;
1610out2:
1611 kfree(hba->task_ctx);
1612 hba->task_ctx = NULL;
1613out1:
1614 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1615 hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma);
1616 hba->task_ctx_bd_tbl = NULL;
1617out:
1618 return rc;
1619}
1620
1621void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba)
1622{
1623 int i;
1624
1625 if (hba->task_ctx_bd_tbl) {
1626 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1627 hba->task_ctx_bd_tbl,
1628 hba->task_ctx_bd_dma);
1629 hba->task_ctx_bd_tbl = NULL;
1630 }
1631
1632 if (hba->task_ctx) {
1633 for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
1634 if (hba->task_ctx[i]) {
1635 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1636 hba->task_ctx[i],
1637 hba->task_ctx_dma[i]);
1638 hba->task_ctx[i] = NULL;
1639 }
1640 }
1641 kfree(hba->task_ctx);
1642 hba->task_ctx = NULL;
1643 }
1644
1645 kfree(hba->task_ctx_dma);
1646 hba->task_ctx_dma = NULL;
1647}
1648
1649static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba)
1650{
1651 int i;
1652 int segment_count;
1653 int hash_table_size;
1654 u32 *pbl;
1655
1656 segment_count = hba->hash_tbl_segment_count;
1657 hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
1658 sizeof(struct fcoe_hash_table_entry);
1659
1660 pbl = hba->hash_tbl_pbl;
1661 for (i = 0; i < segment_count; ++i) {
1662 dma_addr_t dma_address;
1663
1664 dma_address = le32_to_cpu(*pbl);
1665 ++pbl;
1666 dma_address += ((u64)le32_to_cpu(*pbl)) << 32;
1667 ++pbl;
1668 dma_free_coherent(&hba->pcidev->dev,
1669 BNX2FC_HASH_TBL_CHUNK_SIZE,
1670 hba->hash_tbl_segments[i],
1671 dma_address);
1672
1673 }
1674
1675 if (hba->hash_tbl_pbl) {
1676 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1677 hba->hash_tbl_pbl,
1678 hba->hash_tbl_pbl_dma);
1679 hba->hash_tbl_pbl = NULL;
1680 }
1681}
1682
1683static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba)
1684{
1685 int i;
1686 int hash_table_size;
1687 int segment_count;
1688 int segment_array_size;
1689 int dma_segment_array_size;
1690 dma_addr_t *dma_segment_array;
1691 u32 *pbl;
1692
1693 hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
1694 sizeof(struct fcoe_hash_table_entry);
1695
1696 segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1;
1697 segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE;
1698 hba->hash_tbl_segment_count = segment_count;
1699
1700 segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments);
1701 hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL);
1702 if (!hba->hash_tbl_segments) {
1703 printk(KERN_ERR PFX "hash table pointers alloc failed\n");
1704 return -ENOMEM;
1705 }
1706 dma_segment_array_size = segment_count * sizeof(*dma_segment_array);
1707 dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL);
1708 if (!dma_segment_array) {
1709 printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n");
1710 return -ENOMEM;
1711 }
1712
1713 for (i = 0; i < segment_count; ++i) {
1714 hba->hash_tbl_segments[i] =
1715 dma_alloc_coherent(&hba->pcidev->dev,
1716 BNX2FC_HASH_TBL_CHUNK_SIZE,
1717 &dma_segment_array[i],
1718 GFP_KERNEL);
1719 if (!hba->hash_tbl_segments[i]) {
1720 printk(KERN_ERR PFX "hash segment alloc failed\n");
1721 while (--i >= 0) {
1722 dma_free_coherent(&hba->pcidev->dev,
1723 BNX2FC_HASH_TBL_CHUNK_SIZE,
1724 hba->hash_tbl_segments[i],
1725 dma_segment_array[i]);
1726 hba->hash_tbl_segments[i] = NULL;
1727 }
1728 kfree(dma_segment_array);
1729 return -ENOMEM;
1730 }
1731 memset(hba->hash_tbl_segments[i], 0,
1732 BNX2FC_HASH_TBL_CHUNK_SIZE);
1733 }
1734
1735 hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev,
1736 PAGE_SIZE,
1737 &hba->hash_tbl_pbl_dma,
1738 GFP_KERNEL);
1739 if (!hba->hash_tbl_pbl) {
1740 printk(KERN_ERR PFX "hash table pbl alloc failed\n");
1741 kfree(dma_segment_array);
1742 return -ENOMEM;
1743 }
1744 memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
1745
1746 pbl = hba->hash_tbl_pbl;
1747 for (i = 0; i < segment_count; ++i) {
1748 u64 paddr = dma_segment_array[i];
1749 *pbl = cpu_to_le32((u32) paddr);
1750 ++pbl;
1751 *pbl = cpu_to_le32((u32) (paddr >> 32));
1752 ++pbl;
1753 }
1754 pbl = hba->hash_tbl_pbl;
1755 i = 0;
1756 while (*pbl && *(pbl + 1)) {
1757 u32 lo;
1758 u32 hi;
1759 lo = *pbl;
1760 ++pbl;
1761 hi = *pbl;
1762 ++pbl;
1763 ++i;
1764 }
1765 kfree(dma_segment_array);
1766 return 0;
1767}
1768
1769/**
1770 * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
1771 *
1772 * @hba: Pointer to adapter structure
1773 *
1774 */
1775int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
1776{
1777 u64 addr;
1778 u32 mem_size;
1779 int i;
1780
1781 if (bnx2fc_allocate_hash_table(hba))
1782 return -ENOMEM;
1783
1784 mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
1785 hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
1786 &hba->t2_hash_tbl_ptr_dma,
1787 GFP_KERNEL);
1788 if (!hba->t2_hash_tbl_ptr) {
1789 printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
1790 bnx2fc_free_fw_resc(hba);
1791 return -ENOMEM;
1792 }
1793 memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
1794
1795 mem_size = BNX2FC_NUM_MAX_SESS *
1796 sizeof(struct fcoe_t2_hash_table_entry);
1797 hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
1798 &hba->t2_hash_tbl_dma,
1799 GFP_KERNEL);
1800 if (!hba->t2_hash_tbl) {
1801 printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
1802 bnx2fc_free_fw_resc(hba);
1803 return -ENOMEM;
1804 }
1805 memset(hba->t2_hash_tbl, 0x00, mem_size);
1806 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
1807 addr = (unsigned long) hba->t2_hash_tbl_dma +
1808 ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
1809 hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff;
1810 hba->t2_hash_tbl[i].next.hi = addr >> 32;
1811 }
1812
1813 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
1814 PAGE_SIZE, &hba->dummy_buf_dma,
1815 GFP_KERNEL);
1816 if (!hba->dummy_buffer) {
1817 printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n");
1818 bnx2fc_free_fw_resc(hba);
1819 return -ENOMEM;
1820 }
1821
1822 hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
1823 PAGE_SIZE,
1824 &hba->stats_buf_dma,
1825 GFP_KERNEL);
1826 if (!hba->stats_buffer) {
1827 printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
1828 bnx2fc_free_fw_resc(hba);
1829 return -ENOMEM;
1830 }
1831 memset(hba->stats_buffer, 0x00, PAGE_SIZE);
1832
1833 return 0;
1834}
1835
1836void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba)
1837{
1838 u32 mem_size;
1839
1840 if (hba->stats_buffer) {
1841 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1842 hba->stats_buffer, hba->stats_buf_dma);
1843 hba->stats_buffer = NULL;
1844 }
1845
1846 if (hba->dummy_buffer) {
1847 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
1848 hba->dummy_buffer, hba->dummy_buf_dma);
1849 hba->dummy_buffer = NULL;
1850 }
1851
1852 if (hba->t2_hash_tbl_ptr) {
1853 mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
1854 dma_free_coherent(&hba->pcidev->dev, mem_size,
1855 hba->t2_hash_tbl_ptr,
1856 hba->t2_hash_tbl_ptr_dma);
1857 hba->t2_hash_tbl_ptr = NULL;
1858 }
1859
1860 if (hba->t2_hash_tbl) {
1861 mem_size = BNX2FC_NUM_MAX_SESS *
1862 sizeof(struct fcoe_t2_hash_table_entry);
1863 dma_free_coherent(&hba->pcidev->dev, mem_size,
1864 hba->t2_hash_tbl, hba->t2_hash_tbl_dma);
1865 hba->t2_hash_tbl = NULL;
1866 }
1867 bnx2fc_free_hash_table(hba);
1868}
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
new file mode 100644
index 000000000000..0f1dd23730db
--- /dev/null
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -0,0 +1,1833 @@
1/* bnx2fc_io.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * IO manager and SCSI IO processing.
3 *
4 * Copyright (c) 2008 - 2010 Broadcom Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
9 *
10 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
11 */
12
13#include "bnx2fc.h"
14static int bnx2fc_split_bd(struct bnx2fc_cmd *io_req, u64 addr, int sg_len,
15 int bd_index);
16static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req);
17static void bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req);
18static int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
19 struct bnx2fc_cmd *io_req);
20static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req);
21static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req);
22static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
23 struct fcoe_fcp_rsp_payload *fcp_rsp,
24 u8 num_rq);
25
26void bnx2fc_cmd_timer_set(struct bnx2fc_cmd *io_req,
27 unsigned int timer_msec)
28{
29 struct bnx2fc_hba *hba = io_req->port->priv;
30
31 if (queue_delayed_work(hba->timer_work_queue, &io_req->timeout_work,
32 msecs_to_jiffies(timer_msec)))
33 kref_get(&io_req->refcount);
34}
35
36static void bnx2fc_cmd_timeout(struct work_struct *work)
37{
38 struct bnx2fc_cmd *io_req = container_of(work, struct bnx2fc_cmd,
39 timeout_work.work);
40 struct fc_lport *lport;
41 struct fc_rport_priv *rdata;
42 u8 cmd_type = io_req->cmd_type;
43 struct bnx2fc_rport *tgt = io_req->tgt;
44 int logo_issued;
45 int rc;
46
47 BNX2FC_IO_DBG(io_req, "cmd_timeout, cmd_type = %d,"
48 "req_flags = %lx\n", cmd_type, io_req->req_flags);
49
50 spin_lock_bh(&tgt->tgt_lock);
51 if (test_and_clear_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags)) {
52 clear_bit(BNX2FC_FLAG_RETIRE_OXID, &io_req->req_flags);
53 /*
54 * ideally we should hold the io_req until RRQ complets,
55 * and release io_req from timeout hold.
56 */
57 spin_unlock_bh(&tgt->tgt_lock);
58 bnx2fc_send_rrq(io_req);
59 return;
60 }
61 if (test_and_clear_bit(BNX2FC_FLAG_RETIRE_OXID, &io_req->req_flags)) {
62 BNX2FC_IO_DBG(io_req, "IO ready for reuse now\n");
63 goto done;
64 }
65
66 switch (cmd_type) {
67 case BNX2FC_SCSI_CMD:
68 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
69 &io_req->req_flags)) {
70 /* Handle eh_abort timeout */
71 BNX2FC_IO_DBG(io_req, "eh_abort timed out\n");
72 complete(&io_req->tm_done);
73 } else if (test_bit(BNX2FC_FLAG_ISSUE_ABTS,
74 &io_req->req_flags)) {
75 /* Handle internally generated ABTS timeout */
76 BNX2FC_IO_DBG(io_req, "ABTS timed out refcnt = %d\n",
77 io_req->refcount.refcount.counter);
78 if (!(test_and_set_bit(BNX2FC_FLAG_ABTS_DONE,
79 &io_req->req_flags))) {
80
81 lport = io_req->port->lport;
82 rdata = io_req->tgt->rdata;
83 logo_issued = test_and_set_bit(
84 BNX2FC_FLAG_EXPL_LOGO,
85 &tgt->flags);
86 kref_put(&io_req->refcount, bnx2fc_cmd_release);
87 spin_unlock_bh(&tgt->tgt_lock);
88
89 /* Explicitly logo the target */
90 if (!logo_issued) {
91 BNX2FC_IO_DBG(io_req, "Explicit "
92 "logo - tgt flags = 0x%lx\n",
93 tgt->flags);
94
95 mutex_lock(&lport->disc.disc_mutex);
96 lport->tt.rport_logoff(rdata);
97 mutex_unlock(&lport->disc.disc_mutex);
98 }
99 return;
100 }
101 } else {
102 /* Hanlde IO timeout */
103 BNX2FC_IO_DBG(io_req, "IO timed out. issue ABTS\n");
104 if (test_and_set_bit(BNX2FC_FLAG_IO_COMPL,
105 &io_req->req_flags)) {
106 BNX2FC_IO_DBG(io_req, "IO completed before "
107 " timer expiry\n");
108 goto done;
109 }
110
111 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
112 &io_req->req_flags)) {
113 rc = bnx2fc_initiate_abts(io_req);
114 if (rc == SUCCESS)
115 goto done;
116 /*
117 * Explicitly logo the target if
118 * abts initiation fails
119 */
120 lport = io_req->port->lport;
121 rdata = io_req->tgt->rdata;
122 logo_issued = test_and_set_bit(
123 BNX2FC_FLAG_EXPL_LOGO,
124 &tgt->flags);
125 kref_put(&io_req->refcount, bnx2fc_cmd_release);
126 spin_unlock_bh(&tgt->tgt_lock);
127
128 if (!logo_issued) {
129 BNX2FC_IO_DBG(io_req, "Explicit "
130 "logo - tgt flags = 0x%lx\n",
131 tgt->flags);
132
133
134 mutex_lock(&lport->disc.disc_mutex);
135 lport->tt.rport_logoff(rdata);
136 mutex_unlock(&lport->disc.disc_mutex);
137 }
138 return;
139 } else {
140 BNX2FC_IO_DBG(io_req, "IO already in "
141 "ABTS processing\n");
142 }
143 }
144 break;
145 case BNX2FC_ELS:
146
147 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
148 BNX2FC_IO_DBG(io_req, "ABTS for ELS timed out\n");
149
150 if (!test_and_set_bit(BNX2FC_FLAG_ABTS_DONE,
151 &io_req->req_flags)) {
152 lport = io_req->port->lport;
153 rdata = io_req->tgt->rdata;
154 logo_issued = test_and_set_bit(
155 BNX2FC_FLAG_EXPL_LOGO,
156 &tgt->flags);
157 kref_put(&io_req->refcount, bnx2fc_cmd_release);
158 spin_unlock_bh(&tgt->tgt_lock);
159
160 /* Explicitly logo the target */
161 if (!logo_issued) {
162 BNX2FC_IO_DBG(io_req, "Explicitly logo"
163 "(els)\n");
164 mutex_lock(&lport->disc.disc_mutex);
165 lport->tt.rport_logoff(rdata);
166 mutex_unlock(&lport->disc.disc_mutex);
167 }
168 return;
169 }
170 } else {
171 /*
172 * Handle ELS timeout.
173 * tgt_lock is used to sync compl path and timeout
174 * path. If els compl path is processing this IO, we
175 * have nothing to do here, just release the timer hold
176 */
177 BNX2FC_IO_DBG(io_req, "ELS timed out\n");
178 if (test_and_set_bit(BNX2FC_FLAG_ELS_DONE,
179 &io_req->req_flags))
180 goto done;
181
182 /* Indicate the cb_func that this ELS is timed out */
183 set_bit(BNX2FC_FLAG_ELS_TIMEOUT, &io_req->req_flags);
184
185 if ((io_req->cb_func) && (io_req->cb_arg)) {
186 io_req->cb_func(io_req->cb_arg);
187 io_req->cb_arg = NULL;
188 }
189 }
190 break;
191 default:
192 printk(KERN_ERR PFX "cmd_timeout: invalid cmd_type %d\n",
193 cmd_type);
194 break;
195 }
196
197done:
198 /* release the cmd that was held when timer was set */
199 kref_put(&io_req->refcount, bnx2fc_cmd_release);
200 spin_unlock_bh(&tgt->tgt_lock);
201}
202
203static void bnx2fc_scsi_done(struct bnx2fc_cmd *io_req, int err_code)
204{
205 /* Called with host lock held */
206 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
207
208 /*
209 * active_cmd_queue may have other command types as well,
210 * and during flush operation, we want to error back only
211 * scsi commands.
212 */
213 if (io_req->cmd_type != BNX2FC_SCSI_CMD)
214 return;
215
216 BNX2FC_IO_DBG(io_req, "scsi_done. err_code = 0x%x\n", err_code);
217 bnx2fc_unmap_sg_list(io_req);
218 io_req->sc_cmd = NULL;
219 if (!sc_cmd) {
220 printk(KERN_ERR PFX "scsi_done - sc_cmd NULL. "
221 "IO(0x%x) already cleaned up\n",
222 io_req->xid);
223 return;
224 }
225 sc_cmd->result = err_code << 16;
226
227 BNX2FC_IO_DBG(io_req, "sc=%p, result=0x%x, retries=%d, allowed=%d\n",
228 sc_cmd, host_byte(sc_cmd->result), sc_cmd->retries,
229 sc_cmd->allowed);
230 scsi_set_resid(sc_cmd, scsi_bufflen(sc_cmd));
231 sc_cmd->SCp.ptr = NULL;
232 sc_cmd->scsi_done(sc_cmd);
233}
234
235struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba,
236 u16 min_xid, u16 max_xid)
237{
238 struct bnx2fc_cmd_mgr *cmgr;
239 struct io_bdt *bdt_info;
240 struct bnx2fc_cmd *io_req;
241 size_t len;
242 u32 mem_size;
243 u16 xid;
244 int i;
245 int num_ios;
246 size_t bd_tbl_sz;
247
248 if (max_xid <= min_xid || max_xid == FC_XID_UNKNOWN) {
249 printk(KERN_ERR PFX "cmd_mgr_alloc: Invalid min_xid 0x%x \
250 and max_xid 0x%x\n", min_xid, max_xid);
251 return NULL;
252 }
253 BNX2FC_MISC_DBG("min xid 0x%x, max xid 0x%x\n", min_xid, max_xid);
254
255 num_ios = max_xid - min_xid + 1;
256 len = (num_ios * (sizeof(struct bnx2fc_cmd *)));
257 len += sizeof(struct bnx2fc_cmd_mgr);
258
259 cmgr = kzalloc(len, GFP_KERNEL);
260 if (!cmgr) {
261 printk(KERN_ERR PFX "failed to alloc cmgr\n");
262 return NULL;
263 }
264
265 cmgr->free_list = kzalloc(sizeof(*cmgr->free_list) *
266 num_possible_cpus(), GFP_KERNEL);
267 if (!cmgr->free_list) {
268 printk(KERN_ERR PFX "failed to alloc free_list\n");
269 goto mem_err;
270 }
271
272 cmgr->free_list_lock = kzalloc(sizeof(*cmgr->free_list_lock) *
273 num_possible_cpus(), GFP_KERNEL);
274 if (!cmgr->free_list_lock) {
275 printk(KERN_ERR PFX "failed to alloc free_list_lock\n");
276 goto mem_err;
277 }
278
279 cmgr->hba = hba;
280 cmgr->cmds = (struct bnx2fc_cmd **)(cmgr + 1);
281
282 for (i = 0; i < num_possible_cpus(); i++) {
283 INIT_LIST_HEAD(&cmgr->free_list[i]);
284 spin_lock_init(&cmgr->free_list_lock[i]);
285 }
286
287 /* Pre-allocated pool of bnx2fc_cmds */
288 xid = BNX2FC_MIN_XID;
289 for (i = 0; i < num_ios; i++) {
290 io_req = kzalloc(sizeof(*io_req), GFP_KERNEL);
291
292 if (!io_req) {
293 printk(KERN_ERR PFX "failed to alloc io_req\n");
294 goto mem_err;
295 }
296
297 INIT_LIST_HEAD(&io_req->link);
298 INIT_DELAYED_WORK(&io_req->timeout_work, bnx2fc_cmd_timeout);
299
300 io_req->xid = xid++;
301 if (io_req->xid >= BNX2FC_MAX_OUTSTANDING_CMNDS)
302 printk(KERN_ERR PFX "ERROR allocating xids - 0x%x\n",
303 io_req->xid);
304 list_add_tail(&io_req->link,
305 &cmgr->free_list[io_req->xid % num_possible_cpus()]);
306 io_req++;
307 }
308
309 /* Allocate pool of io_bdts - one for each bnx2fc_cmd */
310 mem_size = num_ios * sizeof(struct io_bdt *);
311 cmgr->io_bdt_pool = kmalloc(mem_size, GFP_KERNEL);
312 if (!cmgr->io_bdt_pool) {
313 printk(KERN_ERR PFX "failed to alloc io_bdt_pool\n");
314 goto mem_err;
315 }
316
317 mem_size = sizeof(struct io_bdt);
318 for (i = 0; i < num_ios; i++) {
319 cmgr->io_bdt_pool[i] = kmalloc(mem_size, GFP_KERNEL);
320 if (!cmgr->io_bdt_pool[i]) {
321 printk(KERN_ERR PFX "failed to alloc "
322 "io_bdt_pool[%d]\n", i);
323 goto mem_err;
324 }
325 }
326
327 /* Allocate an map fcoe_bdt_ctx structures */
328 bd_tbl_sz = BNX2FC_MAX_BDS_PER_CMD * sizeof(struct fcoe_bd_ctx);
329 for (i = 0; i < num_ios; i++) {
330 bdt_info = cmgr->io_bdt_pool[i];
331 bdt_info->bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
332 bd_tbl_sz,
333 &bdt_info->bd_tbl_dma,
334 GFP_KERNEL);
335 if (!bdt_info->bd_tbl) {
336 printk(KERN_ERR PFX "failed to alloc "
337 "bdt_tbl[%d]\n", i);
338 goto mem_err;
339 }
340 }
341
342 return cmgr;
343
344mem_err:
345 bnx2fc_cmd_mgr_free(cmgr);
346 return NULL;
347}
348
349void bnx2fc_cmd_mgr_free(struct bnx2fc_cmd_mgr *cmgr)
350{
351 struct io_bdt *bdt_info;
352 struct bnx2fc_hba *hba = cmgr->hba;
353 size_t bd_tbl_sz;
354 u16 min_xid = BNX2FC_MIN_XID;
355 u16 max_xid = BNX2FC_MAX_XID;
356 int num_ios;
357 int i;
358
359 num_ios = max_xid - min_xid + 1;
360
361 /* Free fcoe_bdt_ctx structures */
362 if (!cmgr->io_bdt_pool)
363 goto free_cmd_pool;
364
365 bd_tbl_sz = BNX2FC_MAX_BDS_PER_CMD * sizeof(struct fcoe_bd_ctx);
366 for (i = 0; i < num_ios; i++) {
367 bdt_info = cmgr->io_bdt_pool[i];
368 if (bdt_info->bd_tbl) {
369 dma_free_coherent(&hba->pcidev->dev, bd_tbl_sz,
370 bdt_info->bd_tbl,
371 bdt_info->bd_tbl_dma);
372 bdt_info->bd_tbl = NULL;
373 }
374 }
375
376 /* Destroy io_bdt pool */
377 for (i = 0; i < num_ios; i++) {
378 kfree(cmgr->io_bdt_pool[i]);
379 cmgr->io_bdt_pool[i] = NULL;
380 }
381
382 kfree(cmgr->io_bdt_pool);
383 cmgr->io_bdt_pool = NULL;
384
385free_cmd_pool:
386 kfree(cmgr->free_list_lock);
387
388 /* Destroy cmd pool */
389 if (!cmgr->free_list)
390 goto free_cmgr;
391
392 for (i = 0; i < num_possible_cpus(); i++) {
393 struct list_head *list;
394 struct list_head *tmp;
395
396 list_for_each_safe(list, tmp, &cmgr->free_list[i]) {
397 struct bnx2fc_cmd *io_req = (struct bnx2fc_cmd *)list;
398 list_del(&io_req->link);
399 kfree(io_req);
400 }
401 }
402 kfree(cmgr->free_list);
403free_cmgr:
404 /* Free command manager itself */
405 kfree(cmgr);
406}
407
408struct bnx2fc_cmd *bnx2fc_elstm_alloc(struct bnx2fc_rport *tgt, int type)
409{
410 struct fcoe_port *port = tgt->port;
411 struct bnx2fc_hba *hba = port->priv;
412 struct bnx2fc_cmd_mgr *cmd_mgr = hba->cmd_mgr;
413 struct bnx2fc_cmd *io_req;
414 struct list_head *listp;
415 struct io_bdt *bd_tbl;
416 u32 max_sqes;
417 u16 xid;
418
419 max_sqes = tgt->max_sqes;
420 switch (type) {
421 case BNX2FC_TASK_MGMT_CMD:
422 max_sqes = BNX2FC_TM_MAX_SQES;
423 break;
424 case BNX2FC_ELS:
425 max_sqes = BNX2FC_ELS_MAX_SQES;
426 break;
427 default:
428 break;
429 }
430
431 /*
432 * NOTE: Free list insertions and deletions are protected with
433 * cmgr lock
434 */
435 spin_lock_bh(&cmd_mgr->free_list_lock[smp_processor_id()]);
436 if ((list_empty(&(cmd_mgr->free_list[smp_processor_id()]))) ||
437 (tgt->num_active_ios.counter >= max_sqes)) {
438 BNX2FC_TGT_DBG(tgt, "No free els_tm cmds available "
439 "ios(%d):sqes(%d)\n",
440 tgt->num_active_ios.counter, tgt->max_sqes);
441 if (list_empty(&(cmd_mgr->free_list[smp_processor_id()])))
442 printk(KERN_ERR PFX "elstm_alloc: list_empty\n");
443 spin_unlock_bh(&cmd_mgr->free_list_lock[smp_processor_id()]);
444 return NULL;
445 }
446
447 listp = (struct list_head *)
448 cmd_mgr->free_list[smp_processor_id()].next;
449 list_del_init(listp);
450 io_req = (struct bnx2fc_cmd *) listp;
451 xid = io_req->xid;
452 cmd_mgr->cmds[xid] = io_req;
453 atomic_inc(&tgt->num_active_ios);
454 spin_unlock_bh(&cmd_mgr->free_list_lock[smp_processor_id()]);
455
456 INIT_LIST_HEAD(&io_req->link);
457
458 io_req->port = port;
459 io_req->cmd_mgr = cmd_mgr;
460 io_req->req_flags = 0;
461 io_req->cmd_type = type;
462
463 /* Bind io_bdt for this io_req */
464 /* Have a static link between io_req and io_bdt_pool */
465 bd_tbl = io_req->bd_tbl = cmd_mgr->io_bdt_pool[xid];
466 bd_tbl->io_req = io_req;
467
468 /* Hold the io_req against deletion */
469 kref_init(&io_req->refcount);
470 return io_req;
471}
472static struct bnx2fc_cmd *bnx2fc_cmd_alloc(struct bnx2fc_rport *tgt)
473{
474 struct fcoe_port *port = tgt->port;
475 struct bnx2fc_hba *hba = port->priv;
476 struct bnx2fc_cmd_mgr *cmd_mgr = hba->cmd_mgr;
477 struct bnx2fc_cmd *io_req;
478 struct list_head *listp;
479 struct io_bdt *bd_tbl;
480 u32 max_sqes;
481 u16 xid;
482
483 max_sqes = BNX2FC_SCSI_MAX_SQES;
484 /*
485 * NOTE: Free list insertions and deletions are protected with
486 * cmgr lock
487 */
488 spin_lock_bh(&cmd_mgr->free_list_lock[smp_processor_id()]);
489 if ((list_empty(&cmd_mgr->free_list[smp_processor_id()])) ||
490 (tgt->num_active_ios.counter >= max_sqes)) {
491 spin_unlock_bh(&cmd_mgr->free_list_lock[smp_processor_id()]);
492 return NULL;
493 }
494
495 listp = (struct list_head *)
496 cmd_mgr->free_list[smp_processor_id()].next;
497 list_del_init(listp);
498 io_req = (struct bnx2fc_cmd *) listp;
499 xid = io_req->xid;
500 cmd_mgr->cmds[xid] = io_req;
501 atomic_inc(&tgt->num_active_ios);
502 spin_unlock_bh(&cmd_mgr->free_list_lock[smp_processor_id()]);
503
504 INIT_LIST_HEAD(&io_req->link);
505
506 io_req->port = port;
507 io_req->cmd_mgr = cmd_mgr;
508 io_req->req_flags = 0;
509
510 /* Bind io_bdt for this io_req */
511 /* Have a static link between io_req and io_bdt_pool */
512 bd_tbl = io_req->bd_tbl = cmd_mgr->io_bdt_pool[xid];
513 bd_tbl->io_req = io_req;
514
515 /* Hold the io_req against deletion */
516 kref_init(&io_req->refcount);
517 return io_req;
518}
519
520void bnx2fc_cmd_release(struct kref *ref)
521{
522 struct bnx2fc_cmd *io_req = container_of(ref,
523 struct bnx2fc_cmd, refcount);
524 struct bnx2fc_cmd_mgr *cmd_mgr = io_req->cmd_mgr;
525
526 spin_lock_bh(&cmd_mgr->free_list_lock[smp_processor_id()]);
527 if (io_req->cmd_type != BNX2FC_SCSI_CMD)
528 bnx2fc_free_mp_resc(io_req);
529 cmd_mgr->cmds[io_req->xid] = NULL;
530 /* Delete IO from retire queue */
531 list_del_init(&io_req->link);
532 /* Add it to the free list */
533 list_add(&io_req->link,
534 &cmd_mgr->free_list[smp_processor_id()]);
535 atomic_dec(&io_req->tgt->num_active_ios);
536 spin_unlock_bh(&cmd_mgr->free_list_lock[smp_processor_id()]);
537}
538
539static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req)
540{
541 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
542 struct bnx2fc_hba *hba = io_req->port->priv;
543 size_t sz = sizeof(struct fcoe_bd_ctx);
544
545 /* clear tm flags */
546 mp_req->tm_flags = 0;
547 if (mp_req->mp_req_bd) {
548 dma_free_coherent(&hba->pcidev->dev, sz,
549 mp_req->mp_req_bd,
550 mp_req->mp_req_bd_dma);
551 mp_req->mp_req_bd = NULL;
552 }
553 if (mp_req->mp_resp_bd) {
554 dma_free_coherent(&hba->pcidev->dev, sz,
555 mp_req->mp_resp_bd,
556 mp_req->mp_resp_bd_dma);
557 mp_req->mp_resp_bd = NULL;
558 }
559 if (mp_req->req_buf) {
560 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
561 mp_req->req_buf,
562 mp_req->req_buf_dma);
563 mp_req->req_buf = NULL;
564 }
565 if (mp_req->resp_buf) {
566 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
567 mp_req->resp_buf,
568 mp_req->resp_buf_dma);
569 mp_req->resp_buf = NULL;
570 }
571}
572
573int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
574{
575 struct bnx2fc_mp_req *mp_req;
576 struct fcoe_bd_ctx *mp_req_bd;
577 struct fcoe_bd_ctx *mp_resp_bd;
578 struct bnx2fc_hba *hba = io_req->port->priv;
579 dma_addr_t addr;
580 size_t sz;
581
582 mp_req = (struct bnx2fc_mp_req *)&(io_req->mp_req);
583 memset(mp_req, 0, sizeof(struct bnx2fc_mp_req));
584
585 mp_req->req_len = sizeof(struct fcp_cmnd);
586 io_req->data_xfer_len = mp_req->req_len;
587 mp_req->req_buf = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
588 &mp_req->req_buf_dma,
589 GFP_ATOMIC);
590 if (!mp_req->req_buf) {
591 printk(KERN_ERR PFX "unable to alloc MP req buffer\n");
592 bnx2fc_free_mp_resc(io_req);
593 return FAILED;
594 }
595
596 mp_req->resp_buf = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
597 &mp_req->resp_buf_dma,
598 GFP_ATOMIC);
599 if (!mp_req->resp_buf) {
600 printk(KERN_ERR PFX "unable to alloc TM resp buffer\n");
601 bnx2fc_free_mp_resc(io_req);
602 return FAILED;
603 }
604 memset(mp_req->req_buf, 0, PAGE_SIZE);
605 memset(mp_req->resp_buf, 0, PAGE_SIZE);
606
607 /* Allocate and map mp_req_bd and mp_resp_bd */
608 sz = sizeof(struct fcoe_bd_ctx);
609 mp_req->mp_req_bd = dma_alloc_coherent(&hba->pcidev->dev, sz,
610 &mp_req->mp_req_bd_dma,
611 GFP_ATOMIC);
612 if (!mp_req->mp_req_bd) {
613 printk(KERN_ERR PFX "unable to alloc MP req bd\n");
614 bnx2fc_free_mp_resc(io_req);
615 return FAILED;
616 }
617 mp_req->mp_resp_bd = dma_alloc_coherent(&hba->pcidev->dev, sz,
618 &mp_req->mp_resp_bd_dma,
619 GFP_ATOMIC);
620 if (!mp_req->mp_req_bd) {
621 printk(KERN_ERR PFX "unable to alloc MP resp bd\n");
622 bnx2fc_free_mp_resc(io_req);
623 return FAILED;
624 }
625 /* Fill bd table */
626 addr = mp_req->req_buf_dma;
627 mp_req_bd = mp_req->mp_req_bd;
628 mp_req_bd->buf_addr_lo = (u32)addr & 0xffffffff;
629 mp_req_bd->buf_addr_hi = (u32)((u64)addr >> 32);
630 mp_req_bd->buf_len = PAGE_SIZE;
631 mp_req_bd->flags = 0;
632
633 /*
634 * MP buffer is either a task mgmt command or an ELS.
635 * So the assumption is that it consumes a single bd
636 * entry in the bd table
637 */
638 mp_resp_bd = mp_req->mp_resp_bd;
639 addr = mp_req->resp_buf_dma;
640 mp_resp_bd->buf_addr_lo = (u32)addr & 0xffffffff;
641 mp_resp_bd->buf_addr_hi = (u32)((u64)addr >> 32);
642 mp_resp_bd->buf_len = PAGE_SIZE;
643 mp_resp_bd->flags = 0;
644
645 return SUCCESS;
646}
647
648static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
649{
650 struct fc_lport *lport;
651 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
652 struct fc_rport_libfc_priv *rp = rport->dd_data;
653 struct fcoe_port *port;
654 struct bnx2fc_hba *hba;
655 struct bnx2fc_rport *tgt;
656 struct bnx2fc_cmd *io_req;
657 struct bnx2fc_mp_req *tm_req;
658 struct fcoe_task_ctx_entry *task;
659 struct fcoe_task_ctx_entry *task_page;
660 struct Scsi_Host *host = sc_cmd->device->host;
661 struct fc_frame_header *fc_hdr;
662 struct fcp_cmnd *fcp_cmnd;
663 int task_idx, index;
664 int rc = SUCCESS;
665 u16 xid;
666 u32 sid, did;
667 unsigned long start = jiffies;
668
669 lport = shost_priv(host);
670 port = lport_priv(lport);
671 hba = port->priv;
672
673 if (rport == NULL) {
674 printk(KERN_ALERT PFX "device_reset: rport is NULL\n");
675 rc = FAILED;
676 goto tmf_err;
677 }
678
679 rc = fc_block_scsi_eh(sc_cmd);
680 if (rc)
681 return rc;
682
683 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
684 printk(KERN_ERR PFX "device_reset: link is not ready\n");
685 rc = FAILED;
686 goto tmf_err;
687 }
688 /* rport and tgt are allocated together, so tgt should be non-NULL */
689 tgt = (struct bnx2fc_rport *)&rp[1];
690
691 if (!(test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
692 printk(KERN_ERR PFX "device_reset: tgt not offloaded\n");
693 rc = FAILED;
694 goto tmf_err;
695 }
696retry_tmf:
697 io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_TASK_MGMT_CMD);
698 if (!io_req) {
699 if (time_after(jiffies, start + HZ)) {
700 printk(KERN_ERR PFX "tmf: Failed TMF");
701 rc = FAILED;
702 goto tmf_err;
703 }
704 msleep(20);
705 goto retry_tmf;
706 }
707 /* Initialize rest of io_req fields */
708 io_req->sc_cmd = sc_cmd;
709 io_req->port = port;
710 io_req->tgt = tgt;
711
712 tm_req = (struct bnx2fc_mp_req *)&(io_req->mp_req);
713
714 rc = bnx2fc_init_mp_req(io_req);
715 if (rc == FAILED) {
716 printk(KERN_ERR PFX "Task mgmt MP request init failed\n");
717 kref_put(&io_req->refcount, bnx2fc_cmd_release);
718 goto tmf_err;
719 }
720
721 /* Set TM flags */
722 io_req->io_req_flags = 0;
723 tm_req->tm_flags = tm_flags;
724
725 /* Fill FCP_CMND */
726 bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)tm_req->req_buf);
727 fcp_cmnd = (struct fcp_cmnd *)tm_req->req_buf;
728 memset(fcp_cmnd->fc_cdb, 0, sc_cmd->cmd_len);
729 fcp_cmnd->fc_dl = 0;
730
731 /* Fill FC header */
732 fc_hdr = &(tm_req->req_fc_hdr);
733 sid = tgt->sid;
734 did = rport->port_id;
735 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_DD_UNSOL_CMD, did, sid,
736 FC_TYPE_FCP, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
737 FC_FC_SEQ_INIT, 0);
738 /* Obtain exchange id */
739 xid = io_req->xid;
740
741 BNX2FC_TGT_DBG(tgt, "Initiate TMF - xid = 0x%x\n", xid);
742 task_idx = xid/BNX2FC_TASKS_PER_PAGE;
743 index = xid % BNX2FC_TASKS_PER_PAGE;
744
745 /* Initialize task context for this IO request */
746 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx];
747 task = &(task_page[index]);
748 bnx2fc_init_mp_task(io_req, task);
749
750 sc_cmd->SCp.ptr = (char *)io_req;
751
752 /* Obtain free SQ entry */
753 spin_lock_bh(&tgt->tgt_lock);
754 bnx2fc_add_2_sq(tgt, xid);
755
756 /* Enqueue the io_req to active_tm_queue */
757 io_req->on_tmf_queue = 1;
758 list_add_tail(&io_req->link, &tgt->active_tm_queue);
759
760 init_completion(&io_req->tm_done);
761 io_req->wait_for_comp = 1;
762
763 /* Ring doorbell */
764 bnx2fc_ring_doorbell(tgt);
765 spin_unlock_bh(&tgt->tgt_lock);
766
767 rc = wait_for_completion_timeout(&io_req->tm_done,
768 BNX2FC_TM_TIMEOUT * HZ);
769 spin_lock_bh(&tgt->tgt_lock);
770
771 io_req->wait_for_comp = 0;
772 if (!(test_bit(BNX2FC_FLAG_TM_COMPL, &io_req->req_flags)))
773 set_bit(BNX2FC_FLAG_TM_TIMEOUT, &io_req->req_flags);
774
775 spin_unlock_bh(&tgt->tgt_lock);
776
777 if (!rc) {
778 printk(KERN_ERR PFX "task mgmt command failed...\n");
779 rc = FAILED;
780 } else {
781 printk(KERN_ERR PFX "task mgmt command success...\n");
782 rc = SUCCESS;
783 }
784tmf_err:
785 return rc;
786}
787
788int bnx2fc_initiate_abts(struct bnx2fc_cmd *io_req)
789{
790 struct fc_lport *lport;
791 struct bnx2fc_rport *tgt = io_req->tgt;
792 struct fc_rport *rport = tgt->rport;
793 struct fc_rport_priv *rdata = tgt->rdata;
794 struct bnx2fc_hba *hba;
795 struct fcoe_port *port;
796 struct bnx2fc_cmd *abts_io_req;
797 struct fcoe_task_ctx_entry *task;
798 struct fcoe_task_ctx_entry *task_page;
799 struct fc_frame_header *fc_hdr;
800 struct bnx2fc_mp_req *abts_req;
801 int task_idx, index;
802 u32 sid, did;
803 u16 xid;
804 int rc = SUCCESS;
805 u32 r_a_tov = rdata->r_a_tov;
806
807 /* called with tgt_lock held */
808 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_abts\n");
809
810 port = io_req->port;
811 hba = port->priv;
812 lport = port->lport;
813
814 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
815 printk(KERN_ERR PFX "initiate_abts: tgt not offloaded\n");
816 rc = FAILED;
817 goto abts_err;
818 }
819
820 if (rport == NULL) {
821 printk(KERN_ALERT PFX "initiate_abts: rport is NULL\n");
822 rc = FAILED;
823 goto abts_err;
824 }
825
826 if (lport->state != LPORT_ST_READY || !(lport->link_up)) {
827 printk(KERN_ERR PFX "initiate_abts: link is not ready\n");
828 rc = FAILED;
829 goto abts_err;
830 }
831
832 abts_io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_ABTS);
833 if (!abts_io_req) {
834 printk(KERN_ERR PFX "abts: couldnt allocate cmd\n");
835 rc = FAILED;
836 goto abts_err;
837 }
838
839 /* Initialize rest of io_req fields */
840 abts_io_req->sc_cmd = NULL;
841 abts_io_req->port = port;
842 abts_io_req->tgt = tgt;
843 abts_io_req->data_xfer_len = 0; /* No data transfer for ABTS */
844
845 abts_req = (struct bnx2fc_mp_req *)&(abts_io_req->mp_req);
846 memset(abts_req, 0, sizeof(struct bnx2fc_mp_req));
847
848 /* Fill FC header */
849 fc_hdr = &(abts_req->req_fc_hdr);
850
851 /* Obtain oxid and rxid for the original exchange to be aborted */
852 fc_hdr->fh_ox_id = htons(io_req->xid);
853 fc_hdr->fh_rx_id = htons(io_req->task->rx_wr_tx_rd.rx_id);
854
855 sid = tgt->sid;
856 did = rport->port_id;
857
858 __fc_fill_fc_hdr(fc_hdr, FC_RCTL_BA_ABTS, did, sid,
859 FC_TYPE_BLS, FC_FC_FIRST_SEQ | FC_FC_END_SEQ |
860 FC_FC_SEQ_INIT, 0);
861
862 xid = abts_io_req->xid;
863 BNX2FC_IO_DBG(abts_io_req, "ABTS io_req\n");
864 task_idx = xid/BNX2FC_TASKS_PER_PAGE;
865 index = xid % BNX2FC_TASKS_PER_PAGE;
866
867 /* Initialize task context for this IO request */
868 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx];
869 task = &(task_page[index]);
870 bnx2fc_init_mp_task(abts_io_req, task);
871
872 /*
873 * ABTS task is a temporary task that will be cleaned up
874 * irrespective of ABTS response. We need to start the timer
875 * for the original exchange, as the CQE is posted for the original
876 * IO request.
877 *
878 * Timer for ABTS is started only when it is originated by a
879 * TM request. For the ABTS issued as part of ULP timeout,
880 * scsi-ml maintains the timers.
881 */
882
883 /* if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags))*/
884 bnx2fc_cmd_timer_set(io_req, 2 * r_a_tov);
885
886 /* Obtain free SQ entry */
887 bnx2fc_add_2_sq(tgt, xid);
888
889 /* Ring doorbell */
890 bnx2fc_ring_doorbell(tgt);
891
892abts_err:
893 return rc;
894}
895
896int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
897{
898 struct fc_lport *lport;
899 struct bnx2fc_rport *tgt = io_req->tgt;
900 struct bnx2fc_hba *hba;
901 struct fcoe_port *port;
902 struct bnx2fc_cmd *cleanup_io_req;
903 struct fcoe_task_ctx_entry *task;
904 struct fcoe_task_ctx_entry *task_page;
905 int task_idx, index;
906 u16 xid, orig_xid;
907 int rc = 0;
908
909 /* ASSUMPTION: called with tgt_lock held */
910 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_cleanup\n");
911
912 port = io_req->port;
913 hba = port->priv;
914 lport = port->lport;
915
916 cleanup_io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_CLEANUP);
917 if (!cleanup_io_req) {
918 printk(KERN_ERR PFX "cleanup: couldnt allocate cmd\n");
919 rc = -1;
920 goto cleanup_err;
921 }
922
923 /* Initialize rest of io_req fields */
924 cleanup_io_req->sc_cmd = NULL;
925 cleanup_io_req->port = port;
926 cleanup_io_req->tgt = tgt;
927 cleanup_io_req->data_xfer_len = 0; /* No data transfer for cleanup */
928
929 xid = cleanup_io_req->xid;
930
931 task_idx = xid/BNX2FC_TASKS_PER_PAGE;
932 index = xid % BNX2FC_TASKS_PER_PAGE;
933
934 /* Initialize task context for this IO request */
935 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx];
936 task = &(task_page[index]);
937 orig_xid = io_req->xid;
938
939 BNX2FC_IO_DBG(io_req, "CLEANUP io_req xid = 0x%x\n", xid);
940
941 bnx2fc_init_cleanup_task(cleanup_io_req, task, orig_xid);
942
943 /* Obtain free SQ entry */
944 bnx2fc_add_2_sq(tgt, xid);
945
946 /* Ring doorbell */
947 bnx2fc_ring_doorbell(tgt);
948
949cleanup_err:
950 return rc;
951}
952
953/**
954 * bnx2fc_eh_target_reset: Reset a target
955 *
956 * @sc_cmd: SCSI command
957 *
958 * Set from SCSI host template to send task mgmt command to the target
959 * and wait for the response
960 */
961int bnx2fc_eh_target_reset(struct scsi_cmnd *sc_cmd)
962{
963 return bnx2fc_initiate_tmf(sc_cmd, FCP_TMF_TGT_RESET);
964}
965
966/**
967 * bnx2fc_eh_device_reset - Reset a single LUN
968 *
969 * @sc_cmd: SCSI command
970 *
971 * Set from SCSI host template to send task mgmt command to the target
972 * and wait for the response
973 */
974int bnx2fc_eh_device_reset(struct scsi_cmnd *sc_cmd)
975{
976 return bnx2fc_initiate_tmf(sc_cmd, FCP_TMF_LUN_RESET);
977}
978
979/**
980 * bnx2fc_eh_abort - eh_abort_handler api to abort an outstanding
981 * SCSI command
982 *
983 * @sc_cmd: SCSI_ML command pointer
984 *
985 * SCSI abort request handler
986 */
987int bnx2fc_eh_abort(struct scsi_cmnd *sc_cmd)
988{
989 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
990 struct fc_rport_libfc_priv *rp = rport->dd_data;
991 struct bnx2fc_cmd *io_req;
992 struct fc_lport *lport;
993 struct bnx2fc_rport *tgt;
994 int rc = FAILED;
995
996
997 rc = fc_block_scsi_eh(sc_cmd);
998 if (rc)
999 return rc;
1000
1001 lport = shost_priv(sc_cmd->device->host);
1002 if ((lport->state != LPORT_ST_READY) || !(lport->link_up)) {
1003 printk(KERN_ALERT PFX "eh_abort: link not ready\n");
1004 return rc;
1005 }
1006
1007 tgt = (struct bnx2fc_rport *)&rp[1];
1008
1009 BNX2FC_TGT_DBG(tgt, "Entered bnx2fc_eh_abort\n");
1010
1011 spin_lock_bh(&tgt->tgt_lock);
1012 io_req = (struct bnx2fc_cmd *)sc_cmd->SCp.ptr;
1013 if (!io_req) {
1014 /* Command might have just completed */
1015 printk(KERN_ERR PFX "eh_abort: io_req is NULL\n");
1016 spin_unlock_bh(&tgt->tgt_lock);
1017 return SUCCESS;
1018 }
1019 BNX2FC_IO_DBG(io_req, "eh_abort - refcnt = %d\n",
1020 io_req->refcount.refcount.counter);
1021
1022 /* Hold IO request across abort processing */
1023 kref_get(&io_req->refcount);
1024
1025 BUG_ON(tgt != io_req->tgt);
1026
1027 /* Remove the io_req from the active_q. */
1028 /*
1029 * Task Mgmt functions (LUN RESET & TGT RESET) will not
1030 * issue an ABTS on this particular IO req, as the
1031 * io_req is no longer in the active_q.
1032 */
1033 if (tgt->flush_in_prog) {
1034 printk(KERN_ALERT PFX "eh_abort: io_req (xid = 0x%x) "
1035 "flush in progress\n", io_req->xid);
1036 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1037 spin_unlock_bh(&tgt->tgt_lock);
1038 return SUCCESS;
1039 }
1040
1041 if (io_req->on_active_queue == 0) {
1042 printk(KERN_ALERT PFX "eh_abort: io_req (xid = 0x%x) "
1043 "not on active_q\n", io_req->xid);
1044 /*
1045 * This condition can happen only due to the FW bug,
1046 * where we do not receive cleanup response from
1047 * the FW. Handle this case gracefully by erroring
1048 * back the IO request to SCSI-ml
1049 */
1050 bnx2fc_scsi_done(io_req, DID_ABORT);
1051
1052 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1053 spin_unlock_bh(&tgt->tgt_lock);
1054 return SUCCESS;
1055 }
1056
1057 /*
1058 * Only eh_abort processing will remove the IO from
1059 * active_cmd_q before processing the request. this is
1060 * done to avoid race conditions between IOs aborted
1061 * as part of task management completion and eh_abort
1062 * processing
1063 */
1064 list_del_init(&io_req->link);
1065 io_req->on_active_queue = 0;
1066 /* Move IO req to retire queue */
1067 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1068
1069 init_completion(&io_req->tm_done);
1070 io_req->wait_for_comp = 1;
1071
1072 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
1073 /* Cancel the current timer running on this io_req */
1074 if (cancel_delayed_work(&io_req->timeout_work))
1075 kref_put(&io_req->refcount,
1076 bnx2fc_cmd_release); /* drop timer hold */
1077 set_bit(BNX2FC_FLAG_EH_ABORT, &io_req->req_flags);
1078 rc = bnx2fc_initiate_abts(io_req);
1079 } else {
1080 printk(KERN_ALERT PFX "eh_abort: io_req (xid = 0x%x) "
1081 "already in abts processing\n", io_req->xid);
1082 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1083 spin_unlock_bh(&tgt->tgt_lock);
1084 return SUCCESS;
1085 }
1086 if (rc == FAILED) {
1087 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1088 spin_unlock_bh(&tgt->tgt_lock);
1089 return rc;
1090 }
1091 spin_unlock_bh(&tgt->tgt_lock);
1092
1093 wait_for_completion(&io_req->tm_done);
1094
1095 spin_lock_bh(&tgt->tgt_lock);
1096 io_req->wait_for_comp = 0;
1097 if (!(test_and_set_bit(BNX2FC_FLAG_ABTS_DONE,
1098 &io_req->req_flags))) {
1099 /* Let the scsi-ml try to recover this command */
1100 printk(KERN_ERR PFX "abort failed, xid = 0x%x\n",
1101 io_req->xid);
1102 rc = FAILED;
1103 } else {
1104 /*
1105 * We come here even when there was a race condition
1106 * between timeout and abts completion, and abts
1107 * completion happens just in time.
1108 */
1109 BNX2FC_IO_DBG(io_req, "abort succeeded\n");
1110 rc = SUCCESS;
1111 bnx2fc_scsi_done(io_req, DID_ABORT);
1112 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1113 }
1114
1115 /* release the reference taken in eh_abort */
1116 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1117 spin_unlock_bh(&tgt->tgt_lock);
1118 return rc;
1119}
1120
1121void bnx2fc_process_cleanup_compl(struct bnx2fc_cmd *io_req,
1122 struct fcoe_task_ctx_entry *task,
1123 u8 num_rq)
1124{
1125 BNX2FC_IO_DBG(io_req, "Entered process_cleanup_compl "
1126 "refcnt = %d, cmd_type = %d\n",
1127 io_req->refcount.refcount.counter, io_req->cmd_type);
1128 bnx2fc_scsi_done(io_req, DID_ERROR);
1129 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1130}
1131
1132void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req,
1133 struct fcoe_task_ctx_entry *task,
1134 u8 num_rq)
1135{
1136 u32 r_ctl;
1137 u32 r_a_tov = FC_DEF_R_A_TOV;
1138 u8 issue_rrq = 0;
1139 struct bnx2fc_rport *tgt = io_req->tgt;
1140
1141 BNX2FC_IO_DBG(io_req, "Entered process_abts_compl xid = 0x%x"
1142 "refcnt = %d, cmd_type = %d\n",
1143 io_req->xid,
1144 io_req->refcount.refcount.counter, io_req->cmd_type);
1145
1146 if (test_and_set_bit(BNX2FC_FLAG_ABTS_DONE,
1147 &io_req->req_flags)) {
1148 BNX2FC_IO_DBG(io_req, "Timer context finished processing"
1149 " this io\n");
1150 return;
1151 }
1152
1153 /* Do not issue RRQ as this IO is already cleanedup */
1154 if (test_and_set_bit(BNX2FC_FLAG_IO_CLEANUP,
1155 &io_req->req_flags))
1156 goto io_compl;
1157
1158 /*
1159 * For ABTS issued due to SCSI eh_abort_handler, timeout
1160 * values are maintained by scsi-ml itself. Cancel timeout
1161 * in case ABTS issued as part of task management function
1162 * or due to FW error.
1163 */
1164 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags))
1165 if (cancel_delayed_work(&io_req->timeout_work))
1166 kref_put(&io_req->refcount,
1167 bnx2fc_cmd_release); /* drop timer hold */
1168
1169 r_ctl = task->cmn.general.rsp_info.abts_rsp.r_ctl;
1170
1171 switch (r_ctl) {
1172 case FC_RCTL_BA_ACC:
1173 /*
1174 * Dont release this cmd yet. It will be relesed
1175 * after we get RRQ response
1176 */
1177 BNX2FC_IO_DBG(io_req, "ABTS response - ACC Send RRQ\n");
1178 issue_rrq = 1;
1179 break;
1180
1181 case FC_RCTL_BA_RJT:
1182 BNX2FC_IO_DBG(io_req, "ABTS response - RJT\n");
1183 break;
1184 default:
1185 printk(KERN_ERR PFX "Unknown ABTS response\n");
1186 break;
1187 }
1188
1189 if (issue_rrq) {
1190 BNX2FC_IO_DBG(io_req, "Issue RRQ after R_A_TOV\n");
1191 set_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
1192 }
1193 set_bit(BNX2FC_FLAG_RETIRE_OXID, &io_req->req_flags);
1194 bnx2fc_cmd_timer_set(io_req, r_a_tov);
1195
1196io_compl:
1197 if (io_req->wait_for_comp) {
1198 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
1199 &io_req->req_flags))
1200 complete(&io_req->tm_done);
1201 } else {
1202 /*
1203 * We end up here when ABTS is issued as
1204 * in asynchronous context, i.e., as part
1205 * of task management completion, or
1206 * when FW error is received or when the
1207 * ABTS is issued when the IO is timed
1208 * out.
1209 */
1210
1211 if (io_req->on_active_queue) {
1212 list_del_init(&io_req->link);
1213 io_req->on_active_queue = 0;
1214 /* Move IO req to retire queue */
1215 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1216 }
1217 bnx2fc_scsi_done(io_req, DID_ERROR);
1218 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1219 }
1220}
1221
1222static void bnx2fc_lun_reset_cmpl(struct bnx2fc_cmd *io_req)
1223{
1224 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1225 struct bnx2fc_rport *tgt = io_req->tgt;
1226 struct list_head *list;
1227 struct list_head *tmp;
1228 struct bnx2fc_cmd *cmd;
1229 int tm_lun = sc_cmd->device->lun;
1230 int rc = 0;
1231 int lun;
1232
1233 /* called with tgt_lock held */
1234 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_lun_reset_cmpl\n");
1235 /*
1236 * Walk thru the active_ios queue and ABORT the IO
1237 * that matches with the LUN that was reset
1238 */
1239 list_for_each_safe(list, tmp, &tgt->active_cmd_queue) {
1240 BNX2FC_TGT_DBG(tgt, "LUN RST cmpl: scan for pending IOs\n");
1241 cmd = (struct bnx2fc_cmd *)list;
1242 lun = cmd->sc_cmd->device->lun;
1243 if (lun == tm_lun) {
1244 /* Initiate ABTS on this cmd */
1245 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
1246 &cmd->req_flags)) {
1247 /* cancel the IO timeout */
1248 if (cancel_delayed_work(&io_req->timeout_work))
1249 kref_put(&io_req->refcount,
1250 bnx2fc_cmd_release);
1251 /* timer hold */
1252 rc = bnx2fc_initiate_abts(cmd);
1253 /* abts shouldnt fail in this context */
1254 WARN_ON(rc != SUCCESS);
1255 } else
1256 printk(KERN_ERR PFX "lun_rst: abts already in"
1257 " progress for this IO 0x%x\n",
1258 cmd->xid);
1259 }
1260 }
1261}
1262
1263static void bnx2fc_tgt_reset_cmpl(struct bnx2fc_cmd *io_req)
1264{
1265 struct bnx2fc_rport *tgt = io_req->tgt;
1266 struct list_head *list;
1267 struct list_head *tmp;
1268 struct bnx2fc_cmd *cmd;
1269 int rc = 0;
1270
1271 /* called with tgt_lock held */
1272 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_tgt_reset_cmpl\n");
1273 /*
1274 * Walk thru the active_ios queue and ABORT the IO
1275 * that matches with the LUN that was reset
1276 */
1277 list_for_each_safe(list, tmp, &tgt->active_cmd_queue) {
1278 BNX2FC_TGT_DBG(tgt, "TGT RST cmpl: scan for pending IOs\n");
1279 cmd = (struct bnx2fc_cmd *)list;
1280 /* Initiate ABTS */
1281 if (!test_and_set_bit(BNX2FC_FLAG_ISSUE_ABTS,
1282 &cmd->req_flags)) {
1283 /* cancel the IO timeout */
1284 if (cancel_delayed_work(&io_req->timeout_work))
1285 kref_put(&io_req->refcount,
1286 bnx2fc_cmd_release); /* timer hold */
1287 rc = bnx2fc_initiate_abts(cmd);
1288 /* abts shouldnt fail in this context */
1289 WARN_ON(rc != SUCCESS);
1290
1291 } else
1292 printk(KERN_ERR PFX "tgt_rst: abts already in progress"
1293 " for this IO 0x%x\n", cmd->xid);
1294 }
1295}
1296
1297void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
1298 struct fcoe_task_ctx_entry *task, u8 num_rq)
1299{
1300 struct bnx2fc_mp_req *tm_req;
1301 struct fc_frame_header *fc_hdr;
1302 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1303 u64 *hdr;
1304 u64 *temp_hdr;
1305 void *rsp_buf;
1306
1307 /* Called with tgt_lock held */
1308 BNX2FC_IO_DBG(io_req, "Entered process_tm_compl\n");
1309
1310 if (!(test_bit(BNX2FC_FLAG_TM_TIMEOUT, &io_req->req_flags)))
1311 set_bit(BNX2FC_FLAG_TM_COMPL, &io_req->req_flags);
1312 else {
1313 /* TM has already timed out and we got
1314 * delayed completion. Ignore completion
1315 * processing.
1316 */
1317 return;
1318 }
1319
1320 tm_req = &(io_req->mp_req);
1321 fc_hdr = &(tm_req->resp_fc_hdr);
1322 hdr = (u64 *)fc_hdr;
1323 temp_hdr = (u64 *)
1324 &task->cmn.general.cmd_info.mp_fc_frame.fc_hdr;
1325 hdr[0] = cpu_to_be64(temp_hdr[0]);
1326 hdr[1] = cpu_to_be64(temp_hdr[1]);
1327 hdr[2] = cpu_to_be64(temp_hdr[2]);
1328
1329 tm_req->resp_len = task->rx_wr_only.sgl_ctx.mul_sges.cur_sge_off;
1330
1331 rsp_buf = tm_req->resp_buf;
1332
1333 if (fc_hdr->fh_r_ctl == FC_RCTL_DD_CMD_STATUS) {
1334 bnx2fc_parse_fcp_rsp(io_req,
1335 (struct fcoe_fcp_rsp_payload *)
1336 rsp_buf, num_rq);
1337 if (io_req->fcp_rsp_code == 0) {
1338 /* TM successful */
1339 if (tm_req->tm_flags & FCP_TMF_LUN_RESET)
1340 bnx2fc_lun_reset_cmpl(io_req);
1341 else if (tm_req->tm_flags & FCP_TMF_TGT_RESET)
1342 bnx2fc_tgt_reset_cmpl(io_req);
1343 }
1344 } else {
1345 printk(KERN_ERR PFX "tmf's fc_hdr r_ctl = 0x%x\n",
1346 fc_hdr->fh_r_ctl);
1347 }
1348 if (!sc_cmd->SCp.ptr) {
1349 printk(KERN_ALERT PFX "tm_compl: SCp.ptr is NULL\n");
1350 return;
1351 }
1352 switch (io_req->fcp_status) {
1353 case FC_GOOD:
1354 if (io_req->cdb_status == 0) {
1355 /* Good IO completion */
1356 sc_cmd->result = DID_OK << 16;
1357 } else {
1358 /* Transport status is good, SCSI status not good */
1359 sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
1360 }
1361 if (io_req->fcp_resid)
1362 scsi_set_resid(sc_cmd, io_req->fcp_resid);
1363 break;
1364
1365 default:
1366 BNX2FC_IO_DBG(io_req, "process_tm_compl: fcp_status = %d\n",
1367 io_req->fcp_status);
1368 break;
1369 }
1370
1371 sc_cmd = io_req->sc_cmd;
1372 io_req->sc_cmd = NULL;
1373
1374 /* check if the io_req exists in tgt's tmf_q */
1375 if (io_req->on_tmf_queue) {
1376
1377 list_del_init(&io_req->link);
1378 io_req->on_tmf_queue = 0;
1379 } else {
1380
1381 printk(KERN_ALERT PFX "Command not on active_cmd_queue!\n");
1382 return;
1383 }
1384
1385 sc_cmd->SCp.ptr = NULL;
1386 sc_cmd->scsi_done(sc_cmd);
1387
1388 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1389 if (io_req->wait_for_comp) {
1390 BNX2FC_IO_DBG(io_req, "tm_compl - wake up the waiter\n");
1391 complete(&io_req->tm_done);
1392 }
1393}
1394
1395static int bnx2fc_split_bd(struct bnx2fc_cmd *io_req, u64 addr, int sg_len,
1396 int bd_index)
1397{
1398 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1399 int frag_size, sg_frags;
1400
1401 sg_frags = 0;
1402 while (sg_len) {
1403 if (sg_len >= BNX2FC_BD_SPLIT_SZ)
1404 frag_size = BNX2FC_BD_SPLIT_SZ;
1405 else
1406 frag_size = sg_len;
1407 bd[bd_index + sg_frags].buf_addr_lo = addr & 0xffffffff;
1408 bd[bd_index + sg_frags].buf_addr_hi = addr >> 32;
1409 bd[bd_index + sg_frags].buf_len = (u16)frag_size;
1410 bd[bd_index + sg_frags].flags = 0;
1411
1412 addr += (u64) frag_size;
1413 sg_frags++;
1414 sg_len -= frag_size;
1415 }
1416 return sg_frags;
1417
1418}
1419
1420static int bnx2fc_map_sg(struct bnx2fc_cmd *io_req)
1421{
1422 struct scsi_cmnd *sc = io_req->sc_cmd;
1423 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1424 struct scatterlist *sg;
1425 int byte_count = 0;
1426 int sg_count = 0;
1427 int bd_count = 0;
1428 int sg_frags;
1429 unsigned int sg_len;
1430 u64 addr;
1431 int i;
1432
1433 sg_count = scsi_dma_map(sc);
1434 scsi_for_each_sg(sc, sg, sg_count, i) {
1435 sg_len = sg_dma_len(sg);
1436 addr = sg_dma_address(sg);
1437 if (sg_len > BNX2FC_MAX_BD_LEN) {
1438 sg_frags = bnx2fc_split_bd(io_req, addr, sg_len,
1439 bd_count);
1440 } else {
1441
1442 sg_frags = 1;
1443 bd[bd_count].buf_addr_lo = addr & 0xffffffff;
1444 bd[bd_count].buf_addr_hi = addr >> 32;
1445 bd[bd_count].buf_len = (u16)sg_len;
1446 bd[bd_count].flags = 0;
1447 }
1448 bd_count += sg_frags;
1449 byte_count += sg_len;
1450 }
1451 if (byte_count != scsi_bufflen(sc))
1452 printk(KERN_ERR PFX "byte_count = %d != scsi_bufflen = %d, "
1453 "task_id = 0x%x\n", byte_count, scsi_bufflen(sc),
1454 io_req->xid);
1455 return bd_count;
1456}
1457
1458static void bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req)
1459{
1460 struct scsi_cmnd *sc = io_req->sc_cmd;
1461 struct fcoe_bd_ctx *bd = io_req->bd_tbl->bd_tbl;
1462 int bd_count;
1463
1464 if (scsi_sg_count(sc))
1465 bd_count = bnx2fc_map_sg(io_req);
1466 else {
1467 bd_count = 0;
1468 bd[0].buf_addr_lo = bd[0].buf_addr_hi = 0;
1469 bd[0].buf_len = bd[0].flags = 0;
1470 }
1471 io_req->bd_tbl->bd_valid = bd_count;
1472}
1473
1474static void bnx2fc_unmap_sg_list(struct bnx2fc_cmd *io_req)
1475{
1476 struct scsi_cmnd *sc = io_req->sc_cmd;
1477
1478 if (io_req->bd_tbl->bd_valid && sc) {
1479 scsi_dma_unmap(sc);
1480 io_req->bd_tbl->bd_valid = 0;
1481 }
1482}
1483
1484void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
1485 struct fcp_cmnd *fcp_cmnd)
1486{
1487 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1488 char tag[2];
1489
1490 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
1491
1492 int_to_scsilun(sc_cmd->device->lun,
1493 (struct scsi_lun *) fcp_cmnd->fc_lun);
1494
1495
1496 fcp_cmnd->fc_dl = htonl(io_req->data_xfer_len);
1497 memcpy(fcp_cmnd->fc_cdb, sc_cmd->cmnd, sc_cmd->cmd_len);
1498
1499 fcp_cmnd->fc_cmdref = 0;
1500 fcp_cmnd->fc_pri_ta = 0;
1501 fcp_cmnd->fc_tm_flags = io_req->mp_req.tm_flags;
1502 fcp_cmnd->fc_flags = io_req->io_req_flags;
1503
1504 if (scsi_populate_tag_msg(sc_cmd, tag)) {
1505 switch (tag[0]) {
1506 case HEAD_OF_QUEUE_TAG:
1507 fcp_cmnd->fc_pri_ta = FCP_PTA_HEADQ;
1508 break;
1509 case ORDERED_QUEUE_TAG:
1510 fcp_cmnd->fc_pri_ta = FCP_PTA_ORDERED;
1511 break;
1512 default:
1513 fcp_cmnd->fc_pri_ta = FCP_PTA_SIMPLE;
1514 break;
1515 }
1516 } else {
1517 fcp_cmnd->fc_pri_ta = 0;
1518 }
1519}
1520
1521static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
1522 struct fcoe_fcp_rsp_payload *fcp_rsp,
1523 u8 num_rq)
1524{
1525 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1526 struct bnx2fc_rport *tgt = io_req->tgt;
1527 u8 rsp_flags = fcp_rsp->fcp_flags.flags;
1528 u32 rq_buff_len = 0;
1529 int i;
1530 unsigned char *rq_data;
1531 unsigned char *dummy;
1532 int fcp_sns_len = 0;
1533 int fcp_rsp_len = 0;
1534
1535 io_req->fcp_status = FC_GOOD;
1536 io_req->fcp_resid = fcp_rsp->fcp_resid;
1537
1538 io_req->scsi_comp_flags = rsp_flags;
1539 CMD_SCSI_STATUS(sc_cmd) = io_req->cdb_status =
1540 fcp_rsp->scsi_status_code;
1541
1542 /* Fetch fcp_rsp_info and fcp_sns_info if available */
1543 if (num_rq) {
1544
1545 /*
1546 * We do not anticipate num_rq >1, as the linux defined
1547 * SCSI_SENSE_BUFFERSIZE is 96 bytes + 8 bytes of FCP_RSP_INFO
1548 * 256 bytes of single rq buffer is good enough to hold this.
1549 */
1550
1551 if (rsp_flags &
1552 FCOE_FCP_RSP_FLAGS_FCP_RSP_LEN_VALID) {
1553 fcp_rsp_len = rq_buff_len
1554 = fcp_rsp->fcp_rsp_len;
1555 }
1556
1557 if (rsp_flags &
1558 FCOE_FCP_RSP_FLAGS_FCP_SNS_LEN_VALID) {
1559 fcp_sns_len = fcp_rsp->fcp_sns_len;
1560 rq_buff_len += fcp_rsp->fcp_sns_len;
1561 }
1562
1563 io_req->fcp_rsp_len = fcp_rsp_len;
1564 io_req->fcp_sns_len = fcp_sns_len;
1565
1566 if (rq_buff_len > num_rq * BNX2FC_RQ_BUF_SZ) {
1567 /* Invalid sense sense length. */
1568 printk(KERN_ALERT PFX "invalid sns length %d\n",
1569 rq_buff_len);
1570 /* reset rq_buff_len */
1571 rq_buff_len = num_rq * BNX2FC_RQ_BUF_SZ;
1572 }
1573
1574 rq_data = bnx2fc_get_next_rqe(tgt, 1);
1575
1576 if (num_rq > 1) {
1577 /* We do not need extra sense data */
1578 for (i = 1; i < num_rq; i++)
1579 dummy = bnx2fc_get_next_rqe(tgt, 1);
1580 }
1581
1582 /* fetch fcp_rsp_code */
1583 if ((fcp_rsp_len == 4) || (fcp_rsp_len == 8)) {
1584 /* Only for task management function */
1585 io_req->fcp_rsp_code = rq_data[3];
1586 printk(KERN_ERR PFX "fcp_rsp_code = %d\n",
1587 io_req->fcp_rsp_code);
1588 }
1589
1590 /* fetch sense data */
1591 rq_data += fcp_rsp_len;
1592
1593 if (fcp_sns_len > SCSI_SENSE_BUFFERSIZE) {
1594 printk(KERN_ERR PFX "Truncating sense buffer\n");
1595 fcp_sns_len = SCSI_SENSE_BUFFERSIZE;
1596 }
1597
1598 memset(sc_cmd->sense_buffer, 0, sizeof(sc_cmd->sense_buffer));
1599 if (fcp_sns_len)
1600 memcpy(sc_cmd->sense_buffer, rq_data, fcp_sns_len);
1601
1602 /* return RQ entries */
1603 for (i = 0; i < num_rq; i++)
1604 bnx2fc_return_rqe(tgt, 1);
1605 }
1606}
1607
1608/**
1609 * bnx2fc_queuecommand - Queuecommand function of the scsi template
1610 *
1611 * @host: The Scsi_Host the command was issued to
1612 * @sc_cmd: struct scsi_cmnd to be executed
1613 *
1614 * This is the IO strategy routine, called by SCSI-ML
1615 **/
1616int bnx2fc_queuecommand(struct Scsi_Host *host,
1617 struct scsi_cmnd *sc_cmd)
1618{
1619 struct fc_lport *lport = shost_priv(host);
1620 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
1621 struct fc_rport_libfc_priv *rp = rport->dd_data;
1622 struct bnx2fc_rport *tgt;
1623 struct bnx2fc_cmd *io_req;
1624 int rc = 0;
1625 int rval;
1626
1627 rval = fc_remote_port_chkready(rport);
1628 if (rval) {
1629 sc_cmd->result = rval;
1630 sc_cmd->scsi_done(sc_cmd);
1631 return 0;
1632 }
1633
1634 if ((lport->state != LPORT_ST_READY) || !(lport->link_up)) {
1635 rc = SCSI_MLQUEUE_HOST_BUSY;
1636 goto exit_qcmd;
1637 }
1638
1639 /* rport and tgt are allocated together, so tgt should be non-NULL */
1640 tgt = (struct bnx2fc_rport *)&rp[1];
1641
1642 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
1643 /*
1644 * Session is not offloaded yet. Let SCSI-ml retry
1645 * the command.
1646 */
1647 rc = SCSI_MLQUEUE_TARGET_BUSY;
1648 goto exit_qcmd;
1649 }
1650
1651 io_req = bnx2fc_cmd_alloc(tgt);
1652 if (!io_req) {
1653 rc = SCSI_MLQUEUE_HOST_BUSY;
1654 goto exit_qcmd;
1655 }
1656 io_req->sc_cmd = sc_cmd;
1657
1658 if (bnx2fc_post_io_req(tgt, io_req)) {
1659 printk(KERN_ERR PFX "Unable to post io_req\n");
1660 rc = SCSI_MLQUEUE_HOST_BUSY;
1661 goto exit_qcmd;
1662 }
1663exit_qcmd:
1664 return rc;
1665}
1666
1667void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
1668 struct fcoe_task_ctx_entry *task,
1669 u8 num_rq)
1670{
1671 struct fcoe_fcp_rsp_payload *fcp_rsp;
1672 struct bnx2fc_rport *tgt = io_req->tgt;
1673 struct scsi_cmnd *sc_cmd;
1674 struct Scsi_Host *host;
1675
1676
1677 /* scsi_cmd_cmpl is called with tgt lock held */
1678
1679 if (test_and_set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags)) {
1680 /* we will not receive ABTS response for this IO */
1681 BNX2FC_IO_DBG(io_req, "Timer context finished processing "
1682 "this scsi cmd\n");
1683 }
1684
1685 /* Cancel the timeout_work, as we received IO completion */
1686 if (cancel_delayed_work(&io_req->timeout_work))
1687 kref_put(&io_req->refcount,
1688 bnx2fc_cmd_release); /* drop timer hold */
1689
1690 sc_cmd = io_req->sc_cmd;
1691 if (sc_cmd == NULL) {
1692 printk(KERN_ERR PFX "scsi_cmd_compl - sc_cmd is NULL\n");
1693 return;
1694 }
1695
1696 /* Fetch fcp_rsp from task context and perform cmd completion */
1697 fcp_rsp = (struct fcoe_fcp_rsp_payload *)
1698 &(task->cmn.general.rsp_info.fcp_rsp.payload);
1699
1700 /* parse fcp_rsp and obtain sense data from RQ if available */
1701 bnx2fc_parse_fcp_rsp(io_req, fcp_rsp, num_rq);
1702
1703 host = sc_cmd->device->host;
1704 if (!sc_cmd->SCp.ptr) {
1705 printk(KERN_ERR PFX "SCp.ptr is NULL\n");
1706 return;
1707 }
1708 io_req->sc_cmd = NULL;
1709
1710 if (io_req->on_active_queue) {
1711 list_del_init(&io_req->link);
1712 io_req->on_active_queue = 0;
1713 /* Move IO req to retire queue */
1714 list_add_tail(&io_req->link, &tgt->io_retire_queue);
1715 } else {
1716 /* This should not happen, but could have been pulled
1717 * by bnx2fc_flush_active_ios(), or during a race
1718 * between command abort and (late) completion.
1719 */
1720 BNX2FC_IO_DBG(io_req, "xid not on active_cmd_queue\n");
1721 if (io_req->wait_for_comp)
1722 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
1723 &io_req->req_flags))
1724 complete(&io_req->tm_done);
1725 }
1726
1727 bnx2fc_unmap_sg_list(io_req);
1728
1729 switch (io_req->fcp_status) {
1730 case FC_GOOD:
1731 if (io_req->cdb_status == 0) {
1732 /* Good IO completion */
1733 sc_cmd->result = DID_OK << 16;
1734 } else {
1735 /* Transport status is good, SCSI status not good */
1736 BNX2FC_IO_DBG(io_req, "scsi_cmpl: cdb_status = %d"
1737 " fcp_resid = 0x%x\n",
1738 io_req->cdb_status, io_req->fcp_resid);
1739 sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
1740 }
1741 if (io_req->fcp_resid)
1742 scsi_set_resid(sc_cmd, io_req->fcp_resid);
1743 break;
1744 default:
1745 printk(KERN_ALERT PFX "scsi_cmd_compl: fcp_status = %d\n",
1746 io_req->fcp_status);
1747 break;
1748 }
1749 sc_cmd->SCp.ptr = NULL;
1750 sc_cmd->scsi_done(sc_cmd);
1751 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1752}
1753
1754static int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
1755 struct bnx2fc_cmd *io_req)
1756{
1757 struct fcoe_task_ctx_entry *task;
1758 struct fcoe_task_ctx_entry *task_page;
1759 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1760 struct fcoe_port *port = tgt->port;
1761 struct bnx2fc_hba *hba = port->priv;
1762 struct fc_lport *lport = port->lport;
1763 struct fcoe_dev_stats *stats;
1764 int task_idx, index;
1765 u16 xid;
1766
1767 /* Initialize rest of io_req fields */
1768 io_req->cmd_type = BNX2FC_SCSI_CMD;
1769 io_req->port = port;
1770 io_req->tgt = tgt;
1771 io_req->data_xfer_len = scsi_bufflen(sc_cmd);
1772 sc_cmd->SCp.ptr = (char *)io_req;
1773
1774 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
1775 if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) {
1776 io_req->io_req_flags = BNX2FC_READ;
1777 stats->InputRequests++;
1778 stats->InputBytes += io_req->data_xfer_len;
1779 } else if (sc_cmd->sc_data_direction == DMA_TO_DEVICE) {
1780 io_req->io_req_flags = BNX2FC_WRITE;
1781 stats->OutputRequests++;
1782 stats->OutputBytes += io_req->data_xfer_len;
1783 } else {
1784 io_req->io_req_flags = 0;
1785 stats->ControlRequests++;
1786 }
1787 put_cpu();
1788
1789 xid = io_req->xid;
1790
1791 /* Build buffer descriptor list for firmware from sg list */
1792 bnx2fc_build_bd_list_from_sg(io_req);
1793
1794 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
1795 index = xid % BNX2FC_TASKS_PER_PAGE;
1796
1797 /* Initialize task context for this IO request */
1798 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx];
1799 task = &(task_page[index]);
1800 bnx2fc_init_task(io_req, task);
1801
1802 spin_lock_bh(&tgt->tgt_lock);
1803
1804 if (tgt->flush_in_prog) {
1805 printk(KERN_ERR PFX "Flush in progress..Host Busy\n");
1806 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1807 spin_unlock_bh(&tgt->tgt_lock);
1808 return -EAGAIN;
1809 }
1810
1811 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
1812 printk(KERN_ERR PFX "Session not ready...post_io\n");
1813 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1814 spin_unlock_bh(&tgt->tgt_lock);
1815 return -EAGAIN;
1816 }
1817
1818 /* Time IO req */
1819 bnx2fc_cmd_timer_set(io_req, BNX2FC_IO_TIMEOUT);
1820 /* Obtain free SQ entry */
1821 bnx2fc_add_2_sq(tgt, xid);
1822
1823 /* Enqueue the io_req to active_cmd_queue */
1824
1825 io_req->on_active_queue = 1;
1826 /* move io_req from pending_queue to active_queue */
1827 list_add_tail(&io_req->link, &tgt->active_cmd_queue);
1828
1829 /* Ring doorbell */
1830 bnx2fc_ring_doorbell(tgt);
1831 spin_unlock_bh(&tgt->tgt_lock);
1832 return 0;
1833}
diff --git a/drivers/scsi/bnx2fc/bnx2fc_tgt.c b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
new file mode 100644
index 000000000000..7ea93af60260
--- /dev/null
+++ b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
@@ -0,0 +1,844 @@
1/* bnx2fc_tgt.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * Handles operations such as session offload/upload etc, and manages
3 * session resources such as connection id and qp resources.
4 *
5 * Copyright (c) 2008 - 2010 Broadcom Corporation
6 *
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.
10 *
11 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
12 */
13
14#include "bnx2fc.h"
15static void bnx2fc_upld_timer(unsigned long data);
16static void bnx2fc_ofld_timer(unsigned long data);
17static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
18 struct fcoe_port *port,
19 struct fc_rport_priv *rdata);
20static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
21 struct bnx2fc_rport *tgt);
22static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
23 struct bnx2fc_rport *tgt);
24static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
25 struct bnx2fc_rport *tgt);
26static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id);
27
28static void bnx2fc_upld_timer(unsigned long data)
29{
30
31 struct bnx2fc_rport *tgt = (struct bnx2fc_rport *)data;
32
33 BNX2FC_TGT_DBG(tgt, "upld_timer - Upload compl not received!!\n");
34 /* fake upload completion */
35 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
36 set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
37 wake_up_interruptible(&tgt->upld_wait);
38}
39
40static void bnx2fc_ofld_timer(unsigned long data)
41{
42
43 struct bnx2fc_rport *tgt = (struct bnx2fc_rport *)data;
44
45 BNX2FC_TGT_DBG(tgt, "entered bnx2fc_ofld_timer\n");
46 /* NOTE: This function should never be called, as
47 * offload should never timeout
48 */
49 /*
50 * If the timer has expired, this session is dead
51 * Clear offloaded flag and logout of this device.
52 * Since OFFLOADED flag is cleared, this case
53 * will be considered as offload error and the
54 * port will be logged off, and conn_id, session
55 * resources are freed up in bnx2fc_offload_session
56 */
57 clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
58 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
59 wake_up_interruptible(&tgt->ofld_wait);
60}
61
62static void bnx2fc_offload_session(struct fcoe_port *port,
63 struct bnx2fc_rport *tgt,
64 struct fc_rport_priv *rdata)
65{
66 struct fc_lport *lport = rdata->local_port;
67 struct fc_rport *rport = rdata->rport;
68 struct bnx2fc_hba *hba = port->priv;
69 int rval;
70 int i = 0;
71
72 /* Initialize bnx2fc_rport */
73 /* NOTE: tgt is already bzero'd */
74 rval = bnx2fc_init_tgt(tgt, port, rdata);
75 if (rval) {
76 printk(KERN_ERR PFX "Failed to allocate conn id for "
77 "port_id (%6x)\n", rport->port_id);
78 goto ofld_err;
79 }
80
81 /* Allocate session resources */
82 rval = bnx2fc_alloc_session_resc(hba, tgt);
83 if (rval) {
84 printk(KERN_ERR PFX "Failed to allocate resources\n");
85 goto ofld_err;
86 }
87
88 /*
89 * Initialize FCoE session offload process.
90 * Upon completion of offload process add
91 * rport to list of rports
92 */
93retry_ofld:
94 clear_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
95 rval = bnx2fc_send_session_ofld_req(port, tgt);
96 if (rval) {
97 printk(KERN_ERR PFX "ofld_req failed\n");
98 goto ofld_err;
99 }
100
101 /*
102 * wait for the session is offloaded and enabled. 3 Secs
103 * should be ample time for this process to complete.
104 */
105 setup_timer(&tgt->ofld_timer, bnx2fc_ofld_timer, (unsigned long)tgt);
106 mod_timer(&tgt->ofld_timer, jiffies + BNX2FC_FW_TIMEOUT);
107
108 wait_event_interruptible(tgt->ofld_wait,
109 (test_bit(
110 BNX2FC_FLAG_OFLD_REQ_CMPL,
111 &tgt->flags)));
112 if (signal_pending(current))
113 flush_signals(current);
114
115 del_timer_sync(&tgt->ofld_timer);
116
117 if (!(test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags))) {
118 if (test_and_clear_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE,
119 &tgt->flags)) {
120 BNX2FC_TGT_DBG(tgt, "ctx_alloc_failure, "
121 "retry ofld..%d\n", i++);
122 msleep_interruptible(1000);
123 if (i > 3) {
124 i = 0;
125 goto ofld_err;
126 }
127 goto retry_ofld;
128 }
129 goto ofld_err;
130 }
131 if (bnx2fc_map_doorbell(tgt)) {
132 printk(KERN_ERR PFX "map doorbell failed - no mem\n");
133 /* upload will take care of cleaning up sess resc */
134 lport->tt.rport_logoff(rdata);
135 }
136 return;
137
138ofld_err:
139 /* couldn't offload the session. log off from this rport */
140 BNX2FC_TGT_DBG(tgt, "bnx2fc_offload_session - offload error\n");
141 lport->tt.rport_logoff(rdata);
142 /* Free session resources */
143 bnx2fc_free_session_resc(hba, tgt);
144 if (tgt->fcoe_conn_id != -1)
145 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
146}
147
148void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
149{
150 struct bnx2fc_cmd *io_req;
151 struct list_head *list;
152 struct list_head *tmp;
153 int rc;
154 int i = 0;
155 BNX2FC_TGT_DBG(tgt, "Entered flush_active_ios - %d\n",
156 tgt->num_active_ios.counter);
157
158 spin_lock_bh(&tgt->tgt_lock);
159 tgt->flush_in_prog = 1;
160
161 list_for_each_safe(list, tmp, &tgt->active_cmd_queue) {
162 i++;
163 io_req = (struct bnx2fc_cmd *)list;
164 list_del_init(&io_req->link);
165 io_req->on_active_queue = 0;
166 BNX2FC_IO_DBG(io_req, "cmd_queue cleanup\n");
167
168 if (cancel_delayed_work(&io_req->timeout_work)) {
169 if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
170 &io_req->req_flags)) {
171 /* Handle eh_abort timeout */
172 BNX2FC_IO_DBG(io_req, "eh_abort for IO "
173 "cleaned up\n");
174 complete(&io_req->tm_done);
175 }
176 kref_put(&io_req->refcount,
177 bnx2fc_cmd_release); /* drop timer hold */
178 }
179
180 set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags);
181 set_bit(BNX2FC_FLAG_IO_CLEANUP, &io_req->req_flags);
182 rc = bnx2fc_initiate_cleanup(io_req);
183 BUG_ON(rc);
184 }
185
186 list_for_each_safe(list, tmp, &tgt->els_queue) {
187 i++;
188 io_req = (struct bnx2fc_cmd *)list;
189 list_del_init(&io_req->link);
190 io_req->on_active_queue = 0;
191
192 BNX2FC_IO_DBG(io_req, "els_queue cleanup\n");
193
194 if (cancel_delayed_work(&io_req->timeout_work))
195 kref_put(&io_req->refcount,
196 bnx2fc_cmd_release); /* drop timer hold */
197
198 if ((io_req->cb_func) && (io_req->cb_arg)) {
199 io_req->cb_func(io_req->cb_arg);
200 io_req->cb_arg = NULL;
201 }
202
203 rc = bnx2fc_initiate_cleanup(io_req);
204 BUG_ON(rc);
205 }
206
207 list_for_each_safe(list, tmp, &tgt->io_retire_queue) {
208 i++;
209 io_req = (struct bnx2fc_cmd *)list;
210 list_del_init(&io_req->link);
211
212 BNX2FC_IO_DBG(io_req, "retire_queue flush\n");
213
214 if (cancel_delayed_work(&io_req->timeout_work))
215 kref_put(&io_req->refcount, bnx2fc_cmd_release);
216
217 clear_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
218 }
219
220 BNX2FC_TGT_DBG(tgt, "IOs flushed = %d\n", i);
221 i = 0;
222 spin_unlock_bh(&tgt->tgt_lock);
223 /* wait for active_ios to go to 0 */
224 while ((tgt->num_active_ios.counter != 0) && (i++ < BNX2FC_WAIT_CNT))
225 msleep(25);
226 if (tgt->num_active_ios.counter != 0)
227 printk(KERN_ERR PFX "CLEANUP on port 0x%x:"
228 " active_ios = %d\n",
229 tgt->rdata->ids.port_id, tgt->num_active_ios.counter);
230 spin_lock_bh(&tgt->tgt_lock);
231 tgt->flush_in_prog = 0;
232 spin_unlock_bh(&tgt->tgt_lock);
233}
234
235static void bnx2fc_upload_session(struct fcoe_port *port,
236 struct bnx2fc_rport *tgt)
237{
238 struct bnx2fc_hba *hba = port->priv;
239
240 BNX2FC_TGT_DBG(tgt, "upload_session: active_ios = %d\n",
241 tgt->num_active_ios.counter);
242
243 /*
244 * Called with hba->hba_mutex held.
245 * This is a blocking call
246 */
247 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
248 bnx2fc_send_session_disable_req(port, tgt);
249
250 /*
251 * wait for upload to complete. 3 Secs
252 * should be sufficient time for this process to complete.
253 */
254 setup_timer(&tgt->upld_timer, bnx2fc_upld_timer, (unsigned long)tgt);
255 mod_timer(&tgt->upld_timer, jiffies + BNX2FC_FW_TIMEOUT);
256
257 BNX2FC_TGT_DBG(tgt, "waiting for disable compl\n");
258 wait_event_interruptible(tgt->upld_wait,
259 (test_bit(
260 BNX2FC_FLAG_UPLD_REQ_COMPL,
261 &tgt->flags)));
262
263 if (signal_pending(current))
264 flush_signals(current);
265
266 del_timer_sync(&tgt->upld_timer);
267
268 /*
269 * traverse thru the active_q and tmf_q and cleanup
270 * IOs in these lists
271 */
272 BNX2FC_TGT_DBG(tgt, "flush/upload - disable wait flags = 0x%lx\n",
273 tgt->flags);
274 bnx2fc_flush_active_ios(tgt);
275
276 /* Issue destroy KWQE */
277 if (test_bit(BNX2FC_FLAG_DISABLED, &tgt->flags)) {
278 BNX2FC_TGT_DBG(tgt, "send destroy req\n");
279 clear_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
280 bnx2fc_send_session_destroy_req(hba, tgt);
281
282 /* wait for destroy to complete */
283 setup_timer(&tgt->upld_timer,
284 bnx2fc_upld_timer, (unsigned long)tgt);
285 mod_timer(&tgt->upld_timer, jiffies + BNX2FC_FW_TIMEOUT);
286
287 wait_event_interruptible(tgt->upld_wait,
288 (test_bit(
289 BNX2FC_FLAG_UPLD_REQ_COMPL,
290 &tgt->flags)));
291
292 if (!(test_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags)))
293 printk(KERN_ERR PFX "ERROR!! destroy timed out\n");
294
295 BNX2FC_TGT_DBG(tgt, "destroy wait complete flags = 0x%lx\n",
296 tgt->flags);
297 if (signal_pending(current))
298 flush_signals(current);
299
300 del_timer_sync(&tgt->upld_timer);
301
302 } else
303 printk(KERN_ERR PFX "ERROR!! DISABLE req timed out, destroy"
304 " not sent to FW\n");
305
306 /* Free session resources */
307 spin_lock_bh(&tgt->cq_lock);
308 bnx2fc_free_session_resc(hba, tgt);
309 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
310 spin_unlock_bh(&tgt->cq_lock);
311}
312
313static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
314 struct fcoe_port *port,
315 struct fc_rport_priv *rdata)
316{
317
318 struct fc_rport *rport = rdata->rport;
319 struct bnx2fc_hba *hba = port->priv;
320
321 tgt->rport = rport;
322 tgt->rdata = rdata;
323 tgt->port = port;
324
325 if (hba->num_ofld_sess >= BNX2FC_NUM_MAX_SESS) {
326 BNX2FC_TGT_DBG(tgt, "exceeded max sessions. logoff this tgt\n");
327 tgt->fcoe_conn_id = -1;
328 return -1;
329 }
330
331 tgt->fcoe_conn_id = bnx2fc_alloc_conn_id(hba, tgt);
332 if (tgt->fcoe_conn_id == -1)
333 return -1;
334
335 BNX2FC_TGT_DBG(tgt, "init_tgt - conn_id = 0x%x\n", tgt->fcoe_conn_id);
336
337 tgt->max_sqes = BNX2FC_SQ_WQES_MAX;
338 tgt->max_rqes = BNX2FC_RQ_WQES_MAX;
339 tgt->max_cqes = BNX2FC_CQ_WQES_MAX;
340
341 /* Initialize the toggle bit */
342 tgt->sq_curr_toggle_bit = 1;
343 tgt->cq_curr_toggle_bit = 1;
344 tgt->sq_prod_idx = 0;
345 tgt->cq_cons_idx = 0;
346 tgt->rq_prod_idx = 0x8000;
347 tgt->rq_cons_idx = 0;
348 atomic_set(&tgt->num_active_ios, 0);
349
350 tgt->work_time_slice = 2;
351
352 spin_lock_init(&tgt->tgt_lock);
353 spin_lock_init(&tgt->cq_lock);
354
355 /* Initialize active_cmd_queue list */
356 INIT_LIST_HEAD(&tgt->active_cmd_queue);
357
358 /* Initialize IO retire queue */
359 INIT_LIST_HEAD(&tgt->io_retire_queue);
360
361 INIT_LIST_HEAD(&tgt->els_queue);
362
363 /* Initialize active_tm_queue list */
364 INIT_LIST_HEAD(&tgt->active_tm_queue);
365
366 init_waitqueue_head(&tgt->ofld_wait);
367 init_waitqueue_head(&tgt->upld_wait);
368
369 return 0;
370}
371
372/**
373 * This event_callback is called after successful completion of libfc
374 * initiated target login. bnx2fc can proceed with initiating the session
375 * establishment.
376 */
377void bnx2fc_rport_event_handler(struct fc_lport *lport,
378 struct fc_rport_priv *rdata,
379 enum fc_rport_event event)
380{
381 struct fcoe_port *port = lport_priv(lport);
382 struct bnx2fc_hba *hba = port->priv;
383 struct fc_rport *rport = rdata->rport;
384 struct fc_rport_libfc_priv *rp;
385 struct bnx2fc_rport *tgt;
386 u32 port_id;
387
388 BNX2FC_HBA_DBG(lport, "rport_event_hdlr: event = %d, port_id = 0x%x\n",
389 event, rdata->ids.port_id);
390 switch (event) {
391 case RPORT_EV_READY:
392 if (!rport) {
393 printk(KERN_ALERT PFX "rport is NULL: ERROR!\n");
394 break;
395 }
396
397 rp = rport->dd_data;
398 if (rport->port_id == FC_FID_DIR_SERV) {
399 /*
400 * bnx2fc_rport structure doesnt exist for
401 * directory server.
402 * We should not come here, as lport will
403 * take care of fabric login
404 */
405 printk(KERN_ALERT PFX "%x - rport_event_handler ERROR\n",
406 rdata->ids.port_id);
407 break;
408 }
409
410 if (rdata->spp_type != FC_TYPE_FCP) {
411 BNX2FC_HBA_DBG(lport, "not FCP type target."
412 " not offloading\n");
413 break;
414 }
415 if (!(rdata->ids.roles & FC_RPORT_ROLE_FCP_TARGET)) {
416 BNX2FC_HBA_DBG(lport, "not FCP_TARGET"
417 " not offloading\n");
418 break;
419 }
420
421 /*
422 * Offlaod process is protected with hba mutex.
423 * Use the same mutex_lock for upload process too
424 */
425 mutex_lock(&hba->hba_mutex);
426 tgt = (struct bnx2fc_rport *)&rp[1];
427
428 /* This can happen when ADISC finds the same target */
429 if (test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags)) {
430 BNX2FC_TGT_DBG(tgt, "already offloaded\n");
431 mutex_unlock(&hba->hba_mutex);
432 return;
433 }
434
435 /*
436 * Offload the session. This is a blocking call, and will
437 * wait until the session is offloaded.
438 */
439 bnx2fc_offload_session(port, tgt, rdata);
440
441 BNX2FC_TGT_DBG(tgt, "OFFLOAD num_ofld_sess = %d\n",
442 hba->num_ofld_sess);
443
444 if (test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags)) {
445 /*
446 * Session is offloaded and enabled. Map
447 * doorbell register for this target
448 */
449 BNX2FC_TGT_DBG(tgt, "sess offloaded\n");
450 /* This counter is protected with hba mutex */
451 hba->num_ofld_sess++;
452
453 set_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
454 } else {
455 /*
456 * Offload or enable would have failed.
457 * In offload/enable completion path, the
458 * rport would have already been removed
459 */
460 BNX2FC_TGT_DBG(tgt, "Port is being logged off as "
461 "offloaded flag not set\n");
462 }
463 mutex_unlock(&hba->hba_mutex);
464 break;
465 case RPORT_EV_LOGO:
466 case RPORT_EV_FAILED:
467 case RPORT_EV_STOP:
468 port_id = rdata->ids.port_id;
469 if (port_id == FC_FID_DIR_SERV)
470 break;
471
472 if (!rport) {
473 printk(KERN_ALERT PFX "%x - rport not created Yet!!\n",
474 port_id);
475 break;
476 }
477 rp = rport->dd_data;
478 mutex_lock(&hba->hba_mutex);
479 /*
480 * Perform session upload. Note that rdata->peers is already
481 * removed from disc->rports list before we get this event.
482 */
483 tgt = (struct bnx2fc_rport *)&rp[1];
484
485 if (!(test_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags))) {
486 mutex_unlock(&hba->hba_mutex);
487 break;
488 }
489 clear_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags);
490
491 bnx2fc_upload_session(port, tgt);
492 hba->num_ofld_sess--;
493 BNX2FC_TGT_DBG(tgt, "UPLOAD num_ofld_sess = %d\n",
494 hba->num_ofld_sess);
495 /*
496 * Try to wake up the linkdown wait thread. If num_ofld_sess
497 * is 0, the waiting therad wakes up
498 */
499 if ((hba->wait_for_link_down) &&
500 (hba->num_ofld_sess == 0)) {
501 wake_up_interruptible(&hba->shutdown_wait);
502 }
503 if (test_bit(BNX2FC_FLAG_EXPL_LOGO, &tgt->flags)) {
504 printk(KERN_ERR PFX "Relogin to the tgt\n");
505 mutex_lock(&lport->disc.disc_mutex);
506 lport->tt.rport_login(rdata);
507 mutex_unlock(&lport->disc.disc_mutex);
508 }
509 mutex_unlock(&hba->hba_mutex);
510
511 break;
512
513 case RPORT_EV_NONE:
514 break;
515 }
516}
517
518/**
519 * bnx2fc_tgt_lookup() - Lookup a bnx2fc_rport by port_id
520 *
521 * @port: fcoe_port struct to lookup the target port on
522 * @port_id: The remote port ID to look up
523 */
524struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port,
525 u32 port_id)
526{
527 struct bnx2fc_hba *hba = port->priv;
528 struct bnx2fc_rport *tgt;
529 struct fc_rport_priv *rdata;
530 int i;
531
532 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
533 tgt = hba->tgt_ofld_list[i];
534 if ((tgt) && (tgt->port == port)) {
535 rdata = tgt->rdata;
536 if (rdata->ids.port_id == port_id) {
537 if (rdata->rp_state != RPORT_ST_DELETE) {
538 BNX2FC_TGT_DBG(tgt, "rport "
539 "obtained\n");
540 return tgt;
541 } else {
542 printk(KERN_ERR PFX "rport 0x%x "
543 "is in DELETED state\n",
544 rdata->ids.port_id);
545 return NULL;
546 }
547 }
548 }
549 }
550 return NULL;
551}
552
553
554/**
555 * bnx2fc_alloc_conn_id - allocates FCOE Connection id
556 *
557 * @hba: pointer to adapter structure
558 * @tgt: pointer to bnx2fc_rport structure
559 */
560static u32 bnx2fc_alloc_conn_id(struct bnx2fc_hba *hba,
561 struct bnx2fc_rport *tgt)
562{
563 u32 conn_id, next;
564
565 /* called with hba mutex held */
566
567 /*
568 * tgt_ofld_list access is synchronized using
569 * both hba mutex and hba lock. Atleast hba mutex or
570 * hba lock needs to be held for read access.
571 */
572
573 spin_lock_bh(&hba->hba_lock);
574 next = hba->next_conn_id;
575 conn_id = hba->next_conn_id++;
576 if (hba->next_conn_id == BNX2FC_NUM_MAX_SESS)
577 hba->next_conn_id = 0;
578
579 while (hba->tgt_ofld_list[conn_id] != NULL) {
580 conn_id++;
581 if (conn_id == BNX2FC_NUM_MAX_SESS)
582 conn_id = 0;
583
584 if (conn_id == next) {
585 /* No free conn_ids are available */
586 spin_unlock_bh(&hba->hba_lock);
587 return -1;
588 }
589 }
590 hba->tgt_ofld_list[conn_id] = tgt;
591 tgt->fcoe_conn_id = conn_id;
592 spin_unlock_bh(&hba->hba_lock);
593 return conn_id;
594}
595
596static void bnx2fc_free_conn_id(struct bnx2fc_hba *hba, u32 conn_id)
597{
598 /* called with hba mutex held */
599 spin_lock_bh(&hba->hba_lock);
600 hba->tgt_ofld_list[conn_id] = NULL;
601 hba->next_conn_id = conn_id;
602 spin_unlock_bh(&hba->hba_lock);
603}
604
605/**
606 *bnx2fc_alloc_session_resc - Allocate qp resources for the session
607 *
608 */
609static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
610 struct bnx2fc_rport *tgt)
611{
612 dma_addr_t page;
613 int num_pages;
614 u32 *pbl;
615
616 /* Allocate and map SQ */
617 tgt->sq_mem_size = tgt->max_sqes * BNX2FC_SQ_WQE_SIZE;
618 tgt->sq_mem_size = (tgt->sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
619
620 tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
621 &tgt->sq_dma, GFP_KERNEL);
622 if (!tgt->sq) {
623 printk(KERN_ALERT PFX "unable to allocate SQ memory %d\n",
624 tgt->sq_mem_size);
625 goto mem_alloc_failure;
626 }
627 memset(tgt->sq, 0, tgt->sq_mem_size);
628
629 /* Allocate and map CQ */
630 tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE;
631 tgt->cq_mem_size = (tgt->cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
632
633 tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
634 &tgt->cq_dma, GFP_KERNEL);
635 if (!tgt->cq) {
636 printk(KERN_ALERT PFX "unable to allocate CQ memory %d\n",
637 tgt->cq_mem_size);
638 goto mem_alloc_failure;
639 }
640 memset(tgt->cq, 0, tgt->cq_mem_size);
641
642 /* Allocate and map RQ and RQ PBL */
643 tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE;
644 tgt->rq_mem_size = (tgt->rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
645
646 tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
647 &tgt->rq_dma, GFP_KERNEL);
648 if (!tgt->rq) {
649 printk(KERN_ALERT PFX "unable to allocate RQ memory %d\n",
650 tgt->rq_mem_size);
651 goto mem_alloc_failure;
652 }
653 memset(tgt->rq, 0, tgt->rq_mem_size);
654
655 tgt->rq_pbl_size = (tgt->rq_mem_size / PAGE_SIZE) * sizeof(void *);
656 tgt->rq_pbl_size = (tgt->rq_pbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
657
658 tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
659 &tgt->rq_pbl_dma, GFP_KERNEL);
660 if (!tgt->rq_pbl) {
661 printk(KERN_ALERT PFX "unable to allocate RQ PBL %d\n",
662 tgt->rq_pbl_size);
663 goto mem_alloc_failure;
664 }
665
666 memset(tgt->rq_pbl, 0, tgt->rq_pbl_size);
667 num_pages = tgt->rq_mem_size / PAGE_SIZE;
668 page = tgt->rq_dma;
669 pbl = (u32 *)tgt->rq_pbl;
670
671 while (num_pages--) {
672 *pbl = (u32)page;
673 pbl++;
674 *pbl = (u32)((u64)page >> 32);
675 pbl++;
676 page += PAGE_SIZE;
677 }
678
679 /* Allocate and map XFERQ */
680 tgt->xferq_mem_size = tgt->max_sqes * BNX2FC_XFERQ_WQE_SIZE;
681 tgt->xferq_mem_size = (tgt->xferq_mem_size + (PAGE_SIZE - 1)) &
682 PAGE_MASK;
683
684 tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
685 &tgt->xferq_dma, GFP_KERNEL);
686 if (!tgt->xferq) {
687 printk(KERN_ALERT PFX "unable to allocate XFERQ %d\n",
688 tgt->xferq_mem_size);
689 goto mem_alloc_failure;
690 }
691 memset(tgt->xferq, 0, tgt->xferq_mem_size);
692
693 /* Allocate and map CONFQ & CONFQ PBL */
694 tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE;
695 tgt->confq_mem_size = (tgt->confq_mem_size + (PAGE_SIZE - 1)) &
696 PAGE_MASK;
697
698 tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
699 &tgt->confq_dma, GFP_KERNEL);
700 if (!tgt->confq) {
701 printk(KERN_ALERT PFX "unable to allocate CONFQ %d\n",
702 tgt->confq_mem_size);
703 goto mem_alloc_failure;
704 }
705 memset(tgt->confq, 0, tgt->confq_mem_size);
706
707 tgt->confq_pbl_size =
708 (tgt->confq_mem_size / PAGE_SIZE) * sizeof(void *);
709 tgt->confq_pbl_size =
710 (tgt->confq_pbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
711
712 tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
713 tgt->confq_pbl_size,
714 &tgt->confq_pbl_dma, GFP_KERNEL);
715 if (!tgt->confq_pbl) {
716 printk(KERN_ALERT PFX "unable to allocate CONFQ PBL %d\n",
717 tgt->confq_pbl_size);
718 goto mem_alloc_failure;
719 }
720
721 memset(tgt->confq_pbl, 0, tgt->confq_pbl_size);
722 num_pages = tgt->confq_mem_size / PAGE_SIZE;
723 page = tgt->confq_dma;
724 pbl = (u32 *)tgt->confq_pbl;
725
726 while (num_pages--) {
727 *pbl = (u32)page;
728 pbl++;
729 *pbl = (u32)((u64)page >> 32);
730 pbl++;
731 page += PAGE_SIZE;
732 }
733
734 /* Allocate and map ConnDB */
735 tgt->conn_db_mem_size = sizeof(struct fcoe_conn_db);
736
737 tgt->conn_db = dma_alloc_coherent(&hba->pcidev->dev,
738 tgt->conn_db_mem_size,
739 &tgt->conn_db_dma, GFP_KERNEL);
740 if (!tgt->conn_db) {
741 printk(KERN_ALERT PFX "unable to allocate conn_db %d\n",
742 tgt->conn_db_mem_size);
743 goto mem_alloc_failure;
744 }
745 memset(tgt->conn_db, 0, tgt->conn_db_mem_size);
746
747
748 /* Allocate and map LCQ */
749 tgt->lcq_mem_size = (tgt->max_sqes + 8) * BNX2FC_SQ_WQE_SIZE;
750 tgt->lcq_mem_size = (tgt->lcq_mem_size + (PAGE_SIZE - 1)) &
751 PAGE_MASK;
752
753 tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
754 &tgt->lcq_dma, GFP_KERNEL);
755
756 if (!tgt->lcq) {
757 printk(KERN_ALERT PFX "unable to allocate lcq %d\n",
758 tgt->lcq_mem_size);
759 goto mem_alloc_failure;
760 }
761 memset(tgt->lcq, 0, tgt->lcq_mem_size);
762
763 /* Arm CQ */
764 tgt->conn_db->cq_arm.lo = -1;
765 tgt->conn_db->rq_prod = 0x8000;
766
767 return 0;
768
769mem_alloc_failure:
770 bnx2fc_free_session_resc(hba, tgt);
771 bnx2fc_free_conn_id(hba, tgt->fcoe_conn_id);
772 return -ENOMEM;
773}
774
775/**
776 * bnx2i_free_session_resc - free qp resources for the session
777 *
778 * @hba: adapter structure pointer
779 * @tgt: bnx2fc_rport structure pointer
780 *
781 * Free QP resources - SQ/RQ/CQ/XFERQ memory and PBL
782 */
783static void bnx2fc_free_session_resc(struct bnx2fc_hba *hba,
784 struct bnx2fc_rport *tgt)
785{
786 BNX2FC_TGT_DBG(tgt, "Freeing up session resources\n");
787
788 if (tgt->ctx_base) {
789 iounmap(tgt->ctx_base);
790 tgt->ctx_base = NULL;
791 }
792 /* Free LCQ */
793 if (tgt->lcq) {
794 dma_free_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
795 tgt->lcq, tgt->lcq_dma);
796 tgt->lcq = NULL;
797 }
798 /* Free connDB */
799 if (tgt->conn_db) {
800 dma_free_coherent(&hba->pcidev->dev, tgt->conn_db_mem_size,
801 tgt->conn_db, tgt->conn_db_dma);
802 tgt->conn_db = NULL;
803 }
804 /* Free confq and confq pbl */
805 if (tgt->confq_pbl) {
806 dma_free_coherent(&hba->pcidev->dev, tgt->confq_pbl_size,
807 tgt->confq_pbl, tgt->confq_pbl_dma);
808 tgt->confq_pbl = NULL;
809 }
810 if (tgt->confq) {
811 dma_free_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
812 tgt->confq, tgt->confq_dma);
813 tgt->confq = NULL;
814 }
815 /* Free XFERQ */
816 if (tgt->xferq) {
817 dma_free_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
818 tgt->xferq, tgt->xferq_dma);
819 tgt->xferq = NULL;
820 }
821 /* Free RQ PBL and RQ */
822 if (tgt->rq_pbl) {
823 dma_free_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
824 tgt->rq_pbl, tgt->rq_pbl_dma);
825 tgt->rq_pbl = NULL;
826 }
827 if (tgt->rq) {
828 dma_free_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
829 tgt->rq, tgt->rq_dma);
830 tgt->rq = NULL;
831 }
832 /* Free CQ */
833 if (tgt->cq) {
834 dma_free_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
835 tgt->cq, tgt->cq_dma);
836 tgt->cq = NULL;
837 }
838 /* Free SQ */
839 if (tgt->sq) {
840 dma_free_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
841 tgt->sq, tgt->sq_dma);
842 tgt->sq = NULL;
843 }
844}
diff --git a/drivers/scsi/bnx2i/bnx2i.h b/drivers/scsi/bnx2i/bnx2i.h
index e1ca5fe7e6bb..cfd59023227b 100644
--- a/drivers/scsi/bnx2i/bnx2i.h
+++ b/drivers/scsi/bnx2i/bnx2i.h
@@ -360,7 +360,7 @@ struct bnx2i_hba {
360 #define ADAPTER_STATE_LINK_DOWN 2 360 #define ADAPTER_STATE_LINK_DOWN 2
361 #define ADAPTER_STATE_INIT_FAILED 31 361 #define ADAPTER_STATE_INIT_FAILED 31
362 unsigned int mtu_supported; 362 unsigned int mtu_supported;
363 #define BNX2I_MAX_MTU_SUPPORTED 1500 363 #define BNX2I_MAX_MTU_SUPPORTED 9000
364 364
365 struct Scsi_Host *shost; 365 struct Scsi_Host *shost;
366 366
@@ -751,6 +751,8 @@ extern int bnx2i_send_iscsi_login(struct bnx2i_conn *conn,
751 struct iscsi_task *mtask); 751 struct iscsi_task *mtask);
752extern int bnx2i_send_iscsi_tmf(struct bnx2i_conn *conn, 752extern int bnx2i_send_iscsi_tmf(struct bnx2i_conn *conn,
753 struct iscsi_task *mtask); 753 struct iscsi_task *mtask);
754extern int bnx2i_send_iscsi_text(struct bnx2i_conn *conn,
755 struct iscsi_task *mtask);
754extern int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *conn, 756extern int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *conn,
755 struct bnx2i_cmd *cmnd); 757 struct bnx2i_cmd *cmnd);
756extern int bnx2i_send_iscsi_nopout(struct bnx2i_conn *conn, 758extern int bnx2i_send_iscsi_nopout(struct bnx2i_conn *conn,
diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index 96505e3ab986..1da34c019b8a 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -445,6 +445,56 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
445} 445}
446 446
447/** 447/**
448 * bnx2i_send_iscsi_text - post iSCSI text WQE to hardware
449 * @conn: iscsi connection
450 * @mtask: driver command structure which is requesting
451 * a WQE to sent to chip for further processing
452 *
453 * prepare and post an iSCSI Text request WQE to CNIC firmware
454 */
455int bnx2i_send_iscsi_text(struct bnx2i_conn *bnx2i_conn,
456 struct iscsi_task *mtask)
457{
458 struct bnx2i_cmd *bnx2i_cmd;
459 struct bnx2i_text_request *text_wqe;
460 struct iscsi_text *text_hdr;
461 u32 dword;
462
463 bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
464 text_hdr = (struct iscsi_text *)mtask->hdr;
465 text_wqe = (struct bnx2i_text_request *) bnx2i_conn->ep->qp.sq_prod_qe;
466
467 memset(text_wqe, 0, sizeof(struct bnx2i_text_request));
468
469 text_wqe->op_code = text_hdr->opcode;
470 text_wqe->op_attr = text_hdr->flags;
471 text_wqe->data_length = ntoh24(text_hdr->dlength);
472 text_wqe->itt = mtask->itt |
473 (ISCSI_TASK_TYPE_MPATH << ISCSI_TEXT_REQUEST_TYPE_SHIFT);
474 text_wqe->ttt = be32_to_cpu(text_hdr->ttt);
475
476 text_wqe->cmd_sn = be32_to_cpu(text_hdr->cmdsn);
477
478 text_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
479 text_wqe->resp_bd_list_addr_hi =
480 (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
481
482 dword = ((1 << ISCSI_TEXT_REQUEST_NUM_RESP_BDS_SHIFT) |
483 (bnx2i_conn->gen_pdu.resp_buf_size <<
484 ISCSI_TEXT_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
485 text_wqe->resp_buffer = dword;
486 text_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
487 text_wqe->bd_list_addr_hi =
488 (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
489 text_wqe->num_bds = 1;
490 text_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
491
492 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
493 return 0;
494}
495
496
497/**
448 * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware 498 * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
449 * @conn: iscsi connection 499 * @conn: iscsi connection
450 * @cmd: driver command structure which is requesting 500 * @cmd: driver command structure which is requesting
@@ -490,15 +540,18 @@ int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
490 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data; 540 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
491 nopout_hdr = (struct iscsi_nopout *)task->hdr; 541 nopout_hdr = (struct iscsi_nopout *)task->hdr;
492 nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe; 542 nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
543
544 memset(nopout_wqe, 0x00, sizeof(struct bnx2i_nop_out_request));
545
493 nopout_wqe->op_code = nopout_hdr->opcode; 546 nopout_wqe->op_code = nopout_hdr->opcode;
494 nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL; 547 nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
495 memcpy(nopout_wqe->lun, nopout_hdr->lun, 8); 548 memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
496 549
497 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) { 550 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
498 u32 tmp = nopout_hdr->lun[0]; 551 u32 tmp = nopout_wqe->lun[0];
499 /* 57710 requires LUN field to be swapped */ 552 /* 57710 requires LUN field to be swapped */
500 nopout_hdr->lun[0] = nopout_hdr->lun[1]; 553 nopout_wqe->lun[0] = nopout_wqe->lun[1];
501 nopout_hdr->lun[1] = tmp; 554 nopout_wqe->lun[1] = tmp;
502 } 555 }
503 556
504 nopout_wqe->itt = ((u16)task->itt | 557 nopout_wqe->itt = ((u16)task->itt |
@@ -1425,6 +1478,68 @@ done:
1425 return 0; 1478 return 0;
1426} 1479}
1427 1480
1481
1482/**
1483 * bnx2i_process_text_resp - this function handles iscsi text response
1484 * @session: iscsi session pointer
1485 * @bnx2i_conn: iscsi connection pointer
1486 * @cqe: pointer to newly DMA'ed CQE entry for processing
1487 *
1488 * process iSCSI Text Response CQE& complete it to open-iscsi user daemon
1489 */
1490static int bnx2i_process_text_resp(struct iscsi_session *session,
1491 struct bnx2i_conn *bnx2i_conn,
1492 struct cqe *cqe)
1493{
1494 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1495 struct iscsi_task *task;
1496 struct bnx2i_text_response *text;
1497 struct iscsi_text_rsp *resp_hdr;
1498 int pld_len;
1499 int pad_len;
1500
1501 text = (struct bnx2i_text_response *) cqe;
1502 spin_lock(&session->lock);
1503 task = iscsi_itt_to_task(conn, text->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1504 if (!task)
1505 goto done;
1506
1507 resp_hdr = (struct iscsi_text_rsp *)&bnx2i_conn->gen_pdu.resp_hdr;
1508 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1509 resp_hdr->opcode = text->op_code;
1510 resp_hdr->flags = text->response_flags;
1511 resp_hdr->hlength = 0;
1512
1513 hton24(resp_hdr->dlength, text->data_length);
1514 resp_hdr->itt = task->hdr->itt;
1515 resp_hdr->ttt = cpu_to_be32(text->ttt);
1516 resp_hdr->statsn = task->hdr->exp_statsn;
1517 resp_hdr->exp_cmdsn = cpu_to_be32(text->exp_cmd_sn);
1518 resp_hdr->max_cmdsn = cpu_to_be32(text->max_cmd_sn);
1519 pld_len = text->data_length;
1520 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf +
1521 pld_len;
1522 pad_len = 0;
1523 if (pld_len & 0x3)
1524 pad_len = 4 - (pld_len % 4);
1525
1526 if (pad_len) {
1527 int i = 0;
1528 for (i = 0; i < pad_len; i++) {
1529 bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1530 bnx2i_conn->gen_pdu.resp_wr_ptr++;
1531 }
1532 }
1533 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1534 bnx2i_conn->gen_pdu.resp_buf,
1535 bnx2i_conn->gen_pdu.resp_wr_ptr -
1536 bnx2i_conn->gen_pdu.resp_buf);
1537done:
1538 spin_unlock(&session->lock);
1539 return 0;
1540}
1541
1542
1428/** 1543/**
1429 * bnx2i_process_tmf_resp - this function handles iscsi TMF response 1544 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1430 * @session: iscsi session pointer 1545 * @session: iscsi session pointer
@@ -1766,6 +1881,10 @@ static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
1766 bnx2i_process_tmf_resp(session, bnx2i_conn, 1881 bnx2i_process_tmf_resp(session, bnx2i_conn,
1767 qp->cq_cons_qe); 1882 qp->cq_cons_qe);
1768 break; 1883 break;
1884 case ISCSI_OP_TEXT_RSP:
1885 bnx2i_process_text_resp(session, bnx2i_conn,
1886 qp->cq_cons_qe);
1887 break;
1769 case ISCSI_OP_LOGOUT_RSP: 1888 case ISCSI_OP_LOGOUT_RSP:
1770 bnx2i_process_logout_resp(session, bnx2i_conn, 1889 bnx2i_process_logout_resp(session, bnx2i_conn,
1771 qp->cq_cons_qe); 1890 qp->cq_cons_qe);
diff --git a/drivers/scsi/bnx2i/bnx2i_init.c b/drivers/scsi/bnx2i/bnx2i_init.c
index 72a7b2d4a439..1d24a2819736 100644
--- a/drivers/scsi/bnx2i/bnx2i_init.c
+++ b/drivers/scsi/bnx2i/bnx2i_init.c
@@ -18,8 +18,8 @@ static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list);
18static u32 adapter_count; 18static u32 adapter_count;
19 19
20#define DRV_MODULE_NAME "bnx2i" 20#define DRV_MODULE_NAME "bnx2i"
21#define DRV_MODULE_VERSION "2.6.2.2" 21#define DRV_MODULE_VERSION "2.6.2.3"
22#define DRV_MODULE_RELDATE "Nov 23, 2010" 22#define DRV_MODULE_RELDATE "Dec 31, 2010"
23 23
24static char version[] __devinitdata = 24static char version[] __devinitdata =
25 "Broadcom NetXtreme II iSCSI Driver " DRV_MODULE_NAME \ 25 "Broadcom NetXtreme II iSCSI Driver " DRV_MODULE_NAME \
@@ -29,7 +29,7 @@ static char version[] __devinitdata =
29MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and " 29MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and "
30 "Eddie Wai <eddie.wai@broadcom.com>"); 30 "Eddie Wai <eddie.wai@broadcom.com>");
31 31
32MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/57710/57711" 32MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/57710/57711/57712"
33 " iSCSI Driver"); 33 " iSCSI Driver");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35MODULE_VERSION(DRV_MODULE_VERSION); 35MODULE_VERSION(DRV_MODULE_VERSION);
@@ -88,9 +88,11 @@ void bnx2i_identify_device(struct bnx2i_hba *hba)
88 (hba->pci_did == PCI_DEVICE_ID_NX2_5709S)) { 88 (hba->pci_did == PCI_DEVICE_ID_NX2_5709S)) {
89 set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type); 89 set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type);
90 hba->mail_queue_access = BNX2I_MQ_BIN_MODE; 90 hba->mail_queue_access = BNX2I_MQ_BIN_MODE;
91 } else if (hba->pci_did == PCI_DEVICE_ID_NX2_57710 || 91 } else if (hba->pci_did == PCI_DEVICE_ID_NX2_57710 ||
92 hba->pci_did == PCI_DEVICE_ID_NX2_57711 || 92 hba->pci_did == PCI_DEVICE_ID_NX2_57711 ||
93 hba->pci_did == PCI_DEVICE_ID_NX2_57711E) 93 hba->pci_did == PCI_DEVICE_ID_NX2_57711E ||
94 hba->pci_did == PCI_DEVICE_ID_NX2_57712 ||
95 hba->pci_did == PCI_DEVICE_ID_NX2_57712E)
94 set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type); 96 set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type);
95 else 97 else
96 printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n", 98 printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n",
@@ -161,6 +163,21 @@ void bnx2i_start(void *handle)
161 struct bnx2i_hba *hba = handle; 163 struct bnx2i_hba *hba = handle;
162 int i = HZ; 164 int i = HZ;
163 165
166 if (!hba->cnic->max_iscsi_conn) {
167 printk(KERN_ALERT "bnx2i: dev %s does not support "
168 "iSCSI\n", hba->netdev->name);
169
170 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
171 mutex_lock(&bnx2i_dev_lock);
172 list_del_init(&hba->link);
173 adapter_count--;
174 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
175 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
176 mutex_unlock(&bnx2i_dev_lock);
177 bnx2i_free_hba(hba);
178 }
179 return;
180 }
164 bnx2i_send_fw_iscsi_init_msg(hba); 181 bnx2i_send_fw_iscsi_init_msg(hba);
165 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--) 182 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
166 msleep(BNX2I_INIT_POLL_TIME); 183 msleep(BNX2I_INIT_POLL_TIME);
diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index f0dce26593eb..1809f9ccc4ce 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -1092,6 +1092,9 @@ static int bnx2i_iscsi_send_generic_request(struct iscsi_task *task)
1092 case ISCSI_OP_SCSI_TMFUNC: 1092 case ISCSI_OP_SCSI_TMFUNC:
1093 rc = bnx2i_send_iscsi_tmf(bnx2i_conn, task); 1093 rc = bnx2i_send_iscsi_tmf(bnx2i_conn, task);
1094 break; 1094 break;
1095 case ISCSI_OP_TEXT:
1096 rc = bnx2i_send_iscsi_text(bnx2i_conn, task);
1097 break;
1095 default: 1098 default:
1096 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data, 1099 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1097 "send_gen: unsupported op 0x%x\n", 1100 "send_gen: unsupported op 0x%x\n",
@@ -1455,42 +1458,40 @@ static void bnx2i_conn_destroy(struct iscsi_cls_conn *cls_conn)
1455 1458
1456 1459
1457/** 1460/**
1458 * bnx2i_conn_get_param - return iscsi connection parameter to caller 1461 * bnx2i_ep_get_param - return iscsi ep parameter to caller
1459 * @cls_conn: pointer to iscsi cls conn 1462 * @ep: pointer to iscsi endpoint
1460 * @param: parameter type identifier 1463 * @param: parameter type identifier
1461 * @buf: buffer pointer 1464 * @buf: buffer pointer
1462 * 1465 *
1463 * returns iSCSI connection parameters 1466 * returns iSCSI ep parameters
1464 */ 1467 */
1465static int bnx2i_conn_get_param(struct iscsi_cls_conn *cls_conn, 1468static int bnx2i_ep_get_param(struct iscsi_endpoint *ep,
1466 enum iscsi_param param, char *buf) 1469 enum iscsi_param param, char *buf)
1467{ 1470{
1468 struct iscsi_conn *conn = cls_conn->dd_data; 1471 struct bnx2i_endpoint *bnx2i_ep = ep->dd_data;
1469 struct bnx2i_conn *bnx2i_conn = conn->dd_data; 1472 struct bnx2i_hba *hba = bnx2i_ep->hba;
1470 int len = 0; 1473 int len = -ENOTCONN;
1471 1474
1472 if (!(bnx2i_conn && bnx2i_conn->ep && bnx2i_conn->ep->hba)) 1475 if (!hba)
1473 goto out; 1476 return -ENOTCONN;
1474 1477
1475 switch (param) { 1478 switch (param) {
1476 case ISCSI_PARAM_CONN_PORT: 1479 case ISCSI_PARAM_CONN_PORT:
1477 mutex_lock(&bnx2i_conn->ep->hba->net_dev_lock); 1480 mutex_lock(&hba->net_dev_lock);
1478 if (bnx2i_conn->ep->cm_sk) 1481 if (bnx2i_ep->cm_sk)
1479 len = sprintf(buf, "%hu\n", 1482 len = sprintf(buf, "%hu\n", bnx2i_ep->cm_sk->dst_port);
1480 bnx2i_conn->ep->cm_sk->dst_port); 1483 mutex_unlock(&hba->net_dev_lock);
1481 mutex_unlock(&bnx2i_conn->ep->hba->net_dev_lock);
1482 break; 1484 break;
1483 case ISCSI_PARAM_CONN_ADDRESS: 1485 case ISCSI_PARAM_CONN_ADDRESS:
1484 mutex_lock(&bnx2i_conn->ep->hba->net_dev_lock); 1486 mutex_lock(&hba->net_dev_lock);
1485 if (bnx2i_conn->ep->cm_sk) 1487 if (bnx2i_ep->cm_sk)
1486 len = sprintf(buf, "%pI4\n", 1488 len = sprintf(buf, "%pI4\n", &bnx2i_ep->cm_sk->dst_ip);
1487 &bnx2i_conn->ep->cm_sk->dst_ip); 1489 mutex_unlock(&hba->net_dev_lock);
1488 mutex_unlock(&bnx2i_conn->ep->hba->net_dev_lock);
1489 break; 1490 break;
1490 default: 1491 default:
1491 return iscsi_conn_get_param(cls_conn, param, buf); 1492 return -ENOSYS;
1492 } 1493 }
1493out: 1494
1494 return len; 1495 return len;
1495} 1496}
1496 1497
@@ -1935,13 +1936,13 @@ static int bnx2i_ep_tcp_conn_active(struct bnx2i_endpoint *bnx2i_ep)
1935 cnic_dev_10g = 1; 1936 cnic_dev_10g = 1;
1936 1937
1937 switch (bnx2i_ep->state) { 1938 switch (bnx2i_ep->state) {
1938 case EP_STATE_CONNECT_FAILED:
1939 case EP_STATE_CLEANUP_FAILED: 1939 case EP_STATE_CLEANUP_FAILED:
1940 case EP_STATE_OFLD_FAILED: 1940 case EP_STATE_OFLD_FAILED:
1941 case EP_STATE_DISCONN_TIMEDOUT: 1941 case EP_STATE_DISCONN_TIMEDOUT:
1942 ret = 0; 1942 ret = 0;
1943 break; 1943 break;
1944 case EP_STATE_CONNECT_START: 1944 case EP_STATE_CONNECT_START:
1945 case EP_STATE_CONNECT_FAILED:
1945 case EP_STATE_CONNECT_COMPL: 1946 case EP_STATE_CONNECT_COMPL:
1946 case EP_STATE_ULP_UPDATE_START: 1947 case EP_STATE_ULP_UPDATE_START:
1947 case EP_STATE_ULP_UPDATE_COMPL: 1948 case EP_STATE_ULP_UPDATE_COMPL:
@@ -2167,7 +2168,8 @@ struct iscsi_transport bnx2i_iscsi_transport = {
2167 .name = "bnx2i", 2168 .name = "bnx2i",
2168 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | 2169 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST |
2169 CAP_MULTI_R2T | CAP_DATADGST | 2170 CAP_MULTI_R2T | CAP_DATADGST |
2170 CAP_DATA_PATH_OFFLOAD, 2171 CAP_DATA_PATH_OFFLOAD |
2172 CAP_TEXT_NEGO,
2171 .param_mask = ISCSI_MAX_RECV_DLENGTH | 2173 .param_mask = ISCSI_MAX_RECV_DLENGTH |
2172 ISCSI_MAX_XMIT_DLENGTH | 2174 ISCSI_MAX_XMIT_DLENGTH |
2173 ISCSI_HDRDGST_EN | 2175 ISCSI_HDRDGST_EN |
@@ -2200,7 +2202,7 @@ struct iscsi_transport bnx2i_iscsi_transport = {
2200 .bind_conn = bnx2i_conn_bind, 2202 .bind_conn = bnx2i_conn_bind,
2201 .destroy_conn = bnx2i_conn_destroy, 2203 .destroy_conn = bnx2i_conn_destroy,
2202 .set_param = iscsi_set_param, 2204 .set_param = iscsi_set_param,
2203 .get_conn_param = bnx2i_conn_get_param, 2205 .get_conn_param = iscsi_conn_get_param,
2204 .get_session_param = iscsi_session_get_param, 2206 .get_session_param = iscsi_session_get_param,
2205 .get_host_param = bnx2i_host_get_param, 2207 .get_host_param = bnx2i_host_get_param,
2206 .start_conn = bnx2i_conn_start, 2208 .start_conn = bnx2i_conn_start,
@@ -2209,6 +2211,7 @@ struct iscsi_transport bnx2i_iscsi_transport = {
2209 .xmit_task = bnx2i_task_xmit, 2211 .xmit_task = bnx2i_task_xmit,
2210 .get_stats = bnx2i_conn_get_stats, 2212 .get_stats = bnx2i_conn_get_stats,
2211 /* TCP connect - disconnect - option-2 interface calls */ 2213 /* TCP connect - disconnect - option-2 interface calls */
2214 .get_ep_param = bnx2i_ep_get_param,
2212 .ep_connect = bnx2i_ep_connect, 2215 .ep_connect = bnx2i_ep_connect,
2213 .ep_poll = bnx2i_ep_poll, 2216 .ep_poll = bnx2i_ep_poll,
2214 .ep_disconnect = bnx2i_ep_disconnect, 2217 .ep_disconnect = bnx2i_ep_disconnect,
diff --git a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
index a129a170b47b..fc2cdb62f53b 100644
--- a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
+++ b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
@@ -105,7 +105,7 @@ static struct iscsi_transport cxgb3i_iscsi_transport = {
105 /* owner and name should be set already */ 105 /* owner and name should be set already */
106 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST 106 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST
107 | CAP_DATADGST | CAP_DIGEST_OFFLOAD | 107 | CAP_DATADGST | CAP_DIGEST_OFFLOAD |
108 CAP_PADDING_OFFLOAD, 108 CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
109 .param_mask = ISCSI_MAX_RECV_DLENGTH | ISCSI_MAX_XMIT_DLENGTH | 109 .param_mask = ISCSI_MAX_RECV_DLENGTH | ISCSI_MAX_XMIT_DLENGTH |
110 ISCSI_HDRDGST_EN | ISCSI_DATADGST_EN | 110 ISCSI_HDRDGST_EN | ISCSI_DATADGST_EN |
111 ISCSI_INITIAL_R2T_EN | ISCSI_MAX_R2T | 111 ISCSI_INITIAL_R2T_EN | ISCSI_MAX_R2T |
@@ -137,7 +137,7 @@ static struct iscsi_transport cxgb3i_iscsi_transport = {
137 .destroy_conn = iscsi_tcp_conn_teardown, 137 .destroy_conn = iscsi_tcp_conn_teardown,
138 .start_conn = iscsi_conn_start, 138 .start_conn = iscsi_conn_start,
139 .stop_conn = iscsi_conn_stop, 139 .stop_conn = iscsi_conn_stop,
140 .get_conn_param = cxgbi_get_conn_param, 140 .get_conn_param = iscsi_conn_get_param,
141 .set_param = cxgbi_set_conn_param, 141 .set_param = cxgbi_set_conn_param,
142 .get_stats = cxgbi_get_conn_stats, 142 .get_stats = cxgbi_get_conn_stats,
143 /* pdu xmit req from user space */ 143 /* pdu xmit req from user space */
@@ -152,6 +152,7 @@ static struct iscsi_transport cxgb3i_iscsi_transport = {
152 .xmit_pdu = cxgbi_conn_xmit_pdu, 152 .xmit_pdu = cxgbi_conn_xmit_pdu,
153 .parse_pdu_itt = cxgbi_parse_pdu_itt, 153 .parse_pdu_itt = cxgbi_parse_pdu_itt,
154 /* TCP connect/disconnect */ 154 /* TCP connect/disconnect */
155 .get_ep_param = cxgbi_get_ep_param,
155 .ep_connect = cxgbi_ep_connect, 156 .ep_connect = cxgbi_ep_connect,
156 .ep_poll = cxgbi_ep_poll, 157 .ep_poll = cxgbi_ep_poll,
157 .ep_disconnect = cxgbi_ep_disconnect, 158 .ep_disconnect = cxgbi_ep_disconnect,
@@ -1108,10 +1109,11 @@ static int ddp_set_map(struct cxgbi_sock *csk, struct cxgbi_pagepod_hdr *hdr,
1108 csk, idx, npods, gl); 1109 csk, idx, npods, gl);
1109 1110
1110 for (i = 0; i < npods; i++, idx++, pm_addr += PPOD_SIZE) { 1111 for (i = 0; i < npods; i++, idx++, pm_addr += PPOD_SIZE) {
1111 struct sk_buff *skb = ddp->gl_skb[idx]; 1112 struct sk_buff *skb = alloc_wr(sizeof(struct ulp_mem_io) +
1113 PPOD_SIZE, 0, GFP_ATOMIC);
1112 1114
1113 /* hold on to the skb until we clear the ddp mapping */ 1115 if (!skb)
1114 skb_get(skb); 1116 return -ENOMEM;
1115 1117
1116 ulp_mem_io_set_hdr(skb, pm_addr); 1118 ulp_mem_io_set_hdr(skb, pm_addr);
1117 cxgbi_ddp_ppod_set((struct cxgbi_pagepod *)(skb->head + 1119 cxgbi_ddp_ppod_set((struct cxgbi_pagepod *)(skb->head +
@@ -1136,56 +1138,20 @@ static void ddp_clear_map(struct cxgbi_hba *chba, unsigned int tag,
1136 cdev, idx, npods, tag); 1138 cdev, idx, npods, tag);
1137 1139
1138 for (i = 0; i < npods; i++, idx++, pm_addr += PPOD_SIZE) { 1140 for (i = 0; i < npods; i++, idx++, pm_addr += PPOD_SIZE) {
1139 struct sk_buff *skb = ddp->gl_skb[idx]; 1141 struct sk_buff *skb = alloc_wr(sizeof(struct ulp_mem_io) +
1142 PPOD_SIZE, 0, GFP_ATOMIC);
1140 1143
1141 if (!skb) { 1144 if (!skb) {
1142 pr_err("tag 0x%x, 0x%x, %d/%u, skb NULL.\n", 1145 pr_err("tag 0x%x, 0x%x, %d/%u, skb OOM.\n",
1143 tag, idx, i, npods); 1146 tag, idx, i, npods);
1144 continue; 1147 continue;
1145 } 1148 }
1146 ddp->gl_skb[idx] = NULL;
1147 memset(skb->head + sizeof(struct ulp_mem_io), 0, PPOD_SIZE);
1148 ulp_mem_io_set_hdr(skb, pm_addr); 1149 ulp_mem_io_set_hdr(skb, pm_addr);
1149 skb->priority = CPL_PRIORITY_CONTROL; 1150 skb->priority = CPL_PRIORITY_CONTROL;
1150 cxgb3_ofld_send(cdev->lldev, skb); 1151 cxgb3_ofld_send(cdev->lldev, skb);
1151 } 1152 }
1152} 1153}
1153 1154
1154static void ddp_free_gl_skb(struct cxgbi_ddp_info *ddp, int idx, int cnt)
1155{
1156 int i;
1157
1158 log_debug(1 << CXGBI_DBG_DDP,
1159 "ddp 0x%p, idx %d, cnt %d.\n", ddp, idx, cnt);
1160
1161 for (i = 0; i < cnt; i++, idx++)
1162 if (ddp->gl_skb[idx]) {
1163 kfree_skb(ddp->gl_skb[idx]);
1164 ddp->gl_skb[idx] = NULL;
1165 }
1166}
1167
1168static int ddp_alloc_gl_skb(struct cxgbi_ddp_info *ddp, int idx,
1169 int cnt, gfp_t gfp)
1170{
1171 int i;
1172
1173 log_debug(1 << CXGBI_DBG_DDP,
1174 "ddp 0x%p, idx %d, cnt %d.\n", ddp, idx, cnt);
1175
1176 for (i = 0; i < cnt; i++) {
1177 struct sk_buff *skb = alloc_wr(sizeof(struct ulp_mem_io) +
1178 PPOD_SIZE, 0, gfp);
1179 if (skb)
1180 ddp->gl_skb[idx + i] = skb;
1181 else {
1182 ddp_free_gl_skb(ddp, idx, i);
1183 return -ENOMEM;
1184 }
1185 }
1186 return 0;
1187}
1188
1189static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, 1155static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk,
1190 unsigned int tid, int pg_idx, bool reply) 1156 unsigned int tid, int pg_idx, bool reply)
1191{ 1157{
@@ -1316,8 +1282,6 @@ static int cxgb3i_ddp_init(struct cxgbi_device *cdev)
1316 } 1282 }
1317 tdev->ulp_iscsi = ddp; 1283 tdev->ulp_iscsi = ddp;
1318 1284
1319 cdev->csk_ddp_free_gl_skb = ddp_free_gl_skb;
1320 cdev->csk_ddp_alloc_gl_skb = ddp_alloc_gl_skb;
1321 cdev->csk_ddp_setup_digest = ddp_setup_conn_digest; 1285 cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
1322 cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx; 1286 cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
1323 cdev->csk_ddp_set = ddp_set_map; 1287 cdev->csk_ddp_set = ddp_set_map;
diff --git a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.h b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.h
index 5f5e3394b594..20593fd69d8f 100644
--- a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.h
+++ b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.h
@@ -24,10 +24,21 @@
24 24
25extern cxgb3_cpl_handler_func cxgb3i_cpl_handlers[NUM_CPL_CMDS]; 25extern cxgb3_cpl_handler_func cxgb3i_cpl_handlers[NUM_CPL_CMDS];
26 26
27#define cxgb3i_get_private_ipv4addr(ndev) \ 27static inline unsigned int cxgb3i_get_private_ipv4addr(struct net_device *ndev)
28 (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr) 28{
29#define cxgb3i_set_private_ipv4addr(ndev, addr) \ 29 return ((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr;
30 (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr) = addr 30}
31
32static inline void cxgb3i_set_private_ipv4addr(struct net_device *ndev,
33 unsigned int addr)
34{
35 struct port_info *pi = (struct port_info *)netdev_priv(ndev);
36
37 pi->iscsic.flags = addr ? 1 : 0;
38 pi->iscsi_ipv4addr = addr;
39 if (addr)
40 memcpy(pi->iscsic.mac_addr, ndev->dev_addr, ETH_ALEN);
41}
31 42
32struct cpl_iscsi_hdr_norss { 43struct cpl_iscsi_hdr_norss {
33 union opcode_tid ot; 44 union opcode_tid ot;
diff --git a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
index 8c04fada710b..f3a4cd7cf782 100644
--- a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
+++ b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
@@ -106,7 +106,7 @@ static struct iscsi_transport cxgb4i_iscsi_transport = {
106 .name = DRV_MODULE_NAME, 106 .name = DRV_MODULE_NAME,
107 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST | 107 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
108 CAP_DATADGST | CAP_DIGEST_OFFLOAD | 108 CAP_DATADGST | CAP_DIGEST_OFFLOAD |
109 CAP_PADDING_OFFLOAD, 109 CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
110 .param_mask = ISCSI_MAX_RECV_DLENGTH | ISCSI_MAX_XMIT_DLENGTH | 110 .param_mask = ISCSI_MAX_RECV_DLENGTH | ISCSI_MAX_XMIT_DLENGTH |
111 ISCSI_HDRDGST_EN | ISCSI_DATADGST_EN | 111 ISCSI_HDRDGST_EN | ISCSI_DATADGST_EN |
112 ISCSI_INITIAL_R2T_EN | ISCSI_MAX_R2T | 112 ISCSI_INITIAL_R2T_EN | ISCSI_MAX_R2T |
@@ -138,7 +138,7 @@ static struct iscsi_transport cxgb4i_iscsi_transport = {
138 .destroy_conn = iscsi_tcp_conn_teardown, 138 .destroy_conn = iscsi_tcp_conn_teardown,
139 .start_conn = iscsi_conn_start, 139 .start_conn = iscsi_conn_start,
140 .stop_conn = iscsi_conn_stop, 140 .stop_conn = iscsi_conn_stop,
141 .get_conn_param = cxgbi_get_conn_param, 141 .get_conn_param = iscsi_conn_get_param,
142 .set_param = cxgbi_set_conn_param, 142 .set_param = cxgbi_set_conn_param,
143 .get_stats = cxgbi_get_conn_stats, 143 .get_stats = cxgbi_get_conn_stats,
144 /* pdu xmit req from user space */ 144 /* pdu xmit req from user space */
@@ -153,6 +153,7 @@ static struct iscsi_transport cxgb4i_iscsi_transport = {
153 .xmit_pdu = cxgbi_conn_xmit_pdu, 153 .xmit_pdu = cxgbi_conn_xmit_pdu,
154 .parse_pdu_itt = cxgbi_parse_pdu_itt, 154 .parse_pdu_itt = cxgbi_parse_pdu_itt,
155 /* TCP connect/disconnect */ 155 /* TCP connect/disconnect */
156 .get_ep_param = cxgbi_get_ep_param,
156 .ep_connect = cxgbi_ep_connect, 157 .ep_connect = cxgbi_ep_connect,
157 .ep_poll = cxgbi_ep_poll, 158 .ep_poll = cxgbi_ep_poll,
158 .ep_disconnect = cxgbi_ep_disconnect, 159 .ep_disconnect = cxgbi_ep_disconnect,
@@ -1425,8 +1426,6 @@ static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
1425 cxgbi_ddp_page_size_factor(pgsz_factor); 1426 cxgbi_ddp_page_size_factor(pgsz_factor);
1426 cxgb4_iscsi_init(lldi->ports[0], tagmask, pgsz_factor); 1427 cxgb4_iscsi_init(lldi->ports[0], tagmask, pgsz_factor);
1427 1428
1428 cdev->csk_ddp_free_gl_skb = NULL;
1429 cdev->csk_ddp_alloc_gl_skb = NULL;
1430 cdev->csk_ddp_setup_digest = ddp_setup_conn_digest; 1429 cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
1431 cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx; 1430 cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
1432 cdev->csk_ddp_set = ddp_set_map; 1431 cdev->csk_ddp_set = ddp_set_map;
diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c
index a24dff9f9163..de764ea7419d 100644
--- a/drivers/scsi/cxgbi/libcxgbi.c
+++ b/drivers/scsi/cxgbi/libcxgbi.c
@@ -530,6 +530,7 @@ static struct cxgbi_sock *cxgbi_check_route(struct sockaddr *dst_addr)
530 csk->dst = dst; 530 csk->dst = dst;
531 csk->daddr.sin_addr.s_addr = daddr->sin_addr.s_addr; 531 csk->daddr.sin_addr.s_addr = daddr->sin_addr.s_addr;
532 csk->daddr.sin_port = daddr->sin_port; 532 csk->daddr.sin_port = daddr->sin_port;
533 csk->daddr.sin_family = daddr->sin_family;
533 csk->saddr.sin_addr.s_addr = rt->rt_src; 534 csk->saddr.sin_addr.s_addr = rt->rt_src;
534 535
535 return csk; 536 return csk;
@@ -1264,12 +1265,6 @@ static int ddp_tag_reserve(struct cxgbi_sock *csk, unsigned int tid,
1264 return idx; 1265 return idx;
1265 } 1266 }
1266 1267
1267 if (cdev->csk_ddp_alloc_gl_skb) {
1268 err = cdev->csk_ddp_alloc_gl_skb(ddp, idx, npods, gfp);
1269 if (err < 0)
1270 goto unmark_entries;
1271 }
1272
1273 tag = cxgbi_ddp_tag_base(tformat, sw_tag); 1268 tag = cxgbi_ddp_tag_base(tformat, sw_tag);
1274 tag |= idx << PPOD_IDX_SHIFT; 1269 tag |= idx << PPOD_IDX_SHIFT;
1275 1270
@@ -1280,11 +1275,8 @@ static int ddp_tag_reserve(struct cxgbi_sock *csk, unsigned int tid,
1280 hdr.page_offset = htonl(gl->offset); 1275 hdr.page_offset = htonl(gl->offset);
1281 1276
1282 err = cdev->csk_ddp_set(csk, &hdr, idx, npods, gl); 1277 err = cdev->csk_ddp_set(csk, &hdr, idx, npods, gl);
1283 if (err < 0) { 1278 if (err < 0)
1284 if (cdev->csk_ddp_free_gl_skb)
1285 cdev->csk_ddp_free_gl_skb(ddp, idx, npods);
1286 goto unmark_entries; 1279 goto unmark_entries;
1287 }
1288 1280
1289 ddp->idx_last = idx; 1281 ddp->idx_last = idx;
1290 log_debug(1 << CXGBI_DBG_DDP, 1282 log_debug(1 << CXGBI_DBG_DDP,
@@ -1350,8 +1342,6 @@ static void ddp_destroy(struct kref *kref)
1350 >> PPOD_PAGES_SHIFT; 1342 >> PPOD_PAGES_SHIFT;
1351 pr_info("cdev 0x%p, ddp %d + %d.\n", cdev, i, npods); 1343 pr_info("cdev 0x%p, ddp %d + %d.\n", cdev, i, npods);
1352 kfree(gl); 1344 kfree(gl);
1353 if (cdev->csk_ddp_free_gl_skb)
1354 cdev->csk_ddp_free_gl_skb(ddp, i, npods);
1355 i += npods; 1345 i += npods;
1356 } else 1346 } else
1357 i++; 1347 i++;
@@ -1394,8 +1384,6 @@ int cxgbi_ddp_init(struct cxgbi_device *cdev,
1394 return -ENOMEM; 1384 return -ENOMEM;
1395 } 1385 }
1396 ddp->gl_map = (struct cxgbi_gather_list **)(ddp + 1); 1386 ddp->gl_map = (struct cxgbi_gather_list **)(ddp + 1);
1397 ddp->gl_skb = (struct sk_buff **)(((char *)ddp->gl_map) +
1398 ppmax * sizeof(struct cxgbi_gather_list *));
1399 cdev->ddp = ddp; 1387 cdev->ddp = ddp;
1400 1388
1401 spin_lock_init(&ddp->map_lock); 1389 spin_lock_init(&ddp->map_lock);
@@ -1895,13 +1883,16 @@ EXPORT_SYMBOL_GPL(cxgbi_conn_alloc_pdu);
1895 1883
1896static inline void tx_skb_setmode(struct sk_buff *skb, int hcrc, int dcrc) 1884static inline void tx_skb_setmode(struct sk_buff *skb, int hcrc, int dcrc)
1897{ 1885{
1898 u8 submode = 0; 1886 if (hcrc || dcrc) {
1887 u8 submode = 0;
1899 1888
1900 if (hcrc) 1889 if (hcrc)
1901 submode |= 1; 1890 submode |= 1;
1902 if (dcrc) 1891 if (dcrc)
1903 submode |= 2; 1892 submode |= 2;
1904 cxgbi_skcb_ulp_mode(skb) = (ULP2_MODE_ISCSI << 4) | submode; 1893 cxgbi_skcb_ulp_mode(skb) = (ULP2_MODE_ISCSI << 4) | submode;
1894 } else
1895 cxgbi_skcb_ulp_mode(skb) = 0;
1905} 1896}
1906 1897
1907int cxgbi_conn_init_pdu(struct iscsi_task *task, unsigned int offset, 1898int cxgbi_conn_init_pdu(struct iscsi_task *task, unsigned int offset,
@@ -2197,32 +2188,34 @@ int cxgbi_set_conn_param(struct iscsi_cls_conn *cls_conn,
2197} 2188}
2198EXPORT_SYMBOL_GPL(cxgbi_set_conn_param); 2189EXPORT_SYMBOL_GPL(cxgbi_set_conn_param);
2199 2190
2200int cxgbi_get_conn_param(struct iscsi_cls_conn *cls_conn, 2191int cxgbi_get_ep_param(struct iscsi_endpoint *ep, enum iscsi_param param,
2201 enum iscsi_param param, char *buf) 2192 char *buf)
2202{ 2193{
2203 struct iscsi_conn *iconn = cls_conn->dd_data; 2194 struct cxgbi_endpoint *cep = ep->dd_data;
2195 struct cxgbi_sock *csk;
2204 int len; 2196 int len;
2205 2197
2206 log_debug(1 << CXGBI_DBG_ISCSI, 2198 log_debug(1 << CXGBI_DBG_ISCSI,
2207 "cls_conn 0x%p, param %d.\n", cls_conn, param); 2199 "cls_conn 0x%p, param %d.\n", ep, param);
2208 2200
2209 switch (param) { 2201 switch (param) {
2210 case ISCSI_PARAM_CONN_PORT: 2202 case ISCSI_PARAM_CONN_PORT:
2211 spin_lock_bh(&iconn->session->lock);
2212 len = sprintf(buf, "%hu\n", iconn->portal_port);
2213 spin_unlock_bh(&iconn->session->lock);
2214 break;
2215 case ISCSI_PARAM_CONN_ADDRESS: 2203 case ISCSI_PARAM_CONN_ADDRESS:
2216 spin_lock_bh(&iconn->session->lock); 2204 if (!cep)
2217 len = sprintf(buf, "%s\n", iconn->portal_address); 2205 return -ENOTCONN;
2218 spin_unlock_bh(&iconn->session->lock); 2206
2219 break; 2207 csk = cep->csk;
2208 if (!csk)
2209 return -ENOTCONN;
2210
2211 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2212 &csk->daddr, param, buf);
2220 default: 2213 default:
2221 return iscsi_conn_get_param(cls_conn, param, buf); 2214 return -ENOSYS;
2222 } 2215 }
2223 return len; 2216 return len;
2224} 2217}
2225EXPORT_SYMBOL_GPL(cxgbi_get_conn_param); 2218EXPORT_SYMBOL_GPL(cxgbi_get_ep_param);
2226 2219
2227struct iscsi_cls_conn * 2220struct iscsi_cls_conn *
2228cxgbi_create_conn(struct iscsi_cls_session *cls_session, u32 cid) 2221cxgbi_create_conn(struct iscsi_cls_session *cls_session, u32 cid)
@@ -2289,11 +2282,6 @@ int cxgbi_bind_conn(struct iscsi_cls_session *cls_session,
2289 cxgbi_conn_max_xmit_dlength(conn); 2282 cxgbi_conn_max_xmit_dlength(conn);
2290 cxgbi_conn_max_recv_dlength(conn); 2283 cxgbi_conn_max_recv_dlength(conn);
2291 2284
2292 spin_lock_bh(&conn->session->lock);
2293 sprintf(conn->portal_address, "%pI4", &csk->daddr.sin_addr.s_addr);
2294 conn->portal_port = ntohs(csk->daddr.sin_port);
2295 spin_unlock_bh(&conn->session->lock);
2296
2297 log_debug(1 << CXGBI_DBG_ISCSI, 2285 log_debug(1 << CXGBI_DBG_ISCSI,
2298 "cls 0x%p,0x%p, ep 0x%p, cconn 0x%p, csk 0x%p.\n", 2286 "cls 0x%p,0x%p, ep 0x%p, cconn 0x%p, csk 0x%p.\n",
2299 cls_session, cls_conn, ep, cconn, csk); 2287 cls_session, cls_conn, ep, cconn, csk);
diff --git a/drivers/scsi/cxgbi/libcxgbi.h b/drivers/scsi/cxgbi/libcxgbi.h
index c57d59db000c..0a20fd5f7102 100644
--- a/drivers/scsi/cxgbi/libcxgbi.h
+++ b/drivers/scsi/cxgbi/libcxgbi.h
@@ -131,7 +131,6 @@ struct cxgbi_ddp_info {
131 unsigned int rsvd_tag_mask; 131 unsigned int rsvd_tag_mask;
132 spinlock_t map_lock; 132 spinlock_t map_lock;
133 struct cxgbi_gather_list **gl_map; 133 struct cxgbi_gather_list **gl_map;
134 struct sk_buff **gl_skb;
135}; 134};
136 135
137#define DDP_PGIDX_MAX 4 136#define DDP_PGIDX_MAX 4
@@ -536,8 +535,6 @@ struct cxgbi_device {
536 struct cxgbi_ddp_info *ddp; 535 struct cxgbi_ddp_info *ddp;
537 536
538 void (*dev_ddp_cleanup)(struct cxgbi_device *); 537 void (*dev_ddp_cleanup)(struct cxgbi_device *);
539 void (*csk_ddp_free_gl_skb)(struct cxgbi_ddp_info *, int, int);
540 int (*csk_ddp_alloc_gl_skb)(struct cxgbi_ddp_info *, int, int, gfp_t);
541 int (*csk_ddp_set)(struct cxgbi_sock *, struct cxgbi_pagepod_hdr *, 538 int (*csk_ddp_set)(struct cxgbi_sock *, struct cxgbi_pagepod_hdr *,
542 unsigned int, unsigned int, 539 unsigned int, unsigned int,
543 struct cxgbi_gather_list *); 540 struct cxgbi_gather_list *);
@@ -715,7 +712,7 @@ void cxgbi_cleanup_task(struct iscsi_task *task);
715void cxgbi_get_conn_stats(struct iscsi_cls_conn *, struct iscsi_stats *); 712void cxgbi_get_conn_stats(struct iscsi_cls_conn *, struct iscsi_stats *);
716int cxgbi_set_conn_param(struct iscsi_cls_conn *, 713int cxgbi_set_conn_param(struct iscsi_cls_conn *,
717 enum iscsi_param, char *, int); 714 enum iscsi_param, char *, int);
718int cxgbi_get_conn_param(struct iscsi_cls_conn *, enum iscsi_param, char *); 715int cxgbi_get_ep_param(struct iscsi_endpoint *ep, enum iscsi_param, char *);
719struct iscsi_cls_conn *cxgbi_create_conn(struct iscsi_cls_session *, u32); 716struct iscsi_cls_conn *cxgbi_create_conn(struct iscsi_cls_session *, u32);
720int cxgbi_bind_conn(struct iscsi_cls_session *, 717int cxgbi_bind_conn(struct iscsi_cls_session *,
721 struct iscsi_cls_conn *, u64, int); 718 struct iscsi_cls_conn *, u64, int);
diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
index b837c5b3c8f9..564e6ecd17c2 100644
--- a/drivers/scsi/device_handler/scsi_dh.c
+++ b/drivers/scsi/device_handler/scsi_dh.c
@@ -25,16 +25,9 @@
25#include <scsi/scsi_dh.h> 25#include <scsi/scsi_dh.h>
26#include "../scsi_priv.h" 26#include "../scsi_priv.h"
27 27
28struct scsi_dh_devinfo_list {
29 struct list_head node;
30 char vendor[9];
31 char model[17];
32 struct scsi_device_handler *handler;
33};
34
35static DEFINE_SPINLOCK(list_lock); 28static DEFINE_SPINLOCK(list_lock);
36static LIST_HEAD(scsi_dh_list); 29static LIST_HEAD(scsi_dh_list);
37static LIST_HEAD(scsi_dh_dev_list); 30static int scsi_dh_list_idx = 1;
38 31
39static struct scsi_device_handler *get_device_handler(const char *name) 32static struct scsi_device_handler *get_device_handler(const char *name)
40{ 33{
@@ -51,40 +44,18 @@ static struct scsi_device_handler *get_device_handler(const char *name)
51 return found; 44 return found;
52} 45}
53 46
54 47static struct scsi_device_handler *get_device_handler_by_idx(int idx)
55static struct scsi_device_handler *
56scsi_dh_cache_lookup(struct scsi_device *sdev)
57{ 48{
58 struct scsi_dh_devinfo_list *tmp; 49 struct scsi_device_handler *tmp, *found = NULL;
59 struct scsi_device_handler *found_dh = NULL;
60 50
61 spin_lock(&list_lock); 51 spin_lock(&list_lock);
62 list_for_each_entry(tmp, &scsi_dh_dev_list, node) { 52 list_for_each_entry(tmp, &scsi_dh_list, list) {
63 if (!strncmp(sdev->vendor, tmp->vendor, strlen(tmp->vendor)) && 53 if (tmp->idx == idx) {
64 !strncmp(sdev->model, tmp->model, strlen(tmp->model))) { 54 found = tmp;
65 found_dh = tmp->handler;
66 break; 55 break;
67 } 56 }
68 } 57 }
69 spin_unlock(&list_lock); 58 spin_unlock(&list_lock);
70
71 return found_dh;
72}
73
74static int scsi_dh_handler_lookup(struct scsi_device_handler *scsi_dh,
75 struct scsi_device *sdev)
76{
77 int i, found = 0;
78
79 for(i = 0; scsi_dh->devlist[i].vendor; i++) {
80 if (!strncmp(sdev->vendor, scsi_dh->devlist[i].vendor,
81 strlen(scsi_dh->devlist[i].vendor)) &&
82 !strncmp(sdev->model, scsi_dh->devlist[i].model,
83 strlen(scsi_dh->devlist[i].model))) {
84 found = 1;
85 break;
86 }
87 }
88 return found; 59 return found;
89} 60}
90 61
@@ -102,41 +73,14 @@ device_handler_match(struct scsi_device_handler *scsi_dh,
102 struct scsi_device *sdev) 73 struct scsi_device *sdev)
103{ 74{
104 struct scsi_device_handler *found_dh = NULL; 75 struct scsi_device_handler *found_dh = NULL;
105 struct scsi_dh_devinfo_list *tmp; 76 int idx;
106 77
107 found_dh = scsi_dh_cache_lookup(sdev); 78 idx = scsi_get_device_flags_keyed(sdev, sdev->vendor, sdev->model,
108 if (found_dh) 79 SCSI_DEVINFO_DH);
109 return found_dh; 80 found_dh = get_device_handler_by_idx(idx);
110 81
111 if (scsi_dh) { 82 if (scsi_dh && found_dh != scsi_dh)
112 if (scsi_dh_handler_lookup(scsi_dh, sdev)) 83 found_dh = NULL;
113 found_dh = scsi_dh;
114 } else {
115 struct scsi_device_handler *tmp_dh;
116
117 spin_lock(&list_lock);
118 list_for_each_entry(tmp_dh, &scsi_dh_list, list) {
119 if (scsi_dh_handler_lookup(tmp_dh, sdev))
120 found_dh = tmp_dh;
121 }
122 spin_unlock(&list_lock);
123 }
124
125 if (found_dh) { /* If device is found, add it to the cache */
126 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
127 if (tmp) {
128 strncpy(tmp->vendor, sdev->vendor, 8);
129 strncpy(tmp->model, sdev->model, 16);
130 tmp->vendor[8] = '\0';
131 tmp->model[16] = '\0';
132 tmp->handler = found_dh;
133 spin_lock(&list_lock);
134 list_add(&tmp->node, &scsi_dh_dev_list);
135 spin_unlock(&list_lock);
136 } else {
137 found_dh = NULL;
138 }
139 }
140 84
141 return found_dh; 85 return found_dh;
142} 86}
@@ -373,12 +317,25 @@ static int scsi_dh_notifier_remove(struct device *dev, void *data)
373 */ 317 */
374int scsi_register_device_handler(struct scsi_device_handler *scsi_dh) 318int scsi_register_device_handler(struct scsi_device_handler *scsi_dh)
375{ 319{
320 int i;
321
376 if (get_device_handler(scsi_dh->name)) 322 if (get_device_handler(scsi_dh->name))
377 return -EBUSY; 323 return -EBUSY;
378 324
379 spin_lock(&list_lock); 325 spin_lock(&list_lock);
326 scsi_dh->idx = scsi_dh_list_idx++;
380 list_add(&scsi_dh->list, &scsi_dh_list); 327 list_add(&scsi_dh->list, &scsi_dh_list);
381 spin_unlock(&list_lock); 328 spin_unlock(&list_lock);
329
330 for (i = 0; scsi_dh->devlist[i].vendor; i++) {
331 scsi_dev_info_list_add_keyed(0,
332 scsi_dh->devlist[i].vendor,
333 scsi_dh->devlist[i].model,
334 NULL,
335 scsi_dh->idx,
336 SCSI_DEVINFO_DH);
337 }
338
382 bus_for_each_dev(&scsi_bus_type, NULL, scsi_dh, scsi_dh_notifier_add); 339 bus_for_each_dev(&scsi_bus_type, NULL, scsi_dh, scsi_dh_notifier_add);
383 printk(KERN_INFO "%s: device handler registered\n", scsi_dh->name); 340 printk(KERN_INFO "%s: device handler registered\n", scsi_dh->name);
384 341
@@ -395,7 +352,7 @@ EXPORT_SYMBOL_GPL(scsi_register_device_handler);
395 */ 352 */
396int scsi_unregister_device_handler(struct scsi_device_handler *scsi_dh) 353int scsi_unregister_device_handler(struct scsi_device_handler *scsi_dh)
397{ 354{
398 struct scsi_dh_devinfo_list *tmp, *pos; 355 int i;
399 356
400 if (!get_device_handler(scsi_dh->name)) 357 if (!get_device_handler(scsi_dh->name))
401 return -ENODEV; 358 return -ENODEV;
@@ -403,14 +360,14 @@ int scsi_unregister_device_handler(struct scsi_device_handler *scsi_dh)
403 bus_for_each_dev(&scsi_bus_type, NULL, scsi_dh, 360 bus_for_each_dev(&scsi_bus_type, NULL, scsi_dh,
404 scsi_dh_notifier_remove); 361 scsi_dh_notifier_remove);
405 362
363 for (i = 0; scsi_dh->devlist[i].vendor; i++) {
364 scsi_dev_info_list_del_keyed(scsi_dh->devlist[i].vendor,
365 scsi_dh->devlist[i].model,
366 SCSI_DEVINFO_DH);
367 }
368
406 spin_lock(&list_lock); 369 spin_lock(&list_lock);
407 list_del(&scsi_dh->list); 370 list_del(&scsi_dh->list);
408 list_for_each_entry_safe(pos, tmp, &scsi_dh_dev_list, node) {
409 if (pos->handler == scsi_dh) {
410 list_del(&pos->node);
411 kfree(pos);
412 }
413 }
414 spin_unlock(&list_lock); 371 spin_unlock(&list_lock);
415 printk(KERN_INFO "%s: device handler unregistered\n", scsi_dh->name); 372 printk(KERN_INFO "%s: device handler unregistered\n", scsi_dh->name);
416 373
@@ -576,6 +533,10 @@ static int __init scsi_dh_init(void)
576{ 533{
577 int r; 534 int r;
578 535
536 r = scsi_dev_info_add_list(SCSI_DEVINFO_DH, "SCSI Device Handler");
537 if (r)
538 return r;
539
579 r = bus_register_notifier(&scsi_bus_type, &scsi_dh_nb); 540 r = bus_register_notifier(&scsi_bus_type, &scsi_dh_nb);
580 541
581 if (!r) 542 if (!r)
@@ -590,6 +551,7 @@ static void __exit scsi_dh_exit(void)
590 bus_for_each_dev(&scsi_bus_type, NULL, NULL, 551 bus_for_each_dev(&scsi_bus_type, NULL, NULL,
591 scsi_dh_sysfs_attr_remove); 552 scsi_dh_sysfs_attr_remove);
592 bus_unregister_notifier(&scsi_bus_type, &scsi_dh_nb); 553 bus_unregister_notifier(&scsi_bus_type, &scsi_dh_nb);
554 scsi_dev_info_remove_list(SCSI_DEVINFO_DH);
593} 555}
594 556
595module_init(scsi_dh_init); 557module_init(scsi_dh_init);
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 6b729324b8d3..7cae0bc85390 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -253,13 +253,15 @@ static void stpg_endio(struct request *req, int error)
253{ 253{
254 struct alua_dh_data *h = req->end_io_data; 254 struct alua_dh_data *h = req->end_io_data;
255 struct scsi_sense_hdr sense_hdr; 255 struct scsi_sense_hdr sense_hdr;
256 unsigned err = SCSI_DH_IO; 256 unsigned err = SCSI_DH_OK;
257 257
258 if (error || host_byte(req->errors) != DID_OK || 258 if (error || host_byte(req->errors) != DID_OK ||
259 msg_byte(req->errors) != COMMAND_COMPLETE) 259 msg_byte(req->errors) != COMMAND_COMPLETE) {
260 err = SCSI_DH_IO;
260 goto done; 261 goto done;
262 }
261 263
262 if (err == SCSI_DH_IO && h->senselen > 0) { 264 if (h->senselen > 0) {
263 err = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, 265 err = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE,
264 &sense_hdr); 266 &sense_hdr);
265 if (!err) { 267 if (!err) {
@@ -285,7 +287,8 @@ static void stpg_endio(struct request *req, int error)
285 print_alua_state(h->state)); 287 print_alua_state(h->state));
286 } 288 }
287done: 289done:
288 blk_put_request(req); 290 req->end_io_data = NULL;
291 __blk_put_request(req->q, req);
289 if (h->callback_fn) { 292 if (h->callback_fn) {
290 h->callback_fn(h->callback_data, err); 293 h->callback_fn(h->callback_data, err);
291 h->callback_fn = h->callback_data = NULL; 294 h->callback_fn = h->callback_data = NULL;
@@ -303,7 +306,6 @@ done:
303static unsigned submit_stpg(struct alua_dh_data *h) 306static unsigned submit_stpg(struct alua_dh_data *h)
304{ 307{
305 struct request *rq; 308 struct request *rq;
306 int err = SCSI_DH_RES_TEMP_UNAVAIL;
307 int stpg_len = 8; 309 int stpg_len = 8;
308 struct scsi_device *sdev = h->sdev; 310 struct scsi_device *sdev = h->sdev;
309 311
@@ -332,7 +334,7 @@ static unsigned submit_stpg(struct alua_dh_data *h)
332 rq->end_io_data = h; 334 rq->end_io_data = h;
333 335
334 blk_execute_rq_nowait(rq->q, NULL, rq, 1, stpg_endio); 336 blk_execute_rq_nowait(rq->q, NULL, rq, 1, stpg_endio);
335 return err; 337 return SCSI_DH_OK;
336} 338}
337 339
338/* 340/*
@@ -730,7 +732,9 @@ static const struct scsi_dh_devlist alua_dev_list[] = {
730 {"Pillar", "Axiom" }, 732 {"Pillar", "Axiom" },
731 {"Intel", "Multi-Flex"}, 733 {"Intel", "Multi-Flex"},
732 {"NETAPP", "LUN"}, 734 {"NETAPP", "LUN"},
735 {"NETAPP", "LUN C-Mode"},
733 {"AIX", "NVDISK"}, 736 {"AIX", "NVDISK"},
737 {"Promise", "VTrak"},
734 {NULL, NULL} 738 {NULL, NULL}
735}; 739};
736 740
@@ -759,7 +763,7 @@ static int alua_bus_attach(struct scsi_device *sdev)
759 unsigned long flags; 763 unsigned long flags;
760 int err = SCSI_DH_OK; 764 int err = SCSI_DH_OK;
761 765
762 scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *) 766 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
763 + sizeof(*h) , GFP_KERNEL); 767 + sizeof(*h) , GFP_KERNEL);
764 if (!scsi_dh_data) { 768 if (!scsi_dh_data) {
765 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", 769 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c b/drivers/scsi/device_handler/scsi_dh_emc.c
index 6faf472f7537..48441f6908a4 100644
--- a/drivers/scsi/device_handler/scsi_dh_emc.c
+++ b/drivers/scsi/device_handler/scsi_dh_emc.c
@@ -650,7 +650,7 @@ static int clariion_bus_attach(struct scsi_device *sdev)
650 unsigned long flags; 650 unsigned long flags;
651 int err; 651 int err;
652 652
653 scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *) 653 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
654 + sizeof(*h) , GFP_KERNEL); 654 + sizeof(*h) , GFP_KERNEL);
655 if (!scsi_dh_data) { 655 if (!scsi_dh_data) {
656 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", 656 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index e3916641e627..b479f1eef968 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -225,7 +225,8 @@ static void start_stop_endio(struct request *req, int error)
225 } 225 }
226 } 226 }
227done: 227done:
228 blk_put_request(req); 228 req->end_io_data = NULL;
229 __blk_put_request(req->q, req);
229 if (h->callback_fn) { 230 if (h->callback_fn) {
230 h->callback_fn(h->callback_data, err); 231 h->callback_fn(h->callback_data, err);
231 h->callback_fn = h->callback_data = NULL; 232 h->callback_fn = h->callback_data = NULL;
@@ -338,8 +339,8 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
338 unsigned long flags; 339 unsigned long flags;
339 int ret; 340 int ret;
340 341
341 scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *) 342 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
342 + sizeof(struct hp_sw_dh_data) , GFP_KERNEL); 343 + sizeof(*h) , GFP_KERNEL);
343 if (!scsi_dh_data) { 344 if (!scsi_dh_data) {
344 sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n", 345 sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n",
345 HP_SW_NAME); 346 HP_SW_NAME);
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index 5be3ae15cb71..293c183dfe6d 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -281,11 +281,13 @@ static struct request *get_rdac_req(struct scsi_device *sdev,
281} 281}
282 282
283static struct request *rdac_failover_get(struct scsi_device *sdev, 283static struct request *rdac_failover_get(struct scsi_device *sdev,
284 struct rdac_dh_data *h) 284 struct rdac_dh_data *h, struct list_head *list)
285{ 285{
286 struct request *rq; 286 struct request *rq;
287 struct rdac_mode_common *common; 287 struct rdac_mode_common *common;
288 unsigned data_size; 288 unsigned data_size;
289 struct rdac_queue_data *qdata;
290 u8 *lun_table;
289 291
290 if (h->ctlr->use_ms10) { 292 if (h->ctlr->use_ms10) {
291 struct rdac_pg_expanded *rdac_pg; 293 struct rdac_pg_expanded *rdac_pg;
@@ -298,6 +300,7 @@ static struct request *rdac_failover_get(struct scsi_device *sdev,
298 rdac_pg->subpage_code = 0x1; 300 rdac_pg->subpage_code = 0x1;
299 rdac_pg->page_len[0] = 0x01; 301 rdac_pg->page_len[0] = 0x01;
300 rdac_pg->page_len[1] = 0x28; 302 rdac_pg->page_len[1] = 0x28;
303 lun_table = rdac_pg->lun_table;
301 } else { 304 } else {
302 struct rdac_pg_legacy *rdac_pg; 305 struct rdac_pg_legacy *rdac_pg;
303 306
@@ -307,11 +310,16 @@ static struct request *rdac_failover_get(struct scsi_device *sdev,
307 common = &rdac_pg->common; 310 common = &rdac_pg->common;
308 rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER; 311 rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER;
309 rdac_pg->page_len = 0x68; 312 rdac_pg->page_len = 0x68;
313 lun_table = rdac_pg->lun_table;
310 } 314 }
311 common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS; 315 common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS;
312 common->quiescence_timeout = RDAC_QUIESCENCE_TIME; 316 common->quiescence_timeout = RDAC_QUIESCENCE_TIME;
313 common->rdac_options = RDAC_FORCED_QUIESENCE; 317 common->rdac_options = RDAC_FORCED_QUIESENCE;
314 318
319 list_for_each_entry(qdata, list, entry) {
320 lun_table[qdata->h->lun] = 0x81;
321 }
322
315 /* get request for block layer packet command */ 323 /* get request for block layer packet command */
316 rq = get_rdac_req(sdev, &h->ctlr->mode_select, data_size, WRITE); 324 rq = get_rdac_req(sdev, &h->ctlr->mode_select, data_size, WRITE);
317 if (!rq) 325 if (!rq)
@@ -565,7 +573,6 @@ static void send_mode_select(struct work_struct *work)
565 int err, retry_cnt = RDAC_RETRY_COUNT; 573 int err, retry_cnt = RDAC_RETRY_COUNT;
566 struct rdac_queue_data *tmp, *qdata; 574 struct rdac_queue_data *tmp, *qdata;
567 LIST_HEAD(list); 575 LIST_HEAD(list);
568 u8 *lun_table;
569 576
570 spin_lock(&ctlr->ms_lock); 577 spin_lock(&ctlr->ms_lock);
571 list_splice_init(&ctlr->ms_head, &list); 578 list_splice_init(&ctlr->ms_head, &list);
@@ -573,21 +580,12 @@ static void send_mode_select(struct work_struct *work)
573 ctlr->ms_sdev = NULL; 580 ctlr->ms_sdev = NULL;
574 spin_unlock(&ctlr->ms_lock); 581 spin_unlock(&ctlr->ms_lock);
575 582
576 if (ctlr->use_ms10)
577 lun_table = ctlr->mode_select.expanded.lun_table;
578 else
579 lun_table = ctlr->mode_select.legacy.lun_table;
580
581retry: 583retry:
582 err = SCSI_DH_RES_TEMP_UNAVAIL; 584 err = SCSI_DH_RES_TEMP_UNAVAIL;
583 rq = rdac_failover_get(sdev, h); 585 rq = rdac_failover_get(sdev, h, &list);
584 if (!rq) 586 if (!rq)
585 goto done; 587 goto done;
586 588
587 list_for_each_entry(qdata, &list, entry) {
588 lun_table[qdata->h->lun] = 0x81;
589 }
590
591 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, " 589 RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
592 "%s MODE_SELECT command", 590 "%s MODE_SELECT command",
593 (char *) h->ctlr->array_name, h->ctlr->index, 591 (char *) h->ctlr->array_name, h->ctlr->index,
@@ -769,6 +767,7 @@ static const struct scsi_dh_devlist rdac_dev_list[] = {
769 {"DELL", "MD32xx"}, 767 {"DELL", "MD32xx"},
770 {"DELL", "MD32xxi"}, 768 {"DELL", "MD32xxi"},
771 {"DELL", "MD36xxi"}, 769 {"DELL", "MD36xxi"},
770 {"DELL", "MD36xxf"},
772 {"LSI", "INF-01-00"}, 771 {"LSI", "INF-01-00"},
773 {"ENGENIO", "INF-01-00"}, 772 {"ENGENIO", "INF-01-00"},
774 {"STK", "FLEXLINE 380"}, 773 {"STK", "FLEXLINE 380"},
@@ -800,7 +799,7 @@ static int rdac_bus_attach(struct scsi_device *sdev)
800 int err; 799 int err;
801 char array_name[ARRAY_LABEL_LEN]; 800 char array_name[ARRAY_LABEL_LEN];
802 801
803 scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *) 802 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
804 + sizeof(*h) , GFP_KERNEL); 803 + sizeof(*h) , GFP_KERNEL);
805 if (!scsi_dh_data) { 804 if (!scsi_dh_data) {
806 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", 805 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
@@ -906,4 +905,5 @@ module_exit(rdac_exit);
906 905
907MODULE_DESCRIPTION("Multipath LSI/Engenio RDAC driver"); 906MODULE_DESCRIPTION("Multipath LSI/Engenio RDAC driver");
908MODULE_AUTHOR("Mike Christie, Chandra Seetharaman"); 907MODULE_AUTHOR("Mike Christie, Chandra Seetharaman");
908MODULE_VERSION("01.00.0000.0000");
909MODULE_LICENSE("GPL"); 909MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/fcoe/Makefile b/drivers/scsi/fcoe/Makefile
index 950f27615c76..f6d37d0271f7 100644
--- a/drivers/scsi/fcoe/Makefile
+++ b/drivers/scsi/fcoe/Makefile
@@ -1,2 +1,4 @@
1obj-$(CONFIG_FCOE) += fcoe.o 1obj-$(CONFIG_FCOE) += fcoe.o
2obj-$(CONFIG_LIBFCOE) += libfcoe.o 2obj-$(CONFIG_LIBFCOE) += libfcoe.o
3
4libfcoe-objs := fcoe_ctlr.o fcoe_transport.o
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 3becc6a20a4f..bde6ee5333eb 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -31,6 +31,7 @@
31#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/sysfs.h> 32#include <linux/sysfs.h>
33#include <linux/ctype.h> 33#include <linux/ctype.h>
34#include <linux/workqueue.h>
34#include <scsi/scsi_tcq.h> 35#include <scsi/scsi_tcq.h>
35#include <scsi/scsicam.h> 36#include <scsi/scsicam.h>
36#include <scsi/scsi_transport.h> 37#include <scsi/scsi_transport.h>
@@ -58,6 +59,8 @@ MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \
58 59
59DEFINE_MUTEX(fcoe_config_mutex); 60DEFINE_MUTEX(fcoe_config_mutex);
60 61
62static struct workqueue_struct *fcoe_wq;
63
61/* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */ 64/* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */
62static DECLARE_COMPLETION(fcoe_flush_completion); 65static DECLARE_COMPLETION(fcoe_flush_completion);
63 66
@@ -72,7 +75,6 @@ static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
72static int fcoe_rcv(struct sk_buff *, struct net_device *, 75static int fcoe_rcv(struct sk_buff *, struct net_device *,
73 struct packet_type *, struct net_device *); 76 struct packet_type *, struct net_device *);
74static int fcoe_percpu_receive_thread(void *); 77static int fcoe_percpu_receive_thread(void *);
75static void fcoe_clean_pending_queue(struct fc_lport *);
76static void fcoe_percpu_clean(struct fc_lport *); 78static void fcoe_percpu_clean(struct fc_lport *);
77static int fcoe_link_speed_update(struct fc_lport *); 79static int fcoe_link_speed_update(struct fc_lport *);
78static int fcoe_link_ok(struct fc_lport *); 80static int fcoe_link_ok(struct fc_lport *);
@@ -80,7 +82,6 @@ static int fcoe_link_ok(struct fc_lport *);
80static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *); 82static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
81static int fcoe_hostlist_add(const struct fc_lport *); 83static int fcoe_hostlist_add(const struct fc_lport *);
82 84
83static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *);
84static int fcoe_device_notification(struct notifier_block *, ulong, void *); 85static int fcoe_device_notification(struct notifier_block *, ulong, void *);
85static void fcoe_dev_setup(void); 86static void fcoe_dev_setup(void);
86static void fcoe_dev_cleanup(void); 87static void fcoe_dev_cleanup(void);
@@ -101,10 +102,11 @@ static int fcoe_ddp_done(struct fc_lport *, u16);
101 102
102static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *); 103static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *);
103 104
104static int fcoe_create(const char *, struct kernel_param *); 105static bool fcoe_match(struct net_device *netdev);
105static int fcoe_destroy(const char *, struct kernel_param *); 106static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode);
106static int fcoe_enable(const char *, struct kernel_param *); 107static int fcoe_destroy(struct net_device *netdev);
107static int fcoe_disable(const char *, struct kernel_param *); 108static int fcoe_enable(struct net_device *netdev);
109static int fcoe_disable(struct net_device *netdev);
108 110
109static struct fc_seq *fcoe_elsct_send(struct fc_lport *, 111static struct fc_seq *fcoe_elsct_send(struct fc_lport *,
110 u32 did, struct fc_frame *, 112 u32 did, struct fc_frame *,
@@ -117,24 +119,6 @@ static void fcoe_recv_frame(struct sk_buff *skb);
117 119
118static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *); 120static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *);
119 121
120module_param_call(create, fcoe_create, NULL, (void *)FIP_MODE_FABRIC, S_IWUSR);
121__MODULE_PARM_TYPE(create, "string");
122MODULE_PARM_DESC(create, " Creates fcoe instance on a ethernet interface");
123module_param_call(create_vn2vn, fcoe_create, NULL,
124 (void *)FIP_MODE_VN2VN, S_IWUSR);
125__MODULE_PARM_TYPE(create_vn2vn, "string");
126MODULE_PARM_DESC(create_vn2vn, " Creates a VN_node to VN_node FCoE instance "
127 "on an Ethernet interface");
128module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
129__MODULE_PARM_TYPE(destroy, "string");
130MODULE_PARM_DESC(destroy, " Destroys fcoe instance on a ethernet interface");
131module_param_call(enable, fcoe_enable, NULL, NULL, S_IWUSR);
132__MODULE_PARM_TYPE(enable, "string");
133MODULE_PARM_DESC(enable, " Enables fcoe on a ethernet interface.");
134module_param_call(disable, fcoe_disable, NULL, NULL, S_IWUSR);
135__MODULE_PARM_TYPE(disable, "string");
136MODULE_PARM_DESC(disable, " Disables fcoe on a ethernet interface.");
137
138/* notification function for packets from net device */ 122/* notification function for packets from net device */
139static struct notifier_block fcoe_notifier = { 123static struct notifier_block fcoe_notifier = {
140 .notifier_call = fcoe_device_notification, 124 .notifier_call = fcoe_device_notification,
@@ -145,8 +129,8 @@ static struct notifier_block fcoe_cpu_notifier = {
145 .notifier_call = fcoe_cpu_callback, 129 .notifier_call = fcoe_cpu_callback,
146}; 130};
147 131
148static struct scsi_transport_template *fcoe_transport_template; 132static struct scsi_transport_template *fcoe_nport_scsi_transport;
149static struct scsi_transport_template *fcoe_vport_transport_template; 133static struct scsi_transport_template *fcoe_vport_scsi_transport;
150 134
151static int fcoe_vport_destroy(struct fc_vport *); 135static int fcoe_vport_destroy(struct fc_vport *);
152static int fcoe_vport_create(struct fc_vport *, bool disabled); 136static int fcoe_vport_create(struct fc_vport *, bool disabled);
@@ -163,7 +147,7 @@ static struct libfc_function_template fcoe_libfc_fcn_templ = {
163 .lport_set_port_id = fcoe_set_port_id, 147 .lport_set_port_id = fcoe_set_port_id,
164}; 148};
165 149
166struct fc_function_template fcoe_transport_function = { 150struct fc_function_template fcoe_nport_fc_functions = {
167 .show_host_node_name = 1, 151 .show_host_node_name = 1,
168 .show_host_port_name = 1, 152 .show_host_port_name = 1,
169 .show_host_supported_classes = 1, 153 .show_host_supported_classes = 1,
@@ -203,7 +187,7 @@ struct fc_function_template fcoe_transport_function = {
203 .bsg_request = fc_lport_bsg_request, 187 .bsg_request = fc_lport_bsg_request,
204}; 188};
205 189
206struct fc_function_template fcoe_vport_transport_function = { 190struct fc_function_template fcoe_vport_fc_functions = {
207 .show_host_node_name = 1, 191 .show_host_node_name = 1,
208 .show_host_port_name = 1, 192 .show_host_port_name = 1,
209 .show_host_supported_classes = 1, 193 .show_host_supported_classes = 1,
@@ -354,10 +338,18 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
354 struct fcoe_interface *fcoe; 338 struct fcoe_interface *fcoe;
355 int err; 339 int err;
356 340
341 if (!try_module_get(THIS_MODULE)) {
342 FCOE_NETDEV_DBG(netdev,
343 "Could not get a reference to the module\n");
344 fcoe = ERR_PTR(-EBUSY);
345 goto out;
346 }
347
357 fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL); 348 fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL);
358 if (!fcoe) { 349 if (!fcoe) {
359 FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n"); 350 FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
360 return NULL; 351 fcoe = ERR_PTR(-ENOMEM);
352 goto out_nomod;
361 } 353 }
362 354
363 dev_hold(netdev); 355 dev_hold(netdev);
@@ -376,9 +368,15 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
376 fcoe_ctlr_destroy(&fcoe->ctlr); 368 fcoe_ctlr_destroy(&fcoe->ctlr);
377 kfree(fcoe); 369 kfree(fcoe);
378 dev_put(netdev); 370 dev_put(netdev);
379 return NULL; 371 fcoe = ERR_PTR(err);
372 goto out_nomod;
380 } 373 }
381 374
375 goto out;
376
377out_nomod:
378 module_put(THIS_MODULE);
379out:
382 return fcoe; 380 return fcoe;
383} 381}
384 382
@@ -440,6 +438,7 @@ static void fcoe_interface_release(struct kref *kref)
440 fcoe_ctlr_destroy(&fcoe->ctlr); 438 fcoe_ctlr_destroy(&fcoe->ctlr);
441 kfree(fcoe); 439 kfree(fcoe);
442 dev_put(netdev); 440 dev_put(netdev);
441 module_put(THIS_MODULE);
443} 442}
444 443
445/** 444/**
@@ -503,7 +502,7 @@ static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
503static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr) 502static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr)
504{ 503{
505 struct fcoe_port *port = lport_priv(lport); 504 struct fcoe_port *port = lport_priv(lport);
506 struct fcoe_interface *fcoe = port->fcoe; 505 struct fcoe_interface *fcoe = port->priv;
507 506
508 rtnl_lock(); 507 rtnl_lock();
509 if (!is_zero_ether_addr(port->data_src_addr)) 508 if (!is_zero_ether_addr(port->data_src_addr))
@@ -559,17 +558,6 @@ static int fcoe_lport_config(struct fc_lport *lport)
559} 558}
560 559
561/** 560/**
562 * fcoe_queue_timer() - The fcoe queue timer
563 * @lport: The local port
564 *
565 * Calls fcoe_check_wait_queue on timeout
566 */
567static void fcoe_queue_timer(ulong lport)
568{
569 fcoe_check_wait_queue((struct fc_lport *)lport, NULL);
570}
571
572/**
573 * fcoe_get_wwn() - Get the world wide name from LLD if it supports it 561 * fcoe_get_wwn() - Get the world wide name from LLD if it supports it
574 * @netdev: the associated net device 562 * @netdev: the associated net device
575 * @wwn: the output WWN 563 * @wwn: the output WWN
@@ -648,7 +636,7 @@ static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev)
648 636
649 /* Setup lport private data to point to fcoe softc */ 637 /* Setup lport private data to point to fcoe softc */
650 port = lport_priv(lport); 638 port = lport_priv(lport);
651 fcoe = port->fcoe; 639 fcoe = port->priv;
652 640
653 /* 641 /*
654 * Determine max frame size based on underlying device and optional 642 * Determine max frame size based on underlying device and optional
@@ -706,9 +694,9 @@ static int fcoe_shost_config(struct fc_lport *lport, struct device *dev)
706 lport->host->max_cmd_len = FCOE_MAX_CMD_LEN; 694 lport->host->max_cmd_len = FCOE_MAX_CMD_LEN;
707 695
708 if (lport->vport) 696 if (lport->vport)
709 lport->host->transportt = fcoe_vport_transport_template; 697 lport->host->transportt = fcoe_vport_scsi_transport;
710 else 698 else
711 lport->host->transportt = fcoe_transport_template; 699 lport->host->transportt = fcoe_nport_scsi_transport;
712 700
713 /* add the new host to the SCSI-ml */ 701 /* add the new host to the SCSI-ml */
714 rc = scsi_add_host(lport->host, dev); 702 rc = scsi_add_host(lport->host, dev);
@@ -758,7 +746,7 @@ bool fcoe_oem_match(struct fc_frame *fp)
758static inline int fcoe_em_config(struct fc_lport *lport) 746static inline int fcoe_em_config(struct fc_lport *lport)
759{ 747{
760 struct fcoe_port *port = lport_priv(lport); 748 struct fcoe_port *port = lport_priv(lport);
761 struct fcoe_interface *fcoe = port->fcoe; 749 struct fcoe_interface *fcoe = port->priv;
762 struct fcoe_interface *oldfcoe = NULL; 750 struct fcoe_interface *oldfcoe = NULL;
763 struct net_device *old_real_dev, *cur_real_dev; 751 struct net_device *old_real_dev, *cur_real_dev;
764 u16 min_xid = FCOE_MIN_XID; 752 u16 min_xid = FCOE_MIN_XID;
@@ -842,7 +830,7 @@ skip_oem:
842static void fcoe_if_destroy(struct fc_lport *lport) 830static void fcoe_if_destroy(struct fc_lport *lport)
843{ 831{
844 struct fcoe_port *port = lport_priv(lport); 832 struct fcoe_port *port = lport_priv(lport);
845 struct fcoe_interface *fcoe = port->fcoe; 833 struct fcoe_interface *fcoe = port->priv;
846 struct net_device *netdev = fcoe->netdev; 834 struct net_device *netdev = fcoe->netdev;
847 835
848 FCOE_NETDEV_DBG(netdev, "Destroying interface\n"); 836 FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
@@ -884,7 +872,6 @@ static void fcoe_if_destroy(struct fc_lport *lport)
884 872
885 /* Release the Scsi_Host */ 873 /* Release the Scsi_Host */
886 scsi_host_put(lport->host); 874 scsi_host_put(lport->host);
887 module_put(THIS_MODULE);
888} 875}
889 876
890/** 877/**
@@ -939,8 +926,9 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
939 struct device *parent, int npiv) 926 struct device *parent, int npiv)
940{ 927{
941 struct net_device *netdev = fcoe->netdev; 928 struct net_device *netdev = fcoe->netdev;
942 struct fc_lport *lport = NULL; 929 struct fc_lport *lport, *n_port;
943 struct fcoe_port *port; 930 struct fcoe_port *port;
931 struct Scsi_Host *shost;
944 int rc; 932 int rc;
945 /* 933 /*
946 * parent is only a vport if npiv is 1, 934 * parent is only a vport if npiv is 1,
@@ -950,13 +938,11 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
950 938
951 FCOE_NETDEV_DBG(netdev, "Create Interface\n"); 939 FCOE_NETDEV_DBG(netdev, "Create Interface\n");
952 940
953 if (!npiv) { 941 if (!npiv)
954 lport = libfc_host_alloc(&fcoe_shost_template, 942 lport = libfc_host_alloc(&fcoe_shost_template, sizeof(*port));
955 sizeof(struct fcoe_port)); 943 else
956 } else { 944 lport = libfc_vport_create(vport, sizeof(*port));
957 lport = libfc_vport_create(vport, 945
958 sizeof(struct fcoe_port));
959 }
960 if (!lport) { 946 if (!lport) {
961 FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n"); 947 FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
962 rc = -ENOMEM; 948 rc = -ENOMEM;
@@ -964,7 +950,9 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
964 } 950 }
965 port = lport_priv(lport); 951 port = lport_priv(lport);
966 port->lport = lport; 952 port->lport = lport;
967 port->fcoe = fcoe; 953 port->priv = fcoe;
954 port->max_queue_depth = FCOE_MAX_QUEUE_DEPTH;
955 port->min_queue_depth = FCOE_MIN_QUEUE_DEPTH;
968 INIT_WORK(&port->destroy_work, fcoe_destroy_work); 956 INIT_WORK(&port->destroy_work, fcoe_destroy_work);
969 957
970 /* configure a fc_lport including the exchange manager */ 958 /* configure a fc_lport including the exchange manager */
@@ -1007,24 +995,27 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
1007 goto out_lp_destroy; 995 goto out_lp_destroy;
1008 } 996 }
1009 997
1010 if (!npiv) { 998 /*
1011 /* 999 * fcoe_em_alloc() and fcoe_hostlist_add() both
1012 * fcoe_em_alloc() and fcoe_hostlist_add() both 1000 * need to be atomic with respect to other changes to the
1013 * need to be atomic with respect to other changes to the 1001 * hostlist since fcoe_em_alloc() looks for an existing EM
1014 * hostlist since fcoe_em_alloc() looks for an existing EM 1002 * instance on host list updated by fcoe_hostlist_add().
1015 * instance on host list updated by fcoe_hostlist_add(). 1003 *
1016 * 1004 * This is currently handled through the fcoe_config_mutex
1017 * This is currently handled through the fcoe_config_mutex 1005 * begin held.
1018 * begin held. 1006 */
1019 */ 1007 if (!npiv)
1020
1021 /* lport exch manager allocation */ 1008 /* lport exch manager allocation */
1022 rc = fcoe_em_config(lport); 1009 rc = fcoe_em_config(lport);
1023 if (rc) { 1010 else {
1024 FCOE_NETDEV_DBG(netdev, "Could not configure the EM " 1011 shost = vport_to_shost(vport);
1025 "for the interface\n"); 1012 n_port = shost_priv(shost);
1026 goto out_lp_destroy; 1013 rc = fc_exch_mgr_list_clone(n_port, lport);
1027 } 1014 }
1015
1016 if (rc) {
1017 FCOE_NETDEV_DBG(netdev, "Could not configure the EM\n");
1018 goto out_lp_destroy;
1028 } 1019 }
1029 1020
1030 fcoe_interface_get(fcoe); 1021 fcoe_interface_get(fcoe);
@@ -1048,11 +1039,12 @@ out:
1048static int __init fcoe_if_init(void) 1039static int __init fcoe_if_init(void)
1049{ 1040{
1050 /* attach to scsi transport */ 1041 /* attach to scsi transport */
1051 fcoe_transport_template = fc_attach_transport(&fcoe_transport_function); 1042 fcoe_nport_scsi_transport =
1052 fcoe_vport_transport_template = 1043 fc_attach_transport(&fcoe_nport_fc_functions);
1053 fc_attach_transport(&fcoe_vport_transport_function); 1044 fcoe_vport_scsi_transport =
1045 fc_attach_transport(&fcoe_vport_fc_functions);
1054 1046
1055 if (!fcoe_transport_template) { 1047 if (!fcoe_nport_scsi_transport) {
1056 printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n"); 1048 printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
1057 return -ENODEV; 1049 return -ENODEV;
1058 } 1050 }
@@ -1069,10 +1061,10 @@ static int __init fcoe_if_init(void)
1069 */ 1061 */
1070int __exit fcoe_if_exit(void) 1062int __exit fcoe_if_exit(void)
1071{ 1063{
1072 fc_release_transport(fcoe_transport_template); 1064 fc_release_transport(fcoe_nport_scsi_transport);
1073 fc_release_transport(fcoe_vport_transport_template); 1065 fc_release_transport(fcoe_vport_scsi_transport);
1074 fcoe_transport_template = NULL; 1066 fcoe_nport_scsi_transport = NULL;
1075 fcoe_vport_transport_template = NULL; 1067 fcoe_vport_scsi_transport = NULL;
1076 return 0; 1068 return 0;
1077} 1069}
1078 1070
@@ -1359,108 +1351,22 @@ err2:
1359} 1351}
1360 1352
1361/** 1353/**
1362 * fcoe_start_io() - Start FCoE I/O 1354 * fcoe_alloc_paged_crc_eof() - Allocate a page to be used for the trailer CRC
1363 * @skb: The packet to be transmitted
1364 *
1365 * This routine is called from the net device to start transmitting
1366 * FCoE packets.
1367 *
1368 * Returns: 0 for success
1369 */
1370static inline int fcoe_start_io(struct sk_buff *skb)
1371{
1372 struct sk_buff *nskb;
1373 int rc;
1374
1375 nskb = skb_clone(skb, GFP_ATOMIC);
1376 rc = dev_queue_xmit(nskb);
1377 if (rc != 0)
1378 return rc;
1379 kfree_skb(skb);
1380 return 0;
1381}
1382
1383/**
1384 * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC
1385 * @skb: The packet to be transmitted 1355 * @skb: The packet to be transmitted
1386 * @tlen: The total length of the trailer 1356 * @tlen: The total length of the trailer
1387 * 1357 *
1388 * This routine allocates a page for frame trailers. The page is re-used if
1389 * there is enough room left on it for the current trailer. If there isn't
1390 * enough buffer left a new page is allocated for the trailer. Reference to
1391 * the page from this function as well as the skbs using the page fragments
1392 * ensure that the page is freed at the appropriate time.
1393 *
1394 * Returns: 0 for success 1358 * Returns: 0 for success
1395 */ 1359 */
1396static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen) 1360static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen)
1397{ 1361{
1398 struct fcoe_percpu_s *fps; 1362 struct fcoe_percpu_s *fps;
1399 struct page *page; 1363 int rc;
1400 1364
1401 fps = &get_cpu_var(fcoe_percpu); 1365 fps = &get_cpu_var(fcoe_percpu);
1402 page = fps->crc_eof_page; 1366 rc = fcoe_get_paged_crc_eof(skb, tlen, fps);
1403 if (!page) {
1404 page = alloc_page(GFP_ATOMIC);
1405 if (!page) {
1406 put_cpu_var(fcoe_percpu);
1407 return -ENOMEM;
1408 }
1409 fps->crc_eof_page = page;
1410 fps->crc_eof_offset = 0;
1411 }
1412
1413 get_page(page);
1414 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
1415 fps->crc_eof_offset, tlen);
1416 skb->len += tlen;
1417 skb->data_len += tlen;
1418 skb->truesize += tlen;
1419 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
1420
1421 if (fps->crc_eof_offset >= PAGE_SIZE) {
1422 fps->crc_eof_page = NULL;
1423 fps->crc_eof_offset = 0;
1424 put_page(page);
1425 }
1426 put_cpu_var(fcoe_percpu); 1367 put_cpu_var(fcoe_percpu);
1427 return 0;
1428}
1429 1368
1430/** 1369 return rc;
1431 * fcoe_fc_crc() - Calculates the CRC for a given frame
1432 * @fp: The frame to be checksumed
1433 *
1434 * This uses crc32() routine to calculate the CRC for a frame
1435 *
1436 * Return: The 32 bit CRC value
1437 */
1438u32 fcoe_fc_crc(struct fc_frame *fp)
1439{
1440 struct sk_buff *skb = fp_skb(fp);
1441 struct skb_frag_struct *frag;
1442 unsigned char *data;
1443 unsigned long off, len, clen;
1444 u32 crc;
1445 unsigned i;
1446
1447 crc = crc32(~0, skb->data, skb_headlen(skb));
1448
1449 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1450 frag = &skb_shinfo(skb)->frags[i];
1451 off = frag->page_offset;
1452 len = frag->size;
1453 while (len > 0) {
1454 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
1455 data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
1456 KM_SKB_DATA_SOFTIRQ);
1457 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
1458 kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
1459 off += clen;
1460 len -= clen;
1461 }
1462 }
1463 return crc;
1464} 1370}
1465 1371
1466/** 1372/**
@@ -1483,7 +1389,7 @@ int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
1483 unsigned int tlen; /* trailer length */ 1389 unsigned int tlen; /* trailer length */
1484 unsigned int elen; /* eth header, may include vlan */ 1390 unsigned int elen; /* eth header, may include vlan */
1485 struct fcoe_port *port = lport_priv(lport); 1391 struct fcoe_port *port = lport_priv(lport);
1486 struct fcoe_interface *fcoe = port->fcoe; 1392 struct fcoe_interface *fcoe = port->priv;
1487 u8 sof, eof; 1393 u8 sof, eof;
1488 struct fcoe_hdr *hp; 1394 struct fcoe_hdr *hp;
1489 1395
@@ -1524,7 +1430,7 @@ int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
1524 /* copy port crc and eof to the skb buff */ 1430 /* copy port crc and eof to the skb buff */
1525 if (skb_is_nonlinear(skb)) { 1431 if (skb_is_nonlinear(skb)) {
1526 skb_frag_t *frag; 1432 skb_frag_t *frag;
1527 if (fcoe_get_paged_crc_eof(skb, tlen)) { 1433 if (fcoe_alloc_paged_crc_eof(skb, tlen)) {
1528 kfree_skb(skb); 1434 kfree_skb(skb);
1529 return -ENOMEM; 1435 return -ENOMEM;
1530 } 1436 }
@@ -1604,6 +1510,56 @@ static void fcoe_percpu_flush_done(struct sk_buff *skb)
1604} 1510}
1605 1511
1606/** 1512/**
1513 * fcoe_filter_frames() - filter out bad fcoe frames, i.e. bad CRC
1514 * @lport: The local port the frame was received on
1515 * @fp: The received frame
1516 *
1517 * Return: 0 on passing filtering checks
1518 */
1519static inline int fcoe_filter_frames(struct fc_lport *lport,
1520 struct fc_frame *fp)
1521{
1522 struct fcoe_interface *fcoe;
1523 struct fc_frame_header *fh;
1524 struct sk_buff *skb = (struct sk_buff *)fp;
1525 struct fcoe_dev_stats *stats;
1526
1527 /*
1528 * We only check CRC if no offload is available and if it is
1529 * it's solicited data, in which case, the FCP layer would
1530 * check it during the copy.
1531 */
1532 if (lport->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
1533 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1534 else
1535 fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1536
1537 fh = (struct fc_frame_header *) skb_transport_header(skb);
1538 fh = fc_frame_header_get(fp);
1539 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && fh->fh_type == FC_TYPE_FCP)
1540 return 0;
1541
1542 fcoe = ((struct fcoe_port *)lport_priv(lport))->priv;
1543 if (is_fip_mode(&fcoe->ctlr) && fc_frame_payload_op(fp) == ELS_LOGO &&
1544 ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
1545 FCOE_DBG("fcoe: dropping FCoE lport LOGO in fip mode\n");
1546 return -EINVAL;
1547 }
1548
1549 if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED) ||
1550 le32_to_cpu(fr_crc(fp)) == ~crc32(~0, skb->data, skb->len)) {
1551 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1552 return 0;
1553 }
1554
1555 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
1556 stats->InvalidCRCCount++;
1557 if (stats->InvalidCRCCount < 5)
1558 printk(KERN_WARNING "fcoe: dropping frame with CRC error\n");
1559 return -EINVAL;
1560}
1561
1562/**
1607 * fcoe_recv_frame() - process a single received frame 1563 * fcoe_recv_frame() - process a single received frame
1608 * @skb: frame to process 1564 * @skb: frame to process
1609 */ 1565 */
@@ -1613,7 +1569,6 @@ static void fcoe_recv_frame(struct sk_buff *skb)
1613 struct fc_lport *lport; 1569 struct fc_lport *lport;
1614 struct fcoe_rcv_info *fr; 1570 struct fcoe_rcv_info *fr;
1615 struct fcoe_dev_stats *stats; 1571 struct fcoe_dev_stats *stats;
1616 struct fc_frame_header *fh;
1617 struct fcoe_crc_eof crc_eof; 1572 struct fcoe_crc_eof crc_eof;
1618 struct fc_frame *fp; 1573 struct fc_frame *fp;
1619 struct fcoe_port *port; 1574 struct fcoe_port *port;
@@ -1644,7 +1599,6 @@ static void fcoe_recv_frame(struct sk_buff *skb)
1644 * was done in fcoe_rcv already. 1599 * was done in fcoe_rcv already.
1645 */ 1600 */
1646 hp = (struct fcoe_hdr *) skb_network_header(skb); 1601 hp = (struct fcoe_hdr *) skb_network_header(skb);
1647 fh = (struct fc_frame_header *) skb_transport_header(skb);
1648 1602
1649 stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1603 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
1650 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { 1604 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
@@ -1677,35 +1631,11 @@ static void fcoe_recv_frame(struct sk_buff *skb)
1677 if (pskb_trim(skb, fr_len)) 1631 if (pskb_trim(skb, fr_len))
1678 goto drop; 1632 goto drop;
1679 1633
1680 /* 1634 if (!fcoe_filter_frames(lport, fp)) {
1681 * We only check CRC if no offload is available and if it is 1635 put_cpu();
1682 * it's solicited data, in which case, the FCP layer would 1636 fc_exch_recv(lport, fp);
1683 * check it during the copy. 1637 return;
1684 */
1685 if (lport->crc_offload &&
1686 skb->ip_summed == CHECKSUM_UNNECESSARY)
1687 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1688 else
1689 fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1690
1691 fh = fc_frame_header_get(fp);
1692 if ((fh->fh_r_ctl != FC_RCTL_DD_SOL_DATA ||
1693 fh->fh_type != FC_TYPE_FCP) &&
1694 (fr_flags(fp) & FCPHF_CRC_UNCHECKED)) {
1695 if (le32_to_cpu(fr_crc(fp)) !=
1696 ~crc32(~0, skb->data, fr_len)) {
1697 if (stats->InvalidCRCCount < 5)
1698 printk(KERN_WARNING "fcoe: dropping "
1699 "frame with CRC error\n");
1700 stats->InvalidCRCCount++;
1701 goto drop;
1702 }
1703 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1704 } 1638 }
1705 put_cpu();
1706 fc_exch_recv(lport, fp);
1707 return;
1708
1709drop: 1639drop:
1710 stats->ErrorFrames++; 1640 stats->ErrorFrames++;
1711 put_cpu(); 1641 put_cpu();
@@ -1744,64 +1674,6 @@ int fcoe_percpu_receive_thread(void *arg)
1744} 1674}
1745 1675
1746/** 1676/**
1747 * fcoe_check_wait_queue() - Attempt to clear the transmit backlog
1748 * @lport: The local port whose backlog is to be cleared
1749 *
1750 * This empties the wait_queue, dequeues the head of the wait_queue queue
1751 * and calls fcoe_start_io() for each packet. If all skb have been
1752 * transmitted it returns the qlen. If an error occurs it restores
1753 * wait_queue (to try again later) and returns -1.
1754 *
1755 * The wait_queue is used when the skb transmit fails. The failed skb
1756 * will go in the wait_queue which will be emptied by the timer function or
1757 * by the next skb transmit.
1758 */
1759static void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb)
1760{
1761 struct fcoe_port *port = lport_priv(lport);
1762 int rc;
1763
1764 spin_lock_bh(&port->fcoe_pending_queue.lock);
1765
1766 if (skb)
1767 __skb_queue_tail(&port->fcoe_pending_queue, skb);
1768
1769 if (port->fcoe_pending_queue_active)
1770 goto out;
1771 port->fcoe_pending_queue_active = 1;
1772
1773 while (port->fcoe_pending_queue.qlen) {
1774 /* keep qlen > 0 until fcoe_start_io succeeds */
1775 port->fcoe_pending_queue.qlen++;
1776 skb = __skb_dequeue(&port->fcoe_pending_queue);
1777
1778 spin_unlock_bh(&port->fcoe_pending_queue.lock);
1779 rc = fcoe_start_io(skb);
1780 spin_lock_bh(&port->fcoe_pending_queue.lock);
1781
1782 if (rc) {
1783 __skb_queue_head(&port->fcoe_pending_queue, skb);
1784 /* undo temporary increment above */
1785 port->fcoe_pending_queue.qlen--;
1786 break;
1787 }
1788 /* undo temporary increment above */
1789 port->fcoe_pending_queue.qlen--;
1790 }
1791
1792 if (port->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
1793 lport->qfull = 0;
1794 if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer))
1795 mod_timer(&port->timer, jiffies + 2);
1796 port->fcoe_pending_queue_active = 0;
1797out:
1798 if (port->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
1799 lport->qfull = 1;
1800 spin_unlock_bh(&port->fcoe_pending_queue.lock);
1801 return;
1802}
1803
1804/**
1805 * fcoe_dev_setup() - Setup the link change notification interface 1677 * fcoe_dev_setup() - Setup the link change notification interface
1806 */ 1678 */
1807static void fcoe_dev_setup(void) 1679static void fcoe_dev_setup(void)
@@ -1872,7 +1744,7 @@ static int fcoe_device_notification(struct notifier_block *notifier,
1872 list_del(&fcoe->list); 1744 list_del(&fcoe->list);
1873 port = lport_priv(fcoe->ctlr.lp); 1745 port = lport_priv(fcoe->ctlr.lp);
1874 fcoe_interface_cleanup(fcoe); 1746 fcoe_interface_cleanup(fcoe);
1875 schedule_work(&port->destroy_work); 1747 queue_work(fcoe_wq, &port->destroy_work);
1876 goto out; 1748 goto out;
1877 break; 1749 break;
1878 case NETDEV_FEAT_CHANGE: 1750 case NETDEV_FEAT_CHANGE:
@@ -1898,39 +1770,16 @@ out:
1898} 1770}
1899 1771
1900/** 1772/**
1901 * fcoe_if_to_netdev() - Parse a name buffer to get a net device
1902 * @buffer: The name of the net device
1903 *
1904 * Returns: NULL or a ptr to net_device
1905 */
1906static struct net_device *fcoe_if_to_netdev(const char *buffer)
1907{
1908 char *cp;
1909 char ifname[IFNAMSIZ + 2];
1910
1911 if (buffer) {
1912 strlcpy(ifname, buffer, IFNAMSIZ);
1913 cp = ifname + strlen(ifname);
1914 while (--cp >= ifname && *cp == '\n')
1915 *cp = '\0';
1916 return dev_get_by_name(&init_net, ifname);
1917 }
1918 return NULL;
1919}
1920
1921/**
1922 * fcoe_disable() - Disables a FCoE interface 1773 * fcoe_disable() - Disables a FCoE interface
1923 * @buffer: The name of the Ethernet interface to be disabled 1774 * @netdev : The net_device object the Ethernet interface to create on
1924 * @kp: The associated kernel parameter
1925 * 1775 *
1926 * Called from sysfs. 1776 * Called from fcoe transport.
1927 * 1777 *
1928 * Returns: 0 for success 1778 * Returns: 0 for success
1929 */ 1779 */
1930static int fcoe_disable(const char *buffer, struct kernel_param *kp) 1780static int fcoe_disable(struct net_device *netdev)
1931{ 1781{
1932 struct fcoe_interface *fcoe; 1782 struct fcoe_interface *fcoe;
1933 struct net_device *netdev;
1934 int rc = 0; 1783 int rc = 0;
1935 1784
1936 mutex_lock(&fcoe_config_mutex); 1785 mutex_lock(&fcoe_config_mutex);
@@ -1946,16 +1795,9 @@ static int fcoe_disable(const char *buffer, struct kernel_param *kp)
1946 } 1795 }
1947#endif 1796#endif
1948 1797
1949 netdev = fcoe_if_to_netdev(buffer);
1950 if (!netdev) {
1951 rc = -ENODEV;
1952 goto out_nodev;
1953 }
1954
1955 if (!rtnl_trylock()) { 1798 if (!rtnl_trylock()) {
1956 dev_put(netdev);
1957 mutex_unlock(&fcoe_config_mutex); 1799 mutex_unlock(&fcoe_config_mutex);
1958 return restart_syscall(); 1800 return -ERESTARTSYS;
1959 } 1801 }
1960 1802
1961 fcoe = fcoe_hostlist_lookup_port(netdev); 1803 fcoe = fcoe_hostlist_lookup_port(netdev);
@@ -1967,7 +1809,6 @@ static int fcoe_disable(const char *buffer, struct kernel_param *kp)
1967 } else 1809 } else
1968 rc = -ENODEV; 1810 rc = -ENODEV;
1969 1811
1970 dev_put(netdev);
1971out_nodev: 1812out_nodev:
1972 mutex_unlock(&fcoe_config_mutex); 1813 mutex_unlock(&fcoe_config_mutex);
1973 return rc; 1814 return rc;
@@ -1975,17 +1816,15 @@ out_nodev:
1975 1816
1976/** 1817/**
1977 * fcoe_enable() - Enables a FCoE interface 1818 * fcoe_enable() - Enables a FCoE interface
1978 * @buffer: The name of the Ethernet interface to be enabled 1819 * @netdev : The net_device object the Ethernet interface to create on
1979 * @kp: The associated kernel parameter
1980 * 1820 *
1981 * Called from sysfs. 1821 * Called from fcoe transport.
1982 * 1822 *
1983 * Returns: 0 for success 1823 * Returns: 0 for success
1984 */ 1824 */
1985static int fcoe_enable(const char *buffer, struct kernel_param *kp) 1825static int fcoe_enable(struct net_device *netdev)
1986{ 1826{
1987 struct fcoe_interface *fcoe; 1827 struct fcoe_interface *fcoe;
1988 struct net_device *netdev;
1989 int rc = 0; 1828 int rc = 0;
1990 1829
1991 mutex_lock(&fcoe_config_mutex); 1830 mutex_lock(&fcoe_config_mutex);
@@ -2000,17 +1839,9 @@ static int fcoe_enable(const char *buffer, struct kernel_param *kp)
2000 goto out_nodev; 1839 goto out_nodev;
2001 } 1840 }
2002#endif 1841#endif
2003
2004 netdev = fcoe_if_to_netdev(buffer);
2005 if (!netdev) {
2006 rc = -ENODEV;
2007 goto out_nodev;
2008 }
2009
2010 if (!rtnl_trylock()) { 1842 if (!rtnl_trylock()) {
2011 dev_put(netdev);
2012 mutex_unlock(&fcoe_config_mutex); 1843 mutex_unlock(&fcoe_config_mutex);
2013 return restart_syscall(); 1844 return -ERESTARTSYS;
2014 } 1845 }
2015 1846
2016 fcoe = fcoe_hostlist_lookup_port(netdev); 1847 fcoe = fcoe_hostlist_lookup_port(netdev);
@@ -2021,7 +1852,6 @@ static int fcoe_enable(const char *buffer, struct kernel_param *kp)
2021 else if (!fcoe_link_ok(fcoe->ctlr.lp)) 1852 else if (!fcoe_link_ok(fcoe->ctlr.lp))
2022 fcoe_ctlr_link_up(&fcoe->ctlr); 1853 fcoe_ctlr_link_up(&fcoe->ctlr);
2023 1854
2024 dev_put(netdev);
2025out_nodev: 1855out_nodev:
2026 mutex_unlock(&fcoe_config_mutex); 1856 mutex_unlock(&fcoe_config_mutex);
2027 return rc; 1857 return rc;
@@ -2029,17 +1859,15 @@ out_nodev:
2029 1859
2030/** 1860/**
2031 * fcoe_destroy() - Destroy a FCoE interface 1861 * fcoe_destroy() - Destroy a FCoE interface
2032 * @buffer: The name of the Ethernet interface to be destroyed 1862 * @netdev : The net_device object the Ethernet interface to create on
2033 * @kp: The associated kernel parameter
2034 * 1863 *
2035 * Called from sysfs. 1864 * Called from fcoe transport
2036 * 1865 *
2037 * Returns: 0 for success 1866 * Returns: 0 for success
2038 */ 1867 */
2039static int fcoe_destroy(const char *buffer, struct kernel_param *kp) 1868static int fcoe_destroy(struct net_device *netdev)
2040{ 1869{
2041 struct fcoe_interface *fcoe; 1870 struct fcoe_interface *fcoe;
2042 struct net_device *netdev;
2043 int rc = 0; 1871 int rc = 0;
2044 1872
2045 mutex_lock(&fcoe_config_mutex); 1873 mutex_lock(&fcoe_config_mutex);
@@ -2054,32 +1882,21 @@ static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
2054 goto out_nodev; 1882 goto out_nodev;
2055 } 1883 }
2056#endif 1884#endif
2057
2058 netdev = fcoe_if_to_netdev(buffer);
2059 if (!netdev) {
2060 rc = -ENODEV;
2061 goto out_nodev;
2062 }
2063
2064 if (!rtnl_trylock()) { 1885 if (!rtnl_trylock()) {
2065 dev_put(netdev);
2066 mutex_unlock(&fcoe_config_mutex); 1886 mutex_unlock(&fcoe_config_mutex);
2067 return restart_syscall(); 1887 return -ERESTARTSYS;
2068 } 1888 }
2069 1889
2070 fcoe = fcoe_hostlist_lookup_port(netdev); 1890 fcoe = fcoe_hostlist_lookup_port(netdev);
2071 if (!fcoe) { 1891 if (!fcoe) {
2072 rtnl_unlock(); 1892 rtnl_unlock();
2073 rc = -ENODEV; 1893 rc = -ENODEV;
2074 goto out_putdev; 1894 goto out_nodev;
2075 } 1895 }
2076 fcoe_interface_cleanup(fcoe); 1896 fcoe_interface_cleanup(fcoe);
2077 list_del(&fcoe->list); 1897 list_del(&fcoe->list);
2078 /* RTNL mutex is dropped by fcoe_if_destroy */ 1898 /* RTNL mutex is dropped by fcoe_if_destroy */
2079 fcoe_if_destroy(fcoe->ctlr.lp); 1899 fcoe_if_destroy(fcoe->ctlr.lp);
2080
2081out_putdev:
2082 dev_put(netdev);
2083out_nodev: 1900out_nodev:
2084 mutex_unlock(&fcoe_config_mutex); 1901 mutex_unlock(&fcoe_config_mutex);
2085 return rc; 1902 return rc;
@@ -2102,27 +1919,39 @@ static void fcoe_destroy_work(struct work_struct *work)
2102} 1919}
2103 1920
2104/** 1921/**
1922 * fcoe_match() - Check if the FCoE is supported on the given netdevice
1923 * @netdev : The net_device object the Ethernet interface to create on
1924 *
1925 * Called from fcoe transport.
1926 *
1927 * Returns: always returns true as this is the default FCoE transport,
1928 * i.e., support all netdevs.
1929 */
1930static bool fcoe_match(struct net_device *netdev)
1931{
1932 return true;
1933}
1934
1935/**
2105 * fcoe_create() - Create a fcoe interface 1936 * fcoe_create() - Create a fcoe interface
2106 * @buffer: The name of the Ethernet interface to create on 1937 * @netdev : The net_device object the Ethernet interface to create on
2107 * @kp: The associated kernel param 1938 * @fip_mode: The FIP mode for this creation
2108 * 1939 *
2109 * Called from sysfs. 1940 * Called from fcoe transport
2110 * 1941 *
2111 * Returns: 0 for success 1942 * Returns: 0 for success
2112 */ 1943 */
2113static int fcoe_create(const char *buffer, struct kernel_param *kp) 1944static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode)
2114{ 1945{
2115 enum fip_state fip_mode = (enum fip_state)(long)kp->arg;
2116 int rc; 1946 int rc;
2117 struct fcoe_interface *fcoe; 1947 struct fcoe_interface *fcoe;
2118 struct fc_lport *lport; 1948 struct fc_lport *lport;
2119 struct net_device *netdev;
2120 1949
2121 mutex_lock(&fcoe_config_mutex); 1950 mutex_lock(&fcoe_config_mutex);
2122 1951
2123 if (!rtnl_trylock()) { 1952 if (!rtnl_trylock()) {
2124 mutex_unlock(&fcoe_config_mutex); 1953 mutex_unlock(&fcoe_config_mutex);
2125 return restart_syscall(); 1954 return -ERESTARTSYS;
2126 } 1955 }
2127 1956
2128#ifdef CONFIG_FCOE_MODULE 1957#ifdef CONFIG_FCOE_MODULE
@@ -2133,31 +1962,20 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
2133 */ 1962 */
2134 if (THIS_MODULE->state != MODULE_STATE_LIVE) { 1963 if (THIS_MODULE->state != MODULE_STATE_LIVE) {
2135 rc = -ENODEV; 1964 rc = -ENODEV;
2136 goto out_nomod;
2137 }
2138#endif
2139
2140 if (!try_module_get(THIS_MODULE)) {
2141 rc = -EINVAL;
2142 goto out_nomod;
2143 }
2144
2145 netdev = fcoe_if_to_netdev(buffer);
2146 if (!netdev) {
2147 rc = -ENODEV;
2148 goto out_nodev; 1965 goto out_nodev;
2149 } 1966 }
1967#endif
2150 1968
2151 /* look for existing lport */ 1969 /* look for existing lport */
2152 if (fcoe_hostlist_lookup(netdev)) { 1970 if (fcoe_hostlist_lookup(netdev)) {
2153 rc = -EEXIST; 1971 rc = -EEXIST;
2154 goto out_putdev; 1972 goto out_nodev;
2155 } 1973 }
2156 1974
2157 fcoe = fcoe_interface_create(netdev, fip_mode); 1975 fcoe = fcoe_interface_create(netdev, fip_mode);
2158 if (!fcoe) { 1976 if (IS_ERR(fcoe)) {
2159 rc = -ENOMEM; 1977 rc = PTR_ERR(fcoe);
2160 goto out_putdev; 1978 goto out_nodev;
2161 } 1979 }
2162 1980
2163 lport = fcoe_if_create(fcoe, &netdev->dev, 0); 1981 lport = fcoe_if_create(fcoe, &netdev->dev, 0);
@@ -2186,18 +2004,13 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
2186 * should be holding a reference taken in fcoe_if_create(). 2004 * should be holding a reference taken in fcoe_if_create().
2187 */ 2005 */
2188 fcoe_interface_put(fcoe); 2006 fcoe_interface_put(fcoe);
2189 dev_put(netdev);
2190 rtnl_unlock(); 2007 rtnl_unlock();
2191 mutex_unlock(&fcoe_config_mutex); 2008 mutex_unlock(&fcoe_config_mutex);
2192 2009
2193 return 0; 2010 return 0;
2194out_free: 2011out_free:
2195 fcoe_interface_put(fcoe); 2012 fcoe_interface_put(fcoe);
2196out_putdev:
2197 dev_put(netdev);
2198out_nodev: 2013out_nodev:
2199 module_put(THIS_MODULE);
2200out_nomod:
2201 rtnl_unlock(); 2014 rtnl_unlock();
2202 mutex_unlock(&fcoe_config_mutex); 2015 mutex_unlock(&fcoe_config_mutex);
2203 return rc; 2016 return rc;
@@ -2212,8 +2025,7 @@ out_nomod:
2212 */ 2025 */
2213int fcoe_link_speed_update(struct fc_lport *lport) 2026int fcoe_link_speed_update(struct fc_lport *lport)
2214{ 2027{
2215 struct fcoe_port *port = lport_priv(lport); 2028 struct net_device *netdev = fcoe_netdev(lport);
2216 struct net_device *netdev = port->fcoe->netdev;
2217 struct ethtool_cmd ecmd = { ETHTOOL_GSET }; 2029 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
2218 2030
2219 if (!dev_ethtool_get_settings(netdev, &ecmd)) { 2031 if (!dev_ethtool_get_settings(netdev, &ecmd)) {
@@ -2244,8 +2056,7 @@ int fcoe_link_speed_update(struct fc_lport *lport)
2244 */ 2056 */
2245int fcoe_link_ok(struct fc_lport *lport) 2057int fcoe_link_ok(struct fc_lport *lport)
2246{ 2058{
2247 struct fcoe_port *port = lport_priv(lport); 2059 struct net_device *netdev = fcoe_netdev(lport);
2248 struct net_device *netdev = port->fcoe->netdev;
2249 2060
2250 if (netif_oper_up(netdev)) 2061 if (netif_oper_up(netdev))
2251 return 0; 2062 return 0;
@@ -2309,24 +2120,6 @@ void fcoe_percpu_clean(struct fc_lport *lport)
2309} 2120}
2310 2121
2311/** 2122/**
2312 * fcoe_clean_pending_queue() - Dequeue a skb and free it
2313 * @lport: The local port to dequeue a skb on
2314 */
2315void fcoe_clean_pending_queue(struct fc_lport *lport)
2316{
2317 struct fcoe_port *port = lport_priv(lport);
2318 struct sk_buff *skb;
2319
2320 spin_lock_bh(&port->fcoe_pending_queue.lock);
2321 while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) {
2322 spin_unlock_bh(&port->fcoe_pending_queue.lock);
2323 kfree_skb(skb);
2324 spin_lock_bh(&port->fcoe_pending_queue.lock);
2325 }
2326 spin_unlock_bh(&port->fcoe_pending_queue.lock);
2327}
2328
2329/**
2330 * fcoe_reset() - Reset a local port 2123 * fcoe_reset() - Reset a local port
2331 * @shost: The SCSI host associated with the local port to be reset 2124 * @shost: The SCSI host associated with the local port to be reset
2332 * 2125 *
@@ -2335,7 +2128,13 @@ void fcoe_clean_pending_queue(struct fc_lport *lport)
2335int fcoe_reset(struct Scsi_Host *shost) 2128int fcoe_reset(struct Scsi_Host *shost)
2336{ 2129{
2337 struct fc_lport *lport = shost_priv(shost); 2130 struct fc_lport *lport = shost_priv(shost);
2338 fc_lport_reset(lport); 2131 struct fcoe_port *port = lport_priv(lport);
2132 struct fcoe_interface *fcoe = port->priv;
2133
2134 fcoe_ctlr_link_down(&fcoe->ctlr);
2135 fcoe_clean_pending_queue(fcoe->ctlr.lp);
2136 if (!fcoe_link_ok(fcoe->ctlr.lp))
2137 fcoe_ctlr_link_up(&fcoe->ctlr);
2339 return 0; 2138 return 0;
2340} 2139}
2341 2140
@@ -2393,12 +2192,24 @@ static int fcoe_hostlist_add(const struct fc_lport *lport)
2393 fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport)); 2192 fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
2394 if (!fcoe) { 2193 if (!fcoe) {
2395 port = lport_priv(lport); 2194 port = lport_priv(lport);
2396 fcoe = port->fcoe; 2195 fcoe = port->priv;
2397 list_add_tail(&fcoe->list, &fcoe_hostlist); 2196 list_add_tail(&fcoe->list, &fcoe_hostlist);
2398 } 2197 }
2399 return 0; 2198 return 0;
2400} 2199}
2401 2200
2201
2202static struct fcoe_transport fcoe_sw_transport = {
2203 .name = {FCOE_TRANSPORT_DEFAULT},
2204 .attached = false,
2205 .list = LIST_HEAD_INIT(fcoe_sw_transport.list),
2206 .match = fcoe_match,
2207 .create = fcoe_create,
2208 .destroy = fcoe_destroy,
2209 .enable = fcoe_enable,
2210 .disable = fcoe_disable,
2211};
2212
2402/** 2213/**
2403 * fcoe_init() - Initialize fcoe.ko 2214 * fcoe_init() - Initialize fcoe.ko
2404 * 2215 *
@@ -2410,6 +2221,18 @@ static int __init fcoe_init(void)
2410 unsigned int cpu; 2221 unsigned int cpu;
2411 int rc = 0; 2222 int rc = 0;
2412 2223
2224 fcoe_wq = alloc_workqueue("fcoe", 0, 0);
2225 if (!fcoe_wq)
2226 return -ENOMEM;
2227
2228 /* register as a fcoe transport */
2229 rc = fcoe_transport_attach(&fcoe_sw_transport);
2230 if (rc) {
2231 printk(KERN_ERR "failed to register an fcoe transport, check "
2232 "if libfcoe is loaded\n");
2233 return rc;
2234 }
2235
2413 mutex_lock(&fcoe_config_mutex); 2236 mutex_lock(&fcoe_config_mutex);
2414 2237
2415 for_each_possible_cpu(cpu) { 2238 for_each_possible_cpu(cpu) {
@@ -2440,6 +2263,7 @@ out_free:
2440 fcoe_percpu_thread_destroy(cpu); 2263 fcoe_percpu_thread_destroy(cpu);
2441 } 2264 }
2442 mutex_unlock(&fcoe_config_mutex); 2265 mutex_unlock(&fcoe_config_mutex);
2266 destroy_workqueue(fcoe_wq);
2443 return rc; 2267 return rc;
2444} 2268}
2445module_init(fcoe_init); 2269module_init(fcoe_init);
@@ -2465,7 +2289,7 @@ static void __exit fcoe_exit(void)
2465 list_del(&fcoe->list); 2289 list_del(&fcoe->list);
2466 port = lport_priv(fcoe->ctlr.lp); 2290 port = lport_priv(fcoe->ctlr.lp);
2467 fcoe_interface_cleanup(fcoe); 2291 fcoe_interface_cleanup(fcoe);
2468 schedule_work(&port->destroy_work); 2292 queue_work(fcoe_wq, &port->destroy_work);
2469 } 2293 }
2470 rtnl_unlock(); 2294 rtnl_unlock();
2471 2295
@@ -2476,16 +2300,21 @@ static void __exit fcoe_exit(void)
2476 2300
2477 mutex_unlock(&fcoe_config_mutex); 2301 mutex_unlock(&fcoe_config_mutex);
2478 2302
2479 /* flush any asyncronous interface destroys, 2303 /*
2480 * this should happen after the netdev notifier is unregistered */ 2304 * destroy_work's may be chained but destroy_workqueue()
2481 flush_scheduled_work(); 2305 * can take care of them. Just kill the fcoe_wq.
2482 /* That will flush out all the N_Ports on the hostlist, but now we 2306 */
2483 * may have NPIV VN_Ports scheduled for destruction */ 2307 destroy_workqueue(fcoe_wq);
2484 flush_scheduled_work();
2485 2308
2486 /* detach from scsi transport 2309 /*
2487 * must happen after all destroys are done, therefor after the flush */ 2310 * Detaching from the scsi transport must happen after all
2311 * destroys are done on the fcoe_wq. destroy_workqueue will
2312 * enusre the fcoe_wq is flushed.
2313 */
2488 fcoe_if_exit(); 2314 fcoe_if_exit();
2315
2316 /* detach from fcoe transport */
2317 fcoe_transport_detach(&fcoe_sw_transport);
2489} 2318}
2490module_exit(fcoe_exit); 2319module_exit(fcoe_exit);
2491 2320
@@ -2557,7 +2386,7 @@ static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did,
2557 void *arg, u32 timeout) 2386 void *arg, u32 timeout)
2558{ 2387{
2559 struct fcoe_port *port = lport_priv(lport); 2388 struct fcoe_port *port = lport_priv(lport);
2560 struct fcoe_interface *fcoe = port->fcoe; 2389 struct fcoe_interface *fcoe = port->priv;
2561 struct fcoe_ctlr *fip = &fcoe->ctlr; 2390 struct fcoe_ctlr *fip = &fcoe->ctlr;
2562 struct fc_frame_header *fh = fc_frame_header_get(fp); 2391 struct fc_frame_header *fh = fc_frame_header_get(fp);
2563 2392
@@ -2590,7 +2419,7 @@ static int fcoe_vport_create(struct fc_vport *vport, bool disabled)
2590 struct Scsi_Host *shost = vport_to_shost(vport); 2419 struct Scsi_Host *shost = vport_to_shost(vport);
2591 struct fc_lport *n_port = shost_priv(shost); 2420 struct fc_lport *n_port = shost_priv(shost);
2592 struct fcoe_port *port = lport_priv(n_port); 2421 struct fcoe_port *port = lport_priv(n_port);
2593 struct fcoe_interface *fcoe = port->fcoe; 2422 struct fcoe_interface *fcoe = port->priv;
2594 struct net_device *netdev = fcoe->netdev; 2423 struct net_device *netdev = fcoe->netdev;
2595 struct fc_lport *vn_port; 2424 struct fc_lport *vn_port;
2596 2425
@@ -2630,7 +2459,7 @@ static int fcoe_vport_destroy(struct fc_vport *vport)
2630 mutex_lock(&n_port->lp_mutex); 2459 mutex_lock(&n_port->lp_mutex);
2631 list_del(&vn_port->list); 2460 list_del(&vn_port->list);
2632 mutex_unlock(&n_port->lp_mutex); 2461 mutex_unlock(&n_port->lp_mutex);
2633 schedule_work(&port->destroy_work); 2462 queue_work(fcoe_wq, &port->destroy_work);
2634 return 0; 2463 return 0;
2635} 2464}
2636 2465
@@ -2734,7 +2563,7 @@ static void fcoe_set_port_id(struct fc_lport *lport,
2734 u32 port_id, struct fc_frame *fp) 2563 u32 port_id, struct fc_frame *fp)
2735{ 2564{
2736 struct fcoe_port *port = lport_priv(lport); 2565 struct fcoe_port *port = lport_priv(lport);
2737 struct fcoe_interface *fcoe = port->fcoe; 2566 struct fcoe_interface *fcoe = port->priv;
2738 2567
2739 if (fp && fc_frame_payload_op(fp) == ELS_FLOGI) 2568 if (fp && fc_frame_payload_op(fp) == ELS_FLOGI)
2740 fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp); 2569 fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp);
diff --git a/drivers/scsi/fcoe/fcoe.h b/drivers/scsi/fcoe/fcoe.h
index c69b2c56c2d1..408a6fd78fb4 100644
--- a/drivers/scsi/fcoe/fcoe.h
+++ b/drivers/scsi/fcoe/fcoe.h
@@ -24,7 +24,7 @@
24#include <linux/kthread.h> 24#include <linux/kthread.h>
25 25
26#define FCOE_MAX_QUEUE_DEPTH 256 26#define FCOE_MAX_QUEUE_DEPTH 256
27#define FCOE_LOW_QUEUE_DEPTH 32 27#define FCOE_MIN_QUEUE_DEPTH 32
28 28
29#define FCOE_WORD_TO_BYTE 4 29#define FCOE_WORD_TO_BYTE 4
30 30
@@ -40,12 +40,6 @@
40#define FCOE_MIN_XID 0x0000 /* the min xid supported by fcoe_sw */ 40#define FCOE_MIN_XID 0x0000 /* the min xid supported by fcoe_sw */
41#define FCOE_MAX_XID 0x0FFF /* the max xid supported by fcoe_sw */ 41#define FCOE_MAX_XID 0x0FFF /* the max xid supported by fcoe_sw */
42 42
43/*
44 * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload)
45 * + 4 (FC CRC) + 4 (FCoE trailer) = 2158 bytes
46 */
47#define FCOE_MTU 2158
48
49unsigned int fcoe_debug_logging; 43unsigned int fcoe_debug_logging;
50module_param_named(debug_logging, fcoe_debug_logging, int, S_IRUGO|S_IWUSR); 44module_param_named(debug_logging, fcoe_debug_logging, int, S_IRUGO|S_IWUSR);
51MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels"); 45MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
@@ -71,21 +65,6 @@ do { \
71 netdev->name, ##args);) 65 netdev->name, ##args);)
72 66
73/** 67/**
74 * struct fcoe_percpu_s - The per-CPU context for FCoE receive threads
75 * @thread: The thread context
76 * @fcoe_rx_list: The queue of pending packets to process
77 * @page: The memory page for calculating frame trailer CRCs
78 * @crc_eof_offset: The offset into the CRC page pointing to available
79 * memory for a new trailer
80 */
81struct fcoe_percpu_s {
82 struct task_struct *thread;
83 struct sk_buff_head fcoe_rx_list;
84 struct page *crc_eof_page;
85 int crc_eof_offset;
86};
87
88/**
89 * struct fcoe_interface - A FCoE interface 68 * struct fcoe_interface - A FCoE interface
90 * @list: Handle for a list of FCoE interfaces 69 * @list: Handle for a list of FCoE interfaces
91 * @netdev: The associated net device 70 * @netdev: The associated net device
@@ -108,30 +87,6 @@ struct fcoe_interface {
108 struct kref kref; 87 struct kref kref;
109}; 88};
110 89
111/**
112 * struct fcoe_port - The FCoE private structure
113 * @fcoe: The associated fcoe interface
114 * @lport: The associated local port
115 * @fcoe_pending_queue: The pending Rx queue of skbs
116 * @fcoe_pending_queue_active: Indicates if the pending queue is active
117 * @timer: The queue timer
118 * @destroy_work: Handle for work context
119 * (to prevent RTNL deadlocks)
120 * @data_srt_addr: Source address for data
121 *
122 * An instance of this structure is to be allocated along with the
123 * Scsi_Host and libfc fc_lport structures.
124 */
125struct fcoe_port {
126 struct fcoe_interface *fcoe;
127 struct fc_lport *lport;
128 struct sk_buff_head fcoe_pending_queue;
129 u8 fcoe_pending_queue_active;
130 struct timer_list timer;
131 struct work_struct destroy_work;
132 u8 data_src_addr[ETH_ALEN];
133};
134
135#define fcoe_from_ctlr(fip) container_of(fip, struct fcoe_interface, ctlr) 90#define fcoe_from_ctlr(fip) container_of(fip, struct fcoe_interface, ctlr)
136 91
137/** 92/**
@@ -140,7 +95,8 @@ struct fcoe_port {
140 */ 95 */
141static inline struct net_device *fcoe_netdev(const struct fc_lport *lport) 96static inline struct net_device *fcoe_netdev(const struct fc_lport *lport)
142{ 97{
143 return ((struct fcoe_port *)lport_priv(lport))->fcoe->netdev; 98 return ((struct fcoe_interface *)
99 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
144} 100}
145 101
146#endif /* _FCOE_H_ */ 102#endif /* _FCOE_H_ */
diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/fcoe_ctlr.c
index 625c6be25396..c93f007e702f 100644
--- a/drivers/scsi/fcoe/libfcoe.c
+++ b/drivers/scsi/fcoe/fcoe_ctlr.c
@@ -44,9 +44,7 @@
44#include <scsi/libfc.h> 44#include <scsi/libfc.h>
45#include <scsi/libfcoe.h> 45#include <scsi/libfcoe.h>
46 46
47MODULE_AUTHOR("Open-FCoE.org"); 47#include "libfcoe.h"
48MODULE_DESCRIPTION("FIP discovery protocol support for FCoE HBAs");
49MODULE_LICENSE("GPL v2");
50 48
51#define FCOE_CTLR_MIN_FKA 500 /* min keep alive (mS) */ 49#define FCOE_CTLR_MIN_FKA 500 /* min keep alive (mS) */
52#define FCOE_CTLR_DEF_FKA FIP_DEF_FKA /* default keep alive (mS) */ 50#define FCOE_CTLR_DEF_FKA FIP_DEF_FKA /* default keep alive (mS) */
@@ -66,31 +64,7 @@ static u8 fcoe_all_enode[ETH_ALEN] = FIP_ALL_ENODE_MACS;
66static u8 fcoe_all_vn2vn[ETH_ALEN] = FIP_ALL_VN2VN_MACS; 64static u8 fcoe_all_vn2vn[ETH_ALEN] = FIP_ALL_VN2VN_MACS;
67static u8 fcoe_all_p2p[ETH_ALEN] = FIP_ALL_P2P_MACS; 65static u8 fcoe_all_p2p[ETH_ALEN] = FIP_ALL_P2P_MACS;
68 66
69unsigned int libfcoe_debug_logging; 67static const char * const fcoe_ctlr_states[] = {
70module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR);
71MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
72
73#define LIBFCOE_LOGGING 0x01 /* General logging, not categorized */
74#define LIBFCOE_FIP_LOGGING 0x02 /* FIP logging */
75
76#define LIBFCOE_CHECK_LOGGING(LEVEL, CMD) \
77do { \
78 if (unlikely(libfcoe_debug_logging & LEVEL)) \
79 do { \
80 CMD; \
81 } while (0); \
82} while (0)
83
84#define LIBFCOE_DBG(fmt, args...) \
85 LIBFCOE_CHECK_LOGGING(LIBFCOE_LOGGING, \
86 printk(KERN_INFO "libfcoe: " fmt, ##args);)
87
88#define LIBFCOE_FIP_DBG(fip, fmt, args...) \
89 LIBFCOE_CHECK_LOGGING(LIBFCOE_FIP_LOGGING, \
90 printk(KERN_INFO "host%d: fip: " fmt, \
91 (fip)->lp->host->host_no, ##args);)
92
93static const char *fcoe_ctlr_states[] = {
94 [FIP_ST_DISABLED] = "DISABLED", 68 [FIP_ST_DISABLED] = "DISABLED",
95 [FIP_ST_LINK_WAIT] = "LINK_WAIT", 69 [FIP_ST_LINK_WAIT] = "LINK_WAIT",
96 [FIP_ST_AUTO] = "AUTO", 70 [FIP_ST_AUTO] = "AUTO",
@@ -308,8 +282,8 @@ static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf)
308 struct fip_mac_desc mac; 282 struct fip_mac_desc mac;
309 struct fip_wwn_desc wwnn; 283 struct fip_wwn_desc wwnn;
310 struct fip_size_desc size; 284 struct fip_size_desc size;
311 } __attribute__((packed)) desc; 285 } __packed desc;
312 } __attribute__((packed)) *sol; 286 } __packed * sol;
313 u32 fcoe_size; 287 u32 fcoe_size;
314 288
315 skb = dev_alloc_skb(sizeof(*sol)); 289 skb = dev_alloc_skb(sizeof(*sol));
@@ -456,7 +430,7 @@ static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip,
456 struct ethhdr eth; 430 struct ethhdr eth;
457 struct fip_header fip; 431 struct fip_header fip;
458 struct fip_mac_desc mac; 432 struct fip_mac_desc mac;
459 } __attribute__((packed)) *kal; 433 } __packed * kal;
460 struct fip_vn_desc *vn; 434 struct fip_vn_desc *vn;
461 u32 len; 435 u32 len;
462 struct fc_lport *lp; 436 struct fc_lport *lp;
@@ -527,7 +501,7 @@ static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip, struct fc_lport *lport,
527 struct ethhdr eth; 501 struct ethhdr eth;
528 struct fip_header fip; 502 struct fip_header fip;
529 struct fip_encaps encaps; 503 struct fip_encaps encaps;
530 } __attribute__((packed)) *cap; 504 } __packed * cap;
531 struct fc_frame_header *fh; 505 struct fc_frame_header *fh;
532 struct fip_mac_desc *mac; 506 struct fip_mac_desc *mac;
533 struct fcoe_fcf *fcf; 507 struct fcoe_fcf *fcf;
@@ -1819,7 +1793,7 @@ static void fcoe_ctlr_vn_send(struct fcoe_ctlr *fip,
1819 struct fip_mac_desc mac; 1793 struct fip_mac_desc mac;
1820 struct fip_wwn_desc wwnn; 1794 struct fip_wwn_desc wwnn;
1821 struct fip_vn_desc vn; 1795 struct fip_vn_desc vn;
1822 } __attribute__((packed)) *frame; 1796 } __packed * frame;
1823 struct fip_fc4_feat *ff; 1797 struct fip_fc4_feat *ff;
1824 struct fip_size_desc *size; 1798 struct fip_size_desc *size;
1825 u32 fcp_feat; 1799 u32 fcp_feat;
diff --git a/drivers/scsi/fcoe/fcoe_transport.c b/drivers/scsi/fcoe/fcoe_transport.c
new file mode 100644
index 000000000000..258684101bfd
--- /dev/null
+++ b/drivers/scsi/fcoe/fcoe_transport.c
@@ -0,0 +1,770 @@
1/*
2 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Maintained at www.Open-FCoE.org
18 */
19
20#include <linux/types.h>
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/list.h>
24#include <linux/netdevice.h>
25#include <linux/errno.h>
26#include <linux/crc32.h>
27#include <scsi/libfcoe.h>
28
29#include "libfcoe.h"
30
31MODULE_AUTHOR("Open-FCoE.org");
32MODULE_DESCRIPTION("FIP discovery protocol and FCoE transport for FCoE HBAs");
33MODULE_LICENSE("GPL v2");
34
35static int fcoe_transport_create(const char *, struct kernel_param *);
36static int fcoe_transport_destroy(const char *, struct kernel_param *);
37static int fcoe_transport_show(char *buffer, const struct kernel_param *kp);
38static struct fcoe_transport *fcoe_transport_lookup(struct net_device *device);
39static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *device);
40static int fcoe_transport_enable(const char *, struct kernel_param *);
41static int fcoe_transport_disable(const char *, struct kernel_param *);
42static int libfcoe_device_notification(struct notifier_block *notifier,
43 ulong event, void *ptr);
44
45static LIST_HEAD(fcoe_transports);
46static DEFINE_MUTEX(ft_mutex);
47static LIST_HEAD(fcoe_netdevs);
48static DEFINE_MUTEX(fn_mutex);
49
50unsigned int libfcoe_debug_logging;
51module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR);
52MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
53
54module_param_call(show, NULL, fcoe_transport_show, NULL, S_IRUSR);
55__MODULE_PARM_TYPE(show, "string");
56MODULE_PARM_DESC(show, " Show attached FCoE transports");
57
58module_param_call(create, fcoe_transport_create, NULL,
59 (void *)FIP_MODE_FABRIC, S_IWUSR);
60__MODULE_PARM_TYPE(create, "string");
61MODULE_PARM_DESC(create, " Creates fcoe instance on a ethernet interface");
62
63module_param_call(create_vn2vn, fcoe_transport_create, NULL,
64 (void *)FIP_MODE_VN2VN, S_IWUSR);
65__MODULE_PARM_TYPE(create_vn2vn, "string");
66MODULE_PARM_DESC(create_vn2vn, " Creates a VN_node to VN_node FCoE instance "
67 "on an Ethernet interface");
68
69module_param_call(destroy, fcoe_transport_destroy, NULL, NULL, S_IWUSR);
70__MODULE_PARM_TYPE(destroy, "string");
71MODULE_PARM_DESC(destroy, " Destroys fcoe instance on a ethernet interface");
72
73module_param_call(enable, fcoe_transport_enable, NULL, NULL, S_IWUSR);
74__MODULE_PARM_TYPE(enable, "string");
75MODULE_PARM_DESC(enable, " Enables fcoe on a ethernet interface.");
76
77module_param_call(disable, fcoe_transport_disable, NULL, NULL, S_IWUSR);
78__MODULE_PARM_TYPE(disable, "string");
79MODULE_PARM_DESC(disable, " Disables fcoe on a ethernet interface.");
80
81/* notification function for packets from net device */
82static struct notifier_block libfcoe_notifier = {
83 .notifier_call = libfcoe_device_notification,
84};
85
86/**
87 * fcoe_fc_crc() - Calculates the CRC for a given frame
88 * @fp: The frame to be checksumed
89 *
90 * This uses crc32() routine to calculate the CRC for a frame
91 *
92 * Return: The 32 bit CRC value
93 */
94u32 fcoe_fc_crc(struct fc_frame *fp)
95{
96 struct sk_buff *skb = fp_skb(fp);
97 struct skb_frag_struct *frag;
98 unsigned char *data;
99 unsigned long off, len, clen;
100 u32 crc;
101 unsigned i;
102
103 crc = crc32(~0, skb->data, skb_headlen(skb));
104
105 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
106 frag = &skb_shinfo(skb)->frags[i];
107 off = frag->page_offset;
108 len = frag->size;
109 while (len > 0) {
110 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
111 data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
112 KM_SKB_DATA_SOFTIRQ);
113 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
114 kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
115 off += clen;
116 len -= clen;
117 }
118 }
119 return crc;
120}
121EXPORT_SYMBOL_GPL(fcoe_fc_crc);
122
123/**
124 * fcoe_start_io() - Start FCoE I/O
125 * @skb: The packet to be transmitted
126 *
127 * This routine is called from the net device to start transmitting
128 * FCoE packets.
129 *
130 * Returns: 0 for success
131 */
132int fcoe_start_io(struct sk_buff *skb)
133{
134 struct sk_buff *nskb;
135 int rc;
136
137 nskb = skb_clone(skb, GFP_ATOMIC);
138 if (!nskb)
139 return -ENOMEM;
140 rc = dev_queue_xmit(nskb);
141 if (rc != 0)
142 return rc;
143 kfree_skb(skb);
144 return 0;
145}
146EXPORT_SYMBOL_GPL(fcoe_start_io);
147
148
149/**
150 * fcoe_clean_pending_queue() - Dequeue a skb and free it
151 * @lport: The local port to dequeue a skb on
152 */
153void fcoe_clean_pending_queue(struct fc_lport *lport)
154{
155 struct fcoe_port *port = lport_priv(lport);
156 struct sk_buff *skb;
157
158 spin_lock_bh(&port->fcoe_pending_queue.lock);
159 while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) {
160 spin_unlock_bh(&port->fcoe_pending_queue.lock);
161 kfree_skb(skb);
162 spin_lock_bh(&port->fcoe_pending_queue.lock);
163 }
164 spin_unlock_bh(&port->fcoe_pending_queue.lock);
165}
166EXPORT_SYMBOL_GPL(fcoe_clean_pending_queue);
167
168/**
169 * fcoe_check_wait_queue() - Attempt to clear the transmit backlog
170 * @lport: The local port whose backlog is to be cleared
171 *
172 * This empties the wait_queue, dequeues the head of the wait_queue queue
173 * and calls fcoe_start_io() for each packet. If all skb have been
174 * transmitted it returns the qlen. If an error occurs it restores
175 * wait_queue (to try again later) and returns -1.
176 *
177 * The wait_queue is used when the skb transmit fails. The failed skb
178 * will go in the wait_queue which will be emptied by the timer function or
179 * by the next skb transmit.
180 */
181void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb)
182{
183 struct fcoe_port *port = lport_priv(lport);
184 int rc;
185
186 spin_lock_bh(&port->fcoe_pending_queue.lock);
187
188 if (skb)
189 __skb_queue_tail(&port->fcoe_pending_queue, skb);
190
191 if (port->fcoe_pending_queue_active)
192 goto out;
193 port->fcoe_pending_queue_active = 1;
194
195 while (port->fcoe_pending_queue.qlen) {
196 /* keep qlen > 0 until fcoe_start_io succeeds */
197 port->fcoe_pending_queue.qlen++;
198 skb = __skb_dequeue(&port->fcoe_pending_queue);
199
200 spin_unlock_bh(&port->fcoe_pending_queue.lock);
201 rc = fcoe_start_io(skb);
202 spin_lock_bh(&port->fcoe_pending_queue.lock);
203
204 if (rc) {
205 __skb_queue_head(&port->fcoe_pending_queue, skb);
206 /* undo temporary increment above */
207 port->fcoe_pending_queue.qlen--;
208 break;
209 }
210 /* undo temporary increment above */
211 port->fcoe_pending_queue.qlen--;
212 }
213
214 if (port->fcoe_pending_queue.qlen < port->min_queue_depth)
215 lport->qfull = 0;
216 if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer))
217 mod_timer(&port->timer, jiffies + 2);
218 port->fcoe_pending_queue_active = 0;
219out:
220 if (port->fcoe_pending_queue.qlen > port->max_queue_depth)
221 lport->qfull = 1;
222 spin_unlock_bh(&port->fcoe_pending_queue.lock);
223}
224EXPORT_SYMBOL_GPL(fcoe_check_wait_queue);
225
226/**
227 * fcoe_queue_timer() - The fcoe queue timer
228 * @lport: The local port
229 *
230 * Calls fcoe_check_wait_queue on timeout
231 */
232void fcoe_queue_timer(ulong lport)
233{
234 fcoe_check_wait_queue((struct fc_lport *)lport, NULL);
235}
236EXPORT_SYMBOL_GPL(fcoe_queue_timer);
237
238/**
239 * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC
240 * @skb: The packet to be transmitted
241 * @tlen: The total length of the trailer
242 * @fps: The fcoe context
243 *
244 * This routine allocates a page for frame trailers. The page is re-used if
245 * there is enough room left on it for the current trailer. If there isn't
246 * enough buffer left a new page is allocated for the trailer. Reference to
247 * the page from this function as well as the skbs using the page fragments
248 * ensure that the page is freed at the appropriate time.
249 *
250 * Returns: 0 for success
251 */
252int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
253 struct fcoe_percpu_s *fps)
254{
255 struct page *page;
256
257 page = fps->crc_eof_page;
258 if (!page) {
259 page = alloc_page(GFP_ATOMIC);
260 if (!page)
261 return -ENOMEM;
262
263 fps->crc_eof_page = page;
264 fps->crc_eof_offset = 0;
265 }
266
267 get_page(page);
268 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
269 fps->crc_eof_offset, tlen);
270 skb->len += tlen;
271 skb->data_len += tlen;
272 skb->truesize += tlen;
273 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
274
275 if (fps->crc_eof_offset >= PAGE_SIZE) {
276 fps->crc_eof_page = NULL;
277 fps->crc_eof_offset = 0;
278 put_page(page);
279 }
280
281 return 0;
282}
283EXPORT_SYMBOL_GPL(fcoe_get_paged_crc_eof);
284
285/**
286 * fcoe_transport_lookup - find an fcoe transport that matches a netdev
287 * @netdev: The netdev to look for from all attached transports
288 *
289 * Returns : ptr to the fcoe transport that supports this netdev or NULL
290 * if not found.
291 *
292 * The ft_mutex should be held when this is called
293 */
294static struct fcoe_transport *fcoe_transport_lookup(struct net_device *netdev)
295{
296 struct fcoe_transport *ft = NULL;
297
298 list_for_each_entry(ft, &fcoe_transports, list)
299 if (ft->match && ft->match(netdev))
300 return ft;
301 return NULL;
302}
303
304/**
305 * fcoe_transport_attach - Attaches an FCoE transport
306 * @ft: The fcoe transport to be attached
307 *
308 * Returns : 0 for success
309 */
310int fcoe_transport_attach(struct fcoe_transport *ft)
311{
312 int rc = 0;
313
314 mutex_lock(&ft_mutex);
315 if (ft->attached) {
316 LIBFCOE_TRANSPORT_DBG("transport %s already attached\n",
317 ft->name);
318 rc = -EEXIST;
319 goto out_attach;
320 }
321
322 /* Add default transport to the tail */
323 if (strcmp(ft->name, FCOE_TRANSPORT_DEFAULT))
324 list_add(&ft->list, &fcoe_transports);
325 else
326 list_add_tail(&ft->list, &fcoe_transports);
327
328 ft->attached = true;
329 LIBFCOE_TRANSPORT_DBG("attaching transport %s\n", ft->name);
330
331out_attach:
332 mutex_unlock(&ft_mutex);
333 return rc;
334}
335EXPORT_SYMBOL(fcoe_transport_attach);
336
337/**
338 * fcoe_transport_attach - Detaches an FCoE transport
339 * @ft: The fcoe transport to be attached
340 *
341 * Returns : 0 for success
342 */
343int fcoe_transport_detach(struct fcoe_transport *ft)
344{
345 int rc = 0;
346
347 mutex_lock(&ft_mutex);
348 if (!ft->attached) {
349 LIBFCOE_TRANSPORT_DBG("transport %s already detached\n",
350 ft->name);
351 rc = -ENODEV;
352 goto out_attach;
353 }
354
355 list_del(&ft->list);
356 ft->attached = false;
357 LIBFCOE_TRANSPORT_DBG("detaching transport %s\n", ft->name);
358
359out_attach:
360 mutex_unlock(&ft_mutex);
361 return rc;
362
363}
364EXPORT_SYMBOL(fcoe_transport_detach);
365
366static int fcoe_transport_show(char *buffer, const struct kernel_param *kp)
367{
368 int i, j;
369 struct fcoe_transport *ft = NULL;
370
371 i = j = sprintf(buffer, "Attached FCoE transports:");
372 mutex_lock(&ft_mutex);
373 list_for_each_entry(ft, &fcoe_transports, list) {
374 i += snprintf(&buffer[i], IFNAMSIZ, "%s ", ft->name);
375 if (i >= PAGE_SIZE)
376 break;
377 }
378 mutex_unlock(&ft_mutex);
379 if (i == j)
380 i += snprintf(&buffer[i], IFNAMSIZ, "none");
381 return i;
382}
383
384static int __init fcoe_transport_init(void)
385{
386 register_netdevice_notifier(&libfcoe_notifier);
387 return 0;
388}
389
390static int __exit fcoe_transport_exit(void)
391{
392 struct fcoe_transport *ft;
393
394 unregister_netdevice_notifier(&libfcoe_notifier);
395 mutex_lock(&ft_mutex);
396 list_for_each_entry(ft, &fcoe_transports, list)
397 printk(KERN_ERR "FCoE transport %s is still attached!\n",
398 ft->name);
399 mutex_unlock(&ft_mutex);
400 return 0;
401}
402
403
404static int fcoe_add_netdev_mapping(struct net_device *netdev,
405 struct fcoe_transport *ft)
406{
407 struct fcoe_netdev_mapping *nm;
408
409 nm = kmalloc(sizeof(*nm), GFP_KERNEL);
410 if (!nm) {
411 printk(KERN_ERR "Unable to allocate netdev_mapping");
412 return -ENOMEM;
413 }
414
415 nm->netdev = netdev;
416 nm->ft = ft;
417
418 mutex_lock(&fn_mutex);
419 list_add(&nm->list, &fcoe_netdevs);
420 mutex_unlock(&fn_mutex);
421 return 0;
422}
423
424
425static void fcoe_del_netdev_mapping(struct net_device *netdev)
426{
427 struct fcoe_netdev_mapping *nm = NULL, *tmp;
428
429 mutex_lock(&fn_mutex);
430 list_for_each_entry_safe(nm, tmp, &fcoe_netdevs, list) {
431 if (nm->netdev == netdev) {
432 list_del(&nm->list);
433 kfree(nm);
434 mutex_unlock(&fn_mutex);
435 return;
436 }
437 }
438 mutex_unlock(&fn_mutex);
439}
440
441
442/**
443 * fcoe_netdev_map_lookup - find the fcoe transport that matches the netdev on which
444 * it was created
445 *
446 * Returns : ptr to the fcoe transport that supports this netdev or NULL
447 * if not found.
448 *
449 * The ft_mutex should be held when this is called
450 */
451static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *netdev)
452{
453 struct fcoe_transport *ft = NULL;
454 struct fcoe_netdev_mapping *nm;
455
456 mutex_lock(&fn_mutex);
457 list_for_each_entry(nm, &fcoe_netdevs, list) {
458 if (netdev == nm->netdev) {
459 ft = nm->ft;
460 mutex_unlock(&fn_mutex);
461 return ft;
462 }
463 }
464
465 mutex_unlock(&fn_mutex);
466 return NULL;
467}
468
469/**
470 * fcoe_if_to_netdev() - Parse a name buffer to get a net device
471 * @buffer: The name of the net device
472 *
473 * Returns: NULL or a ptr to net_device
474 */
475static struct net_device *fcoe_if_to_netdev(const char *buffer)
476{
477 char *cp;
478 char ifname[IFNAMSIZ + 2];
479
480 if (buffer) {
481 strlcpy(ifname, buffer, IFNAMSIZ);
482 cp = ifname + strlen(ifname);
483 while (--cp >= ifname && *cp == '\n')
484 *cp = '\0';
485 return dev_get_by_name(&init_net, ifname);
486 }
487 return NULL;
488}
489
490/**
491 * libfcoe_device_notification() - Handler for net device events
492 * @notifier: The context of the notification
493 * @event: The type of event
494 * @ptr: The net device that the event was on
495 *
496 * This function is called by the Ethernet driver in case of link change event.
497 *
498 * Returns: 0 for success
499 */
500static int libfcoe_device_notification(struct notifier_block *notifier,
501 ulong event, void *ptr)
502{
503 struct net_device *netdev = ptr;
504
505 switch (event) {
506 case NETDEV_UNREGISTER:
507 printk(KERN_ERR "libfcoe_device_notification: NETDEV_UNREGISTER %s\n",
508 netdev->name);
509 fcoe_del_netdev_mapping(netdev);
510 break;
511 }
512 return NOTIFY_OK;
513}
514
515
516/**
517 * fcoe_transport_create() - Create a fcoe interface
518 * @buffer: The name of the Ethernet interface to create on
519 * @kp: The associated kernel param
520 *
521 * Called from sysfs. This holds the ft_mutex while calling the
522 * registered fcoe transport's create function.
523 *
524 * Returns: 0 for success
525 */
526static int fcoe_transport_create(const char *buffer, struct kernel_param *kp)
527{
528 int rc = -ENODEV;
529 struct net_device *netdev = NULL;
530 struct fcoe_transport *ft = NULL;
531 enum fip_state fip_mode = (enum fip_state)(long)kp->arg;
532
533 if (!mutex_trylock(&ft_mutex))
534 return restart_syscall();
535
536#ifdef CONFIG_LIBFCOE_MODULE
537 /*
538 * Make sure the module has been initialized, and is not about to be
539 * removed. Module parameter sysfs files are writable before the
540 * module_init function is called and after module_exit.
541 */
542 if (THIS_MODULE->state != MODULE_STATE_LIVE)
543 goto out_nodev;
544#endif
545
546 netdev = fcoe_if_to_netdev(buffer);
547 if (!netdev) {
548 LIBFCOE_TRANSPORT_DBG("Invalid device %s.\n", buffer);
549 goto out_nodev;
550 }
551
552 ft = fcoe_netdev_map_lookup(netdev);
553 if (ft) {
554 LIBFCOE_TRANSPORT_DBG("transport %s already has existing "
555 "FCoE instance on %s.\n",
556 ft->name, netdev->name);
557 rc = -EEXIST;
558 goto out_putdev;
559 }
560
561 ft = fcoe_transport_lookup(netdev);
562 if (!ft) {
563 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
564 netdev->name);
565 goto out_putdev;
566 }
567
568 rc = fcoe_add_netdev_mapping(netdev, ft);
569 if (rc) {
570 LIBFCOE_TRANSPORT_DBG("failed to add new netdev mapping "
571 "for FCoE transport %s for %s.\n",
572 ft->name, netdev->name);
573 goto out_putdev;
574 }
575
576 /* pass to transport create */
577 rc = ft->create ? ft->create(netdev, fip_mode) : -ENODEV;
578 if (rc)
579 fcoe_del_netdev_mapping(netdev);
580
581 LIBFCOE_TRANSPORT_DBG("transport %s %s to create fcoe on %s.\n",
582 ft->name, (rc) ? "failed" : "succeeded",
583 netdev->name);
584
585out_putdev:
586 dev_put(netdev);
587out_nodev:
588 mutex_unlock(&ft_mutex);
589 if (rc == -ERESTARTSYS)
590 return restart_syscall();
591 else
592 return rc;
593}
594
595/**
596 * fcoe_transport_destroy() - Destroy a FCoE interface
597 * @buffer: The name of the Ethernet interface to be destroyed
598 * @kp: The associated kernel parameter
599 *
600 * Called from sysfs. This holds the ft_mutex while calling the
601 * registered fcoe transport's destroy function.
602 *
603 * Returns: 0 for success
604 */
605static int fcoe_transport_destroy(const char *buffer, struct kernel_param *kp)
606{
607 int rc = -ENODEV;
608 struct net_device *netdev = NULL;
609 struct fcoe_transport *ft = NULL;
610
611 if (!mutex_trylock(&ft_mutex))
612 return restart_syscall();
613
614#ifdef CONFIG_LIBFCOE_MODULE
615 /*
616 * Make sure the module has been initialized, and is not about to be
617 * removed. Module parameter sysfs files are writable before the
618 * module_init function is called and after module_exit.
619 */
620 if (THIS_MODULE->state != MODULE_STATE_LIVE)
621 goto out_nodev;
622#endif
623
624 netdev = fcoe_if_to_netdev(buffer);
625 if (!netdev) {
626 LIBFCOE_TRANSPORT_DBG("invalid device %s.\n", buffer);
627 goto out_nodev;
628 }
629
630 ft = fcoe_netdev_map_lookup(netdev);
631 if (!ft) {
632 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
633 netdev->name);
634 goto out_putdev;
635 }
636
637 /* pass to transport destroy */
638 rc = ft->destroy ? ft->destroy(netdev) : -ENODEV;
639 fcoe_del_netdev_mapping(netdev);
640 LIBFCOE_TRANSPORT_DBG("transport %s %s to destroy fcoe on %s.\n",
641 ft->name, (rc) ? "failed" : "succeeded",
642 netdev->name);
643
644out_putdev:
645 dev_put(netdev);
646out_nodev:
647 mutex_unlock(&ft_mutex);
648
649 if (rc == -ERESTARTSYS)
650 return restart_syscall();
651 else
652 return rc;
653}
654
655/**
656 * fcoe_transport_disable() - Disables a FCoE interface
657 * @buffer: The name of the Ethernet interface to be disabled
658 * @kp: The associated kernel parameter
659 *
660 * Called from sysfs.
661 *
662 * Returns: 0 for success
663 */
664static int fcoe_transport_disable(const char *buffer, struct kernel_param *kp)
665{
666 int rc = -ENODEV;
667 struct net_device *netdev = NULL;
668 struct fcoe_transport *ft = NULL;
669
670 if (!mutex_trylock(&ft_mutex))
671 return restart_syscall();
672
673#ifdef CONFIG_LIBFCOE_MODULE
674 /*
675 * Make sure the module has been initialized, and is not about to be
676 * removed. Module parameter sysfs files are writable before the
677 * module_init function is called and after module_exit.
678 */
679 if (THIS_MODULE->state != MODULE_STATE_LIVE)
680 goto out_nodev;
681#endif
682
683 netdev = fcoe_if_to_netdev(buffer);
684 if (!netdev)
685 goto out_nodev;
686
687 ft = fcoe_netdev_map_lookup(netdev);
688 if (!ft)
689 goto out_putdev;
690
691 rc = ft->disable ? ft->disable(netdev) : -ENODEV;
692
693out_putdev:
694 dev_put(netdev);
695out_nodev:
696 mutex_unlock(&ft_mutex);
697
698 if (rc == -ERESTARTSYS)
699 return restart_syscall();
700 else
701 return rc;
702}
703
704/**
705 * fcoe_transport_enable() - Enables a FCoE interface
706 * @buffer: The name of the Ethernet interface to be enabled
707 * @kp: The associated kernel parameter
708 *
709 * Called from sysfs.
710 *
711 * Returns: 0 for success
712 */
713static int fcoe_transport_enable(const char *buffer, struct kernel_param *kp)
714{
715 int rc = -ENODEV;
716 struct net_device *netdev = NULL;
717 struct fcoe_transport *ft = NULL;
718
719 if (!mutex_trylock(&ft_mutex))
720 return restart_syscall();
721
722#ifdef CONFIG_LIBFCOE_MODULE
723 /*
724 * Make sure the module has been initialized, and is not about to be
725 * removed. Module parameter sysfs files are writable before the
726 * module_init function is called and after module_exit.
727 */
728 if (THIS_MODULE->state != MODULE_STATE_LIVE)
729 goto out_nodev;
730#endif
731
732 netdev = fcoe_if_to_netdev(buffer);
733 if (!netdev)
734 goto out_nodev;
735
736 ft = fcoe_netdev_map_lookup(netdev);
737 if (!ft)
738 goto out_putdev;
739
740 rc = ft->enable ? ft->enable(netdev) : -ENODEV;
741
742out_putdev:
743 dev_put(netdev);
744out_nodev:
745 mutex_unlock(&ft_mutex);
746 if (rc == -ERESTARTSYS)
747 return restart_syscall();
748 else
749 return rc;
750}
751
752/**
753 * libfcoe_init() - Initialization routine for libfcoe.ko
754 */
755static int __init libfcoe_init(void)
756{
757 fcoe_transport_init();
758
759 return 0;
760}
761module_init(libfcoe_init);
762
763/**
764 * libfcoe_exit() - Tear down libfcoe.ko
765 */
766static void __exit libfcoe_exit(void)
767{
768 fcoe_transport_exit();
769}
770module_exit(libfcoe_exit);
diff --git a/drivers/scsi/fcoe/libfcoe.h b/drivers/scsi/fcoe/libfcoe.h
new file mode 100644
index 000000000000..6af5fc3a17d8
--- /dev/null
+++ b/drivers/scsi/fcoe/libfcoe.h
@@ -0,0 +1,31 @@
1#ifndef _FCOE_LIBFCOE_H_
2#define _FCOE_LIBFCOE_H_
3
4extern unsigned int libfcoe_debug_logging;
5#define LIBFCOE_LOGGING 0x01 /* General logging, not categorized */
6#define LIBFCOE_FIP_LOGGING 0x02 /* FIP logging */
7#define LIBFCOE_TRANSPORT_LOGGING 0x04 /* FCoE transport logging */
8
9#define LIBFCOE_CHECK_LOGGING(LEVEL, CMD) \
10do { \
11 if (unlikely(libfcoe_debug_logging & LEVEL)) \
12 do { \
13 CMD; \
14 } while (0); \
15} while (0)
16
17#define LIBFCOE_DBG(fmt, args...) \
18 LIBFCOE_CHECK_LOGGING(LIBFCOE_LOGGING, \
19 printk(KERN_INFO "libfcoe: " fmt, ##args);)
20
21#define LIBFCOE_FIP_DBG(fip, fmt, args...) \
22 LIBFCOE_CHECK_LOGGING(LIBFCOE_FIP_LOGGING, \
23 printk(KERN_INFO "host%d: fip: " fmt, \
24 (fip)->lp->host->host_no, ##args);)
25
26#define LIBFCOE_TRANSPORT_DBG(fmt, args...) \
27 LIBFCOE_CHECK_LOGGING(LIBFCOE_TRANSPORT_LOGGING, \
28 printk(KERN_INFO "%s: " fmt, \
29 __func__, ##args);)
30
31#endif /* _FCOE_LIBFCOE_H_ */
diff --git a/drivers/scsi/fnic/fnic.h b/drivers/scsi/fnic/fnic.h
index 92f185081e62..671cde9d4060 100644
--- a/drivers/scsi/fnic/fnic.h
+++ b/drivers/scsi/fnic/fnic.h
@@ -37,7 +37,7 @@
37 37
38#define DRV_NAME "fnic" 38#define DRV_NAME "fnic"
39#define DRV_DESCRIPTION "Cisco FCoE HBA Driver" 39#define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
40#define DRV_VERSION "1.4.0.145" 40#define DRV_VERSION "1.5.0.1"
41#define PFX DRV_NAME ": " 41#define PFX DRV_NAME ": "
42#define DFX DRV_NAME "%d: " 42#define DFX DRV_NAME "%d: "
43 43
diff --git a/drivers/scsi/fnic/vnic_dev.c b/drivers/scsi/fnic/vnic_dev.c
index db710148d156..b576be734e2e 100644
--- a/drivers/scsi/fnic/vnic_dev.c
+++ b/drivers/scsi/fnic/vnic_dev.c
@@ -654,7 +654,7 @@ void vnic_dev_unregister(struct vnic_dev *vdev)
654 vdev->linkstatus_pa); 654 vdev->linkstatus_pa);
655 if (vdev->stats) 655 if (vdev->stats)
656 pci_free_consistent(vdev->pdev, 656 pci_free_consistent(vdev->pdev,
657 sizeof(struct vnic_dev), 657 sizeof(struct vnic_stats),
658 vdev->stats, vdev->stats_pa); 658 vdev->stats, vdev->stats_pa);
659 if (vdev->fw_info) 659 if (vdev->fw_info)
660 pci_free_consistent(vdev->pdev, 660 pci_free_consistent(vdev->pdev,
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 12deffccb8da..415ad4fb50d4 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -74,6 +74,10 @@ static int hpsa_allow_any;
74module_param(hpsa_allow_any, int, S_IRUGO|S_IWUSR); 74module_param(hpsa_allow_any, int, S_IRUGO|S_IWUSR);
75MODULE_PARM_DESC(hpsa_allow_any, 75MODULE_PARM_DESC(hpsa_allow_any,
76 "Allow hpsa driver to access unknown HP Smart Array hardware"); 76 "Allow hpsa driver to access unknown HP Smart Array hardware");
77static int hpsa_simple_mode;
78module_param(hpsa_simple_mode, int, S_IRUGO|S_IWUSR);
79MODULE_PARM_DESC(hpsa_simple_mode,
80 "Use 'simple mode' rather than 'performant mode'");
77 81
78/* define the PCI info for the cards we can control */ 82/* define the PCI info for the cards we can control */
79static const struct pci_device_id hpsa_pci_device_id[] = { 83static const struct pci_device_id hpsa_pci_device_id[] = {
@@ -85,11 +89,13 @@ static const struct pci_device_id hpsa_pci_device_id[] = {
85 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324a}, 89 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324a},
86 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324b}, 90 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324b},
87 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3233}, 91 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3233},
88 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3250}, 92 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3350},
89 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3251}, 93 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3351},
90 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3252}, 94 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3352},
91 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3253}, 95 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3353},
92 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3254}, 96 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3354},
97 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3355},
98 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x3356},
93 {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 99 {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
94 PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0}, 100 PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0},
95 {0,} 101 {0,}
@@ -109,11 +115,13 @@ static struct board_type products[] = {
109 {0x3249103C, "Smart Array P812", &SA5_access}, 115 {0x3249103C, "Smart Array P812", &SA5_access},
110 {0x324a103C, "Smart Array P712m", &SA5_access}, 116 {0x324a103C, "Smart Array P712m", &SA5_access},
111 {0x324b103C, "Smart Array P711m", &SA5_access}, 117 {0x324b103C, "Smart Array P711m", &SA5_access},
112 {0x3250103C, "Smart Array", &SA5_access}, 118 {0x3350103C, "Smart Array", &SA5_access},
113 {0x3250113C, "Smart Array", &SA5_access}, 119 {0x3351103C, "Smart Array", &SA5_access},
114 {0x3250123C, "Smart Array", &SA5_access}, 120 {0x3352103C, "Smart Array", &SA5_access},
115 {0x3250133C, "Smart Array", &SA5_access}, 121 {0x3353103C, "Smart Array", &SA5_access},
116 {0x3250143C, "Smart Array", &SA5_access}, 122 {0x3354103C, "Smart Array", &SA5_access},
123 {0x3355103C, "Smart Array", &SA5_access},
124 {0x3356103C, "Smart Array", &SA5_access},
117 {0xFFFF103C, "Unknown Smart Array", &SA5_access}, 125 {0xFFFF103C, "Unknown Smart Array", &SA5_access},
118}; 126};
119 127
@@ -147,17 +155,7 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd);
147static int hpsa_slave_alloc(struct scsi_device *sdev); 155static int hpsa_slave_alloc(struct scsi_device *sdev);
148static void hpsa_slave_destroy(struct scsi_device *sdev); 156static void hpsa_slave_destroy(struct scsi_device *sdev);
149 157
150static ssize_t raid_level_show(struct device *dev,
151 struct device_attribute *attr, char *buf);
152static ssize_t lunid_show(struct device *dev,
153 struct device_attribute *attr, char *buf);
154static ssize_t unique_id_show(struct device *dev,
155 struct device_attribute *attr, char *buf);
156static ssize_t host_show_firmware_revision(struct device *dev,
157 struct device_attribute *attr, char *buf);
158static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno); 158static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno);
159static ssize_t host_store_rescan(struct device *dev,
160 struct device_attribute *attr, const char *buf, size_t count);
161static int check_for_unit_attention(struct ctlr_info *h, 159static int check_for_unit_attention(struct ctlr_info *h,
162 struct CommandList *c); 160 struct CommandList *c);
163static void check_ioctl_unit_attention(struct ctlr_info *h, 161static void check_ioctl_unit_attention(struct ctlr_info *h,
@@ -173,47 +171,10 @@ static int __devinit hpsa_find_cfg_addrs(struct pci_dev *pdev,
173static int __devinit hpsa_pci_find_memory_BAR(struct pci_dev *pdev, 171static int __devinit hpsa_pci_find_memory_BAR(struct pci_dev *pdev,
174 unsigned long *memory_bar); 172 unsigned long *memory_bar);
175static int __devinit hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id); 173static int __devinit hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id);
176 174static int __devinit hpsa_wait_for_board_state(struct pci_dev *pdev,
177static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL); 175 void __iomem *vaddr, int wait_for_ready);
178static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL); 176#define BOARD_NOT_READY 0
179static DEVICE_ATTR(unique_id, S_IRUGO, unique_id_show, NULL); 177#define BOARD_READY 1
180static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan);
181static DEVICE_ATTR(firmware_revision, S_IRUGO,
182 host_show_firmware_revision, NULL);
183
184static struct device_attribute *hpsa_sdev_attrs[] = {
185 &dev_attr_raid_level,
186 &dev_attr_lunid,
187 &dev_attr_unique_id,
188 NULL,
189};
190
191static struct device_attribute *hpsa_shost_attrs[] = {
192 &dev_attr_rescan,
193 &dev_attr_firmware_revision,
194 NULL,
195};
196
197static struct scsi_host_template hpsa_driver_template = {
198 .module = THIS_MODULE,
199 .name = "hpsa",
200 .proc_name = "hpsa",
201 .queuecommand = hpsa_scsi_queue_command,
202 .scan_start = hpsa_scan_start,
203 .scan_finished = hpsa_scan_finished,
204 .change_queue_depth = hpsa_change_queue_depth,
205 .this_id = -1,
206 .use_clustering = ENABLE_CLUSTERING,
207 .eh_device_reset_handler = hpsa_eh_device_reset_handler,
208 .ioctl = hpsa_ioctl,
209 .slave_alloc = hpsa_slave_alloc,
210 .slave_destroy = hpsa_slave_destroy,
211#ifdef CONFIG_COMPAT
212 .compat_ioctl = hpsa_compat_ioctl,
213#endif
214 .sdev_attrs = hpsa_sdev_attrs,
215 .shost_attrs = hpsa_shost_attrs,
216};
217 178
218static inline struct ctlr_info *sdev_to_hba(struct scsi_device *sdev) 179static inline struct ctlr_info *sdev_to_hba(struct scsi_device *sdev)
219{ 180{
@@ -291,67 +252,63 @@ static ssize_t host_show_firmware_revision(struct device *dev,
291 fwrev[0], fwrev[1], fwrev[2], fwrev[3]); 252 fwrev[0], fwrev[1], fwrev[2], fwrev[3]);
292} 253}
293 254
294/* Enqueuing and dequeuing functions for cmdlists. */ 255static ssize_t host_show_commands_outstanding(struct device *dev,
295static inline void addQ(struct hlist_head *list, struct CommandList *c) 256 struct device_attribute *attr, char *buf)
296{ 257{
297 hlist_add_head(&c->list, list); 258 struct Scsi_Host *shost = class_to_shost(dev);
259 struct ctlr_info *h = shost_to_hba(shost);
260
261 return snprintf(buf, 20, "%d\n", h->commands_outstanding);
298} 262}
299 263
300static inline u32 next_command(struct ctlr_info *h) 264static ssize_t host_show_transport_mode(struct device *dev,
265 struct device_attribute *attr, char *buf)
301{ 266{
302 u32 a; 267 struct ctlr_info *h;
303 268 struct Scsi_Host *shost = class_to_shost(dev);
304 if (unlikely(h->transMethod != CFGTBL_Trans_Performant))
305 return h->access.command_completed(h);
306 269
307 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) { 270 h = shost_to_hba(shost);
308 a = *(h->reply_pool_head); /* Next cmd in ring buffer */ 271 return snprintf(buf, 20, "%s\n",
309 (h->reply_pool_head)++; 272 h->transMethod & CFGTBL_Trans_Performant ?
310 h->commands_outstanding--; 273 "performant" : "simple");
311 } else {
312 a = FIFO_EMPTY;
313 }
314 /* Check for wraparound */
315 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
316 h->reply_pool_head = h->reply_pool;
317 h->reply_pool_wraparound ^= 1;
318 }
319 return a;
320} 274}
321 275
322/* set_performant_mode: Modify the tag for cciss performant 276/* List of controllers which cannot be reset on kexec with reset_devices */
323 * set bit 0 for pull model, bits 3-1 for block fetch 277static u32 unresettable_controller[] = {
324 * register number 278 0x324a103C, /* Smart Array P712m */
325 */ 279 0x324b103C, /* SmartArray P711m */
326static void set_performant_mode(struct ctlr_info *h, struct CommandList *c) 280 0x3223103C, /* Smart Array P800 */
327{ 281 0x3234103C, /* Smart Array P400 */
328 if (likely(h->transMethod == CFGTBL_Trans_Performant)) 282 0x3235103C, /* Smart Array P400i */
329 c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1); 283 0x3211103C, /* Smart Array E200i */
330} 284 0x3212103C, /* Smart Array E200 */
285 0x3213103C, /* Smart Array E200i */
286 0x3214103C, /* Smart Array E200i */
287 0x3215103C, /* Smart Array E200i */
288 0x3237103C, /* Smart Array E500 */
289 0x323D103C, /* Smart Array P700m */
290 0x409C0E11, /* Smart Array 6400 */
291 0x409D0E11, /* Smart Array 6400 EM */
292};
331 293
332static void enqueue_cmd_and_start_io(struct ctlr_info *h, 294static int ctlr_is_resettable(struct ctlr_info *h)
333 struct CommandList *c)
334{ 295{
335 unsigned long flags; 296 int i;
336 297
337 set_performant_mode(h, c); 298 for (i = 0; i < ARRAY_SIZE(unresettable_controller); i++)
338 spin_lock_irqsave(&h->lock, flags); 299 if (unresettable_controller[i] == h->board_id)
339 addQ(&h->reqQ, c); 300 return 0;
340 h->Qdepth++; 301 return 1;
341 start_io(h);
342 spin_unlock_irqrestore(&h->lock, flags);
343} 302}
344 303
345static inline void removeQ(struct CommandList *c) 304static ssize_t host_show_resettable(struct device *dev,
305 struct device_attribute *attr, char *buf)
346{ 306{
347 if (WARN_ON(hlist_unhashed(&c->list))) 307 struct ctlr_info *h;
348 return; 308 struct Scsi_Host *shost = class_to_shost(dev);
349 hlist_del_init(&c->list);
350}
351 309
352static inline int is_hba_lunid(unsigned char scsi3addr[]) 310 h = shost_to_hba(shost);
353{ 311 return snprintf(buf, 20, "%d\n", ctlr_is_resettable(h));
354 return memcmp(scsi3addr, RAID_CTLR_LUNID, 8) == 0;
355} 312}
356 313
357static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[]) 314static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[])
@@ -359,15 +316,6 @@ static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[])
359 return (scsi3addr[3] & 0xC0) == 0x40; 316 return (scsi3addr[3] & 0xC0) == 0x40;
360} 317}
361 318
362static inline int is_scsi_rev_5(struct ctlr_info *h)
363{
364 if (!h->hba_inquiry_data)
365 return 0;
366 if ((h->hba_inquiry_data[2] & 0x07) == 5)
367 return 1;
368 return 0;
369}
370
371static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", 319static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG",
372 "UNKNOWN" 320 "UNKNOWN"
373}; 321};
@@ -459,6 +407,129 @@ static ssize_t unique_id_show(struct device *dev,
459 sn[12], sn[13], sn[14], sn[15]); 407 sn[12], sn[13], sn[14], sn[15]);
460} 408}
461 409
410static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL);
411static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL);
412static DEVICE_ATTR(unique_id, S_IRUGO, unique_id_show, NULL);
413static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan);
414static DEVICE_ATTR(firmware_revision, S_IRUGO,
415 host_show_firmware_revision, NULL);
416static DEVICE_ATTR(commands_outstanding, S_IRUGO,
417 host_show_commands_outstanding, NULL);
418static DEVICE_ATTR(transport_mode, S_IRUGO,
419 host_show_transport_mode, NULL);
420static DEVICE_ATTR(resettable, S_IRUGO,
421 host_show_resettable, NULL);
422
423static struct device_attribute *hpsa_sdev_attrs[] = {
424 &dev_attr_raid_level,
425 &dev_attr_lunid,
426 &dev_attr_unique_id,
427 NULL,
428};
429
430static struct device_attribute *hpsa_shost_attrs[] = {
431 &dev_attr_rescan,
432 &dev_attr_firmware_revision,
433 &dev_attr_commands_outstanding,
434 &dev_attr_transport_mode,
435 &dev_attr_resettable,
436 NULL,
437};
438
439static struct scsi_host_template hpsa_driver_template = {
440 .module = THIS_MODULE,
441 .name = "hpsa",
442 .proc_name = "hpsa",
443 .queuecommand = hpsa_scsi_queue_command,
444 .scan_start = hpsa_scan_start,
445 .scan_finished = hpsa_scan_finished,
446 .change_queue_depth = hpsa_change_queue_depth,
447 .this_id = -1,
448 .use_clustering = ENABLE_CLUSTERING,
449 .eh_device_reset_handler = hpsa_eh_device_reset_handler,
450 .ioctl = hpsa_ioctl,
451 .slave_alloc = hpsa_slave_alloc,
452 .slave_destroy = hpsa_slave_destroy,
453#ifdef CONFIG_COMPAT
454 .compat_ioctl = hpsa_compat_ioctl,
455#endif
456 .sdev_attrs = hpsa_sdev_attrs,
457 .shost_attrs = hpsa_shost_attrs,
458};
459
460
461/* Enqueuing and dequeuing functions for cmdlists. */
462static inline void addQ(struct list_head *list, struct CommandList *c)
463{
464 list_add_tail(&c->list, list);
465}
466
467static inline u32 next_command(struct ctlr_info *h)
468{
469 u32 a;
470
471 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
472 return h->access.command_completed(h);
473
474 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
475 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
476 (h->reply_pool_head)++;
477 h->commands_outstanding--;
478 } else {
479 a = FIFO_EMPTY;
480 }
481 /* Check for wraparound */
482 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
483 h->reply_pool_head = h->reply_pool;
484 h->reply_pool_wraparound ^= 1;
485 }
486 return a;
487}
488
489/* set_performant_mode: Modify the tag for cciss performant
490 * set bit 0 for pull model, bits 3-1 for block fetch
491 * register number
492 */
493static void set_performant_mode(struct ctlr_info *h, struct CommandList *c)
494{
495 if (likely(h->transMethod & CFGTBL_Trans_Performant))
496 c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1);
497}
498
499static void enqueue_cmd_and_start_io(struct ctlr_info *h,
500 struct CommandList *c)
501{
502 unsigned long flags;
503
504 set_performant_mode(h, c);
505 spin_lock_irqsave(&h->lock, flags);
506 addQ(&h->reqQ, c);
507 h->Qdepth++;
508 start_io(h);
509 spin_unlock_irqrestore(&h->lock, flags);
510}
511
512static inline void removeQ(struct CommandList *c)
513{
514 if (WARN_ON(list_empty(&c->list)))
515 return;
516 list_del_init(&c->list);
517}
518
519static inline int is_hba_lunid(unsigned char scsi3addr[])
520{
521 return memcmp(scsi3addr, RAID_CTLR_LUNID, 8) == 0;
522}
523
524static inline int is_scsi_rev_5(struct ctlr_info *h)
525{
526 if (!h->hba_inquiry_data)
527 return 0;
528 if ((h->hba_inquiry_data[2] & 0x07) == 5)
529 return 1;
530 return 0;
531}
532
462static int hpsa_find_target_lun(struct ctlr_info *h, 533static int hpsa_find_target_lun(struct ctlr_info *h,
463 unsigned char scsi3addr[], int bus, int *target, int *lun) 534 unsigned char scsi3addr[], int bus, int *target, int *lun)
464{ 535{
@@ -1130,6 +1201,10 @@ static void complete_scsi_command(struct CommandList *cp,
1130 cmd->result = DID_TIME_OUT << 16; 1201 cmd->result = DID_TIME_OUT << 16;
1131 dev_warn(&h->pdev->dev, "cp %p timedout\n", cp); 1202 dev_warn(&h->pdev->dev, "cp %p timedout\n", cp);
1132 break; 1203 break;
1204 case CMD_UNABORTABLE:
1205 cmd->result = DID_ERROR << 16;
1206 dev_warn(&h->pdev->dev, "Command unabortable\n");
1207 break;
1133 default: 1208 default:
1134 cmd->result = DID_ERROR << 16; 1209 cmd->result = DID_ERROR << 16;
1135 dev_warn(&h->pdev->dev, "cp %p returned unknown status %x\n", 1210 dev_warn(&h->pdev->dev, "cp %p returned unknown status %x\n",
@@ -1160,7 +1235,7 @@ static int hpsa_scsi_detect(struct ctlr_info *h)
1160 sh->sg_tablesize = h->maxsgentries; 1235 sh->sg_tablesize = h->maxsgentries;
1161 h->scsi_host = sh; 1236 h->scsi_host = sh;
1162 sh->hostdata[0] = (unsigned long) h; 1237 sh->hostdata[0] = (unsigned long) h;
1163 sh->irq = h->intr[PERF_MODE_INT]; 1238 sh->irq = h->intr[h->intr_mode];
1164 sh->unique_id = sh->irq; 1239 sh->unique_id = sh->irq;
1165 error = scsi_add_host(sh, &h->pdev->dev); 1240 error = scsi_add_host(sh, &h->pdev->dev);
1166 if (error) 1241 if (error)
@@ -1295,6 +1370,9 @@ static void hpsa_scsi_interpret_error(struct CommandList *cp)
1295 case CMD_TIMEOUT: 1370 case CMD_TIMEOUT:
1296 dev_warn(d, "cp %p timed out\n", cp); 1371 dev_warn(d, "cp %p timed out\n", cp);
1297 break; 1372 break;
1373 case CMD_UNABORTABLE:
1374 dev_warn(d, "Command unabortable\n");
1375 break;
1298 default: 1376 default:
1299 dev_warn(d, "cp %p returned unknown status %x\n", cp, 1377 dev_warn(d, "cp %p returned unknown status %x\n", cp,
1300 ei->CommandStatus); 1378 ei->CommandStatus);
@@ -1595,6 +1673,8 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,
1595 if (lun == 0) /* if lun is 0, then obviously we have a lun 0. */ 1673 if (lun == 0) /* if lun is 0, then obviously we have a lun 0. */
1596 return 0; 1674 return 0;
1597 1675
1676 memset(scsi3addr, 0, 8);
1677 scsi3addr[3] = target;
1598 if (is_hba_lunid(scsi3addr)) 1678 if (is_hba_lunid(scsi3addr))
1599 return 0; /* Don't add the RAID controller here. */ 1679 return 0; /* Don't add the RAID controller here. */
1600 1680
@@ -1609,8 +1689,6 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,
1609 return 0; 1689 return 0;
1610 } 1690 }
1611 1691
1612 memset(scsi3addr, 0, 8);
1613 scsi3addr[3] = target;
1614 if (hpsa_update_device_info(h, scsi3addr, this_device)) 1692 if (hpsa_update_device_info(h, scsi3addr, this_device))
1615 return 0; 1693 return 0;
1616 (*nmsa2xxx_enclosures)++; 1694 (*nmsa2xxx_enclosures)++;
@@ -2199,7 +2277,7 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h)
2199 2277
2200 c->cmdindex = i; 2278 c->cmdindex = i;
2201 2279
2202 INIT_HLIST_NODE(&c->list); 2280 INIT_LIST_HEAD(&c->list);
2203 c->busaddr = (u32) cmd_dma_handle; 2281 c->busaddr = (u32) cmd_dma_handle;
2204 temp64.val = (u64) err_dma_handle; 2282 temp64.val = (u64) err_dma_handle;
2205 c->ErrDesc.Addr.lower = temp64.val32.lower; 2283 c->ErrDesc.Addr.lower = temp64.val32.lower;
@@ -2237,7 +2315,7 @@ static struct CommandList *cmd_special_alloc(struct ctlr_info *h)
2237 } 2315 }
2238 memset(c->err_info, 0, sizeof(*c->err_info)); 2316 memset(c->err_info, 0, sizeof(*c->err_info));
2239 2317
2240 INIT_HLIST_NODE(&c->list); 2318 INIT_LIST_HEAD(&c->list);
2241 c->busaddr = (u32) cmd_dma_handle; 2319 c->busaddr = (u32) cmd_dma_handle;
2242 temp64.val = (u64) err_dma_handle; 2320 temp64.val = (u64) err_dma_handle;
2243 c->ErrDesc.Addr.lower = temp64.val32.lower; 2321 c->ErrDesc.Addr.lower = temp64.val32.lower;
@@ -2267,7 +2345,7 @@ static void cmd_special_free(struct ctlr_info *h, struct CommandList *c)
2267 pci_free_consistent(h->pdev, sizeof(*c->err_info), 2345 pci_free_consistent(h->pdev, sizeof(*c->err_info),
2268 c->err_info, (dma_addr_t) temp64.val); 2346 c->err_info, (dma_addr_t) temp64.val);
2269 pci_free_consistent(h->pdev, sizeof(*c), 2347 pci_free_consistent(h->pdev, sizeof(*c),
2270 c, (dma_addr_t) c->busaddr); 2348 c, (dma_addr_t) (c->busaddr & DIRECT_LOOKUP_MASK));
2271} 2349}
2272 2350
2273#ifdef CONFIG_COMPAT 2351#ifdef CONFIG_COMPAT
@@ -2281,6 +2359,7 @@ static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg)
2281 int err; 2359 int err;
2282 u32 cp; 2360 u32 cp;
2283 2361
2362 memset(&arg64, 0, sizeof(arg64));
2284 err = 0; 2363 err = 0;
2285 err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, 2364 err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
2286 sizeof(arg64.LUN_info)); 2365 sizeof(arg64.LUN_info));
@@ -2317,6 +2396,7 @@ static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
2317 int err; 2396 int err;
2318 u32 cp; 2397 u32 cp;
2319 2398
2399 memset(&arg64, 0, sizeof(arg64));
2320 err = 0; 2400 err = 0;
2321 err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, 2401 err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
2322 sizeof(arg64.LUN_info)); 2402 sizeof(arg64.LUN_info));
@@ -2433,15 +2513,17 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2433 buff = kmalloc(iocommand.buf_size, GFP_KERNEL); 2513 buff = kmalloc(iocommand.buf_size, GFP_KERNEL);
2434 if (buff == NULL) 2514 if (buff == NULL)
2435 return -EFAULT; 2515 return -EFAULT;
2436 } 2516 if (iocommand.Request.Type.Direction == XFER_WRITE) {
2437 if (iocommand.Request.Type.Direction == XFER_WRITE) { 2517 /* Copy the data into the buffer we created */
2438 /* Copy the data into the buffer we created */ 2518 if (copy_from_user(buff, iocommand.buf,
2439 if (copy_from_user(buff, iocommand.buf, iocommand.buf_size)) { 2519 iocommand.buf_size)) {
2440 kfree(buff); 2520 kfree(buff);
2441 return -EFAULT; 2521 return -EFAULT;
2522 }
2523 } else {
2524 memset(buff, 0, iocommand.buf_size);
2442 } 2525 }
2443 } else 2526 }
2444 memset(buff, 0, iocommand.buf_size);
2445 c = cmd_special_alloc(h); 2527 c = cmd_special_alloc(h);
2446 if (c == NULL) { 2528 if (c == NULL) {
2447 kfree(buff); 2529 kfree(buff);
@@ -2487,8 +2569,8 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2487 cmd_special_free(h, c); 2569 cmd_special_free(h, c);
2488 return -EFAULT; 2570 return -EFAULT;
2489 } 2571 }
2490 2572 if (iocommand.Request.Type.Direction == XFER_READ &&
2491 if (iocommand.Request.Type.Direction == XFER_READ) { 2573 iocommand.buf_size > 0) {
2492 /* Copy the data out of the buffer we created */ 2574 /* Copy the data out of the buffer we created */
2493 if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) { 2575 if (copy_to_user(iocommand.buf, buff, iocommand.buf_size)) {
2494 kfree(buff); 2576 kfree(buff);
@@ -2581,14 +2663,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2581 } 2663 }
2582 c->cmd_type = CMD_IOCTL_PEND; 2664 c->cmd_type = CMD_IOCTL_PEND;
2583 c->Header.ReplyQueue = 0; 2665 c->Header.ReplyQueue = 0;
2584 2666 c->Header.SGList = c->Header.SGTotal = sg_used;
2585 if (ioc->buf_size > 0) {
2586 c->Header.SGList = sg_used;
2587 c->Header.SGTotal = sg_used;
2588 } else {
2589 c->Header.SGList = 0;
2590 c->Header.SGTotal = 0;
2591 }
2592 memcpy(&c->Header.LUN, &ioc->LUN_info, sizeof(c->Header.LUN)); 2667 memcpy(&c->Header.LUN, &ioc->LUN_info, sizeof(c->Header.LUN));
2593 c->Header.Tag.lower = c->busaddr; 2668 c->Header.Tag.lower = c->busaddr;
2594 memcpy(&c->Request, &ioc->Request, sizeof(c->Request)); 2669 memcpy(&c->Request, &ioc->Request, sizeof(c->Request));
@@ -2605,7 +2680,8 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2605 } 2680 }
2606 } 2681 }
2607 hpsa_scsi_do_simple_cmd_core(h, c); 2682 hpsa_scsi_do_simple_cmd_core(h, c);
2608 hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL); 2683 if (sg_used)
2684 hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL);
2609 check_ioctl_unit_attention(h, c); 2685 check_ioctl_unit_attention(h, c);
2610 /* Copy the error information out */ 2686 /* Copy the error information out */
2611 memcpy(&ioc->error_info, c->err_info, sizeof(ioc->error_info)); 2687 memcpy(&ioc->error_info, c->err_info, sizeof(ioc->error_info));
@@ -2614,7 +2690,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2614 status = -EFAULT; 2690 status = -EFAULT;
2615 goto cleanup1; 2691 goto cleanup1;
2616 } 2692 }
2617 if (ioc->Request.Type.Direction == XFER_READ) { 2693 if (ioc->Request.Type.Direction == XFER_READ && ioc->buf_size > 0) {
2618 /* Copy the data out of the buffer we created */ 2694 /* Copy the data out of the buffer we created */
2619 BYTE __user *ptr = ioc->buf; 2695 BYTE __user *ptr = ioc->buf;
2620 for (i = 0; i < sg_used; i++) { 2696 for (i = 0; i < sg_used; i++) {
@@ -2810,8 +2886,8 @@ static void start_io(struct ctlr_info *h)
2810{ 2886{
2811 struct CommandList *c; 2887 struct CommandList *c;
2812 2888
2813 while (!hlist_empty(&h->reqQ)) { 2889 while (!list_empty(&h->reqQ)) {
2814 c = hlist_entry(h->reqQ.first, struct CommandList, list); 2890 c = list_entry(h->reqQ.next, struct CommandList, list);
2815 /* can't do anything if fifo is full */ 2891 /* can't do anything if fifo is full */
2816 if ((h->access.fifo_full(h))) { 2892 if ((h->access.fifo_full(h))) {
2817 dev_warn(&h->pdev->dev, "fifo full\n"); 2893 dev_warn(&h->pdev->dev, "fifo full\n");
@@ -2867,20 +2943,22 @@ static inline void finish_cmd(struct CommandList *c, u32 raw_tag)
2867 2943
2868static inline u32 hpsa_tag_contains_index(u32 tag) 2944static inline u32 hpsa_tag_contains_index(u32 tag)
2869{ 2945{
2870#define DIRECT_LOOKUP_BIT 0x10
2871 return tag & DIRECT_LOOKUP_BIT; 2946 return tag & DIRECT_LOOKUP_BIT;
2872} 2947}
2873 2948
2874static inline u32 hpsa_tag_to_index(u32 tag) 2949static inline u32 hpsa_tag_to_index(u32 tag)
2875{ 2950{
2876#define DIRECT_LOOKUP_SHIFT 5
2877 return tag >> DIRECT_LOOKUP_SHIFT; 2951 return tag >> DIRECT_LOOKUP_SHIFT;
2878} 2952}
2879 2953
2880static inline u32 hpsa_tag_discard_error_bits(u32 tag) 2954
2955static inline u32 hpsa_tag_discard_error_bits(struct ctlr_info *h, u32 tag)
2881{ 2956{
2882#define HPSA_ERROR_BITS 0x03 2957#define HPSA_PERF_ERROR_BITS ((1 << DIRECT_LOOKUP_SHIFT) - 1)
2883 return tag & ~HPSA_ERROR_BITS; 2958#define HPSA_SIMPLE_ERROR_BITS 0x03
2959 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
2960 return tag & ~HPSA_SIMPLE_ERROR_BITS;
2961 return tag & ~HPSA_PERF_ERROR_BITS;
2884} 2962}
2885 2963
2886/* process completion of an indexed ("direct lookup") command */ 2964/* process completion of an indexed ("direct lookup") command */
@@ -2904,10 +2982,9 @@ static inline u32 process_nonindexed_cmd(struct ctlr_info *h,
2904{ 2982{
2905 u32 tag; 2983 u32 tag;
2906 struct CommandList *c = NULL; 2984 struct CommandList *c = NULL;
2907 struct hlist_node *tmp;
2908 2985
2909 tag = hpsa_tag_discard_error_bits(raw_tag); 2986 tag = hpsa_tag_discard_error_bits(h, raw_tag);
2910 hlist_for_each_entry(c, tmp, &h->cmpQ, list) { 2987 list_for_each_entry(c, &h->cmpQ, list) {
2911 if ((c->busaddr & 0xFFFFFFE0) == (tag & 0xFFFFFFE0)) { 2988 if ((c->busaddr & 0xFFFFFFE0) == (tag & 0xFFFFFFE0)) {
2912 finish_cmd(c, raw_tag); 2989 finish_cmd(c, raw_tag);
2913 return next_command(h); 2990 return next_command(h);
@@ -2957,7 +3034,10 @@ static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id)
2957 return IRQ_HANDLED; 3034 return IRQ_HANDLED;
2958} 3035}
2959 3036
2960/* Send a message CDB to the firmware. */ 3037/* Send a message CDB to the firmware. Careful, this only works
3038 * in simple mode, not performant mode due to the tag lookup.
3039 * We only ever use this immediately after a controller reset.
3040 */
2961static __devinit int hpsa_message(struct pci_dev *pdev, unsigned char opcode, 3041static __devinit int hpsa_message(struct pci_dev *pdev, unsigned char opcode,
2962 unsigned char type) 3042 unsigned char type)
2963{ 3043{
@@ -3023,7 +3103,7 @@ static __devinit int hpsa_message(struct pci_dev *pdev, unsigned char opcode,
3023 3103
3024 for (i = 0; i < HPSA_MSG_SEND_RETRY_LIMIT; i++) { 3104 for (i = 0; i < HPSA_MSG_SEND_RETRY_LIMIT; i++) {
3025 tag = readl(vaddr + SA5_REPLY_PORT_OFFSET); 3105 tag = readl(vaddr + SA5_REPLY_PORT_OFFSET);
3026 if (hpsa_tag_discard_error_bits(tag) == paddr32) 3106 if ((tag & ~HPSA_SIMPLE_ERROR_BITS) == paddr32)
3027 break; 3107 break;
3028 msleep(HPSA_MSG_SEND_RETRY_INTERVAL_MSECS); 3108 msleep(HPSA_MSG_SEND_RETRY_INTERVAL_MSECS);
3029 } 3109 }
@@ -3055,38 +3135,6 @@ static __devinit int hpsa_message(struct pci_dev *pdev, unsigned char opcode,
3055#define hpsa_soft_reset_controller(p) hpsa_message(p, 1, 0) 3135#define hpsa_soft_reset_controller(p) hpsa_message(p, 1, 0)
3056#define hpsa_noop(p) hpsa_message(p, 3, 0) 3136#define hpsa_noop(p) hpsa_message(p, 3, 0)
3057 3137
3058static __devinit int hpsa_reset_msi(struct pci_dev *pdev)
3059{
3060/* the #defines are stolen from drivers/pci/msi.h. */
3061#define msi_control_reg(base) (base + PCI_MSI_FLAGS)
3062#define PCI_MSIX_FLAGS_ENABLE (1 << 15)
3063
3064 int pos;
3065 u16 control = 0;
3066
3067 pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
3068 if (pos) {
3069 pci_read_config_word(pdev, msi_control_reg(pos), &control);
3070 if (control & PCI_MSI_FLAGS_ENABLE) {
3071 dev_info(&pdev->dev, "resetting MSI\n");
3072 pci_write_config_word(pdev, msi_control_reg(pos),
3073 control & ~PCI_MSI_FLAGS_ENABLE);
3074 }
3075 }
3076
3077 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
3078 if (pos) {
3079 pci_read_config_word(pdev, msi_control_reg(pos), &control);
3080 if (control & PCI_MSIX_FLAGS_ENABLE) {
3081 dev_info(&pdev->dev, "resetting MSI-X\n");
3082 pci_write_config_word(pdev, msi_control_reg(pos),
3083 control & ~PCI_MSIX_FLAGS_ENABLE);
3084 }
3085 }
3086
3087 return 0;
3088}
3089
3090static int hpsa_controller_hard_reset(struct pci_dev *pdev, 3138static int hpsa_controller_hard_reset(struct pci_dev *pdev,
3091 void * __iomem vaddr, bool use_doorbell) 3139 void * __iomem vaddr, bool use_doorbell)
3092{ 3140{
@@ -3142,17 +3190,17 @@ static int hpsa_controller_hard_reset(struct pci_dev *pdev,
3142 */ 3190 */
3143static __devinit int hpsa_kdump_hard_reset_controller(struct pci_dev *pdev) 3191static __devinit int hpsa_kdump_hard_reset_controller(struct pci_dev *pdev)
3144{ 3192{
3145 u16 saved_config_space[32];
3146 u64 cfg_offset; 3193 u64 cfg_offset;
3147 u32 cfg_base_addr; 3194 u32 cfg_base_addr;
3148 u64 cfg_base_addr_index; 3195 u64 cfg_base_addr_index;
3149 void __iomem *vaddr; 3196 void __iomem *vaddr;
3150 unsigned long paddr; 3197 unsigned long paddr;
3151 u32 misc_fw_support, active_transport; 3198 u32 misc_fw_support, active_transport;
3152 int rc, i; 3199 int rc;
3153 struct CfgTable __iomem *cfgtable; 3200 struct CfgTable __iomem *cfgtable;
3154 bool use_doorbell; 3201 bool use_doorbell;
3155 u32 board_id; 3202 u32 board_id;
3203 u16 command_register;
3156 3204
3157 /* For controllers as old as the P600, this is very nearly 3205 /* For controllers as old as the P600, this is very nearly
3158 * the same thing as 3206 * the same thing as
@@ -3162,14 +3210,6 @@ static __devinit int hpsa_kdump_hard_reset_controller(struct pci_dev *pdev)
3162 * pci_set_power_state(pci_dev, PCI_D0); 3210 * pci_set_power_state(pci_dev, PCI_D0);
3163 * pci_restore_state(pci_dev); 3211 * pci_restore_state(pci_dev);
3164 * 3212 *
3165 * but we can't use these nice canned kernel routines on
3166 * kexec, because they also check the MSI/MSI-X state in PCI
3167 * configuration space and do the wrong thing when it is
3168 * set/cleared. Also, the pci_save/restore_state functions
3169 * violate the ordering requirements for restoring the
3170 * configuration space from the CCISS document (see the
3171 * comment below). So we roll our own ....
3172 *
3173 * For controllers newer than the P600, the pci power state 3213 * For controllers newer than the P600, the pci power state
3174 * method of resetting doesn't work so we have another way 3214 * method of resetting doesn't work so we have another way
3175 * using the doorbell register. 3215 * using the doorbell register.
@@ -3182,13 +3222,21 @@ static __devinit int hpsa_kdump_hard_reset_controller(struct pci_dev *pdev)
3182 * likely not be happy. Just forbid resetting this conjoined mess. 3222 * likely not be happy. Just forbid resetting this conjoined mess.
3183 * The 640x isn't really supported by hpsa anyway. 3223 * The 640x isn't really supported by hpsa anyway.
3184 */ 3224 */
3185 hpsa_lookup_board_id(pdev, &board_id); 3225 rc = hpsa_lookup_board_id(pdev, &board_id);
3226 if (rc < 0) {
3227 dev_warn(&pdev->dev, "Not resetting device.\n");
3228 return -ENODEV;
3229 }
3186 if (board_id == 0x409C0E11 || board_id == 0x409D0E11) 3230 if (board_id == 0x409C0E11 || board_id == 0x409D0E11)
3187 return -ENOTSUPP; 3231 return -ENOTSUPP;
3188 3232
3189 for (i = 0; i < 32; i++) 3233 /* Save the PCI command register */
3190 pci_read_config_word(pdev, 2*i, &saved_config_space[i]); 3234 pci_read_config_word(pdev, 4, &command_register);
3191 3235 /* Turn the board off. This is so that later pci_restore_state()
3236 * won't turn the board on before the rest of config space is ready.
3237 */
3238 pci_disable_device(pdev);
3239 pci_save_state(pdev);
3192 3240
3193 /* find the first memory BAR, so we can find the cfg table */ 3241 /* find the first memory BAR, so we can find the cfg table */
3194 rc = hpsa_pci_find_memory_BAR(pdev, &paddr); 3242 rc = hpsa_pci_find_memory_BAR(pdev, &paddr);
@@ -3214,46 +3262,47 @@ static __devinit int hpsa_kdump_hard_reset_controller(struct pci_dev *pdev)
3214 misc_fw_support = readl(&cfgtable->misc_fw_support); 3262 misc_fw_support = readl(&cfgtable->misc_fw_support);
3215 use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET; 3263 use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET;
3216 3264
3217 /* The doorbell reset seems to cause lockups on some Smart
3218 * Arrays (e.g. P410, P410i, maybe others). Until this is
3219 * fixed or at least isolated, avoid the doorbell reset.
3220 */
3221 use_doorbell = 0;
3222
3223 rc = hpsa_controller_hard_reset(pdev, vaddr, use_doorbell); 3265 rc = hpsa_controller_hard_reset(pdev, vaddr, use_doorbell);
3224 if (rc) 3266 if (rc)
3225 goto unmap_cfgtable; 3267 goto unmap_cfgtable;
3226 3268
3227 /* Restore the PCI configuration space. The Open CISS 3269 pci_restore_state(pdev);
3228 * Specification says, "Restore the PCI Configuration 3270 rc = pci_enable_device(pdev);
3229 * Registers, offsets 00h through 60h. It is important to 3271 if (rc) {
3230 * restore the command register, 16-bits at offset 04h, 3272 dev_warn(&pdev->dev, "failed to enable device.\n");
3231 * last. Do not restore the configuration status register, 3273 goto unmap_cfgtable;
3232 * 16-bits at offset 06h." Note that the offset is 2*i.
3233 */
3234 for (i = 0; i < 32; i++) {
3235 if (i == 2 || i == 3)
3236 continue;
3237 pci_write_config_word(pdev, 2*i, saved_config_space[i]);
3238 } 3274 }
3239 wmb(); 3275 pci_write_config_word(pdev, 4, command_register);
3240 pci_write_config_word(pdev, 4, saved_config_space[2]);
3241 3276
3242 /* Some devices (notably the HP Smart Array 5i Controller) 3277 /* Some devices (notably the HP Smart Array 5i Controller)
3243 need a little pause here */ 3278 need a little pause here */
3244 msleep(HPSA_POST_RESET_PAUSE_MSECS); 3279 msleep(HPSA_POST_RESET_PAUSE_MSECS);
3245 3280
3281 /* Wait for board to become not ready, then ready. */
3282 dev_info(&pdev->dev, "Waiting for board to become ready.\n");
3283 rc = hpsa_wait_for_board_state(pdev, vaddr, BOARD_NOT_READY);
3284 if (rc)
3285 dev_warn(&pdev->dev,
3286 "failed waiting for board to become not ready\n");
3287 rc = hpsa_wait_for_board_state(pdev, vaddr, BOARD_READY);
3288 if (rc) {
3289 dev_warn(&pdev->dev,
3290 "failed waiting for board to become ready\n");
3291 goto unmap_cfgtable;
3292 }
3293 dev_info(&pdev->dev, "board ready.\n");
3294
3246 /* Controller should be in simple mode at this point. If it's not, 3295 /* Controller should be in simple mode at this point. If it's not,
3247 * It means we're on one of those controllers which doesn't support 3296 * It means we're on one of those controllers which doesn't support
3248 * the doorbell reset method and on which the PCI power management reset 3297 * the doorbell reset method and on which the PCI power management reset
3249 * method doesn't work (P800, for example.) 3298 * method doesn't work (P800, for example.)
3250 * In those cases, pretend the reset worked and hope for the best. 3299 * In those cases, don't try to proceed, as it generally doesn't work.
3251 */ 3300 */
3252 active_transport = readl(&cfgtable->TransportActive); 3301 active_transport = readl(&cfgtable->TransportActive);
3253 if (active_transport & PERFORMANT_MODE) { 3302 if (active_transport & PERFORMANT_MODE) {
3254 dev_warn(&pdev->dev, "Unable to successfully reset controller," 3303 dev_warn(&pdev->dev, "Unable to successfully reset controller,"
3255 " proceeding anyway.\n"); 3304 " Ignoring controller.\n");
3256 rc = -ENOTSUPP; 3305 rc = -ENODEV;
3257 } 3306 }
3258 3307
3259unmap_cfgtable: 3308unmap_cfgtable:
@@ -3386,7 +3435,7 @@ static void __devinit hpsa_interrupt_mode(struct ctlr_info *h)
3386default_int_mode: 3435default_int_mode:
3387#endif /* CONFIG_PCI_MSI */ 3436#endif /* CONFIG_PCI_MSI */
3388 /* if we get here we're going to use the default interrupt mode */ 3437 /* if we get here we're going to use the default interrupt mode */
3389 h->intr[PERF_MODE_INT] = h->pdev->irq; 3438 h->intr[h->intr_mode] = h->pdev->irq;
3390} 3439}
3391 3440
3392static int __devinit hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id) 3441static int __devinit hpsa_lookup_board_id(struct pci_dev *pdev, u32 *board_id)
@@ -3438,18 +3487,28 @@ static int __devinit hpsa_pci_find_memory_BAR(struct pci_dev *pdev,
3438 return -ENODEV; 3487 return -ENODEV;
3439} 3488}
3440 3489
3441static int __devinit hpsa_wait_for_board_ready(struct ctlr_info *h) 3490static int __devinit hpsa_wait_for_board_state(struct pci_dev *pdev,
3491 void __iomem *vaddr, int wait_for_ready)
3442{ 3492{
3443 int i; 3493 int i, iterations;
3444 u32 scratchpad; 3494 u32 scratchpad;
3495 if (wait_for_ready)
3496 iterations = HPSA_BOARD_READY_ITERATIONS;
3497 else
3498 iterations = HPSA_BOARD_NOT_READY_ITERATIONS;
3445 3499
3446 for (i = 0; i < HPSA_BOARD_READY_ITERATIONS; i++) { 3500 for (i = 0; i < iterations; i++) {
3447 scratchpad = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET); 3501 scratchpad = readl(vaddr + SA5_SCRATCHPAD_OFFSET);
3448 if (scratchpad == HPSA_FIRMWARE_READY) 3502 if (wait_for_ready) {
3449 return 0; 3503 if (scratchpad == HPSA_FIRMWARE_READY)
3504 return 0;
3505 } else {
3506 if (scratchpad != HPSA_FIRMWARE_READY)
3507 return 0;
3508 }
3450 msleep(HPSA_BOARD_READY_POLL_INTERVAL_MSECS); 3509 msleep(HPSA_BOARD_READY_POLL_INTERVAL_MSECS);
3451 } 3510 }
3452 dev_warn(&h->pdev->dev, "board not ready, timed out.\n"); 3511 dev_warn(&pdev->dev, "board not ready, timed out.\n");
3453 return -ENODEV; 3512 return -ENODEV;
3454} 3513}
3455 3514
@@ -3497,6 +3556,11 @@ static int __devinit hpsa_find_cfgtables(struct ctlr_info *h)
3497static void __devinit hpsa_get_max_perf_mode_cmds(struct ctlr_info *h) 3556static void __devinit hpsa_get_max_perf_mode_cmds(struct ctlr_info *h)
3498{ 3557{
3499 h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands)); 3558 h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands));
3559
3560 /* Limit commands in memory limited kdump scenario. */
3561 if (reset_devices && h->max_commands > 32)
3562 h->max_commands = 32;
3563
3500 if (h->max_commands < 16) { 3564 if (h->max_commands < 16) {
3501 dev_warn(&h->pdev->dev, "Controller reports " 3565 dev_warn(&h->pdev->dev, "Controller reports "
3502 "max supported commands of %d, an obvious lie. " 3566 "max supported commands of %d, an obvious lie. "
@@ -3571,16 +3635,21 @@ static inline void hpsa_p600_dma_prefetch_quirk(struct ctlr_info *h)
3571static void __devinit hpsa_wait_for_mode_change_ack(struct ctlr_info *h) 3635static void __devinit hpsa_wait_for_mode_change_ack(struct ctlr_info *h)
3572{ 3636{
3573 int i; 3637 int i;
3638 u32 doorbell_value;
3639 unsigned long flags;
3574 3640
3575 /* under certain very rare conditions, this can take awhile. 3641 /* under certain very rare conditions, this can take awhile.
3576 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right 3642 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
3577 * as we enter this code.) 3643 * as we enter this code.)
3578 */ 3644 */
3579 for (i = 0; i < MAX_CONFIG_WAIT; i++) { 3645 for (i = 0; i < MAX_CONFIG_WAIT; i++) {
3580 if (!(readl(h->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq)) 3646 spin_lock_irqsave(&h->lock, flags);
3647 doorbell_value = readl(h->vaddr + SA5_DOORBELL);
3648 spin_unlock_irqrestore(&h->lock, flags);
3649 if (!(doorbell_value & CFGTBL_ChangeReq))
3581 break; 3650 break;
3582 /* delay and try again */ 3651 /* delay and try again */
3583 msleep(10); 3652 usleep_range(10000, 20000);
3584 } 3653 }
3585} 3654}
3586 3655
@@ -3603,6 +3672,7 @@ static int __devinit hpsa_enter_simple_mode(struct ctlr_info *h)
3603 "unable to get board into simple mode\n"); 3672 "unable to get board into simple mode\n");
3604 return -ENODEV; 3673 return -ENODEV;
3605 } 3674 }
3675 h->transMethod = CFGTBL_Trans_Simple;
3606 return 0; 3676 return 0;
3607} 3677}
3608 3678
@@ -3641,7 +3711,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
3641 err = -ENOMEM; 3711 err = -ENOMEM;
3642 goto err_out_free_res; 3712 goto err_out_free_res;
3643 } 3713 }
3644 err = hpsa_wait_for_board_ready(h); 3714 err = hpsa_wait_for_board_state(h->pdev, h->vaddr, BOARD_READY);
3645 if (err) 3715 if (err)
3646 goto err_out_free_res; 3716 goto err_out_free_res;
3647 err = hpsa_find_cfgtables(h); 3717 err = hpsa_find_cfgtables(h);
@@ -3710,8 +3780,6 @@ static __devinit int hpsa_init_reset_devices(struct pci_dev *pdev)
3710 return 0; /* just try to do the kdump anyhow. */ 3780 return 0; /* just try to do the kdump anyhow. */
3711 if (rc) 3781 if (rc)
3712 return -ENODEV; 3782 return -ENODEV;
3713 if (hpsa_reset_msi(pdev))
3714 return -ENODEV;
3715 3783
3716 /* Now try to get the controller to respond to a no-op */ 3784 /* Now try to get the controller to respond to a no-op */
3717 for (i = 0; i < HPSA_POST_RESET_NOOP_RETRIES; i++) { 3785 for (i = 0; i < HPSA_POST_RESET_NOOP_RETRIES; i++) {
@@ -3749,8 +3817,11 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
3749 3817
3750 h->pdev = pdev; 3818 h->pdev = pdev;
3751 h->busy_initializing = 1; 3819 h->busy_initializing = 1;
3752 INIT_HLIST_HEAD(&h->cmpQ); 3820 h->intr_mode = hpsa_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT;
3753 INIT_HLIST_HEAD(&h->reqQ); 3821 INIT_LIST_HEAD(&h->cmpQ);
3822 INIT_LIST_HEAD(&h->reqQ);
3823 spin_lock_init(&h->lock);
3824 spin_lock_init(&h->scan_lock);
3754 rc = hpsa_pci_init(h); 3825 rc = hpsa_pci_init(h);
3755 if (rc != 0) 3826 if (rc != 0)
3756 goto clean1; 3827 goto clean1;
@@ -3777,20 +3848,20 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
3777 h->access.set_intr_mask(h, HPSA_INTR_OFF); 3848 h->access.set_intr_mask(h, HPSA_INTR_OFF);
3778 3849
3779 if (h->msix_vector || h->msi_vector) 3850 if (h->msix_vector || h->msi_vector)
3780 rc = request_irq(h->intr[PERF_MODE_INT], do_hpsa_intr_msi, 3851 rc = request_irq(h->intr[h->intr_mode], do_hpsa_intr_msi,
3781 IRQF_DISABLED, h->devname, h); 3852 IRQF_DISABLED, h->devname, h);
3782 else 3853 else
3783 rc = request_irq(h->intr[PERF_MODE_INT], do_hpsa_intr_intx, 3854 rc = request_irq(h->intr[h->intr_mode], do_hpsa_intr_intx,
3784 IRQF_DISABLED, h->devname, h); 3855 IRQF_DISABLED, h->devname, h);
3785 if (rc) { 3856 if (rc) {
3786 dev_err(&pdev->dev, "unable to get irq %d for %s\n", 3857 dev_err(&pdev->dev, "unable to get irq %d for %s\n",
3787 h->intr[PERF_MODE_INT], h->devname); 3858 h->intr[h->intr_mode], h->devname);
3788 goto clean2; 3859 goto clean2;
3789 } 3860 }
3790 3861
3791 dev_info(&pdev->dev, "%s: <0x%x> at IRQ %d%s using DAC\n", 3862 dev_info(&pdev->dev, "%s: <0x%x> at IRQ %d%s using DAC\n",
3792 h->devname, pdev->device, 3863 h->devname, pdev->device,
3793 h->intr[PERF_MODE_INT], dac ? "" : " not"); 3864 h->intr[h->intr_mode], dac ? "" : " not");
3794 3865
3795 h->cmd_pool_bits = 3866 h->cmd_pool_bits =
3796 kmalloc(((h->nr_cmds + BITS_PER_LONG - 3867 kmalloc(((h->nr_cmds + BITS_PER_LONG -
@@ -3810,8 +3881,6 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
3810 } 3881 }
3811 if (hpsa_allocate_sg_chain_blocks(h)) 3882 if (hpsa_allocate_sg_chain_blocks(h))
3812 goto clean4; 3883 goto clean4;
3813 spin_lock_init(&h->lock);
3814 spin_lock_init(&h->scan_lock);
3815 init_waitqueue_head(&h->scan_wait_queue); 3884 init_waitqueue_head(&h->scan_wait_queue);
3816 h->scan_finished = 1; /* no scan currently in progress */ 3885 h->scan_finished = 1; /* no scan currently in progress */
3817 3886
@@ -3843,7 +3912,7 @@ clean4:
3843 h->nr_cmds * sizeof(struct ErrorInfo), 3912 h->nr_cmds * sizeof(struct ErrorInfo),
3844 h->errinfo_pool, 3913 h->errinfo_pool,
3845 h->errinfo_pool_dhandle); 3914 h->errinfo_pool_dhandle);
3846 free_irq(h->intr[PERF_MODE_INT], h); 3915 free_irq(h->intr[h->intr_mode], h);
3847clean2: 3916clean2:
3848clean1: 3917clean1:
3849 h->busy_initializing = 0; 3918 h->busy_initializing = 0;
@@ -3887,7 +3956,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
3887 */ 3956 */
3888 hpsa_flush_cache(h); 3957 hpsa_flush_cache(h);
3889 h->access.set_intr_mask(h, HPSA_INTR_OFF); 3958 h->access.set_intr_mask(h, HPSA_INTR_OFF);
3890 free_irq(h->intr[PERF_MODE_INT], h); 3959 free_irq(h->intr[h->intr_mode], h);
3891#ifdef CONFIG_PCI_MSI 3960#ifdef CONFIG_PCI_MSI
3892 if (h->msix_vector) 3961 if (h->msix_vector)
3893 pci_disable_msix(h->pdev); 3962 pci_disable_msix(h->pdev);
@@ -3989,7 +4058,8 @@ static void calc_bucket_map(int bucket[], int num_buckets,
3989 } 4058 }
3990} 4059}
3991 4060
3992static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h) 4061static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
4062 u32 use_short_tags)
3993{ 4063{
3994 int i; 4064 int i;
3995 unsigned long register_value; 4065 unsigned long register_value;
@@ -4037,7 +4107,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h)
4037 writel(0, &h->transtable->RepQCtrAddrHigh32); 4107 writel(0, &h->transtable->RepQCtrAddrHigh32);
4038 writel(h->reply_pool_dhandle, &h->transtable->RepQAddr0Low32); 4108 writel(h->reply_pool_dhandle, &h->transtable->RepQAddr0Low32);
4039 writel(0, &h->transtable->RepQAddr0High32); 4109 writel(0, &h->transtable->RepQAddr0High32);
4040 writel(CFGTBL_Trans_Performant, 4110 writel(CFGTBL_Trans_Performant | use_short_tags,
4041 &(h->cfgtable->HostWrite.TransportRequest)); 4111 &(h->cfgtable->HostWrite.TransportRequest));
4042 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL); 4112 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
4043 hpsa_wait_for_mode_change_ack(h); 4113 hpsa_wait_for_mode_change_ack(h);
@@ -4047,12 +4117,18 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h)
4047 " performant mode\n"); 4117 " performant mode\n");
4048 return; 4118 return;
4049 } 4119 }
4120 /* Change the access methods to the performant access methods */
4121 h->access = SA5_performant_access;
4122 h->transMethod = CFGTBL_Trans_Performant;
4050} 4123}
4051 4124
4052static __devinit void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h) 4125static __devinit void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h)
4053{ 4126{
4054 u32 trans_support; 4127 u32 trans_support;
4055 4128
4129 if (hpsa_simple_mode)
4130 return;
4131
4056 trans_support = readl(&(h->cfgtable->TransportSupport)); 4132 trans_support = readl(&(h->cfgtable->TransportSupport));
4057 if (!(trans_support & PERFORMANT_MODE)) 4133 if (!(trans_support & PERFORMANT_MODE))
4058 return; 4134 return;
@@ -4072,11 +4148,8 @@ static __devinit void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h)
4072 || (h->blockFetchTable == NULL)) 4148 || (h->blockFetchTable == NULL))
4073 goto clean_up; 4149 goto clean_up;
4074 4150
4075 hpsa_enter_performant_mode(h); 4151 hpsa_enter_performant_mode(h,
4076 4152 trans_support & CFGTBL_Trans_use_short_tags);
4077 /* Change the access methods to the performant access methods */
4078 h->access = SA5_performant_access;
4079 h->transMethod = CFGTBL_Trans_Performant;
4080 4153
4081 return; 4154 return;
4082 4155
diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
index 19586e189f0f..621a1530054a 100644
--- a/drivers/scsi/hpsa.h
+++ b/drivers/scsi/hpsa.h
@@ -72,11 +72,12 @@ struct ctlr_info {
72 unsigned int intr[4]; 72 unsigned int intr[4];
73 unsigned int msix_vector; 73 unsigned int msix_vector;
74 unsigned int msi_vector; 74 unsigned int msi_vector;
75 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
75 struct access_method access; 76 struct access_method access;
76 77
77 /* queue and queue Info */ 78 /* queue and queue Info */
78 struct hlist_head reqQ; 79 struct list_head reqQ;
79 struct hlist_head cmpQ; 80 struct list_head cmpQ;
80 unsigned int Qdepth; 81 unsigned int Qdepth;
81 unsigned int maxQsinceinit; 82 unsigned int maxQsinceinit;
82 unsigned int maxSG; 83 unsigned int maxSG;
@@ -154,12 +155,16 @@ struct ctlr_info {
154 * HPSA_BOARD_READY_ITERATIONS are derived from those. 155 * HPSA_BOARD_READY_ITERATIONS are derived from those.
155 */ 156 */
156#define HPSA_BOARD_READY_WAIT_SECS (120) 157#define HPSA_BOARD_READY_WAIT_SECS (120)
158#define HPSA_BOARD_NOT_READY_WAIT_SECS (10)
157#define HPSA_BOARD_READY_POLL_INTERVAL_MSECS (100) 159#define HPSA_BOARD_READY_POLL_INTERVAL_MSECS (100)
158#define HPSA_BOARD_READY_POLL_INTERVAL \ 160#define HPSA_BOARD_READY_POLL_INTERVAL \
159 ((HPSA_BOARD_READY_POLL_INTERVAL_MSECS * HZ) / 1000) 161 ((HPSA_BOARD_READY_POLL_INTERVAL_MSECS * HZ) / 1000)
160#define HPSA_BOARD_READY_ITERATIONS \ 162#define HPSA_BOARD_READY_ITERATIONS \
161 ((HPSA_BOARD_READY_WAIT_SECS * 1000) / \ 163 ((HPSA_BOARD_READY_WAIT_SECS * 1000) / \
162 HPSA_BOARD_READY_POLL_INTERVAL_MSECS) 164 HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
165#define HPSA_BOARD_NOT_READY_ITERATIONS \
166 ((HPSA_BOARD_NOT_READY_WAIT_SECS * 1000) / \
167 HPSA_BOARD_READY_POLL_INTERVAL_MSECS)
163#define HPSA_POST_RESET_PAUSE_MSECS (3000) 168#define HPSA_POST_RESET_PAUSE_MSECS (3000)
164#define HPSA_POST_RESET_NOOP_RETRIES (12) 169#define HPSA_POST_RESET_NOOP_RETRIES (12)
165 170
diff --git a/drivers/scsi/hpsa_cmd.h b/drivers/scsi/hpsa_cmd.h
index f5c4c3cc0530..18464900e761 100644
--- a/drivers/scsi/hpsa_cmd.h
+++ b/drivers/scsi/hpsa_cmd.h
@@ -104,6 +104,7 @@
104 104
105#define CFGTBL_Trans_Simple 0x00000002l 105#define CFGTBL_Trans_Simple 0x00000002l
106#define CFGTBL_Trans_Performant 0x00000004l 106#define CFGTBL_Trans_Performant 0x00000004l
107#define CFGTBL_Trans_use_short_tags 0x20000000l
107 108
108#define CFGTBL_BusType_Ultra2 0x00000001l 109#define CFGTBL_BusType_Ultra2 0x00000001l
109#define CFGTBL_BusType_Ultra3 0x00000002l 110#define CFGTBL_BusType_Ultra3 0x00000002l
@@ -265,6 +266,7 @@ struct ErrorInfo {
265 266
266#define DIRECT_LOOKUP_SHIFT 5 267#define DIRECT_LOOKUP_SHIFT 5
267#define DIRECT_LOOKUP_BIT 0x10 268#define DIRECT_LOOKUP_BIT 0x10
269#define DIRECT_LOOKUP_MASK (~((1 << DIRECT_LOOKUP_SHIFT) - 1))
268 270
269#define HPSA_ERROR_BIT 0x02 271#define HPSA_ERROR_BIT 0x02
270struct ctlr_info; /* defined in hpsa.h */ 272struct ctlr_info; /* defined in hpsa.h */
@@ -291,7 +293,7 @@ struct CommandList {
291 struct ctlr_info *h; 293 struct ctlr_info *h;
292 int cmd_type; 294 int cmd_type;
293 long cmdindex; 295 long cmdindex;
294 struct hlist_node list; 296 struct list_head list;
295 struct request *rq; 297 struct request *rq;
296 struct completion *waiting; 298 struct completion *waiting;
297 void *scsi_cmd; 299 void *scsi_cmd;
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index d841e98a8bd5..0621238fac4a 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -1301,7 +1301,7 @@ static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1301 ipr_clear_res_target(res); 1301 ipr_clear_res_target(res);
1302 list_move_tail(&res->queue, &ioa_cfg->free_res_q); 1302 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1303 } 1303 }
1304 } else if (!res->sdev) { 1304 } else if (!res->sdev || res->del_from_ml) {
1305 res->add_to_ml = 1; 1305 res->add_to_ml = 1;
1306 if (ioa_cfg->allow_ml_add_del) 1306 if (ioa_cfg->allow_ml_add_del)
1307 schedule_work(&ioa_cfg->work_q); 1307 schedule_work(&ioa_cfg->work_q);
@@ -3104,7 +3104,10 @@ restart:
3104 did_work = 1; 3104 did_work = 1;
3105 sdev = res->sdev; 3105 sdev = res->sdev;
3106 if (!scsi_device_get(sdev)) { 3106 if (!scsi_device_get(sdev)) {
3107 list_move_tail(&res->queue, &ioa_cfg->free_res_q); 3107 if (!res->add_to_ml)
3108 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3109 else
3110 res->del_from_ml = 0;
3108 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3111 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3109 scsi_remove_device(sdev); 3112 scsi_remove_device(sdev);
3110 scsi_device_put(sdev); 3113 scsi_device_put(sdev);
@@ -8864,7 +8867,7 @@ static void __ipr_remove(struct pci_dev *pdev)
8864 8867
8865 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags); 8868 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8866 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 8869 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8867 flush_scheduled_work(); 8870 flush_work_sync(&ioa_cfg->work_q);
8868 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags); 8871 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8869 8872
8870 spin_lock(&ipr_driver_lock); 8873 spin_lock(&ipr_driver_lock);
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index fec47de72535..a860452a8f71 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -608,54 +608,12 @@ static void iscsi_sw_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
608 iscsi_sw_tcp_release_conn(conn); 608 iscsi_sw_tcp_release_conn(conn);
609} 609}
610 610
611static int iscsi_sw_tcp_get_addr(struct iscsi_conn *conn, struct socket *sock,
612 char *buf, int *port,
613 int (*getname)(struct socket *,
614 struct sockaddr *,
615 int *addrlen))
616{
617 struct sockaddr_storage *addr;
618 struct sockaddr_in6 *sin6;
619 struct sockaddr_in *sin;
620 int rc = 0, len;
621
622 addr = kmalloc(sizeof(*addr), GFP_KERNEL);
623 if (!addr)
624 return -ENOMEM;
625
626 if (getname(sock, (struct sockaddr *) addr, &len)) {
627 rc = -ENODEV;
628 goto free_addr;
629 }
630
631 switch (addr->ss_family) {
632 case AF_INET:
633 sin = (struct sockaddr_in *)addr;
634 spin_lock_bh(&conn->session->lock);
635 sprintf(buf, "%pI4", &sin->sin_addr.s_addr);
636 *port = be16_to_cpu(sin->sin_port);
637 spin_unlock_bh(&conn->session->lock);
638 break;
639 case AF_INET6:
640 sin6 = (struct sockaddr_in6 *)addr;
641 spin_lock_bh(&conn->session->lock);
642 sprintf(buf, "%pI6", &sin6->sin6_addr);
643 *port = be16_to_cpu(sin6->sin6_port);
644 spin_unlock_bh(&conn->session->lock);
645 break;
646 }
647free_addr:
648 kfree(addr);
649 return rc;
650}
651
652static int 611static int
653iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session, 612iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
654 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, 613 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
655 int is_leading) 614 int is_leading)
656{ 615{
657 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); 616 struct iscsi_session *session = cls_session->dd_data;
658 struct iscsi_host *ihost = shost_priv(shost);
659 struct iscsi_conn *conn = cls_conn->dd_data; 617 struct iscsi_conn *conn = cls_conn->dd_data;
660 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 618 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
661 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; 619 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
@@ -670,27 +628,15 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
670 "sockfd_lookup failed %d\n", err); 628 "sockfd_lookup failed %d\n", err);
671 return -EEXIST; 629 return -EEXIST;
672 } 630 }
673 /*
674 * copy these values now because if we drop the session
675 * userspace may still want to query the values since we will
676 * be using them for the reconnect
677 */
678 err = iscsi_sw_tcp_get_addr(conn, sock, conn->portal_address,
679 &conn->portal_port, kernel_getpeername);
680 if (err)
681 goto free_socket;
682
683 err = iscsi_sw_tcp_get_addr(conn, sock, ihost->local_address,
684 &ihost->local_port, kernel_getsockname);
685 if (err)
686 goto free_socket;
687 631
688 err = iscsi_conn_bind(cls_session, cls_conn, is_leading); 632 err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
689 if (err) 633 if (err)
690 goto free_socket; 634 goto free_socket;
691 635
636 spin_lock_bh(&session->lock);
692 /* bind iSCSI connection and socket */ 637 /* bind iSCSI connection and socket */
693 tcp_sw_conn->sock = sock; 638 tcp_sw_conn->sock = sock;
639 spin_unlock_bh(&session->lock);
694 640
695 /* setup Socket parameters */ 641 /* setup Socket parameters */
696 sk = sock->sk; 642 sk = sock->sk;
@@ -752,24 +698,74 @@ static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
752 enum iscsi_param param, char *buf) 698 enum iscsi_param param, char *buf)
753{ 699{
754 struct iscsi_conn *conn = cls_conn->dd_data; 700 struct iscsi_conn *conn = cls_conn->dd_data;
755 int len; 701 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
702 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
703 struct sockaddr_in6 addr;
704 int rc, len;
756 705
757 switch(param) { 706 switch(param) {
758 case ISCSI_PARAM_CONN_PORT: 707 case ISCSI_PARAM_CONN_PORT:
759 spin_lock_bh(&conn->session->lock);
760 len = sprintf(buf, "%hu\n", conn->portal_port);
761 spin_unlock_bh(&conn->session->lock);
762 break;
763 case ISCSI_PARAM_CONN_ADDRESS: 708 case ISCSI_PARAM_CONN_ADDRESS:
764 spin_lock_bh(&conn->session->lock); 709 spin_lock_bh(&conn->session->lock);
765 len = sprintf(buf, "%s\n", conn->portal_address); 710 if (!tcp_sw_conn || !tcp_sw_conn->sock) {
711 spin_unlock_bh(&conn->session->lock);
712 return -ENOTCONN;
713 }
714 rc = kernel_getpeername(tcp_sw_conn->sock,
715 (struct sockaddr *)&addr, &len);
766 spin_unlock_bh(&conn->session->lock); 716 spin_unlock_bh(&conn->session->lock);
767 break; 717 if (rc)
718 return rc;
719
720 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
721 &addr, param, buf);
768 default: 722 default:
769 return iscsi_conn_get_param(cls_conn, param, buf); 723 return iscsi_conn_get_param(cls_conn, param, buf);
770 } 724 }
771 725
772 return len; 726 return 0;
727}
728
729static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
730 enum iscsi_host_param param, char *buf)
731{
732 struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(shost);
733 struct iscsi_session *session = tcp_sw_host->session;
734 struct iscsi_conn *conn;
735 struct iscsi_tcp_conn *tcp_conn;
736 struct iscsi_sw_tcp_conn *tcp_sw_conn;
737 struct sockaddr_in6 addr;
738 int rc, len;
739
740 switch (param) {
741 case ISCSI_HOST_PARAM_IPADDRESS:
742 spin_lock_bh(&session->lock);
743 conn = session->leadconn;
744 if (!conn) {
745 spin_unlock_bh(&session->lock);
746 return -ENOTCONN;
747 }
748 tcp_conn = conn->dd_data;
749
750 tcp_sw_conn = tcp_conn->dd_data;
751 if (!tcp_sw_conn->sock) {
752 spin_unlock_bh(&session->lock);
753 return -ENOTCONN;
754 }
755
756 rc = kernel_getsockname(tcp_sw_conn->sock,
757 (struct sockaddr *)&addr, &len);
758 spin_unlock_bh(&session->lock);
759 if (rc)
760 return rc;
761
762 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
763 &addr, param, buf);
764 default:
765 return iscsi_host_get_param(shost, param, buf);
766 }
767
768 return 0;
773} 769}
774 770
775static void 771static void
@@ -797,6 +793,7 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
797{ 793{
798 struct iscsi_cls_session *cls_session; 794 struct iscsi_cls_session *cls_session;
799 struct iscsi_session *session; 795 struct iscsi_session *session;
796 struct iscsi_sw_tcp_host *tcp_sw_host;
800 struct Scsi_Host *shost; 797 struct Scsi_Host *shost;
801 798
802 if (ep) { 799 if (ep) {
@@ -804,7 +801,8 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
804 return NULL; 801 return NULL;
805 } 802 }
806 803
807 shost = iscsi_host_alloc(&iscsi_sw_tcp_sht, 0, 1); 804 shost = iscsi_host_alloc(&iscsi_sw_tcp_sht,
805 sizeof(struct iscsi_sw_tcp_host), 1);
808 if (!shost) 806 if (!shost)
809 return NULL; 807 return NULL;
810 shost->transportt = iscsi_sw_tcp_scsi_transport; 808 shost->transportt = iscsi_sw_tcp_scsi_transport;
@@ -825,6 +823,8 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
825 if (!cls_session) 823 if (!cls_session)
826 goto remove_host; 824 goto remove_host;
827 session = cls_session->dd_data; 825 session = cls_session->dd_data;
826 tcp_sw_host = iscsi_host_priv(shost);
827 tcp_sw_host->session = session;
828 828
829 shost->can_queue = session->scsi_cmds_max; 829 shost->can_queue = session->scsi_cmds_max;
830 if (iscsi_tcp_r2tpool_alloc(session)) 830 if (iscsi_tcp_r2tpool_alloc(session))
@@ -929,7 +929,7 @@ static struct iscsi_transport iscsi_sw_tcp_transport = {
929 .start_conn = iscsi_conn_start, 929 .start_conn = iscsi_conn_start,
930 .stop_conn = iscsi_sw_tcp_conn_stop, 930 .stop_conn = iscsi_sw_tcp_conn_stop,
931 /* iscsi host params */ 931 /* iscsi host params */
932 .get_host_param = iscsi_host_get_param, 932 .get_host_param = iscsi_sw_tcp_host_get_param,
933 .set_host_param = iscsi_host_set_param, 933 .set_host_param = iscsi_host_set_param,
934 /* IO */ 934 /* IO */
935 .send_pdu = iscsi_conn_send_pdu, 935 .send_pdu = iscsi_conn_send_pdu,
diff --git a/drivers/scsi/iscsi_tcp.h b/drivers/scsi/iscsi_tcp.h
index 94644bad0ed7..666fe09378fa 100644
--- a/drivers/scsi/iscsi_tcp.h
+++ b/drivers/scsi/iscsi_tcp.h
@@ -55,6 +55,10 @@ struct iscsi_sw_tcp_conn {
55 ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int); 55 ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
56}; 56};
57 57
58struct iscsi_sw_tcp_host {
59 struct iscsi_session *session;
60};
61
58struct iscsi_sw_tcp_hdrbuf { 62struct iscsi_sw_tcp_hdrbuf {
59 struct iscsi_hdr hdrbuf; 63 struct iscsi_hdr hdrbuf;
60 char hdrextbuf[ISCSI_MAX_AHS_SIZE + 64 char hdrextbuf[ISCSI_MAX_AHS_SIZE +
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index d21367d3305f..28231badd9e6 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -38,7 +38,7 @@ u16 fc_cpu_mask; /* cpu mask for possible cpus */
38EXPORT_SYMBOL(fc_cpu_mask); 38EXPORT_SYMBOL(fc_cpu_mask);
39static u16 fc_cpu_order; /* 2's power to represent total possible cpus */ 39static u16 fc_cpu_order; /* 2's power to represent total possible cpus */
40static struct kmem_cache *fc_em_cachep; /* cache for exchanges */ 40static struct kmem_cache *fc_em_cachep; /* cache for exchanges */
41struct workqueue_struct *fc_exch_workqueue; 41static struct workqueue_struct *fc_exch_workqueue;
42 42
43/* 43/*
44 * Structure and function definitions for managing Fibre Channel Exchanges 44 * Structure and function definitions for managing Fibre Channel Exchanges
@@ -558,6 +558,22 @@ static struct fc_seq *fc_seq_start_next(struct fc_seq *sp)
558 return sp; 558 return sp;
559} 559}
560 560
561/*
562 * Set the response handler for the exchange associated with a sequence.
563 */
564static void fc_seq_set_resp(struct fc_seq *sp,
565 void (*resp)(struct fc_seq *, struct fc_frame *,
566 void *),
567 void *arg)
568{
569 struct fc_exch *ep = fc_seq_exch(sp);
570
571 spin_lock_bh(&ep->ex_lock);
572 ep->resp = resp;
573 ep->arg = arg;
574 spin_unlock_bh(&ep->ex_lock);
575}
576
561/** 577/**
562 * fc_seq_exch_abort() - Abort an exchange and sequence 578 * fc_seq_exch_abort() - Abort an exchange and sequence
563 * @req_sp: The sequence to be aborted 579 * @req_sp: The sequence to be aborted
@@ -650,13 +666,10 @@ static void fc_exch_timeout(struct work_struct *work)
650 if (e_stat & ESB_ST_ABNORMAL) 666 if (e_stat & ESB_ST_ABNORMAL)
651 rc = fc_exch_done_locked(ep); 667 rc = fc_exch_done_locked(ep);
652 spin_unlock_bh(&ep->ex_lock); 668 spin_unlock_bh(&ep->ex_lock);
669 if (!rc)
670 fc_exch_delete(ep);
653 if (resp) 671 if (resp)
654 resp(sp, ERR_PTR(-FC_EX_TIMEOUT), arg); 672 resp(sp, ERR_PTR(-FC_EX_TIMEOUT), arg);
655 if (!rc) {
656 /* delete the exchange if it's already being aborted */
657 fc_exch_delete(ep);
658 return;
659 }
660 fc_seq_exch_abort(sp, 2 * ep->r_a_tov); 673 fc_seq_exch_abort(sp, 2 * ep->r_a_tov);
661 goto done; 674 goto done;
662 } 675 }
@@ -1266,6 +1279,8 @@ free:
1266 * @fp: The request frame 1279 * @fp: The request frame
1267 * 1280 *
1268 * On success, the sequence pointer will be returned and also in fr_seq(@fp). 1281 * On success, the sequence pointer will be returned and also in fr_seq(@fp).
1282 * A reference will be held on the exchange/sequence for the caller, which
1283 * must call fc_seq_release().
1269 */ 1284 */
1270static struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp) 1285static struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp)
1271{ 1286{
@@ -1283,6 +1298,15 @@ static struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp)
1283} 1298}
1284 1299
1285/** 1300/**
1301 * fc_seq_release() - Release the hold
1302 * @sp: The sequence.
1303 */
1304static void fc_seq_release(struct fc_seq *sp)
1305{
1306 fc_exch_release(fc_seq_exch(sp));
1307}
1308
1309/**
1286 * fc_exch_recv_req() - Handler for an incoming request 1310 * fc_exch_recv_req() - Handler for an incoming request
1287 * @lport: The local port that received the request 1311 * @lport: The local port that received the request
1288 * @mp: The EM that the exchange is on 1312 * @mp: The EM that the exchange is on
@@ -2151,6 +2175,7 @@ err:
2151 fc_exch_mgr_del(ema); 2175 fc_exch_mgr_del(ema);
2152 return -ENOMEM; 2176 return -ENOMEM;
2153} 2177}
2178EXPORT_SYMBOL(fc_exch_mgr_list_clone);
2154 2179
2155/** 2180/**
2156 * fc_exch_mgr_alloc() - Allocate an exchange manager 2181 * fc_exch_mgr_alloc() - Allocate an exchange manager
@@ -2254,16 +2279,45 @@ void fc_exch_mgr_free(struct fc_lport *lport)
2254EXPORT_SYMBOL(fc_exch_mgr_free); 2279EXPORT_SYMBOL(fc_exch_mgr_free);
2255 2280
2256/** 2281/**
2282 * fc_find_ema() - Lookup and return appropriate Exchange Manager Anchor depending
2283 * upon 'xid'.
2284 * @f_ctl: f_ctl
2285 * @lport: The local port the frame was received on
2286 * @fh: The received frame header
2287 */
2288static struct fc_exch_mgr_anchor *fc_find_ema(u32 f_ctl,
2289 struct fc_lport *lport,
2290 struct fc_frame_header *fh)
2291{
2292 struct fc_exch_mgr_anchor *ema;
2293 u16 xid;
2294
2295 if (f_ctl & FC_FC_EX_CTX)
2296 xid = ntohs(fh->fh_ox_id);
2297 else {
2298 xid = ntohs(fh->fh_rx_id);
2299 if (xid == FC_XID_UNKNOWN)
2300 return list_entry(lport->ema_list.prev,
2301 typeof(*ema), ema_list);
2302 }
2303
2304 list_for_each_entry(ema, &lport->ema_list, ema_list) {
2305 if ((xid >= ema->mp->min_xid) &&
2306 (xid <= ema->mp->max_xid))
2307 return ema;
2308 }
2309 return NULL;
2310}
2311/**
2257 * fc_exch_recv() - Handler for received frames 2312 * fc_exch_recv() - Handler for received frames
2258 * @lport: The local port the frame was received on 2313 * @lport: The local port the frame was received on
2259 * @fp: The received frame 2314 * @fp: The received frame
2260 */ 2315 */
2261void fc_exch_recv(struct fc_lport *lport, struct fc_frame *fp) 2316void fc_exch_recv(struct fc_lport *lport, struct fc_frame *fp)
2262{ 2317{
2263 struct fc_frame_header *fh = fc_frame_header_get(fp); 2318 struct fc_frame_header *fh = fc_frame_header_get(fp);
2264 struct fc_exch_mgr_anchor *ema; 2319 struct fc_exch_mgr_anchor *ema;
2265 u32 f_ctl, found = 0; 2320 u32 f_ctl;
2266 u16 oxid;
2267 2321
2268 /* lport lock ? */ 2322 /* lport lock ? */
2269 if (!lport || lport->state == LPORT_ST_DISABLED) { 2323 if (!lport || lport->state == LPORT_ST_DISABLED) {
@@ -2274,24 +2328,17 @@ void fc_exch_recv(struct fc_lport *lport, struct fc_frame *fp)
2274 } 2328 }
2275 2329
2276 f_ctl = ntoh24(fh->fh_f_ctl); 2330 f_ctl = ntoh24(fh->fh_f_ctl);
2277 oxid = ntohs(fh->fh_ox_id); 2331 ema = fc_find_ema(f_ctl, lport, fh);
2278 if (f_ctl & FC_FC_EX_CTX) { 2332 if (!ema) {
2279 list_for_each_entry(ema, &lport->ema_list, ema_list) { 2333 FC_LPORT_DBG(lport, "Unable to find Exchange Manager Anchor,"
2280 if ((oxid >= ema->mp->min_xid) && 2334 "fc_ctl <0x%x>, xid <0x%x>\n",
2281 (oxid <= ema->mp->max_xid)) { 2335 f_ctl,
2282 found = 1; 2336 (f_ctl & FC_FC_EX_CTX) ?
2283 break; 2337 ntohs(fh->fh_ox_id) :
2284 } 2338 ntohs(fh->fh_rx_id));
2285 } 2339 fc_frame_free(fp);
2286 2340 return;
2287 if (!found) { 2341 }
2288 FC_LPORT_DBG(lport, "Received response for out "
2289 "of range oxid:%hx\n", oxid);
2290 fc_frame_free(fp);
2291 return;
2292 }
2293 } else
2294 ema = list_entry(lport->ema_list.prev, typeof(*ema), ema_list);
2295 2342
2296 /* 2343 /*
2297 * If frame is marked invalid, just drop it. 2344 * If frame is marked invalid, just drop it.
@@ -2329,6 +2376,9 @@ int fc_exch_init(struct fc_lport *lport)
2329 if (!lport->tt.seq_start_next) 2376 if (!lport->tt.seq_start_next)
2330 lport->tt.seq_start_next = fc_seq_start_next; 2377 lport->tt.seq_start_next = fc_seq_start_next;
2331 2378
2379 if (!lport->tt.seq_set_resp)
2380 lport->tt.seq_set_resp = fc_seq_set_resp;
2381
2332 if (!lport->tt.exch_seq_send) 2382 if (!lport->tt.exch_seq_send)
2333 lport->tt.exch_seq_send = fc_exch_seq_send; 2383 lport->tt.exch_seq_send = fc_exch_seq_send;
2334 2384
@@ -2350,6 +2400,9 @@ int fc_exch_init(struct fc_lport *lport)
2350 if (!lport->tt.seq_assign) 2400 if (!lport->tt.seq_assign)
2351 lport->tt.seq_assign = fc_seq_assign; 2401 lport->tt.seq_assign = fc_seq_assign;
2352 2402
2403 if (!lport->tt.seq_release)
2404 lport->tt.seq_release = fc_seq_release;
2405
2353 return 0; 2406 return 0;
2354} 2407}
2355EXPORT_SYMBOL(fc_exch_init); 2408EXPORT_SYMBOL(fc_exch_init);
@@ -2357,7 +2410,7 @@ EXPORT_SYMBOL(fc_exch_init);
2357/** 2410/**
2358 * fc_setup_exch_mgr() - Setup an exchange manager 2411 * fc_setup_exch_mgr() - Setup an exchange manager
2359 */ 2412 */
2360int fc_setup_exch_mgr() 2413int fc_setup_exch_mgr(void)
2361{ 2414{
2362 fc_em_cachep = kmem_cache_create("libfc_em", sizeof(struct fc_exch), 2415 fc_em_cachep = kmem_cache_create("libfc_em", sizeof(struct fc_exch),
2363 0, SLAB_HWCACHE_ALIGN, NULL); 2416 0, SLAB_HWCACHE_ALIGN, NULL);
@@ -2395,7 +2448,7 @@ int fc_setup_exch_mgr()
2395/** 2448/**
2396 * fc_destroy_exch_mgr() - Destroy an exchange manager 2449 * fc_destroy_exch_mgr() - Destroy an exchange manager
2397 */ 2450 */
2398void fc_destroy_exch_mgr() 2451void fc_destroy_exch_mgr(void)
2399{ 2452{
2400 destroy_workqueue(fc_exch_workqueue); 2453 destroy_workqueue(fc_exch_workqueue);
2401 kmem_cache_destroy(fc_em_cachep); 2454 kmem_cache_destroy(fc_em_cachep);
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 5962d1a5a674..b1b03af158bf 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -42,7 +42,7 @@
42 42
43#include "fc_libfc.h" 43#include "fc_libfc.h"
44 44
45struct kmem_cache *scsi_pkt_cachep; 45static struct kmem_cache *scsi_pkt_cachep;
46 46
47/* SRB state definitions */ 47/* SRB state definitions */
48#define FC_SRB_FREE 0 /* cmd is free */ 48#define FC_SRB_FREE 0 /* cmd is free */
@@ -155,6 +155,7 @@ static struct fc_fcp_pkt *fc_fcp_pkt_alloc(struct fc_lport *lport, gfp_t gfp)
155 if (fsp) { 155 if (fsp) {
156 memset(fsp, 0, sizeof(*fsp)); 156 memset(fsp, 0, sizeof(*fsp));
157 fsp->lp = lport; 157 fsp->lp = lport;
158 fsp->xfer_ddp = FC_XID_UNKNOWN;
158 atomic_set(&fsp->ref_cnt, 1); 159 atomic_set(&fsp->ref_cnt, 1);
159 init_timer(&fsp->timer); 160 init_timer(&fsp->timer);
160 INIT_LIST_HEAD(&fsp->list); 161 INIT_LIST_HEAD(&fsp->list);
@@ -1201,6 +1202,7 @@ unlock:
1201static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp) 1202static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp)
1202{ 1203{
1203 int rc = FAILED; 1204 int rc = FAILED;
1205 unsigned long ticks_left;
1204 1206
1205 if (fc_fcp_send_abort(fsp)) 1207 if (fc_fcp_send_abort(fsp))
1206 return FAILED; 1208 return FAILED;
@@ -1209,13 +1211,13 @@ static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp)
1209 fsp->wait_for_comp = 1; 1211 fsp->wait_for_comp = 1;
1210 1212
1211 spin_unlock_bh(&fsp->scsi_pkt_lock); 1213 spin_unlock_bh(&fsp->scsi_pkt_lock);
1212 rc = wait_for_completion_timeout(&fsp->tm_done, FC_SCSI_TM_TOV); 1214 ticks_left = wait_for_completion_timeout(&fsp->tm_done,
1215 FC_SCSI_TM_TOV);
1213 spin_lock_bh(&fsp->scsi_pkt_lock); 1216 spin_lock_bh(&fsp->scsi_pkt_lock);
1214 fsp->wait_for_comp = 0; 1217 fsp->wait_for_comp = 0;
1215 1218
1216 if (!rc) { 1219 if (!ticks_left) {
1217 FC_FCP_DBG(fsp, "target abort cmd failed\n"); 1220 FC_FCP_DBG(fsp, "target abort cmd failed\n");
1218 rc = FAILED;
1219 } else if (fsp->state & FC_SRB_ABORTED) { 1221 } else if (fsp->state & FC_SRB_ABORTED) {
1220 FC_FCP_DBG(fsp, "target abort cmd passed\n"); 1222 FC_FCP_DBG(fsp, "target abort cmd passed\n");
1221 rc = SUCCESS; 1223 rc = SUCCESS;
@@ -1321,7 +1323,7 @@ static void fc_tm_done(struct fc_seq *seq, struct fc_frame *fp, void *arg)
1321 * 1323 *
1322 * scsi-eh will escalate for when either happens. 1324 * scsi-eh will escalate for when either happens.
1323 */ 1325 */
1324 goto out; 1326 return;
1325 } 1327 }
1326 1328
1327 if (fc_fcp_lock_pkt(fsp)) 1329 if (fc_fcp_lock_pkt(fsp))
@@ -1787,15 +1789,14 @@ static inline int fc_fcp_lport_queue_ready(struct fc_lport *lport)
1787 1789
1788/** 1790/**
1789 * fc_queuecommand() - The queuecommand function of the SCSI template 1791 * fc_queuecommand() - The queuecommand function of the SCSI template
1792 * @shost: The Scsi_Host that the command was issued to
1790 * @cmd: The scsi_cmnd to be executed 1793 * @cmd: The scsi_cmnd to be executed
1791 * @done: The callback function to be called when the scsi_cmnd is complete
1792 * 1794 *
1793 * This is the i/o strategy routine, called by the SCSI layer. This routine 1795 * This is the i/o strategy routine, called by the SCSI layer.
1794 * is called with the host_lock held.
1795 */ 1796 */
1796static int fc_queuecommand_lck(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) 1797int fc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *sc_cmd)
1797{ 1798{
1798 struct fc_lport *lport; 1799 struct fc_lport *lport = shost_priv(shost);
1799 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); 1800 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
1800 struct fc_fcp_pkt *fsp; 1801 struct fc_fcp_pkt *fsp;
1801 struct fc_rport_libfc_priv *rpriv; 1802 struct fc_rport_libfc_priv *rpriv;
@@ -1803,15 +1804,12 @@ static int fc_queuecommand_lck(struct scsi_cmnd *sc_cmd, void (*done)(struct scs
1803 int rc = 0; 1804 int rc = 0;
1804 struct fcoe_dev_stats *stats; 1805 struct fcoe_dev_stats *stats;
1805 1806
1806 lport = shost_priv(sc_cmd->device->host);
1807
1808 rval = fc_remote_port_chkready(rport); 1807 rval = fc_remote_port_chkready(rport);
1809 if (rval) { 1808 if (rval) {
1810 sc_cmd->result = rval; 1809 sc_cmd->result = rval;
1811 done(sc_cmd); 1810 sc_cmd->scsi_done(sc_cmd);
1812 return 0; 1811 return 0;
1813 } 1812 }
1814 spin_unlock_irq(lport->host->host_lock);
1815 1813
1816 if (!*(struct fc_remote_port **)rport->dd_data) { 1814 if (!*(struct fc_remote_port **)rport->dd_data) {
1817 /* 1815 /*
@@ -1819,7 +1817,7 @@ static int fc_queuecommand_lck(struct scsi_cmnd *sc_cmd, void (*done)(struct scs
1819 * online 1817 * online
1820 */ 1818 */
1821 sc_cmd->result = DID_IMM_RETRY << 16; 1819 sc_cmd->result = DID_IMM_RETRY << 16;
1822 done(sc_cmd); 1820 sc_cmd->scsi_done(sc_cmd);
1823 goto out; 1821 goto out;
1824 } 1822 }
1825 1823
@@ -1842,10 +1840,7 @@ static int fc_queuecommand_lck(struct scsi_cmnd *sc_cmd, void (*done)(struct scs
1842 * build the libfc request pkt 1840 * build the libfc request pkt
1843 */ 1841 */
1844 fsp->cmd = sc_cmd; /* save the cmd */ 1842 fsp->cmd = sc_cmd; /* save the cmd */
1845 fsp->lp = lport; /* save the softc ptr */
1846 fsp->rport = rport; /* set the remote port ptr */ 1843 fsp->rport = rport; /* set the remote port ptr */
1847 fsp->xfer_ddp = FC_XID_UNKNOWN;
1848 sc_cmd->scsi_done = done;
1849 1844
1850 /* 1845 /*
1851 * set up the transfer length 1846 * set up the transfer length
@@ -1886,11 +1881,8 @@ static int fc_queuecommand_lck(struct scsi_cmnd *sc_cmd, void (*done)(struct scs
1886 rc = SCSI_MLQUEUE_HOST_BUSY; 1881 rc = SCSI_MLQUEUE_HOST_BUSY;
1887 } 1882 }
1888out: 1883out:
1889 spin_lock_irq(lport->host->host_lock);
1890 return rc; 1884 return rc;
1891} 1885}
1892
1893DEF_SCSI_QCMD(fc_queuecommand)
1894EXPORT_SYMBOL(fc_queuecommand); 1886EXPORT_SYMBOL(fc_queuecommand);
1895 1887
1896/** 1888/**
@@ -2112,7 +2104,6 @@ int fc_eh_device_reset(struct scsi_cmnd *sc_cmd)
2112 * the sc passed in is not setup for execution like when sent 2104 * the sc passed in is not setup for execution like when sent
2113 * through the queuecommand callout. 2105 * through the queuecommand callout.
2114 */ 2106 */
2115 fsp->lp = lport; /* save the softc ptr */
2116 fsp->rport = rport; /* set the remote port ptr */ 2107 fsp->rport = rport; /* set the remote port ptr */
2117 2108
2118 /* 2109 /*
@@ -2245,7 +2236,7 @@ void fc_fcp_destroy(struct fc_lport *lport)
2245} 2236}
2246EXPORT_SYMBOL(fc_fcp_destroy); 2237EXPORT_SYMBOL(fc_fcp_destroy);
2247 2238
2248int fc_setup_fcp() 2239int fc_setup_fcp(void)
2249{ 2240{
2250 int rc = 0; 2241 int rc = 0;
2251 2242
@@ -2261,7 +2252,7 @@ int fc_setup_fcp()
2261 return rc; 2252 return rc;
2262} 2253}
2263 2254
2264void fc_destroy_fcp() 2255void fc_destroy_fcp(void)
2265{ 2256{
2266 if (scsi_pkt_cachep) 2257 if (scsi_pkt_cachep)
2267 kmem_cache_destroy(scsi_pkt_cachep); 2258 kmem_cache_destroy(scsi_pkt_cachep);
diff --git a/drivers/scsi/libfc/fc_libfc.c b/drivers/scsi/libfc/fc_libfc.c
index 6a48c28e4420..b7735129f1f3 100644
--- a/drivers/scsi/libfc/fc_libfc.c
+++ b/drivers/scsi/libfc/fc_libfc.c
@@ -35,6 +35,27 @@ unsigned int fc_debug_logging;
35module_param_named(debug_logging, fc_debug_logging, int, S_IRUGO|S_IWUSR); 35module_param_named(debug_logging, fc_debug_logging, int, S_IRUGO|S_IWUSR);
36MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels"); 36MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
37 37
38DEFINE_MUTEX(fc_prov_mutex);
39static LIST_HEAD(fc_local_ports);
40struct blocking_notifier_head fc_lport_notifier_head =
41 BLOCKING_NOTIFIER_INIT(fc_lport_notifier_head);
42EXPORT_SYMBOL(fc_lport_notifier_head);
43
44/*
45 * Providers which primarily send requests and PRLIs.
46 */
47struct fc4_prov *fc_active_prov[FC_FC4_PROV_SIZE] = {
48 [0] = &fc_rport_t0_prov,
49 [FC_TYPE_FCP] = &fc_rport_fcp_init,
50};
51
52/*
53 * Providers which receive requests.
54 */
55struct fc4_prov *fc_passive_prov[FC_FC4_PROV_SIZE] = {
56 [FC_TYPE_ELS] = &fc_lport_els_prov,
57};
58
38/** 59/**
39 * libfc_init() - Initialize libfc.ko 60 * libfc_init() - Initialize libfc.ko
40 */ 61 */
@@ -210,3 +231,102 @@ void fc_fill_reply_hdr(struct fc_frame *fp, const struct fc_frame *in_fp,
210 fc_fill_hdr(fp, in_fp, r_ctl, FC_FCTL_RESP, 0, parm_offset); 231 fc_fill_hdr(fp, in_fp, r_ctl, FC_FCTL_RESP, 0, parm_offset);
211} 232}
212EXPORT_SYMBOL(fc_fill_reply_hdr); 233EXPORT_SYMBOL(fc_fill_reply_hdr);
234
235/**
236 * fc_fc4_conf_lport_params() - Modify "service_params" of specified lport
237 * if there is service provider (target provider) registered with libfc
238 * for specified "fc_ft_type"
239 * @lport: Local port which service_params needs to be modified
240 * @type: FC-4 type, such as FC_TYPE_FCP
241 */
242void fc_fc4_conf_lport_params(struct fc_lport *lport, enum fc_fh_type type)
243{
244 struct fc4_prov *prov_entry;
245 BUG_ON(type >= FC_FC4_PROV_SIZE);
246 BUG_ON(!lport);
247 prov_entry = fc_passive_prov[type];
248 if (type == FC_TYPE_FCP) {
249 if (prov_entry && prov_entry->recv)
250 lport->service_params |= FCP_SPPF_TARG_FCN;
251 }
252}
253
254void fc_lport_iterate(void (*notify)(struct fc_lport *, void *), void *arg)
255{
256 struct fc_lport *lport;
257
258 mutex_lock(&fc_prov_mutex);
259 list_for_each_entry(lport, &fc_local_ports, lport_list)
260 notify(lport, arg);
261 mutex_unlock(&fc_prov_mutex);
262}
263EXPORT_SYMBOL(fc_lport_iterate);
264
265/**
266 * fc_fc4_register_provider() - register FC-4 upper-level provider.
267 * @type: FC-4 type, such as FC_TYPE_FCP
268 * @prov: structure describing provider including ops vector.
269 *
270 * Returns 0 on success, negative error otherwise.
271 */
272int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *prov)
273{
274 struct fc4_prov **prov_entry;
275 int ret = 0;
276
277 if (type >= FC_FC4_PROV_SIZE)
278 return -EINVAL;
279 mutex_lock(&fc_prov_mutex);
280 prov_entry = (prov->recv ? fc_passive_prov : fc_active_prov) + type;
281 if (*prov_entry)
282 ret = -EBUSY;
283 else
284 *prov_entry = prov;
285 mutex_unlock(&fc_prov_mutex);
286 return ret;
287}
288EXPORT_SYMBOL(fc_fc4_register_provider);
289
290/**
291 * fc_fc4_deregister_provider() - deregister FC-4 upper-level provider.
292 * @type: FC-4 type, such as FC_TYPE_FCP
293 * @prov: structure describing provider including ops vector.
294 */
295void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *prov)
296{
297 BUG_ON(type >= FC_FC4_PROV_SIZE);
298 mutex_lock(&fc_prov_mutex);
299 if (prov->recv)
300 rcu_assign_pointer(fc_passive_prov[type], NULL);
301 else
302 rcu_assign_pointer(fc_active_prov[type], NULL);
303 mutex_unlock(&fc_prov_mutex);
304 synchronize_rcu();
305}
306EXPORT_SYMBOL(fc_fc4_deregister_provider);
307
308/**
309 * fc_fc4_add_lport() - add new local port to list and run notifiers.
310 * @lport: The new local port.
311 */
312void fc_fc4_add_lport(struct fc_lport *lport)
313{
314 mutex_lock(&fc_prov_mutex);
315 list_add_tail(&lport->lport_list, &fc_local_ports);
316 blocking_notifier_call_chain(&fc_lport_notifier_head,
317 FC_LPORT_EV_ADD, lport);
318 mutex_unlock(&fc_prov_mutex);
319}
320
321/**
322 * fc_fc4_del_lport() - remove local port from list and run notifiers.
323 * @lport: The new local port.
324 */
325void fc_fc4_del_lport(struct fc_lport *lport)
326{
327 mutex_lock(&fc_prov_mutex);
328 list_del(&lport->lport_list);
329 blocking_notifier_call_chain(&fc_lport_notifier_head,
330 FC_LPORT_EV_DEL, lport);
331 mutex_unlock(&fc_prov_mutex);
332}
diff --git a/drivers/scsi/libfc/fc_libfc.h b/drivers/scsi/libfc/fc_libfc.h
index eea0c3541b71..fedc819d70c0 100644
--- a/drivers/scsi/libfc/fc_libfc.h
+++ b/drivers/scsi/libfc/fc_libfc.h
@@ -94,6 +94,17 @@ extern unsigned int fc_debug_logging;
94 (lport)->host->host_no, ##args)) 94 (lport)->host->host_no, ##args))
95 95
96/* 96/*
97 * FC-4 Providers.
98 */
99extern struct fc4_prov *fc_active_prov[]; /* providers without recv */
100extern struct fc4_prov *fc_passive_prov[]; /* providers with recv */
101extern struct mutex fc_prov_mutex; /* lock over table changes */
102
103extern struct fc4_prov fc_rport_t0_prov; /* type 0 provider */
104extern struct fc4_prov fc_lport_els_prov; /* ELS provider */
105extern struct fc4_prov fc_rport_fcp_init; /* FCP initiator provider */
106
107/*
97 * Set up direct-data placement for this I/O request 108 * Set up direct-data placement for this I/O request
98 */ 109 */
99void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid); 110void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid);
@@ -112,6 +123,9 @@ void fc_destroy_fcp(void);
112 * Internal libfc functions 123 * Internal libfc functions
113 */ 124 */
114const char *fc_els_resp_type(struct fc_frame *); 125const char *fc_els_resp_type(struct fc_frame *);
126extern void fc_fc4_add_lport(struct fc_lport *);
127extern void fc_fc4_del_lport(struct fc_lport *);
128extern void fc_fc4_conf_lport_params(struct fc_lport *, enum fc_fh_type);
115 129
116/* 130/*
117 * Copies a buffer into an sg list 131 * Copies a buffer into an sg list
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index c5a10f94f845..8c08b210001d 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -633,6 +633,7 @@ int fc_lport_destroy(struct fc_lport *lport)
633 lport->tt.fcp_abort_io(lport); 633 lport->tt.fcp_abort_io(lport);
634 lport->tt.disc_stop_final(lport); 634 lport->tt.disc_stop_final(lport);
635 lport->tt.exch_mgr_reset(lport, 0, 0); 635 lport->tt.exch_mgr_reset(lport, 0, 0);
636 fc_fc4_del_lport(lport);
636 return 0; 637 return 0;
637} 638}
638EXPORT_SYMBOL(fc_lport_destroy); 639EXPORT_SYMBOL(fc_lport_destroy);
@@ -849,7 +850,7 @@ out:
849} 850}
850 851
851/** 852/**
852 * fc_lport_recv_req() - The generic lport request handler 853 * fc_lport_recv_els_req() - The generic lport ELS request handler
853 * @lport: The local port that received the request 854 * @lport: The local port that received the request
854 * @fp: The request frame 855 * @fp: The request frame
855 * 856 *
@@ -859,9 +860,9 @@ out:
859 * Locking Note: This function should not be called with the lport 860 * Locking Note: This function should not be called with the lport
860 * lock held becuase it will grab the lock. 861 * lock held becuase it will grab the lock.
861 */ 862 */
862static void fc_lport_recv_req(struct fc_lport *lport, struct fc_frame *fp) 863static void fc_lport_recv_els_req(struct fc_lport *lport,
864 struct fc_frame *fp)
863{ 865{
864 struct fc_frame_header *fh = fc_frame_header_get(fp);
865 void (*recv)(struct fc_lport *, struct fc_frame *); 866 void (*recv)(struct fc_lport *, struct fc_frame *);
866 867
867 mutex_lock(&lport->lp_mutex); 868 mutex_lock(&lport->lp_mutex);
@@ -873,8 +874,7 @@ static void fc_lport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
873 */ 874 */
874 if (!lport->link_up) 875 if (!lport->link_up)
875 fc_frame_free(fp); 876 fc_frame_free(fp);
876 else if (fh->fh_type == FC_TYPE_ELS && 877 else {
877 fh->fh_r_ctl == FC_RCTL_ELS_REQ) {
878 /* 878 /*
879 * Check opcode. 879 * Check opcode.
880 */ 880 */
@@ -903,14 +903,62 @@ static void fc_lport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
903 } 903 }
904 904
905 recv(lport, fp); 905 recv(lport, fp);
906 } else {
907 FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)\n",
908 fr_eof(fp));
909 fc_frame_free(fp);
910 } 906 }
911 mutex_unlock(&lport->lp_mutex); 907 mutex_unlock(&lport->lp_mutex);
912} 908}
913 909
910static int fc_lport_els_prli(struct fc_rport_priv *rdata, u32 spp_len,
911 const struct fc_els_spp *spp_in,
912 struct fc_els_spp *spp_out)
913{
914 return FC_SPP_RESP_INVL;
915}
916
917struct fc4_prov fc_lport_els_prov = {
918 .prli = fc_lport_els_prli,
919 .recv = fc_lport_recv_els_req,
920};
921
922/**
923 * fc_lport_recv_req() - The generic lport request handler
924 * @lport: The lport that received the request
925 * @fp: The frame the request is in
926 *
927 * Locking Note: This function should not be called with the lport
928 * lock held becuase it may grab the lock.
929 */
930static void fc_lport_recv_req(struct fc_lport *lport,
931 struct fc_frame *fp)
932{
933 struct fc_frame_header *fh = fc_frame_header_get(fp);
934 struct fc_seq *sp = fr_seq(fp);
935 struct fc4_prov *prov;
936
937 /*
938 * Use RCU read lock and module_lock to be sure module doesn't
939 * deregister and get unloaded while we're calling it.
940 * try_module_get() is inlined and accepts a NULL parameter.
941 * Only ELSes and FCP target ops should come through here.
942 * The locking is unfortunate, and a better scheme is being sought.
943 */
944
945 rcu_read_lock();
946 if (fh->fh_type >= FC_FC4_PROV_SIZE)
947 goto drop;
948 prov = rcu_dereference(fc_passive_prov[fh->fh_type]);
949 if (!prov || !try_module_get(prov->module))
950 goto drop;
951 rcu_read_unlock();
952 prov->recv(lport, fp);
953 module_put(prov->module);
954 return;
955drop:
956 rcu_read_unlock();
957 FC_LPORT_DBG(lport, "dropping unexpected frame type %x\n", fh->fh_type);
958 fc_frame_free(fp);
959 lport->tt.exch_done(sp);
960}
961
914/** 962/**
915 * fc_lport_reset() - Reset a local port 963 * fc_lport_reset() - Reset a local port
916 * @lport: The local port which should be reset 964 * @lport: The local port which should be reset
@@ -1542,6 +1590,7 @@ void fc_lport_enter_flogi(struct fc_lport *lport)
1542 */ 1590 */
1543int fc_lport_config(struct fc_lport *lport) 1591int fc_lport_config(struct fc_lport *lport)
1544{ 1592{
1593 INIT_LIST_HEAD(&lport->ema_list);
1545 INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout); 1594 INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout);
1546 mutex_init(&lport->lp_mutex); 1595 mutex_init(&lport->lp_mutex);
1547 1596
@@ -1549,6 +1598,7 @@ int fc_lport_config(struct fc_lport *lport)
1549 1598
1550 fc_lport_add_fc4_type(lport, FC_TYPE_FCP); 1599 fc_lport_add_fc4_type(lport, FC_TYPE_FCP);
1551 fc_lport_add_fc4_type(lport, FC_TYPE_CT); 1600 fc_lport_add_fc4_type(lport, FC_TYPE_CT);
1601 fc_fc4_conf_lport_params(lport, FC_TYPE_FCP);
1552 1602
1553 return 0; 1603 return 0;
1554} 1604}
@@ -1586,6 +1636,7 @@ int fc_lport_init(struct fc_lport *lport)
1586 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT; 1636 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT;
1587 if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT) 1637 if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT)
1588 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT; 1638 fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT;
1639 fc_fc4_add_lport(lport);
1589 1640
1590 return 0; 1641 return 0;
1591} 1642}
diff --git a/drivers/scsi/libfc/fc_npiv.c b/drivers/scsi/libfc/fc_npiv.c
index dd2b43bb1c70..f33b897e4784 100644
--- a/drivers/scsi/libfc/fc_npiv.c
+++ b/drivers/scsi/libfc/fc_npiv.c
@@ -37,9 +37,7 @@ struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
37 37
38 vn_port = libfc_host_alloc(shost->hostt, privsize); 38 vn_port = libfc_host_alloc(shost->hostt, privsize);
39 if (!vn_port) 39 if (!vn_port)
40 goto err_out; 40 return vn_port;
41 if (fc_exch_mgr_list_clone(n_port, vn_port))
42 goto err_put;
43 41
44 vn_port->vport = vport; 42 vn_port->vport = vport;
45 vport->dd_data = vn_port; 43 vport->dd_data = vn_port;
@@ -49,11 +47,6 @@ struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
49 mutex_unlock(&n_port->lp_mutex); 47 mutex_unlock(&n_port->lp_mutex);
50 48
51 return vn_port; 49 return vn_port;
52
53err_put:
54 scsi_host_put(vn_port->host);
55err_out:
56 return NULL;
57} 50}
58EXPORT_SYMBOL(libfc_vport_create); 51EXPORT_SYMBOL(libfc_vport_create);
59 52
@@ -86,6 +79,7 @@ struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id)
86 79
87 return lport; 80 return lport;
88} 81}
82EXPORT_SYMBOL(fc_vport_id_lookup);
89 83
90/* 84/*
91 * When setting the link state of vports during an lport state change, it's 85 * When setting the link state of vports during an lport state change, it's
diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index a7175adab32d..49e1ccca09d5 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -58,7 +58,7 @@
58 58
59#include "fc_libfc.h" 59#include "fc_libfc.h"
60 60
61struct workqueue_struct *rport_event_queue; 61static struct workqueue_struct *rport_event_queue;
62 62
63static void fc_rport_enter_flogi(struct fc_rport_priv *); 63static void fc_rport_enter_flogi(struct fc_rport_priv *);
64static void fc_rport_enter_plogi(struct fc_rport_priv *); 64static void fc_rport_enter_plogi(struct fc_rport_priv *);
@@ -145,8 +145,10 @@ static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport,
145 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD; 145 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
146 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout); 146 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
147 INIT_WORK(&rdata->event_work, fc_rport_work); 147 INIT_WORK(&rdata->event_work, fc_rport_work);
148 if (port_id != FC_FID_DIR_SERV) 148 if (port_id != FC_FID_DIR_SERV) {
149 rdata->lld_event_callback = lport->tt.rport_event_callback;
149 list_add_rcu(&rdata->peers, &lport->disc.rports); 150 list_add_rcu(&rdata->peers, &lport->disc.rports);
151 }
150 return rdata; 152 return rdata;
151} 153}
152 154
@@ -257,6 +259,8 @@ static void fc_rport_work(struct work_struct *work)
257 struct fc_rport_operations *rport_ops; 259 struct fc_rport_operations *rport_ops;
258 struct fc_rport_identifiers ids; 260 struct fc_rport_identifiers ids;
259 struct fc_rport *rport; 261 struct fc_rport *rport;
262 struct fc4_prov *prov;
263 u8 type;
260 264
261 mutex_lock(&rdata->rp_mutex); 265 mutex_lock(&rdata->rp_mutex);
262 event = rdata->event; 266 event = rdata->event;
@@ -300,12 +304,25 @@ static void fc_rport_work(struct work_struct *work)
300 FC_RPORT_DBG(rdata, "callback ev %d\n", event); 304 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
301 rport_ops->event_callback(lport, rdata, event); 305 rport_ops->event_callback(lport, rdata, event);
302 } 306 }
307 if (rdata->lld_event_callback) {
308 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
309 rdata->lld_event_callback(lport, rdata, event);
310 }
303 kref_put(&rdata->kref, lport->tt.rport_destroy); 311 kref_put(&rdata->kref, lport->tt.rport_destroy);
304 break; 312 break;
305 313
306 case RPORT_EV_FAILED: 314 case RPORT_EV_FAILED:
307 case RPORT_EV_LOGO: 315 case RPORT_EV_LOGO:
308 case RPORT_EV_STOP: 316 case RPORT_EV_STOP:
317 if (rdata->prli_count) {
318 mutex_lock(&fc_prov_mutex);
319 for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
320 prov = fc_passive_prov[type];
321 if (prov && prov->prlo)
322 prov->prlo(rdata);
323 }
324 mutex_unlock(&fc_prov_mutex);
325 }
309 port_id = rdata->ids.port_id; 326 port_id = rdata->ids.port_id;
310 mutex_unlock(&rdata->rp_mutex); 327 mutex_unlock(&rdata->rp_mutex);
311 328
@@ -313,6 +330,10 @@ static void fc_rport_work(struct work_struct *work)
313 FC_RPORT_DBG(rdata, "callback ev %d\n", event); 330 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
314 rport_ops->event_callback(lport, rdata, event); 331 rport_ops->event_callback(lport, rdata, event);
315 } 332 }
333 if (rdata->lld_event_callback) {
334 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
335 rdata->lld_event_callback(lport, rdata, event);
336 }
316 cancel_delayed_work_sync(&rdata->retry_work); 337 cancel_delayed_work_sync(&rdata->retry_work);
317 338
318 /* 339 /*
@@ -336,6 +357,7 @@ static void fc_rport_work(struct work_struct *work)
336 if (port_id == FC_FID_DIR_SERV) { 357 if (port_id == FC_FID_DIR_SERV) {
337 rdata->event = RPORT_EV_NONE; 358 rdata->event = RPORT_EV_NONE;
338 mutex_unlock(&rdata->rp_mutex); 359 mutex_unlock(&rdata->rp_mutex);
360 kref_put(&rdata->kref, lport->tt.rport_destroy);
339 } else if ((rdata->flags & FC_RP_STARTED) && 361 } else if ((rdata->flags & FC_RP_STARTED) &&
340 rdata->major_retries < 362 rdata->major_retries <
341 lport->max_rport_retry_count) { 363 lport->max_rport_retry_count) {
@@ -575,7 +597,7 @@ static void fc_rport_error_retry(struct fc_rport_priv *rdata,
575 597
576 /* make sure this isn't an FC_EX_CLOSED error, never retry those */ 598 /* make sure this isn't an FC_EX_CLOSED error, never retry those */
577 if (PTR_ERR(fp) == -FC_EX_CLOSED) 599 if (PTR_ERR(fp) == -FC_EX_CLOSED)
578 return fc_rport_error(rdata, fp); 600 goto out;
579 601
580 if (rdata->retries < rdata->local_port->max_rport_retry_count) { 602 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
581 FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n", 603 FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n",
@@ -588,7 +610,8 @@ static void fc_rport_error_retry(struct fc_rport_priv *rdata,
588 return; 610 return;
589 } 611 }
590 612
591 return fc_rport_error(rdata, fp); 613out:
614 fc_rport_error(rdata, fp);
592} 615}
593 616
594/** 617/**
@@ -878,6 +901,9 @@ static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
878 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn); 901 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
879 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn); 902 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
880 903
904 /* save plogi response sp_features for further reference */
905 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
906
881 if (lport->point_to_multipoint) 907 if (lport->point_to_multipoint)
882 fc_rport_login_complete(rdata, fp); 908 fc_rport_login_complete(rdata, fp);
883 csp_seq = ntohs(plp->fl_csp.sp_tot_seq); 909 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
@@ -949,6 +975,8 @@ static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
949 struct fc_els_prli prli; 975 struct fc_els_prli prli;
950 struct fc_els_spp spp; 976 struct fc_els_spp spp;
951 } *pp; 977 } *pp;
978 struct fc_els_spp temp_spp;
979 struct fc4_prov *prov;
952 u32 roles = FC_RPORT_ROLE_UNKNOWN; 980 u32 roles = FC_RPORT_ROLE_UNKNOWN;
953 u32 fcp_parm = 0; 981 u32 fcp_parm = 0;
954 u8 op; 982 u8 op;
@@ -983,6 +1011,7 @@ static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
983 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK); 1011 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
984 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n", 1012 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n",
985 pp->spp.spp_flags); 1013 pp->spp.spp_flags);
1014 rdata->spp_type = pp->spp.spp_type;
986 if (resp_code != FC_SPP_RESP_ACK) { 1015 if (resp_code != FC_SPP_RESP_ACK) {
987 if (resp_code == FC_SPP_RESP_CONF) 1016 if (resp_code == FC_SPP_RESP_CONF)
988 fc_rport_error(rdata, fp); 1017 fc_rport_error(rdata, fp);
@@ -996,6 +1025,15 @@ static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
996 fcp_parm = ntohl(pp->spp.spp_params); 1025 fcp_parm = ntohl(pp->spp.spp_params);
997 if (fcp_parm & FCP_SPPF_RETRY) 1026 if (fcp_parm & FCP_SPPF_RETRY)
998 rdata->flags |= FC_RP_FLAGS_RETRY; 1027 rdata->flags |= FC_RP_FLAGS_RETRY;
1028 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1029 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
1030
1031 prov = fc_passive_prov[FC_TYPE_FCP];
1032 if (prov) {
1033 memset(&temp_spp, 0, sizeof(temp_spp));
1034 prov->prli(rdata, pp->prli.prli_spp_len,
1035 &pp->spp, &temp_spp);
1036 }
999 1037
1000 rdata->supported_classes = FC_COS_CLASS3; 1038 rdata->supported_classes = FC_COS_CLASS3;
1001 if (fcp_parm & FCP_SPPF_INIT_FCN) 1039 if (fcp_parm & FCP_SPPF_INIT_FCN)
@@ -1033,6 +1071,7 @@ static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
1033 struct fc_els_spp spp; 1071 struct fc_els_spp spp;
1034 } *pp; 1072 } *pp;
1035 struct fc_frame *fp; 1073 struct fc_frame *fp;
1074 struct fc4_prov *prov;
1036 1075
1037 /* 1076 /*
1038 * If the rport is one of the well known addresses 1077 * If the rport is one of the well known addresses
@@ -1054,9 +1093,20 @@ static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
1054 return; 1093 return;
1055 } 1094 }
1056 1095
1057 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PRLI, 1096 fc_prli_fill(lport, fp);
1058 fc_rport_prli_resp, rdata, 1097
1059 2 * lport->r_a_tov)) 1098 prov = fc_passive_prov[FC_TYPE_FCP];
1099 if (prov) {
1100 pp = fc_frame_payload_get(fp, sizeof(*pp));
1101 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1102 }
1103
1104 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1105 fc_host_port_id(lport->host), FC_TYPE_ELS,
1106 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1107
1108 if (!lport->tt.exch_seq_send(lport, fp, fc_rport_prli_resp,
1109 NULL, rdata, 2 * lport->r_a_tov))
1060 fc_rport_error_retry(rdata, NULL); 1110 fc_rport_error_retry(rdata, NULL);
1061 else 1111 else
1062 kref_get(&rdata->kref); 1112 kref_get(&rdata->kref);
@@ -1642,9 +1692,9 @@ static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
1642 unsigned int len; 1692 unsigned int len;
1643 unsigned int plen; 1693 unsigned int plen;
1644 enum fc_els_spp_resp resp; 1694 enum fc_els_spp_resp resp;
1695 enum fc_els_spp_resp passive;
1645 struct fc_seq_els_data rjt_data; 1696 struct fc_seq_els_data rjt_data;
1646 u32 fcp_parm; 1697 struct fc4_prov *prov;
1647 u32 roles = FC_RPORT_ROLE_UNKNOWN;
1648 1698
1649 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n", 1699 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1650 fc_rport_state(rdata)); 1700 fc_rport_state(rdata));
@@ -1678,46 +1728,42 @@ static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
1678 pp->prli.prli_len = htons(len); 1728 pp->prli.prli_len = htons(len);
1679 len -= sizeof(struct fc_els_prli); 1729 len -= sizeof(struct fc_els_prli);
1680 1730
1681 /* reinitialize remote port roles */
1682 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1683
1684 /* 1731 /*
1685 * Go through all the service parameter pages and build 1732 * Go through all the service parameter pages and build
1686 * response. If plen indicates longer SPP than standard, 1733 * response. If plen indicates longer SPP than standard,
1687 * use that. The entire response has been pre-cleared above. 1734 * use that. The entire response has been pre-cleared above.
1688 */ 1735 */
1689 spp = &pp->spp; 1736 spp = &pp->spp;
1737 mutex_lock(&fc_prov_mutex);
1690 while (len >= plen) { 1738 while (len >= plen) {
1739 rdata->spp_type = rspp->spp_type;
1691 spp->spp_type = rspp->spp_type; 1740 spp->spp_type = rspp->spp_type;
1692 spp->spp_type_ext = rspp->spp_type_ext; 1741 spp->spp_type_ext = rspp->spp_type_ext;
1693 spp->spp_flags = rspp->spp_flags & FC_SPP_EST_IMG_PAIR; 1742 resp = 0;
1694 resp = FC_SPP_RESP_ACK; 1743
1695 1744 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
1696 switch (rspp->spp_type) { 1745 prov = fc_active_prov[rspp->spp_type];
1697 case 0: /* common to all FC-4 types */ 1746 if (prov)
1698 break; 1747 resp = prov->prli(rdata, plen, rspp, spp);
1699 case FC_TYPE_FCP: 1748 prov = fc_passive_prov[rspp->spp_type];
1700 fcp_parm = ntohl(rspp->spp_params); 1749 if (prov) {
1701 if (fcp_parm & FCP_SPPF_RETRY) 1750 passive = prov->prli(rdata, plen, rspp, spp);
1702 rdata->flags |= FC_RP_FLAGS_RETRY; 1751 if (!resp || passive == FC_SPP_RESP_ACK)
1703 rdata->supported_classes = FC_COS_CLASS3; 1752 resp = passive;
1704 if (fcp_parm & FCP_SPPF_INIT_FCN) 1753 }
1705 roles |= FC_RPORT_ROLE_FCP_INITIATOR; 1754 }
1706 if (fcp_parm & FCP_SPPF_TARG_FCN) 1755 if (!resp) {
1707 roles |= FC_RPORT_ROLE_FCP_TARGET; 1756 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
1708 rdata->ids.roles = roles; 1757 resp |= FC_SPP_RESP_CONF;
1709 1758 else
1710 spp->spp_params = htonl(lport->service_params); 1759 resp |= FC_SPP_RESP_INVL;
1711 break;
1712 default:
1713 resp = FC_SPP_RESP_INVL;
1714 break;
1715 } 1760 }
1716 spp->spp_flags |= resp; 1761 spp->spp_flags |= resp;
1717 len -= plen; 1762 len -= plen;
1718 rspp = (struct fc_els_spp *)((char *)rspp + plen); 1763 rspp = (struct fc_els_spp *)((char *)rspp + plen);
1719 spp = (struct fc_els_spp *)((char *)spp + plen); 1764 spp = (struct fc_els_spp *)((char *)spp + plen);
1720 } 1765 }
1766 mutex_unlock(&fc_prov_mutex);
1721 1767
1722 /* 1768 /*
1723 * Send LS_ACC. If this fails, the originator should retry. 1769 * Send LS_ACC. If this fails, the originator should retry.
@@ -1887,9 +1933,82 @@ int fc_rport_init(struct fc_lport *lport)
1887EXPORT_SYMBOL(fc_rport_init); 1933EXPORT_SYMBOL(fc_rport_init);
1888 1934
1889/** 1935/**
1936 * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
1937 * @rdata: remote port private
1938 * @spp_len: service parameter page length
1939 * @rspp: received service parameter page
1940 * @spp: response service parameter page
1941 *
1942 * Returns the value for the response code to be placed in spp_flags;
1943 * Returns 0 if not an initiator.
1944 */
1945static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
1946 const struct fc_els_spp *rspp,
1947 struct fc_els_spp *spp)
1948{
1949 struct fc_lport *lport = rdata->local_port;
1950 u32 fcp_parm;
1951
1952 fcp_parm = ntohl(rspp->spp_params);
1953 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1954 if (fcp_parm & FCP_SPPF_INIT_FCN)
1955 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1956 if (fcp_parm & FCP_SPPF_TARG_FCN)
1957 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1958 if (fcp_parm & FCP_SPPF_RETRY)
1959 rdata->flags |= FC_RP_FLAGS_RETRY;
1960 rdata->supported_classes = FC_COS_CLASS3;
1961
1962 if (!(lport->service_params & FC_RPORT_ROLE_FCP_INITIATOR))
1963 return 0;
1964
1965 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
1966
1967 /*
1968 * OR in our service parameters with other providers (target), if any.
1969 */
1970 fcp_parm = ntohl(spp->spp_params);
1971 spp->spp_params = htonl(fcp_parm | lport->service_params);
1972 return FC_SPP_RESP_ACK;
1973}
1974
1975/*
1976 * FC-4 provider ops for FCP initiator.
1977 */
1978struct fc4_prov fc_rport_fcp_init = {
1979 .prli = fc_rport_fcp_prli,
1980};
1981
1982/**
1983 * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
1984 * @rdata: remote port private
1985 * @spp_len: service parameter page length
1986 * @rspp: received service parameter page
1987 * @spp: response service parameter page
1988 */
1989static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
1990 const struct fc_els_spp *rspp,
1991 struct fc_els_spp *spp)
1992{
1993 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
1994 return FC_SPP_RESP_INVL;
1995 return FC_SPP_RESP_ACK;
1996}
1997
1998/*
1999 * FC-4 provider ops for type 0 service parameters.
2000 *
2001 * This handles the special case of type 0 which is always successful
2002 * but doesn't do anything otherwise.
2003 */
2004struct fc4_prov fc_rport_t0_prov = {
2005 .prli = fc_rport_t0_prli,
2006};
2007
2008/**
1890 * fc_setup_rport() - Initialize the rport_event_queue 2009 * fc_setup_rport() - Initialize the rport_event_queue
1891 */ 2010 */
1892int fc_setup_rport() 2011int fc_setup_rport(void)
1893{ 2012{
1894 rport_event_queue = create_singlethread_workqueue("fc_rport_eq"); 2013 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
1895 if (!rport_event_queue) 2014 if (!rport_event_queue)
@@ -1900,7 +2019,7 @@ int fc_setup_rport()
1900/** 2019/**
1901 * fc_destroy_rport() - Destroy the rport_event_queue 2020 * fc_destroy_rport() - Destroy the rport_event_queue
1902 */ 2021 */
1903void fc_destroy_rport() 2022void fc_destroy_rport(void)
1904{ 2023{
1905 destroy_workqueue(rport_event_queue); 2024 destroy_workqueue(rport_event_queue);
1906} 2025}
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index da8b61543ee4..0c550d5b9133 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -3352,6 +3352,47 @@ int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
3352} 3352}
3353EXPORT_SYMBOL_GPL(iscsi_session_get_param); 3353EXPORT_SYMBOL_GPL(iscsi_session_get_param);
3354 3354
3355int iscsi_conn_get_addr_param(struct sockaddr_storage *addr,
3356 enum iscsi_param param, char *buf)
3357{
3358 struct sockaddr_in6 *sin6 = NULL;
3359 struct sockaddr_in *sin = NULL;
3360 int len;
3361
3362 switch (addr->ss_family) {
3363 case AF_INET:
3364 sin = (struct sockaddr_in *)addr;
3365 break;
3366 case AF_INET6:
3367 sin6 = (struct sockaddr_in6 *)addr;
3368 break;
3369 default:
3370 return -EINVAL;
3371 }
3372
3373 switch (param) {
3374 case ISCSI_PARAM_CONN_ADDRESS:
3375 case ISCSI_HOST_PARAM_IPADDRESS:
3376 if (sin)
3377 len = sprintf(buf, "%pI4\n", &sin->sin_addr.s_addr);
3378 else
3379 len = sprintf(buf, "%pI6\n", &sin6->sin6_addr);
3380 break;
3381 case ISCSI_PARAM_CONN_PORT:
3382 if (sin)
3383 len = sprintf(buf, "%hu\n", be16_to_cpu(sin->sin_port));
3384 else
3385 len = sprintf(buf, "%hu\n",
3386 be16_to_cpu(sin6->sin6_port));
3387 break;
3388 default:
3389 return -EINVAL;
3390 }
3391
3392 return len;
3393}
3394EXPORT_SYMBOL_GPL(iscsi_conn_get_addr_param);
3395
3355int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn, 3396int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
3356 enum iscsi_param param, char *buf) 3397 enum iscsi_param param, char *buf)
3357{ 3398{
@@ -3416,9 +3457,6 @@ int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
3416 case ISCSI_HOST_PARAM_INITIATOR_NAME: 3457 case ISCSI_HOST_PARAM_INITIATOR_NAME:
3417 len = sprintf(buf, "%s\n", ihost->initiatorname); 3458 len = sprintf(buf, "%s\n", ihost->initiatorname);
3418 break; 3459 break;
3419 case ISCSI_HOST_PARAM_IPADDRESS:
3420 len = sprintf(buf, "%s\n", ihost->local_address);
3421 break;
3422 default: 3460 default:
3423 return -ENOSYS; 3461 return -ENOSYS;
3424 } 3462 }
diff --git a/drivers/scsi/libsas/Kconfig b/drivers/scsi/libsas/Kconfig
index 18f33cd54411..9dafe64e7c7a 100644
--- a/drivers/scsi/libsas/Kconfig
+++ b/drivers/scsi/libsas/Kconfig
@@ -46,11 +46,3 @@ config SCSI_SAS_HOST_SMP
46 Allows sas hosts to receive SMP frames. Selecting this 46 Allows sas hosts to receive SMP frames. Selecting this
47 option builds an SMP interpreter into libsas. Say 47 option builds an SMP interpreter into libsas. Say
48 N here if you want to save the few kb this consumes. 48 N here if you want to save the few kb this consumes.
49
50config SCSI_SAS_LIBSAS_DEBUG
51 bool "Compile the SAS Domain Transport Attributes in debug mode"
52 default y
53 depends on SCSI_SAS_LIBSAS
54 help
55 Compiles the SAS Layer in debug mode. In debug mode, the
56 SAS Layer prints diagnostic and debug messages.
diff --git a/drivers/scsi/libsas/Makefile b/drivers/scsi/libsas/Makefile
index 1ad1323c60fa..566a10024598 100644
--- a/drivers/scsi/libsas/Makefile
+++ b/drivers/scsi/libsas/Makefile
@@ -21,10 +21,6 @@
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22# USA 22# USA
23 23
24ifeq ($(CONFIG_SCSI_SAS_LIBSAS_DEBUG),y)
25 EXTRA_CFLAGS += -DSAS_DEBUG
26endif
27
28obj-$(CONFIG_SCSI_SAS_LIBSAS) += libsas.o 24obj-$(CONFIG_SCSI_SAS_LIBSAS) += libsas.o
29libsas-y += sas_init.o \ 25libsas-y += sas_init.o \
30 sas_phy.o \ 26 sas_phy.o \
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 4d3b704ede1c..31fc21f4d831 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -71,13 +71,13 @@ static enum ata_completion_errors sas_to_ata_err(struct task_status_struct *ts)
71 case SAS_SG_ERR: 71 case SAS_SG_ERR:
72 return AC_ERR_INVALID; 72 return AC_ERR_INVALID;
73 73
74 case SAM_STAT_CHECK_CONDITION:
75 case SAS_OPEN_TO: 74 case SAS_OPEN_TO:
76 case SAS_OPEN_REJECT: 75 case SAS_OPEN_REJECT:
77 SAS_DPRINTK("%s: Saw error %d. What to do?\n", 76 SAS_DPRINTK("%s: Saw error %d. What to do?\n",
78 __func__, ts->stat); 77 __func__, ts->stat);
79 return AC_ERR_OTHER; 78 return AC_ERR_OTHER;
80 79
80 case SAM_STAT_CHECK_CONDITION:
81 case SAS_ABORTED_TASK: 81 case SAS_ABORTED_TASK:
82 return AC_ERR_DEV; 82 return AC_ERR_DEV;
83 83
@@ -107,13 +107,15 @@ static void sas_ata_task_done(struct sas_task *task)
107 sas_ha = dev->port->ha; 107 sas_ha = dev->port->ha;
108 108
109 spin_lock_irqsave(dev->sata_dev.ap->lock, flags); 109 spin_lock_irqsave(dev->sata_dev.ap->lock, flags);
110 if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD) { 110 if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD ||
111 ((stat->stat == SAM_STAT_CHECK_CONDITION &&
112 dev->sata_dev.command_set == ATAPI_COMMAND_SET))) {
111 ata_tf_from_fis(resp->ending_fis, &dev->sata_dev.tf); 113 ata_tf_from_fis(resp->ending_fis, &dev->sata_dev.tf);
112 qc->err_mask |= ac_err_mask(dev->sata_dev.tf.command); 114 qc->err_mask |= ac_err_mask(dev->sata_dev.tf.command);
113 dev->sata_dev.sstatus = resp->sstatus; 115 dev->sata_dev.sstatus = resp->sstatus;
114 dev->sata_dev.serror = resp->serror; 116 dev->sata_dev.serror = resp->serror;
115 dev->sata_dev.scontrol = resp->scontrol; 117 dev->sata_dev.scontrol = resp->scontrol;
116 } else if (stat->stat != SAM_STAT_GOOD) { 118 } else {
117 ac = sas_to_ata_err(stat); 119 ac = sas_to_ata_err(stat);
118 if (ac) { 120 if (ac) {
119 SAS_DPRINTK("%s: SAS error %x\n", __func__, 121 SAS_DPRINTK("%s: SAS error %x\n", __func__,
@@ -305,55 +307,6 @@ static void sas_ata_post_internal(struct ata_queued_cmd *qc)
305 } 307 }
306} 308}
307 309
308static int sas_ata_scr_write(struct ata_link *link, unsigned int sc_reg_in,
309 u32 val)
310{
311 struct domain_device *dev = link->ap->private_data;
312
313 SAS_DPRINTK("STUB %s\n", __func__);
314 switch (sc_reg_in) {
315 case SCR_STATUS:
316 dev->sata_dev.sstatus = val;
317 break;
318 case SCR_CONTROL:
319 dev->sata_dev.scontrol = val;
320 break;
321 case SCR_ERROR:
322 dev->sata_dev.serror = val;
323 break;
324 case SCR_ACTIVE:
325 dev->sata_dev.ap->link.sactive = val;
326 break;
327 default:
328 return -EINVAL;
329 }
330 return 0;
331}
332
333static int sas_ata_scr_read(struct ata_link *link, unsigned int sc_reg_in,
334 u32 *val)
335{
336 struct domain_device *dev = link->ap->private_data;
337
338 SAS_DPRINTK("STUB %s\n", __func__);
339 switch (sc_reg_in) {
340 case SCR_STATUS:
341 *val = dev->sata_dev.sstatus;
342 return 0;
343 case SCR_CONTROL:
344 *val = dev->sata_dev.scontrol;
345 return 0;
346 case SCR_ERROR:
347 *val = dev->sata_dev.serror;
348 return 0;
349 case SCR_ACTIVE:
350 *val = dev->sata_dev.ap->link.sactive;
351 return 0;
352 default:
353 return -EINVAL;
354 }
355}
356
357static struct ata_port_operations sas_sata_ops = { 310static struct ata_port_operations sas_sata_ops = {
358 .prereset = ata_std_prereset, 311 .prereset = ata_std_prereset,
359 .softreset = NULL, 312 .softreset = NULL,
@@ -367,8 +320,6 @@ static struct ata_port_operations sas_sata_ops = {
367 .qc_fill_rtf = sas_ata_qc_fill_rtf, 320 .qc_fill_rtf = sas_ata_qc_fill_rtf,
368 .port_start = ata_sas_port_start, 321 .port_start = ata_sas_port_start,
369 .port_stop = ata_sas_port_stop, 322 .port_stop = ata_sas_port_stop,
370 .scr_read = sas_ata_scr_read,
371 .scr_write = sas_ata_scr_write
372}; 323};
373 324
374static struct ata_port_info sata_port_info = { 325static struct ata_port_info sata_port_info = {
@@ -801,7 +752,7 @@ void sas_ata_strategy_handler(struct Scsi_Host *shost)
801 752
802 if (!dev_is_sata(ddev)) 753 if (!dev_is_sata(ddev))
803 continue; 754 continue;
804 755
805 ata_port_printk(ap, KERN_DEBUG, "sas eh calling libata port error handler"); 756 ata_port_printk(ap, KERN_DEBUG, "sas eh calling libata port error handler");
806 ata_scsi_port_error_handler(shost, ap); 757 ata_scsi_port_error_handler(shost, ap);
807 } 758 }
@@ -834,13 +785,13 @@ int sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q,
834 LIST_HEAD(sata_q); 785 LIST_HEAD(sata_q);
835 786
836 ap = NULL; 787 ap = NULL;
837 788
838 list_for_each_entry_safe(cmd, n, work_q, eh_entry) { 789 list_for_each_entry_safe(cmd, n, work_q, eh_entry) {
839 struct domain_device *ddev = cmd_to_domain_dev(cmd); 790 struct domain_device *ddev = cmd_to_domain_dev(cmd);
840 791
841 if (!dev_is_sata(ddev) || TO_SAS_TASK(cmd)) 792 if (!dev_is_sata(ddev) || TO_SAS_TASK(cmd))
842 continue; 793 continue;
843 if(ap && ap != ddev->sata_dev.ap) 794 if (ap && ap != ddev->sata_dev.ap)
844 continue; 795 continue;
845 ap = ddev->sata_dev.ap; 796 ap = ddev->sata_dev.ap;
846 rtn = 1; 797 rtn = 1;
@@ -848,8 +799,21 @@ int sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q,
848 } 799 }
849 800
850 if (!list_empty(&sata_q)) { 801 if (!list_empty(&sata_q)) {
851 ata_port_printk(ap, KERN_DEBUG,"sas eh calling libata cmd error handler\n"); 802 ata_port_printk(ap, KERN_DEBUG, "sas eh calling libata cmd error handler\n");
852 ata_scsi_cmd_error_handler(shost, ap, &sata_q); 803 ata_scsi_cmd_error_handler(shost, ap, &sata_q);
804 /*
805 * ata's error handler may leave the cmd on the list
806 * so make sure they don't remain on a stack list
807 * about to go out of scope.
808 *
809 * This looks strange, since the commands are
810 * now part of no list, but the next error
811 * action will be ata_port_error_handler()
812 * which takes no list and sweeps them up
813 * anyway from the ata tag array.
814 */
815 while (!list_empty(&sata_q))
816 list_del_init(sata_q.next);
853 } 817 }
854 } while (ap); 818 } while (ap);
855 819
diff --git a/drivers/scsi/libsas/sas_dump.c b/drivers/scsi/libsas/sas_dump.c
index c17c25030f1c..fc460933575c 100644
--- a/drivers/scsi/libsas/sas_dump.c
+++ b/drivers/scsi/libsas/sas_dump.c
@@ -24,8 +24,6 @@
24 24
25#include "sas_dump.h" 25#include "sas_dump.h"
26 26
27#ifdef SAS_DEBUG
28
29static const char *sas_hae_str[] = { 27static const char *sas_hae_str[] = {
30 [0] = "HAE_RESET", 28 [0] = "HAE_RESET",
31}; 29};
@@ -72,5 +70,3 @@ void sas_dump_port(struct asd_sas_port *port)
72 SAS_DPRINTK("port%d: oob_mode:0x%x\n", port->id, port->oob_mode); 70 SAS_DPRINTK("port%d: oob_mode:0x%x\n", port->id, port->oob_mode);
73 SAS_DPRINTK("port%d: num_phys:%d\n", port->id, port->num_phys); 71 SAS_DPRINTK("port%d: num_phys:%d\n", port->id, port->num_phys);
74} 72}
75
76#endif /* SAS_DEBUG */
diff --git a/drivers/scsi/libsas/sas_dump.h b/drivers/scsi/libsas/sas_dump.h
index 47b45d4f5258..800e4c69093f 100644
--- a/drivers/scsi/libsas/sas_dump.h
+++ b/drivers/scsi/libsas/sas_dump.h
@@ -24,19 +24,7 @@
24 24
25#include "sas_internal.h" 25#include "sas_internal.h"
26 26
27#ifdef SAS_DEBUG
28
29void sas_dprint_porte(int phyid, enum port_event pe); 27void sas_dprint_porte(int phyid, enum port_event pe);
30void sas_dprint_phye(int phyid, enum phy_event pe); 28void sas_dprint_phye(int phyid, enum phy_event pe);
31void sas_dprint_hae(struct sas_ha_struct *sas_ha, enum ha_event he); 29void sas_dprint_hae(struct sas_ha_struct *sas_ha, enum ha_event he);
32void sas_dump_port(struct asd_sas_port *port); 30void sas_dump_port(struct asd_sas_port *port);
33
34#else /* SAS_DEBUG */
35
36static inline void sas_dprint_porte(int phyid, enum port_event pe) { }
37static inline void sas_dprint_phye(int phyid, enum phy_event pe) { }
38static inline void sas_dprint_hae(struct sas_ha_struct *sas_ha,
39 enum ha_event he) { }
40static inline void sas_dump_port(struct asd_sas_port *port) { }
41
42#endif /* SAS_DEBUG */
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 505ffe358293..f3f693b772ac 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -244,6 +244,11 @@ static int sas_ex_phy_discover_helper(struct domain_device *dev, u8 *disc_req,
244 * dev to host FIS as described in section G.5 of 244 * dev to host FIS as described in section G.5 of
245 * sas-2 r 04b */ 245 * sas-2 r 04b */
246 dr = &((struct smp_resp *)disc_resp)->disc; 246 dr = &((struct smp_resp *)disc_resp)->disc;
247 if (memcmp(dev->sas_addr, dr->attached_sas_addr,
248 SAS_ADDR_SIZE) == 0) {
249 sas_printk("Found loopback topology, just ignore it!\n");
250 return 0;
251 }
247 if (!(dr->attached_dev_type == 0 && 252 if (!(dr->attached_dev_type == 0 &&
248 dr->attached_sata_dev)) 253 dr->attached_sata_dev))
249 break; 254 break;
diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
index 0001374bd6b2..8b538bd1ff2b 100644
--- a/drivers/scsi/libsas/sas_internal.h
+++ b/drivers/scsi/libsas/sas_internal.h
@@ -33,11 +33,7 @@
33 33
34#define sas_printk(fmt, ...) printk(KERN_NOTICE "sas: " fmt, ## __VA_ARGS__) 34#define sas_printk(fmt, ...) printk(KERN_NOTICE "sas: " fmt, ## __VA_ARGS__)
35 35
36#ifdef SAS_DEBUG 36#define SAS_DPRINTK(fmt, ...) printk(KERN_DEBUG "sas: " fmt, ## __VA_ARGS__)
37#define SAS_DPRINTK(fmt, ...) printk(KERN_NOTICE "sas: " fmt, ## __VA_ARGS__)
38#else
39#define SAS_DPRINTK(fmt, ...)
40#endif
41 37
42#define TO_SAS_TASK(_scsi_cmd) ((void *)(_scsi_cmd)->host_scribble) 38#define TO_SAS_TASK(_scsi_cmd) ((void *)(_scsi_cmd)->host_scribble)
43#define ASSIGN_SAS_TASK(_sc, _t) do { (_sc)->host_scribble = (void *) _t; } while (0) 39#define ASSIGN_SAS_TASK(_sc, _t) do { (_sc)->host_scribble = (void *) _t; } while (0)
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 67758ea8eb7f..f6e189f40917 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -681,11 +681,10 @@ enum blk_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
681{ 681{
682 struct sas_task *task = TO_SAS_TASK(cmd); 682 struct sas_task *task = TO_SAS_TASK(cmd);
683 unsigned long flags; 683 unsigned long flags;
684 enum blk_eh_timer_return rtn; 684 enum blk_eh_timer_return rtn;
685 685
686 if (sas_ata_timed_out(cmd, task, &rtn)) 686 if (sas_ata_timed_out(cmd, task, &rtn))
687 return rtn; 687 return rtn;
688
689 688
690 if (!task) { 689 if (!task) {
691 cmd->request->timeout /= 2; 690 cmd->request->timeout /= 2;
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index 746dd3d7a092..b64c6da870d3 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2010 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -325,6 +325,7 @@ struct lpfc_vport {
325#define FC_VPORT_CVL_RCVD 0x400000 /* VLink failed due to CVL */ 325#define FC_VPORT_CVL_RCVD 0x400000 /* VLink failed due to CVL */
326#define FC_VFI_REGISTERED 0x800000 /* VFI is registered */ 326#define FC_VFI_REGISTERED 0x800000 /* VFI is registered */
327#define FC_FDISC_COMPLETED 0x1000000/* FDISC completed */ 327#define FC_FDISC_COMPLETED 0x1000000/* FDISC completed */
328#define FC_DISC_DELAYED 0x2000000/* Delay NPort discovery */
328 329
329 uint32_t ct_flags; 330 uint32_t ct_flags;
330#define FC_CT_RFF_ID 0x1 /* RFF_ID accepted by switch */ 331#define FC_CT_RFF_ID 0x1 /* RFF_ID accepted by switch */
@@ -348,6 +349,8 @@ struct lpfc_vport {
348 349
349 uint32_t fc_myDID; /* fibre channel S_ID */ 350 uint32_t fc_myDID; /* fibre channel S_ID */
350 uint32_t fc_prevDID; /* previous fibre channel S_ID */ 351 uint32_t fc_prevDID; /* previous fibre channel S_ID */
352 struct lpfc_name fabric_portname;
353 struct lpfc_name fabric_nodename;
351 354
352 int32_t stopped; /* HBA has not been restarted since last ERATT */ 355 int32_t stopped; /* HBA has not been restarted since last ERATT */
353 uint8_t fc_linkspeed; /* Link speed after last READ_LA */ 356 uint8_t fc_linkspeed; /* Link speed after last READ_LA */
@@ -372,6 +375,7 @@ struct lpfc_vport {
372#define WORKER_DISC_TMO 0x1 /* vport: Discovery timeout */ 375#define WORKER_DISC_TMO 0x1 /* vport: Discovery timeout */
373#define WORKER_ELS_TMO 0x2 /* vport: ELS timeout */ 376#define WORKER_ELS_TMO 0x2 /* vport: ELS timeout */
374#define WORKER_FDMI_TMO 0x4 /* vport: FDMI timeout */ 377#define WORKER_FDMI_TMO 0x4 /* vport: FDMI timeout */
378#define WORKER_DELAYED_DISC_TMO 0x8 /* vport: delayed discovery */
375 379
376#define WORKER_MBOX_TMO 0x100 /* hba: MBOX timeout */ 380#define WORKER_MBOX_TMO 0x100 /* hba: MBOX timeout */
377#define WORKER_HB_TMO 0x200 /* hba: Heart beat timeout */ 381#define WORKER_HB_TMO 0x200 /* hba: Heart beat timeout */
@@ -382,6 +386,7 @@ struct lpfc_vport {
382 386
383 struct timer_list fc_fdmitmo; 387 struct timer_list fc_fdmitmo;
384 struct timer_list els_tmofunc; 388 struct timer_list els_tmofunc;
389 struct timer_list delayed_disc_tmo;
385 390
386 int unreg_vpi_cmpl; 391 int unreg_vpi_cmpl;
387 392
@@ -548,6 +553,8 @@ struct lpfc_hba {
548#define LPFC_SLI3_CRP_ENABLED 0x08 553#define LPFC_SLI3_CRP_ENABLED 0x08
549#define LPFC_SLI3_BG_ENABLED 0x20 554#define LPFC_SLI3_BG_ENABLED 0x20
550#define LPFC_SLI3_DSS_ENABLED 0x40 555#define LPFC_SLI3_DSS_ENABLED 0x40
556#define LPFC_SLI4_PERFH_ENABLED 0x80
557#define LPFC_SLI4_PHWQ_ENABLED 0x100
551 uint32_t iocb_cmd_size; 558 uint32_t iocb_cmd_size;
552 uint32_t iocb_rsp_size; 559 uint32_t iocb_rsp_size;
553 560
@@ -655,7 +662,7 @@ struct lpfc_hba {
655#define LPFC_INITIALIZE_LINK 0 /* do normal init_link mbox */ 662#define LPFC_INITIALIZE_LINK 0 /* do normal init_link mbox */
656#define LPFC_DELAY_INIT_LINK 1 /* layered driver hold off */ 663#define LPFC_DELAY_INIT_LINK 1 /* layered driver hold off */
657#define LPFC_DELAY_INIT_LINK_INDEFINITELY 2 /* wait, manual intervention */ 664#define LPFC_DELAY_INIT_LINK_INDEFINITELY 2 /* wait, manual intervention */
658 665 uint32_t cfg_enable_dss;
659 lpfc_vpd_t vpd; /* vital product data */ 666 lpfc_vpd_t vpd; /* vital product data */
660 667
661 struct pci_dev *pcidev; 668 struct pci_dev *pcidev;
@@ -792,6 +799,10 @@ struct lpfc_hba {
792 struct dentry *debug_slow_ring_trc; 799 struct dentry *debug_slow_ring_trc;
793 struct lpfc_debugfs_trc *slow_ring_trc; 800 struct lpfc_debugfs_trc *slow_ring_trc;
794 atomic_t slow_ring_trc_cnt; 801 atomic_t slow_ring_trc_cnt;
802 /* iDiag debugfs sub-directory */
803 struct dentry *idiag_root;
804 struct dentry *idiag_pci_cfg;
805 struct dentry *idiag_que_info;
795#endif 806#endif
796 807
797 /* Used for deferred freeing of ELS data buffers */ 808 /* Used for deferred freeing of ELS data buffers */
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 3512abb8a587..e7c020df12fa 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -623,10 +623,14 @@ lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
623 int status = 0; 623 int status = 0;
624 int cnt = 0; 624 int cnt = 0;
625 int i; 625 int i;
626 int rc;
626 627
627 init_completion(&online_compl); 628 init_completion(&online_compl);
628 lpfc_workq_post_event(phba, &status, &online_compl, 629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
629 LPFC_EVT_OFFLINE_PREP); 630 LPFC_EVT_OFFLINE_PREP);
631 if (rc == 0)
632 return -ENOMEM;
633
630 wait_for_completion(&online_compl); 634 wait_for_completion(&online_compl);
631 635
632 if (status != 0) 636 if (status != 0)
@@ -652,7 +656,10 @@ lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
652 } 656 }
653 657
654 init_completion(&online_compl); 658 init_completion(&online_compl);
655 lpfc_workq_post_event(phba, &status, &online_compl, type); 659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
660 if (rc == 0)
661 return -ENOMEM;
662
656 wait_for_completion(&online_compl); 663 wait_for_completion(&online_compl);
657 664
658 if (status != 0) 665 if (status != 0)
@@ -671,6 +678,7 @@ lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
671 * 678 *
672 * Notes: 679 * Notes:
673 * Assumes any error from lpfc_do_offline() will be negative. 680 * Assumes any error from lpfc_do_offline() will be negative.
681 * Do not make this function static.
674 * 682 *
675 * Returns: 683 * Returns:
676 * lpfc_do_offline() return code if not zero 684 * lpfc_do_offline() return code if not zero
@@ -682,6 +690,7 @@ lpfc_selective_reset(struct lpfc_hba *phba)
682{ 690{
683 struct completion online_compl; 691 struct completion online_compl;
684 int status = 0; 692 int status = 0;
693 int rc;
685 694
686 if (!phba->cfg_enable_hba_reset) 695 if (!phba->cfg_enable_hba_reset)
687 return -EIO; 696 return -EIO;
@@ -692,8 +701,11 @@ lpfc_selective_reset(struct lpfc_hba *phba)
692 return status; 701 return status;
693 702
694 init_completion(&online_compl); 703 init_completion(&online_compl);
695 lpfc_workq_post_event(phba, &status, &online_compl, 704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
696 LPFC_EVT_ONLINE); 705 LPFC_EVT_ONLINE);
706 if (rc == 0)
707 return -ENOMEM;
708
697 wait_for_completion(&online_compl); 709 wait_for_completion(&online_compl);
698 710
699 if (status != 0) 711 if (status != 0)
@@ -812,14 +824,17 @@ lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
812 struct lpfc_hba *phba = vport->phba; 824 struct lpfc_hba *phba = vport->phba;
813 struct completion online_compl; 825 struct completion online_compl;
814 int status=0; 826 int status=0;
827 int rc;
815 828
816 if (!phba->cfg_enable_hba_reset) 829 if (!phba->cfg_enable_hba_reset)
817 return -EACCES; 830 return -EACCES;
818 init_completion(&online_compl); 831 init_completion(&online_compl);
819 832
820 if(strncmp(buf, "online", sizeof("online") - 1) == 0) { 833 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
821 lpfc_workq_post_event(phba, &status, &online_compl, 834 rc = lpfc_workq_post_event(phba, &status, &online_compl,
822 LPFC_EVT_ONLINE); 835 LPFC_EVT_ONLINE);
836 if (rc == 0)
837 return -ENOMEM;
823 wait_for_completion(&online_compl); 838 wait_for_completion(&online_compl);
824 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) 839 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
825 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); 840 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
@@ -1279,6 +1294,28 @@ lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1279} 1294}
1280 1295
1281/** 1296/**
1297 * lpfc_dss_show - Return the current state of dss and the configured state
1298 * @dev: class converted to a Scsi_host structure.
1299 * @attr: device attribute, not used.
1300 * @buf: on return contains the formatted text.
1301 *
1302 * Returns: size of formatted string.
1303 **/
1304static ssize_t
1305lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1306 char *buf)
1307{
1308 struct Scsi_Host *shost = class_to_shost(dev);
1309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1310 struct lpfc_hba *phba = vport->phba;
1311
1312 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1313 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1314 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1315 "" : "Not ");
1316}
1317
1318/**
1282 * lpfc_param_show - Return a cfg attribute value in decimal 1319 * lpfc_param_show - Return a cfg attribute value in decimal
1283 * 1320 *
1284 * Description: 1321 * Description:
@@ -1597,13 +1634,13 @@ lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1597 1634
1598#define LPFC_ATTR(name, defval, minval, maxval, desc) \ 1635#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1599static uint lpfc_##name = defval;\ 1636static uint lpfc_##name = defval;\
1600module_param(lpfc_##name, uint, 0);\ 1637module_param(lpfc_##name, uint, S_IRUGO);\
1601MODULE_PARM_DESC(lpfc_##name, desc);\ 1638MODULE_PARM_DESC(lpfc_##name, desc);\
1602lpfc_param_init(name, defval, minval, maxval) 1639lpfc_param_init(name, defval, minval, maxval)
1603 1640
1604#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ 1641#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1605static uint lpfc_##name = defval;\ 1642static uint lpfc_##name = defval;\
1606module_param(lpfc_##name, uint, 0);\ 1643module_param(lpfc_##name, uint, S_IRUGO);\
1607MODULE_PARM_DESC(lpfc_##name, desc);\ 1644MODULE_PARM_DESC(lpfc_##name, desc);\
1608lpfc_param_show(name)\ 1645lpfc_param_show(name)\
1609lpfc_param_init(name, defval, minval, maxval)\ 1646lpfc_param_init(name, defval, minval, maxval)\
@@ -1611,7 +1648,7 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1611 1648
1612#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ 1649#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1613static uint lpfc_##name = defval;\ 1650static uint lpfc_##name = defval;\
1614module_param(lpfc_##name, uint, 0);\ 1651module_param(lpfc_##name, uint, S_IRUGO);\
1615MODULE_PARM_DESC(lpfc_##name, desc);\ 1652MODULE_PARM_DESC(lpfc_##name, desc);\
1616lpfc_param_show(name)\ 1653lpfc_param_show(name)\
1617lpfc_param_init(name, defval, minval, maxval)\ 1654lpfc_param_init(name, defval, minval, maxval)\
@@ -1622,7 +1659,7 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1622 1659
1623#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ 1660#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1624static uint lpfc_##name = defval;\ 1661static uint lpfc_##name = defval;\
1625module_param(lpfc_##name, uint, 0);\ 1662module_param(lpfc_##name, uint, S_IRUGO);\
1626MODULE_PARM_DESC(lpfc_##name, desc);\ 1663MODULE_PARM_DESC(lpfc_##name, desc);\
1627lpfc_param_hex_show(name)\ 1664lpfc_param_hex_show(name)\
1628lpfc_param_init(name, defval, minval, maxval)\ 1665lpfc_param_init(name, defval, minval, maxval)\
@@ -1630,7 +1667,7 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1630 1667
1631#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ 1668#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1632static uint lpfc_##name = defval;\ 1669static uint lpfc_##name = defval;\
1633module_param(lpfc_##name, uint, 0);\ 1670module_param(lpfc_##name, uint, S_IRUGO);\
1634MODULE_PARM_DESC(lpfc_##name, desc);\ 1671MODULE_PARM_DESC(lpfc_##name, desc);\
1635lpfc_param_hex_show(name)\ 1672lpfc_param_hex_show(name)\
1636lpfc_param_init(name, defval, minval, maxval)\ 1673lpfc_param_init(name, defval, minval, maxval)\
@@ -1641,13 +1678,13 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1641 1678
1642#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \ 1679#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1643static uint lpfc_##name = defval;\ 1680static uint lpfc_##name = defval;\
1644module_param(lpfc_##name, uint, 0);\ 1681module_param(lpfc_##name, uint, S_IRUGO);\
1645MODULE_PARM_DESC(lpfc_##name, desc);\ 1682MODULE_PARM_DESC(lpfc_##name, desc);\
1646lpfc_vport_param_init(name, defval, minval, maxval) 1683lpfc_vport_param_init(name, defval, minval, maxval)
1647 1684
1648#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \ 1685#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1649static uint lpfc_##name = defval;\ 1686static uint lpfc_##name = defval;\
1650module_param(lpfc_##name, uint, 0);\ 1687module_param(lpfc_##name, uint, S_IRUGO);\
1651MODULE_PARM_DESC(lpfc_##name, desc);\ 1688MODULE_PARM_DESC(lpfc_##name, desc);\
1652lpfc_vport_param_show(name)\ 1689lpfc_vport_param_show(name)\
1653lpfc_vport_param_init(name, defval, minval, maxval)\ 1690lpfc_vport_param_init(name, defval, minval, maxval)\
@@ -1655,7 +1692,7 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1655 1692
1656#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \ 1693#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1657static uint lpfc_##name = defval;\ 1694static uint lpfc_##name = defval;\
1658module_param(lpfc_##name, uint, 0);\ 1695module_param(lpfc_##name, uint, S_IRUGO);\
1659MODULE_PARM_DESC(lpfc_##name, desc);\ 1696MODULE_PARM_DESC(lpfc_##name, desc);\
1660lpfc_vport_param_show(name)\ 1697lpfc_vport_param_show(name)\
1661lpfc_vport_param_init(name, defval, minval, maxval)\ 1698lpfc_vport_param_init(name, defval, minval, maxval)\
@@ -1666,7 +1703,7 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1666 1703
1667#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \ 1704#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1668static uint lpfc_##name = defval;\ 1705static uint lpfc_##name = defval;\
1669module_param(lpfc_##name, uint, 0);\ 1706module_param(lpfc_##name, uint, S_IRUGO);\
1670MODULE_PARM_DESC(lpfc_##name, desc);\ 1707MODULE_PARM_DESC(lpfc_##name, desc);\
1671lpfc_vport_param_hex_show(name)\ 1708lpfc_vport_param_hex_show(name)\
1672lpfc_vport_param_init(name, defval, minval, maxval)\ 1709lpfc_vport_param_init(name, defval, minval, maxval)\
@@ -1674,7 +1711,7 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1674 1711
1675#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ 1712#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1676static uint lpfc_##name = defval;\ 1713static uint lpfc_##name = defval;\
1677module_param(lpfc_##name, uint, 0);\ 1714module_param(lpfc_##name, uint, S_IRUGO);\
1678MODULE_PARM_DESC(lpfc_##name, desc);\ 1715MODULE_PARM_DESC(lpfc_##name, desc);\
1679lpfc_vport_param_hex_show(name)\ 1716lpfc_vport_param_hex_show(name)\
1680lpfc_vport_param_init(name, defval, minval, maxval)\ 1717lpfc_vport_param_init(name, defval, minval, maxval)\
@@ -1718,7 +1755,7 @@ static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1718static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL); 1755static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1719static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL); 1756static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1720static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL); 1757static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1721 1758static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
1722 1759
1723static char *lpfc_soft_wwn_key = "C99G71SL8032A"; 1760static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1724 1761
@@ -1813,6 +1850,7 @@ lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1813 int stat1=0, stat2=0; 1850 int stat1=0, stat2=0;
1814 unsigned int i, j, cnt=count; 1851 unsigned int i, j, cnt=count;
1815 u8 wwpn[8]; 1852 u8 wwpn[8];
1853 int rc;
1816 1854
1817 if (!phba->cfg_enable_hba_reset) 1855 if (!phba->cfg_enable_hba_reset)
1818 return -EACCES; 1856 return -EACCES;
@@ -1863,7 +1901,11 @@ lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1863 "0463 lpfc_soft_wwpn attribute set failed to " 1901 "0463 lpfc_soft_wwpn attribute set failed to "
1864 "reinit adapter - %d\n", stat1); 1902 "reinit adapter - %d\n", stat1);
1865 init_completion(&online_compl); 1903 init_completion(&online_compl);
1866 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE); 1904 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
1905 LPFC_EVT_ONLINE);
1906 if (rc == 0)
1907 return -ENOMEM;
1908
1867 wait_for_completion(&online_compl); 1909 wait_for_completion(&online_compl);
1868 if (stat2) 1910 if (stat2)
1869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 1911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
@@ -1954,7 +1996,7 @@ static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1954 1996
1955 1997
1956static int lpfc_poll = 0; 1998static int lpfc_poll = 0;
1957module_param(lpfc_poll, int, 0); 1999module_param(lpfc_poll, int, S_IRUGO);
1958MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" 2000MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1959 " 0 - none," 2001 " 0 - none,"
1960 " 1 - poll with interrupts enabled" 2002 " 1 - poll with interrupts enabled"
@@ -1964,21 +2006,21 @@ static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1964 lpfc_poll_show, lpfc_poll_store); 2006 lpfc_poll_show, lpfc_poll_store);
1965 2007
1966int lpfc_sli_mode = 0; 2008int lpfc_sli_mode = 0;
1967module_param(lpfc_sli_mode, int, 0); 2009module_param(lpfc_sli_mode, int, S_IRUGO);
1968MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:" 2010MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1969 " 0 - auto (SLI-3 if supported)," 2011 " 0 - auto (SLI-3 if supported),"
1970 " 2 - select SLI-2 even on SLI-3 capable HBAs," 2012 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1971 " 3 - select SLI-3"); 2013 " 3 - select SLI-3");
1972 2014
1973int lpfc_enable_npiv = 1; 2015int lpfc_enable_npiv = 1;
1974module_param(lpfc_enable_npiv, int, 0); 2016module_param(lpfc_enable_npiv, int, S_IRUGO);
1975MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality"); 2017MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1976lpfc_param_show(enable_npiv); 2018lpfc_param_show(enable_npiv);
1977lpfc_param_init(enable_npiv, 1, 0, 1); 2019lpfc_param_init(enable_npiv, 1, 0, 1);
1978static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL); 2020static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
1979 2021
1980int lpfc_enable_rrq; 2022int lpfc_enable_rrq;
1981module_param(lpfc_enable_rrq, int, 0); 2023module_param(lpfc_enable_rrq, int, S_IRUGO);
1982MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality"); 2024MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
1983lpfc_param_show(enable_rrq); 2025lpfc_param_show(enable_rrq);
1984lpfc_param_init(enable_rrq, 0, 0, 1); 2026lpfc_param_init(enable_rrq, 0, 0, 1);
@@ -2040,7 +2082,7 @@ static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2040 lpfc_txcmplq_hw_show, NULL); 2082 lpfc_txcmplq_hw_show, NULL);
2041 2083
2042int lpfc_iocb_cnt = 2; 2084int lpfc_iocb_cnt = 2;
2043module_param(lpfc_iocb_cnt, int, 1); 2085module_param(lpfc_iocb_cnt, int, S_IRUGO);
2044MODULE_PARM_DESC(lpfc_iocb_cnt, 2086MODULE_PARM_DESC(lpfc_iocb_cnt,
2045 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs"); 2087 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2046lpfc_param_show(iocb_cnt); 2088lpfc_param_show(iocb_cnt);
@@ -2192,7 +2234,7 @@ static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2192# disappear until the timer expires. Value range is [0,255]. Default 2234# disappear until the timer expires. Value range is [0,255]. Default
2193# value is 30. 2235# value is 30.
2194*/ 2236*/
2195module_param(lpfc_devloss_tmo, int, 0); 2237module_param(lpfc_devloss_tmo, int, S_IRUGO);
2196MODULE_PARM_DESC(lpfc_devloss_tmo, 2238MODULE_PARM_DESC(lpfc_devloss_tmo,
2197 "Seconds driver will hold I/O waiting " 2239 "Seconds driver will hold I/O waiting "
2198 "for a device to come back"); 2240 "for a device to come back");
@@ -2302,7 +2344,7 @@ LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2302# Default value of this parameter is 1. 2344# Default value of this parameter is 1.
2303*/ 2345*/
2304static int lpfc_restrict_login = 1; 2346static int lpfc_restrict_login = 1;
2305module_param(lpfc_restrict_login, int, 0); 2347module_param(lpfc_restrict_login, int, S_IRUGO);
2306MODULE_PARM_DESC(lpfc_restrict_login, 2348MODULE_PARM_DESC(lpfc_restrict_login,
2307 "Restrict virtual ports login to remote initiators."); 2349 "Restrict virtual ports login to remote initiators.");
2308lpfc_vport_param_show(restrict_login); 2350lpfc_vport_param_show(restrict_login);
@@ -2473,7 +2515,7 @@ lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2473 return -EINVAL; 2515 return -EINVAL;
2474} 2516}
2475static int lpfc_topology = 0; 2517static int lpfc_topology = 0;
2476module_param(lpfc_topology, int, 0); 2518module_param(lpfc_topology, int, S_IRUGO);
2477MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology"); 2519MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2478lpfc_param_show(topology) 2520lpfc_param_show(topology)
2479lpfc_param_init(topology, 0, 0, 6) 2521lpfc_param_init(topology, 0, 0, 6)
@@ -2915,7 +2957,7 @@ lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2915} 2957}
2916 2958
2917static int lpfc_link_speed = 0; 2959static int lpfc_link_speed = 0;
2918module_param(lpfc_link_speed, int, 0); 2960module_param(lpfc_link_speed, int, S_IRUGO);
2919MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); 2961MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2920lpfc_param_show(link_speed) 2962lpfc_param_show(link_speed)
2921 2963
@@ -3043,7 +3085,7 @@ lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3043} 3085}
3044 3086
3045static int lpfc_aer_support = 1; 3087static int lpfc_aer_support = 1;
3046module_param(lpfc_aer_support, int, 1); 3088module_param(lpfc_aer_support, int, S_IRUGO);
3047MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support"); 3089MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3048lpfc_param_show(aer_support) 3090lpfc_param_show(aer_support)
3049 3091
@@ -3155,7 +3197,7 @@ LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3155# The value is set in milliseconds. 3197# The value is set in milliseconds.
3156*/ 3198*/
3157static int lpfc_max_scsicmpl_time; 3199static int lpfc_max_scsicmpl_time;
3158module_param(lpfc_max_scsicmpl_time, int, 0); 3200module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3159MODULE_PARM_DESC(lpfc_max_scsicmpl_time, 3201MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3160 "Use command completion time to control queue depth"); 3202 "Use command completion time to control queue depth");
3161lpfc_vport_param_show(max_scsicmpl_time); 3203lpfc_vport_param_show(max_scsicmpl_time);
@@ -3331,7 +3373,7 @@ LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3331*/ 3373*/
3332unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION; 3374unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
3333 3375
3334module_param(lpfc_prot_mask, uint, 0); 3376module_param(lpfc_prot_mask, uint, S_IRUGO);
3335MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask"); 3377MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3336 3378
3337/* 3379/*
@@ -3343,9 +3385,28 @@ MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3343# 3385#
3344*/ 3386*/
3345unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP; 3387unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3346module_param(lpfc_prot_guard, byte, 0); 3388module_param(lpfc_prot_guard, byte, S_IRUGO);
3347MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type"); 3389MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3348 3390
3391/*
3392 * Delay initial NPort discovery when Clean Address bit is cleared in
3393 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3394 * This parameter can have value 0 or 1.
3395 * When this parameter is set to 0, no delay is added to the initial
3396 * discovery.
3397 * When this parameter is set to non-zero value, initial Nport discovery is
3398 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3399 * accept and FCID/Fabric name/Fabric portname is changed.
3400 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3401 * when Clean Address bit is cleared in FLOGI/FDISC
3402 * accept and FCID/Fabric name/Fabric portname is changed.
3403 * Default value is 0.
3404 */
3405int lpfc_delay_discovery;
3406module_param(lpfc_delay_discovery, int, S_IRUGO);
3407MODULE_PARM_DESC(lpfc_delay_discovery,
3408 "Delay NPort discovery when Clean Address bit is cleared. "
3409 "Allowed values: 0,1.");
3349 3410
3350/* 3411/*
3351 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count 3412 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
@@ -3437,6 +3498,7 @@ struct device_attribute *lpfc_hba_attrs[] = {
3437 &dev_attr_txcmplq_hw, 3498 &dev_attr_txcmplq_hw,
3438 &dev_attr_lpfc_fips_level, 3499 &dev_attr_lpfc_fips_level,
3439 &dev_attr_lpfc_fips_rev, 3500 &dev_attr_lpfc_fips_rev,
3501 &dev_attr_lpfc_dss,
3440 NULL, 3502 NULL,
3441}; 3503};
3442 3504
@@ -4639,6 +4701,7 @@ lpfc_get_cfgparam(struct lpfc_hba *phba)
4639 lpfc_aer_support_init(phba, lpfc_aer_support); 4701 lpfc_aer_support_init(phba, lpfc_aer_support);
4640 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up); 4702 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
4641 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt); 4703 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
4704 phba->cfg_enable_dss = 1;
4642 return; 4705 return;
4643} 4706}
4644 4707
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index 17fde522c84a..3d40023f4804 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -53,9 +53,9 @@ void lpfc_unreg_vpi(struct lpfc_hba *, uint16_t, LPFC_MBOXQ_t *);
53void lpfc_init_link(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t); 53void lpfc_init_link(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t);
54void lpfc_request_features(struct lpfc_hba *, struct lpfcMboxq *); 54void lpfc_request_features(struct lpfc_hba *, struct lpfcMboxq *);
55void lpfc_supported_pages(struct lpfcMboxq *); 55void lpfc_supported_pages(struct lpfcMboxq *);
56void lpfc_sli4_params(struct lpfcMboxq *); 56void lpfc_pc_sli4_params(struct lpfcMboxq *);
57int lpfc_pc_sli4_params_get(struct lpfc_hba *, LPFC_MBOXQ_t *); 57int lpfc_pc_sli4_params_get(struct lpfc_hba *, LPFC_MBOXQ_t *);
58 58int lpfc_get_sli4_parameters(struct lpfc_hba *, LPFC_MBOXQ_t *);
59struct lpfc_vport *lpfc_find_vport_by_did(struct lpfc_hba *, uint32_t); 59struct lpfc_vport *lpfc_find_vport_by_did(struct lpfc_hba *, uint32_t);
60void lpfc_cleanup_rcv_buffers(struct lpfc_vport *); 60void lpfc_cleanup_rcv_buffers(struct lpfc_vport *);
61void lpfc_rcv_seq_check_edtov(struct lpfc_vport *); 61void lpfc_rcv_seq_check_edtov(struct lpfc_vport *);
@@ -167,6 +167,8 @@ int lpfc_ns_cmd(struct lpfc_vport *, int, uint8_t, uint32_t);
167int lpfc_fdmi_cmd(struct lpfc_vport *, struct lpfc_nodelist *, int); 167int lpfc_fdmi_cmd(struct lpfc_vport *, struct lpfc_nodelist *, int);
168void lpfc_fdmi_tmo(unsigned long); 168void lpfc_fdmi_tmo(unsigned long);
169void lpfc_fdmi_timeout_handler(struct lpfc_vport *); 169void lpfc_fdmi_timeout_handler(struct lpfc_vport *);
170void lpfc_delayed_disc_tmo(unsigned long);
171void lpfc_delayed_disc_timeout_handler(struct lpfc_vport *);
170 172
171int lpfc_config_port_prep(struct lpfc_hba *); 173int lpfc_config_port_prep(struct lpfc_hba *);
172int lpfc_config_port_post(struct lpfc_hba *); 174int lpfc_config_port_post(struct lpfc_hba *);
@@ -341,6 +343,7 @@ extern struct fc_function_template lpfc_transport_functions;
341extern struct fc_function_template lpfc_vport_transport_functions; 343extern struct fc_function_template lpfc_vport_transport_functions;
342extern int lpfc_sli_mode; 344extern int lpfc_sli_mode;
343extern int lpfc_enable_npiv; 345extern int lpfc_enable_npiv;
346extern int lpfc_delay_discovery;
344 347
345int lpfc_vport_symbolic_node_name(struct lpfc_vport *, char *, size_t); 348int lpfc_vport_symbolic_node_name(struct lpfc_vport *, char *, size_t);
346int lpfc_vport_symbolic_port_name(struct lpfc_vport *, char *, size_t); 349int lpfc_vport_symbolic_port_name(struct lpfc_vport *, char *, size_t);
@@ -423,6 +426,6 @@ int lpfc_send_rrq(struct lpfc_hba *, struct lpfc_node_rrq *);
423int lpfc_set_rrq_active(struct lpfc_hba *, struct lpfc_nodelist *, 426int lpfc_set_rrq_active(struct lpfc_hba *, struct lpfc_nodelist *,
424 uint16_t, uint16_t, uint16_t); 427 uint16_t, uint16_t, uint16_t);
425void lpfc_cleanup_wt_rrqs(struct lpfc_hba *); 428void lpfc_cleanup_wt_rrqs(struct lpfc_hba *);
426void lpfc_cleanup_vports_rrqs(struct lpfc_vport *); 429void lpfc_cleanup_vports_rrqs(struct lpfc_vport *, struct lpfc_nodelist *);
427struct lpfc_node_rrq *lpfc_get_active_rrq(struct lpfc_vport *, uint16_t, 430struct lpfc_node_rrq *lpfc_get_active_rrq(struct lpfc_vport *, uint16_t,
428 uint32_t); 431 uint32_t);
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index c004fa9a681e..d9edfd90d7ff 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -1738,6 +1738,55 @@ fdmi_cmd_exit:
1738 return 1; 1738 return 1;
1739} 1739}
1740 1740
1741/**
1742 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
1743 * @ptr - Context object of the timer.
1744 *
1745 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
1746 * the worker thread.
1747 **/
1748void
1749lpfc_delayed_disc_tmo(unsigned long ptr)
1750{
1751 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1752 struct lpfc_hba *phba = vport->phba;
1753 uint32_t tmo_posted;
1754 unsigned long iflag;
1755
1756 spin_lock_irqsave(&vport->work_port_lock, iflag);
1757 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
1758 if (!tmo_posted)
1759 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
1760 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1761
1762 if (!tmo_posted)
1763 lpfc_worker_wake_up(phba);
1764 return;
1765}
1766
1767/**
1768 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
1769 * handle delayed discovery.
1770 * @vport: pointer to a host virtual N_Port data structure.
1771 *
1772 * This function start nport discovery of the vport.
1773 **/
1774void
1775lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
1776{
1777 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1778
1779 spin_lock_irq(shost->host_lock);
1780 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
1781 spin_unlock_irq(shost->host_lock);
1782 return;
1783 }
1784 vport->fc_flag &= ~FC_DISC_DELAYED;
1785 spin_unlock_irq(shost->host_lock);
1786
1787 lpfc_do_scr_ns_plogi(vport->phba, vport);
1788}
1789
1741void 1790void
1742lpfc_fdmi_tmo(unsigned long ptr) 1791lpfc_fdmi_tmo(unsigned long ptr)
1743{ 1792{
diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
index a80d938fafc9..a753581509d6 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.c
+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007-2009 Emulex. All rights reserved. * 4 * Copyright (C) 2007-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -57,8 +57,8 @@
57 * # mount -t debugfs none /sys/kernel/debug 57 * # mount -t debugfs none /sys/kernel/debug
58 * 58 *
59 * The lpfc debugfs directory hierarchy is: 59 * The lpfc debugfs directory hierarchy is:
60 * lpfc/lpfcX/vportY 60 * /sys/kernel/debug/lpfc/fnX/vportY
61 * where X is the lpfc hba unique_id 61 * where X is the lpfc hba function unique_id
62 * where Y is the vport VPI on that hba 62 * where Y is the vport VPI on that hba
63 * 63 *
64 * Debugging services available per vport: 64 * Debugging services available per vport:
@@ -82,52 +82,34 @@
82 * the HBA. X MUST also be a power of 2. 82 * the HBA. X MUST also be a power of 2.
83 */ 83 */
84static int lpfc_debugfs_enable = 1; 84static int lpfc_debugfs_enable = 1;
85module_param(lpfc_debugfs_enable, int, 0); 85module_param(lpfc_debugfs_enable, int, S_IRUGO);
86MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services"); 86MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
87 87
88/* This MUST be a power of 2 */ 88/* This MUST be a power of 2 */
89static int lpfc_debugfs_max_disc_trc; 89static int lpfc_debugfs_max_disc_trc;
90module_param(lpfc_debugfs_max_disc_trc, int, 0); 90module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
91MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc, 91MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
92 "Set debugfs discovery trace depth"); 92 "Set debugfs discovery trace depth");
93 93
94/* This MUST be a power of 2 */ 94/* This MUST be a power of 2 */
95static int lpfc_debugfs_max_slow_ring_trc; 95static int lpfc_debugfs_max_slow_ring_trc;
96module_param(lpfc_debugfs_max_slow_ring_trc, int, 0); 96module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
97MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc, 97MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
98 "Set debugfs slow ring trace depth"); 98 "Set debugfs slow ring trace depth");
99 99
100static int lpfc_debugfs_mask_disc_trc; 100static int lpfc_debugfs_mask_disc_trc;
101module_param(lpfc_debugfs_mask_disc_trc, int, 0); 101module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
102MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc, 102MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
103 "Set debugfs discovery trace mask"); 103 "Set debugfs discovery trace mask");
104 104
105#include <linux/debugfs.h> 105#include <linux/debugfs.h>
106 106
107/* size of output line, for discovery_trace and slow_ring_trace */
108#define LPFC_DEBUG_TRC_ENTRY_SIZE 100
109
110/* nodelist output buffer size */
111#define LPFC_NODELIST_SIZE 8192
112#define LPFC_NODELIST_ENTRY_SIZE 120
113
114/* dumpHBASlim output buffer size */
115#define LPFC_DUMPHBASLIM_SIZE 4096
116
117/* dumpHostSlim output buffer size */
118#define LPFC_DUMPHOSTSLIM_SIZE 4096
119
120/* hbqinfo output buffer size */
121#define LPFC_HBQINFO_SIZE 8192
122
123struct lpfc_debug {
124 char *buffer;
125 int len;
126};
127
128static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0); 107static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
129static unsigned long lpfc_debugfs_start_time = 0L; 108static unsigned long lpfc_debugfs_start_time = 0L;
130 109
110/* iDiag */
111static struct lpfc_idiag idiag;
112
131/** 113/**
132 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer 114 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
133 * @vport: The vport to gather the log info from. 115 * @vport: The vport to gather the log info from.
@@ -996,8 +978,6 @@ lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
996 return nbytes; 978 return nbytes;
997} 979}
998 980
999
1000
1001/** 981/**
1002 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file 982 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1003 * @inode: The inode pointer that contains a vport pointer. 983 * @inode: The inode pointer that contains a vport pointer.
@@ -1099,6 +1079,7 @@ lpfc_debugfs_read(struct file *file, char __user *buf,
1099 size_t nbytes, loff_t *ppos) 1079 size_t nbytes, loff_t *ppos)
1100{ 1080{
1101 struct lpfc_debug *debug = file->private_data; 1081 struct lpfc_debug *debug = file->private_data;
1082
1102 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer, 1083 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1103 debug->len); 1084 debug->len);
1104} 1085}
@@ -1137,6 +1118,776 @@ lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1137 return 0; 1118 return 0;
1138} 1119}
1139 1120
1121/*
1122 * iDiag debugfs file access methods
1123 */
1124
1125/*
1126 * iDiag PCI config space register access methods:
1127 *
1128 * The PCI config space register accessees of read, write, read-modify-write
1129 * for set bits, and read-modify-write for clear bits to SLI4 PCI functions
1130 * are provided. In the proper SLI4 PCI function's debugfs iDiag directory,
1131 *
1132 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1133 *
1134 * the access is through the debugfs entry pciCfg:
1135 *
1136 * 1. For PCI config space register read access, there are two read methods:
1137 * A) read a single PCI config space register in the size of a byte
1138 * (8 bits), a word (16 bits), or a dword (32 bits); or B) browse through
1139 * the 4K extended PCI config space.
1140 *
1141 * A) Read a single PCI config space register consists of two steps:
1142 *
1143 * Step-1: Set up PCI config space register read command, the command
1144 * syntax is,
1145 *
1146 * echo 1 <where> <count> > pciCfg
1147 *
1148 * where, 1 is the iDiag command for PCI config space read, <where> is the
1149 * offset from the beginning of the device's PCI config space to read from,
1150 * and <count> is the size of PCI config space register data to read back,
1151 * it will be 1 for reading a byte (8 bits), 2 for reading a word (16 bits
1152 * or 2 bytes), or 4 for reading a dword (32 bits or 4 bytes).
1153 *
1154 * Setp-2: Perform the debugfs read operation to execute the idiag command
1155 * set up in Step-1,
1156 *
1157 * cat pciCfg
1158 *
1159 * Examples:
1160 * To read PCI device's vendor-id and device-id from PCI config space,
1161 *
1162 * echo 1 0 4 > pciCfg
1163 * cat pciCfg
1164 *
1165 * To read PCI device's currnt command from config space,
1166 *
1167 * echo 1 4 2 > pciCfg
1168 * cat pciCfg
1169 *
1170 * B) Browse through the entire 4K extended PCI config space also consists
1171 * of two steps:
1172 *
1173 * Step-1: Set up PCI config space register browsing command, the command
1174 * syntax is,
1175 *
1176 * echo 1 0 4096 > pciCfg
1177 *
1178 * where, 1 is the iDiag command for PCI config space read, 0 must be used
1179 * as the offset for PCI config space register browse, and 4096 must be
1180 * used as the count for PCI config space register browse.
1181 *
1182 * Step-2: Repeately issue the debugfs read operation to browse through
1183 * the entire PCI config space registers:
1184 *
1185 * cat pciCfg
1186 * cat pciCfg
1187 * cat pciCfg
1188 * ...
1189 *
1190 * When browsing to the end of the 4K PCI config space, the browse method
1191 * shall wrap around to start reading from beginning again, and again...
1192 *
1193 * 2. For PCI config space register write access, it supports a single PCI
1194 * config space register write in the size of a byte (8 bits), a word
1195 * (16 bits), or a dword (32 bits). The command syntax is,
1196 *
1197 * echo 2 <where> <count> <value> > pciCfg
1198 *
1199 * where, 2 is the iDiag command for PCI config space write, <where> is
1200 * the offset from the beginning of the device's PCI config space to write
1201 * into, <count> is the size of data to write into the PCI config space,
1202 * it will be 1 for writing a byte (8 bits), 2 for writing a word (16 bits
1203 * or 2 bytes), or 4 for writing a dword (32 bits or 4 bytes), and <value>
1204 * is the data to be written into the PCI config space register at the
1205 * offset.
1206 *
1207 * Examples:
1208 * To disable PCI device's interrupt assertion,
1209 *
1210 * 1) Read in device's PCI config space register command field <cmd>:
1211 *
1212 * echo 1 4 2 > pciCfg
1213 * cat pciCfg
1214 *
1215 * 2) Set bit 10 (Interrupt Disable bit) in the <cmd>:
1216 *
1217 * <cmd> = <cmd> | (1 < 10)
1218 *
1219 * 3) Write the modified command back:
1220 *
1221 * echo 2 4 2 <cmd> > pciCfg
1222 *
1223 * 3. For PCI config space register set bits access, it supports a single PCI
1224 * config space register set bits in the size of a byte (8 bits), a word
1225 * (16 bits), or a dword (32 bits). The command syntax is,
1226 *
1227 * echo 3 <where> <count> <bitmask> > pciCfg
1228 *
1229 * where, 3 is the iDiag command for PCI config space set bits, <where> is
1230 * the offset from the beginning of the device's PCI config space to set
1231 * bits into, <count> is the size of the bitmask to set into the PCI config
1232 * space, it will be 1 for setting a byte (8 bits), 2 for setting a word
1233 * (16 bits or 2 bytes), or 4 for setting a dword (32 bits or 4 bytes), and
1234 * <bitmask> is the bitmask, indicating the bits to be set into the PCI
1235 * config space register at the offset. The logic performed to the content
1236 * of the PCI config space register, regval, is,
1237 *
1238 * regval |= <bitmask>
1239 *
1240 * 4. For PCI config space register clear bits access, it supports a single
1241 * PCI config space register clear bits in the size of a byte (8 bits),
1242 * a word (16 bits), or a dword (32 bits). The command syntax is,
1243 *
1244 * echo 4 <where> <count> <bitmask> > pciCfg
1245 *
1246 * where, 4 is the iDiag command for PCI config space clear bits, <where>
1247 * is the offset from the beginning of the device's PCI config space to
1248 * clear bits from, <count> is the size of the bitmask to set into the PCI
1249 * config space, it will be 1 for setting a byte (8 bits), 2 for setting
1250 * a word(16 bits or 2 bytes), or 4 for setting a dword (32 bits or 4
1251 * bytes), and <bitmask> is the bitmask, indicating the bits to be cleared
1252 * from the PCI config space register at the offset. the logic performed
1253 * to the content of the PCI config space register, regval, is,
1254 *
1255 * regval &= ~<bitmask>
1256 *
1257 * Note, for all single register read, write, set bits, or clear bits access,
1258 * the offset (<where>) must be aligned with the size of the data:
1259 *
1260 * For data size of byte (8 bits), the offset must be aligned to the byte
1261 * boundary; for data size of word (16 bits), the offset must be aligned
1262 * to the word boundary; while for data size of dword (32 bits), the offset
1263 * must be aligned to the dword boundary. Otherwise, the interface will
1264 * return the error:
1265 *
1266 * "-bash: echo: write error: Invalid argument".
1267 *
1268 * For example:
1269 *
1270 * echo 1 2 4 > pciCfg
1271 * -bash: echo: write error: Invalid argument
1272 *
1273 * Note also, all of the numbers in the command fields for all read, write,
1274 * set bits, and clear bits PCI config space register command fields can be
1275 * either decimal or hex.
1276 *
1277 * For example,
1278 * echo 1 0 4096 > pciCfg
1279 *
1280 * will be the same as
1281 * echo 1 0 0x1000 > pciCfg
1282 *
1283 * And,
1284 * echo 2 155 1 10 > pciCfg
1285 *
1286 * will be
1287 * echo 2 0x9b 1 0xa > pciCfg
1288 */
1289
1290/**
1291 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1292 * @buf: The pointer to the user space buffer.
1293 * @nbytes: The number of bytes in the user space buffer.
1294 * @idiag_cmd: pointer to the idiag command struct.
1295 *
1296 * This routine reads data from debugfs user space buffer and parses the
1297 * buffer for getting the idiag command and arguments. The while space in
1298 * between the set of data is used as the parsing separator.
1299 *
1300 * This routine returns 0 when successful, it returns proper error code
1301 * back to the user space in error conditions.
1302 */
1303static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1304 struct lpfc_idiag_cmd *idiag_cmd)
1305{
1306 char mybuf[64];
1307 char *pbuf, *step_str;
1308 int bsize, i;
1309
1310 /* Protect copy from user */
1311 if (!access_ok(VERIFY_READ, buf, nbytes))
1312 return -EFAULT;
1313
1314 memset(mybuf, 0, sizeof(mybuf));
1315 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1316 bsize = min(nbytes, (sizeof(mybuf)-1));
1317
1318 if (copy_from_user(mybuf, buf, bsize))
1319 return -EFAULT;
1320 pbuf = &mybuf[0];
1321 step_str = strsep(&pbuf, "\t ");
1322
1323 /* The opcode must present */
1324 if (!step_str)
1325 return -EINVAL;
1326
1327 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1328 if (idiag_cmd->opcode == 0)
1329 return -EINVAL;
1330
1331 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1332 step_str = strsep(&pbuf, "\t ");
1333 if (!step_str)
1334 return 0;
1335 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1336 }
1337 return 0;
1338}
1339
1340/**
1341 * lpfc_idiag_open - idiag open debugfs
1342 * @inode: The inode pointer that contains a pointer to phba.
1343 * @file: The file pointer to attach the file operation.
1344 *
1345 * Description:
1346 * This routine is the entry point for the debugfs open file operation. It
1347 * gets the reference to phba from the i_private field in @inode, it then
1348 * allocates buffer for the file operation, performs the necessary PCI config
1349 * space read into the allocated buffer according to the idiag user command
1350 * setup, and then returns a pointer to buffer in the private_data field in
1351 * @file.
1352 *
1353 * Returns:
1354 * This function returns zero if successful. On error it will return an
1355 * negative error value.
1356 **/
1357static int
1358lpfc_idiag_open(struct inode *inode, struct file *file)
1359{
1360 struct lpfc_debug *debug;
1361
1362 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1363 if (!debug)
1364 return -ENOMEM;
1365
1366 debug->i_private = inode->i_private;
1367 debug->buffer = NULL;
1368 file->private_data = debug;
1369
1370 return 0;
1371}
1372
1373/**
1374 * lpfc_idiag_release - Release idiag access file operation
1375 * @inode: The inode pointer that contains a vport pointer. (unused)
1376 * @file: The file pointer that contains the buffer to release.
1377 *
1378 * Description:
1379 * This routine is the generic release routine for the idiag access file
1380 * operation, it frees the buffer that was allocated when the debugfs file
1381 * was opened.
1382 *
1383 * Returns:
1384 * This function returns zero.
1385 **/
1386static int
1387lpfc_idiag_release(struct inode *inode, struct file *file)
1388{
1389 struct lpfc_debug *debug = file->private_data;
1390
1391 /* Free the buffers to the file operation */
1392 kfree(debug->buffer);
1393 kfree(debug);
1394
1395 return 0;
1396}
1397
1398/**
1399 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1400 * @inode: The inode pointer that contains a vport pointer. (unused)
1401 * @file: The file pointer that contains the buffer to release.
1402 *
1403 * Description:
1404 * This routine frees the buffer that was allocated when the debugfs file
1405 * was opened. It also reset the fields in the idiag command struct in the
1406 * case the command is not continuous browsing of the data structure.
1407 *
1408 * Returns:
1409 * This function returns zero.
1410 **/
1411static int
1412lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1413{
1414 struct lpfc_debug *debug = file->private_data;
1415
1416 /* Read PCI config register, if not read all, clear command fields */
1417 if ((debug->op == LPFC_IDIAG_OP_RD) &&
1418 (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD))
1419 if ((idiag.cmd.data[1] == sizeof(uint8_t)) ||
1420 (idiag.cmd.data[1] == sizeof(uint16_t)) ||
1421 (idiag.cmd.data[1] == sizeof(uint32_t)))
1422 memset(&idiag, 0, sizeof(idiag));
1423
1424 /* Write PCI config register, clear command fields */
1425 if ((debug->op == LPFC_IDIAG_OP_WR) &&
1426 (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR))
1427 memset(&idiag, 0, sizeof(idiag));
1428
1429 /* Free the buffers to the file operation */
1430 kfree(debug->buffer);
1431 kfree(debug);
1432
1433 return 0;
1434}
1435
1436/**
1437 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1438 * @file: The file pointer to read from.
1439 * @buf: The buffer to copy the data to.
1440 * @nbytes: The number of bytes to read.
1441 * @ppos: The position in the file to start reading from.
1442 *
1443 * Description:
1444 * This routine reads data from the @phba pci config space according to the
1445 * idiag command, and copies to user @buf. Depending on the PCI config space
1446 * read command setup, it does either a single register read of a byte
1447 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1448 * registers from the 4K extended PCI config space.
1449 *
1450 * Returns:
1451 * This function returns the amount of data that was read (this could be less
1452 * than @nbytes if the end of the file was reached) or a negative error value.
1453 **/
1454static ssize_t
1455lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1456 loff_t *ppos)
1457{
1458 struct lpfc_debug *debug = file->private_data;
1459 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1460 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1461 int where, count;
1462 char *pbuffer;
1463 struct pci_dev *pdev;
1464 uint32_t u32val;
1465 uint16_t u16val;
1466 uint8_t u8val;
1467
1468 pdev = phba->pcidev;
1469 if (!pdev)
1470 return 0;
1471
1472 /* This is a user read operation */
1473 debug->op = LPFC_IDIAG_OP_RD;
1474
1475 if (!debug->buffer)
1476 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1477 if (!debug->buffer)
1478 return 0;
1479 pbuffer = debug->buffer;
1480
1481 if (*ppos)
1482 return 0;
1483
1484 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1485 where = idiag.cmd.data[0];
1486 count = idiag.cmd.data[1];
1487 } else
1488 return 0;
1489
1490 /* Read single PCI config space register */
1491 switch (count) {
1492 case SIZE_U8: /* byte (8 bits) */
1493 pci_read_config_byte(pdev, where, &u8val);
1494 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1495 "%03x: %02x\n", where, u8val);
1496 break;
1497 case SIZE_U16: /* word (16 bits) */
1498 pci_read_config_word(pdev, where, &u16val);
1499 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1500 "%03x: %04x\n", where, u16val);
1501 break;
1502 case SIZE_U32: /* double word (32 bits) */
1503 pci_read_config_dword(pdev, where, &u32val);
1504 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1505 "%03x: %08x\n", where, u32val);
1506 break;
1507 case LPFC_PCI_CFG_SIZE: /* browse all */
1508 goto pcicfg_browse;
1509 break;
1510 default:
1511 /* illegal count */
1512 len = 0;
1513 break;
1514 }
1515 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1516
1517pcicfg_browse:
1518
1519 /* Browse all PCI config space registers */
1520 offset_label = idiag.offset.last_rd;
1521 offset = offset_label;
1522
1523 /* Read PCI config space */
1524 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1525 "%03x: ", offset_label);
1526 while (index > 0) {
1527 pci_read_config_dword(pdev, offset, &u32val);
1528 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1529 "%08x ", u32val);
1530 offset += sizeof(uint32_t);
1531 index -= sizeof(uint32_t);
1532 if (!index)
1533 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1534 "\n");
1535 else if (!(index % (8 * sizeof(uint32_t)))) {
1536 offset_label += (8 * sizeof(uint32_t));
1537 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1538 "\n%03x: ", offset_label);
1539 }
1540 }
1541
1542 /* Set up the offset for next portion of pci cfg read */
1543 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1544 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1545 idiag.offset.last_rd = 0;
1546
1547 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1548}
1549
1550/**
1551 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1552 * @file: The file pointer to read from.
1553 * @buf: The buffer to copy the user data from.
1554 * @nbytes: The number of bytes to get.
1555 * @ppos: The position in the file to start reading from.
1556 *
1557 * This routine get the debugfs idiag command struct from user space and
1558 * then perform the syntax check for PCI config space read or write command
1559 * accordingly. In the case of PCI config space read command, it sets up
1560 * the command in the idiag command struct for the debugfs read operation.
1561 * In the case of PCI config space write operation, it executes the write
1562 * operation into the PCI config space accordingly.
1563 *
1564 * It returns the @nbytges passing in from debugfs user space when successful.
1565 * In case of error conditions, it returns proper error code back to the user
1566 * space.
1567 */
1568static ssize_t
1569lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1570 size_t nbytes, loff_t *ppos)
1571{
1572 struct lpfc_debug *debug = file->private_data;
1573 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1574 uint32_t where, value, count;
1575 uint32_t u32val;
1576 uint16_t u16val;
1577 uint8_t u8val;
1578 struct pci_dev *pdev;
1579 int rc;
1580
1581 pdev = phba->pcidev;
1582 if (!pdev)
1583 return -EFAULT;
1584
1585 /* This is a user write operation */
1586 debug->op = LPFC_IDIAG_OP_WR;
1587
1588 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1589 if (rc)
1590 return rc;
1591
1592 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1593 /* Read command from PCI config space, set up command fields */
1594 where = idiag.cmd.data[0];
1595 count = idiag.cmd.data[1];
1596 if (count == LPFC_PCI_CFG_SIZE) {
1597 if (where != 0)
1598 goto error_out;
1599 } else if ((count != sizeof(uint8_t)) &&
1600 (count != sizeof(uint16_t)) &&
1601 (count != sizeof(uint32_t)))
1602 goto error_out;
1603 if (count == sizeof(uint8_t)) {
1604 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1605 goto error_out;
1606 if (where % sizeof(uint8_t))
1607 goto error_out;
1608 }
1609 if (count == sizeof(uint16_t)) {
1610 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1611 goto error_out;
1612 if (where % sizeof(uint16_t))
1613 goto error_out;
1614 }
1615 if (count == sizeof(uint32_t)) {
1616 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1617 goto error_out;
1618 if (where % sizeof(uint32_t))
1619 goto error_out;
1620 }
1621 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1622 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1623 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1624 /* Write command to PCI config space, read-modify-write */
1625 where = idiag.cmd.data[0];
1626 count = idiag.cmd.data[1];
1627 value = idiag.cmd.data[2];
1628 /* Sanity checks */
1629 if ((count != sizeof(uint8_t)) &&
1630 (count != sizeof(uint16_t)) &&
1631 (count != sizeof(uint32_t)))
1632 goto error_out;
1633 if (count == sizeof(uint8_t)) {
1634 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1635 goto error_out;
1636 if (where % sizeof(uint8_t))
1637 goto error_out;
1638 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1639 pci_write_config_byte(pdev, where,
1640 (uint8_t)value);
1641 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1642 rc = pci_read_config_byte(pdev, where, &u8val);
1643 if (!rc) {
1644 u8val |= (uint8_t)value;
1645 pci_write_config_byte(pdev, where,
1646 u8val);
1647 }
1648 }
1649 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1650 rc = pci_read_config_byte(pdev, where, &u8val);
1651 if (!rc) {
1652 u8val &= (uint8_t)(~value);
1653 pci_write_config_byte(pdev, where,
1654 u8val);
1655 }
1656 }
1657 }
1658 if (count == sizeof(uint16_t)) {
1659 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1660 goto error_out;
1661 if (where % sizeof(uint16_t))
1662 goto error_out;
1663 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1664 pci_write_config_word(pdev, where,
1665 (uint16_t)value);
1666 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1667 rc = pci_read_config_word(pdev, where, &u16val);
1668 if (!rc) {
1669 u16val |= (uint16_t)value;
1670 pci_write_config_word(pdev, where,
1671 u16val);
1672 }
1673 }
1674 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1675 rc = pci_read_config_word(pdev, where, &u16val);
1676 if (!rc) {
1677 u16val &= (uint16_t)(~value);
1678 pci_write_config_word(pdev, where,
1679 u16val);
1680 }
1681 }
1682 }
1683 if (count == sizeof(uint32_t)) {
1684 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1685 goto error_out;
1686 if (where % sizeof(uint32_t))
1687 goto error_out;
1688 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1689 pci_write_config_dword(pdev, where, value);
1690 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1691 rc = pci_read_config_dword(pdev, where,
1692 &u32val);
1693 if (!rc) {
1694 u32val |= value;
1695 pci_write_config_dword(pdev, where,
1696 u32val);
1697 }
1698 }
1699 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1700 rc = pci_read_config_dword(pdev, where,
1701 &u32val);
1702 if (!rc) {
1703 u32val &= ~value;
1704 pci_write_config_dword(pdev, where,
1705 u32val);
1706 }
1707 }
1708 }
1709 } else
1710 /* All other opecodes are illegal for now */
1711 goto error_out;
1712
1713 return nbytes;
1714error_out:
1715 memset(&idiag, 0, sizeof(idiag));
1716 return -EINVAL;
1717}
1718
1719/**
1720 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1721 * @file: The file pointer to read from.
1722 * @buf: The buffer to copy the data to.
1723 * @nbytes: The number of bytes to read.
1724 * @ppos: The position in the file to start reading from.
1725 *
1726 * Description:
1727 * This routine reads data from the @phba SLI4 PCI function queue information,
1728 * and copies to user @buf.
1729 *
1730 * Returns:
1731 * This function returns the amount of data that was read (this could be less
1732 * than @nbytes if the end of the file was reached) or a negative error value.
1733 **/
1734static ssize_t
1735lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
1736 loff_t *ppos)
1737{
1738 struct lpfc_debug *debug = file->private_data;
1739 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1740 int len = 0, fcp_qidx;
1741 char *pbuffer;
1742
1743 if (!debug->buffer)
1744 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
1745 if (!debug->buffer)
1746 return 0;
1747 pbuffer = debug->buffer;
1748
1749 if (*ppos)
1750 return 0;
1751
1752 /* Get slow-path event queue information */
1753 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1754 "Slow-path EQ information:\n");
1755 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1756 "\tID [%02d], EQE-COUNT [%04d], "
1757 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1758 phba->sli4_hba.sp_eq->queue_id,
1759 phba->sli4_hba.sp_eq->entry_count,
1760 phba->sli4_hba.sp_eq->host_index,
1761 phba->sli4_hba.sp_eq->hba_index);
1762
1763 /* Get fast-path event queue information */
1764 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1765 "Fast-path EQ information:\n");
1766 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
1767 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1768 "\tID [%02d], EQE-COUNT [%04d], "
1769 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1770 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
1771 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
1772 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
1773 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
1774 }
1775 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1776
1777 /* Get mailbox complete queue information */
1778 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1779 "Mailbox CQ information:\n");
1780 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1781 "\t\tAssociated EQ-ID [%02d]:\n",
1782 phba->sli4_hba.mbx_cq->assoc_qid);
1783 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1784 "\tID [%02d], CQE-COUNT [%04d], "
1785 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1786 phba->sli4_hba.mbx_cq->queue_id,
1787 phba->sli4_hba.mbx_cq->entry_count,
1788 phba->sli4_hba.mbx_cq->host_index,
1789 phba->sli4_hba.mbx_cq->hba_index);
1790
1791 /* Get slow-path complete queue information */
1792 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1793 "Slow-path CQ information:\n");
1794 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1795 "\t\tAssociated EQ-ID [%02d]:\n",
1796 phba->sli4_hba.els_cq->assoc_qid);
1797 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1798 "\tID [%02d], CQE-COUNT [%04d], "
1799 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1800 phba->sli4_hba.els_cq->queue_id,
1801 phba->sli4_hba.els_cq->entry_count,
1802 phba->sli4_hba.els_cq->host_index,
1803 phba->sli4_hba.els_cq->hba_index);
1804
1805 /* Get fast-path complete queue information */
1806 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1807 "Fast-path CQ information:\n");
1808 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
1809 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1810 "\t\tAssociated EQ-ID [%02d]:\n",
1811 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
1812 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1813 "\tID [%02d], EQE-COUNT [%04d], "
1814 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1815 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
1816 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
1817 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
1818 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
1819 }
1820 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1821
1822 /* Get mailbox queue information */
1823 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1824 "Mailbox MQ information:\n");
1825 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1826 "\t\tAssociated CQ-ID [%02d]:\n",
1827 phba->sli4_hba.mbx_wq->assoc_qid);
1828 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1829 "\tID [%02d], MQE-COUNT [%04d], "
1830 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1831 phba->sli4_hba.mbx_wq->queue_id,
1832 phba->sli4_hba.mbx_wq->entry_count,
1833 phba->sli4_hba.mbx_wq->host_index,
1834 phba->sli4_hba.mbx_wq->hba_index);
1835
1836 /* Get slow-path work queue information */
1837 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1838 "Slow-path WQ information:\n");
1839 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1840 "\t\tAssociated CQ-ID [%02d]:\n",
1841 phba->sli4_hba.els_wq->assoc_qid);
1842 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1843 "\tID [%02d], WQE-COUNT [%04d], "
1844 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n\n",
1845 phba->sli4_hba.els_wq->queue_id,
1846 phba->sli4_hba.els_wq->entry_count,
1847 phba->sli4_hba.els_wq->host_index,
1848 phba->sli4_hba.els_wq->hba_index);
1849
1850 /* Get fast-path work queue information */
1851 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1852 "Fast-path WQ information:\n");
1853 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
1854 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1855 "\t\tAssociated CQ-ID [%02d]:\n",
1856 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
1857 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1858 "\tID [%02d], WQE-COUNT [%04d], "
1859 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1860 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
1861 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
1862 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
1863 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
1864 }
1865 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1866
1867 /* Get receive queue information */
1868 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1869 "Slow-path RQ information:\n");
1870 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1871 "\t\tAssociated CQ-ID [%02d]:\n",
1872 phba->sli4_hba.hdr_rq->assoc_qid);
1873 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1874 "\tID [%02d], RHQE-COUNT [%04d], "
1875 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1876 phba->sli4_hba.hdr_rq->queue_id,
1877 phba->sli4_hba.hdr_rq->entry_count,
1878 phba->sli4_hba.hdr_rq->host_index,
1879 phba->sli4_hba.hdr_rq->hba_index);
1880 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1881 "\tID [%02d], RDQE-COUNT [%04d], "
1882 "HOST-INDEX [%04x], PORT-INDEX [%04x]\n",
1883 phba->sli4_hba.dat_rq->queue_id,
1884 phba->sli4_hba.dat_rq->entry_count,
1885 phba->sli4_hba.dat_rq->host_index,
1886 phba->sli4_hba.dat_rq->hba_index);
1887
1888 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1889}
1890
1140#undef lpfc_debugfs_op_disc_trc 1891#undef lpfc_debugfs_op_disc_trc
1141static const struct file_operations lpfc_debugfs_op_disc_trc = { 1892static const struct file_operations lpfc_debugfs_op_disc_trc = {
1142 .owner = THIS_MODULE, 1893 .owner = THIS_MODULE,
@@ -1213,6 +1964,28 @@ static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
1213 1964
1214static struct dentry *lpfc_debugfs_root = NULL; 1965static struct dentry *lpfc_debugfs_root = NULL;
1215static atomic_t lpfc_debugfs_hba_count; 1966static atomic_t lpfc_debugfs_hba_count;
1967
1968/*
1969 * File operations for the iDiag debugfs
1970 */
1971#undef lpfc_idiag_op_pciCfg
1972static const struct file_operations lpfc_idiag_op_pciCfg = {
1973 .owner = THIS_MODULE,
1974 .open = lpfc_idiag_open,
1975 .llseek = lpfc_debugfs_lseek,
1976 .read = lpfc_idiag_pcicfg_read,
1977 .write = lpfc_idiag_pcicfg_write,
1978 .release = lpfc_idiag_cmd_release,
1979};
1980
1981#undef lpfc_idiag_op_queInfo
1982static const struct file_operations lpfc_idiag_op_queInfo = {
1983 .owner = THIS_MODULE,
1984 .open = lpfc_idiag_open,
1985 .read = lpfc_idiag_queinfo_read,
1986 .release = lpfc_idiag_release,
1987};
1988
1216#endif 1989#endif
1217 1990
1218/** 1991/**
@@ -1249,8 +2022,8 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
1249 if (!lpfc_debugfs_start_time) 2022 if (!lpfc_debugfs_start_time)
1250 lpfc_debugfs_start_time = jiffies; 2023 lpfc_debugfs_start_time = jiffies;
1251 2024
1252 /* Setup lpfcX directory for specific HBA */ 2025 /* Setup funcX directory for specific HBA PCI function */
1253 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no); 2026 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
1254 if (!phba->hba_debugfs_root) { 2027 if (!phba->hba_debugfs_root) {
1255 phba->hba_debugfs_root = 2028 phba->hba_debugfs_root =
1256 debugfs_create_dir(name, lpfc_debugfs_root); 2029 debugfs_create_dir(name, lpfc_debugfs_root);
@@ -1275,28 +2048,38 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
1275 } 2048 }
1276 2049
1277 /* Setup dumpHBASlim */ 2050 /* Setup dumpHBASlim */
1278 snprintf(name, sizeof(name), "dumpHBASlim"); 2051 if (phba->sli_rev < LPFC_SLI_REV4) {
1279 phba->debug_dumpHBASlim = 2052 snprintf(name, sizeof(name), "dumpHBASlim");
1280 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 2053 phba->debug_dumpHBASlim =
1281 phba->hba_debugfs_root, 2054 debugfs_create_file(name,
1282 phba, &lpfc_debugfs_op_dumpHBASlim); 2055 S_IFREG|S_IRUGO|S_IWUSR,
1283 if (!phba->debug_dumpHBASlim) { 2056 phba->hba_debugfs_root,
1284 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 2057 phba, &lpfc_debugfs_op_dumpHBASlim);
1285 "0413 Cannot create debugfs dumpHBASlim\n"); 2058 if (!phba->debug_dumpHBASlim) {
1286 goto debug_failed; 2059 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1287 } 2060 "0413 Cannot create debugfs "
2061 "dumpHBASlim\n");
2062 goto debug_failed;
2063 }
2064 } else
2065 phba->debug_dumpHBASlim = NULL;
1288 2066
1289 /* Setup dumpHostSlim */ 2067 /* Setup dumpHostSlim */
1290 snprintf(name, sizeof(name), "dumpHostSlim"); 2068 if (phba->sli_rev < LPFC_SLI_REV4) {
1291 phba->debug_dumpHostSlim = 2069 snprintf(name, sizeof(name), "dumpHostSlim");
1292 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 2070 phba->debug_dumpHostSlim =
1293 phba->hba_debugfs_root, 2071 debugfs_create_file(name,
1294 phba, &lpfc_debugfs_op_dumpHostSlim); 2072 S_IFREG|S_IRUGO|S_IWUSR,
1295 if (!phba->debug_dumpHostSlim) { 2073 phba->hba_debugfs_root,
1296 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 2074 phba, &lpfc_debugfs_op_dumpHostSlim);
1297 "0414 Cannot create debugfs dumpHostSlim\n"); 2075 if (!phba->debug_dumpHostSlim) {
1298 goto debug_failed; 2076 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1299 } 2077 "0414 Cannot create debugfs "
2078 "dumpHostSlim\n");
2079 goto debug_failed;
2080 }
2081 } else
2082 phba->debug_dumpHBASlim = NULL;
1300 2083
1301 /* Setup dumpData */ 2084 /* Setup dumpData */
1302 snprintf(name, sizeof(name), "dumpData"); 2085 snprintf(name, sizeof(name), "dumpData");
@@ -1322,8 +2105,6 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
1322 goto debug_failed; 2105 goto debug_failed;
1323 } 2106 }
1324 2107
1325
1326
1327 /* Setup slow ring trace */ 2108 /* Setup slow ring trace */
1328 if (lpfc_debugfs_max_slow_ring_trc) { 2109 if (lpfc_debugfs_max_slow_ring_trc) {
1329 num = lpfc_debugfs_max_slow_ring_trc - 1; 2110 num = lpfc_debugfs_max_slow_ring_trc - 1;
@@ -1342,7 +2123,6 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
1342 } 2123 }
1343 } 2124 }
1344 2125
1345
1346 snprintf(name, sizeof(name), "slow_ring_trace"); 2126 snprintf(name, sizeof(name), "slow_ring_trace");
1347 phba->debug_slow_ring_trc = 2127 phba->debug_slow_ring_trc =
1348 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 2128 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
@@ -1434,6 +2214,53 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
1434 "0409 Cant create debugfs nodelist\n"); 2214 "0409 Cant create debugfs nodelist\n");
1435 goto debug_failed; 2215 goto debug_failed;
1436 } 2216 }
2217
2218 /*
2219 * iDiag debugfs root entry points for SLI4 device only
2220 */
2221 if (phba->sli_rev < LPFC_SLI_REV4)
2222 goto debug_failed;
2223
2224 snprintf(name, sizeof(name), "iDiag");
2225 if (!phba->idiag_root) {
2226 phba->idiag_root =
2227 debugfs_create_dir(name, phba->hba_debugfs_root);
2228 if (!phba->idiag_root) {
2229 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2230 "2922 Can't create idiag debugfs\n");
2231 goto debug_failed;
2232 }
2233 /* Initialize iDiag data structure */
2234 memset(&idiag, 0, sizeof(idiag));
2235 }
2236
2237 /* iDiag read PCI config space */
2238 snprintf(name, sizeof(name), "pciCfg");
2239 if (!phba->idiag_pci_cfg) {
2240 phba->idiag_pci_cfg =
2241 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2242 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
2243 if (!phba->idiag_pci_cfg) {
2244 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2245 "2923 Can't create idiag debugfs\n");
2246 goto debug_failed;
2247 }
2248 idiag.offset.last_rd = 0;
2249 }
2250
2251 /* iDiag get PCI function queue information */
2252 snprintf(name, sizeof(name), "queInfo");
2253 if (!phba->idiag_que_info) {
2254 phba->idiag_que_info =
2255 debugfs_create_file(name, S_IFREG|S_IRUGO,
2256 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
2257 if (!phba->idiag_que_info) {
2258 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2259 "2924 Can't create idiag debugfs\n");
2260 goto debug_failed;
2261 }
2262 }
2263
1437debug_failed: 2264debug_failed:
1438 return; 2265 return;
1439#endif 2266#endif
@@ -1508,8 +2335,31 @@ lpfc_debugfs_terminate(struct lpfc_vport *vport)
1508 phba->debug_slow_ring_trc = NULL; 2335 phba->debug_slow_ring_trc = NULL;
1509 } 2336 }
1510 2337
2338 /*
2339 * iDiag release
2340 */
2341 if (phba->sli_rev == LPFC_SLI_REV4) {
2342 if (phba->idiag_que_info) {
2343 /* iDiag queInfo */
2344 debugfs_remove(phba->idiag_que_info);
2345 phba->idiag_que_info = NULL;
2346 }
2347 if (phba->idiag_pci_cfg) {
2348 /* iDiag pciCfg */
2349 debugfs_remove(phba->idiag_pci_cfg);
2350 phba->idiag_pci_cfg = NULL;
2351 }
2352
2353 /* Finally remove the iDiag debugfs root */
2354 if (phba->idiag_root) {
2355 /* iDiag root */
2356 debugfs_remove(phba->idiag_root);
2357 phba->idiag_root = NULL;
2358 }
2359 }
2360
1511 if (phba->hba_debugfs_root) { 2361 if (phba->hba_debugfs_root) {
1512 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */ 2362 debugfs_remove(phba->hba_debugfs_root); /* fnX */
1513 phba->hba_debugfs_root = NULL; 2363 phba->hba_debugfs_root = NULL;
1514 atomic_dec(&lpfc_debugfs_hba_count); 2364 atomic_dec(&lpfc_debugfs_hba_count);
1515 } 2365 }
diff --git a/drivers/scsi/lpfc/lpfc_debugfs.h b/drivers/scsi/lpfc/lpfc_debugfs.h
index 03c7313a1012..91b9a9427cda 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.h
+++ b/drivers/scsi/lpfc/lpfc_debugfs.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007 Emulex. All rights reserved. * 4 * Copyright (C) 2007-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -22,6 +22,44 @@
22#define _H_LPFC_DEBUG_FS 22#define _H_LPFC_DEBUG_FS
23 23
24#ifdef CONFIG_SCSI_LPFC_DEBUG_FS 24#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
25
26/* size of output line, for discovery_trace and slow_ring_trace */
27#define LPFC_DEBUG_TRC_ENTRY_SIZE 100
28
29/* nodelist output buffer size */
30#define LPFC_NODELIST_SIZE 8192
31#define LPFC_NODELIST_ENTRY_SIZE 120
32
33/* dumpHBASlim output buffer size */
34#define LPFC_DUMPHBASLIM_SIZE 4096
35
36/* dumpHostSlim output buffer size */
37#define LPFC_DUMPHOSTSLIM_SIZE 4096
38
39/* hbqinfo output buffer size */
40#define LPFC_HBQINFO_SIZE 8192
41
42/* rdPciConf output buffer size */
43#define LPFC_PCI_CFG_SIZE 4096
44#define LPFC_PCI_CFG_RD_BUF_SIZE (LPFC_PCI_CFG_SIZE/2)
45#define LPFC_PCI_CFG_RD_SIZE (LPFC_PCI_CFG_SIZE/4)
46
47/* queue info output buffer size */
48#define LPFC_QUE_INFO_GET_BUF_SIZE 2048
49
50#define SIZE_U8 sizeof(uint8_t)
51#define SIZE_U16 sizeof(uint16_t)
52#define SIZE_U32 sizeof(uint32_t)
53
54struct lpfc_debug {
55 char *i_private;
56 char op;
57#define LPFC_IDIAG_OP_RD 1
58#define LPFC_IDIAG_OP_WR 2
59 char *buffer;
60 int len;
61};
62
25struct lpfc_debugfs_trc { 63struct lpfc_debugfs_trc {
26 char *fmt; 64 char *fmt;
27 uint32_t data1; 65 uint32_t data1;
@@ -30,6 +68,26 @@ struct lpfc_debugfs_trc {
30 uint32_t seq_cnt; 68 uint32_t seq_cnt;
31 unsigned long jif; 69 unsigned long jif;
32}; 70};
71
72struct lpfc_idiag_offset {
73 uint32_t last_rd;
74};
75
76#define LPFC_IDIAG_CMD_DATA_SIZE 4
77struct lpfc_idiag_cmd {
78 uint32_t opcode;
79#define LPFC_IDIAG_CMD_PCICFG_RD 0x00000001
80#define LPFC_IDIAG_CMD_PCICFG_WR 0x00000002
81#define LPFC_IDIAG_CMD_PCICFG_ST 0x00000003
82#define LPFC_IDIAG_CMD_PCICFG_CL 0x00000004
83 uint32_t data[LPFC_IDIAG_CMD_DATA_SIZE];
84};
85
86struct lpfc_idiag {
87 uint32_t active;
88 struct lpfc_idiag_cmd cmd;
89 struct lpfc_idiag_offset offset;
90};
33#endif 91#endif
34 92
35/* Mask for discovery_trace */ 93/* Mask for discovery_trace */
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index c62d567cc845..8e28edf9801e 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -485,6 +485,59 @@ fail:
485} 485}
486 486
487/** 487/**
488 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
489 * @vport: pointer to a host virtual N_Port data structure.
490 * @sp: pointer to service parameter data structure.
491 *
492 * This routine is called from FLOGI/FDISC completion handler functions.
493 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
494 * node nodename is changed in the completion service parameter else return
495 * 0. This function also set flag in the vport data structure to delay
496 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
497 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
498 * node nodename is changed in the completion service parameter.
499 *
500 * Return code
501 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
502 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
503 *
504 **/
505static uint8_t
506lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
507 struct serv_parm *sp)
508{
509 uint8_t fabric_param_changed = 0;
510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
511
512 if ((vport->fc_prevDID != vport->fc_myDID) ||
513 memcmp(&vport->fabric_portname, &sp->portName,
514 sizeof(struct lpfc_name)) ||
515 memcmp(&vport->fabric_nodename, &sp->nodeName,
516 sizeof(struct lpfc_name)))
517 fabric_param_changed = 1;
518
519 /*
520 * Word 1 Bit 31 in common service parameter is overloaded.
521 * Word 1 Bit 31 in FLOGI request is multiple NPort request
522 * Word 1 Bit 31 in FLOGI response is clean address bit
523 *
524 * If fabric parameter is changed and clean address bit is
525 * cleared delay nport discovery if
526 * - vport->fc_prevDID != 0 (not initial discovery) OR
527 * - lpfc_delay_discovery module parameter is set.
528 */
529 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
530 (vport->fc_prevDID || lpfc_delay_discovery)) {
531 spin_lock_irq(shost->host_lock);
532 vport->fc_flag |= FC_DISC_DELAYED;
533 spin_unlock_irq(shost->host_lock);
534 }
535
536 return fabric_param_changed;
537}
538
539
540/**
488 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port 541 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
489 * @vport: pointer to a host virtual N_Port data structure. 542 * @vport: pointer to a host virtual N_Port data structure.
490 * @ndlp: pointer to a node-list data structure. 543 * @ndlp: pointer to a node-list data structure.
@@ -512,6 +565,7 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
512 struct lpfc_hba *phba = vport->phba; 565 struct lpfc_hba *phba = vport->phba;
513 struct lpfc_nodelist *np; 566 struct lpfc_nodelist *np;
514 struct lpfc_nodelist *next_np; 567 struct lpfc_nodelist *next_np;
568 uint8_t fabric_param_changed;
515 569
516 spin_lock_irq(shost->host_lock); 570 spin_lock_irq(shost->host_lock);
517 vport->fc_flag |= FC_FABRIC; 571 vport->fc_flag |= FC_FABRIC;
@@ -544,6 +598,12 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
544 ndlp->nlp_class_sup |= FC_COS_CLASS4; 598 ndlp->nlp_class_sup |= FC_COS_CLASS4;
545 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | 599 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
546 sp->cmn.bbRcvSizeLsb; 600 sp->cmn.bbRcvSizeLsb;
601
602 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
603 memcpy(&vport->fabric_portname, &sp->portName,
604 sizeof(struct lpfc_name));
605 memcpy(&vport->fabric_nodename, &sp->nodeName,
606 sizeof(struct lpfc_name));
547 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); 607 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
548 608
549 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { 609 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
@@ -565,7 +625,7 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
565 } 625 }
566 } 626 }
567 627
568 if ((vport->fc_prevDID != vport->fc_myDID) && 628 if (fabric_param_changed &&
569 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { 629 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
570 630
571 /* If our NportID changed, we need to ensure all 631 /* If our NportID changed, we need to ensure all
@@ -2203,6 +2263,7 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2203 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 2263 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2204 IOCB_t *irsp; 2264 IOCB_t *irsp;
2205 struct lpfc_sli *psli; 2265 struct lpfc_sli *psli;
2266 struct lpfcMboxq *mbox;
2206 2267
2207 psli = &phba->sli; 2268 psli = &phba->sli;
2208 /* we pass cmdiocb to state machine which needs rspiocb as well */ 2269 /* we pass cmdiocb to state machine which needs rspiocb as well */
@@ -2260,6 +2321,21 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2260 NLP_EVT_CMPL_LOGO); 2321 NLP_EVT_CMPL_LOGO);
2261out: 2322out:
2262 lpfc_els_free_iocb(phba, cmdiocb); 2323 lpfc_els_free_iocb(phba, cmdiocb);
2324 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2325 if ((vport->fc_flag & FC_PT2PT) &&
2326 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2327 phba->pport->fc_myDID = 0;
2328 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2329 if (mbox) {
2330 lpfc_config_link(phba, mbox);
2331 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2332 mbox->vport = vport;
2333 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2334 MBX_NOT_FINISHED) {
2335 mempool_free(mbox, phba->mbox_mem_pool);
2336 }
2337 }
2338 }
2263 return; 2339 return;
2264} 2340}
2265 2341
@@ -2745,7 +2821,8 @@ lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2745 } 2821 }
2746 break; 2822 break;
2747 case ELS_CMD_FDISC: 2823 case ELS_CMD_FDISC:
2748 lpfc_issue_els_fdisc(vport, ndlp, retry); 2824 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2825 lpfc_issue_els_fdisc(vport, ndlp, retry);
2749 break; 2826 break;
2750 } 2827 }
2751 return; 2828 return;
@@ -2815,9 +2892,17 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2815 2892
2816 switch (irsp->ulpStatus) { 2893 switch (irsp->ulpStatus) {
2817 case IOSTAT_FCP_RSP_ERROR: 2894 case IOSTAT_FCP_RSP_ERROR:
2895 break;
2818 case IOSTAT_REMOTE_STOP: 2896 case IOSTAT_REMOTE_STOP:
2897 if (phba->sli_rev == LPFC_SLI_REV4) {
2898 /* This IO was aborted by the target, we don't
2899 * know the rxid and because we did not send the
2900 * ABTS we cannot generate and RRQ.
2901 */
2902 lpfc_set_rrq_active(phba, ndlp,
2903 cmdiocb->sli4_xritag, 0, 0);
2904 }
2819 break; 2905 break;
2820
2821 case IOSTAT_LOCAL_REJECT: 2906 case IOSTAT_LOCAL_REJECT:
2822 switch ((irsp->un.ulpWord[4] & 0xff)) { 2907 switch ((irsp->un.ulpWord[4] & 0xff)) {
2823 case IOERR_LOOP_OPEN_FAILURE: 2908 case IOERR_LOOP_OPEN_FAILURE:
@@ -4013,28 +4098,34 @@ lpfc_els_clear_rrq(struct lpfc_vport *vport,
4013 uint8_t *pcmd; 4098 uint8_t *pcmd;
4014 struct RRQ *rrq; 4099 struct RRQ *rrq;
4015 uint16_t rxid; 4100 uint16_t rxid;
4101 uint16_t xri;
4016 struct lpfc_node_rrq *prrq; 4102 struct lpfc_node_rrq *prrq;
4017 4103
4018 4104
4019 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt); 4105 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4020 pcmd += sizeof(uint32_t); 4106 pcmd += sizeof(uint32_t);
4021 rrq = (struct RRQ *)pcmd; 4107 rrq = (struct RRQ *)pcmd;
4022 rxid = bf_get(rrq_oxid, rrq); 4108 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4109 rxid = be16_to_cpu(bf_get(rrq_rxid, rrq));
4023 4110
4024 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 4111 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4025 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" 4112 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4026 " x%x x%x\n", 4113 " x%x x%x\n",
4027 bf_get(rrq_did, rrq), 4114 be32_to_cpu(bf_get(rrq_did, rrq)),
4028 bf_get(rrq_oxid, rrq), 4115 be16_to_cpu(bf_get(rrq_oxid, rrq)),
4029 rxid, 4116 rxid,
4030 iocb->iotag, iocb->iocb.ulpContext); 4117 iocb->iotag, iocb->iocb.ulpContext);
4031 4118
4032 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 4119 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4033 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x", 4120 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4034 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); 4121 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4035 prrq = lpfc_get_active_rrq(vport, rxid, ndlp->nlp_DID); 4122 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4123 xri = be16_to_cpu(bf_get(rrq_oxid, rrq));
4124 else
4125 xri = rxid;
4126 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
4036 if (prrq) 4127 if (prrq)
4037 lpfc_clr_rrq_active(phba, rxid, prrq); 4128 lpfc_clr_rrq_active(phba, xri, prrq);
4038 return; 4129 return;
4039} 4130}
4040 4131
@@ -6166,6 +6257,11 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6166 if (vport->load_flag & FC_UNLOADING) 6257 if (vport->load_flag & FC_UNLOADING)
6167 goto dropit; 6258 goto dropit;
6168 6259
6260 /* If NPort discovery is delayed drop incoming ELS */
6261 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6262 (cmd != ELS_CMD_PLOGI))
6263 goto dropit;
6264
6169 ndlp = lpfc_findnode_did(vport, did); 6265 ndlp = lpfc_findnode_did(vport, did);
6170 if (!ndlp) { 6266 if (!ndlp) {
6171 /* Cannot find existing Fabric ndlp, so allocate a new one */ 6267 /* Cannot find existing Fabric ndlp, so allocate a new one */
@@ -6218,6 +6314,12 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6218 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); 6314 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6219 6315
6220 lpfc_send_els_event(vport, ndlp, payload); 6316 lpfc_send_els_event(vport, ndlp, payload);
6317
6318 /* If Nport discovery is delayed, reject PLOGIs */
6319 if (vport->fc_flag & FC_DISC_DELAYED) {
6320 rjt_err = LSRJT_UNABLE_TPC;
6321 break;
6322 }
6221 if (vport->port_state < LPFC_DISC_AUTH) { 6323 if (vport->port_state < LPFC_DISC_AUTH) {
6222 if (!(phba->pport->fc_flag & FC_PT2PT) || 6324 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6223 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { 6325 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
@@ -6596,6 +6698,21 @@ void
6596lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) 6698lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6597{ 6699{
6598 struct lpfc_nodelist *ndlp, *ndlp_fdmi; 6700 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6701 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6702
6703 /*
6704 * If lpfc_delay_discovery parameter is set and the clean address
6705 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6706 * discovery.
6707 */
6708 spin_lock_irq(shost->host_lock);
6709 if (vport->fc_flag & FC_DISC_DELAYED) {
6710 spin_unlock_irq(shost->host_lock);
6711 mod_timer(&vport->delayed_disc_tmo,
6712 jiffies + HZ * phba->fc_ratov);
6713 return;
6714 }
6715 spin_unlock_irq(shost->host_lock);
6599 6716
6600 ndlp = lpfc_findnode_did(vport, NameServer_DID); 6717 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6601 if (!ndlp) { 6718 if (!ndlp) {
@@ -6938,6 +7055,9 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6938 struct lpfc_nodelist *next_np; 7055 struct lpfc_nodelist *next_np;
6939 IOCB_t *irsp = &rspiocb->iocb; 7056 IOCB_t *irsp = &rspiocb->iocb;
6940 struct lpfc_iocbq *piocb; 7057 struct lpfc_iocbq *piocb;
7058 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7059 struct serv_parm *sp;
7060 uint8_t fabric_param_changed;
6941 7061
6942 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7062 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6943 "0123 FDISC completes. x%x/x%x prevDID: x%x\n", 7063 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
@@ -6981,7 +7101,14 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6981 7101
6982 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; 7102 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6983 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); 7103 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6984 if ((vport->fc_prevDID != vport->fc_myDID) && 7104 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7105 sp = prsp->virt + sizeof(uint32_t);
7106 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7107 memcpy(&vport->fabric_portname, &sp->portName,
7108 sizeof(struct lpfc_name));
7109 memcpy(&vport->fabric_nodename, &sp->nodeName,
7110 sizeof(struct lpfc_name));
7111 if (fabric_param_changed &&
6985 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { 7112 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6986 /* If our NportID changed, we need to ensure all 7113 /* If our NportID changed, we need to ensure all
6987 * remaining NPORTs get unreg_login'ed so we can 7114 * remaining NPORTs get unreg_login'ed so we can
@@ -7582,6 +7709,32 @@ void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7582} 7709}
7583 7710
7584/** 7711/**
7712 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7713 * @vport: pointer to lpfc vport data structure.
7714 *
7715 * This routine is invoked by the vport cleanup for deletions and the cleanup
7716 * for an ndlp on removal.
7717 **/
7718void
7719lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7720{
7721 struct lpfc_hba *phba = vport->phba;
7722 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7723 unsigned long iflag = 0;
7724
7725 spin_lock_irqsave(&phba->hbalock, iflag);
7726 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7727 list_for_each_entry_safe(sglq_entry, sglq_next,
7728 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7729 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7730 sglq_entry->ndlp = NULL;
7731 }
7732 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7733 spin_unlock_irqrestore(&phba->hbalock, iflag);
7734 return;
7735}
7736
7737/**
7585 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort 7738 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7586 * @phba: pointer to lpfc hba data structure. 7739 * @phba: pointer to lpfc hba data structure.
7587 * @axri: pointer to the els xri abort wcqe structure. 7740 * @axri: pointer to the els xri abort wcqe structure.
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index bb015960dbc9..154c715fb3af 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -658,6 +658,8 @@ lpfc_work_done(struct lpfc_hba *phba)
658 lpfc_ramp_down_queue_handler(phba); 658 lpfc_ramp_down_queue_handler(phba);
659 if (work_port_events & WORKER_RAMP_UP_QUEUE) 659 if (work_port_events & WORKER_RAMP_UP_QUEUE)
660 lpfc_ramp_up_queue_handler(phba); 660 lpfc_ramp_up_queue_handler(phba);
661 if (work_port_events & WORKER_DELAYED_DISC_TMO)
662 lpfc_delayed_disc_timeout_handler(vport);
661 } 663 }
662 lpfc_destroy_vport_work_array(phba, vports); 664 lpfc_destroy_vport_work_array(phba, vports);
663 665
@@ -838,6 +840,11 @@ lpfc_linkdown_port(struct lpfc_vport *vport)
838 840
839 lpfc_port_link_failure(vport); 841 lpfc_port_link_failure(vport);
840 842
843 /* Stop delayed Nport discovery */
844 spin_lock_irq(shost->host_lock);
845 vport->fc_flag &= ~FC_DISC_DELAYED;
846 spin_unlock_irq(shost->host_lock);
847 del_timer_sync(&vport->delayed_disc_tmo);
841} 848}
842 849
843int 850int
@@ -3160,7 +3167,7 @@ lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3160 spin_unlock_irq(shost->host_lock); 3167 spin_unlock_irq(shost->host_lock);
3161 vport->unreg_vpi_cmpl = VPORT_OK; 3168 vport->unreg_vpi_cmpl = VPORT_OK;
3162 mempool_free(pmb, phba->mbox_mem_pool); 3169 mempool_free(pmb, phba->mbox_mem_pool);
3163 lpfc_cleanup_vports_rrqs(vport); 3170 lpfc_cleanup_vports_rrqs(vport, NULL);
3164 /* 3171 /*
3165 * This shost reference might have been taken at the beginning of 3172 * This shost reference might have been taken at the beginning of
3166 * lpfc_vport_delete() 3173 * lpfc_vport_delete()
@@ -3900,6 +3907,8 @@ lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3900 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) 3907 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3901 return; 3908 return;
3902 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); 3909 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
3910 if (vport->phba->sli_rev == LPFC_SLI_REV4)
3911 lpfc_cleanup_vports_rrqs(vport, ndlp);
3903 lpfc_nlp_put(ndlp); 3912 lpfc_nlp_put(ndlp);
3904 return; 3913 return;
3905} 3914}
@@ -4289,7 +4298,7 @@ lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4289 4298
4290 list_del_init(&ndlp->els_retry_evt.evt_listp); 4299 list_del_init(&ndlp->els_retry_evt.evt_listp);
4291 list_del_init(&ndlp->dev_loss_evt.evt_listp); 4300 list_del_init(&ndlp->dev_loss_evt.evt_listp);
4292 4301 lpfc_cleanup_vports_rrqs(vport, ndlp);
4293 lpfc_unreg_rpi(vport, ndlp); 4302 lpfc_unreg_rpi(vport, ndlp);
4294 4303
4295 return 0; 4304 return 0;
@@ -4426,10 +4435,11 @@ lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4426{ 4435{
4427 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 4436 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4428 struct lpfc_nodelist *ndlp; 4437 struct lpfc_nodelist *ndlp;
4438 unsigned long iflags;
4429 4439
4430 spin_lock_irq(shost->host_lock); 4440 spin_lock_irqsave(shost->host_lock, iflags);
4431 ndlp = __lpfc_findnode_did(vport, did); 4441 ndlp = __lpfc_findnode_did(vport, did);
4432 spin_unlock_irq(shost->host_lock); 4442 spin_unlock_irqrestore(shost->host_lock, iflags);
4433 return ndlp; 4443 return ndlp;
4434} 4444}
4435 4445
diff --git a/drivers/scsi/lpfc/lpfc_hw.h b/drivers/scsi/lpfc/lpfc_hw.h
index 96ed3ba6ba95..94ae37c5111a 100644
--- a/drivers/scsi/lpfc/lpfc_hw.h
+++ b/drivers/scsi/lpfc/lpfc_hw.h
@@ -341,6 +341,12 @@ struct csp {
341 uint8_t bbCreditMsb; 341 uint8_t bbCreditMsb;
342 uint8_t bbCreditlsb; /* FC Word 0, byte 3 */ 342 uint8_t bbCreditlsb; /* FC Word 0, byte 3 */
343 343
344/*
345 * Word 1 Bit 31 in common service parameter is overloaded.
346 * Word 1 Bit 31 in FLOGI request is multiple NPort request
347 * Word 1 Bit 31 in FLOGI response is clean address bit
348 */
349#define clean_address_bit request_multiple_Nport /* Word 1, bit 31 */
344#ifdef __BIG_ENDIAN_BITFIELD 350#ifdef __BIG_ENDIAN_BITFIELD
345 uint16_t request_multiple_Nport:1; /* FC Word 1, bit 31 */ 351 uint16_t request_multiple_Nport:1; /* FC Word 1, bit 31 */
346 uint16_t randomOffset:1; /* FC Word 1, bit 30 */ 352 uint16_t randomOffset:1; /* FC Word 1, bit 30 */
@@ -3198,7 +3204,10 @@ typedef struct {
3198#define IOERR_SLER_RRQ_RJT_ERR 0x4C 3204#define IOERR_SLER_RRQ_RJT_ERR 0x4C
3199#define IOERR_SLER_RRQ_RETRY_ERR 0x4D 3205#define IOERR_SLER_RRQ_RETRY_ERR 0x4D
3200#define IOERR_SLER_ABTS_ERR 0x4E 3206#define IOERR_SLER_ABTS_ERR 0x4E
3201 3207#define IOERR_ELXSEC_KEY_UNWRAP_ERROR 0xF0
3208#define IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR 0xF1
3209#define IOERR_ELXSEC_CRYPTO_ERROR 0xF2
3210#define IOERR_ELXSEC_CRYPTO_COMPARE_ERROR 0xF3
3202#define IOERR_DRVR_MASK 0x100 3211#define IOERR_DRVR_MASK 0x100
3203#define IOERR_SLI_DOWN 0x101 /* ulpStatus - Driver defined */ 3212#define IOERR_SLI_DOWN 0x101 /* ulpStatus - Driver defined */
3204#define IOERR_SLI_BRESET 0x102 3213#define IOERR_SLI_BRESET 0x102
diff --git a/drivers/scsi/lpfc/lpfc_hw4.h b/drivers/scsi/lpfc/lpfc_hw4.h
index 94c1aa1136de..c7178d60c7bf 100644
--- a/drivers/scsi/lpfc/lpfc_hw4.h
+++ b/drivers/scsi/lpfc/lpfc_hw4.h
@@ -778,6 +778,7 @@ struct mbox_header {
778#define LPFC_MBOX_OPCODE_QUERY_FW_CFG 0x3A 778#define LPFC_MBOX_OPCODE_QUERY_FW_CFG 0x3A
779#define LPFC_MBOX_OPCODE_FUNCTION_RESET 0x3D 779#define LPFC_MBOX_OPCODE_FUNCTION_RESET 0x3D
780#define LPFC_MBOX_OPCODE_MQ_CREATE_EXT 0x5A 780#define LPFC_MBOX_OPCODE_MQ_CREATE_EXT 0x5A
781#define LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS 0xB5
781 782
782/* FCoE Opcodes */ 783/* FCoE Opcodes */
783#define LPFC_MBOX_OPCODE_FCOE_WQ_CREATE 0x01 784#define LPFC_MBOX_OPCODE_FCOE_WQ_CREATE 0x01
@@ -1852,6 +1853,9 @@ struct lpfc_mbx_request_features {
1852#define lpfc_mbx_rq_ftr_rq_ifip_SHIFT 7 1853#define lpfc_mbx_rq_ftr_rq_ifip_SHIFT 7
1853#define lpfc_mbx_rq_ftr_rq_ifip_MASK 0x00000001 1854#define lpfc_mbx_rq_ftr_rq_ifip_MASK 0x00000001
1854#define lpfc_mbx_rq_ftr_rq_ifip_WORD word2 1855#define lpfc_mbx_rq_ftr_rq_ifip_WORD word2
1856#define lpfc_mbx_rq_ftr_rq_perfh_SHIFT 11
1857#define lpfc_mbx_rq_ftr_rq_perfh_MASK 0x00000001
1858#define lpfc_mbx_rq_ftr_rq_perfh_WORD word2
1855 uint32_t word3; 1859 uint32_t word3;
1856#define lpfc_mbx_rq_ftr_rsp_iaab_SHIFT 0 1860#define lpfc_mbx_rq_ftr_rsp_iaab_SHIFT 0
1857#define lpfc_mbx_rq_ftr_rsp_iaab_MASK 0x00000001 1861#define lpfc_mbx_rq_ftr_rsp_iaab_MASK 0x00000001
@@ -1877,6 +1881,9 @@ struct lpfc_mbx_request_features {
1877#define lpfc_mbx_rq_ftr_rsp_ifip_SHIFT 7 1881#define lpfc_mbx_rq_ftr_rsp_ifip_SHIFT 7
1878#define lpfc_mbx_rq_ftr_rsp_ifip_MASK 0x00000001 1882#define lpfc_mbx_rq_ftr_rsp_ifip_MASK 0x00000001
1879#define lpfc_mbx_rq_ftr_rsp_ifip_WORD word3 1883#define lpfc_mbx_rq_ftr_rsp_ifip_WORD word3
1884#define lpfc_mbx_rq_ftr_rsp_perfh_SHIFT 11
1885#define lpfc_mbx_rq_ftr_rsp_perfh_MASK 0x00000001
1886#define lpfc_mbx_rq_ftr_rsp_perfh_WORD word3
1880}; 1887};
1881 1888
1882struct lpfc_mbx_supp_pages { 1889struct lpfc_mbx_supp_pages {
@@ -1935,7 +1942,7 @@ struct lpfc_mbx_supp_pages {
1935#define LPFC_SLI4_PARAMETERS 2 1942#define LPFC_SLI4_PARAMETERS 2
1936}; 1943};
1937 1944
1938struct lpfc_mbx_sli4_params { 1945struct lpfc_mbx_pc_sli4_params {
1939 uint32_t word1; 1946 uint32_t word1;
1940#define qs_SHIFT 0 1947#define qs_SHIFT 0
1941#define qs_MASK 0x00000001 1948#define qs_MASK 0x00000001
@@ -2051,6 +2058,88 @@ struct lpfc_mbx_sli4_params {
2051 uint32_t rsvd_13_63[51]; 2058 uint32_t rsvd_13_63[51];
2052}; 2059};
2053 2060
2061struct lpfc_sli4_parameters {
2062 uint32_t word0;
2063#define cfg_prot_type_SHIFT 0
2064#define cfg_prot_type_MASK 0x000000FF
2065#define cfg_prot_type_WORD word0
2066 uint32_t word1;
2067#define cfg_ft_SHIFT 0
2068#define cfg_ft_MASK 0x00000001
2069#define cfg_ft_WORD word1
2070#define cfg_sli_rev_SHIFT 4
2071#define cfg_sli_rev_MASK 0x0000000f
2072#define cfg_sli_rev_WORD word1
2073#define cfg_sli_family_SHIFT 8
2074#define cfg_sli_family_MASK 0x0000000f
2075#define cfg_sli_family_WORD word1
2076#define cfg_if_type_SHIFT 12
2077#define cfg_if_type_MASK 0x0000000f
2078#define cfg_if_type_WORD word1
2079#define cfg_sli_hint_1_SHIFT 16
2080#define cfg_sli_hint_1_MASK 0x000000ff
2081#define cfg_sli_hint_1_WORD word1
2082#define cfg_sli_hint_2_SHIFT 24
2083#define cfg_sli_hint_2_MASK 0x0000001f
2084#define cfg_sli_hint_2_WORD word1
2085 uint32_t word2;
2086 uint32_t word3;
2087 uint32_t word4;
2088#define cfg_cqv_SHIFT 14
2089#define cfg_cqv_MASK 0x00000003
2090#define cfg_cqv_WORD word4
2091 uint32_t word5;
2092 uint32_t word6;
2093#define cfg_mqv_SHIFT 14
2094#define cfg_mqv_MASK 0x00000003
2095#define cfg_mqv_WORD word6
2096 uint32_t word7;
2097 uint32_t word8;
2098#define cfg_wqv_SHIFT 14
2099#define cfg_wqv_MASK 0x00000003
2100#define cfg_wqv_WORD word8
2101 uint32_t word9;
2102 uint32_t word10;
2103#define cfg_rqv_SHIFT 14
2104#define cfg_rqv_MASK 0x00000003
2105#define cfg_rqv_WORD word10
2106 uint32_t word11;
2107#define cfg_rq_db_window_SHIFT 28
2108#define cfg_rq_db_window_MASK 0x0000000f
2109#define cfg_rq_db_window_WORD word11
2110 uint32_t word12;
2111#define cfg_fcoe_SHIFT 0
2112#define cfg_fcoe_MASK 0x00000001
2113#define cfg_fcoe_WORD word12
2114#define cfg_phwq_SHIFT 15
2115#define cfg_phwq_MASK 0x00000001
2116#define cfg_phwq_WORD word12
2117#define cfg_loopbk_scope_SHIFT 28
2118#define cfg_loopbk_scope_MASK 0x0000000f
2119#define cfg_loopbk_scope_WORD word12
2120 uint32_t sge_supp_len;
2121 uint32_t word14;
2122#define cfg_sgl_page_cnt_SHIFT 0
2123#define cfg_sgl_page_cnt_MASK 0x0000000f
2124#define cfg_sgl_page_cnt_WORD word14
2125#define cfg_sgl_page_size_SHIFT 8
2126#define cfg_sgl_page_size_MASK 0x000000ff
2127#define cfg_sgl_page_size_WORD word14
2128#define cfg_sgl_pp_align_SHIFT 16
2129#define cfg_sgl_pp_align_MASK 0x000000ff
2130#define cfg_sgl_pp_align_WORD word14
2131 uint32_t word15;
2132 uint32_t word16;
2133 uint32_t word17;
2134 uint32_t word18;
2135 uint32_t word19;
2136};
2137
2138struct lpfc_mbx_get_sli4_parameters {
2139 struct mbox_header header;
2140 struct lpfc_sli4_parameters sli4_parameters;
2141};
2142
2054/* Mailbox Completion Queue Error Messages */ 2143/* Mailbox Completion Queue Error Messages */
2055#define MB_CQE_STATUS_SUCCESS 0x0 2144#define MB_CQE_STATUS_SUCCESS 0x0
2056#define MB_CQE_STATUS_INSUFFICIENT_PRIVILEGES 0x1 2145#define MB_CQE_STATUS_INSUFFICIENT_PRIVILEGES 0x1
@@ -2103,7 +2192,8 @@ struct lpfc_mqe {
2103 struct lpfc_mbx_post_hdr_tmpl hdr_tmpl; 2192 struct lpfc_mbx_post_hdr_tmpl hdr_tmpl;
2104 struct lpfc_mbx_query_fw_cfg query_fw_cfg; 2193 struct lpfc_mbx_query_fw_cfg query_fw_cfg;
2105 struct lpfc_mbx_supp_pages supp_pages; 2194 struct lpfc_mbx_supp_pages supp_pages;
2106 struct lpfc_mbx_sli4_params sli4_params; 2195 struct lpfc_mbx_pc_sli4_params sli4_params;
2196 struct lpfc_mbx_get_sli4_parameters get_sli4_parameters;
2107 struct lpfc_mbx_nop nop; 2197 struct lpfc_mbx_nop nop;
2108 } un; 2198 } un;
2109}; 2199};
@@ -2381,6 +2471,10 @@ struct wqe_common {
2381#define wqe_wqes_SHIFT 15 2471#define wqe_wqes_SHIFT 15
2382#define wqe_wqes_MASK 0x00000001 2472#define wqe_wqes_MASK 0x00000001
2383#define wqe_wqes_WORD word10 2473#define wqe_wqes_WORD word10
2474/* Note that this field overlaps above fields */
2475#define wqe_wqid_SHIFT 1
2476#define wqe_wqid_MASK 0x0000007f
2477#define wqe_wqid_WORD word10
2384#define wqe_pri_SHIFT 16 2478#define wqe_pri_SHIFT 16
2385#define wqe_pri_MASK 0x00000007 2479#define wqe_pri_MASK 0x00000007
2386#define wqe_pri_WORD word10 2480#define wqe_pri_WORD word10
@@ -2599,7 +2693,8 @@ struct fcp_iwrite64_wqe {
2599 uint32_t total_xfer_len; 2693 uint32_t total_xfer_len;
2600 uint32_t initial_xfer_len; 2694 uint32_t initial_xfer_len;
2601 struct wqe_common wqe_com; /* words 6-11 */ 2695 struct wqe_common wqe_com; /* words 6-11 */
2602 uint32_t rsvd_12_15[4]; /* word 12-15 */ 2696 uint32_t rsrvd12;
2697 struct ulp_bde64 ph_bde; /* words 13-15 */
2603}; 2698};
2604 2699
2605struct fcp_iread64_wqe { 2700struct fcp_iread64_wqe {
@@ -2608,7 +2703,8 @@ struct fcp_iread64_wqe {
2608 uint32_t total_xfer_len; /* word 4 */ 2703 uint32_t total_xfer_len; /* word 4 */
2609 uint32_t rsrvd5; /* word 5 */ 2704 uint32_t rsrvd5; /* word 5 */
2610 struct wqe_common wqe_com; /* words 6-11 */ 2705 struct wqe_common wqe_com; /* words 6-11 */
2611 uint32_t rsvd_12_15[4]; /* word 12-15 */ 2706 uint32_t rsrvd12;
2707 struct ulp_bde64 ph_bde; /* words 13-15 */
2612}; 2708};
2613 2709
2614struct fcp_icmnd64_wqe { 2710struct fcp_icmnd64_wqe {
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 6d0b36aa3389..35665cfb5689 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -460,7 +460,7 @@ lpfc_config_port_post(struct lpfc_hba *phba)
460 || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) 460 || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G)
461 && !(phba->lmt & LMT_16Gb))) { 461 && !(phba->lmt & LMT_16Gb))) {
462 /* Reset link speed to auto */ 462 /* Reset link speed to auto */
463 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT, 463 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
464 "1302 Invalid speed for this board: " 464 "1302 Invalid speed for this board: "
465 "Reset link speed to auto: x%x\n", 465 "Reset link speed to auto: x%x\n",
466 phba->cfg_link_speed); 466 phba->cfg_link_speed);
@@ -945,17 +945,13 @@ static void
945lpfc_rrq_timeout(unsigned long ptr) 945lpfc_rrq_timeout(unsigned long ptr)
946{ 946{
947 struct lpfc_hba *phba; 947 struct lpfc_hba *phba;
948 uint32_t tmo_posted;
949 unsigned long iflag; 948 unsigned long iflag;
950 949
951 phba = (struct lpfc_hba *)ptr; 950 phba = (struct lpfc_hba *)ptr;
952 spin_lock_irqsave(&phba->pport->work_port_lock, iflag); 951 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
953 tmo_posted = phba->hba_flag & HBA_RRQ_ACTIVE; 952 phba->hba_flag |= HBA_RRQ_ACTIVE;
954 if (!tmo_posted)
955 phba->hba_flag |= HBA_RRQ_ACTIVE;
956 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); 953 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
957 if (!tmo_posted) 954 lpfc_worker_wake_up(phba);
958 lpfc_worker_wake_up(phba);
959} 955}
960 956
961/** 957/**
@@ -2280,6 +2276,7 @@ lpfc_cleanup(struct lpfc_vport *vport)
2280 /* Wait for any activity on ndlps to settle */ 2276 /* Wait for any activity on ndlps to settle */
2281 msleep(10); 2277 msleep(10);
2282 } 2278 }
2279 lpfc_cleanup_vports_rrqs(vport, NULL);
2283} 2280}
2284 2281
2285/** 2282/**
@@ -2295,6 +2292,7 @@ lpfc_stop_vport_timers(struct lpfc_vport *vport)
2295{ 2292{
2296 del_timer_sync(&vport->els_tmofunc); 2293 del_timer_sync(&vport->els_tmofunc);
2297 del_timer_sync(&vport->fc_fdmitmo); 2294 del_timer_sync(&vport->fc_fdmitmo);
2295 del_timer_sync(&vport->delayed_disc_tmo);
2298 lpfc_can_disctmo(vport); 2296 lpfc_can_disctmo(vport);
2299 return; 2297 return;
2300} 2298}
@@ -2355,6 +2353,10 @@ lpfc_stop_hba_timers(struct lpfc_hba *phba)
2355 del_timer_sync(&phba->fabric_block_timer); 2353 del_timer_sync(&phba->fabric_block_timer);
2356 del_timer_sync(&phba->eratt_poll); 2354 del_timer_sync(&phba->eratt_poll);
2357 del_timer_sync(&phba->hb_tmofunc); 2355 del_timer_sync(&phba->hb_tmofunc);
2356 if (phba->sli_rev == LPFC_SLI_REV4) {
2357 del_timer_sync(&phba->rrq_tmr);
2358 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2359 }
2358 phba->hb_outstanding = 0; 2360 phba->hb_outstanding = 0;
2359 2361
2360 switch (phba->pci_dev_grp) { 2362 switch (phba->pci_dev_grp) {
@@ -2732,6 +2734,11 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
2732 init_timer(&vport->els_tmofunc); 2734 init_timer(&vport->els_tmofunc);
2733 vport->els_tmofunc.function = lpfc_els_timeout; 2735 vport->els_tmofunc.function = lpfc_els_timeout;
2734 vport->els_tmofunc.data = (unsigned long)vport; 2736 vport->els_tmofunc.data = (unsigned long)vport;
2737
2738 init_timer(&vport->delayed_disc_tmo);
2739 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
2740 vport->delayed_disc_tmo.data = (unsigned long)vport;
2741
2735 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); 2742 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
2736 if (error) 2743 if (error)
2737 goto out_put_shost; 2744 goto out_put_shost;
@@ -4283,36 +4290,37 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4283 goto out_free_bsmbx; 4290 goto out_free_bsmbx;
4284 } 4291 }
4285 4292
4286 /* Get the Supported Pages. It is always available. */ 4293 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
4287 lpfc_supported_pages(mboxq); 4294 lpfc_supported_pages(mboxq);
4288 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); 4295 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4289 if (unlikely(rc)) { 4296 if (!rc) {
4290 rc = -EIO; 4297 mqe = &mboxq->u.mqe;
4291 mempool_free(mboxq, phba->mbox_mem_pool); 4298 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
4292 goto out_free_bsmbx; 4299 LPFC_MAX_SUPPORTED_PAGES);
4293 } 4300 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
4294 4301 switch (pn_page[i]) {
4295 mqe = &mboxq->u.mqe; 4302 case LPFC_SLI4_PARAMETERS:
4296 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), 4303 phba->sli4_hba.pc_sli4_params.supported = 1;
4297 LPFC_MAX_SUPPORTED_PAGES); 4304 break;
4298 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { 4305 default:
4299 switch (pn_page[i]) { 4306 break;
4300 case LPFC_SLI4_PARAMETERS: 4307 }
4301 phba->sli4_hba.pc_sli4_params.supported = 1; 4308 }
4302 break; 4309 /* Read the port's SLI4 Parameters capabilities if supported. */
4303 default: 4310 if (phba->sli4_hba.pc_sli4_params.supported)
4304 break; 4311 rc = lpfc_pc_sli4_params_get(phba, mboxq);
4312 if (rc) {
4313 mempool_free(mboxq, phba->mbox_mem_pool);
4314 rc = -EIO;
4315 goto out_free_bsmbx;
4305 } 4316 }
4306 } 4317 }
4307 4318 /*
4308 /* Read the port's SLI4 Parameters capabilities if supported. */ 4319 * Get sli4 parameters that override parameters from Port capabilities.
4309 if (phba->sli4_hba.pc_sli4_params.supported) 4320 * If this call fails it is not a critical error so continue loading.
4310 rc = lpfc_pc_sli4_params_get(phba, mboxq); 4321 */
4322 lpfc_get_sli4_parameters(phba, mboxq);
4311 mempool_free(mboxq, phba->mbox_mem_pool); 4323 mempool_free(mboxq, phba->mbox_mem_pool);
4312 if (rc) {
4313 rc = -EIO;
4314 goto out_free_bsmbx;
4315 }
4316 /* Create all the SLI4 queues */ 4324 /* Create all the SLI4 queues */
4317 rc = lpfc_sli4_queue_create(phba); 4325 rc = lpfc_sli4_queue_create(phba);
4318 if (rc) 4326 if (rc)
@@ -7810,7 +7818,7 @@ lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7810 mqe = &mboxq->u.mqe; 7818 mqe = &mboxq->u.mqe;
7811 7819
7812 /* Read the port's SLI4 Parameters port capabilities */ 7820 /* Read the port's SLI4 Parameters port capabilities */
7813 lpfc_sli4_params(mboxq); 7821 lpfc_pc_sli4_params(mboxq);
7814 if (!phba->sli4_hba.intr_enable) 7822 if (!phba->sli4_hba.intr_enable)
7815 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); 7823 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7816 else { 7824 else {
@@ -7854,6 +7862,66 @@ lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7854} 7862}
7855 7863
7856/** 7864/**
7865 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
7866 * @phba: Pointer to HBA context object.
7867 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
7868 *
7869 * This function is called in the SLI4 code path to read the port's
7870 * sli4 capabilities.
7871 *
7872 * This function may be be called from any context that can block-wait
7873 * for the completion. The expectation is that this routine is called
7874 * typically from probe_one or from the online routine.
7875 **/
7876int
7877lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7878{
7879 int rc;
7880 struct lpfc_mqe *mqe = &mboxq->u.mqe;
7881 struct lpfc_pc_sli4_params *sli4_params;
7882 int length;
7883 struct lpfc_sli4_parameters *mbx_sli4_parameters;
7884
7885 /* Read the port's SLI4 Config Parameters */
7886 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
7887 sizeof(struct lpfc_sli4_cfg_mhdr));
7888 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
7889 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
7890 length, LPFC_SLI4_MBX_EMBED);
7891 if (!phba->sli4_hba.intr_enable)
7892 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7893 else
7894 rc = lpfc_sli_issue_mbox_wait(phba, mboxq,
7895 lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG));
7896 if (unlikely(rc))
7897 return rc;
7898 sli4_params = &phba->sli4_hba.pc_sli4_params;
7899 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
7900 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
7901 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
7902 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
7903 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
7904 mbx_sli4_parameters);
7905 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
7906 mbx_sli4_parameters);
7907 if (bf_get(cfg_phwq, mbx_sli4_parameters))
7908 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
7909 else
7910 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
7911 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
7912 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
7913 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
7914 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
7915 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
7916 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
7917 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
7918 mbx_sli4_parameters);
7919 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
7920 mbx_sli4_parameters);
7921 return 0;
7922}
7923
7924/**
7857 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. 7925 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
7858 * @pdev: pointer to PCI device 7926 * @pdev: pointer to PCI device
7859 * @pid: pointer to PCI device identifier 7927 * @pid: pointer to PCI device identifier
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index 23403c650207..dba32dfdb59b 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -1263,7 +1263,8 @@ lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1263 if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) { 1263 if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1264 if (phba->cfg_enable_bg) 1264 if (phba->cfg_enable_bg)
1265 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ 1265 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
1266 mb->un.varCfgPort.cdss = 1; /* Configure Security */ 1266 if (phba->cfg_enable_dss)
1267 mb->un.varCfgPort.cdss = 1; /* Configure Security */
1267 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ 1268 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
1268 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ 1269 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1269 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); 1270 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
@@ -1692,7 +1693,7 @@ lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1692 * @mbox: pointer to lpfc mbox command. 1693 * @mbox: pointer to lpfc mbox command.
1693 * @subsystem: The sli4 config sub mailbox subsystem. 1694 * @subsystem: The sli4 config sub mailbox subsystem.
1694 * @opcode: The sli4 config sub mailbox command opcode. 1695 * @opcode: The sli4 config sub mailbox command opcode.
1695 * @length: Length of the sli4 config mailbox command. 1696 * @length: Length of the sli4 config mailbox command (including sub-header).
1696 * 1697 *
1697 * This routine sets up the header fields of SLI4 specific mailbox command 1698 * This routine sets up the header fields of SLI4 specific mailbox command
1698 * for sending IOCTL command. 1699 * for sending IOCTL command.
@@ -1723,14 +1724,14 @@ lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1723 if (emb) { 1724 if (emb) {
1724 /* Set up main header fields */ 1725 /* Set up main header fields */
1725 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1); 1726 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1726 sli4_config->header.cfg_mhdr.payload_length = 1727 sli4_config->header.cfg_mhdr.payload_length = length;
1727 LPFC_MBX_CMD_HDR_LENGTH + length;
1728 /* Set up sub-header fields following main header */ 1728 /* Set up sub-header fields following main header */
1729 bf_set(lpfc_mbox_hdr_opcode, 1729 bf_set(lpfc_mbox_hdr_opcode,
1730 &sli4_config->header.cfg_shdr.request, opcode); 1730 &sli4_config->header.cfg_shdr.request, opcode);
1731 bf_set(lpfc_mbox_hdr_subsystem, 1731 bf_set(lpfc_mbox_hdr_subsystem,
1732 &sli4_config->header.cfg_shdr.request, subsystem); 1732 &sli4_config->header.cfg_shdr.request, subsystem);
1733 sli4_config->header.cfg_shdr.request.request_length = length; 1733 sli4_config->header.cfg_shdr.request.request_length =
1734 length - LPFC_MBX_CMD_HDR_LENGTH;
1734 return length; 1735 return length;
1735 } 1736 }
1736 1737
@@ -1902,6 +1903,7 @@ lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
1902 1903
1903 /* Set up host requested features. */ 1904 /* Set up host requested features. */
1904 bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1); 1905 bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
1906 bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1);
1905 1907
1906 /* Enable DIF (block guard) only if configured to do so. */ 1908 /* Enable DIF (block guard) only if configured to do so. */
1907 if (phba->cfg_enable_bg) 1909 if (phba->cfg_enable_bg)
@@ -2159,17 +2161,16 @@ lpfc_supported_pages(struct lpfcMboxq *mbox)
2159} 2161}
2160 2162
2161/** 2163/**
2162 * lpfc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params 2164 * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd.
2163 * mailbox command.
2164 * @mbox: pointer to lpfc mbox command to initialize. 2165 * @mbox: pointer to lpfc mbox command to initialize.
2165 * 2166 *
2166 * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to 2167 * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
2167 * retrieve the particular SLI4 features supported by the port. 2168 * retrieve the particular SLI4 features supported by the port.
2168 **/ 2169 **/
2169void 2170void
2170lpfc_sli4_params(struct lpfcMboxq *mbox) 2171lpfc_pc_sli4_params(struct lpfcMboxq *mbox)
2171{ 2172{
2172 struct lpfc_mbx_sli4_params *sli4_params; 2173 struct lpfc_mbx_pc_sli4_params *sli4_params;
2173 2174
2174 memset(mbox, 0, sizeof(*mbox)); 2175 memset(mbox, 0, sizeof(*mbox));
2175 sli4_params = &mbox->u.mqe.un.sli4_params; 2176 sli4_params = &mbox->u.mqe.un.sli4_params;
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index d85a7423a694..52b35159fc35 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -350,7 +350,11 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
350 ndlp->nlp_maxframe = 350 ndlp->nlp_maxframe =
351 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb; 351 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
352 352
353 /* no need to reg_login if we are already in one of these states */ 353 /*
354 * Need to unreg_login if we are already in one of these states and
355 * change to NPR state. This will block the port until after the ACC
356 * completes and the reg_login is issued and completed.
357 */
354 switch (ndlp->nlp_state) { 358 switch (ndlp->nlp_state) {
355 case NLP_STE_NPR_NODE: 359 case NLP_STE_NPR_NODE:
356 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) 360 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
@@ -359,8 +363,9 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
359 case NLP_STE_PRLI_ISSUE: 363 case NLP_STE_PRLI_ISSUE:
360 case NLP_STE_UNMAPPED_NODE: 364 case NLP_STE_UNMAPPED_NODE:
361 case NLP_STE_MAPPED_NODE: 365 case NLP_STE_MAPPED_NODE:
362 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); 366 lpfc_unreg_rpi(vport, ndlp);
363 return 1; 367 ndlp->nlp_prev_state = ndlp->nlp_state;
368 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
364 } 369 }
365 370
366 if ((vport->fc_flag & FC_PT2PT) && 371 if ((vport->fc_flag & FC_PT2PT) &&
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index c97751c95d77..bf34178b80bf 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -609,6 +609,32 @@ lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
609} 609}
610 610
611/** 611/**
612 * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
613 * @vport: pointer to lpfc vport data structure.
614 *
615 * This routine is invoked by the vport cleanup for deletions and the cleanup
616 * for an ndlp on removal.
617 **/
618void
619lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
620{
621 struct lpfc_hba *phba = vport->phba;
622 struct lpfc_scsi_buf *psb, *next_psb;
623 unsigned long iflag = 0;
624
625 spin_lock_irqsave(&phba->hbalock, iflag);
626 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
627 list_for_each_entry_safe(psb, next_psb,
628 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
629 if (psb->rdata && psb->rdata->pnode
630 && psb->rdata->pnode->vport == vport)
631 psb->rdata = NULL;
632 }
633 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
634 spin_unlock_irqrestore(&phba->hbalock, iflag);
635}
636
637/**
612 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort 638 * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
613 * @phba: pointer to lpfc hba data structure. 639 * @phba: pointer to lpfc hba data structure.
614 * @axri: pointer to the fcp xri abort wcqe structure. 640 * @axri: pointer to the fcp xri abort wcqe structure.
@@ -640,7 +666,11 @@ lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
640 psb->status = IOSTAT_SUCCESS; 666 psb->status = IOSTAT_SUCCESS;
641 spin_unlock( 667 spin_unlock(
642 &phba->sli4_hba.abts_scsi_buf_list_lock); 668 &phba->sli4_hba.abts_scsi_buf_list_lock);
643 ndlp = psb->rdata->pnode; 669 if (psb->rdata && psb->rdata->pnode)
670 ndlp = psb->rdata->pnode;
671 else
672 ndlp = NULL;
673
644 rrq_empty = list_empty(&phba->active_rrq_list); 674 rrq_empty = list_empty(&phba->active_rrq_list);
645 spin_unlock_irqrestore(&phba->hbalock, iflag); 675 spin_unlock_irqrestore(&phba->hbalock, iflag);
646 if (ndlp) 676 if (ndlp)
@@ -964,36 +994,29 @@ lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
964static struct lpfc_scsi_buf* 994static struct lpfc_scsi_buf*
965lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) 995lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
966{ 996{
967 struct lpfc_scsi_buf *lpfc_cmd = NULL; 997 struct lpfc_scsi_buf *lpfc_cmd ;
968 struct lpfc_scsi_buf *start_lpfc_cmd = NULL;
969 struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
970 unsigned long iflag = 0; 998 unsigned long iflag = 0;
971 int found = 0; 999 int found = 0;
972 1000
973 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); 1001 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
974 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list); 1002 list_for_each_entry(lpfc_cmd, &phba->lpfc_scsi_buf_list,
975 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); 1003 list) {
976 while (!found && lpfc_cmd) {
977 if (lpfc_test_rrq_active(phba, ndlp, 1004 if (lpfc_test_rrq_active(phba, ndlp,
978 lpfc_cmd->cur_iocbq.sli4_xritag)) { 1005 lpfc_cmd->cur_iocbq.sli4_xritag))
979 lpfc_release_scsi_buf_s4(phba, lpfc_cmd); 1006 continue;
980 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); 1007 list_del(&lpfc_cmd->list);
981 list_remove_head(scsi_buf_list, lpfc_cmd,
982 struct lpfc_scsi_buf, list);
983 spin_unlock_irqrestore(&phba->scsi_buf_list_lock,
984 iflag);
985 if (lpfc_cmd == start_lpfc_cmd) {
986 lpfc_cmd = NULL;
987 break;
988 } else
989 continue;
990 }
991 found = 1; 1008 found = 1;
992 lpfc_cmd->seg_cnt = 0; 1009 lpfc_cmd->seg_cnt = 0;
993 lpfc_cmd->nonsg_phys = 0; 1010 lpfc_cmd->nonsg_phys = 0;
994 lpfc_cmd->prot_seg_cnt = 0; 1011 lpfc_cmd->prot_seg_cnt = 0;
1012 break;
995 } 1013 }
996 return lpfc_cmd; 1014 spin_unlock_irqrestore(&phba->scsi_buf_list_lock,
1015 iflag);
1016 if (!found)
1017 return NULL;
1018 else
1019 return lpfc_cmd;
997} 1020}
998/** 1021/**
999 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA 1022 * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
@@ -1981,12 +2004,14 @@ lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
1981 struct scatterlist *sgel = NULL; 2004 struct scatterlist *sgel = NULL;
1982 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd; 2005 struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
1983 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; 2006 struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
2007 struct sli4_sge *first_data_sgl;
1984 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; 2008 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
1985 dma_addr_t physaddr; 2009 dma_addr_t physaddr;
1986 uint32_t num_bde = 0; 2010 uint32_t num_bde = 0;
1987 uint32_t dma_len; 2011 uint32_t dma_len;
1988 uint32_t dma_offset = 0; 2012 uint32_t dma_offset = 0;
1989 int nseg; 2013 int nseg;
2014 struct ulp_bde64 *bde;
1990 2015
1991 /* 2016 /*
1992 * There are three possibilities here - use scatter-gather segment, use 2017 * There are three possibilities here - use scatter-gather segment, use
@@ -2011,7 +2036,7 @@ lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
2011 bf_set(lpfc_sli4_sge_last, sgl, 0); 2036 bf_set(lpfc_sli4_sge_last, sgl, 0);
2012 sgl->word2 = cpu_to_le32(sgl->word2); 2037 sgl->word2 = cpu_to_le32(sgl->word2);
2013 sgl += 1; 2038 sgl += 1;
2014 2039 first_data_sgl = sgl;
2015 lpfc_cmd->seg_cnt = nseg; 2040 lpfc_cmd->seg_cnt = nseg;
2016 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) { 2041 if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
2017 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:" 2042 lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:"
@@ -2047,6 +2072,17 @@ lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
2047 dma_offset += dma_len; 2072 dma_offset += dma_len;
2048 sgl++; 2073 sgl++;
2049 } 2074 }
2075 /* setup the performance hint (first data BDE) if enabled */
2076 if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) {
2077 bde = (struct ulp_bde64 *)
2078 &(iocb_cmd->unsli3.sli3Words[5]);
2079 bde->addrLow = first_data_sgl->addr_lo;
2080 bde->addrHigh = first_data_sgl->addr_hi;
2081 bde->tus.f.bdeSize =
2082 le32_to_cpu(first_data_sgl->sge_len);
2083 bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2084 bde->tus.w = cpu_to_le32(bde->tus.w);
2085 }
2050 } else { 2086 } else {
2051 sgl += 1; 2087 sgl += 1;
2052 /* clear the last flag in the fcp_rsp map entry */ 2088 /* clear the last flag in the fcp_rsp map entry */
@@ -2471,6 +2507,16 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
2471 lpfc_worker_wake_up(phba); 2507 lpfc_worker_wake_up(phba);
2472 break; 2508 break;
2473 case IOSTAT_LOCAL_REJECT: 2509 case IOSTAT_LOCAL_REJECT:
2510 case IOSTAT_REMOTE_STOP:
2511 if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
2512 lpfc_cmd->result ==
2513 IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
2514 lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
2515 lpfc_cmd->result ==
2516 IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
2517 cmd->result = ScsiResult(DID_NO_CONNECT, 0);
2518 break;
2519 }
2474 if (lpfc_cmd->result == IOERR_INVALID_RPI || 2520 if (lpfc_cmd->result == IOERR_INVALID_RPI ||
2475 lpfc_cmd->result == IOERR_NO_RESOURCES || 2521 lpfc_cmd->result == IOERR_NO_RESOURCES ||
2476 lpfc_cmd->result == IOERR_ABORT_REQUESTED || 2522 lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
@@ -2478,7 +2524,6 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
2478 cmd->result = ScsiResult(DID_REQUEUE, 0); 2524 cmd->result = ScsiResult(DID_REQUEUE, 0);
2479 break; 2525 break;
2480 } 2526 }
2481
2482 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED || 2527 if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
2483 lpfc_cmd->result == IOERR_TX_DMA_FAILED) && 2528 lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
2484 pIocbOut->iocb.unsli3.sli3_bg.bgstat) { 2529 pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
@@ -2497,7 +2542,17 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
2497 "on unprotected cmd\n"); 2542 "on unprotected cmd\n");
2498 } 2543 }
2499 } 2544 }
2500 2545 if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
2546 && (phba->sli_rev == LPFC_SLI_REV4)
2547 && (pnode && NLP_CHK_NODE_ACT(pnode))) {
2548 /* This IO was aborted by the target, we don't
2549 * know the rxid and because we did not send the
2550 * ABTS we cannot generate and RRQ.
2551 */
2552 lpfc_set_rrq_active(phba, pnode,
2553 lpfc_cmd->cur_iocbq.sli4_xritag,
2554 0, 0);
2555 }
2501 /* else: fall through */ 2556 /* else: fall through */
2502 default: 2557 default:
2503 cmd->result = ScsiResult(DID_ERROR, 0); 2558 cmd->result = ScsiResult(DID_ERROR, 0);
@@ -2508,9 +2563,8 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
2508 || (pnode->nlp_state != NLP_STE_MAPPED_NODE)) 2563 || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
2509 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 2564 cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
2510 SAM_STAT_BUSY); 2565 SAM_STAT_BUSY);
2511 } else { 2566 } else
2512 cmd->result = ScsiResult(DID_OK, 0); 2567 cmd->result = ScsiResult(DID_OK, 0);
2513 }
2514 2568
2515 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) { 2569 if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
2516 uint32_t *lp = (uint32_t *)cmd->sense_buffer; 2570 uint32_t *lp = (uint32_t *)cmd->sense_buffer;
@@ -3004,11 +3058,11 @@ lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
3004 * transport is still transitioning. 3058 * transport is still transitioning.
3005 */ 3059 */
3006 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { 3060 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
3007 cmnd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0); 3061 cmnd->result = ScsiResult(DID_IMM_RETRY, 0);
3008 goto out_fail_command; 3062 goto out_fail_command;
3009 } 3063 }
3010 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth) 3064 if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth)
3011 goto out_host_busy; 3065 goto out_tgt_busy;
3012 3066
3013 lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp); 3067 lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp);
3014 if (lpfc_cmd == NULL) { 3068 if (lpfc_cmd == NULL) {
@@ -3125,6 +3179,9 @@ lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
3125 out_host_busy: 3179 out_host_busy:
3126 return SCSI_MLQUEUE_HOST_BUSY; 3180 return SCSI_MLQUEUE_HOST_BUSY;
3127 3181
3182 out_tgt_busy:
3183 return SCSI_MLQUEUE_TARGET_BUSY;
3184
3128 out_fail_command: 3185 out_fail_command:
3129 done(cmnd); 3186 done(cmnd);
3130 return 0; 3187 return 0;
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index a359d2b873ce..2ee0374a9908 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -96,7 +96,8 @@ lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
96 /* set consumption flag every once in a while */ 96 /* set consumption flag every once in a while */
97 if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL)) 97 if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL))
98 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); 98 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
99 99 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
100 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
100 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); 101 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
101 102
102 /* Update the host index before invoking device */ 103 /* Update the host index before invoking device */
@@ -534,15 +535,35 @@ __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
534 uint16_t adj_xri; 535 uint16_t adj_xri;
535 struct lpfc_node_rrq *rrq; 536 struct lpfc_node_rrq *rrq;
536 int empty; 537 int empty;
538 uint32_t did = 0;
539
540
541 if (!ndlp)
542 return -EINVAL;
543
544 if (!phba->cfg_enable_rrq)
545 return -EINVAL;
546
547 if (phba->pport->load_flag & FC_UNLOADING) {
548 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
549 goto out;
550 }
551 did = ndlp->nlp_DID;
537 552
538 /* 553 /*
539 * set the active bit even if there is no mem available. 554 * set the active bit even if there is no mem available.
540 */ 555 */
541 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; 556 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
542 if (!ndlp) 557
543 return -EINVAL; 558 if (NLP_CHK_FREE_REQ(ndlp))
559 goto out;
560
561 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
562 goto out;
563
544 if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) 564 if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap))
545 return -EINVAL; 565 goto out;
566
546 rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); 567 rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
547 if (rrq) { 568 if (rrq) {
548 rrq->send_rrq = send_rrq; 569 rrq->send_rrq = send_rrq;
@@ -553,14 +574,7 @@ __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
553 rrq->vport = ndlp->vport; 574 rrq->vport = ndlp->vport;
554 rrq->rxid = rxid; 575 rrq->rxid = rxid;
555 empty = list_empty(&phba->active_rrq_list); 576 empty = list_empty(&phba->active_rrq_list);
556 if (phba->cfg_enable_rrq && send_rrq) 577 rrq->send_rrq = send_rrq;
557 /*
558 * We need the xri before we can add this to the
559 * phba active rrq list.
560 */
561 rrq->send_rrq = send_rrq;
562 else
563 rrq->send_rrq = 0;
564 list_add_tail(&rrq->list, &phba->active_rrq_list); 578 list_add_tail(&rrq->list, &phba->active_rrq_list);
565 if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) { 579 if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
566 phba->hba_flag |= HBA_RRQ_ACTIVE; 580 phba->hba_flag |= HBA_RRQ_ACTIVE;
@@ -569,40 +583,49 @@ __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
569 } 583 }
570 return 0; 584 return 0;
571 } 585 }
572 return -ENOMEM; 586out:
587 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
588 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
589 " DID:0x%x Send:%d\n",
590 xritag, rxid, did, send_rrq);
591 return -EINVAL;
573} 592}
574 593
575/** 594/**
576 * __lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. 595 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
577 * @phba: Pointer to HBA context object. 596 * @phba: Pointer to HBA context object.
578 * @xritag: xri used in this exchange. 597 * @xritag: xri used in this exchange.
579 * @rrq: The RRQ to be cleared. 598 * @rrq: The RRQ to be cleared.
580 * 599 *
581 * This function is called with hbalock held. This function
582 **/ 600 **/
583static void 601void
584__lpfc_clr_rrq_active(struct lpfc_hba *phba, 602lpfc_clr_rrq_active(struct lpfc_hba *phba,
585 uint16_t xritag, 603 uint16_t xritag,
586 struct lpfc_node_rrq *rrq) 604 struct lpfc_node_rrq *rrq)
587{ 605{
588 uint16_t adj_xri; 606 uint16_t adj_xri;
589 struct lpfc_nodelist *ndlp; 607 struct lpfc_nodelist *ndlp = NULL;
590 608
591 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); 609 if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
610 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
592 611
593 /* The target DID could have been swapped (cable swap) 612 /* The target DID could have been swapped (cable swap)
594 * we should use the ndlp from the findnode if it is 613 * we should use the ndlp from the findnode if it is
595 * available. 614 * available.
596 */ 615 */
597 if (!ndlp) 616 if ((!ndlp) && rrq->ndlp)
598 ndlp = rrq->ndlp; 617 ndlp = rrq->ndlp;
599 618
619 if (!ndlp)
620 goto out;
621
600 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; 622 adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base;
601 if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) { 623 if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) {
602 rrq->send_rrq = 0; 624 rrq->send_rrq = 0;
603 rrq->xritag = 0; 625 rrq->xritag = 0;
604 rrq->rrq_stop_time = 0; 626 rrq->rrq_stop_time = 0;
605 } 627 }
628out:
606 mempool_free(rrq, phba->rrq_pool); 629 mempool_free(rrq, phba->rrq_pool);
607} 630}
608 631
@@ -627,34 +650,34 @@ lpfc_handle_rrq_active(struct lpfc_hba *phba)
627 struct lpfc_node_rrq *nextrrq; 650 struct lpfc_node_rrq *nextrrq;
628 unsigned long next_time; 651 unsigned long next_time;
629 unsigned long iflags; 652 unsigned long iflags;
653 LIST_HEAD(send_rrq);
630 654
631 spin_lock_irqsave(&phba->hbalock, iflags); 655 spin_lock_irqsave(&phba->hbalock, iflags);
632 phba->hba_flag &= ~HBA_RRQ_ACTIVE; 656 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
633 next_time = jiffies + HZ * (phba->fc_ratov + 1); 657 next_time = jiffies + HZ * (phba->fc_ratov + 1);
634 list_for_each_entry_safe(rrq, nextrrq, 658 list_for_each_entry_safe(rrq, nextrrq,
635 &phba->active_rrq_list, list) { 659 &phba->active_rrq_list, list) {
636 if (time_after(jiffies, rrq->rrq_stop_time)) { 660 if (time_after(jiffies, rrq->rrq_stop_time))
637 list_del(&rrq->list); 661 list_move(&rrq->list, &send_rrq);
638 if (!rrq->send_rrq) 662 else if (time_before(rrq->rrq_stop_time, next_time))
639 /* this call will free the rrq */
640 __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
641 else {
642 /* if we send the rrq then the completion handler
643 * will clear the bit in the xribitmap.
644 */
645 spin_unlock_irqrestore(&phba->hbalock, iflags);
646 if (lpfc_send_rrq(phba, rrq)) {
647 lpfc_clr_rrq_active(phba, rrq->xritag,
648 rrq);
649 }
650 spin_lock_irqsave(&phba->hbalock, iflags);
651 }
652 } else if (time_before(rrq->rrq_stop_time, next_time))
653 next_time = rrq->rrq_stop_time; 663 next_time = rrq->rrq_stop_time;
654 } 664 }
655 spin_unlock_irqrestore(&phba->hbalock, iflags); 665 spin_unlock_irqrestore(&phba->hbalock, iflags);
656 if (!list_empty(&phba->active_rrq_list)) 666 if (!list_empty(&phba->active_rrq_list))
657 mod_timer(&phba->rrq_tmr, next_time); 667 mod_timer(&phba->rrq_tmr, next_time);
668 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
669 list_del(&rrq->list);
670 if (!rrq->send_rrq)
671 /* this call will free the rrq */
672 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
673 else if (lpfc_send_rrq(phba, rrq)) {
674 /* if we send the rrq then the completion handler
675 * will clear the bit in the xribitmap.
676 */
677 lpfc_clr_rrq_active(phba, rrq->xritag,
678 rrq);
679 }
680 }
658} 681}
659 682
660/** 683/**
@@ -692,29 +715,37 @@ lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
692/** 715/**
693 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. 716 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
694 * @vport: Pointer to vport context object. 717 * @vport: Pointer to vport context object.
695 * 718 * @ndlp: Pointer to the lpfc_node_list structure.
696 * Remove all active RRQs for this vport from the phba->active_rrq_list and 719 * If ndlp is NULL Remove all active RRQs for this vport from the
697 * clear the rrq. 720 * phba->active_rrq_list and clear the rrq.
721 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
698 **/ 722 **/
699void 723void
700lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport) 724lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
701 725
702{ 726{
703 struct lpfc_hba *phba = vport->phba; 727 struct lpfc_hba *phba = vport->phba;
704 struct lpfc_node_rrq *rrq; 728 struct lpfc_node_rrq *rrq;
705 struct lpfc_node_rrq *nextrrq; 729 struct lpfc_node_rrq *nextrrq;
706 unsigned long iflags; 730 unsigned long iflags;
731 LIST_HEAD(rrq_list);
707 732
708 if (phba->sli_rev != LPFC_SLI_REV4) 733 if (phba->sli_rev != LPFC_SLI_REV4)
709 return; 734 return;
710 spin_lock_irqsave(&phba->hbalock, iflags); 735 if (!ndlp) {
711 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { 736 lpfc_sli4_vport_delete_els_xri_aborted(vport);
712 if (rrq->vport == vport) { 737 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
713 list_del(&rrq->list);
714 __lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
715 }
716 } 738 }
739 spin_lock_irqsave(&phba->hbalock, iflags);
740 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
741 if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
742 list_move(&rrq->list, &rrq_list);
717 spin_unlock_irqrestore(&phba->hbalock, iflags); 743 spin_unlock_irqrestore(&phba->hbalock, iflags);
744
745 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
746 list_del(&rrq->list);
747 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
748 }
718} 749}
719 750
720/** 751/**
@@ -732,24 +763,27 @@ lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
732 struct lpfc_node_rrq *nextrrq; 763 struct lpfc_node_rrq *nextrrq;
733 unsigned long next_time; 764 unsigned long next_time;
734 unsigned long iflags; 765 unsigned long iflags;
766 LIST_HEAD(rrq_list);
735 767
736 if (phba->sli_rev != LPFC_SLI_REV4) 768 if (phba->sli_rev != LPFC_SLI_REV4)
737 return; 769 return;
738 spin_lock_irqsave(&phba->hbalock, iflags); 770 spin_lock_irqsave(&phba->hbalock, iflags);
739 phba->hba_flag &= ~HBA_RRQ_ACTIVE; 771 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
740 next_time = jiffies + HZ * (phba->fc_ratov * 2); 772 next_time = jiffies + HZ * (phba->fc_ratov * 2);
741 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { 773 list_splice_init(&phba->active_rrq_list, &rrq_list);
774 spin_unlock_irqrestore(&phba->hbalock, iflags);
775
776 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
742 list_del(&rrq->list); 777 list_del(&rrq->list);
743 __lpfc_clr_rrq_active(phba, rrq->xritag, rrq); 778 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
744 } 779 }
745 spin_unlock_irqrestore(&phba->hbalock, iflags);
746 if (!list_empty(&phba->active_rrq_list)) 780 if (!list_empty(&phba->active_rrq_list))
747 mod_timer(&phba->rrq_tmr, next_time); 781 mod_timer(&phba->rrq_tmr, next_time);
748} 782}
749 783
750 784
751/** 785/**
752 * __lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. 786 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
753 * @phba: Pointer to HBA context object. 787 * @phba: Pointer to HBA context object.
754 * @ndlp: Targets nodelist pointer for this exchange. 788 * @ndlp: Targets nodelist pointer for this exchange.
755 * @xritag the xri in the bitmap to test. 789 * @xritag the xri in the bitmap to test.
@@ -758,8 +792,8 @@ lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
758 * returns 0 = rrq not active for this xri 792 * returns 0 = rrq not active for this xri
759 * 1 = rrq is valid for this xri. 793 * 1 = rrq is valid for this xri.
760 **/ 794 **/
761static int 795int
762__lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, 796lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
763 uint16_t xritag) 797 uint16_t xritag)
764{ 798{
765 uint16_t adj_xri; 799 uint16_t adj_xri;
@@ -802,52 +836,6 @@ lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
802} 836}
803 837
804/** 838/**
805 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
806 * @phba: Pointer to HBA context object.
807 * @xritag: xri used in this exchange.
808 * @rrq: The RRQ to be cleared.
809 *
810 * This function is takes the hbalock.
811 **/
812void
813lpfc_clr_rrq_active(struct lpfc_hba *phba,
814 uint16_t xritag,
815 struct lpfc_node_rrq *rrq)
816{
817 unsigned long iflags;
818
819 spin_lock_irqsave(&phba->hbalock, iflags);
820 __lpfc_clr_rrq_active(phba, xritag, rrq);
821 spin_unlock_irqrestore(&phba->hbalock, iflags);
822 return;
823}
824
825
826
827/**
828 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
829 * @phba: Pointer to HBA context object.
830 * @ndlp: Targets nodelist pointer for this exchange.
831 * @xritag the xri in the bitmap to test.
832 *
833 * This function takes the hbalock.
834 * returns 0 = rrq not active for this xri
835 * 1 = rrq is valid for this xri.
836 **/
837int
838lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
839 uint16_t xritag)
840{
841 int ret;
842 unsigned long iflags;
843
844 spin_lock_irqsave(&phba->hbalock, iflags);
845 ret = __lpfc_test_rrq_active(phba, ndlp, xritag);
846 spin_unlock_irqrestore(&phba->hbalock, iflags);
847 return ret;
848}
849
850/**
851 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool 839 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
852 * @phba: Pointer to HBA context object. 840 * @phba: Pointer to HBA context object.
853 * @piocb: Pointer to the iocbq. 841 * @piocb: Pointer to the iocbq.
@@ -884,7 +872,7 @@ __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
884 return NULL; 872 return NULL;
885 adj_xri = sglq->sli4_xritag - 873 adj_xri = sglq->sli4_xritag -
886 phba->sli4_hba.max_cfg_param.xri_base; 874 phba->sli4_hba.max_cfg_param.xri_base;
887 if (__lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) { 875 if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
888 /* This xri has an rrq outstanding for this DID. 876 /* This xri has an rrq outstanding for this DID.
889 * put it back in the list and get another xri. 877 * put it back in the list and get another xri.
890 */ 878 */
@@ -969,7 +957,8 @@ __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
969 } else { 957 } else {
970 sglq->state = SGL_FREED; 958 sglq->state = SGL_FREED;
971 sglq->ndlp = NULL; 959 sglq->ndlp = NULL;
972 list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list); 960 list_add_tail(&sglq->list,
961 &phba->sli4_hba.lpfc_sgl_list);
973 962
974 /* Check if TXQ queue needs to be serviced */ 963 /* Check if TXQ queue needs to be serviced */
975 if (pring->txq_cnt) 964 if (pring->txq_cnt)
@@ -4817,7 +4806,10 @@ lpfc_sli4_hba_setup(struct lpfc_hba *phba)
4817 "0378 No support for fcpi mode.\n"); 4806 "0378 No support for fcpi mode.\n");
4818 ftr_rsp++; 4807 ftr_rsp++;
4819 } 4808 }
4820 4809 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
4810 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
4811 else
4812 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
4821 /* 4813 /*
4822 * If the port cannot support the host's requested features 4814 * If the port cannot support the host's requested features
4823 * then turn off the global config parameters to disable the 4815 * then turn off the global config parameters to disable the
@@ -5004,7 +4996,8 @@ lpfc_sli4_hba_setup(struct lpfc_hba *phba)
5004 spin_lock_irq(&phba->hbalock); 4996 spin_lock_irq(&phba->hbalock);
5005 phba->link_state = LPFC_LINK_DOWN; 4997 phba->link_state = LPFC_LINK_DOWN;
5006 spin_unlock_irq(&phba->hbalock); 4998 spin_unlock_irq(&phba->hbalock);
5007 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); 4999 if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK)
5000 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
5008out_unset_queue: 5001out_unset_queue:
5009 /* Unset all the queues set up in this routine when error out */ 5002 /* Unset all the queues set up in this routine when error out */
5010 if (rc) 5003 if (rc)
@@ -10478,6 +10471,7 @@ lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
10478 cq->type = type; 10471 cq->type = type;
10479 cq->subtype = subtype; 10472 cq->subtype = subtype;
10480 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); 10473 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
10474 cq->assoc_qid = eq->queue_id;
10481 cq->host_index = 0; 10475 cq->host_index = 0;
10482 cq->hba_index = 0; 10476 cq->hba_index = 0;
10483 10477
@@ -10672,6 +10666,7 @@ lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
10672 goto out; 10666 goto out;
10673 } 10667 }
10674 mq->type = LPFC_MQ; 10668 mq->type = LPFC_MQ;
10669 mq->assoc_qid = cq->queue_id;
10675 mq->subtype = subtype; 10670 mq->subtype = subtype;
10676 mq->host_index = 0; 10671 mq->host_index = 0;
10677 mq->hba_index = 0; 10672 mq->hba_index = 0;
@@ -10759,6 +10754,7 @@ lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
10759 goto out; 10754 goto out;
10760 } 10755 }
10761 wq->type = LPFC_WQ; 10756 wq->type = LPFC_WQ;
10757 wq->assoc_qid = cq->queue_id;
10762 wq->subtype = subtype; 10758 wq->subtype = subtype;
10763 wq->host_index = 0; 10759 wq->host_index = 0;
10764 wq->hba_index = 0; 10760 wq->hba_index = 0;
@@ -10876,6 +10872,7 @@ lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
10876 goto out; 10872 goto out;
10877 } 10873 }
10878 hrq->type = LPFC_HRQ; 10874 hrq->type = LPFC_HRQ;
10875 hrq->assoc_qid = cq->queue_id;
10879 hrq->subtype = subtype; 10876 hrq->subtype = subtype;
10880 hrq->host_index = 0; 10877 hrq->host_index = 0;
10881 hrq->hba_index = 0; 10878 hrq->hba_index = 0;
@@ -10936,6 +10933,7 @@ lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
10936 goto out; 10933 goto out;
10937 } 10934 }
10938 drq->type = LPFC_DRQ; 10935 drq->type = LPFC_DRQ;
10936 drq->assoc_qid = cq->queue_id;
10939 drq->subtype = subtype; 10937 drq->subtype = subtype;
10940 drq->host_index = 0; 10938 drq->host_index = 0;
10941 drq->hba_index = 0; 10939 drq->hba_index = 0;
@@ -11189,7 +11187,7 @@ lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
11189 if (!mbox) 11187 if (!mbox)
11190 return -ENOMEM; 11188 return -ENOMEM;
11191 length = (sizeof(struct lpfc_mbx_rq_destroy) - 11189 length = (sizeof(struct lpfc_mbx_rq_destroy) -
11192 sizeof(struct mbox_header)); 11190 sizeof(struct lpfc_sli4_cfg_mhdr));
11193 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, 11191 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
11194 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, 11192 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
11195 length, LPFC_SLI4_MBX_EMBED); 11193 length, LPFC_SLI4_MBX_EMBED);
@@ -11279,7 +11277,7 @@ lpfc_sli4_post_sgl(struct lpfc_hba *phba,
11279 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, 11277 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
11280 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, 11278 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
11281 sizeof(struct lpfc_mbx_post_sgl_pages) - 11279 sizeof(struct lpfc_mbx_post_sgl_pages) -
11282 sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); 11280 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
11283 11281
11284 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) 11282 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
11285 &mbox->u.mqe.un.post_sgl_pages; 11283 &mbox->u.mqe.un.post_sgl_pages;
@@ -12402,7 +12400,8 @@ lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
12402 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, 12400 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
12403 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, 12401 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
12404 sizeof(struct lpfc_mbx_post_hdr_tmpl) - 12402 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
12405 sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); 12403 sizeof(struct lpfc_sli4_cfg_mhdr),
12404 LPFC_SLI4_MBX_EMBED);
12406 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, 12405 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
12407 hdr_tmpl, rpi_page->page_count); 12406 hdr_tmpl, rpi_page->page_count);
12408 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, 12407 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
diff --git a/drivers/scsi/lpfc/lpfc_sli4.h b/drivers/scsi/lpfc/lpfc_sli4.h
index c7217d579e0f..595056b89608 100644
--- a/drivers/scsi/lpfc/lpfc_sli4.h
+++ b/drivers/scsi/lpfc/lpfc_sli4.h
@@ -125,9 +125,9 @@ struct lpfc_queue {
125 uint32_t entry_count; /* Number of entries to support on the queue */ 125 uint32_t entry_count; /* Number of entries to support on the queue */
126 uint32_t entry_size; /* Size of each queue entry. */ 126 uint32_t entry_size; /* Size of each queue entry. */
127 uint32_t queue_id; /* Queue ID assigned by the hardware */ 127 uint32_t queue_id; /* Queue ID assigned by the hardware */
128 uint32_t assoc_qid; /* Queue ID associated with, for CQ/WQ/MQ */
128 struct list_head page_list; 129 struct list_head page_list;
129 uint32_t page_count; /* Number of pages allocated for this queue */ 130 uint32_t page_count; /* Number of pages allocated for this queue */
130
131 uint32_t host_index; /* The host's index for putting or getting */ 131 uint32_t host_index; /* The host's index for putting or getting */
132 uint32_t hba_index; /* The last known hba index for get or put */ 132 uint32_t hba_index; /* The last known hba index for get or put */
133 union sli4_qe qe[1]; /* array to index entries (must be last) */ 133 union sli4_qe qe[1]; /* array to index entries (must be last) */
@@ -359,6 +359,10 @@ struct lpfc_pc_sli4_params {
359 uint32_t hdr_pp_align; 359 uint32_t hdr_pp_align;
360 uint32_t sgl_pages_max; 360 uint32_t sgl_pages_max;
361 uint32_t sgl_pp_align; 361 uint32_t sgl_pp_align;
362 uint8_t cqv;
363 uint8_t mqv;
364 uint8_t wqv;
365 uint8_t rqv;
362}; 366};
363 367
364/* SLI4 HBA data structure entries */ 368/* SLI4 HBA data structure entries */
@@ -562,6 +566,8 @@ void lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *,
562 struct sli4_wcqe_xri_aborted *); 566 struct sli4_wcqe_xri_aborted *);
563void lpfc_sli4_els_xri_aborted(struct lpfc_hba *, 567void lpfc_sli4_els_xri_aborted(struct lpfc_hba *,
564 struct sli4_wcqe_xri_aborted *); 568 struct sli4_wcqe_xri_aborted *);
569void lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *);
570void lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *);
565int lpfc_sli4_brdreset(struct lpfc_hba *); 571int lpfc_sli4_brdreset(struct lpfc_hba *);
566int lpfc_sli4_add_fcf_record(struct lpfc_hba *, struct fcf_record *); 572int lpfc_sli4_add_fcf_record(struct lpfc_hba *, struct fcf_record *);
567void lpfc_sli_remove_dflt_fcf(struct lpfc_hba *); 573void lpfc_sli_remove_dflt_fcf(struct lpfc_hba *);
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index 386cf92de492..0a4d376dbca5 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2010 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -18,7 +18,7 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_DRIVER_VERSION "8.3.20" 21#define LPFC_DRIVER_VERSION "8.3.21"
22#define LPFC_DRIVER_NAME "lpfc" 22#define LPFC_DRIVER_NAME "lpfc"
23#define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp" 23#define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp"
24#define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp" 24#define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp"
diff --git a/drivers/scsi/lpfc/lpfc_vport.c b/drivers/scsi/lpfc/lpfc_vport.c
index 6b8d2952e32f..30ba5440c67a 100644
--- a/drivers/scsi/lpfc/lpfc_vport.c
+++ b/drivers/scsi/lpfc/lpfc_vport.c
@@ -464,6 +464,7 @@ disable_vport(struct fc_vport *fc_vport)
464 struct lpfc_hba *phba = vport->phba; 464 struct lpfc_hba *phba = vport->phba;
465 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL; 465 struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
466 long timeout; 466 long timeout;
467 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
467 468
468 ndlp = lpfc_findnode_did(vport, Fabric_DID); 469 ndlp = lpfc_findnode_did(vport, Fabric_DID);
469 if (ndlp && NLP_CHK_NODE_ACT(ndlp) 470 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
@@ -498,6 +499,9 @@ disable_vport(struct fc_vport *fc_vport)
498 * scsi_host_put() to release the vport. 499 * scsi_host_put() to release the vport.
499 */ 500 */
500 lpfc_mbx_unreg_vpi(vport); 501 lpfc_mbx_unreg_vpi(vport);
502 spin_lock_irq(shost->host_lock);
503 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
504 spin_unlock_irq(shost->host_lock);
501 505
502 lpfc_vport_set_state(vport, FC_VPORT_DISABLED); 506 lpfc_vport_set_state(vport, FC_VPORT_DISABLED);
503 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, 507 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 1b5e375732c0..635b228c3ead 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -33,9 +33,9 @@
33/* 33/*
34 * MegaRAID SAS Driver meta data 34 * MegaRAID SAS Driver meta data
35 */ 35 */
36#define MEGASAS_VERSION "00.00.05.29-rc1" 36#define MEGASAS_VERSION "00.00.05.34-rc1"
37#define MEGASAS_RELDATE "Dec. 7, 2010" 37#define MEGASAS_RELDATE "Feb. 24, 2011"
38#define MEGASAS_EXT_VERSION "Tue. Dec. 7 17:00:00 PDT 2010" 38#define MEGASAS_EXT_VERSION "Thu. Feb. 24 17:00:00 PDT 2011"
39 39
40/* 40/*
41 * Device IDs 41 * Device IDs
@@ -723,6 +723,7 @@ struct megasas_ctrl_info {
723 MEGASAS_MAX_DEV_PER_CHANNEL) 723 MEGASAS_MAX_DEV_PER_CHANNEL)
724 724
725#define MEGASAS_MAX_SECTORS (2*1024) 725#define MEGASAS_MAX_SECTORS (2*1024)
726#define MEGASAS_MAX_SECTORS_IEEE (2*128)
726#define MEGASAS_DBG_LVL 1 727#define MEGASAS_DBG_LVL 1
727 728
728#define MEGASAS_FW_BUSY 1 729#define MEGASAS_FW_BUSY 1
@@ -1477,4 +1478,7 @@ struct megasas_mgmt_info {
1477 int max_index; 1478 int max_index;
1478}; 1479};
1479 1480
1481#define msi_control_reg(base) (base + PCI_MSI_FLAGS)
1482#define PCI_MSIX_FLAGS_ENABLE (1 << 15)
1483
1480#endif /*LSI_MEGARAID_SAS_H */ 1484#endif /*LSI_MEGARAID_SAS_H */
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 5d6d07bd1cd0..f875e818905f 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -18,12 +18,13 @@
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 * FILE: megaraid_sas_base.c 20 * FILE: megaraid_sas_base.c
21 * Version : v00.00.05.29-rc1 21 * Version : v00.00.05.34-rc1
22 * 22 *
23 * Authors: LSI Corporation 23 * Authors: LSI Corporation
24 * Sreenivas Bagalkote 24 * Sreenivas Bagalkote
25 * Sumant Patro 25 * Sumant Patro
26 * Bo Yang 26 * Bo Yang
27 * Adam Radford <linuxraid@lsi.com>
27 * 28 *
28 * Send feedback to: <megaraidlinux@lsi.com> 29 * Send feedback to: <megaraidlinux@lsi.com>
29 * 30 *
@@ -134,7 +135,11 @@ spinlock_t poll_aen_lock;
134void 135void
135megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, 136megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
136 u8 alt_status); 137 u8 alt_status);
137 138static u32
139megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs);
140static int
141megasas_adp_reset_gen2(struct megasas_instance *instance,
142 struct megasas_register_set __iomem *reg_set);
138static irqreturn_t megasas_isr(int irq, void *devp); 143static irqreturn_t megasas_isr(int irq, void *devp);
139static u32 144static u32
140megasas_init_adapter_mfi(struct megasas_instance *instance); 145megasas_init_adapter_mfi(struct megasas_instance *instance);
@@ -554,6 +559,8 @@ static int
554megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) 559megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs)
555{ 560{
556 u32 status; 561 u32 status;
562 u32 mfiStatus = 0;
563
557 /* 564 /*
558 * Check if it is our interrupt 565 * Check if it is our interrupt
559 */ 566 */
@@ -564,6 +571,15 @@ megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs)
564 } 571 }
565 572
566 /* 573 /*
574 * Check if it is our interrupt
575 */
576 if ((megasas_read_fw_status_reg_gen2(regs) & MFI_STATE_MASK) ==
577 MFI_STATE_FAULT) {
578 mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE;
579 } else
580 mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE;
581
582 /*
567 * Clear the interrupt by writing back the same value 583 * Clear the interrupt by writing back the same value
568 */ 584 */
569 writel(status, &regs->outbound_intr_status); 585 writel(status, &regs->outbound_intr_status);
@@ -573,7 +589,7 @@ megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs)
573 */ 589 */
574 readl(&regs->outbound_intr_status); 590 readl(&regs->outbound_intr_status);
575 591
576 return 1; 592 return mfiStatus;
577} 593}
578 594
579/** 595/**
@@ -597,17 +613,6 @@ megasas_fire_cmd_skinny(struct megasas_instance *instance,
597} 613}
598 614
599/** 615/**
600 * megasas_adp_reset_skinny - For controller reset
601 * @regs: MFI register set
602 */
603static int
604megasas_adp_reset_skinny(struct megasas_instance *instance,
605 struct megasas_register_set __iomem *regs)
606{
607 return 0;
608}
609
610/**
611 * megasas_check_reset_skinny - For controller reset check 616 * megasas_check_reset_skinny - For controller reset check
612 * @regs: MFI register set 617 * @regs: MFI register set
613 */ 618 */
@@ -625,7 +630,7 @@ static struct megasas_instance_template megasas_instance_template_skinny = {
625 .disable_intr = megasas_disable_intr_skinny, 630 .disable_intr = megasas_disable_intr_skinny,
626 .clear_intr = megasas_clear_intr_skinny, 631 .clear_intr = megasas_clear_intr_skinny,
627 .read_fw_status_reg = megasas_read_fw_status_reg_skinny, 632 .read_fw_status_reg = megasas_read_fw_status_reg_skinny,
628 .adp_reset = megasas_adp_reset_skinny, 633 .adp_reset = megasas_adp_reset_gen2,
629 .check_reset = megasas_check_reset_skinny, 634 .check_reset = megasas_check_reset_skinny,
630 .service_isr = megasas_isr, 635 .service_isr = megasas_isr,
631 .tasklet = megasas_complete_cmd_dpc, 636 .tasklet = megasas_complete_cmd_dpc,
@@ -740,20 +745,28 @@ megasas_adp_reset_gen2(struct megasas_instance *instance,
740{ 745{
741 u32 retry = 0 ; 746 u32 retry = 0 ;
742 u32 HostDiag; 747 u32 HostDiag;
748 u32 *seq_offset = &reg_set->seq_offset;
749 u32 *hostdiag_offset = &reg_set->host_diag;
750
751 if (instance->instancet == &megasas_instance_template_skinny) {
752 seq_offset = &reg_set->fusion_seq_offset;
753 hostdiag_offset = &reg_set->fusion_host_diag;
754 }
755
756 writel(0, seq_offset);
757 writel(4, seq_offset);
758 writel(0xb, seq_offset);
759 writel(2, seq_offset);
760 writel(7, seq_offset);
761 writel(0xd, seq_offset);
743 762
744 writel(0, &reg_set->seq_offset);
745 writel(4, &reg_set->seq_offset);
746 writel(0xb, &reg_set->seq_offset);
747 writel(2, &reg_set->seq_offset);
748 writel(7, &reg_set->seq_offset);
749 writel(0xd, &reg_set->seq_offset);
750 msleep(1000); 763 msleep(1000);
751 764
752 HostDiag = (u32)readl(&reg_set->host_diag); 765 HostDiag = (u32)readl(hostdiag_offset);
753 766
754 while ( !( HostDiag & DIAG_WRITE_ENABLE) ) { 767 while ( !( HostDiag & DIAG_WRITE_ENABLE) ) {
755 msleep(100); 768 msleep(100);
756 HostDiag = (u32)readl(&reg_set->host_diag); 769 HostDiag = (u32)readl(hostdiag_offset);
757 printk(KERN_NOTICE "RESETGEN2: retry=%x, hostdiag=%x\n", 770 printk(KERN_NOTICE "RESETGEN2: retry=%x, hostdiag=%x\n",
758 retry, HostDiag); 771 retry, HostDiag);
759 772
@@ -764,14 +777,14 @@ megasas_adp_reset_gen2(struct megasas_instance *instance,
764 777
765 printk(KERN_NOTICE "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); 778 printk(KERN_NOTICE "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag);
766 779
767 writel((HostDiag | DIAG_RESET_ADAPTER), &reg_set->host_diag); 780 writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset);
768 781
769 ssleep(10); 782 ssleep(10);
770 783
771 HostDiag = (u32)readl(&reg_set->host_diag); 784 HostDiag = (u32)readl(hostdiag_offset);
772 while ( ( HostDiag & DIAG_RESET_ADAPTER) ) { 785 while ( ( HostDiag & DIAG_RESET_ADAPTER) ) {
773 msleep(100); 786 msleep(100);
774 HostDiag = (u32)readl(&reg_set->host_diag); 787 HostDiag = (u32)readl(hostdiag_offset);
775 printk(KERN_NOTICE "RESET_GEN2: retry=%x, hostdiag=%x\n", 788 printk(KERN_NOTICE "RESET_GEN2: retry=%x, hostdiag=%x\n",
776 retry, HostDiag); 789 retry, HostDiag);
777 790
@@ -2503,7 +2516,9 @@ megasas_deplete_reply_queue(struct megasas_instance *instance,
2503 if ((mfiStatus = instance->instancet->clear_intr( 2516 if ((mfiStatus = instance->instancet->clear_intr(
2504 instance->reg_set) 2517 instance->reg_set)
2505 ) == 0) { 2518 ) == 0) {
2506 return IRQ_NONE; 2519 /* Hardware may not set outbound_intr_status in MSI-X mode */
2520 if (!instance->msi_flag)
2521 return IRQ_NONE;
2507 } 2522 }
2508 2523
2509 instance->mfiStatus = mfiStatus; 2524 instance->mfiStatus = mfiStatus;
@@ -2611,7 +2626,9 @@ megasas_transition_to_ready(struct megasas_instance* instance)
2611 case MFI_STATE_FAULT: 2626 case MFI_STATE_FAULT:
2612 2627
2613 printk(KERN_DEBUG "megasas: FW in FAULT state!!\n"); 2628 printk(KERN_DEBUG "megasas: FW in FAULT state!!\n");
2614 return -ENODEV; 2629 max_wait = MEGASAS_RESET_WAIT_TIME;
2630 cur_state = MFI_STATE_FAULT;
2631 break;
2615 2632
2616 case MFI_STATE_WAIT_HANDSHAKE: 2633 case MFI_STATE_WAIT_HANDSHAKE:
2617 /* 2634 /*
@@ -3424,7 +3441,6 @@ fail_reply_queue:
3424 megasas_free_cmds(instance); 3441 megasas_free_cmds(instance);
3425 3442
3426fail_alloc_cmds: 3443fail_alloc_cmds:
3427 iounmap(instance->reg_set);
3428 return 1; 3444 return 1;
3429} 3445}
3430 3446
@@ -3494,7 +3510,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
3494 3510
3495 /* Get operational params, sge flags, send init cmd to controller */ 3511 /* Get operational params, sge flags, send init cmd to controller */
3496 if (instance->instancet->init_adapter(instance)) 3512 if (instance->instancet->init_adapter(instance))
3497 return -ENODEV; 3513 goto fail_init_adapter;
3498 3514
3499 printk(KERN_ERR "megasas: INIT adapter done\n"); 3515 printk(KERN_ERR "megasas: INIT adapter done\n");
3500 3516
@@ -3543,7 +3559,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
3543 * Setup tasklet for cmd completion 3559 * Setup tasklet for cmd completion
3544 */ 3560 */
3545 3561
3546 tasklet_init(&instance->isr_tasklet, megasas_complete_cmd_dpc, 3562 tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
3547 (unsigned long)instance); 3563 (unsigned long)instance);
3548 3564
3549 /* Initialize the cmd completion timer */ 3565 /* Initialize the cmd completion timer */
@@ -3553,6 +3569,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
3553 MEGASAS_COMPLETION_TIMER_INTERVAL); 3569 MEGASAS_COMPLETION_TIMER_INTERVAL);
3554 return 0; 3570 return 0;
3555 3571
3572fail_init_adapter:
3556fail_ready_state: 3573fail_ready_state:
3557 iounmap(instance->reg_set); 3574 iounmap(instance->reg_set);
3558 3575
@@ -3820,6 +3837,10 @@ static int megasas_io_attach(struct megasas_instance *instance)
3820 instance->max_fw_cmds - MEGASAS_INT_CMDS; 3837 instance->max_fw_cmds - MEGASAS_INT_CMDS;
3821 host->this_id = instance->init_id; 3838 host->this_id = instance->init_id;
3822 host->sg_tablesize = instance->max_num_sge; 3839 host->sg_tablesize = instance->max_num_sge;
3840
3841 if (instance->fw_support_ieee)
3842 instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE;
3843
3823 /* 3844 /*
3824 * Check if the module parameter value for max_sectors can be used 3845 * Check if the module parameter value for max_sectors can be used
3825 */ 3846 */
@@ -3899,9 +3920,26 @@ fail_set_dma_mask:
3899static int __devinit 3920static int __devinit
3900megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) 3921megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
3901{ 3922{
3902 int rval; 3923 int rval, pos;
3903 struct Scsi_Host *host; 3924 struct Scsi_Host *host;
3904 struct megasas_instance *instance; 3925 struct megasas_instance *instance;
3926 u16 control = 0;
3927
3928 /* Reset MSI-X in the kdump kernel */
3929 if (reset_devices) {
3930 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
3931 if (pos) {
3932 pci_read_config_word(pdev, msi_control_reg(pos),
3933 &control);
3934 if (control & PCI_MSIX_FLAGS_ENABLE) {
3935 dev_info(&pdev->dev, "resetting MSI-X\n");
3936 pci_write_config_word(pdev,
3937 msi_control_reg(pos),
3938 control &
3939 ~PCI_MSIX_FLAGS_ENABLE);
3940 }
3941 }
3942 }
3905 3943
3906 /* 3944 /*
3907 * Announce PCI information 3945 * Announce PCI information
@@ -4039,12 +4077,6 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4039 else 4077 else
4040 INIT_WORK(&instance->work_init, process_fw_state_change_wq); 4078 INIT_WORK(&instance->work_init, process_fw_state_change_wq);
4041 4079
4042 /*
4043 * Initialize MFI Firmware
4044 */
4045 if (megasas_init_fw(instance))
4046 goto fail_init_mfi;
4047
4048 /* Try to enable MSI-X */ 4080 /* Try to enable MSI-X */
4049 if ((instance->pdev->device != PCI_DEVICE_ID_LSI_SAS1078R) && 4081 if ((instance->pdev->device != PCI_DEVICE_ID_LSI_SAS1078R) &&
4050 (instance->pdev->device != PCI_DEVICE_ID_LSI_SAS1078DE) && 4082 (instance->pdev->device != PCI_DEVICE_ID_LSI_SAS1078DE) &&
@@ -4054,6 +4086,12 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4054 instance->msi_flag = 1; 4086 instance->msi_flag = 1;
4055 4087
4056 /* 4088 /*
4089 * Initialize MFI Firmware
4090 */
4091 if (megasas_init_fw(instance))
4092 goto fail_init_mfi;
4093
4094 /*
4057 * Register IRQ 4095 * Register IRQ
4058 */ 4096 */
4059 if (request_irq(instance->msi_flag ? instance->msixentry.vector : 4097 if (request_irq(instance->msi_flag ? instance->msixentry.vector :
@@ -4105,24 +4143,23 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4105 instance->instancet->disable_intr(instance->reg_set); 4143 instance->instancet->disable_intr(instance->reg_set);
4106 free_irq(instance->msi_flag ? instance->msixentry.vector : 4144 free_irq(instance->msi_flag ? instance->msixentry.vector :
4107 instance->pdev->irq, instance); 4145 instance->pdev->irq, instance);
4146fail_irq:
4147 if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION)
4148 megasas_release_fusion(instance);
4149 else
4150 megasas_release_mfi(instance);
4151 fail_init_mfi:
4108 if (instance->msi_flag) 4152 if (instance->msi_flag)
4109 pci_disable_msix(instance->pdev); 4153 pci_disable_msix(instance->pdev);
4110
4111 fail_irq:
4112 fail_init_mfi:
4113 fail_alloc_dma_buf: 4154 fail_alloc_dma_buf:
4114 if (instance->evt_detail) 4155 if (instance->evt_detail)
4115 pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), 4156 pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
4116 instance->evt_detail, 4157 instance->evt_detail,
4117 instance->evt_detail_h); 4158 instance->evt_detail_h);
4118 4159
4119 if (instance->producer) { 4160 if (instance->producer)
4120 pci_free_consistent(pdev, sizeof(u32), instance->producer, 4161 pci_free_consistent(pdev, sizeof(u32), instance->producer,
4121 instance->producer_h); 4162 instance->producer_h);
4122 megasas_release_mfi(instance);
4123 } else {
4124 megasas_release_fusion(instance);
4125 }
4126 if (instance->consumer) 4163 if (instance->consumer)
4127 pci_free_consistent(pdev, sizeof(u32), instance->consumer, 4164 pci_free_consistent(pdev, sizeof(u32), instance->consumer,
4128 instance->consumer_h); 4165 instance->consumer_h);
@@ -4242,9 +4279,8 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
4242 /* cancel the delayed work if this work still in queue */ 4279 /* cancel the delayed work if this work still in queue */
4243 if (instance->ev != NULL) { 4280 if (instance->ev != NULL) {
4244 struct megasas_aen_event *ev = instance->ev; 4281 struct megasas_aen_event *ev = instance->ev;
4245 cancel_delayed_work( 4282 cancel_delayed_work_sync(
4246 (struct delayed_work *)&ev->hotplug_work); 4283 (struct delayed_work *)&ev->hotplug_work);
4247 flush_scheduled_work();
4248 instance->ev = NULL; 4284 instance->ev = NULL;
4249 } 4285 }
4250 4286
@@ -4297,6 +4333,10 @@ megasas_resume(struct pci_dev *pdev)
4297 if (megasas_set_dma_mask(pdev)) 4333 if (megasas_set_dma_mask(pdev))
4298 goto fail_set_dma_mask; 4334 goto fail_set_dma_mask;
4299 4335
4336 /* Now re-enable MSI-X */
4337 if (instance->msi_flag)
4338 pci_enable_msix(instance->pdev, &instance->msixentry, 1);
4339
4300 /* 4340 /*
4301 * Initialize MFI Firmware 4341 * Initialize MFI Firmware
4302 */ 4342 */
@@ -4333,10 +4373,6 @@ megasas_resume(struct pci_dev *pdev)
4333 tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, 4373 tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
4334 (unsigned long)instance); 4374 (unsigned long)instance);
4335 4375
4336 /* Now re-enable MSI-X */
4337 if (instance->msi_flag)
4338 pci_enable_msix(instance->pdev, &instance->msixentry, 1);
4339
4340 /* 4376 /*
4341 * Register IRQ 4377 * Register IRQ
4342 */ 4378 */
@@ -4417,9 +4453,8 @@ static void __devexit megasas_detach_one(struct pci_dev *pdev)
4417 /* cancel the delayed work if this work still in queue*/ 4453 /* cancel the delayed work if this work still in queue*/
4418 if (instance->ev != NULL) { 4454 if (instance->ev != NULL) {
4419 struct megasas_aen_event *ev = instance->ev; 4455 struct megasas_aen_event *ev = instance->ev;
4420 cancel_delayed_work( 4456 cancel_delayed_work_sync(
4421 (struct delayed_work *)&ev->hotplug_work); 4457 (struct delayed_work *)&ev->hotplug_work);
4422 flush_scheduled_work();
4423 instance->ev = NULL; 4458 instance->ev = NULL;
4424 } 4459 }
4425 4460
@@ -4611,6 +4646,9 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
4611 * For each user buffer, create a mirror buffer and copy in 4646 * For each user buffer, create a mirror buffer and copy in
4612 */ 4647 */
4613 for (i = 0; i < ioc->sge_count; i++) { 4648 for (i = 0; i < ioc->sge_count; i++) {
4649 if (!ioc->sgl[i].iov_len)
4650 continue;
4651
4614 kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, 4652 kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev,
4615 ioc->sgl[i].iov_len, 4653 ioc->sgl[i].iov_len,
4616 &buf_handle, GFP_KERNEL); 4654 &buf_handle, GFP_KERNEL);
@@ -5177,6 +5215,7 @@ megasas_aen_polling(struct work_struct *work)
5177 break; 5215 break;
5178 5216
5179 case MR_EVT_LD_OFFLINE: 5217 case MR_EVT_LD_OFFLINE:
5218 case MR_EVT_CFG_CLEARED:
5180 case MR_EVT_LD_DELETED: 5219 case MR_EVT_LD_DELETED:
5181 megasas_get_ld_list(instance); 5220 megasas_get_ld_list(instance);
5182 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { 5221 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index d6e2a663b165..145a8cffb1fa 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -81,6 +81,10 @@ u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_FW_RAID_MAP_ALL *map);
81struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_FW_RAID_MAP_ALL *map); 81struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_FW_RAID_MAP_ALL *map);
82 82
83u16 MR_GetLDTgtId(u32 ld, struct MR_FW_RAID_MAP_ALL *map); 83u16 MR_GetLDTgtId(u32 ld, struct MR_FW_RAID_MAP_ALL *map);
84
85void
86megasas_check_and_restore_queue_depth(struct megasas_instance *instance);
87
84u8 MR_ValidateMapInfo(struct MR_FW_RAID_MAP_ALL *map, 88u8 MR_ValidateMapInfo(struct MR_FW_RAID_MAP_ALL *map,
85 struct LD_LOAD_BALANCE_INFO *lbInfo); 89 struct LD_LOAD_BALANCE_INFO *lbInfo);
86u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo, 90u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo,
@@ -983,13 +987,15 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
983 987
984 return 0; 988 return 0;
985 989
986fail_alloc_cmds:
987fail_alloc_mfi_cmds:
988fail_map_info: 990fail_map_info:
989 if (i == 1) 991 if (i == 1)
990 dma_free_coherent(&instance->pdev->dev, fusion->map_sz, 992 dma_free_coherent(&instance->pdev->dev, fusion->map_sz,
991 fusion->ld_map[0], fusion->ld_map_phys[0]); 993 fusion->ld_map[0], fusion->ld_map_phys[0]);
992fail_ioc_init: 994fail_ioc_init:
995 megasas_free_cmds_fusion(instance);
996fail_alloc_cmds:
997 megasas_free_cmds(instance);
998fail_alloc_mfi_cmds:
993 return 1; 999 return 1;
994} 1000}
995 1001
@@ -1431,8 +1437,7 @@ megasas_build_dcdb_fusion(struct megasas_instance *instance,
1431 local_map_ptr = fusion->ld_map[(instance->map_id & 1)]; 1437 local_map_ptr = fusion->ld_map[(instance->map_id & 1)];
1432 1438
1433 /* Check if this is a system PD I/O */ 1439 /* Check if this is a system PD I/O */
1434 if ((instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) && 1440 if (instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) {
1435 (instance->pd_list[pd_index].driveType == TYPE_DISK)) {
1436 io_request->Function = 0; 1441 io_request->Function = 0;
1437 io_request->DevHandle = 1442 io_request->DevHandle =
1438 local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl; 1443 local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
@@ -1455,7 +1460,7 @@ megasas_build_dcdb_fusion(struct megasas_instance *instance,
1455 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 1460 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1456 } 1461 }
1457 io_request->RaidContext.VirtualDiskTgtId = device_id; 1462 io_request->RaidContext.VirtualDiskTgtId = device_id;
1458 io_request->LUN[0] = scmd->device->lun; 1463 io_request->LUN[1] = scmd->device->lun;
1459 io_request->DataLength = scsi_bufflen(scmd); 1464 io_request->DataLength = scsi_bufflen(scmd);
1460} 1465}
1461 1466
@@ -1479,7 +1484,7 @@ megasas_build_io_fusion(struct megasas_instance *instance,
1479 device_id = MEGASAS_DEV_INDEX(instance, scp); 1484 device_id = MEGASAS_DEV_INDEX(instance, scp);
1480 1485
1481 /* Zero out some fields so they don't get reused */ 1486 /* Zero out some fields so they don't get reused */
1482 io_request->LUN[0] = 0; 1487 io_request->LUN[1] = 0;
1483 io_request->CDB.EEDP32.PrimaryReferenceTag = 0; 1488 io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
1484 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0; 1489 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
1485 io_request->EEDPFlags = 0; 1490 io_request->EEDPFlags = 0;
@@ -1743,7 +1748,7 @@ complete_cmd_fusion(struct megasas_instance *instance)
1743 wmb(); 1748 wmb();
1744 writel(fusion->last_reply_idx, 1749 writel(fusion->last_reply_idx,
1745 &instance->reg_set->reply_post_host_index); 1750 &instance->reg_set->reply_post_host_index);
1746 1751 megasas_check_and_restore_queue_depth(instance);
1747 return IRQ_HANDLED; 1752 return IRQ_HANDLED;
1748} 1753}
1749 1754
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2.h b/drivers/scsi/mpt2sas/mpi/mpi2.h
index 8be75e65f763..a3e60385787f 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2.h
@@ -8,7 +8,7 @@
8 * scatter/gather formats. 8 * scatter/gather formats.
9 * Creation Date: June 21, 2006 9 * Creation Date: June 21, 2006
10 * 10 *
11 * mpi2.h Version: 02.00.16 11 * mpi2.h Version: 02.00.17
12 * 12 *
13 * Version History 13 * Version History
14 * --------------- 14 * ---------------
@@ -63,6 +63,7 @@
63 * function codes, 0xF0 to 0xFF. 63 * function codes, 0xF0 to 0xFF.
64 * 05-12-10 02.00.16 Bumped MPI2_HEADER_VERSION_UNIT. 64 * 05-12-10 02.00.16 Bumped MPI2_HEADER_VERSION_UNIT.
65 * Added alternative defines for the SGE Direction bit. 65 * Added alternative defines for the SGE Direction bit.
66 * 08-11-10 02.00.17 Bumped MPI2_HEADER_VERSION_UNIT.
66 * -------------------------------------------------------------------------- 67 * --------------------------------------------------------------------------
67 */ 68 */
68 69
@@ -88,7 +89,7 @@
88#define MPI2_VERSION_02_00 (0x0200) 89#define MPI2_VERSION_02_00 (0x0200)
89 90
90/* versioning for this MPI header set */ 91/* versioning for this MPI header set */
91#define MPI2_HEADER_VERSION_UNIT (0x10) 92#define MPI2_HEADER_VERSION_UNIT (0x11)
92#define MPI2_HEADER_VERSION_DEV (0x00) 93#define MPI2_HEADER_VERSION_DEV (0x00)
93#define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00) 94#define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00)
94#define MPI2_HEADER_VERSION_UNIT_SHIFT (8) 95#define MPI2_HEADER_VERSION_UNIT_SHIFT (8)
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h b/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
index d76a65847603..f5b9c766e28f 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
@@ -6,7 +6,7 @@
6 * Title: MPI Configuration messages and pages 6 * Title: MPI Configuration messages and pages
7 * Creation Date: November 10, 2006 7 * Creation Date: November 10, 2006
8 * 8 *
9 * mpi2_cnfg.h Version: 02.00.15 9 * mpi2_cnfg.h Version: 02.00.16
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -125,6 +125,8 @@
125 * define. 125 * define.
126 * Added MPI2_PHYSDISK0_INCOMPATIBLE_MEDIA_TYPE define. 126 * Added MPI2_PHYSDISK0_INCOMPATIBLE_MEDIA_TYPE define.
127 * Added MPI2_SAS_NEG_LINK_RATE_UNSUPPORTED_PHY define. 127 * Added MPI2_SAS_NEG_LINK_RATE_UNSUPPORTED_PHY define.
128 * 08-11-10 02.00.16 Removed IO Unit Page 1 device path (multi-pathing)
129 * defines.
128 * -------------------------------------------------------------------------- 130 * --------------------------------------------------------------------------
129 */ 131 */
130 132
@@ -745,8 +747,6 @@ typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_1
745#define MPI2_IOUNITPAGE1_DISABLE_IR (0x00000040) 747#define MPI2_IOUNITPAGE1_DISABLE_IR (0x00000040)
746#define MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING (0x00000020) 748#define MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING (0x00000020)
747#define MPI2_IOUNITPAGE1_IR_USE_STATIC_VOLUME_ID (0x00000004) 749#define MPI2_IOUNITPAGE1_IR_USE_STATIC_VOLUME_ID (0x00000004)
748#define MPI2_IOUNITPAGE1_MULTI_PATHING (0x00000002)
749#define MPI2_IOUNITPAGE1_SINGLE_PATHING (0x00000000)
750 750
751 751
752/* IO Unit Page 3 */ 752/* IO Unit Page 3 */
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_history.txt b/drivers/scsi/mpt2sas/mpi/mpi2_history.txt
deleted file mode 100644
index b1e88f26b748..000000000000
--- a/drivers/scsi/mpt2sas/mpi/mpi2_history.txt
+++ /dev/null
@@ -1,384 +0,0 @@
1 ==============================
2 Fusion-MPT MPI 2.0 Header File Change History
3 ==============================
4
5 Copyright (c) 2000-2010 LSI Corporation.
6
7 ---------------------------------------
8 Header Set Release Version: 02.00.14
9 Header Set Release Date: 10-28-09
10 ---------------------------------------
11
12 Filename Current version Prior version
13 ---------- --------------- -------------
14 mpi2.h 02.00.14 02.00.13
15 mpi2_cnfg.h 02.00.13 02.00.12
16 mpi2_init.h 02.00.08 02.00.07
17 mpi2_ioc.h 02.00.13 02.00.12
18 mpi2_raid.h 02.00.04 02.00.04
19 mpi2_sas.h 02.00.03 02.00.02
20 mpi2_targ.h 02.00.03 02.00.03
21 mpi2_tool.h 02.00.04 02.00.04
22 mpi2_type.h 02.00.00 02.00.00
23 mpi2_ra.h 02.00.00 02.00.00
24 mpi2_hbd.h 02.00.00
25 mpi2_history.txt 02.00.14 02.00.13
26
27
28 * Date Version Description
29 * -------- -------- ------------------------------------------------------
30
31mpi2.h
32 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
33 * 06-04-07 02.00.01 Bumped MPI2_HEADER_VERSION_UNIT.
34 * 06-26-07 02.00.02 Bumped MPI2_HEADER_VERSION_UNIT.
35 * 08-31-07 02.00.03 Bumped MPI2_HEADER_VERSION_UNIT.
36 * Moved ReplyPostHostIndex register to offset 0x6C of the
37 * MPI2_SYSTEM_INTERFACE_REGS and modified the define for
38 * MPI2_REPLY_POST_HOST_INDEX_OFFSET.
39 * Added union of request descriptors.
40 * Added union of reply descriptors.
41 * 10-31-07 02.00.04 Bumped MPI2_HEADER_VERSION_UNIT.
42 * Added define for MPI2_VERSION_02_00.
43 * Fixed the size of the FunctionDependent5 field in the
44 * MPI2_DEFAULT_REPLY structure.
45 * 12-18-07 02.00.05 Bumped MPI2_HEADER_VERSION_UNIT.
46 * Removed the MPI-defined Fault Codes and extended the
47 * product specific codes up to 0xEFFF.
48 * Added a sixth key value for the WriteSequence register
49 * and changed the flush value to 0x0.
50 * Added message function codes for Diagnostic Buffer Post
51 * and Diagnsotic Release.
52 * New IOCStatus define: MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED
53 * Moved MPI2_VERSION_UNION from mpi2_ioc.h.
54 * 02-29-08 02.00.06 Bumped MPI2_HEADER_VERSION_UNIT.
55 * 03-03-08 02.00.07 Bumped MPI2_HEADER_VERSION_UNIT.
56 * 05-21-08 02.00.08 Bumped MPI2_HEADER_VERSION_UNIT.
57 * Added #defines for marking a reply descriptor as unused.
58 * 06-27-08 02.00.09 Bumped MPI2_HEADER_VERSION_UNIT.
59 * 10-02-08 02.00.10 Bumped MPI2_HEADER_VERSION_UNIT.
60 * Moved LUN field defines from mpi2_init.h.
61 * 01-19-09 02.00.11 Bumped MPI2_HEADER_VERSION_UNIT.
62 * 05-06-09 02.00.12 Bumped MPI2_HEADER_VERSION_UNIT.
63 * In all request and reply descriptors, replaced VF_ID
64 * field with MSIxIndex field.
65 * Removed DevHandle field from
66 * MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR and made those
67 * bytes reserved.
68 * Added RAID Accelerator functionality.
69 * 07-30-09 02.00.13 Bumped MPI2_HEADER_VERSION_UNIT.
70 * 10-28-09 02.00.14 Bumped MPI2_HEADER_VERSION_UNIT.
71 * Added MSI-x index mask and shift for Reply Post Host
72 * Index register.
73 * Added function code for Host Based Discovery Action.
74 * --------------------------------------------------------------------------
75
76mpi2_cnfg.h
77 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
78 * 06-04-07 02.00.01 Added defines for SAS IO Unit Page 2 PhyFlags.
79 * Added Manufacturing Page 11.
80 * Added MPI2_SAS_EXPANDER0_FLAGS_CONNECTOR_END_DEVICE
81 * define.
82 * 06-26-07 02.00.02 Adding generic structure for product-specific
83 * Manufacturing pages: MPI2_CONFIG_PAGE_MANUFACTURING_PS.
84 * Rework of BIOS Page 2 configuration page.
85 * Fixed MPI2_BIOSPAGE2_BOOT_DEVICE to be a union of the
86 * forms.
87 * Added configuration pages IOC Page 8 and Driver
88 * Persistent Mapping Page 0.
89 * 08-31-07 02.00.03 Modified configuration pages dealing with Integrated
90 * RAID (Manufacturing Page 4, RAID Volume Pages 0 and 1,
91 * RAID Physical Disk Pages 0 and 1, RAID Configuration
92 * Page 0).
93 * Added new value for AccessStatus field of SAS Device
94 * Page 0 (_SATA_NEEDS_INITIALIZATION).
95 * 10-31-07 02.00.04 Added missing SEPDevHandle field to
96 * MPI2_CONFIG_PAGE_SAS_ENCLOSURE_0.
97 * 12-18-07 02.00.05 Modified IO Unit Page 0 to use 32-bit version fields for
98 * NVDATA.
99 * Modified IOC Page 7 to use masks and added field for
100 * SASBroadcastPrimitiveMasks.
101 * Added MPI2_CONFIG_PAGE_BIOS_4.
102 * Added MPI2_CONFIG_PAGE_LOG_0.
103 * 02-29-08 02.00.06 Modified various names to make them 32-character unique.
104 * Added SAS Device IDs.
105 * Updated Integrated RAID configuration pages including
106 * Manufacturing Page 4, IOC Page 6, and RAID Configuration
107 * Page 0.
108 * 05-21-08 02.00.07 Added define MPI2_MANPAGE4_MIX_SSD_SAS_SATA.
109 * Added define MPI2_MANPAGE4_PHYSDISK_128MB_COERCION.
110 * Fixed define MPI2_IOCPAGE8_FLAGS_ENCLOSURE_SLOT_MAPPING.
111 * Added missing MaxNumRoutedSasAddresses field to
112 * MPI2_CONFIG_PAGE_EXPANDER_0.
113 * Added SAS Port Page 0.
114 * Modified structure layout for
115 * MPI2_CONFIG_PAGE_DRIVER_MAPPING_0.
116 * 06-27-08 02.00.08 Changed MPI2_CONFIG_PAGE_RD_PDISK_1 to use
117 * MPI2_RAID_PHYS_DISK1_PATH_MAX to size the array.
118 * 10-02-08 02.00.09 Changed MPI2_RAID_PGAD_CONFIGNUM_MASK from 0x0000FFFF
119 * to 0x000000FF.
120 * Added two new values for the Physical Disk Coercion Size
121 * bits in the Flags field of Manufacturing Page 4.
122 * Added product-specific Manufacturing pages 16 to 31.
123 * Modified Flags bits for controlling write cache on SATA
124 * drives in IO Unit Page 1.
125 * Added new bit to AdditionalControlFlags of SAS IO Unit
126 * Page 1 to control Invalid Topology Correction.
127 * Added SupportedPhysDisks field to RAID Volume Page 1 and
128 * added related defines.
129 * Added additional defines for RAID Volume Page 0
130 * VolumeStatusFlags field.
131 * Modified meaning of RAID Volume Page 0 VolumeSettings
132 * define for auto-configure of hot-swap drives.
133 * Added PhysDiskAttributes field (and related defines) to
134 * RAID Physical Disk Page 0.
135 * Added MPI2_SAS_PHYINFO_PHY_VACANT define.
136 * Added three new DiscoveryStatus bits for SAS IO Unit
137 * Page 0 and SAS Expander Page 0.
138 * Removed multiplexing information from SAS IO Unit pages.
139 * Added BootDeviceWaitTime field to SAS IO Unit Page 4.
140 * Removed Zone Address Resolved bit from PhyInfo and from
141 * Expander Page 0 Flags field.
142 * Added two new AccessStatus values to SAS Device Page 0
143 * for indicating routing problems. Added 3 reserved words
144 * to this page.
145 * 01-19-09 02.00.10 Fixed defines for GPIOVal field of IO Unit Page 3.
146 * Inserted missing reserved field into structure for IOC
147 * Page 6.
148 * Added more pending task bits to RAID Volume Page 0
149 * VolumeStatusFlags defines.
150 * Added MPI2_PHYSDISK0_STATUS_FLAG_NOT_CERTIFIED define.
151 * Added a new DiscoveryStatus bit for SAS IO Unit Page 0
152 * and SAS Expander Page 0 to flag a downstream initiator
153 * when in simplified routing mode.
154 * Removed SATA Init Failure defines for DiscoveryStatus
155 * fields of SAS IO Unit Page 0 and SAS Expander Page 0.
156 * Added MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED define.
157 * Added PortGroups, DmaGroup, and ControlGroup fields to
158 * SAS Device Page 0.
159 * 05-06-09 02.00.11 Added structures and defines for IO Unit Page 5 and IO
160 * Unit Page 6.
161 * Added expander reduced functionality data to SAS
162 * Expander Page 0.
163 * Added SAS PHY Page 2 and SAS PHY Page 3.
164 * 07-30-09 02.00.12 Added IO Unit Page 7.
165 * Added new device ids.
166 * Added SAS IO Unit Page 5.
167 * Added partial and slumber power management capable flags
168 * to SAS Device Page 0 Flags field.
169 * Added PhyInfo defines for power condition.
170 * Added Ethernet configuration pages.
171 * 10-28-09 02.00.13 Added MPI2_IOUNITPAGE1_ENABLE_HOST_BASED_DISCOVERY.
172 * Added SAS PHY Page 4 structure and defines.
173 * --------------------------------------------------------------------------
174
175mpi2_init.h
176 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
177 * 10-31-07 02.00.01 Fixed name for pMpi2SCSITaskManagementRequest_t.
178 * 12-18-07 02.00.02 Modified Task Management Target Reset Method defines.
179 * 02-29-08 02.00.03 Added Query Task Set and Query Unit Attention.
180 * 03-03-08 02.00.04 Fixed name of struct _MPI2_SCSI_TASK_MANAGE_REPLY.
181 * 05-21-08 02.00.05 Fixed typo in name of Mpi2SepRequest_t.
182 * 10-02-08 02.00.06 Removed Untagged and No Disconnect values from SCSI IO
183 * Control field Task Attribute flags.
184 * Moved LUN field defines to mpi2.h becasue they are
185 * common to many structures.
186 * 05-06-09 02.00.07 Changed task management type of Query Unit Attention to
187 * Query Asynchronous Event.
188 * Defined two new bits in the SlotStatus field of the SCSI
189 * Enclosure Processor Request and Reply.
190 * 10-28-09 02.00.08 Added defines for decoding the ResponseInfo bytes for
191 * both SCSI IO Error Reply and SCSI Task Management Reply.
192 * Added ResponseInfo field to MPI2_SCSI_TASK_MANAGE_REPLY.
193 * Added MPI2_SCSITASKMGMT_RSP_TM_OVERLAPPED_TAG define.
194 * --------------------------------------------------------------------------
195
196mpi2_ioc.h
197 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
198 * 06-04-07 02.00.01 In IOCFacts Reply structure, renamed MaxDevices to
199 * MaxTargets.
200 * Added TotalImageSize field to FWDownload Request.
201 * Added reserved words to FWUpload Request.
202 * 06-26-07 02.00.02 Added IR Configuration Change List Event.
203 * 08-31-07 02.00.03 Removed SystemReplyQueueDepth field from the IOCInit
204 * request and replaced it with
205 * ReplyDescriptorPostQueueDepth and ReplyFreeQueueDepth.
206 * Replaced the MinReplyQueueDepth field of the IOCFacts
207 * reply with MaxReplyDescriptorPostQueueDepth.
208 * Added MPI2_RDPQ_DEPTH_MIN define to specify the minimum
209 * depth for the Reply Descriptor Post Queue.
210 * Added SASAddress field to Initiator Device Table
211 * Overflow Event data.
212 * 10-31-07 02.00.04 Added ReasonCode MPI2_EVENT_SAS_INIT_RC_NOT_RESPONDING
213 * for SAS Initiator Device Status Change Event data.
214 * Modified Reason Code defines for SAS Topology Change
215 * List Event data, including adding a bit for PHY Vacant
216 * status, and adding a mask for the Reason Code.
217 * Added define for
218 * MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING.
219 * Added define for MPI2_EXT_IMAGE_TYPE_MEGARAID.
220 * 12-18-07 02.00.05 Added Boot Status defines for the IOCExceptions field of
221 * the IOCFacts Reply.
222 * Removed MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER define.
223 * Moved MPI2_VERSION_UNION to mpi2.h.
224 * Changed MPI2_EVENT_NOTIFICATION_REQUEST to use masks
225 * instead of enables, and added SASBroadcastPrimitiveMasks
226 * field.
227 * Added Log Entry Added Event and related structure.
228 * 02-29-08 02.00.06 Added define MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID.
229 * Removed define MPI2_IOCFACTS_PROTOCOL_SMP_TARGET.
230 * Added MaxVolumes and MaxPersistentEntries fields to
231 * IOCFacts reply.
232 * Added ProtocalFlags and IOCCapabilities fields to
233 * MPI2_FW_IMAGE_HEADER.
234 * Removed MPI2_PORTENABLE_FLAGS_ENABLE_SINGLE_PORT.
235 * 03-03-08 02.00.07 Fixed MPI2_FW_IMAGE_HEADER by changing Reserved26 to
236 * a U16 (from a U32).
237 * Removed extra 's' from EventMasks name.
238 * 06-27-08 02.00.08 Fixed an offset in a comment.
239 * 10-02-08 02.00.09 Removed SystemReplyFrameSize from MPI2_IOC_INIT_REQUEST.
240 * Removed CurReplyFrameSize from MPI2_IOC_FACTS_REPLY and
241 * renamed MinReplyFrameSize to ReplyFrameSize.
242 * Added MPI2_IOCFACTS_EXCEPT_IR_FOREIGN_CONFIG_MAX.
243 * Added two new RAIDOperation values for Integrated RAID
244 * Operations Status Event data.
245 * Added four new IR Configuration Change List Event data
246 * ReasonCode values.
247 * Added two new ReasonCode defines for SAS Device Status
248 * Change Event data.
249 * Added three new DiscoveryStatus bits for the SAS
250 * Discovery event data.
251 * Added Multiplexing Status Change bit to the PhyStatus
252 * field of the SAS Topology Change List event data.
253 * Removed define for MPI2_INIT_IMAGE_BOOTFLAGS_XMEMCOPY.
254 * BootFlags are now product-specific.
255 * Added defines for the indivdual signature bytes
256 * for MPI2_INIT_IMAGE_FOOTER.
257 * 01-19-09 02.00.10 Added MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY define.
258 * Added MPI2_EVENT_SAS_DISC_DS_DOWNSTREAM_INITIATOR
259 * define.
260 * Added MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
261 * define.
262 * Removed MPI2_EVENT_SAS_DISC_DS_SATA_INIT_FAILURE define.
263 * 05-06-09 02.00.11 Added MPI2_IOCFACTS_CAPABILITY_RAID_ACCELERATOR define.
264 * Added MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX define.
265 * Added two new reason codes for SAS Device Status Change
266 * Event.
267 * Added new event: SAS PHY Counter.
268 * 07-30-09 02.00.12 Added GPIO Interrupt event define and structure.
269 * Added MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER define.
270 * Added new product id family for 2208.
271 * 10-28-09 02.00.13 Added HostMSIxVectors field to MPI2_IOC_INIT_REQUEST.
272 * Added MaxMSIxVectors field to MPI2_IOC_FACTS_REPLY.
273 * Added MinDevHandle field to MPI2_IOC_FACTS_REPLY.
274 * Added MPI2_IOCFACTS_CAPABILITY_HOST_BASED_DISCOVERY.
275 * Added MPI2_EVENT_HOST_BASED_DISCOVERY_PHY define.
276 * Added MPI2_EVENT_SAS_TOPO_ES_NO_EXPANDER define.
277 * Added Host Based Discovery Phy Event data.
278 * Added defines for ProductID Product field
279 * (MPI2_FW_HEADER_PID_).
280 * Modified values for SAS ProductID Family
281 * (MPI2_FW_HEADER_PID_FAMILY_).
282 * --------------------------------------------------------------------------
283
284mpi2_raid.h
285 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
286 * 08-31-07 02.00.01 Modifications to RAID Action request and reply,
287 * including the Actions and ActionData.
288 * 02-29-08 02.00.02 Added MPI2_RAID_ACTION_ADATA_DISABL_FULL_REBUILD.
289 * 05-21-08 02.00.03 Added MPI2_RAID_VOL_CREATION_NUM_PHYSDISKS so that
290 * the PhysDisk array in MPI2_RAID_VOLUME_CREATION_STRUCT
291 * can be sized by the build environment.
292 * 07-30-09 02.00.04 Added proper define for the Use Default Settings bit of
293 * VolumeCreationFlags and marked the old one as obsolete.
294 * 05-12-10 02.00.05 Added MPI2_RAID_VOL_FLAGS_OP_MDC define.
295 * --------------------------------------------------------------------------
296
297mpi2_sas.h
298 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
299 * 06-26-07 02.00.01 Added Clear All Persistent Operation to SAS IO Unit
300 * Control Request.
301 * 10-02-08 02.00.02 Added Set IOC Parameter Operation to SAS IO Unit Control
302 * Request.
303 * 10-28-09 02.00.03 Changed the type of SGL in MPI2_SATA_PASSTHROUGH_REQUEST
304 * to MPI2_SGE_IO_UNION since it supports chained SGLs.
305 * 05-12-10 02.00.04 Modified some comments.
306 * --------------------------------------------------------------------------
307
308mpi2_targ.h
309 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
310 * 08-31-07 02.00.01 Added Command Buffer Data Location Address Space bits to
311 * BufferPostFlags field of CommandBufferPostBase Request.
312 * 02-29-08 02.00.02 Modified various names to make them 32-character unique.
313 * 10-02-08 02.00.03 Removed NextCmdBufferOffset from
314 * MPI2_TARGET_CMD_BUF_POST_BASE_REQUEST.
315 * Target Status Send Request only takes a single SGE for
316 * response data.
317 * --------------------------------------------------------------------------
318
319mpi2_tool.h
320 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
321 * 12-18-07 02.00.01 Added Diagnostic Buffer Post and Diagnostic Release
322 * structures and defines.
323 * 02-29-08 02.00.02 Modified various names to make them 32-character unique.
324 * 05-06-09 02.00.03 Added ISTWI Read Write Tool and Diagnostic CLI Tool.
325 * 07-30-09 02.00.04 Added ExtendedType field to DiagnosticBufferPost request
326 * and reply messages.
327 * Added MPI2_DIAG_BUF_TYPE_EXTENDED.
328 * Incremented MPI2_DIAG_BUF_TYPE_COUNT.
329 * 05-12-10 02.00.05 Added Diagnostic Data Upload tool.
330 * --------------------------------------------------------------------------
331
332mpi2_type.h
333 * 04-30-07 02.00.00 Corresponds to Fusion-MPT MPI Specification Rev A.
334 * --------------------------------------------------------------------------
335
336mpi2_ra.h
337 * 05-06-09 02.00.00 Initial version.
338 * --------------------------------------------------------------------------
339
340mpi2_hbd.h
341 * 10-28-09 02.00.00 Initial version.
342 * --------------------------------------------------------------------------
343
344
345mpi2_history.txt Parts list history
346
347Filename 02.00.14 02.00.13 02.00.12
348---------- -------- -------- --------
349mpi2.h 02.00.14 02.00.13 02.00.12
350mpi2_cnfg.h 02.00.13 02.00.12 02.00.11
351mpi2_init.h 02.00.08 02.00.07 02.00.07
352mpi2_ioc.h 02.00.13 02.00.12 02.00.11
353mpi2_raid.h 02.00.04 02.00.04 02.00.03
354mpi2_sas.h 02.00.03 02.00.02 02.00.02
355mpi2_targ.h 02.00.03 02.00.03 02.00.03
356mpi2_tool.h 02.00.04 02.00.04 02.00.03
357mpi2_type.h 02.00.00 02.00.00 02.00.00
358mpi2_ra.h 02.00.00 02.00.00 02.00.00
359mpi2_hbd.h 02.00.00
360
361Filename 02.00.11 02.00.10 02.00.09 02.00.08 02.00.07 02.00.06
362---------- -------- -------- -------- -------- -------- --------
363mpi2.h 02.00.11 02.00.10 02.00.09 02.00.08 02.00.07 02.00.06
364mpi2_cnfg.h 02.00.10 02.00.09 02.00.08 02.00.07 02.00.06 02.00.06
365mpi2_init.h 02.00.06 02.00.06 02.00.05 02.00.05 02.00.04 02.00.03
366mpi2_ioc.h 02.00.10 02.00.09 02.00.08 02.00.07 02.00.07 02.00.06
367mpi2_raid.h 02.00.03 02.00.03 02.00.03 02.00.03 02.00.02 02.00.02
368mpi2_sas.h 02.00.02 02.00.02 02.00.01 02.00.01 02.00.01 02.00.01
369mpi2_targ.h 02.00.03 02.00.03 02.00.02 02.00.02 02.00.02 02.00.02
370mpi2_tool.h 02.00.02 02.00.02 02.00.02 02.00.02 02.00.02 02.00.02
371mpi2_type.h 02.00.00 02.00.00 02.00.00 02.00.00 02.00.00 02.00.00
372
373Filename 02.00.05 02.00.04 02.00.03 02.00.02 02.00.01 02.00.00
374---------- -------- -------- -------- -------- -------- --------
375mpi2.h 02.00.05 02.00.04 02.00.03 02.00.02 02.00.01 02.00.00
376mpi2_cnfg.h 02.00.05 02.00.04 02.00.03 02.00.02 02.00.01 02.00.00
377mpi2_init.h 02.00.02 02.00.01 02.00.00 02.00.00 02.00.00 02.00.00
378mpi2_ioc.h 02.00.05 02.00.04 02.00.03 02.00.02 02.00.01 02.00.00
379mpi2_raid.h 02.00.01 02.00.01 02.00.01 02.00.00 02.00.00 02.00.00
380mpi2_sas.h 02.00.01 02.00.01 02.00.01 02.00.01 02.00.00 02.00.00
381mpi2_targ.h 02.00.01 02.00.01 02.00.01 02.00.00 02.00.00 02.00.00
382mpi2_tool.h 02.00.01 02.00.00 02.00.00 02.00.00 02.00.00 02.00.00
383mpi2_type.h 02.00.00 02.00.00 02.00.00 02.00.00 02.00.00 02.00.00
384
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_sas.h b/drivers/scsi/mpt2sas/mpi/mpi2_sas.h
index 608f6d6e6fca..fdffde1ebc0f 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_sas.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_sas.h
@@ -6,7 +6,7 @@
6 * Title: MPI Serial Attached SCSI structures and definitions 6 * Title: MPI Serial Attached SCSI structures and definitions
7 * Creation Date: February 9, 2007 7 * Creation Date: February 9, 2007
8 * 8 *
9 * mpi2_sas.h Version: 02.00.04 9 * mpi2_sas.h Version: 02.00.05
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -21,6 +21,7 @@
21 * 10-28-09 02.00.03 Changed the type of SGL in MPI2_SATA_PASSTHROUGH_REQUEST 21 * 10-28-09 02.00.03 Changed the type of SGL in MPI2_SATA_PASSTHROUGH_REQUEST
22 * to MPI2_SGE_IO_UNION since it supports chained SGLs. 22 * to MPI2_SGE_IO_UNION since it supports chained SGLs.
23 * 05-12-10 02.00.04 Modified some comments. 23 * 05-12-10 02.00.04 Modified some comments.
24 * 08-11-10 02.00.05 Added NCQ operations to SAS IO Unit Control.
24 * -------------------------------------------------------------------------- 25 * --------------------------------------------------------------------------
25 */ 26 */
26 27
@@ -163,7 +164,7 @@ typedef struct _MPI2_SATA_PASSTHROUGH_REQUEST
163 U32 Reserved4; /* 0x14 */ 164 U32 Reserved4; /* 0x14 */
164 U32 DataLength; /* 0x18 */ 165 U32 DataLength; /* 0x18 */
165 U8 CommandFIS[20]; /* 0x1C */ 166 U8 CommandFIS[20]; /* 0x1C */
166 MPI2_SGE_IO_UNION SGL; /* 0x20 */ 167 MPI2_SGE_IO_UNION SGL; /* 0x30 */
167} MPI2_SATA_PASSTHROUGH_REQUEST, MPI2_POINTER PTR_MPI2_SATA_PASSTHROUGH_REQUEST, 168} MPI2_SATA_PASSTHROUGH_REQUEST, MPI2_POINTER PTR_MPI2_SATA_PASSTHROUGH_REQUEST,
168 Mpi2SataPassthroughRequest_t, MPI2_POINTER pMpi2SataPassthroughRequest_t; 169 Mpi2SataPassthroughRequest_t, MPI2_POINTER pMpi2SataPassthroughRequest_t;
169 170
@@ -246,6 +247,8 @@ typedef struct _MPI2_SAS_IOUNIT_CONTROL_REQUEST
246#define MPI2_SAS_OP_REMOVE_DEVICE (0x0D) 247#define MPI2_SAS_OP_REMOVE_DEVICE (0x0D)
247#define MPI2_SAS_OP_LOOKUP_MAPPING (0x0E) 248#define MPI2_SAS_OP_LOOKUP_MAPPING (0x0E)
248#define MPI2_SAS_OP_SET_IOC_PARAMETER (0x0F) 249#define MPI2_SAS_OP_SET_IOC_PARAMETER (0x0F)
250#define MPI2_SAS_OP_DEV_ENABLE_NCQ (0x14)
251#define MPI2_SAS_OP_DEV_DISABLE_NCQ (0x15)
249#define MPI2_SAS_OP_PRODUCT_SPECIFIC_MIN (0x80) 252#define MPI2_SAS_OP_PRODUCT_SPECIFIC_MIN (0x80)
250 253
251/* values for the PrimFlags field */ 254/* values for the PrimFlags field */
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_tool.h b/drivers/scsi/mpt2sas/mpi/mpi2_tool.h
index 5c6e3a67bb94..2a4bceda364b 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_tool.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_tool.h
@@ -6,7 +6,7 @@
6 * Title: MPI diagnostic tool structures and definitions 6 * Title: MPI diagnostic tool structures and definitions
7 * Creation Date: March 26, 2007 7 * Creation Date: March 26, 2007
8 * 8 *
9 * mpi2_tool.h Version: 02.00.05 9 * mpi2_tool.h Version: 02.00.06
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -23,6 +23,8 @@
23 * Added MPI2_DIAG_BUF_TYPE_EXTENDED. 23 * Added MPI2_DIAG_BUF_TYPE_EXTENDED.
24 * Incremented MPI2_DIAG_BUF_TYPE_COUNT. 24 * Incremented MPI2_DIAG_BUF_TYPE_COUNT.
25 * 05-12-10 02.00.05 Added Diagnostic Data Upload tool. 25 * 05-12-10 02.00.05 Added Diagnostic Data Upload tool.
26 * 08-11-10 02.00.06 Added defines that were missing for Diagnostic Buffer
27 * Post Request.
26 * -------------------------------------------------------------------------- 28 * --------------------------------------------------------------------------
27 */ 29 */
28 30
@@ -354,6 +356,10 @@ typedef struct _MPI2_DIAG_BUFFER_POST_REQUEST
354/* count of the number of buffer types */ 356/* count of the number of buffer types */
355#define MPI2_DIAG_BUF_TYPE_COUNT (0x03) 357#define MPI2_DIAG_BUF_TYPE_COUNT (0x03)
356 358
359/* values for the Flags field */
360#define MPI2_DIAG_BUF_FLAG_RELEASE_ON_FULL (0x00000002)
361#define MPI2_DIAG_BUF_FLAG_IMMEDIATE_RELEASE (0x00000001)
362
357 363
358/**************************************************************************** 364/****************************************************************************
359* Diagnostic Buffer Post reply 365* Diagnostic Buffer Post reply
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c b/drivers/scsi/mpt2sas/mpt2sas_base.c
index 9ead0399808a..e8a6f1cf1e4b 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
@@ -752,20 +752,19 @@ static u8
752_base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid) 752_base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
753{ 753{
754 int i; 754 int i;
755 u8 cb_idx = 0xFF; 755 u8 cb_idx;
756 756
757 if (smid >= ioc->hi_priority_smid) { 757 if (smid < ioc->hi_priority_smid) {
758 if (smid < ioc->internal_smid) {
759 i = smid - ioc->hi_priority_smid;
760 cb_idx = ioc->hpr_lookup[i].cb_idx;
761 } else if (smid <= ioc->hba_queue_depth) {
762 i = smid - ioc->internal_smid;
763 cb_idx = ioc->internal_lookup[i].cb_idx;
764 }
765 } else {
766 i = smid - 1; 758 i = smid - 1;
767 cb_idx = ioc->scsi_lookup[i].cb_idx; 759 cb_idx = ioc->scsi_lookup[i].cb_idx;
768 } 760 } else if (smid < ioc->internal_smid) {
761 i = smid - ioc->hi_priority_smid;
762 cb_idx = ioc->hpr_lookup[i].cb_idx;
763 } else if (smid <= ioc->hba_queue_depth) {
764 i = smid - ioc->internal_smid;
765 cb_idx = ioc->internal_lookup[i].cb_idx;
766 } else
767 cb_idx = 0xFF;
769 return cb_idx; 768 return cb_idx;
770} 769}
771 770
@@ -1430,7 +1429,7 @@ mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1430 struct scsi_cmnd *scmd) 1429 struct scsi_cmnd *scmd)
1431{ 1430{
1432 unsigned long flags; 1431 unsigned long flags;
1433 struct request_tracker *request; 1432 struct scsiio_tracker *request;
1434 u16 smid; 1433 u16 smid;
1435 1434
1436 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 1435 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
@@ -1442,7 +1441,7 @@ mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1442 } 1441 }
1443 1442
1444 request = list_entry(ioc->free_list.next, 1443 request = list_entry(ioc->free_list.next,
1445 struct request_tracker, tracker_list); 1444 struct scsiio_tracker, tracker_list);
1446 request->scmd = scmd; 1445 request->scmd = scmd;
1447 request->cb_idx = cb_idx; 1446 request->cb_idx = cb_idx;
1448 smid = request->smid; 1447 smid = request->smid;
@@ -1496,48 +1495,47 @@ mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1496 struct chain_tracker *chain_req, *next; 1495 struct chain_tracker *chain_req, *next;
1497 1496
1498 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 1497 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1499 if (smid >= ioc->hi_priority_smid) { 1498 if (smid < ioc->hi_priority_smid) {
1500 if (smid < ioc->internal_smid) { 1499 /* scsiio queue */
1501 /* hi-priority */ 1500 i = smid - 1;
1502 i = smid - ioc->hi_priority_smid; 1501 if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
1503 ioc->hpr_lookup[i].cb_idx = 0xFF; 1502 list_for_each_entry_safe(chain_req, next,
1504 list_add_tail(&ioc->hpr_lookup[i].tracker_list, 1503 &ioc->scsi_lookup[i].chain_list, tracker_list) {
1505 &ioc->hpr_free_list); 1504 list_del_init(&chain_req->tracker_list);
1506 } else { 1505 list_add_tail(&chain_req->tracker_list,
1507 /* internal queue */ 1506 &ioc->free_chain_list);
1508 i = smid - ioc->internal_smid; 1507 }
1509 ioc->internal_lookup[i].cb_idx = 0xFF;
1510 list_add_tail(&ioc->internal_lookup[i].tracker_list,
1511 &ioc->internal_free_list);
1512 } 1508 }
1509 ioc->scsi_lookup[i].cb_idx = 0xFF;
1510 ioc->scsi_lookup[i].scmd = NULL;
1511 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
1512 &ioc->free_list);
1513 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 1513 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1514 return;
1515 }
1516 1514
1517 /* scsiio queue */ 1515 /*
1518 i = smid - 1; 1516 * See _wait_for_commands_to_complete() call with regards
1519 if (!list_empty(&ioc->scsi_lookup[i].chain_list)) { 1517 * to this code.
1520 list_for_each_entry_safe(chain_req, next, 1518 */
1521 &ioc->scsi_lookup[i].chain_list, tracker_list) { 1519 if (ioc->shost_recovery && ioc->pending_io_count) {
1522 list_del_init(&chain_req->tracker_list); 1520 if (ioc->pending_io_count == 1)
1523 list_add_tail(&chain_req->tracker_list, 1521 wake_up(&ioc->reset_wq);
1524 &ioc->free_chain_list); 1522 ioc->pending_io_count--;
1525 } 1523 }
1524 return;
1525 } else if (smid < ioc->internal_smid) {
1526 /* hi-priority */
1527 i = smid - ioc->hi_priority_smid;
1528 ioc->hpr_lookup[i].cb_idx = 0xFF;
1529 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
1530 &ioc->hpr_free_list);
1531 } else if (smid <= ioc->hba_queue_depth) {
1532 /* internal queue */
1533 i = smid - ioc->internal_smid;
1534 ioc->internal_lookup[i].cb_idx = 0xFF;
1535 list_add_tail(&ioc->internal_lookup[i].tracker_list,
1536 &ioc->internal_free_list);
1526 } 1537 }
1527 ioc->scsi_lookup[i].cb_idx = 0xFF;
1528 ioc->scsi_lookup[i].scmd = NULL;
1529 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
1530 &ioc->free_list);
1531 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 1538 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1532
1533 /*
1534 * See _wait_for_commands_to_complete() call with regards to this code.
1535 */
1536 if (ioc->shost_recovery && ioc->pending_io_count) {
1537 if (ioc->pending_io_count == 1)
1538 wake_up(&ioc->reset_wq);
1539 ioc->pending_io_count--;
1540 }
1541} 1539}
1542 1540
1543/** 1541/**
@@ -1725,6 +1723,31 @@ _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
1725} 1723}
1726 1724
1727/** 1725/**
1726 * _base_display_intel_branding - Display branding string
1727 * @ioc: per adapter object
1728 *
1729 * Return nothing.
1730 */
1731static void
1732_base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc)
1733{
1734 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_INTEL &&
1735 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008) {
1736
1737 switch (ioc->pdev->subsystem_device) {
1738 case MPT2SAS_INTEL_RMS2LL080_SSDID:
1739 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1740 MPT2SAS_INTEL_RMS2LL080_BRANDING);
1741 break;
1742 case MPT2SAS_INTEL_RMS2LL040_SSDID:
1743 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1744 MPT2SAS_INTEL_RMS2LL040_BRANDING);
1745 break;
1746 }
1747 }
1748}
1749
1750/**
1728 * _base_display_ioc_capabilities - Disply IOC's capabilities. 1751 * _base_display_ioc_capabilities - Disply IOC's capabilities.
1729 * @ioc: per adapter object 1752 * @ioc: per adapter object
1730 * 1753 *
@@ -1754,6 +1777,7 @@ _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
1754 ioc->bios_pg3.BiosVersion & 0x000000FF); 1777 ioc->bios_pg3.BiosVersion & 0x000000FF);
1755 1778
1756 _base_display_dell_branding(ioc); 1779 _base_display_dell_branding(ioc);
1780 _base_display_intel_branding(ioc);
1757 1781
1758 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name); 1782 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
1759 1783
@@ -2252,9 +2276,9 @@ _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2252 ioc->name, (unsigned long long) ioc->request_dma)); 2276 ioc->name, (unsigned long long) ioc->request_dma));
2253 total_sz += sz; 2277 total_sz += sz;
2254 2278
2255 sz = ioc->scsiio_depth * sizeof(struct request_tracker); 2279 sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
2256 ioc->scsi_lookup_pages = get_order(sz); 2280 ioc->scsi_lookup_pages = get_order(sz);
2257 ioc->scsi_lookup = (struct request_tracker *)__get_free_pages( 2281 ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
2258 GFP_KERNEL, ioc->scsi_lookup_pages); 2282 GFP_KERNEL, ioc->scsi_lookup_pages);
2259 if (!ioc->scsi_lookup) { 2283 if (!ioc->scsi_lookup) {
2260 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, " 2284 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h
index 283568c6fb04..a3f8aa9baea4 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.h
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.h
@@ -69,8 +69,8 @@
69#define MPT2SAS_DRIVER_NAME "mpt2sas" 69#define MPT2SAS_DRIVER_NAME "mpt2sas"
70#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>" 70#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>"
71#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver" 71#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver"
72#define MPT2SAS_DRIVER_VERSION "07.100.00.00" 72#define MPT2SAS_DRIVER_VERSION "08.100.00.00"
73#define MPT2SAS_MAJOR_VERSION 07 73#define MPT2SAS_MAJOR_VERSION 08
74#define MPT2SAS_MINOR_VERSION 100 74#define MPT2SAS_MINOR_VERSION 100
75#define MPT2SAS_BUILD_VERSION 00 75#define MPT2SAS_BUILD_VERSION 00
76#define MPT2SAS_RELEASE_VERSION 00 76#define MPT2SAS_RELEASE_VERSION 00
@@ -101,7 +101,8 @@
101#define MPT_NAME_LENGTH 32 /* generic length of strings */ 101#define MPT_NAME_LENGTH 32 /* generic length of strings */
102#define MPT_STRING_LENGTH 64 102#define MPT_STRING_LENGTH 64
103 103
104#define MPT_MAX_CALLBACKS 16 104#define MPT_MAX_CALLBACKS 16
105
105 106
106#define CAN_SLEEP 1 107#define CAN_SLEEP 1
107#define NO_SLEEP 0 108#define NO_SLEEP 0
@@ -154,6 +155,20 @@
154#define MPT2SAS_DELL_6GBPS_SAS_SSDID 0x1F22 155#define MPT2SAS_DELL_6GBPS_SAS_SSDID 0x1F22
155 156
156/* 157/*
158 * Intel HBA branding
159 */
160#define MPT2SAS_INTEL_RMS2LL080_BRANDING \
161 "Intel Integrated RAID Module RMS2LL080"
162#define MPT2SAS_INTEL_RMS2LL040_BRANDING \
163 "Intel Integrated RAID Module RMS2LL040"
164
165/*
166 * Intel HBA SSDIDs
167 */
168#define MPT2SAS_INTEL_RMS2LL080_SSDID 0x350E
169#define MPT2SAS_INTEL_RMS2LL040_SSDID 0x350F
170
171/*
157 * per target private data 172 * per target private data
158 */ 173 */
159#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01 174#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01
@@ -431,14 +446,14 @@ struct chain_tracker {
431}; 446};
432 447
433/** 448/**
434 * struct request_tracker - firmware request tracker 449 * struct scsiio_tracker - scsi mf request tracker
435 * @smid: system message id 450 * @smid: system message id
436 * @scmd: scsi request pointer 451 * @scmd: scsi request pointer
437 * @cb_idx: callback index 452 * @cb_idx: callback index
438 * @chain_list: list of chains associated to this IO 453 * @chain_list: list of chains associated to this IO
439 * @tracker_list: list of free request (ioc->free_list) 454 * @tracker_list: list of free request (ioc->free_list)
440 */ 455 */
441struct request_tracker { 456struct scsiio_tracker {
442 u16 smid; 457 u16 smid;
443 struct scsi_cmnd *scmd; 458 struct scsi_cmnd *scmd;
444 u8 cb_idx; 459 u8 cb_idx;
@@ -447,6 +462,19 @@ struct request_tracker {
447}; 462};
448 463
449/** 464/**
465 * struct request_tracker - misc mf request tracker
466 * @smid: system message id
467 * @scmd: scsi request pointer
468 * @cb_idx: callback index
469 * @tracker_list: list of free request (ioc->free_list)
470 */
471struct request_tracker {
472 u16 smid;
473 u8 cb_idx;
474 struct list_head tracker_list;
475};
476
477/**
450 * struct _tr_list - target reset list 478 * struct _tr_list - target reset list
451 * @handle: device handle 479 * @handle: device handle
452 * @state: state machine 480 * @state: state machine
@@ -709,7 +737,7 @@ struct MPT2SAS_ADAPTER {
709 u8 *request; 737 u8 *request;
710 dma_addr_t request_dma; 738 dma_addr_t request_dma;
711 u32 request_dma_sz; 739 u32 request_dma_sz;
712 struct request_tracker *scsi_lookup; 740 struct scsiio_tracker *scsi_lookup;
713 ulong scsi_lookup_pages; 741 ulong scsi_lookup_pages;
714 spinlock_t scsi_lookup_lock; 742 spinlock_t scsi_lookup_lock;
715 struct list_head free_list; 743 struct list_head free_list;
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index 5ded3db6e316..6ceb7759bfe5 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -6975,7 +6975,6 @@ _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
6975 u32 device_state; 6975 u32 device_state;
6976 6976
6977 mpt2sas_base_stop_watchdog(ioc); 6977 mpt2sas_base_stop_watchdog(ioc);
6978 flush_scheduled_work();
6979 scsi_block_requests(shost); 6978 scsi_block_requests(shost);
6980 device_state = pci_choose_state(pdev, state); 6979 device_state = pci_choose_state(pdev, state);
6981 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering " 6980 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
index b37c8a3c1bb0..86afb13f1e79 100644
--- a/drivers/scsi/osd/osd_initiator.c
+++ b/drivers/scsi/osd/osd_initiator.c
@@ -1005,11 +1005,23 @@ int osd_req_read_sg(struct osd_request *or,
1005 const struct osd_sg_entry *sglist, unsigned numentries) 1005 const struct osd_sg_entry *sglist, unsigned numentries)
1006{ 1006{
1007 u64 len; 1007 u64 len;
1008 int ret = _add_sg_continuation_descriptor(or, sglist, numentries, &len); 1008 u64 off;
1009 int ret;
1009 1010
1010 if (ret) 1011 if (numentries > 1) {
1011 return ret; 1012 off = 0;
1012 osd_req_read(or, obj, 0, bio, len); 1013 ret = _add_sg_continuation_descriptor(or, sglist, numentries,
1014 &len);
1015 if (ret)
1016 return ret;
1017 } else {
1018 /* Optimize the case of single segment, read_sg is a
1019 * bidi operation.
1020 */
1021 len = sglist->len;
1022 off = sglist->offset;
1023 }
1024 osd_req_read(or, obj, off, bio, len);
1013 1025
1014 return 0; 1026 return 0;
1015} 1027}
diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index d8db0137c0c7..18b6c55cd08c 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -1382,53 +1382,50 @@ static u32 mpi_msg_consume(struct pm8001_hba_info *pm8001_ha,
1382 return MPI_IO_STATUS_BUSY; 1382 return MPI_IO_STATUS_BUSY;
1383} 1383}
1384 1384
1385static void pm8001_work_queue(struct work_struct *work) 1385static void pm8001_work_fn(struct work_struct *work)
1386{ 1386{
1387 struct delayed_work *dw = container_of(work, struct delayed_work, work); 1387 struct pm8001_work *pw = container_of(work, struct pm8001_work, work);
1388 struct pm8001_wq *wq = container_of(dw, struct pm8001_wq, work_q);
1389 struct pm8001_device *pm8001_dev; 1388 struct pm8001_device *pm8001_dev;
1390 struct domain_device *dev; 1389 struct domain_device *dev;
1391 1390
1392 switch (wq->handler) { 1391 switch (pw->handler) {
1393 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: 1392 case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
1394 pm8001_dev = wq->data; 1393 pm8001_dev = pw->data;
1395 dev = pm8001_dev->sas_device; 1394 dev = pm8001_dev->sas_device;
1396 pm8001_I_T_nexus_reset(dev); 1395 pm8001_I_T_nexus_reset(dev);
1397 break; 1396 break;
1398 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY: 1397 case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
1399 pm8001_dev = wq->data; 1398 pm8001_dev = pw->data;
1400 dev = pm8001_dev->sas_device; 1399 dev = pm8001_dev->sas_device;
1401 pm8001_I_T_nexus_reset(dev); 1400 pm8001_I_T_nexus_reset(dev);
1402 break; 1401 break;
1403 case IO_DS_IN_ERROR: 1402 case IO_DS_IN_ERROR:
1404 pm8001_dev = wq->data; 1403 pm8001_dev = pw->data;
1405 dev = pm8001_dev->sas_device; 1404 dev = pm8001_dev->sas_device;
1406 pm8001_I_T_nexus_reset(dev); 1405 pm8001_I_T_nexus_reset(dev);
1407 break; 1406 break;
1408 case IO_DS_NON_OPERATIONAL: 1407 case IO_DS_NON_OPERATIONAL:
1409 pm8001_dev = wq->data; 1408 pm8001_dev = pw->data;
1410 dev = pm8001_dev->sas_device; 1409 dev = pm8001_dev->sas_device;
1411 pm8001_I_T_nexus_reset(dev); 1410 pm8001_I_T_nexus_reset(dev);
1412 break; 1411 break;
1413 } 1412 }
1414 list_del(&wq->entry); 1413 kfree(pw);
1415 kfree(wq);
1416} 1414}
1417 1415
1418static int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data, 1416static int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data,
1419 int handler) 1417 int handler)
1420{ 1418{
1421 struct pm8001_wq *wq; 1419 struct pm8001_work *pw;
1422 int ret = 0; 1420 int ret = 0;
1423 1421
1424 wq = kmalloc(sizeof(struct pm8001_wq), GFP_ATOMIC); 1422 pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC);
1425 if (wq) { 1423 if (pw) {
1426 wq->pm8001_ha = pm8001_ha; 1424 pw->pm8001_ha = pm8001_ha;
1427 wq->data = data; 1425 pw->data = data;
1428 wq->handler = handler; 1426 pw->handler = handler;
1429 INIT_DELAYED_WORK(&wq->work_q, pm8001_work_queue); 1427 INIT_WORK(&pw->work, pm8001_work_fn);
1430 list_add_tail(&wq->entry, &pm8001_ha->wq_list); 1428 queue_work(pm8001_wq, &pw->work);
1431 schedule_delayed_work(&wq->work_q, 0);
1432 } else 1429 } else
1433 ret = -ENOMEM; 1430 ret = -ENOMEM;
1434 1431
diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index b95285f3383f..002360da01e3 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -51,6 +51,8 @@ static int pm8001_id;
51 51
52LIST_HEAD(hba_list); 52LIST_HEAD(hba_list);
53 53
54struct workqueue_struct *pm8001_wq;
55
54/** 56/**
55 * The main structure which LLDD must register for scsi core. 57 * The main structure which LLDD must register for scsi core.
56 */ 58 */
@@ -134,7 +136,6 @@ static void __devinit pm8001_phy_init(struct pm8001_hba_info *pm8001_ha,
134static void pm8001_free(struct pm8001_hba_info *pm8001_ha) 136static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
135{ 137{
136 int i; 138 int i;
137 struct pm8001_wq *wq;
138 139
139 if (!pm8001_ha) 140 if (!pm8001_ha)
140 return; 141 return;
@@ -150,8 +151,7 @@ static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
150 PM8001_CHIP_DISP->chip_iounmap(pm8001_ha); 151 PM8001_CHIP_DISP->chip_iounmap(pm8001_ha);
151 if (pm8001_ha->shost) 152 if (pm8001_ha->shost)
152 scsi_host_put(pm8001_ha->shost); 153 scsi_host_put(pm8001_ha->shost);
153 list_for_each_entry(wq, &pm8001_ha->wq_list, entry) 154 flush_workqueue(pm8001_wq);
154 cancel_delayed_work(&wq->work_q);
155 kfree(pm8001_ha->tags); 155 kfree(pm8001_ha->tags);
156 kfree(pm8001_ha); 156 kfree(pm8001_ha);
157} 157}
@@ -381,7 +381,6 @@ pm8001_pci_alloc(struct pci_dev *pdev, u32 chip_id, struct Scsi_Host *shost)
381 pm8001_ha->sas = sha; 381 pm8001_ha->sas = sha;
382 pm8001_ha->shost = shost; 382 pm8001_ha->shost = shost;
383 pm8001_ha->id = pm8001_id++; 383 pm8001_ha->id = pm8001_id++;
384 INIT_LIST_HEAD(&pm8001_ha->wq_list);
385 pm8001_ha->logging_level = 0x01; 384 pm8001_ha->logging_level = 0x01;
386 sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id); 385 sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
387#ifdef PM8001_USE_TASKLET 386#ifdef PM8001_USE_TASKLET
@@ -758,7 +757,7 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
758 int i , pos; 757 int i , pos;
759 u32 device_state; 758 u32 device_state;
760 pm8001_ha = sha->lldd_ha; 759 pm8001_ha = sha->lldd_ha;
761 flush_scheduled_work(); 760 flush_workqueue(pm8001_wq);
762 scsi_block_requests(pm8001_ha->shost); 761 scsi_block_requests(pm8001_ha->shost);
763 pos = pci_find_capability(pdev, PCI_CAP_ID_PM); 762 pos = pci_find_capability(pdev, PCI_CAP_ID_PM);
764 if (pos == 0) { 763 if (pos == 0) {
@@ -870,17 +869,26 @@ static struct pci_driver pm8001_pci_driver = {
870 */ 869 */
871static int __init pm8001_init(void) 870static int __init pm8001_init(void)
872{ 871{
873 int rc; 872 int rc = -ENOMEM;
873
874 pm8001_wq = alloc_workqueue("pm8001", 0, 0);
875 if (!pm8001_wq)
876 goto err;
877
874 pm8001_id = 0; 878 pm8001_id = 0;
875 pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops); 879 pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
876 if (!pm8001_stt) 880 if (!pm8001_stt)
877 return -ENOMEM; 881 goto err_wq;
878 rc = pci_register_driver(&pm8001_pci_driver); 882 rc = pci_register_driver(&pm8001_pci_driver);
879 if (rc) 883 if (rc)
880 goto err_out; 884 goto err_tp;
881 return 0; 885 return 0;
882err_out: 886
887err_tp:
883 sas_release_transport(pm8001_stt); 888 sas_release_transport(pm8001_stt);
889err_wq:
890 destroy_workqueue(pm8001_wq);
891err:
884 return rc; 892 return rc;
885} 893}
886 894
@@ -888,6 +896,7 @@ static void __exit pm8001_exit(void)
888{ 896{
889 pci_unregister_driver(&pm8001_pci_driver); 897 pci_unregister_driver(&pm8001_pci_driver);
890 sas_release_transport(pm8001_stt); 898 sas_release_transport(pm8001_stt);
899 destroy_workqueue(pm8001_wq);
891} 900}
892 901
893module_init(pm8001_init); 902module_init(pm8001_init);
diff --git a/drivers/scsi/pm8001/pm8001_sas.h b/drivers/scsi/pm8001/pm8001_sas.h
index 7f064f9ca828..bdb6b27dedd6 100644
--- a/drivers/scsi/pm8001/pm8001_sas.h
+++ b/drivers/scsi/pm8001/pm8001_sas.h
@@ -50,6 +50,7 @@
50#include <linux/dma-mapping.h> 50#include <linux/dma-mapping.h>
51#include <linux/pci.h> 51#include <linux/pci.h>
52#include <linux/interrupt.h> 52#include <linux/interrupt.h>
53#include <linux/workqueue.h>
53#include <scsi/libsas.h> 54#include <scsi/libsas.h>
54#include <scsi/scsi_tcq.h> 55#include <scsi/scsi_tcq.h>
55#include <scsi/sas_ata.h> 56#include <scsi/sas_ata.h>
@@ -379,18 +380,16 @@ struct pm8001_hba_info {
379#ifdef PM8001_USE_TASKLET 380#ifdef PM8001_USE_TASKLET
380 struct tasklet_struct tasklet; 381 struct tasklet_struct tasklet;
381#endif 382#endif
382 struct list_head wq_list;
383 u32 logging_level; 383 u32 logging_level;
384 u32 fw_status; 384 u32 fw_status;
385 const struct firmware *fw_image; 385 const struct firmware *fw_image;
386}; 386};
387 387
388struct pm8001_wq { 388struct pm8001_work {
389 struct delayed_work work_q; 389 struct work_struct work;
390 struct pm8001_hba_info *pm8001_ha; 390 struct pm8001_hba_info *pm8001_ha;
391 void *data; 391 void *data;
392 int handler; 392 int handler;
393 struct list_head entry;
394}; 393};
395 394
396struct pm8001_fw_image_header { 395struct pm8001_fw_image_header {
@@ -460,6 +459,9 @@ struct fw_control_ex {
460 void *param3; 459 void *param3;
461}; 460};
462 461
462/* pm8001 workqueue */
463extern struct workqueue_struct *pm8001_wq;
464
463/******************** function prototype *********************/ 465/******************** function prototype *********************/
464int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out); 466int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out);
465void pm8001_tag_init(struct pm8001_hba_info *pm8001_ha); 467void pm8001_tag_init(struct pm8001_hba_info *pm8001_ha);
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 321cf3ae8630..bcf858e88c64 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -5454,7 +5454,7 @@ static void __devexit pmcraid_remove(struct pci_dev *pdev)
5454 pmcraid_shutdown(pdev); 5454 pmcraid_shutdown(pdev);
5455 5455
5456 pmcraid_disable_interrupts(pinstance, ~0); 5456 pmcraid_disable_interrupts(pinstance, ~0);
5457 flush_scheduled_work(); 5457 flush_work_sync(&pinstance->worker_q);
5458 5458
5459 pmcraid_kill_tasklets(pinstance); 5459 pmcraid_kill_tasklets(pinstance);
5460 pmcraid_unregister_interrupt_handler(pinstance); 5460 pmcraid_unregister_interrupt_handler(pinstance);
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index ccfc8e78be21..6c51c0a35b9e 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2402,13 +2402,13 @@ struct qla_hw_data {
2402 volatile struct { 2402 volatile struct {
2403 uint32_t mbox_int :1; 2403 uint32_t mbox_int :1;
2404 uint32_t mbox_busy :1; 2404 uint32_t mbox_busy :1;
2405
2406 uint32_t disable_risc_code_load :1; 2405 uint32_t disable_risc_code_load :1;
2407 uint32_t enable_64bit_addressing :1; 2406 uint32_t enable_64bit_addressing :1;
2408 uint32_t enable_lip_reset :1; 2407 uint32_t enable_lip_reset :1;
2409 uint32_t enable_target_reset :1; 2408 uint32_t enable_target_reset :1;
2410 uint32_t enable_lip_full_login :1; 2409 uint32_t enable_lip_full_login :1;
2411 uint32_t enable_led_scheme :1; 2410 uint32_t enable_led_scheme :1;
2411
2412 uint32_t msi_enabled :1; 2412 uint32_t msi_enabled :1;
2413 uint32_t msix_enabled :1; 2413 uint32_t msix_enabled :1;
2414 uint32_t disable_serdes :1; 2414 uint32_t disable_serdes :1;
@@ -2417,6 +2417,7 @@ struct qla_hw_data {
2417 uint32_t pci_channel_io_perm_failure :1; 2417 uint32_t pci_channel_io_perm_failure :1;
2418 uint32_t fce_enabled :1; 2418 uint32_t fce_enabled :1;
2419 uint32_t fac_supported :1; 2419 uint32_t fac_supported :1;
2420
2420 uint32_t chip_reset_done :1; 2421 uint32_t chip_reset_done :1;
2421 uint32_t port0 :1; 2422 uint32_t port0 :1;
2422 uint32_t running_gold_fw :1; 2423 uint32_t running_gold_fw :1;
@@ -2424,9 +2425,11 @@ struct qla_hw_data {
2424 uint32_t cpu_affinity_enabled :1; 2425 uint32_t cpu_affinity_enabled :1;
2425 uint32_t disable_msix_handshake :1; 2426 uint32_t disable_msix_handshake :1;
2426 uint32_t fcp_prio_enabled :1; 2427 uint32_t fcp_prio_enabled :1;
2427 uint32_t fw_hung :1; 2428 uint32_t isp82xx_fw_hung:1;
2428 uint32_t quiesce_owner:1; 2429
2430 uint32_t quiesce_owner:1;
2429 uint32_t thermal_supported:1; 2431 uint32_t thermal_supported:1;
2432 uint32_t isp82xx_reset_hdlr_active:1;
2430 /* 26 bits */ 2433 /* 26 bits */
2431 } flags; 2434 } flags;
2432 2435
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 89e900adb679..d48326ee3f61 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -565,6 +565,7 @@ extern int qla82xx_mbx_intr_enable(scsi_qla_host_t *);
565extern int qla82xx_mbx_intr_disable(scsi_qla_host_t *); 565extern int qla82xx_mbx_intr_disable(scsi_qla_host_t *);
566extern void qla82xx_start_iocbs(srb_t *); 566extern void qla82xx_start_iocbs(srb_t *);
567extern int qla82xx_fcoe_ctx_reset(scsi_qla_host_t *); 567extern int qla82xx_fcoe_ctx_reset(scsi_qla_host_t *);
568extern void qla82xx_chip_reset_cleanup(scsi_qla_host_t *);
568 569
569/* BSG related functions */ 570/* BSG related functions */
570extern int qla24xx_bsg_request(struct fc_bsg_job *); 571extern int qla24xx_bsg_request(struct fc_bsg_job *);
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 4c083928c2fb..74a91b6dfc68 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -121,8 +121,11 @@ qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
121 121
122 rval = QLA_FUNCTION_FAILED; 122 rval = QLA_FUNCTION_FAILED;
123 if (ms_pkt->entry_status != 0) { 123 if (ms_pkt->entry_status != 0) {
124 DEBUG2_3(printk("scsi(%ld): %s failed, error status (%x).\n", 124 DEBUG2_3(printk(KERN_WARNING "scsi(%ld): %s failed, error status "
125 vha->host_no, routine, ms_pkt->entry_status)); 125 "(%x) on port_id: %02x%02x%02x.\n",
126 vha->host_no, routine, ms_pkt->entry_status,
127 vha->d_id.b.domain, vha->d_id.b.area,
128 vha->d_id.b.al_pa));
126 } else { 129 } else {
127 if (IS_FWI2_CAPABLE(ha)) 130 if (IS_FWI2_CAPABLE(ha))
128 comp_status = le16_to_cpu( 131 comp_status = le16_to_cpu(
@@ -136,8 +139,10 @@ qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
136 if (ct_rsp->header.response != 139 if (ct_rsp->header.response !=
137 __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) { 140 __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
138 DEBUG2_3(printk("scsi(%ld): %s failed, " 141 DEBUG2_3(printk("scsi(%ld): %s failed, "
139 "rejected request:\n", vha->host_no, 142 "rejected request on port_id: %02x%02x%02x\n",
140 routine)); 143 vha->host_no, routine,
144 vha->d_id.b.domain, vha->d_id.b.area,
145 vha->d_id.b.al_pa));
141 DEBUG2_3(qla2x00_dump_buffer( 146 DEBUG2_3(qla2x00_dump_buffer(
142 (uint8_t *)&ct_rsp->header, 147 (uint8_t *)&ct_rsp->header,
143 sizeof(struct ct_rsp_hdr))); 148 sizeof(struct ct_rsp_hdr)));
@@ -147,8 +152,10 @@ qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
147 break; 152 break;
148 default: 153 default:
149 DEBUG2_3(printk("scsi(%ld): %s failed, completion " 154 DEBUG2_3(printk("scsi(%ld): %s failed, completion "
150 "status (%x).\n", vha->host_no, routine, 155 "status (%x) on port_id: %02x%02x%02x.\n",
151 comp_status)); 156 vha->host_no, routine, comp_status,
157 vha->d_id.b.domain, vha->d_id.b.area,
158 vha->d_id.b.al_pa));
152 break; 159 break;
153 } 160 }
154 } 161 }
@@ -1965,7 +1972,7 @@ qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
1965 "scsi(%ld): GFF_ID issue IOCB failed " 1972 "scsi(%ld): GFF_ID issue IOCB failed "
1966 "(%d).\n", vha->host_no, rval)); 1973 "(%d).\n", vha->host_no, rval));
1967 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, 1974 } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
1968 "GPN_ID") != QLA_SUCCESS) { 1975 "GFF_ID") != QLA_SUCCESS) {
1969 DEBUG2_3(printk(KERN_INFO 1976 DEBUG2_3(printk(KERN_INFO
1970 "scsi(%ld): GFF_ID IOCB status had a " 1977 "scsi(%ld): GFF_ID IOCB status had a "
1971 "failure status code\n", vha->host_no)); 1978 "failure status code\n", vha->host_no));
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index d9479c3fe5f8..8575808dbae0 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -1967,7 +1967,7 @@ qla2x00_fw_ready(scsi_qla_host_t *vha)
1967 } else { 1967 } else {
1968 /* Mailbox cmd failed. Timeout on min_wait. */ 1968 /* Mailbox cmd failed. Timeout on min_wait. */
1969 if (time_after_eq(jiffies, mtime) || 1969 if (time_after_eq(jiffies, mtime) ||
1970 (IS_QLA82XX(ha) && ha->flags.fw_hung)) 1970 ha->flags.isp82xx_fw_hung)
1971 break; 1971 break;
1972 } 1972 }
1973 1973
@@ -3945,8 +3945,13 @@ qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3945 struct qla_hw_data *ha = vha->hw; 3945 struct qla_hw_data *ha = vha->hw;
3946 struct scsi_qla_host *vp; 3946 struct scsi_qla_host *vp;
3947 unsigned long flags; 3947 unsigned long flags;
3948 fc_port_t *fcport;
3948 3949
3949 vha->flags.online = 0; 3950 /* For ISP82XX, driver waits for completion of the commands.
3951 * online flag should be set.
3952 */
3953 if (!IS_QLA82XX(ha))
3954 vha->flags.online = 0;
3950 ha->flags.chip_reset_done = 0; 3955 ha->flags.chip_reset_done = 0;
3951 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); 3956 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3952 ha->qla_stats.total_isp_aborts++; 3957 ha->qla_stats.total_isp_aborts++;
@@ -3954,7 +3959,10 @@ qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3954 qla_printk(KERN_INFO, ha, 3959 qla_printk(KERN_INFO, ha,
3955 "Performing ISP error recovery - ha= %p.\n", ha); 3960 "Performing ISP error recovery - ha= %p.\n", ha);
3956 3961
3957 /* Chip reset does not apply to 82XX */ 3962 /* For ISP82XX, reset_chip is just disabling interrupts.
3963 * Driver waits for the completion of the commands.
3964 * the interrupts need to be enabled.
3965 */
3958 if (!IS_QLA82XX(ha)) 3966 if (!IS_QLA82XX(ha))
3959 ha->isp_ops->reset_chip(vha); 3967 ha->isp_ops->reset_chip(vha);
3960 3968
@@ -3980,14 +3988,31 @@ qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3980 LOOP_DOWN_TIME); 3988 LOOP_DOWN_TIME);
3981 } 3989 }
3982 3990
3991 /* Clear all async request states across all VPs. */
3992 list_for_each_entry(fcport, &vha->vp_fcports, list)
3993 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3994 spin_lock_irqsave(&ha->vport_slock, flags);
3995 list_for_each_entry(vp, &ha->vp_list, list) {
3996 atomic_inc(&vp->vref_count);
3997 spin_unlock_irqrestore(&ha->vport_slock, flags);
3998
3999 list_for_each_entry(fcport, &vp->vp_fcports, list)
4000 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4001
4002 spin_lock_irqsave(&ha->vport_slock, flags);
4003 atomic_dec(&vp->vref_count);
4004 }
4005 spin_unlock_irqrestore(&ha->vport_slock, flags);
4006
3983 if (!ha->flags.eeh_busy) { 4007 if (!ha->flags.eeh_busy) {
3984 /* Make sure for ISP 82XX IO DMA is complete */ 4008 /* Make sure for ISP 82XX IO DMA is complete */
3985 if (IS_QLA82XX(ha)) { 4009 if (IS_QLA82XX(ha)) {
3986 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, 4010 qla82xx_chip_reset_cleanup(vha);
3987 WAIT_HOST) == QLA_SUCCESS) { 4011
3988 DEBUG2(qla_printk(KERN_INFO, ha, 4012 /* Done waiting for pending commands.
3989 "Done wait for pending commands\n")); 4013 * Reset the online flag.
3990 } 4014 */
4015 vha->flags.online = 0;
3991 } 4016 }
3992 4017
3993 /* Requeue all commands in outstanding command list. */ 4018 /* Requeue all commands in outstanding command list. */
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index 4c1ba6263eb3..d78d5896fc33 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -328,6 +328,7 @@ qla2x00_start_scsi(srb_t *sp)
328 struct qla_hw_data *ha; 328 struct qla_hw_data *ha;
329 struct req_que *req; 329 struct req_que *req;
330 struct rsp_que *rsp; 330 struct rsp_que *rsp;
331 char tag[2];
331 332
332 /* Setup device pointers. */ 333 /* Setup device pointers. */
333 ret = 0; 334 ret = 0;
@@ -406,7 +407,22 @@ qla2x00_start_scsi(srb_t *sp)
406 cmd_pkt->lun = cpu_to_le16(sp->cmd->device->lun); 407 cmd_pkt->lun = cpu_to_le16(sp->cmd->device->lun);
407 408
408 /* Update tagged queuing modifier */ 409 /* Update tagged queuing modifier */
409 cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG); 410 if (scsi_populate_tag_msg(cmd, tag)) {
411 switch (tag[0]) {
412 case HEAD_OF_QUEUE_TAG:
413 cmd_pkt->control_flags =
414 __constant_cpu_to_le16(CF_HEAD_TAG);
415 break;
416 case ORDERED_QUEUE_TAG:
417 cmd_pkt->control_flags =
418 __constant_cpu_to_le16(CF_ORDERED_TAG);
419 break;
420 default:
421 cmd_pkt->control_flags =
422 __constant_cpu_to_le16(CF_SIMPLE_TAG);
423 break;
424 }
425 }
410 426
411 /* Load SCSI command packet. */ 427 /* Load SCSI command packet. */
412 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); 428 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
@@ -971,6 +987,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
971 uint16_t fcp_cmnd_len; 987 uint16_t fcp_cmnd_len;
972 struct fcp_cmnd *fcp_cmnd; 988 struct fcp_cmnd *fcp_cmnd;
973 dma_addr_t crc_ctx_dma; 989 dma_addr_t crc_ctx_dma;
990 char tag[2];
974 991
975 cmd = sp->cmd; 992 cmd = sp->cmd;
976 993
@@ -1068,9 +1085,27 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
1068 LSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); 1085 LSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
1069 cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32( 1086 cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32(
1070 MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); 1087 MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
1071 fcp_cmnd->task_attribute = 0;
1072 fcp_cmnd->task_management = 0; 1088 fcp_cmnd->task_management = 0;
1073 1089
1090 /*
1091 * Update tagged queuing modifier if using command tag queuing
1092 */
1093 if (scsi_populate_tag_msg(cmd, tag)) {
1094 switch (tag[0]) {
1095 case HEAD_OF_QUEUE_TAG:
1096 fcp_cmnd->task_attribute = TSK_HEAD_OF_QUEUE;
1097 break;
1098 case ORDERED_QUEUE_TAG:
1099 fcp_cmnd->task_attribute = TSK_ORDERED;
1100 break;
1101 default:
1102 fcp_cmnd->task_attribute = 0;
1103 break;
1104 }
1105 } else {
1106 fcp_cmnd->task_attribute = 0;
1107 }
1108
1074 cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */ 1109 cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */
1075 1110
1076 DEBUG18(printk(KERN_INFO "%s(%ld): Total SG(s) Entries %d, Data" 1111 DEBUG18(printk(KERN_INFO "%s(%ld): Total SG(s) Entries %d, Data"
@@ -1177,6 +1212,7 @@ qla24xx_start_scsi(srb_t *sp)
1177 struct scsi_cmnd *cmd = sp->cmd; 1212 struct scsi_cmnd *cmd = sp->cmd;
1178 struct scsi_qla_host *vha = sp->fcport->vha; 1213 struct scsi_qla_host *vha = sp->fcport->vha;
1179 struct qla_hw_data *ha = vha->hw; 1214 struct qla_hw_data *ha = vha->hw;
1215 char tag[2];
1180 1216
1181 /* Setup device pointers. */ 1217 /* Setup device pointers. */
1182 ret = 0; 1218 ret = 0;
@@ -1260,6 +1296,18 @@ qla24xx_start_scsi(srb_t *sp)
1260 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun); 1296 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
1261 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); 1297 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
1262 1298
1299 /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */
1300 if (scsi_populate_tag_msg(cmd, tag)) {
1301 switch (tag[0]) {
1302 case HEAD_OF_QUEUE_TAG:
1303 cmd_pkt->task = TSK_HEAD_OF_QUEUE;
1304 break;
1305 case ORDERED_QUEUE_TAG:
1306 cmd_pkt->task = TSK_ORDERED;
1307 break;
1308 }
1309 }
1310
1263 /* Load SCSI command packet. */ 1311 /* Load SCSI command packet. */
1264 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); 1312 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
1265 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); 1313 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb));
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index e473e9fb363c..7a7c0ecfe7dd 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -71,6 +71,13 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
71 return QLA_FUNCTION_TIMEOUT; 71 return QLA_FUNCTION_TIMEOUT;
72 } 72 }
73 73
74 if (ha->flags.isp82xx_fw_hung) {
75 /* Setting Link-Down error */
76 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
77 rval = QLA_FUNCTION_FAILED;
78 goto premature_exit;
79 }
80
74 /* 81 /*
75 * Wait for active mailbox commands to finish by waiting at most tov 82 * Wait for active mailbox commands to finish by waiting at most tov
76 * seconds. This is to serialize actual issuing of mailbox cmds during 83 * seconds. This is to serialize actual issuing of mailbox cmds during
@@ -83,13 +90,6 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
83 return QLA_FUNCTION_TIMEOUT; 90 return QLA_FUNCTION_TIMEOUT;
84 } 91 }
85 92
86 if (IS_QLA82XX(ha) && ha->flags.fw_hung) {
87 /* Setting Link-Down error */
88 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
89 rval = QLA_FUNCTION_FAILED;
90 goto premature_exit;
91 }
92
93 ha->flags.mbox_busy = 1; 93 ha->flags.mbox_busy = 1;
94 /* Save mailbox command for debug */ 94 /* Save mailbox command for debug */
95 ha->mcp = mcp; 95 ha->mcp = mcp;
@@ -223,7 +223,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
223 ha->flags.mbox_int = 0; 223 ha->flags.mbox_int = 0;
224 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); 224 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
225 225
226 if (IS_QLA82XX(ha) && ha->flags.fw_hung) { 226 if (ha->flags.isp82xx_fw_hung) {
227 ha->flags.mbox_busy = 0; 227 ha->flags.mbox_busy = 0;
228 /* Setting Link-Down error */ 228 /* Setting Link-Down error */
229 mcp->mb[0] = MBS_LINK_DOWN_ERROR; 229 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
@@ -2462,22 +2462,19 @@ __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2462 "-- completion status (%x).\n", __func__, 2462 "-- completion status (%x).\n", __func__,
2463 vha->host_no, le16_to_cpu(sts->comp_status))); 2463 vha->host_no, le16_to_cpu(sts->comp_status)));
2464 rval = QLA_FUNCTION_FAILED; 2464 rval = QLA_FUNCTION_FAILED;
2465 } else if (!(le16_to_cpu(sts->scsi_status) & 2465 } else if (le16_to_cpu(sts->scsi_status) &
2466 SS_RESPONSE_INFO_LEN_VALID)) { 2466 SS_RESPONSE_INFO_LEN_VALID) {
2467 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 2467 if (le32_to_cpu(sts->rsp_data_len) < 4) {
2468 "-- no response info (%x).\n", __func__, vha->host_no, 2468 DEBUG2_3_11(printk("%s(%ld): ignoring inconsistent "
2469 le16_to_cpu(sts->scsi_status))); 2469 "data length -- not enough response info (%d).\n",
2470 rval = QLA_FUNCTION_FAILED; 2470 __func__, vha->host_no,
2471 } else if (le32_to_cpu(sts->rsp_data_len) < 4) { 2471 le32_to_cpu(sts->rsp_data_len)));
2472 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 2472 } else if (sts->data[3]) {
2473 "-- not enough response info (%d).\n", __func__, 2473 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2474 vha->host_no, le32_to_cpu(sts->rsp_data_len))); 2474 "-- response (%x).\n", __func__,
2475 rval = QLA_FUNCTION_FAILED; 2475 vha->host_no, sts->data[3]));
2476 } else if (sts->data[3]) { 2476 rval = QLA_FUNCTION_FAILED;
2477 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 2477 }
2478 "-- response (%x).\n", __func__,
2479 vha->host_no, sts->data[3]));
2480 rval = QLA_FUNCTION_FAILED;
2481 } 2478 }
2482 2479
2483 /* Issue marker IOCB. */ 2480 /* Issue marker IOCB. */
diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index fdb96a3584a5..76ec876e6b21 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -7,6 +7,7 @@
7#include "qla_def.h" 7#include "qla_def.h"
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/pci.h> 9#include <linux/pci.h>
10#include <scsi/scsi_tcq.h>
10 11
11#define MASK(n) ((1ULL<<(n))-1) 12#define MASK(n) ((1ULL<<(n))-1)
12#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | \ 13#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | \
@@ -2547,7 +2548,7 @@ qla2xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt,
2547 dsd_seg = (uint32_t *)&cmd_pkt->fcp_data_dseg_address; 2548 dsd_seg = (uint32_t *)&cmd_pkt->fcp_data_dseg_address;
2548 *dsd_seg++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); 2549 *dsd_seg++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
2549 *dsd_seg++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); 2550 *dsd_seg++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
2550 *dsd_seg++ = dsd_list_len; 2551 cmd_pkt->fcp_data_dseg_len = dsd_list_len;
2551 } else { 2552 } else {
2552 *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); 2553 *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
2553 *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); 2554 *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
@@ -2620,6 +2621,7 @@ qla82xx_start_scsi(srb_t *sp)
2620 struct qla_hw_data *ha = vha->hw; 2621 struct qla_hw_data *ha = vha->hw;
2621 struct req_que *req = NULL; 2622 struct req_que *req = NULL;
2622 struct rsp_que *rsp = NULL; 2623 struct rsp_que *rsp = NULL;
2624 char tag[2];
2623 2625
2624 /* Setup device pointers. */ 2626 /* Setup device pointers. */
2625 ret = 0; 2627 ret = 0;
@@ -2770,6 +2772,22 @@ sufficient_dsds:
2770 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun); 2772 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
2771 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); 2773 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
2772 2774
2775 /*
2776 * Update tagged queuing modifier -- default is TSK_SIMPLE (0).
2777 */
2778 if (scsi_populate_tag_msg(cmd, tag)) {
2779 switch (tag[0]) {
2780 case HEAD_OF_QUEUE_TAG:
2781 ctx->fcp_cmnd->task_attribute =
2782 TSK_HEAD_OF_QUEUE;
2783 break;
2784 case ORDERED_QUEUE_TAG:
2785 ctx->fcp_cmnd->task_attribute =
2786 TSK_ORDERED;
2787 break;
2788 }
2789 }
2790
2773 /* build FCP_CMND IU */ 2791 /* build FCP_CMND IU */
2774 memset(ctx->fcp_cmnd, 0, sizeof(struct fcp_cmnd)); 2792 memset(ctx->fcp_cmnd, 0, sizeof(struct fcp_cmnd));
2775 int_to_scsilun(sp->cmd->device->lun, &ctx->fcp_cmnd->lun); 2793 int_to_scsilun(sp->cmd->device->lun, &ctx->fcp_cmnd->lun);
@@ -2835,6 +2853,20 @@ sufficient_dsds:
2835 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, 2853 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun,
2836 sizeof(cmd_pkt->lun)); 2854 sizeof(cmd_pkt->lun));
2837 2855
2856 /*
2857 * Update tagged queuing modifier -- default is TSK_SIMPLE (0).
2858 */
2859 if (scsi_populate_tag_msg(cmd, tag)) {
2860 switch (tag[0]) {
2861 case HEAD_OF_QUEUE_TAG:
2862 cmd_pkt->task = TSK_HEAD_OF_QUEUE;
2863 break;
2864 case ORDERED_QUEUE_TAG:
2865 cmd_pkt->task = TSK_ORDERED;
2866 break;
2867 }
2868 }
2869
2838 /* Load SCSI command packet. */ 2870 /* Load SCSI command packet. */
2839 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); 2871 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
2840 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); 2872 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb));
@@ -3457,46 +3489,28 @@ qla82xx_need_reset_handler(scsi_qla_host_t *vha)
3457 } 3489 }
3458} 3490}
3459 3491
3460static void 3492int
3461qla82xx_check_fw_alive(scsi_qla_host_t *vha) 3493qla82xx_check_fw_alive(scsi_qla_host_t *vha)
3462{ 3494{
3463 uint32_t fw_heartbeat_counter, halt_status; 3495 uint32_t fw_heartbeat_counter;
3464 struct qla_hw_data *ha = vha->hw; 3496 int status = 0;
3465 3497
3466 fw_heartbeat_counter = qla82xx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); 3498 fw_heartbeat_counter = qla82xx_rd_32(vha->hw,
3499 QLA82XX_PEG_ALIVE_COUNTER);
3467 /* all 0xff, assume AER/EEH in progress, ignore */ 3500 /* all 0xff, assume AER/EEH in progress, ignore */
3468 if (fw_heartbeat_counter == 0xffffffff) 3501 if (fw_heartbeat_counter == 0xffffffff)
3469 return; 3502 return status;
3470 if (vha->fw_heartbeat_counter == fw_heartbeat_counter) { 3503 if (vha->fw_heartbeat_counter == fw_heartbeat_counter) {
3471 vha->seconds_since_last_heartbeat++; 3504 vha->seconds_since_last_heartbeat++;
3472 /* FW not alive after 2 seconds */ 3505 /* FW not alive after 2 seconds */
3473 if (vha->seconds_since_last_heartbeat == 2) { 3506 if (vha->seconds_since_last_heartbeat == 2) {
3474 vha->seconds_since_last_heartbeat = 0; 3507 vha->seconds_since_last_heartbeat = 0;
3475 halt_status = qla82xx_rd_32(ha, 3508 status = 1;
3476 QLA82XX_PEG_HALT_STATUS1);
3477 if (halt_status & HALT_STATUS_UNRECOVERABLE) {
3478 set_bit(ISP_UNRECOVERABLE, &vha->dpc_flags);
3479 } else {
3480 qla_printk(KERN_INFO, ha,
3481 "scsi(%ld): %s - detect abort needed\n",
3482 vha->host_no, __func__);
3483 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3484 }
3485 qla2xxx_wake_dpc(vha);
3486 ha->flags.fw_hung = 1;
3487 if (ha->flags.mbox_busy) {
3488 ha->flags.mbox_int = 1;
3489 DEBUG2(qla_printk(KERN_ERR, ha,
3490 "Due to fw hung, doing premature "
3491 "completion of mbx command\n"));
3492 if (test_bit(MBX_INTR_WAIT,
3493 &ha->mbx_cmd_flags))
3494 complete(&ha->mbx_intr_comp);
3495 }
3496 } 3509 }
3497 } else 3510 } else
3498 vha->seconds_since_last_heartbeat = 0; 3511 vha->seconds_since_last_heartbeat = 0;
3499 vha->fw_heartbeat_counter = fw_heartbeat_counter; 3512 vha->fw_heartbeat_counter = fw_heartbeat_counter;
3513 return status;
3500} 3514}
3501 3515
3502/* 3516/*
@@ -3557,6 +3571,8 @@ qla82xx_device_state_handler(scsi_qla_host_t *vha)
3557 break; 3571 break;
3558 case QLA82XX_DEV_NEED_RESET: 3572 case QLA82XX_DEV_NEED_RESET:
3559 qla82xx_need_reset_handler(vha); 3573 qla82xx_need_reset_handler(vha);
3574 dev_init_timeout = jiffies +
3575 (ha->nx_dev_init_timeout * HZ);
3560 break; 3576 break;
3561 case QLA82XX_DEV_NEED_QUIESCENT: 3577 case QLA82XX_DEV_NEED_QUIESCENT:
3562 qla82xx_need_qsnt_handler(vha); 3578 qla82xx_need_qsnt_handler(vha);
@@ -3596,30 +3612,18 @@ exit:
3596 3612
3597void qla82xx_watchdog(scsi_qla_host_t *vha) 3613void qla82xx_watchdog(scsi_qla_host_t *vha)
3598{ 3614{
3599 uint32_t dev_state; 3615 uint32_t dev_state, halt_status;
3600 struct qla_hw_data *ha = vha->hw; 3616 struct qla_hw_data *ha = vha->hw;
3601 3617
3602 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3603
3604 /* don't poll if reset is going on */ 3618 /* don't poll if reset is going on */
3605 if (!(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || 3619 if (!ha->flags.isp82xx_reset_hdlr_active) {
3606 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) || 3620 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3607 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags))) { 3621 if (dev_state == QLA82XX_DEV_NEED_RESET &&
3608 if (dev_state == QLA82XX_DEV_NEED_RESET) { 3622 !test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) {
3609 qla_printk(KERN_WARNING, ha, 3623 qla_printk(KERN_WARNING, ha,
3610 "%s(): Adapter reset needed!\n", __func__); 3624 "%s(): Adapter reset needed!\n", __func__);
3611 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); 3625 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3612 qla2xxx_wake_dpc(vha); 3626 qla2xxx_wake_dpc(vha);
3613 ha->flags.fw_hung = 1;
3614 if (ha->flags.mbox_busy) {
3615 ha->flags.mbox_int = 1;
3616 DEBUG2(qla_printk(KERN_ERR, ha,
3617 "Need reset, doing premature "
3618 "completion of mbx command\n"));
3619 if (test_bit(MBX_INTR_WAIT,
3620 &ha->mbx_cmd_flags))
3621 complete(&ha->mbx_intr_comp);
3622 }
3623 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT && 3627 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
3624 !test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags)) { 3628 !test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags)) {
3625 DEBUG(qla_printk(KERN_INFO, ha, 3629 DEBUG(qla_printk(KERN_INFO, ha,
@@ -3629,6 +3633,31 @@ void qla82xx_watchdog(scsi_qla_host_t *vha)
3629 qla2xxx_wake_dpc(vha); 3633 qla2xxx_wake_dpc(vha);
3630 } else { 3634 } else {
3631 qla82xx_check_fw_alive(vha); 3635 qla82xx_check_fw_alive(vha);
3636 if (qla82xx_check_fw_alive(vha)) {
3637 halt_status = qla82xx_rd_32(ha,
3638 QLA82XX_PEG_HALT_STATUS1);
3639 if (halt_status & HALT_STATUS_UNRECOVERABLE) {
3640 set_bit(ISP_UNRECOVERABLE,
3641 &vha->dpc_flags);
3642 } else {
3643 qla_printk(KERN_INFO, ha,
3644 "scsi(%ld): %s - detect abort needed\n",
3645 vha->host_no, __func__);
3646 set_bit(ISP_ABORT_NEEDED,
3647 &vha->dpc_flags);
3648 }
3649 qla2xxx_wake_dpc(vha);
3650 ha->flags.isp82xx_fw_hung = 1;
3651 if (ha->flags.mbox_busy) {
3652 ha->flags.mbox_int = 1;
3653 DEBUG2(qla_printk(KERN_ERR, ha,
3654 "Due to fw hung, doing premature "
3655 "completion of mbx command\n"));
3656 if (test_bit(MBX_INTR_WAIT,
3657 &ha->mbx_cmd_flags))
3658 complete(&ha->mbx_intr_comp);
3659 }
3660 }
3632 } 3661 }
3633 } 3662 }
3634} 3663}
@@ -3663,6 +3692,7 @@ qla82xx_abort_isp(scsi_qla_host_t *vha)
3663 "Exiting.\n", __func__, vha->host_no); 3692 "Exiting.\n", __func__, vha->host_no);
3664 return QLA_SUCCESS; 3693 return QLA_SUCCESS;
3665 } 3694 }
3695 ha->flags.isp82xx_reset_hdlr_active = 1;
3666 3696
3667 qla82xx_idc_lock(ha); 3697 qla82xx_idc_lock(ha);
3668 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE); 3698 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
@@ -3683,7 +3713,8 @@ qla82xx_abort_isp(scsi_qla_host_t *vha)
3683 qla82xx_idc_unlock(ha); 3713 qla82xx_idc_unlock(ha);
3684 3714
3685 if (rval == QLA_SUCCESS) { 3715 if (rval == QLA_SUCCESS) {
3686 ha->flags.fw_hung = 0; 3716 ha->flags.isp82xx_fw_hung = 0;
3717 ha->flags.isp82xx_reset_hdlr_active = 0;
3687 qla82xx_restart_isp(vha); 3718 qla82xx_restart_isp(vha);
3688 } 3719 }
3689 3720
@@ -3791,3 +3822,71 @@ int qla2x00_wait_for_fcoe_ctx_reset(scsi_qla_host_t *vha)
3791 3822
3792 return status; 3823 return status;
3793} 3824}
3825
3826void
3827qla82xx_chip_reset_cleanup(scsi_qla_host_t *vha)
3828{
3829 int i;
3830 unsigned long flags;
3831 struct qla_hw_data *ha = vha->hw;
3832
3833 /* Check if 82XX firmware is alive or not
3834 * We may have arrived here from NEED_RESET
3835 * detection only
3836 */
3837 if (!ha->flags.isp82xx_fw_hung) {
3838 for (i = 0; i < 2; i++) {
3839 msleep(1000);
3840 if (qla82xx_check_fw_alive(vha)) {
3841 ha->flags.isp82xx_fw_hung = 1;
3842 if (ha->flags.mbox_busy) {
3843 ha->flags.mbox_int = 1;
3844 complete(&ha->mbx_intr_comp);
3845 }
3846 break;
3847 }
3848 }
3849 }
3850
3851 /* Abort all commands gracefully if fw NOT hung */
3852 if (!ha->flags.isp82xx_fw_hung) {
3853 int cnt, que;
3854 srb_t *sp;
3855 struct req_que *req;
3856
3857 spin_lock_irqsave(&ha->hardware_lock, flags);
3858 for (que = 0; que < ha->max_req_queues; que++) {
3859 req = ha->req_q_map[que];
3860 if (!req)
3861 continue;
3862 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3863 sp = req->outstanding_cmds[cnt];
3864 if (sp) {
3865 if (!sp->ctx ||
3866 (sp->flags & SRB_FCP_CMND_DMA_VALID)) {
3867 spin_unlock_irqrestore(
3868 &ha->hardware_lock, flags);
3869 if (ha->isp_ops->abort_command(sp)) {
3870 qla_printk(KERN_INFO, ha,
3871 "scsi(%ld): mbx abort command failed in %s\n",
3872 vha->host_no, __func__);
3873 } else {
3874 qla_printk(KERN_INFO, ha,
3875 "scsi(%ld): mbx abort command success in %s\n",
3876 vha->host_no, __func__);
3877 }
3878 spin_lock_irqsave(&ha->hardware_lock, flags);
3879 }
3880 }
3881 }
3882 }
3883 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3884
3885 /* Wait for pending cmds (physical and virtual) to complete */
3886 if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
3887 WAIT_HOST) == QLA_SUCCESS) {
3888 DEBUG2(qla_printk(KERN_INFO, ha,
3889 "Done wait for pending commands\n"));
3890 }
3891 }
3892}
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index e90f7c16b956..75a966c94860 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -506,7 +506,7 @@ qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
506 506
507static inline srb_t * 507static inline srb_t *
508qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport, 508qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
509 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 509 struct scsi_cmnd *cmd)
510{ 510{
511 srb_t *sp; 511 srb_t *sp;
512 struct qla_hw_data *ha = vha->hw; 512 struct qla_hw_data *ha = vha->hw;
@@ -520,14 +520,13 @@ qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
520 sp->cmd = cmd; 520 sp->cmd = cmd;
521 sp->flags = 0; 521 sp->flags = 0;
522 CMD_SP(cmd) = (void *)sp; 522 CMD_SP(cmd) = (void *)sp;
523 cmd->scsi_done = done;
524 sp->ctx = NULL; 523 sp->ctx = NULL;
525 524
526 return sp; 525 return sp;
527} 526}
528 527
529static int 528static int
530qla2xxx_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 529qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
531{ 530{
532 scsi_qla_host_t *vha = shost_priv(cmd->device->host); 531 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
533 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 532 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
@@ -537,7 +536,6 @@ qla2xxx_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)
537 srb_t *sp; 536 srb_t *sp;
538 int rval; 537 int rval;
539 538
540 spin_unlock_irq(vha->host->host_lock);
541 if (ha->flags.eeh_busy) { 539 if (ha->flags.eeh_busy) {
542 if (ha->flags.pci_channel_io_perm_failure) 540 if (ha->flags.pci_channel_io_perm_failure)
543 cmd->result = DID_NO_CONNECT << 16; 541 cmd->result = DID_NO_CONNECT << 16;
@@ -569,40 +567,32 @@ qla2xxx_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)
569 goto qc24_target_busy; 567 goto qc24_target_busy;
570 } 568 }
571 569
572 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done); 570 sp = qla2x00_get_new_sp(base_vha, fcport, cmd);
573 if (!sp) 571 if (!sp)
574 goto qc24_host_busy_lock; 572 goto qc24_host_busy;
575 573
576 rval = ha->isp_ops->start_scsi(sp); 574 rval = ha->isp_ops->start_scsi(sp);
577 if (rval != QLA_SUCCESS) 575 if (rval != QLA_SUCCESS)
578 goto qc24_host_busy_free_sp; 576 goto qc24_host_busy_free_sp;
579 577
580 spin_lock_irq(vha->host->host_lock);
581
582 return 0; 578 return 0;
583 579
584qc24_host_busy_free_sp: 580qc24_host_busy_free_sp:
585 qla2x00_sp_free_dma(sp); 581 qla2x00_sp_free_dma(sp);
586 mempool_free(sp, ha->srb_mempool); 582 mempool_free(sp, ha->srb_mempool);
587 583
588qc24_host_busy_lock: 584qc24_host_busy:
589 spin_lock_irq(vha->host->host_lock);
590 return SCSI_MLQUEUE_HOST_BUSY; 585 return SCSI_MLQUEUE_HOST_BUSY;
591 586
592qc24_target_busy: 587qc24_target_busy:
593 spin_lock_irq(vha->host->host_lock);
594 return SCSI_MLQUEUE_TARGET_BUSY; 588 return SCSI_MLQUEUE_TARGET_BUSY;
595 589
596qc24_fail_command: 590qc24_fail_command:
597 spin_lock_irq(vha->host->host_lock); 591 cmd->scsi_done(cmd);
598 done(cmd);
599 592
600 return 0; 593 return 0;
601} 594}
602 595
603static DEF_SCSI_QCMD(qla2xxx_queuecommand)
604
605
606/* 596/*
607 * qla2x00_eh_wait_on_command 597 * qla2x00_eh_wait_on_command
608 * Waits for the command to be returned by the Firmware for some 598 * Waits for the command to be returned by the Firmware for some
@@ -821,17 +811,20 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
821{ 811{
822 scsi_qla_host_t *vha = shost_priv(cmd->device->host); 812 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
823 srb_t *sp; 813 srb_t *sp;
824 int ret = SUCCESS; 814 int ret;
825 unsigned int id, lun; 815 unsigned int id, lun;
826 unsigned long flags; 816 unsigned long flags;
827 int wait = 0; 817 int wait = 0;
828 struct qla_hw_data *ha = vha->hw; 818 struct qla_hw_data *ha = vha->hw;
829 819
830 fc_block_scsi_eh(cmd);
831
832 if (!CMD_SP(cmd)) 820 if (!CMD_SP(cmd))
833 return SUCCESS; 821 return SUCCESS;
834 822
823 ret = fc_block_scsi_eh(cmd);
824 if (ret != 0)
825 return ret;
826 ret = SUCCESS;
827
835 id = cmd->device->id; 828 id = cmd->device->id;
836 lun = cmd->device->lun; 829 lun = cmd->device->lun;
837 830
@@ -940,11 +933,13 @@ __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
940 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 933 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
941 int err; 934 int err;
942 935
943 fc_block_scsi_eh(cmd);
944
945 if (!fcport) 936 if (!fcport)
946 return FAILED; 937 return FAILED;
947 938
939 err = fc_block_scsi_eh(cmd);
940 if (err != 0)
941 return err;
942
948 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n", 943 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
949 vha->host_no, cmd->device->id, cmd->device->lun, name); 944 vha->host_no, cmd->device->id, cmd->device->lun, name);
950 945
@@ -1018,14 +1013,17 @@ qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1018 int ret = FAILED; 1013 int ret = FAILED;
1019 unsigned int id, lun; 1014 unsigned int id, lun;
1020 1015
1021 fc_block_scsi_eh(cmd);
1022
1023 id = cmd->device->id; 1016 id = cmd->device->id;
1024 lun = cmd->device->lun; 1017 lun = cmd->device->lun;
1025 1018
1026 if (!fcport) 1019 if (!fcport)
1027 return ret; 1020 return ret;
1028 1021
1022 ret = fc_block_scsi_eh(cmd);
1023 if (ret != 0)
1024 return ret;
1025 ret = FAILED;
1026
1029 qla_printk(KERN_INFO, vha->hw, 1027 qla_printk(KERN_INFO, vha->hw,
1030 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun); 1028 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
1031 1029
@@ -1078,14 +1076,17 @@ qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1078 unsigned int id, lun; 1076 unsigned int id, lun;
1079 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); 1077 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1080 1078
1081 fc_block_scsi_eh(cmd);
1082
1083 id = cmd->device->id; 1079 id = cmd->device->id;
1084 lun = cmd->device->lun; 1080 lun = cmd->device->lun;
1085 1081
1086 if (!fcport) 1082 if (!fcport)
1087 return ret; 1083 return ret;
1088 1084
1085 ret = fc_block_scsi_eh(cmd);
1086 if (ret != 0)
1087 return ret;
1088 ret = FAILED;
1089
1089 qla_printk(KERN_INFO, ha, 1090 qla_printk(KERN_INFO, ha,
1090 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun); 1091 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
1091 1092
@@ -3805,7 +3806,7 @@ qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3805 ha->flags.eeh_busy = 1; 3806 ha->flags.eeh_busy = 1;
3806 /* For ISP82XX complete any pending mailbox cmd */ 3807 /* For ISP82XX complete any pending mailbox cmd */
3807 if (IS_QLA82XX(ha)) { 3808 if (IS_QLA82XX(ha)) {
3808 ha->flags.fw_hung = 1; 3809 ha->flags.isp82xx_fw_hung = 1;
3809 if (ha->flags.mbox_busy) { 3810 if (ha->flags.mbox_busy) {
3810 ha->flags.mbox_int = 1; 3811 ha->flags.mbox_int = 1;
3811 DEBUG2(qla_printk(KERN_ERR, ha, 3812 DEBUG2(qla_printk(KERN_ERR, ha,
@@ -3945,7 +3946,7 @@ uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
3945 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, 3946 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3946 QLA82XX_DEV_READY); 3947 QLA82XX_DEV_READY);
3947 qla82xx_idc_unlock(ha); 3948 qla82xx_idc_unlock(ha);
3948 ha->flags.fw_hung = 0; 3949 ha->flags.isp82xx_fw_hung = 0;
3949 rval = qla82xx_restart_isp(base_vha); 3950 rval = qla82xx_restart_isp(base_vha);
3950 qla82xx_idc_lock(ha); 3951 qla82xx_idc_lock(ha);
3951 /* Clear driver state register */ 3952 /* Clear driver state register */
@@ -3958,7 +3959,7 @@ uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
3958 "This devfn is not reset owner = 0x%x\n", ha->pdev->devfn)); 3959 "This devfn is not reset owner = 0x%x\n", ha->pdev->devfn));
3959 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) == 3960 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
3960 QLA82XX_DEV_READY)) { 3961 QLA82XX_DEV_READY)) {
3961 ha->flags.fw_hung = 0; 3962 ha->flags.isp82xx_fw_hung = 0;
3962 rval = qla82xx_restart_isp(base_vha); 3963 rval = qla82xx_restart_isp(base_vha);
3963 qla82xx_idc_lock(ha); 3964 qla82xx_idc_lock(ha);
3964 qla82xx_set_drv_active(base_vha); 3965 qla82xx_set_drv_active(base_vha);
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index cf0075a2d0c2..3a260c3f055a 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,9 +7,9 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.03.05-k0" 10#define QLA2XXX_VERSION "8.03.07.00"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 3 13#define QLA_DRIVER_MINOR_VER 3
14#define QLA_DRIVER_PATCH_VER 5 14#define QLA_DRIVER_PATCH_VER 7
15#define QLA_DRIVER_BETA_VER 0 15#define QLA_DRIVER_BETA_VER 0
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index a6b2d72022fc..fa5758cbdedb 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -89,32 +89,34 @@ static const char * scsi_debug_version_date = "20100324";
89/* With these defaults, this driver will make 1 host with 1 target 89/* With these defaults, this driver will make 1 host with 1 target
90 * (id 0) containing 1 logical unit (lun 0). That is 1 device. 90 * (id 0) containing 1 logical unit (lun 0). That is 1 device.
91 */ 91 */
92#define DEF_ATO 1
92#define DEF_DELAY 1 93#define DEF_DELAY 1
93#define DEF_DEV_SIZE_MB 8 94#define DEF_DEV_SIZE_MB 8
94#define DEF_EVERY_NTH 0 95#define DEF_DIF 0
95#define DEF_NUM_PARTS 0 96#define DEF_DIX 0
96#define DEF_OPTS 0
97#define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */
98#define DEF_PTYPE 0
99#define DEF_D_SENSE 0 97#define DEF_D_SENSE 0
100#define DEF_NO_LUN_0 0 98#define DEF_EVERY_NTH 0
101#define DEF_VIRTUAL_GB 0
102#define DEF_FAKE_RW 0 99#define DEF_FAKE_RW 0
103#define DEF_VPD_USE_HOSTNO 1
104#define DEF_SECTOR_SIZE 512
105#define DEF_DIX 0
106#define DEF_DIF 0
107#define DEF_GUARD 0 100#define DEF_GUARD 0
108#define DEF_ATO 1 101#define DEF_LBPU 0
109#define DEF_PHYSBLK_EXP 0 102#define DEF_LBPWS 0
103#define DEF_LBPWS10 0
110#define DEF_LOWEST_ALIGNED 0 104#define DEF_LOWEST_ALIGNED 0
105#define DEF_NO_LUN_0 0
106#define DEF_NUM_PARTS 0
107#define DEF_OPTS 0
111#define DEF_OPT_BLKS 64 108#define DEF_OPT_BLKS 64
109#define DEF_PHYSBLK_EXP 0
110#define DEF_PTYPE 0
111#define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */
112#define DEF_SECTOR_SIZE 512
113#define DEF_UNMAP_ALIGNMENT 0
114#define DEF_UNMAP_GRANULARITY 1
112#define DEF_UNMAP_MAX_BLOCKS 0xFFFFFFFF 115#define DEF_UNMAP_MAX_BLOCKS 0xFFFFFFFF
113#define DEF_UNMAP_MAX_DESC 256 116#define DEF_UNMAP_MAX_DESC 256
114#define DEF_UNMAP_GRANULARITY 1 117#define DEF_VIRTUAL_GB 0
115#define DEF_UNMAP_ALIGNMENT 0 118#define DEF_VPD_USE_HOSTNO 1
116#define DEF_TPWS 0 119#define DEF_WRITESAME_LENGTH 0xFFFF
117#define DEF_TPU 0
118 120
119/* bit mask values for scsi_debug_opts */ 121/* bit mask values for scsi_debug_opts */
120#define SCSI_DEBUG_OPT_NOISE 1 122#define SCSI_DEBUG_OPT_NOISE 1
@@ -144,6 +146,7 @@ static const char * scsi_debug_version_date = "20100324";
144/* when 1==SCSI_DEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this 146/* when 1==SCSI_DEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this
145 * sector on read commands: */ 147 * sector on read commands: */
146#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */ 148#define OPT_MEDIUM_ERR_ADDR 0x1234 /* that's sector 4660 in decimal */
149#define OPT_MEDIUM_ERR_NUM 10 /* number of consecutive medium errs */
147 150
148/* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1) 151/* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1)
149 * or "peripheral device" addressing (value 0) */ 152 * or "peripheral device" addressing (value 0) */
@@ -155,36 +158,38 @@ static const char * scsi_debug_version_date = "20100324";
155#define SCSI_DEBUG_CANQUEUE 255 158#define SCSI_DEBUG_CANQUEUE 255
156 159
157static int scsi_debug_add_host = DEF_NUM_HOST; 160static int scsi_debug_add_host = DEF_NUM_HOST;
161static int scsi_debug_ato = DEF_ATO;
158static int scsi_debug_delay = DEF_DELAY; 162static int scsi_debug_delay = DEF_DELAY;
159static int scsi_debug_dev_size_mb = DEF_DEV_SIZE_MB; 163static int scsi_debug_dev_size_mb = DEF_DEV_SIZE_MB;
164static int scsi_debug_dif = DEF_DIF;
165static int scsi_debug_dix = DEF_DIX;
166static int scsi_debug_dsense = DEF_D_SENSE;
160static int scsi_debug_every_nth = DEF_EVERY_NTH; 167static int scsi_debug_every_nth = DEF_EVERY_NTH;
168static int scsi_debug_fake_rw = DEF_FAKE_RW;
169static int scsi_debug_guard = DEF_GUARD;
170static int scsi_debug_lowest_aligned = DEF_LOWEST_ALIGNED;
161static int scsi_debug_max_luns = DEF_MAX_LUNS; 171static int scsi_debug_max_luns = DEF_MAX_LUNS;
162static int scsi_debug_max_queue = SCSI_DEBUG_CANQUEUE; 172static int scsi_debug_max_queue = SCSI_DEBUG_CANQUEUE;
163static int scsi_debug_num_parts = DEF_NUM_PARTS; 173static int scsi_debug_no_lun_0 = DEF_NO_LUN_0;
164static int scsi_debug_no_uld = 0; 174static int scsi_debug_no_uld = 0;
175static int scsi_debug_num_parts = DEF_NUM_PARTS;
165static int scsi_debug_num_tgts = DEF_NUM_TGTS; /* targets per host */ 176static int scsi_debug_num_tgts = DEF_NUM_TGTS; /* targets per host */
177static int scsi_debug_opt_blks = DEF_OPT_BLKS;
166static int scsi_debug_opts = DEF_OPTS; 178static int scsi_debug_opts = DEF_OPTS;
167static int scsi_debug_scsi_level = DEF_SCSI_LEVEL; 179static int scsi_debug_physblk_exp = DEF_PHYSBLK_EXP;
168static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */ 180static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */
169static int scsi_debug_dsense = DEF_D_SENSE; 181static int scsi_debug_scsi_level = DEF_SCSI_LEVEL;
170static int scsi_debug_no_lun_0 = DEF_NO_LUN_0; 182static int scsi_debug_sector_size = DEF_SECTOR_SIZE;
171static int scsi_debug_virtual_gb = DEF_VIRTUAL_GB; 183static int scsi_debug_virtual_gb = DEF_VIRTUAL_GB;
172static int scsi_debug_fake_rw = DEF_FAKE_RW;
173static int scsi_debug_vpd_use_hostno = DEF_VPD_USE_HOSTNO; 184static int scsi_debug_vpd_use_hostno = DEF_VPD_USE_HOSTNO;
174static int scsi_debug_sector_size = DEF_SECTOR_SIZE; 185static unsigned int scsi_debug_lbpu = DEF_LBPU;
175static int scsi_debug_dix = DEF_DIX; 186static unsigned int scsi_debug_lbpws = DEF_LBPWS;
176static int scsi_debug_dif = DEF_DIF; 187static unsigned int scsi_debug_lbpws10 = DEF_LBPWS10;
177static int scsi_debug_guard = DEF_GUARD;
178static int scsi_debug_ato = DEF_ATO;
179static int scsi_debug_physblk_exp = DEF_PHYSBLK_EXP;
180static int scsi_debug_lowest_aligned = DEF_LOWEST_ALIGNED;
181static int scsi_debug_opt_blks = DEF_OPT_BLKS;
182static unsigned int scsi_debug_unmap_max_desc = DEF_UNMAP_MAX_DESC;
183static unsigned int scsi_debug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS;
184static unsigned int scsi_debug_unmap_granularity = DEF_UNMAP_GRANULARITY;
185static unsigned int scsi_debug_unmap_alignment = DEF_UNMAP_ALIGNMENT; 188static unsigned int scsi_debug_unmap_alignment = DEF_UNMAP_ALIGNMENT;
186static unsigned int scsi_debug_tpws = DEF_TPWS; 189static unsigned int scsi_debug_unmap_granularity = DEF_UNMAP_GRANULARITY;
187static unsigned int scsi_debug_tpu = DEF_TPU; 190static unsigned int scsi_debug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS;
191static unsigned int scsi_debug_unmap_max_desc = DEF_UNMAP_MAX_DESC;
192static unsigned int scsi_debug_write_same_length = DEF_WRITESAME_LENGTH;
188 193
189static int scsi_debug_cmnd_count = 0; 194static int scsi_debug_cmnd_count = 0;
190 195
@@ -206,6 +211,11 @@ static int sdebug_sectors_per; /* sectors per cylinder */
206 211
207#define SCSI_DEBUG_MAX_CMD_LEN 32 212#define SCSI_DEBUG_MAX_CMD_LEN 32
208 213
214static unsigned int scsi_debug_lbp(void)
215{
216 return scsi_debug_lbpu | scsi_debug_lbpws | scsi_debug_lbpws10;
217}
218
209struct sdebug_dev_info { 219struct sdebug_dev_info {
210 struct list_head dev_list; 220 struct list_head dev_list;
211 unsigned char sense_buff[SDEBUG_SENSE_LEN]; /* weak nexus */ 221 unsigned char sense_buff[SDEBUG_SENSE_LEN]; /* weak nexus */
@@ -727,7 +737,7 @@ static int inquiry_evpd_b0(unsigned char * arr)
727 /* Optimal Transfer Length */ 737 /* Optimal Transfer Length */
728 put_unaligned_be32(scsi_debug_opt_blks, &arr[8]); 738 put_unaligned_be32(scsi_debug_opt_blks, &arr[8]);
729 739
730 if (scsi_debug_tpu) { 740 if (scsi_debug_lbpu) {
731 /* Maximum Unmap LBA Count */ 741 /* Maximum Unmap LBA Count */
732 put_unaligned_be32(scsi_debug_unmap_max_blocks, &arr[16]); 742 put_unaligned_be32(scsi_debug_unmap_max_blocks, &arr[16]);
733 743
@@ -744,7 +754,10 @@ static int inquiry_evpd_b0(unsigned char * arr)
744 /* Optimal Unmap Granularity */ 754 /* Optimal Unmap Granularity */
745 put_unaligned_be32(scsi_debug_unmap_granularity, &arr[24]); 755 put_unaligned_be32(scsi_debug_unmap_granularity, &arr[24]);
746 756
747 return 0x3c; /* Mandatory page length for thin provisioning */ 757 /* Maximum WRITE SAME Length */
758 put_unaligned_be64(scsi_debug_write_same_length, &arr[32]);
759
760 return 0x3c; /* Mandatory page length for Logical Block Provisioning */
748 761
749 return sizeof(vpdb0_data); 762 return sizeof(vpdb0_data);
750} 763}
@@ -767,12 +780,15 @@ static int inquiry_evpd_b2(unsigned char *arr)
767 memset(arr, 0, 0x8); 780 memset(arr, 0, 0x8);
768 arr[0] = 0; /* threshold exponent */ 781 arr[0] = 0; /* threshold exponent */
769 782
770 if (scsi_debug_tpu) 783 if (scsi_debug_lbpu)
771 arr[1] = 1 << 7; 784 arr[1] = 1 << 7;
772 785
773 if (scsi_debug_tpws) 786 if (scsi_debug_lbpws)
774 arr[1] |= 1 << 6; 787 arr[1] |= 1 << 6;
775 788
789 if (scsi_debug_lbpws10)
790 arr[1] |= 1 << 5;
791
776 return 0x8; 792 return 0x8;
777} 793}
778 794
@@ -831,7 +847,8 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
831 arr[n++] = 0x89; /* ATA information */ 847 arr[n++] = 0x89; /* ATA information */
832 arr[n++] = 0xb0; /* Block limits (SBC) */ 848 arr[n++] = 0xb0; /* Block limits (SBC) */
833 arr[n++] = 0xb1; /* Block characteristics (SBC) */ 849 arr[n++] = 0xb1; /* Block characteristics (SBC) */
834 arr[n++] = 0xb2; /* Thin provisioning (SBC) */ 850 if (scsi_debug_lbp()) /* Logical Block Prov. (SBC) */
851 arr[n++] = 0xb2;
835 arr[3] = n - 4; /* number of supported VPD pages */ 852 arr[3] = n - 4; /* number of supported VPD pages */
836 } else if (0x80 == cmd[2]) { /* unit serial number */ 853 } else if (0x80 == cmd[2]) { /* unit serial number */
837 arr[1] = cmd[2]; /*sanity */ 854 arr[1] = cmd[2]; /*sanity */
@@ -879,7 +896,7 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
879 } else if (0xb1 == cmd[2]) { /* Block characteristics (SBC) */ 896 } else if (0xb1 == cmd[2]) { /* Block characteristics (SBC) */
880 arr[1] = cmd[2]; /*sanity */ 897 arr[1] = cmd[2]; /*sanity */
881 arr[3] = inquiry_evpd_b1(&arr[4]); 898 arr[3] = inquiry_evpd_b1(&arr[4]);
882 } else if (0xb2 == cmd[2]) { /* Thin provisioning (SBC) */ 899 } else if (0xb2 == cmd[2]) { /* Logical Block Prov. (SBC) */
883 arr[1] = cmd[2]; /*sanity */ 900 arr[1] = cmd[2]; /*sanity */
884 arr[3] = inquiry_evpd_b2(&arr[4]); 901 arr[3] = inquiry_evpd_b2(&arr[4]);
885 } else { 902 } else {
@@ -1053,8 +1070,8 @@ static int resp_readcap16(struct scsi_cmnd * scp,
1053 arr[13] = scsi_debug_physblk_exp & 0xf; 1070 arr[13] = scsi_debug_physblk_exp & 0xf;
1054 arr[14] = (scsi_debug_lowest_aligned >> 8) & 0x3f; 1071 arr[14] = (scsi_debug_lowest_aligned >> 8) & 0x3f;
1055 1072
1056 if (scsi_debug_tpu || scsi_debug_tpws) 1073 if (scsi_debug_lbp())
1057 arr[14] |= 0x80; /* TPE */ 1074 arr[14] |= 0x80; /* LBPME */
1058 1075
1059 arr[15] = scsi_debug_lowest_aligned & 0xff; 1076 arr[15] = scsi_debug_lowest_aligned & 0xff;
1060 1077
@@ -1791,15 +1808,15 @@ static int resp_read(struct scsi_cmnd *SCpnt, unsigned long long lba,
1791 return ret; 1808 return ret;
1792 1809
1793 if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && 1810 if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) &&
1794 (lba <= OPT_MEDIUM_ERR_ADDR) && 1811 (lba <= (OPT_MEDIUM_ERR_ADDR + OPT_MEDIUM_ERR_NUM - 1)) &&
1795 ((lba + num) > OPT_MEDIUM_ERR_ADDR)) { 1812 ((lba + num) > OPT_MEDIUM_ERR_ADDR)) {
1796 /* claim unrecoverable read error */ 1813 /* claim unrecoverable read error */
1797 mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR, 1814 mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR, 0);
1798 0);
1799 /* set info field and valid bit for fixed descriptor */ 1815 /* set info field and valid bit for fixed descriptor */
1800 if (0x70 == (devip->sense_buff[0] & 0x7f)) { 1816 if (0x70 == (devip->sense_buff[0] & 0x7f)) {
1801 devip->sense_buff[0] |= 0x80; /* Valid bit */ 1817 devip->sense_buff[0] |= 0x80; /* Valid bit */
1802 ret = OPT_MEDIUM_ERR_ADDR; 1818 ret = (lba < OPT_MEDIUM_ERR_ADDR)
1819 ? OPT_MEDIUM_ERR_ADDR : (int)lba;
1803 devip->sense_buff[3] = (ret >> 24) & 0xff; 1820 devip->sense_buff[3] = (ret >> 24) & 0xff;
1804 devip->sense_buff[4] = (ret >> 16) & 0xff; 1821 devip->sense_buff[4] = (ret >> 16) & 0xff;
1805 devip->sense_buff[5] = (ret >> 8) & 0xff; 1822 devip->sense_buff[5] = (ret >> 8) & 0xff;
@@ -2084,6 +2101,12 @@ static int resp_write_same(struct scsi_cmnd *scmd, unsigned long long lba,
2084 if (ret) 2101 if (ret)
2085 return ret; 2102 return ret;
2086 2103
2104 if (num > scsi_debug_write_same_length) {
2105 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
2106 0);
2107 return check_condition_result;
2108 }
2109
2087 write_lock_irqsave(&atomic_rw, iflags); 2110 write_lock_irqsave(&atomic_rw, iflags);
2088 2111
2089 if (unmap && scsi_debug_unmap_granularity) { 2112 if (unmap && scsi_debug_unmap_granularity) {
@@ -2695,37 +2718,40 @@ static int schedule_resp(struct scsi_cmnd * cmnd,
2695 /sys/bus/pseudo/drivers/scsi_debug directory is changed. 2718 /sys/bus/pseudo/drivers/scsi_debug directory is changed.
2696 */ 2719 */
2697module_param_named(add_host, scsi_debug_add_host, int, S_IRUGO | S_IWUSR); 2720module_param_named(add_host, scsi_debug_add_host, int, S_IRUGO | S_IWUSR);
2721module_param_named(ato, scsi_debug_ato, int, S_IRUGO);
2698module_param_named(delay, scsi_debug_delay, int, S_IRUGO | S_IWUSR); 2722module_param_named(delay, scsi_debug_delay, int, S_IRUGO | S_IWUSR);
2699module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, S_IRUGO); 2723module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, S_IRUGO);
2724module_param_named(dif, scsi_debug_dif, int, S_IRUGO);
2725module_param_named(dix, scsi_debug_dix, int, S_IRUGO);
2700module_param_named(dsense, scsi_debug_dsense, int, S_IRUGO | S_IWUSR); 2726module_param_named(dsense, scsi_debug_dsense, int, S_IRUGO | S_IWUSR);
2701module_param_named(every_nth, scsi_debug_every_nth, int, S_IRUGO | S_IWUSR); 2727module_param_named(every_nth, scsi_debug_every_nth, int, S_IRUGO | S_IWUSR);
2702module_param_named(fake_rw, scsi_debug_fake_rw, int, S_IRUGO | S_IWUSR); 2728module_param_named(fake_rw, scsi_debug_fake_rw, int, S_IRUGO | S_IWUSR);
2729module_param_named(guard, scsi_debug_guard, int, S_IRUGO);
2730module_param_named(lbpu, scsi_debug_lbpu, int, S_IRUGO);
2731module_param_named(lbpws, scsi_debug_lbpws, int, S_IRUGO);
2732module_param_named(lbpws10, scsi_debug_lbpws10, int, S_IRUGO);
2733module_param_named(lowest_aligned, scsi_debug_lowest_aligned, int, S_IRUGO);
2703module_param_named(max_luns, scsi_debug_max_luns, int, S_IRUGO | S_IWUSR); 2734module_param_named(max_luns, scsi_debug_max_luns, int, S_IRUGO | S_IWUSR);
2704module_param_named(max_queue, scsi_debug_max_queue, int, S_IRUGO | S_IWUSR); 2735module_param_named(max_queue, scsi_debug_max_queue, int, S_IRUGO | S_IWUSR);
2705module_param_named(no_lun_0, scsi_debug_no_lun_0, int, S_IRUGO | S_IWUSR); 2736module_param_named(no_lun_0, scsi_debug_no_lun_0, int, S_IRUGO | S_IWUSR);
2706module_param_named(no_uld, scsi_debug_no_uld, int, S_IRUGO); 2737module_param_named(no_uld, scsi_debug_no_uld, int, S_IRUGO);
2707module_param_named(num_parts, scsi_debug_num_parts, int, S_IRUGO); 2738module_param_named(num_parts, scsi_debug_num_parts, int, S_IRUGO);
2708module_param_named(num_tgts, scsi_debug_num_tgts, int, S_IRUGO | S_IWUSR); 2739module_param_named(num_tgts, scsi_debug_num_tgts, int, S_IRUGO | S_IWUSR);
2740module_param_named(opt_blks, scsi_debug_opt_blks, int, S_IRUGO);
2709module_param_named(opts, scsi_debug_opts, int, S_IRUGO | S_IWUSR); 2741module_param_named(opts, scsi_debug_opts, int, S_IRUGO | S_IWUSR);
2742module_param_named(physblk_exp, scsi_debug_physblk_exp, int, S_IRUGO);
2710module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR); 2743module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR);
2711module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO); 2744module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO);
2712module_param_named(virtual_gb, scsi_debug_virtual_gb, int, S_IRUGO | S_IWUSR);
2713module_param_named(vpd_use_hostno, scsi_debug_vpd_use_hostno, int,
2714 S_IRUGO | S_IWUSR);
2715module_param_named(sector_size, scsi_debug_sector_size, int, S_IRUGO); 2745module_param_named(sector_size, scsi_debug_sector_size, int, S_IRUGO);
2716module_param_named(dix, scsi_debug_dix, int, S_IRUGO); 2746module_param_named(unmap_alignment, scsi_debug_unmap_alignment, int, S_IRUGO);
2717module_param_named(dif, scsi_debug_dif, int, S_IRUGO); 2747module_param_named(unmap_granularity, scsi_debug_unmap_granularity, int, S_IRUGO);
2718module_param_named(guard, scsi_debug_guard, int, S_IRUGO);
2719module_param_named(ato, scsi_debug_ato, int, S_IRUGO);
2720module_param_named(physblk_exp, scsi_debug_physblk_exp, int, S_IRUGO);
2721module_param_named(opt_blks, scsi_debug_opt_blks, int, S_IRUGO);
2722module_param_named(lowest_aligned, scsi_debug_lowest_aligned, int, S_IRUGO);
2723module_param_named(unmap_max_blocks, scsi_debug_unmap_max_blocks, int, S_IRUGO); 2748module_param_named(unmap_max_blocks, scsi_debug_unmap_max_blocks, int, S_IRUGO);
2724module_param_named(unmap_max_desc, scsi_debug_unmap_max_desc, int, S_IRUGO); 2749module_param_named(unmap_max_desc, scsi_debug_unmap_max_desc, int, S_IRUGO);
2725module_param_named(unmap_granularity, scsi_debug_unmap_granularity, int, S_IRUGO); 2750module_param_named(virtual_gb, scsi_debug_virtual_gb, int, S_IRUGO | S_IWUSR);
2726module_param_named(unmap_alignment, scsi_debug_unmap_alignment, int, S_IRUGO); 2751module_param_named(vpd_use_hostno, scsi_debug_vpd_use_hostno, int,
2727module_param_named(tpu, scsi_debug_tpu, int, S_IRUGO); 2752 S_IRUGO | S_IWUSR);
2728module_param_named(tpws, scsi_debug_tpws, int, S_IRUGO); 2753module_param_named(write_same_length, scsi_debug_write_same_length, int,
2754 S_IRUGO | S_IWUSR);
2729 2755
2730MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); 2756MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert");
2731MODULE_DESCRIPTION("SCSI debug adapter driver"); 2757MODULE_DESCRIPTION("SCSI debug adapter driver");
@@ -2733,36 +2759,38 @@ MODULE_LICENSE("GPL");
2733MODULE_VERSION(SCSI_DEBUG_VERSION); 2759MODULE_VERSION(SCSI_DEBUG_VERSION);
2734 2760
2735MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)"); 2761MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)");
2762MODULE_PARM_DESC(ato, "application tag ownership: 0=disk 1=host (def=1)");
2736MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)"); 2763MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)");
2737MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs(def=8)"); 2764MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs(def=8)");
2765MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");
2766MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)");
2738MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)"); 2767MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)");
2739MODULE_PARM_DESC(every_nth, "timeout every nth command(def=0)"); 2768MODULE_PARM_DESC(every_nth, "timeout every nth command(def=0)");
2740MODULE_PARM_DESC(fake_rw, "fake reads/writes instead of copying (def=0)"); 2769MODULE_PARM_DESC(fake_rw, "fake reads/writes instead of copying (def=0)");
2770MODULE_PARM_DESC(guard, "protection checksum: 0=crc, 1=ip (def=0)");
2771MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)");
2772MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)");
2773MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)");
2774MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)");
2741MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)"); 2775MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)");
2742MODULE_PARM_DESC(max_queue, "max number of queued commands (1 to 255(def))"); 2776MODULE_PARM_DESC(max_queue, "max number of queued commands (1 to 255(def))");
2743MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)"); 2777MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
2744MODULE_PARM_DESC(no_uld, "stop ULD (e.g. sd driver) attaching (def=0))"); 2778MODULE_PARM_DESC(no_uld, "stop ULD (e.g. sd driver) attaching (def=0))");
2745MODULE_PARM_DESC(num_parts, "number of partitions(def=0)"); 2779MODULE_PARM_DESC(num_parts, "number of partitions(def=0)");
2746MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)"); 2780MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)");
2781MODULE_PARM_DESC(opt_blks, "optimal transfer length in block (def=64)");
2747MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)"); 2782MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
2783MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
2748MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); 2784MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
2749MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); 2785MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])");
2750MODULE_PARM_DESC(virtual_gb, "virtual gigabyte size (def=0 -> use dev_size_mb)");
2751MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
2752MODULE_PARM_DESC(sector_size, "logical block size in bytes (def=512)"); 2786MODULE_PARM_DESC(sector_size, "logical block size in bytes (def=512)");
2753MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)"); 2787MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)");
2754MODULE_PARM_DESC(opt_blks, "optimal transfer length in block (def=64)"); 2788MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)");
2755MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)");
2756MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)");
2757MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");
2758MODULE_PARM_DESC(guard, "protection checksum: 0=crc, 1=ip (def=0)");
2759MODULE_PARM_DESC(ato, "application tag ownership: 0=disk 1=host (def=1)");
2760MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)"); 2789MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)");
2761MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)"); 2790MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)");
2762MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)"); 2791MODULE_PARM_DESC(virtual_gb, "virtual gigabyte size (def=0 -> use dev_size_mb)");
2763MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)"); 2792MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
2764MODULE_PARM_DESC(tpu, "enable TP, support UNMAP command (def=0)"); 2793MODULE_PARM_DESC(write_same_length, "Maximum blocks per WRITE SAME cmd (def=0xffff)");
2765MODULE_PARM_DESC(tpws, "enable TP, support WRITE SAME(16) with UNMAP bit (def=0)");
2766 2794
2767static char sdebug_info[256]; 2795static char sdebug_info[256];
2768 2796
@@ -3150,7 +3178,7 @@ static ssize_t sdebug_map_show(struct device_driver *ddp, char *buf)
3150{ 3178{
3151 ssize_t count; 3179 ssize_t count;
3152 3180
3153 if (scsi_debug_tpu == 0 && scsi_debug_tpws == 0) 3181 if (!scsi_debug_lbp())
3154 return scnprintf(buf, PAGE_SIZE, "0-%u\n", 3182 return scnprintf(buf, PAGE_SIZE, "0-%u\n",
3155 sdebug_store_sectors); 3183 sdebug_store_sectors);
3156 3184
@@ -3333,8 +3361,8 @@ static int __init scsi_debug_init(void)
3333 memset(dif_storep, 0xff, dif_size); 3361 memset(dif_storep, 0xff, dif_size);
3334 } 3362 }
3335 3363
3336 /* Thin Provisioning */ 3364 /* Logical Block Provisioning */
3337 if (scsi_debug_tpu || scsi_debug_tpws) { 3365 if (scsi_debug_lbp()) {
3338 unsigned int map_bytes; 3366 unsigned int map_bytes;
3339 3367
3340 scsi_debug_unmap_max_blocks = 3368 scsi_debug_unmap_max_blocks =
@@ -3664,7 +3692,7 @@ int scsi_debug_queuecommand_lck(struct scsi_cmnd *SCpnt, done_funct_t done)
3664 errsts = resp_readcap16(SCpnt, devip); 3692 errsts = resp_readcap16(SCpnt, devip);
3665 else if (cmd[1] == SAI_GET_LBA_STATUS) { 3693 else if (cmd[1] == SAI_GET_LBA_STATUS) {
3666 3694
3667 if (scsi_debug_tpu == 0 && scsi_debug_tpws == 0) { 3695 if (scsi_debug_lbp() == 0) {
3668 mk_sense_buffer(devip, ILLEGAL_REQUEST, 3696 mk_sense_buffer(devip, ILLEGAL_REQUEST,
3669 INVALID_COMMAND_OPCODE, 0); 3697 INVALID_COMMAND_OPCODE, 0);
3670 errsts = check_condition_result; 3698 errsts = check_condition_result;
@@ -3775,8 +3803,10 @@ write:
3775 } 3803 }
3776 break; 3804 break;
3777 case WRITE_SAME_16: 3805 case WRITE_SAME_16:
3806 case WRITE_SAME:
3778 if (cmd[1] & 0x8) { 3807 if (cmd[1] & 0x8) {
3779 if (scsi_debug_tpws == 0) { 3808 if ((*cmd == WRITE_SAME_16 && scsi_debug_lbpws == 0) ||
3809 (*cmd == WRITE_SAME && scsi_debug_lbpws10 == 0)) {
3780 mk_sense_buffer(devip, ILLEGAL_REQUEST, 3810 mk_sense_buffer(devip, ILLEGAL_REQUEST,
3781 INVALID_FIELD_IN_CDB, 0); 3811 INVALID_FIELD_IN_CDB, 0);
3782 errsts = check_condition_result; 3812 errsts = check_condition_result;
@@ -3785,8 +3815,6 @@ write:
3785 } 3815 }
3786 if (errsts) 3816 if (errsts)
3787 break; 3817 break;
3788 /* fall through */
3789 case WRITE_SAME:
3790 errsts = check_readiness(SCpnt, 0, devip); 3818 errsts = check_readiness(SCpnt, 0, devip);
3791 if (errsts) 3819 if (errsts)
3792 break; 3820 break;
@@ -3798,7 +3826,7 @@ write:
3798 if (errsts) 3826 if (errsts)
3799 break; 3827 break;
3800 3828
3801 if (scsi_debug_unmap_max_desc == 0 || scsi_debug_tpu == 0) { 3829 if (scsi_debug_unmap_max_desc == 0 || scsi_debug_lbpu == 0) {
3802 mk_sense_buffer(devip, ILLEGAL_REQUEST, 3830 mk_sense_buffer(devip, ILLEGAL_REQUEST,
3803 INVALID_COMMAND_OPCODE, 0); 3831 INVALID_COMMAND_OPCODE, 0);
3804 errsts = check_condition_result; 3832 errsts = check_condition_result;
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 43fad4c09beb..82e9e5c0476e 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -382,6 +382,91 @@ int scsi_dev_info_list_add_keyed(int compatible, char *vendor, char *model,
382EXPORT_SYMBOL(scsi_dev_info_list_add_keyed); 382EXPORT_SYMBOL(scsi_dev_info_list_add_keyed);
383 383
384/** 384/**
385 * scsi_dev_info_list_del_keyed - remove one dev_info list entry.
386 * @vendor: vendor string
387 * @model: model (product) string
388 * @key: specify list to use
389 *
390 * Description:
391 * Remove and destroy one dev_info entry for @vendor, @model
392 * in list specified by @key.
393 *
394 * Returns: 0 OK, -error on failure.
395 **/
396int scsi_dev_info_list_del_keyed(char *vendor, char *model, int key)
397{
398 struct scsi_dev_info_list *devinfo, *found = NULL;
399 struct scsi_dev_info_list_table *devinfo_table =
400 scsi_devinfo_lookup_by_key(key);
401
402 if (IS_ERR(devinfo_table))
403 return PTR_ERR(devinfo_table);
404
405 list_for_each_entry(devinfo, &devinfo_table->scsi_dev_info_list,
406 dev_info_list) {
407 if (devinfo->compatible) {
408 /*
409 * Behave like the older version of get_device_flags.
410 */
411 size_t max;
412 /*
413 * XXX why skip leading spaces? If an odd INQUIRY
414 * value, that should have been part of the
415 * scsi_static_device_list[] entry, such as " FOO"
416 * rather than "FOO". Since this code is already
417 * here, and we don't know what device it is
418 * trying to work with, leave it as-is.
419 */
420 max = 8; /* max length of vendor */
421 while ((max > 0) && *vendor == ' ') {
422 max--;
423 vendor++;
424 }
425 /*
426 * XXX removing the following strlen() would be
427 * good, using it means that for a an entry not in
428 * the list, we scan every byte of every vendor
429 * listed in scsi_static_device_list[], and never match
430 * a single one (and still have to compare at
431 * least the first byte of each vendor).
432 */
433 if (memcmp(devinfo->vendor, vendor,
434 min(max, strlen(devinfo->vendor))))
435 continue;
436 /*
437 * Skip spaces again.
438 */
439 max = 16; /* max length of model */
440 while ((max > 0) && *model == ' ') {
441 max--;
442 model++;
443 }
444 if (memcmp(devinfo->model, model,
445 min(max, strlen(devinfo->model))))
446 continue;
447 found = devinfo;
448 } else {
449 if (!memcmp(devinfo->vendor, vendor,
450 sizeof(devinfo->vendor)) &&
451 !memcmp(devinfo->model, model,
452 sizeof(devinfo->model)))
453 found = devinfo;
454 }
455 if (found)
456 break;
457 }
458
459 if (found) {
460 list_del(&found->dev_info_list);
461 kfree(found);
462 return 0;
463 }
464
465 return -ENOENT;
466}
467EXPORT_SYMBOL(scsi_dev_info_list_del_keyed);
468
469/**
385 * scsi_dev_info_list_add_str - parse dev_list and add to the scsi_dev_info_list. 470 * scsi_dev_info_list_add_str - parse dev_list and add to the scsi_dev_info_list.
386 * @dev_list: string of device flags to add 471 * @dev_list: string of device flags to add
387 * 472 *
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 45c75649b9e0..991de3c15cfc 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -223,7 +223,7 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
223 * @scmd: Cmd to have sense checked. 223 * @scmd: Cmd to have sense checked.
224 * 224 *
225 * Return value: 225 * Return value:
226 * SUCCESS or FAILED or NEEDS_RETRY 226 * SUCCESS or FAILED or NEEDS_RETRY or TARGET_ERROR
227 * 227 *
228 * Notes: 228 * Notes:
229 * When a deferred error is detected the current command has 229 * When a deferred error is detected the current command has
@@ -326,17 +326,19 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
326 */ 326 */
327 return SUCCESS; 327 return SUCCESS;
328 328
329 /* these three are not supported */ 329 /* these are not supported */
330 case COPY_ABORTED: 330 case COPY_ABORTED:
331 case VOLUME_OVERFLOW: 331 case VOLUME_OVERFLOW:
332 case MISCOMPARE: 332 case MISCOMPARE:
333 return SUCCESS; 333 case BLANK_CHECK:
334 case DATA_PROTECT:
335 return TARGET_ERROR;
334 336
335 case MEDIUM_ERROR: 337 case MEDIUM_ERROR:
336 if (sshdr.asc == 0x11 || /* UNRECOVERED READ ERR */ 338 if (sshdr.asc == 0x11 || /* UNRECOVERED READ ERR */
337 sshdr.asc == 0x13 || /* AMNF DATA FIELD */ 339 sshdr.asc == 0x13 || /* AMNF DATA FIELD */
338 sshdr.asc == 0x14) { /* RECORD NOT FOUND */ 340 sshdr.asc == 0x14) { /* RECORD NOT FOUND */
339 return SUCCESS; 341 return TARGET_ERROR;
340 } 342 }
341 return NEEDS_RETRY; 343 return NEEDS_RETRY;
342 344
@@ -344,11 +346,9 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
344 if (scmd->device->retry_hwerror) 346 if (scmd->device->retry_hwerror)
345 return ADD_TO_MLQUEUE; 347 return ADD_TO_MLQUEUE;
346 else 348 else
347 return SUCCESS; 349 return TARGET_ERROR;
348 350
349 case ILLEGAL_REQUEST: 351 case ILLEGAL_REQUEST:
350 case BLANK_CHECK:
351 case DATA_PROTECT:
352 default: 352 default:
353 return SUCCESS; 353 return SUCCESS;
354 } 354 }
@@ -787,6 +787,7 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd,
787 case SUCCESS: 787 case SUCCESS:
788 case NEEDS_RETRY: 788 case NEEDS_RETRY:
789 case FAILED: 789 case FAILED:
790 case TARGET_ERROR:
790 break; 791 break;
791 case ADD_TO_MLQUEUE: 792 case ADD_TO_MLQUEUE:
792 rtn = NEEDS_RETRY; 793 rtn = NEEDS_RETRY;
@@ -1469,6 +1470,14 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
1469 rtn = scsi_check_sense(scmd); 1470 rtn = scsi_check_sense(scmd);
1470 if (rtn == NEEDS_RETRY) 1471 if (rtn == NEEDS_RETRY)
1471 goto maybe_retry; 1472 goto maybe_retry;
1473 else if (rtn == TARGET_ERROR) {
1474 /*
1475 * Need to modify host byte to signal a
1476 * permanent target failure
1477 */
1478 scmd->result |= (DID_TARGET_FAILURE << 16);
1479 rtn = SUCCESS;
1480 }
1472 /* if rtn == FAILED, we have no sense information; 1481 /* if rtn == FAILED, we have no sense information;
1473 * returning FAILED will wake the error handler thread 1482 * returning FAILED will wake the error handler thread
1474 * to collect the sense and redo the decide 1483 * to collect the sense and redo the decide
@@ -1486,6 +1495,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
1486 case RESERVATION_CONFLICT: 1495 case RESERVATION_CONFLICT:
1487 sdev_printk(KERN_INFO, scmd->device, 1496 sdev_printk(KERN_INFO, scmd->device,
1488 "reservation conflict\n"); 1497 "reservation conflict\n");
1498 scmd->result |= (DID_NEXUS_FAILURE << 16);
1489 return SUCCESS; /* causes immediate i/o error */ 1499 return SUCCESS; /* causes immediate i/o error */
1490 default: 1500 default:
1491 return FAILED; 1501 return FAILED;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index fb2bb35c62cb..2d63c8ad1442 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -667,6 +667,30 @@ void scsi_release_buffers(struct scsi_cmnd *cmd)
667} 667}
668EXPORT_SYMBOL(scsi_release_buffers); 668EXPORT_SYMBOL(scsi_release_buffers);
669 669
670static int __scsi_error_from_host_byte(struct scsi_cmnd *cmd, int result)
671{
672 int error = 0;
673
674 switch(host_byte(result)) {
675 case DID_TRANSPORT_FAILFAST:
676 error = -ENOLINK;
677 break;
678 case DID_TARGET_FAILURE:
679 cmd->result |= (DID_OK << 16);
680 error = -EREMOTEIO;
681 break;
682 case DID_NEXUS_FAILURE:
683 cmd->result |= (DID_OK << 16);
684 error = -EBADE;
685 break;
686 default:
687 error = -EIO;
688 break;
689 }
690
691 return error;
692}
693
670/* 694/*
671 * Function: scsi_io_completion() 695 * Function: scsi_io_completion()
672 * 696 *
@@ -737,7 +761,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
737 req->sense_len = len; 761 req->sense_len = len;
738 } 762 }
739 if (!sense_deferred) 763 if (!sense_deferred)
740 error = -EIO; 764 error = __scsi_error_from_host_byte(cmd, result);
741 } 765 }
742 766
743 req->resid_len = scsi_get_resid(cmd); 767 req->resid_len = scsi_get_resid(cmd);
@@ -796,7 +820,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
796 if (scsi_end_request(cmd, error, good_bytes, result == 0) == NULL) 820 if (scsi_end_request(cmd, error, good_bytes, result == 0) == NULL)
797 return; 821 return;
798 822
799 error = -EIO; 823 error = __scsi_error_from_host_byte(cmd, result);
800 824
801 if (host_byte(result) == DID_RESET) { 825 if (host_byte(result) == DID_RESET) {
802 /* Third party bus reset or reset for error recovery 826 /* Third party bus reset or reset for error recovery
@@ -843,6 +867,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
843 description = "Host Data Integrity Failure"; 867 description = "Host Data Integrity Failure";
844 action = ACTION_FAIL; 868 action = ACTION_FAIL;
845 error = -EILSEQ; 869 error = -EILSEQ;
870 /* INVALID COMMAND OPCODE or INVALID FIELD IN CDB */
871 } else if ((sshdr.asc == 0x20 || sshdr.asc == 0x24) &&
872 (cmd->cmnd[0] == UNMAP ||
873 cmd->cmnd[0] == WRITE_SAME_16 ||
874 cmd->cmnd[0] == WRITE_SAME)) {
875 description = "Discard failure";
876 action = ACTION_FAIL;
846 } else 877 } else
847 action = ACTION_FAIL; 878 action = ACTION_FAIL;
848 break; 879 break;
@@ -1038,6 +1069,7 @@ static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev,
1038 cmd->request = req; 1069 cmd->request = req;
1039 1070
1040 cmd->cmnd = req->cmd; 1071 cmd->cmnd = req->cmd;
1072 cmd->prot_op = SCSI_PROT_NORMAL;
1041 1073
1042 return cmd; 1074 return cmd;
1043} 1075}
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 342ee1a9c41d..2a588955423a 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -45,6 +45,7 @@ static inline void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
45enum { 45enum {
46 SCSI_DEVINFO_GLOBAL = 0, 46 SCSI_DEVINFO_GLOBAL = 0,
47 SCSI_DEVINFO_SPI, 47 SCSI_DEVINFO_SPI,
48 SCSI_DEVINFO_DH,
48}; 49};
49 50
50extern int scsi_get_device_flags(struct scsi_device *sdev, 51extern int scsi_get_device_flags(struct scsi_device *sdev,
@@ -56,6 +57,7 @@ extern int scsi_get_device_flags_keyed(struct scsi_device *sdev,
56extern int scsi_dev_info_list_add_keyed(int compatible, char *vendor, 57extern int scsi_dev_info_list_add_keyed(int compatible, char *vendor,
57 char *model, char *strflags, 58 char *model, char *strflags,
58 int flags, int key); 59 int flags, int key);
60extern int scsi_dev_info_list_del_keyed(char *vendor, char *model, int key);
59extern int scsi_dev_info_add_list(int key, const char *name); 61extern int scsi_dev_info_add_list(int key, const char *name);
60extern int scsi_dev_info_remove_list(int key); 62extern int scsi_dev_info_remove_list(int key);
61 63
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index f905ecb5704d..b4218390941e 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -954,6 +954,7 @@ iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
954 if (dd_size) 954 if (dd_size)
955 conn->dd_data = &conn[1]; 955 conn->dd_data = &conn[1];
956 956
957 mutex_init(&conn->ep_mutex);
957 INIT_LIST_HEAD(&conn->conn_list); 958 INIT_LIST_HEAD(&conn->conn_list);
958 conn->transport = transport; 959 conn->transport = transport;
959 conn->cid = cid; 960 conn->cid = cid;
@@ -975,7 +976,6 @@ iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
975 976
976 spin_lock_irqsave(&connlock, flags); 977 spin_lock_irqsave(&connlock, flags);
977 list_add(&conn->conn_list, &connlist); 978 list_add(&conn->conn_list, &connlist);
978 conn->active = 1;
979 spin_unlock_irqrestore(&connlock, flags); 979 spin_unlock_irqrestore(&connlock, flags);
980 980
981 ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n"); 981 ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n");
@@ -1001,7 +1001,6 @@ int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
1001 unsigned long flags; 1001 unsigned long flags;
1002 1002
1003 spin_lock_irqsave(&connlock, flags); 1003 spin_lock_irqsave(&connlock, flags);
1004 conn->active = 0;
1005 list_del(&conn->conn_list); 1004 list_del(&conn->conn_list);
1006 spin_unlock_irqrestore(&connlock, flags); 1005 spin_unlock_irqrestore(&connlock, flags);
1007 1006
@@ -1430,6 +1429,29 @@ release_host:
1430 return err; 1429 return err;
1431} 1430}
1432 1431
1432static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
1433 u64 ep_handle)
1434{
1435 struct iscsi_cls_conn *conn;
1436 struct iscsi_endpoint *ep;
1437
1438 if (!transport->ep_disconnect)
1439 return -EINVAL;
1440
1441 ep = iscsi_lookup_endpoint(ep_handle);
1442 if (!ep)
1443 return -EINVAL;
1444 conn = ep->conn;
1445 if (conn) {
1446 mutex_lock(&conn->ep_mutex);
1447 conn->ep = NULL;
1448 mutex_unlock(&conn->ep_mutex);
1449 }
1450
1451 transport->ep_disconnect(ep);
1452 return 0;
1453}
1454
1433static int 1455static int
1434iscsi_if_transport_ep(struct iscsi_transport *transport, 1456iscsi_if_transport_ep(struct iscsi_transport *transport,
1435 struct iscsi_uevent *ev, int msg_type) 1457 struct iscsi_uevent *ev, int msg_type)
@@ -1454,14 +1476,8 @@ iscsi_if_transport_ep(struct iscsi_transport *transport,
1454 ev->u.ep_poll.timeout_ms); 1476 ev->u.ep_poll.timeout_ms);
1455 break; 1477 break;
1456 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: 1478 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
1457 if (!transport->ep_disconnect) 1479 rc = iscsi_if_ep_disconnect(transport,
1458 return -EINVAL; 1480 ev->u.ep_disconnect.ep_handle);
1459
1460 ep = iscsi_lookup_endpoint(ev->u.ep_disconnect.ep_handle);
1461 if (!ep)
1462 return -EINVAL;
1463
1464 transport->ep_disconnect(ep);
1465 break; 1481 break;
1466 } 1482 }
1467 return rc; 1483 return rc;
@@ -1609,12 +1625,31 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
1609 session = iscsi_session_lookup(ev->u.b_conn.sid); 1625 session = iscsi_session_lookup(ev->u.b_conn.sid);
1610 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid); 1626 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
1611 1627
1612 if (session && conn) 1628 if (conn && conn->ep)
1613 ev->r.retcode = transport->bind_conn(session, conn, 1629 iscsi_if_ep_disconnect(transport, conn->ep->id);
1614 ev->u.b_conn.transport_eph, 1630
1615 ev->u.b_conn.is_leading); 1631 if (!session || !conn) {
1616 else
1617 err = -EINVAL; 1632 err = -EINVAL;
1633 break;
1634 }
1635
1636 ev->r.retcode = transport->bind_conn(session, conn,
1637 ev->u.b_conn.transport_eph,
1638 ev->u.b_conn.is_leading);
1639 if (ev->r.retcode || !transport->ep_connect)
1640 break;
1641
1642 ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph);
1643 if (ep) {
1644 ep->conn = conn;
1645
1646 mutex_lock(&conn->ep_mutex);
1647 conn->ep = ep;
1648 mutex_unlock(&conn->ep_mutex);
1649 } else
1650 iscsi_cls_conn_printk(KERN_ERR, conn,
1651 "Could not set ep conn "
1652 "binding\n");
1618 break; 1653 break;
1619 case ISCSI_UEVENT_SET_PARAM: 1654 case ISCSI_UEVENT_SET_PARAM:
1620 err = iscsi_set_param(transport, ev); 1655 err = iscsi_set_param(transport, ev);
@@ -1747,13 +1782,48 @@ iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
1747iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN); 1782iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
1748iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN); 1783iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
1749iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT); 1784iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
1750iscsi_conn_attr(port, ISCSI_PARAM_CONN_PORT);
1751iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN); 1785iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
1752iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS); 1786iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
1753iscsi_conn_attr(address, ISCSI_PARAM_CONN_ADDRESS);
1754iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO); 1787iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
1755iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO); 1788iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
1756 1789
1790#define iscsi_conn_ep_attr_show(param) \
1791static ssize_t show_conn_ep_param_##param(struct device *dev, \
1792 struct device_attribute *attr,\
1793 char *buf) \
1794{ \
1795 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
1796 struct iscsi_transport *t = conn->transport; \
1797 struct iscsi_endpoint *ep; \
1798 ssize_t rc; \
1799 \
1800 /* \
1801 * Need to make sure ep_disconnect does not free the LLD's \
1802 * interconnect resources while we are trying to read them. \
1803 */ \
1804 mutex_lock(&conn->ep_mutex); \
1805 ep = conn->ep; \
1806 if (!ep && t->ep_connect) { \
1807 mutex_unlock(&conn->ep_mutex); \
1808 return -ENOTCONN; \
1809 } \
1810 \
1811 if (ep) \
1812 rc = t->get_ep_param(ep, param, buf); \
1813 else \
1814 rc = t->get_conn_param(conn, param, buf); \
1815 mutex_unlock(&conn->ep_mutex); \
1816 return rc; \
1817}
1818
1819#define iscsi_conn_ep_attr(field, param) \
1820 iscsi_conn_ep_attr_show(param) \
1821static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
1822 show_conn_ep_param_##param, NULL);
1823
1824iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS);
1825iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT);
1826
1757/* 1827/*
1758 * iSCSI session attrs 1828 * iSCSI session attrs
1759 */ 1829 */
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index e56730214c05..3be5db5d6343 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -96,6 +96,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC);
96#define SD_MINORS 0 96#define SD_MINORS 0
97#endif 97#endif
98 98
99static void sd_config_discard(struct scsi_disk *, unsigned int);
99static int sd_revalidate_disk(struct gendisk *); 100static int sd_revalidate_disk(struct gendisk *);
100static void sd_unlock_native_capacity(struct gendisk *disk); 101static void sd_unlock_native_capacity(struct gendisk *disk);
101static int sd_probe(struct device *); 102static int sd_probe(struct device *);
@@ -294,7 +295,54 @@ sd_show_thin_provisioning(struct device *dev, struct device_attribute *attr,
294{ 295{
295 struct scsi_disk *sdkp = to_scsi_disk(dev); 296 struct scsi_disk *sdkp = to_scsi_disk(dev);
296 297
297 return snprintf(buf, 20, "%u\n", sdkp->thin_provisioning); 298 return snprintf(buf, 20, "%u\n", sdkp->lbpme);
299}
300
301static const char *lbp_mode[] = {
302 [SD_LBP_FULL] = "full",
303 [SD_LBP_UNMAP] = "unmap",
304 [SD_LBP_WS16] = "writesame_16",
305 [SD_LBP_WS10] = "writesame_10",
306 [SD_LBP_ZERO] = "writesame_zero",
307 [SD_LBP_DISABLE] = "disabled",
308};
309
310static ssize_t
311sd_show_provisioning_mode(struct device *dev, struct device_attribute *attr,
312 char *buf)
313{
314 struct scsi_disk *sdkp = to_scsi_disk(dev);
315
316 return snprintf(buf, 20, "%s\n", lbp_mode[sdkp->provisioning_mode]);
317}
318
319static ssize_t
320sd_store_provisioning_mode(struct device *dev, struct device_attribute *attr,
321 const char *buf, size_t count)
322{
323 struct scsi_disk *sdkp = to_scsi_disk(dev);
324 struct scsi_device *sdp = sdkp->device;
325
326 if (!capable(CAP_SYS_ADMIN))
327 return -EACCES;
328
329 if (sdp->type != TYPE_DISK)
330 return -EINVAL;
331
332 if (!strncmp(buf, lbp_mode[SD_LBP_UNMAP], 20))
333 sd_config_discard(sdkp, SD_LBP_UNMAP);
334 else if (!strncmp(buf, lbp_mode[SD_LBP_WS16], 20))
335 sd_config_discard(sdkp, SD_LBP_WS16);
336 else if (!strncmp(buf, lbp_mode[SD_LBP_WS10], 20))
337 sd_config_discard(sdkp, SD_LBP_WS10);
338 else if (!strncmp(buf, lbp_mode[SD_LBP_ZERO], 20))
339 sd_config_discard(sdkp, SD_LBP_ZERO);
340 else if (!strncmp(buf, lbp_mode[SD_LBP_DISABLE], 20))
341 sd_config_discard(sdkp, SD_LBP_DISABLE);
342 else
343 return -EINVAL;
344
345 return count;
298} 346}
299 347
300static struct device_attribute sd_disk_attrs[] = { 348static struct device_attribute sd_disk_attrs[] = {
@@ -309,6 +357,8 @@ static struct device_attribute sd_disk_attrs[] = {
309 __ATTR(protection_mode, S_IRUGO, sd_show_protection_mode, NULL), 357 __ATTR(protection_mode, S_IRUGO, sd_show_protection_mode, NULL),
310 __ATTR(app_tag_own, S_IRUGO, sd_show_app_tag_own, NULL), 358 __ATTR(app_tag_own, S_IRUGO, sd_show_app_tag_own, NULL),
311 __ATTR(thin_provisioning, S_IRUGO, sd_show_thin_provisioning, NULL), 359 __ATTR(thin_provisioning, S_IRUGO, sd_show_thin_provisioning, NULL),
360 __ATTR(provisioning_mode, S_IRUGO|S_IWUSR, sd_show_provisioning_mode,
361 sd_store_provisioning_mode),
312 __ATTR_NULL, 362 __ATTR_NULL,
313}; 363};
314 364
@@ -433,6 +483,49 @@ static void sd_prot_op(struct scsi_cmnd *scmd, unsigned int dif)
433 scsi_set_prot_type(scmd, dif); 483 scsi_set_prot_type(scmd, dif);
434} 484}
435 485
486static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
487{
488 struct request_queue *q = sdkp->disk->queue;
489 unsigned int logical_block_size = sdkp->device->sector_size;
490 unsigned int max_blocks = 0;
491
492 q->limits.discard_zeroes_data = sdkp->lbprz;
493 q->limits.discard_alignment = sdkp->unmap_alignment;
494 q->limits.discard_granularity =
495 max(sdkp->physical_block_size,
496 sdkp->unmap_granularity * logical_block_size);
497
498 switch (mode) {
499
500 case SD_LBP_DISABLE:
501 q->limits.max_discard_sectors = 0;
502 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
503 return;
504
505 case SD_LBP_UNMAP:
506 max_blocks = min_not_zero(sdkp->max_unmap_blocks, 0xffffffff);
507 break;
508
509 case SD_LBP_WS16:
510 max_blocks = min_not_zero(sdkp->max_ws_blocks, 0xffffffff);
511 break;
512
513 case SD_LBP_WS10:
514 max_blocks = min_not_zero(sdkp->max_ws_blocks, (u32)0xffff);
515 break;
516
517 case SD_LBP_ZERO:
518 max_blocks = min_not_zero(sdkp->max_ws_blocks, (u32)0xffff);
519 q->limits.discard_zeroes_data = 1;
520 break;
521 }
522
523 q->limits.max_discard_sectors = max_blocks * (logical_block_size >> 9);
524 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
525
526 sdkp->provisioning_mode = mode;
527}
528
436/** 529/**
437 * scsi_setup_discard_cmnd - unmap blocks on thinly provisioned device 530 * scsi_setup_discard_cmnd - unmap blocks on thinly provisioned device
438 * @sdp: scsi device to operate one 531 * @sdp: scsi device to operate one
@@ -449,6 +542,7 @@ static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
449 unsigned int nr_sectors = bio_sectors(bio); 542 unsigned int nr_sectors = bio_sectors(bio);
450 unsigned int len; 543 unsigned int len;
451 int ret; 544 int ret;
545 char *buf;
452 struct page *page; 546 struct page *page;
453 547
454 if (sdkp->device->sector_size == 4096) { 548 if (sdkp->device->sector_size == 4096) {
@@ -464,8 +558,9 @@ static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
464 if (!page) 558 if (!page)
465 return BLKPREP_DEFER; 559 return BLKPREP_DEFER;
466 560
467 if (sdkp->unmap) { 561 switch (sdkp->provisioning_mode) {
468 char *buf = page_address(page); 562 case SD_LBP_UNMAP:
563 buf = page_address(page);
469 564
470 rq->cmd_len = 10; 565 rq->cmd_len = 10;
471 rq->cmd[0] = UNMAP; 566 rq->cmd[0] = UNMAP;
@@ -477,7 +572,9 @@ static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
477 put_unaligned_be32(nr_sectors, &buf[16]); 572 put_unaligned_be32(nr_sectors, &buf[16]);
478 573
479 len = 24; 574 len = 24;
480 } else { 575 break;
576
577 case SD_LBP_WS16:
481 rq->cmd_len = 16; 578 rq->cmd_len = 16;
482 rq->cmd[0] = WRITE_SAME_16; 579 rq->cmd[0] = WRITE_SAME_16;
483 rq->cmd[1] = 0x8; /* UNMAP */ 580 rq->cmd[1] = 0x8; /* UNMAP */
@@ -485,11 +582,29 @@ static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
485 put_unaligned_be32(nr_sectors, &rq->cmd[10]); 582 put_unaligned_be32(nr_sectors, &rq->cmd[10]);
486 583
487 len = sdkp->device->sector_size; 584 len = sdkp->device->sector_size;
585 break;
586
587 case SD_LBP_WS10:
588 case SD_LBP_ZERO:
589 rq->cmd_len = 10;
590 rq->cmd[0] = WRITE_SAME;
591 if (sdkp->provisioning_mode == SD_LBP_WS10)
592 rq->cmd[1] = 0x8; /* UNMAP */
593 put_unaligned_be32(sector, &rq->cmd[2]);
594 put_unaligned_be16(nr_sectors, &rq->cmd[7]);
595
596 len = sdkp->device->sector_size;
597 break;
598
599 default:
600 goto out;
488 } 601 }
489 602
490 blk_add_request_payload(rq, page, len); 603 blk_add_request_payload(rq, page, len);
491 ret = scsi_setup_blk_pc_cmnd(sdp, rq); 604 ret = scsi_setup_blk_pc_cmnd(sdp, rq);
492 rq->buffer = page_address(page); 605 rq->buffer = page_address(page);
606
607out:
493 if (ret != BLKPREP_OK) { 608 if (ret != BLKPREP_OK) {
494 __free_page(page); 609 __free_page(page);
495 rq->buffer = NULL; 610 rq->buffer = NULL;
@@ -1251,12 +1366,10 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1251 struct scsi_disk *sdkp = scsi_disk(SCpnt->request->rq_disk); 1366 struct scsi_disk *sdkp = scsi_disk(SCpnt->request->rq_disk);
1252 int sense_valid = 0; 1367 int sense_valid = 0;
1253 int sense_deferred = 0; 1368 int sense_deferred = 0;
1369 unsigned char op = SCpnt->cmnd[0];
1254 1370
1255 if (SCpnt->request->cmd_flags & REQ_DISCARD) { 1371 if ((SCpnt->request->cmd_flags & REQ_DISCARD) && !result)
1256 if (!result) 1372 scsi_set_resid(SCpnt, 0);
1257 scsi_set_resid(SCpnt, 0);
1258 return good_bytes;
1259 }
1260 1373
1261 if (result) { 1374 if (result) {
1262 sense_valid = scsi_command_normalize_sense(SCpnt, &sshdr); 1375 sense_valid = scsi_command_normalize_sense(SCpnt, &sshdr);
@@ -1295,10 +1408,17 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1295 SCpnt->result = 0; 1408 SCpnt->result = 0;
1296 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); 1409 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1297 break; 1410 break;
1298 case ABORTED_COMMAND: /* DIF: Target detected corruption */ 1411 case ABORTED_COMMAND:
1299 case ILLEGAL_REQUEST: /* DIX: Host detected corruption */ 1412 if (sshdr.asc == 0x10) /* DIF: Target detected corruption */
1300 if (sshdr.asc == 0x10) 1413 good_bytes = sd_completed_bytes(SCpnt);
1414 break;
1415 case ILLEGAL_REQUEST:
1416 if (sshdr.asc == 0x10) /* DIX: Host detected corruption */
1301 good_bytes = sd_completed_bytes(SCpnt); 1417 good_bytes = sd_completed_bytes(SCpnt);
1418 /* INVALID COMMAND OPCODE or INVALID FIELD IN CDB */
1419 if ((sshdr.asc == 0x20 || sshdr.asc == 0x24) &&
1420 (op == UNMAP || op == WRITE_SAME_16 || op == WRITE_SAME))
1421 sd_config_discard(sdkp, SD_LBP_DISABLE);
1302 break; 1422 break;
1303 default: 1423 default:
1304 break; 1424 break;
@@ -1596,17 +1716,13 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
1596 sd_printk(KERN_NOTICE, sdkp, 1716 sd_printk(KERN_NOTICE, sdkp,
1597 "physical block alignment offset: %u\n", alignment); 1717 "physical block alignment offset: %u\n", alignment);
1598 1718
1599 if (buffer[14] & 0x80) { /* TPE */ 1719 if (buffer[14] & 0x80) { /* LBPME */
1600 struct request_queue *q = sdp->request_queue; 1720 sdkp->lbpme = 1;
1601 1721
1602 sdkp->thin_provisioning = 1; 1722 if (buffer[14] & 0x40) /* LBPRZ */
1603 q->limits.discard_granularity = sdkp->physical_block_size; 1723 sdkp->lbprz = 1;
1604 q->limits.max_discard_sectors = 0xffffffff;
1605 1724
1606 if (buffer[14] & 0x40) /* TPRZ */ 1725 sd_config_discard(sdkp, SD_LBP_WS16);
1607 q->limits.discard_zeroes_data = 1;
1608
1609 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
1610 } 1726 }
1611 1727
1612 sdkp->capacity = lba + 1; 1728 sdkp->capacity = lba + 1;
@@ -2091,7 +2207,6 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
2091 */ 2207 */
2092static void sd_read_block_limits(struct scsi_disk *sdkp) 2208static void sd_read_block_limits(struct scsi_disk *sdkp)
2093{ 2209{
2094 struct request_queue *q = sdkp->disk->queue;
2095 unsigned int sector_sz = sdkp->device->sector_size; 2210 unsigned int sector_sz = sdkp->device->sector_size;
2096 const int vpd_len = 64; 2211 const int vpd_len = 64;
2097 unsigned char *buffer = kmalloc(vpd_len, GFP_KERNEL); 2212 unsigned char *buffer = kmalloc(vpd_len, GFP_KERNEL);
@@ -2106,39 +2221,46 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
2106 blk_queue_io_opt(sdkp->disk->queue, 2221 blk_queue_io_opt(sdkp->disk->queue,
2107 get_unaligned_be32(&buffer[12]) * sector_sz); 2222 get_unaligned_be32(&buffer[12]) * sector_sz);
2108 2223
2109 /* Thin provisioning enabled and page length indicates TP support */ 2224 if (buffer[3] == 0x3c) {
2110 if (sdkp->thin_provisioning && buffer[3] == 0x3c) { 2225 unsigned int lba_count, desc_count;
2111 unsigned int lba_count, desc_count, granularity;
2112 2226
2113 lba_count = get_unaligned_be32(&buffer[20]); 2227 sdkp->max_ws_blocks =
2114 desc_count = get_unaligned_be32(&buffer[24]); 2228 (u32) min_not_zero(get_unaligned_be64(&buffer[36]),
2115 2229 (u64)0xffffffff);
2116 if (lba_count && desc_count) {
2117 if (sdkp->tpvpd && !sdkp->tpu)
2118 sdkp->unmap = 0;
2119 else
2120 sdkp->unmap = 1;
2121 }
2122 2230
2123 if (sdkp->tpvpd && !sdkp->tpu && !sdkp->tpws) { 2231 if (!sdkp->lbpme)
2124 sd_printk(KERN_ERR, sdkp, "Thin provisioning is " \
2125 "enabled but neither TPU, nor TPWS are " \
2126 "set. Disabling discard!\n");
2127 goto out; 2232 goto out;
2128 }
2129 2233
2130 if (lba_count) 2234 lba_count = get_unaligned_be32(&buffer[20]);
2131 q->limits.max_discard_sectors = 2235 desc_count = get_unaligned_be32(&buffer[24]);
2132 lba_count * sector_sz >> 9;
2133 2236
2134 granularity = get_unaligned_be32(&buffer[28]); 2237 if (lba_count && desc_count)
2238 sdkp->max_unmap_blocks = lba_count;
2135 2239
2136 if (granularity) 2240 sdkp->unmap_granularity = get_unaligned_be32(&buffer[28]);
2137 q->limits.discard_granularity = granularity * sector_sz;
2138 2241
2139 if (buffer[32] & 0x80) 2242 if (buffer[32] & 0x80)
2140 q->limits.discard_alignment = 2243 sdkp->unmap_alignment =
2141 get_unaligned_be32(&buffer[32]) & ~(1 << 31); 2244 get_unaligned_be32(&buffer[32]) & ~(1 << 31);
2245
2246 if (!sdkp->lbpvpd) { /* LBP VPD page not provided */
2247
2248 if (sdkp->max_unmap_blocks)
2249 sd_config_discard(sdkp, SD_LBP_UNMAP);
2250 else
2251 sd_config_discard(sdkp, SD_LBP_WS16);
2252
2253 } else { /* LBP VPD page tells us what to use */
2254
2255 if (sdkp->lbpu && sdkp->max_unmap_blocks)
2256 sd_config_discard(sdkp, SD_LBP_UNMAP);
2257 else if (sdkp->lbpws)
2258 sd_config_discard(sdkp, SD_LBP_WS16);
2259 else if (sdkp->lbpws10)
2260 sd_config_discard(sdkp, SD_LBP_WS10);
2261 else
2262 sd_config_discard(sdkp, SD_LBP_DISABLE);
2263 }
2142 } 2264 }
2143 2265
2144 out: 2266 out:
@@ -2172,15 +2294,15 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp)
2172} 2294}
2173 2295
2174/** 2296/**
2175 * sd_read_thin_provisioning - Query thin provisioning VPD page 2297 * sd_read_block_provisioning - Query provisioning VPD page
2176 * @disk: disk to query 2298 * @disk: disk to query
2177 */ 2299 */
2178static void sd_read_thin_provisioning(struct scsi_disk *sdkp) 2300static void sd_read_block_provisioning(struct scsi_disk *sdkp)
2179{ 2301{
2180 unsigned char *buffer; 2302 unsigned char *buffer;
2181 const int vpd_len = 8; 2303 const int vpd_len = 8;
2182 2304
2183 if (sdkp->thin_provisioning == 0) 2305 if (sdkp->lbpme == 0)
2184 return; 2306 return;
2185 2307
2186 buffer = kmalloc(vpd_len, GFP_KERNEL); 2308 buffer = kmalloc(vpd_len, GFP_KERNEL);
@@ -2188,9 +2310,10 @@ static void sd_read_thin_provisioning(struct scsi_disk *sdkp)
2188 if (!buffer || scsi_get_vpd_page(sdkp->device, 0xb2, buffer, vpd_len)) 2310 if (!buffer || scsi_get_vpd_page(sdkp->device, 0xb2, buffer, vpd_len))
2189 goto out; 2311 goto out;
2190 2312
2191 sdkp->tpvpd = 1; 2313 sdkp->lbpvpd = 1;
2192 sdkp->tpu = (buffer[5] >> 7) & 1; /* UNMAP */ 2314 sdkp->lbpu = (buffer[5] >> 7) & 1; /* UNMAP */
2193 sdkp->tpws = (buffer[5] >> 6) & 1; /* WRITE SAME(16) with UNMAP */ 2315 sdkp->lbpws = (buffer[5] >> 6) & 1; /* WRITE SAME(16) with UNMAP */
2316 sdkp->lbpws10 = (buffer[5] >> 5) & 1; /* WRITE SAME(10) with UNMAP */
2194 2317
2195 out: 2318 out:
2196 kfree(buffer); 2319 kfree(buffer);
@@ -2247,7 +2370,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
2247 sd_read_capacity(sdkp, buffer); 2370 sd_read_capacity(sdkp, buffer);
2248 2371
2249 if (sd_try_extended_inquiry(sdp)) { 2372 if (sd_try_extended_inquiry(sdp)) {
2250 sd_read_thin_provisioning(sdkp); 2373 sd_read_block_provisioning(sdkp);
2251 sd_read_block_limits(sdkp); 2374 sd_read_block_limits(sdkp);
2252 sd_read_block_characteristics(sdkp); 2375 sd_read_block_characteristics(sdkp);
2253 } 2376 }
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index c9d8f6ca49e2..6ad798bfd52a 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -43,6 +43,15 @@ enum {
43 SD_MEMPOOL_SIZE = 2, /* CDB pool size */ 43 SD_MEMPOOL_SIZE = 2, /* CDB pool size */
44}; 44};
45 45
46enum {
47 SD_LBP_FULL = 0, /* Full logical block provisioning */
48 SD_LBP_UNMAP, /* Use UNMAP command */
49 SD_LBP_WS16, /* Use WRITE SAME(16) with UNMAP bit */
50 SD_LBP_WS10, /* Use WRITE SAME(10) with UNMAP bit */
51 SD_LBP_ZERO, /* Use WRITE SAME(10) with zero payload */
52 SD_LBP_DISABLE, /* Discard disabled due to failed cmd */
53};
54
46struct scsi_disk { 55struct scsi_disk {
47 struct scsi_driver *driver; /* always &sd_template */ 56 struct scsi_driver *driver; /* always &sd_template */
48 struct scsi_device *device; 57 struct scsi_device *device;
@@ -50,21 +59,27 @@ struct scsi_disk {
50 struct gendisk *disk; 59 struct gendisk *disk;
51 atomic_t openers; 60 atomic_t openers;
52 sector_t capacity; /* size in 512-byte sectors */ 61 sector_t capacity; /* size in 512-byte sectors */
62 u32 max_ws_blocks;
63 u32 max_unmap_blocks;
64 u32 unmap_granularity;
65 u32 unmap_alignment;
53 u32 index; 66 u32 index;
54 unsigned int physical_block_size; 67 unsigned int physical_block_size;
55 u8 media_present; 68 u8 media_present;
56 u8 write_prot; 69 u8 write_prot;
57 u8 protection_type;/* Data Integrity Field */ 70 u8 protection_type;/* Data Integrity Field */
71 u8 provisioning_mode;
58 unsigned ATO : 1; /* state of disk ATO bit */ 72 unsigned ATO : 1; /* state of disk ATO bit */
59 unsigned WCE : 1; /* state of disk WCE bit */ 73 unsigned WCE : 1; /* state of disk WCE bit */
60 unsigned RCD : 1; /* state of disk RCD bit, unused */ 74 unsigned RCD : 1; /* state of disk RCD bit, unused */
61 unsigned DPOFUA : 1; /* state of disk DPOFUA bit */ 75 unsigned DPOFUA : 1; /* state of disk DPOFUA bit */
62 unsigned first_scan : 1; 76 unsigned first_scan : 1;
63 unsigned thin_provisioning : 1; 77 unsigned lbpme : 1;
64 unsigned unmap : 1; 78 unsigned lbprz : 1;
65 unsigned tpws : 1; 79 unsigned lbpu : 1;
66 unsigned tpu : 1; 80 unsigned lbpws : 1;
67 unsigned tpvpd : 1; 81 unsigned lbpws10 : 1;
82 unsigned lbpvpd : 1;
68}; 83};
69#define to_scsi_disk(obj) container_of(obj,struct scsi_disk,dev) 84#define to_scsi_disk(obj) container_of(obj,struct scsi_disk,dev)
70 85
diff --git a/drivers/target/target_core_cdb.c b/drivers/target/target_core_cdb.c
index 366080baf474..7f19c8b7b84c 100644
--- a/drivers/target/target_core_cdb.c
+++ b/drivers/target/target_core_cdb.c
@@ -667,7 +667,13 @@ target_emulate_readcapacity(struct se_cmd *cmd)
667{ 667{
668 struct se_device *dev = SE_DEV(cmd); 668 struct se_device *dev = SE_DEV(cmd);
669 unsigned char *buf = cmd->t_task->t_task_buf; 669 unsigned char *buf = cmd->t_task->t_task_buf;
670 u32 blocks = dev->transport->get_blocks(dev); 670 unsigned long long blocks_long = dev->transport->get_blocks(dev);
671 u32 blocks;
672
673 if (blocks_long >= 0x00000000ffffffff)
674 blocks = 0xffffffff;
675 else
676 blocks = (u32)blocks_long;
671 677
672 buf[0] = (blocks >> 24) & 0xff; 678 buf[0] = (blocks >> 24) & 0xff;
673 buf[1] = (blocks >> 16) & 0xff; 679 buf[1] = (blocks >> 16) & 0xff;
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 5b038d410e26..511e5ee809ef 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2079,6 +2079,8 @@
2079#define PCI_DEVICE_ID_TIGON3_5723 0x165b 2079#define PCI_DEVICE_ID_TIGON3_5723 0x165b
2080#define PCI_DEVICE_ID_TIGON3_5705M 0x165d 2080#define PCI_DEVICE_ID_TIGON3_5705M 0x165d
2081#define PCI_DEVICE_ID_TIGON3_5705M_2 0x165e 2081#define PCI_DEVICE_ID_TIGON3_5705M_2 0x165e
2082#define PCI_DEVICE_ID_NX2_57712 0x1662
2083#define PCI_DEVICE_ID_NX2_57712E 0x1663
2082#define PCI_DEVICE_ID_TIGON3_5714 0x1668 2084#define PCI_DEVICE_ID_TIGON3_5714 0x1668
2083#define PCI_DEVICE_ID_TIGON3_5714S 0x1669 2085#define PCI_DEVICE_ID_TIGON3_5714S 0x1669
2084#define PCI_DEVICE_ID_TIGON3_5780 0x166a 2086#define PCI_DEVICE_ID_TIGON3_5780 0x166a
diff --git a/include/scsi/fc/fc_ns.h b/include/scsi/fc/fc_ns.h
index 185015dd1166..f7751d53f1d3 100644
--- a/include/scsi/fc/fc_ns.h
+++ b/include/scsi/fc/fc_ns.h
@@ -41,6 +41,7 @@ enum fc_ns_req {
41 FC_NS_GI_A = 0x0101, /* get identifiers - scope */ 41 FC_NS_GI_A = 0x0101, /* get identifiers - scope */
42 FC_NS_GPN_ID = 0x0112, /* get port name by ID */ 42 FC_NS_GPN_ID = 0x0112, /* get port name by ID */
43 FC_NS_GNN_ID = 0x0113, /* get node name by ID */ 43 FC_NS_GNN_ID = 0x0113, /* get node name by ID */
44 FC_NS_GSPN_ID = 0x0118, /* get symbolic port name */
44 FC_NS_GID_PN = 0x0121, /* get ID for port name */ 45 FC_NS_GID_PN = 0x0121, /* get ID for port name */
45 FC_NS_GID_NN = 0x0131, /* get IDs for node name */ 46 FC_NS_GID_NN = 0x0131, /* get IDs for node name */
46 FC_NS_GID_FT = 0x0171, /* get IDs by FC4 type */ 47 FC_NS_GID_FT = 0x0171, /* get IDs by FC4 type */
@@ -144,7 +145,7 @@ struct fc_ns_gid_pn {
144}; 145};
145 146
146/* 147/*
147 * GID_PN response 148 * GID_PN response or GSPN_ID request
148 */ 149 */
149struct fc_gid_pn_resp { 150struct fc_gid_pn_resp {
150 __u8 fp_resvd; 151 __u8 fp_resvd;
@@ -152,6 +153,14 @@ struct fc_gid_pn_resp {
152}; 153};
153 154
154/* 155/*
156 * GSPN_ID response
157 */
158struct fc_gspn_resp {
159 __u8 fp_name_len;
160 char fp_name[];
161};
162
163/*
155 * RFT_ID request - register FC-4 types for ID. 164 * RFT_ID request - register FC-4 types for ID.
156 */ 165 */
157struct fc_ns_rft_id { 166struct fc_ns_rft_id {
diff --git a/include/scsi/fc_encode.h b/include/scsi/fc_encode.h
index 6d293c846a46..be418d8448a5 100644
--- a/include/scsi/fc_encode.h
+++ b/include/scsi/fc_encode.h
@@ -46,16 +46,11 @@ struct fc_ct_req {
46 } payload; 46 } payload;
47}; 47};
48 48
49/** 49static inline void __fc_fill_fc_hdr(struct fc_frame_header *fh,
50 * fill FC header fields in specified fc_frame 50 enum fc_rctl r_ctl,
51 */ 51 u32 did, u32 sid, enum fc_fh_type type,
52static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl, 52 u32 f_ctl, u32 parm_offset)
53 u32 did, u32 sid, enum fc_fh_type type,
54 u32 f_ctl, u32 parm_offset)
55{ 53{
56 struct fc_frame_header *fh;
57
58 fh = fc_frame_header_get(fp);
59 WARN_ON(r_ctl == 0); 54 WARN_ON(r_ctl == 0);
60 fh->fh_r_ctl = r_ctl; 55 fh->fh_r_ctl = r_ctl;
61 hton24(fh->fh_d_id, did); 56 hton24(fh->fh_d_id, did);
@@ -68,6 +63,19 @@ static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
68} 63}
69 64
70/** 65/**
66 * fill FC header fields in specified fc_frame
67 */
68static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
69 u32 did, u32 sid, enum fc_fh_type type,
70 u32 f_ctl, u32 parm_offset)
71{
72 struct fc_frame_header *fh;
73
74 fh = fc_frame_header_get(fp);
75 __fc_fill_fc_hdr(fh, r_ctl, did, sid, type, f_ctl, parm_offset);
76}
77
78/**
71 * fc_adisc_fill() - Fill in adisc request frame 79 * fc_adisc_fill() - Fill in adisc request frame
72 * @lport: local port. 80 * @lport: local port.
73 * @fp: fc frame where payload will be placed. 81 * @fp: fc frame where payload will be placed.
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
index f53c8e31d5fb..24193c1b0da0 100644
--- a/include/scsi/libfc.h
+++ b/include/scsi/libfc.h
@@ -35,6 +35,8 @@
35 35
36#include <scsi/fc_frame.h> 36#include <scsi/fc_frame.h>
37 37
38#define FC_FC4_PROV_SIZE (FC_TYPE_FCP + 1) /* size of tables */
39
38/* 40/*
39 * libfc error codes 41 * libfc error codes
40 */ 42 */
@@ -156,6 +158,7 @@ struct fc_rport_libfc_priv {
156 #define FC_RP_FLAGS_REC_SUPPORTED (1 << 0) 158 #define FC_RP_FLAGS_REC_SUPPORTED (1 << 0)
157 #define FC_RP_FLAGS_RETRY (1 << 1) 159 #define FC_RP_FLAGS_RETRY (1 << 1)
158 #define FC_RP_STARTED (1 << 2) 160 #define FC_RP_STARTED (1 << 2)
161 #define FC_RP_FLAGS_CONF_REQ (1 << 3)
159 unsigned int e_d_tov; 162 unsigned int e_d_tov;
160 unsigned int r_a_tov; 163 unsigned int r_a_tov;
161}; 164};
@@ -179,6 +182,7 @@ struct fc_rport_libfc_priv {
179 * @rp_mutex: The mutex that protects the remote port 182 * @rp_mutex: The mutex that protects the remote port
180 * @retry_work: Handle for retries 183 * @retry_work: Handle for retries
181 * @event_callback: Callback when READY, FAILED or LOGO states complete 184 * @event_callback: Callback when READY, FAILED or LOGO states complete
185 * @prli_count: Count of open PRLI sessions in providers
182 * @rcu: Structure used for freeing in an RCU-safe manner 186 * @rcu: Structure used for freeing in an RCU-safe manner
183 */ 187 */
184struct fc_rport_priv { 188struct fc_rport_priv {
@@ -202,7 +206,13 @@ struct fc_rport_priv {
202 struct list_head peers; 206 struct list_head peers;
203 struct work_struct event_work; 207 struct work_struct event_work;
204 u32 supported_classes; 208 u32 supported_classes;
209 u16 prli_count;
205 struct rcu_head rcu; 210 struct rcu_head rcu;
211 u16 sp_features;
212 u8 spp_type;
213 void (*lld_event_callback)(struct fc_lport *,
214 struct fc_rport_priv *,
215 enum fc_rport_event);
206}; 216};
207 217
208/** 218/**
@@ -551,6 +561,16 @@ struct libfc_function_template {
551 struct fc_seq *(*seq_start_next)(struct fc_seq *); 561 struct fc_seq *(*seq_start_next)(struct fc_seq *);
552 562
553 /* 563 /*
564 * Set a response handler for the exchange of the sequence.
565 *
566 * STATUS: OPTIONAL
567 */
568 void (*seq_set_resp)(struct fc_seq *sp,
569 void (*resp)(struct fc_seq *, struct fc_frame *,
570 void *),
571 void *arg);
572
573 /*
554 * Assign a sequence for an incoming request frame. 574 * Assign a sequence for an incoming request frame.
555 * 575 *
556 * STATUS: OPTIONAL 576 * STATUS: OPTIONAL
@@ -558,6 +578,13 @@ struct libfc_function_template {
558 struct fc_seq *(*seq_assign)(struct fc_lport *, struct fc_frame *); 578 struct fc_seq *(*seq_assign)(struct fc_lport *, struct fc_frame *);
559 579
560 /* 580 /*
581 * Release the reference on the sequence returned by seq_assign().
582 *
583 * STATUS: OPTIONAL
584 */
585 void (*seq_release)(struct fc_seq *);
586
587 /*
561 * Reset an exchange manager, completing all sequences and exchanges. 588 * Reset an exchange manager, completing all sequences and exchanges.
562 * If s_id is non-zero, reset only exchanges originating from that FID. 589 * If s_id is non-zero, reset only exchanges originating from that FID.
563 * If d_id is non-zero, reset only exchanges sending to that FID. 590 * If d_id is non-zero, reset only exchanges sending to that FID.
@@ -656,6 +683,15 @@ struct libfc_function_template {
656 void (*rport_destroy)(struct kref *); 683 void (*rport_destroy)(struct kref *);
657 684
658 /* 685 /*
686 * Callback routine after the remote port is logged in
687 *
688 * STATUS: OPTIONAL
689 */
690 void (*rport_event_callback)(struct fc_lport *,
691 struct fc_rport_priv *,
692 enum fc_rport_event);
693
694 /*
659 * Send a fcp cmd from fsp pkt. 695 * Send a fcp cmd from fsp pkt.
660 * Called with the SCSI host lock unlocked and irqs disabled. 696 * Called with the SCSI host lock unlocked and irqs disabled.
661 * 697 *
@@ -749,6 +785,15 @@ struct fc_disc {
749 enum fc_disc_event); 785 enum fc_disc_event);
750}; 786};
751 787
788/*
789 * Local port notifier and events.
790 */
791extern struct blocking_notifier_head fc_lport_notifier_head;
792enum fc_lport_event {
793 FC_LPORT_EV_ADD,
794 FC_LPORT_EV_DEL,
795};
796
752/** 797/**
753 * struct fc_lport - Local port 798 * struct fc_lport - Local port
754 * @host: The SCSI host associated with a local port 799 * @host: The SCSI host associated with a local port
@@ -789,8 +834,10 @@ struct fc_disc {
789 * @lso_max: The maximum large offload send size 834 * @lso_max: The maximum large offload send size
790 * @fcts: FC-4 type mask 835 * @fcts: FC-4 type mask
791 * @lp_mutex: Mutex to protect the local port 836 * @lp_mutex: Mutex to protect the local port
792 * @list: Handle for list of local ports 837 * @list: Linkage on list of vport peers
793 * @retry_work: Handle to local port for delayed retry context 838 * @retry_work: Handle to local port for delayed retry context
839 * @prov: Pointers available for use by passive FC-4 providers
840 * @lport_list: Linkage on module-wide list of local ports
794 */ 841 */
795struct fc_lport { 842struct fc_lport {
796 /* Associations */ 843 /* Associations */
@@ -846,8 +893,32 @@ struct fc_lport {
846 struct mutex lp_mutex; 893 struct mutex lp_mutex;
847 struct list_head list; 894 struct list_head list;
848 struct delayed_work retry_work; 895 struct delayed_work retry_work;
896 void *prov[FC_FC4_PROV_SIZE];
897 struct list_head lport_list;
849}; 898};
850 899
900/**
901 * struct fc4_prov - FC-4 provider registration
902 * @prli: Handler for incoming PRLI
903 * @prlo: Handler for session reset
904 * @recv: Handler for incoming request
905 * @module: Pointer to module. May be NULL.
906 */
907struct fc4_prov {
908 int (*prli)(struct fc_rport_priv *, u32 spp_len,
909 const struct fc_els_spp *spp_in,
910 struct fc_els_spp *spp_out);
911 void (*prlo)(struct fc_rport_priv *);
912 void (*recv)(struct fc_lport *, struct fc_frame *);
913 struct module *module;
914};
915
916/*
917 * Register FC-4 provider with libfc.
918 */
919int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *);
920void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *);
921
851/* 922/*
852 * FC_LPORT HELPER FUNCTIONS 923 * FC_LPORT HELPER FUNCTIONS
853 *****************************/ 924 *****************************/
@@ -978,6 +1049,7 @@ struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);
978struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id); 1049struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);
979int fc_lport_bsg_request(struct fc_bsg_job *); 1050int fc_lport_bsg_request(struct fc_bsg_job *);
980void fc_lport_set_local_id(struct fc_lport *, u32 port_id); 1051void fc_lport_set_local_id(struct fc_lport *, u32 port_id);
1052void fc_lport_iterate(void (*func)(struct fc_lport *, void *), void *);
981 1053
982/* 1054/*
983 * REMOTE PORT LAYER 1055 * REMOTE PORT LAYER
diff --git a/include/scsi/libfcoe.h b/include/scsi/libfcoe.h
index feb6a94c90ea..8c1638b8c28e 100644
--- a/include/scsi/libfcoe.h
+++ b/include/scsi/libfcoe.h
@@ -33,6 +33,12 @@
33#define FCOE_MAX_CMD_LEN 16 /* Supported CDB length */ 33#define FCOE_MAX_CMD_LEN 16 /* Supported CDB length */
34 34
35/* 35/*
36 * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload)
37 * + 4 (FC CRC) + 4 (FCoE trailer) = 2158 bytes
38 */
39#define FCOE_MTU 2158
40
41/*
36 * FIP tunable parameters. 42 * FIP tunable parameters.
37 */ 43 */
38#define FCOE_CTLR_START_DELAY 2000 /* mS after first adv. to choose FCF */ 44#define FCOE_CTLR_START_DELAY 2000 /* mS after first adv. to choose FCF */
@@ -221,6 +227,8 @@ int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *,
221u64 fcoe_wwn_from_mac(unsigned char mac[], unsigned int, unsigned int); 227u64 fcoe_wwn_from_mac(unsigned char mac[], unsigned int, unsigned int);
222int fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *, 228int fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *,
223 const struct libfc_function_template *, int init_fcp); 229 const struct libfc_function_template *, int init_fcp);
230u32 fcoe_fc_crc(struct fc_frame *fp);
231int fcoe_start_io(struct sk_buff *skb);
224 232
225/** 233/**
226 * is_fip_mode() - returns true if FIP mode selected. 234 * is_fip_mode() - returns true if FIP mode selected.
@@ -231,5 +239,102 @@ static inline bool is_fip_mode(struct fcoe_ctlr *fip)
231 return fip->state == FIP_ST_ENABLED; 239 return fip->state == FIP_ST_ENABLED;
232} 240}
233 241
242/* helper for FCoE SW HBA drivers, can include subven and subdev if needed. The
243 * modpost would use pci_device_id table to auto-generate formatted module alias
244 * into the corresponding .mod.c file, but there may or may not be a pci device
245 * id table for FCoE drivers so we use the following helper for build the fcoe
246 * driver module alias.
247 */
248#define MODULE_ALIAS_FCOE_PCI(ven, dev) \
249 MODULE_ALIAS("fcoe-pci:" \
250 "v" __stringify(ven) \
251 "d" __stringify(dev) "sv*sd*bc*sc*i*")
252
253/* the name of the default FCoE transport driver fcoe.ko */
254#define FCOE_TRANSPORT_DEFAULT "fcoe"
255
256/* struct fcoe_transport - The FCoE transport interface
257 * @name: a vendor specific name for their FCoE transport driver
258 * @attached: whether this transport is already attached
259 * @list: list linkage to all attached transports
260 * @match: handler to allow the transport driver to match up a given netdev
261 * @create: handler to sysfs entry of create for FCoE instances
262 * @destroy: handler to sysfs entry of destroy for FCoE instances
263 * @enable: handler to sysfs entry of enable for FCoE instances
264 * @disable: handler to sysfs entry of disable for FCoE instances
265 */
266struct fcoe_transport {
267 char name[IFNAMSIZ];
268 bool attached;
269 struct list_head list;
270 bool (*match) (struct net_device *device);
271 int (*create) (struct net_device *device, enum fip_state fip_mode);
272 int (*destroy) (struct net_device *device);
273 int (*enable) (struct net_device *device);
274 int (*disable) (struct net_device *device);
275};
276
277/**
278 * struct fcoe_percpu_s - The context for FCoE receive thread(s)
279 * @thread: The thread context
280 * @fcoe_rx_list: The queue of pending packets to process
281 * @page: The memory page for calculating frame trailer CRCs
282 * @crc_eof_offset: The offset into the CRC page pointing to available
283 * memory for a new trailer
284 */
285struct fcoe_percpu_s {
286 struct task_struct *thread;
287 struct sk_buff_head fcoe_rx_list;
288 struct page *crc_eof_page;
289 int crc_eof_offset;
290};
291
292/**
293 * struct fcoe_port - The FCoE private structure
294 * @priv: The associated fcoe interface. The structure is
295 * defined by the low level driver
296 * @lport: The associated local port
297 * @fcoe_pending_queue: The pending Rx queue of skbs
298 * @fcoe_pending_queue_active: Indicates if the pending queue is active
299 * @max_queue_depth: Max queue depth of pending queue
300 * @min_queue_depth: Min queue depth of pending queue
301 * @timer: The queue timer
302 * @destroy_work: Handle for work context
303 * (to prevent RTNL deadlocks)
304 * @data_srt_addr: Source address for data
305 *
306 * An instance of this structure is to be allocated along with the
307 * Scsi_Host and libfc fc_lport structures.
308 */
309struct fcoe_port {
310 void *priv;
311 struct fc_lport *lport;
312 struct sk_buff_head fcoe_pending_queue;
313 u8 fcoe_pending_queue_active;
314 u32 max_queue_depth;
315 u32 min_queue_depth;
316 struct timer_list timer;
317 struct work_struct destroy_work;
318 u8 data_src_addr[ETH_ALEN];
319};
320void fcoe_clean_pending_queue(struct fc_lport *);
321void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb);
322void fcoe_queue_timer(ulong lport);
323int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
324 struct fcoe_percpu_s *fps);
325
326/**
327 * struct netdev_list
328 * A mapping from netdevice to fcoe_transport
329 */
330struct fcoe_netdev_mapping {
331 struct list_head list;
332 struct net_device *netdev;
333 struct fcoe_transport *ft;
334};
335
336/* fcoe transports registration and deregistration */
337int fcoe_transport_attach(struct fcoe_transport *ft);
338int fcoe_transport_detach(struct fcoe_transport *ft);
234 339
235#endif /* _LIBFCOE_H */ 340#endif /* _LIBFCOE_H */
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index 748382b32b52..0f4367751b71 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -212,9 +212,6 @@ struct iscsi_conn {
212 /* values userspace uses to id a conn */ 212 /* values userspace uses to id a conn */
213 int persistent_port; 213 int persistent_port;
214 char *persistent_address; 214 char *persistent_address;
215 /* remote portal currently connected to */
216 int portal_port;
217 char portal_address[ISCSI_ADDRESS_BUF_LEN];
218 215
219 /* MIB-statistics */ 216 /* MIB-statistics */
220 uint64_t txdata_octets; 217 uint64_t txdata_octets;
@@ -319,9 +316,6 @@ struct iscsi_host {
319 /* hw address or netdev iscsi connection is bound to */ 316 /* hw address or netdev iscsi connection is bound to */
320 char *hwaddress; 317 char *hwaddress;
321 char *netdev; 318 char *netdev;
322 /* local address */
323 int local_port;
324 char local_address[ISCSI_ADDRESS_BUF_LEN];
325 319
326 wait_queue_head_t session_removal_wq; 320 wait_queue_head_t session_removal_wq;
327 /* protects sessions and state */ 321 /* protects sessions and state */
@@ -394,6 +388,8 @@ extern void iscsi_session_failure(struct iscsi_session *session,
394 enum iscsi_err err); 388 enum iscsi_err err);
395extern int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn, 389extern int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
396 enum iscsi_param param, char *buf); 390 enum iscsi_param param, char *buf);
391extern int iscsi_conn_get_addr_param(struct sockaddr_storage *addr,
392 enum iscsi_param param, char *buf);
397extern void iscsi_suspend_tx(struct iscsi_conn *conn); 393extern void iscsi_suspend_tx(struct iscsi_conn *conn);
398extern void iscsi_suspend_queue(struct iscsi_conn *conn); 394extern void iscsi_suspend_queue(struct iscsi_conn *conn);
399extern void iscsi_conn_queue_work(struct iscsi_conn *conn); 395extern void iscsi_conn_queue_work(struct iscsi_conn *conn);
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index b76d4006e36d..3668903e397b 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -435,6 +435,10 @@ static inline int scsi_is_wlun(unsigned int lun)
435 * recover the link. Transport class will 435 * recover the link. Transport class will
436 * retry or fail IO */ 436 * retry or fail IO */
437#define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */ 437#define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */
438#define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on
439 * other paths */
440#define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other
441 * paths might yield different results */
438#define DRIVER_OK 0x00 /* Driver status */ 442#define DRIVER_OK 0x00 /* Driver status */
439 443
440/* 444/*
@@ -464,6 +468,7 @@ static inline int scsi_is_wlun(unsigned int lun)
464#define TIMEOUT_ERROR 0x2007 468#define TIMEOUT_ERROR 0x2007
465#define SCSI_RETURN_NOT_HANDLED 0x2008 469#define SCSI_RETURN_NOT_HANDLED 0x2008
466#define FAST_IO_FAIL 0x2009 470#define FAST_IO_FAIL 0x2009
471#define TARGET_ERROR 0x200A
467 472
468/* 473/*
469 * Midlevel queue return values. 474 * Midlevel queue return values.
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 85867dcde335..f171c65dc5a8 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -184,6 +184,7 @@ typedef void (*activate_complete)(void *, int);
184struct scsi_device_handler { 184struct scsi_device_handler {
185 /* Used by the infrastructure */ 185 /* Used by the infrastructure */
186 struct list_head list; /* list of scsi_device_handlers */ 186 struct list_head list; /* list of scsi_device_handlers */
187 int idx;
187 188
188 /* Filled by the hardware handler */ 189 /* Filled by the hardware handler */
189 struct module *module; 190 struct module *module;
diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h
index 7fff94b3b2a8..bf8f52965675 100644
--- a/include/scsi/scsi_transport_iscsi.h
+++ b/include/scsi/scsi_transport_iscsi.h
@@ -101,6 +101,8 @@ struct iscsi_transport {
101 void (*destroy_conn) (struct iscsi_cls_conn *conn); 101 void (*destroy_conn) (struct iscsi_cls_conn *conn);
102 int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param, 102 int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param,
103 char *buf, int buflen); 103 char *buf, int buflen);
104 int (*get_ep_param) (struct iscsi_endpoint *ep, enum iscsi_param param,
105 char *buf);
104 int (*get_conn_param) (struct iscsi_cls_conn *conn, 106 int (*get_conn_param) (struct iscsi_cls_conn *conn,
105 enum iscsi_param param, char *buf); 107 enum iscsi_param param, char *buf);
106 int (*get_session_param) (struct iscsi_cls_session *session, 108 int (*get_session_param) (struct iscsi_cls_session *session,
@@ -160,8 +162,9 @@ struct iscsi_cls_conn {
160 void *dd_data; /* LLD private data */ 162 void *dd_data; /* LLD private data */
161 struct iscsi_transport *transport; 163 struct iscsi_transport *transport;
162 uint32_t cid; /* connection id */ 164 uint32_t cid; /* connection id */
165 struct mutex ep_mutex;
166 struct iscsi_endpoint *ep;
163 167
164 int active; /* must be accessed with the connlock */
165 struct device dev; /* sysfs transport/container device */ 168 struct device dev; /* sysfs transport/container device */
166}; 169};
167 170
@@ -222,6 +225,7 @@ struct iscsi_endpoint {
222 void *dd_data; /* LLD private data */ 225 void *dd_data; /* LLD private data */
223 struct device dev; 226 struct device dev;
224 uint64_t id; 227 uint64_t id;
228 struct iscsi_cls_conn *conn;
225}; 229};
226 230
227/* 231/*
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index 25fbefdf2f2e..db6c93510f74 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -184,6 +184,17 @@
184 scsi_statusbyte_name(SAM_STAT_ACA_ACTIVE), \ 184 scsi_statusbyte_name(SAM_STAT_ACA_ACTIVE), \
185 scsi_statusbyte_name(SAM_STAT_TASK_ABORTED)) 185 scsi_statusbyte_name(SAM_STAT_TASK_ABORTED))
186 186
187#define scsi_prot_op_name(result) { result, #result }
188#define show_prot_op_name(val) \
189 __print_symbolic(val, \
190 scsi_prot_op_name(SCSI_PROT_NORMAL), \
191 scsi_prot_op_name(SCSI_PROT_READ_INSERT), \
192 scsi_prot_op_name(SCSI_PROT_WRITE_STRIP), \
193 scsi_prot_op_name(SCSI_PROT_READ_STRIP), \
194 scsi_prot_op_name(SCSI_PROT_WRITE_INSERT), \
195 scsi_prot_op_name(SCSI_PROT_READ_PASS), \
196 scsi_prot_op_name(SCSI_PROT_WRITE_PASS))
197
187const char *scsi_trace_parse_cdb(struct trace_seq*, unsigned char*, int); 198const char *scsi_trace_parse_cdb(struct trace_seq*, unsigned char*, int);
188#define __parse_cdb(cdb, len) scsi_trace_parse_cdb(p, cdb, len) 199#define __parse_cdb(cdb, len) scsi_trace_parse_cdb(p, cdb, len)
189 200
@@ -202,6 +213,7 @@ TRACE_EVENT(scsi_dispatch_cmd_start,
202 __field( unsigned int, cmd_len ) 213 __field( unsigned int, cmd_len )
203 __field( unsigned int, data_sglen ) 214 __field( unsigned int, data_sglen )
204 __field( unsigned int, prot_sglen ) 215 __field( unsigned int, prot_sglen )
216 __field( unsigned char, prot_op )
205 __dynamic_array(unsigned char, cmnd, cmd->cmd_len) 217 __dynamic_array(unsigned char, cmnd, cmd->cmd_len)
206 ), 218 ),
207 219
@@ -214,13 +226,15 @@ TRACE_EVENT(scsi_dispatch_cmd_start,
214 __entry->cmd_len = cmd->cmd_len; 226 __entry->cmd_len = cmd->cmd_len;
215 __entry->data_sglen = scsi_sg_count(cmd); 227 __entry->data_sglen = scsi_sg_count(cmd);
216 __entry->prot_sglen = scsi_prot_sg_count(cmd); 228 __entry->prot_sglen = scsi_prot_sg_count(cmd);
229 __entry->prot_op = scsi_get_prot_op(cmd);
217 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len); 230 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len);
218 ), 231 ),
219 232
220 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u" \ 233 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u" \
221 " cmnd=(%s %s raw=%s)", 234 " prot_op=%s cmnd=(%s %s raw=%s)",
222 __entry->host_no, __entry->channel, __entry->id, 235 __entry->host_no, __entry->channel, __entry->id,
223 __entry->lun, __entry->data_sglen, __entry->prot_sglen, 236 __entry->lun, __entry->data_sglen, __entry->prot_sglen,
237 show_prot_op_name(__entry->prot_op),
224 show_opcode_name(__entry->opcode), 238 show_opcode_name(__entry->opcode),
225 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len), 239 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len),
226 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len)) 240 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len))
@@ -242,6 +256,7 @@ TRACE_EVENT(scsi_dispatch_cmd_error,
242 __field( unsigned int, cmd_len ) 256 __field( unsigned int, cmd_len )
243 __field( unsigned int, data_sglen ) 257 __field( unsigned int, data_sglen )
244 __field( unsigned int, prot_sglen ) 258 __field( unsigned int, prot_sglen )
259 __field( unsigned char, prot_op )
245 __dynamic_array(unsigned char, cmnd, cmd->cmd_len) 260 __dynamic_array(unsigned char, cmnd, cmd->cmd_len)
246 ), 261 ),
247 262
@@ -255,13 +270,15 @@ TRACE_EVENT(scsi_dispatch_cmd_error,
255 __entry->cmd_len = cmd->cmd_len; 270 __entry->cmd_len = cmd->cmd_len;
256 __entry->data_sglen = scsi_sg_count(cmd); 271 __entry->data_sglen = scsi_sg_count(cmd);
257 __entry->prot_sglen = scsi_prot_sg_count(cmd); 272 __entry->prot_sglen = scsi_prot_sg_count(cmd);
273 __entry->prot_op = scsi_get_prot_op(cmd);
258 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len); 274 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len);
259 ), 275 ),
260 276
261 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u" \ 277 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u" \
262 " cmnd=(%s %s raw=%s) rtn=%d", 278 " prot_op=%s cmnd=(%s %s raw=%s) rtn=%d",
263 __entry->host_no, __entry->channel, __entry->id, 279 __entry->host_no, __entry->channel, __entry->id,
264 __entry->lun, __entry->data_sglen, __entry->prot_sglen, 280 __entry->lun, __entry->data_sglen, __entry->prot_sglen,
281 show_prot_op_name(__entry->prot_op),
265 show_opcode_name(__entry->opcode), 282 show_opcode_name(__entry->opcode),
266 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len), 283 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len),
267 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len), 284 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len),
@@ -284,6 +301,7 @@ DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template,
284 __field( unsigned int, cmd_len ) 301 __field( unsigned int, cmd_len )
285 __field( unsigned int, data_sglen ) 302 __field( unsigned int, data_sglen )
286 __field( unsigned int, prot_sglen ) 303 __field( unsigned int, prot_sglen )
304 __field( unsigned char, prot_op )
287 __dynamic_array(unsigned char, cmnd, cmd->cmd_len) 305 __dynamic_array(unsigned char, cmnd, cmd->cmd_len)
288 ), 306 ),
289 307
@@ -297,14 +315,16 @@ DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template,
297 __entry->cmd_len = cmd->cmd_len; 315 __entry->cmd_len = cmd->cmd_len;
298 __entry->data_sglen = scsi_sg_count(cmd); 316 __entry->data_sglen = scsi_sg_count(cmd);
299 __entry->prot_sglen = scsi_prot_sg_count(cmd); 317 __entry->prot_sglen = scsi_prot_sg_count(cmd);
318 __entry->prot_op = scsi_get_prot_op(cmd);
300 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len); 319 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len);
301 ), 320 ),
302 321
303 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u " \ 322 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u " \
304 "prot_sgl=%u cmnd=(%s %s raw=%s) result=(driver=%s host=%s " \ 323 "prot_sgl=%u prot_op=%s cmnd=(%s %s raw=%s) result=(driver=" \
305 "message=%s status=%s)", 324 "%s host=%s message=%s status=%s)",
306 __entry->host_no, __entry->channel, __entry->id, 325 __entry->host_no, __entry->channel, __entry->id,
307 __entry->lun, __entry->data_sglen, __entry->prot_sglen, 326 __entry->lun, __entry->data_sglen, __entry->prot_sglen,
327 show_prot_op_name(__entry->prot_op),
308 show_opcode_name(__entry->opcode), 328 show_opcode_name(__entry->opcode),
309 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len), 329 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len),
310 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len), 330 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len),