Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 17 Jun 2009 16:50:44 +0000 (09:50 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 17 Jun 2009 16:50:44 +0000 (09:50 -0700)
* git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6:
  [SCSI] aic79xx: make driver respect nvram for IU and QAS settings
  [SCSI] don't attach ULD to Dell Universal Xport
  [SCSI] lpfc 8.3.3 : Update driver version to 8.3.3
  [SCSI] lpfc 8.3.3 : Add support for Target Reset handler entrypoint
  [SCSI] lpfc 8.3.3 : Fix a couple of spin_lock and memory issues and a crash
  [SCSI] lpfc 8.3.3 : FC/FCOE discovery fixes
  [SCSI] lpfc 8.3.3 : Fix various SLI-3 vs SLI-4 differences
  [SCSI] qla2xxx: Resolve a performance issue in interrupt
  [SCSI] cnic, bnx2i: Fix build failure when CONFIG_PCI is not set.
  [SCSI] nsp_cs: time_out reaches -1
  [SCSI] qla2xxx: fix printk format warnings
  [SCSI] ncr53c8xx: div reaches -1
  [SCSI] compat: don't perform unneeded copy in sg_io code
  [SCSI] zfcp: Update FC pass-through support
  [SCSI] zfcp: Add FC pass-through support
  [SCSI] FC Pass Thru support

1  2 
drivers/net/Kconfig
drivers/s390/scsi/zfcp_fc.c
drivers/scsi/lpfc/lpfc_scsi.c
fs/compat_ioctl.c

diff --combined drivers/net/Kconfig
index 3b6383168c6916cf57c41015d8a10c22dee0d015,f6903140dd91402cf2502288801d4ed90ccd4806..892a9e4e275fe34eecd136adbef2ce4c46c36f57
@@@ -1,3 -1,4 +1,3 @@@
 -
  #
  # Network device configuration
  #
@@@ -25,6 -26,15 +25,6 @@@ menuconfig NETDEVICE
  # that for each of the symbols.
  if NETDEVICES
  
 -config COMPAT_NET_DEV_OPS
 -       default y
 -       bool "Enable older network device API compatibility"
 -       ---help---
 -          This option enables kernel compatibility with older network devices
 -          that do not use net_device_ops interface.
 -
 -        If unsure, say Y.
 -
  config IFB
        tristate "Intermediate Functional Block support"
        depends on NET_CLS_ACT
@@@ -516,16 -526,15 +516,16 @@@ config STNI
  config SH_ETH
        tristate "Renesas SuperH Ethernet support"
        depends on SUPERH && \
 -              (CPU_SUBTYPE_SH7710 || CPU_SUBTYPE_SH7712 || CPU_SUBTYPE_SH7763 || \
 -               CPU_SUBTYPE_SH7619)
 +              (CPU_SUBTYPE_SH7710 || CPU_SUBTYPE_SH7712 || \
 +               CPU_SUBTYPE_SH7763 || CPU_SUBTYPE_SH7619 || \
 +               CPU_SUBTYPE_SH7724)
        select CRC32
        select MII
        select MDIO_BITBANG
        select PHYLIB
        help
          Renesas SuperH Ethernet device driver.
 -        This driver support SH7710, SH7712, SH7763 and SH7619.
 +        This driver support SH7710, SH7712, SH7763, SH7619, and SH7724.
  
  config SUNLANCE
        tristate "Sun LANCE support"
@@@ -918,16 -927,6 +918,16 @@@ config NET_NET
          To compile this driver as a module, choose M here. The module
          will be called netx-eth.
  
 +config TI_DAVINCI_EMAC
 +      tristate "TI DaVinci EMAC Support"
 +      depends on ARM && ARCH_DAVINCI
 +      select PHYLIB
 +      help
 +        This driver supports TI's DaVinci Ethernet .
 +
 +        To compile this driver as a module, choose M here: the module
 +        will be called davinci_emac_driver.  This is recommended.
 +
  config DM9000
        tristate "DM9000 support"
        depends on ARM || BLACKFIN || MIPS
@@@ -1001,7 -1000,7 +1001,7 @@@ config SMC911
  
  config SMSC911X
        tristate "SMSC LAN911x/LAN921x families embedded ethernet support"
 -      depends on ARM || SUPERH
 +      depends on ARM || SUPERH || BLACKFIN
        select CRC32
        select MII
        select PHYLIB
@@@ -1723,11 -1722,6 +1723,11 @@@ config TLA
  
          Please email feedback to <torben.mathiasen@compaq.com>.
  
 +config KS8842
 +      tristate "Micrel KSZ8842"
 +      help
 +        This platform driver is for Micrel KSZ8842 chip.
 +
  config VIA_RHINE
        tristate "VIA Rhine support"
        depends on NET_PCI && PCI
@@@ -1864,8 -1858,8 +1864,8 @@@ config 68360_ENE
          the Motorola 68360 processor.
  
  config FEC
 -      bool "FEC ethernet controller (of ColdFire CPUs)"
 -      depends on M523x || M527x || M5272 || M528x || M520x || M532x || MACH_MX27
 +      bool "FEC ethernet controller (of ColdFire and some i.MX CPUs)"
 +      depends on M523x || M527x || M5272 || M528x || M520x || M532x || MACH_MX27 || ARCH_MX35
        help
          Say Y here if you want to use the built-in 10/100 Fast ethernet
          controller on some Motorola ColdFire and Freescale i.MX processors.
@@@ -1886,7 -1880,7 +1886,7 @@@ config FEC_MPC52x
        ---help---
          This option enables support for the MPC5200's on-chip
          Fast Ethernet Controller
 -        If compiled as module, it will be called 'fec_mpc52xx.ko'.
 +        If compiled as module, it will be called fec_mpc52xx.
  
  config FEC_MPC52xx_MDIO
        bool "MPC52xx FEC MDIO bus driver"
          (Motorola? industry standard).
          If your board uses an external PHY connected to FEC, enable this.
          If not sure, enable.
 -        If compiled as module, it will be called 'fec_mpc52xx_phy.ko'.
 +        If compiled as module, it will be called fec_mpc52xx_phy.
  
  config NE_H8300
        tristate "NE2000 compatible support for H8/300"
@@@ -2206,7 -2200,7 +2206,7 @@@ config SKGE_DEBU
         depends on SKGE && DEBUG_FS
         help
         This option adds the ability to dump driver state for debugging.
 -       The file debugfs/skge/ethX displays the state of the internal
 +       The file /sys/kernel/debug/skge/ethX displays the state of the internal
         transmit and receive rings.
  
         If unsure, say N.
@@@ -2232,7 -2226,7 +2232,7 @@@ config SKY2_DEBU
         depends on SKY2 && DEBUG_FS
         help
         This option adds the ability to dump driver state for debugging.
 -       The file debugfs/sky2/ethX displays the state of the internal
 +       The file /sys/kernel/debug/sky2/ethX displays the state of the internal
         transmit and receive rings.
  
         If unsure, say N.
@@@ -2272,8 -2266,9 +2272,9 @@@ config BNX
  
  config CNIC
        tristate "Broadcom CNIC support"
-       depends on BNX2
-       depends on UIO
+       depends on PCI
+       select BNX2
+       select UIO
        help
          This driver supports offload features of Broadcom NetXtremeII
          gigabit Ethernet cards.
@@@ -2368,7 -2363,7 +2369,7 @@@ config UGETH_TX_ON_DEMAN
  
  config MV643XX_ETH
        tristate "Marvell Discovery (643XX) and Orion ethernet support"
 -      depends on MV64360 || MV64X60 || (PPC_MULTIPLATFORM && PPC32) || PLAT_ORION
 +      depends on MV64X60 || PPC32 || PLAT_ORION
        select INET_LRO
        select PHYLIB
        help
          Some boards that use the Discovery chipset are the Momenco
          Ocelot C and Jaguar ATX and Pegasos II.
  
 +config XILINX_LL_TEMAC
 +      tristate "Xilinx LL TEMAC (LocalLink Tri-mode Ethernet MAC) driver"
 +      select PHYLIB
 +      depends on PPC_DCR_NATIVE
 +      help
 +        This driver supports the Xilinx 10/100/1000 LocalLink TEMAC
 +        core used in Xilinx Spartan and Virtex FPGAs
 +
  config QLA3XXX
        tristate "QLogic QLA3XXX Network Driver Support"
        depends on PCI
@@@ -2460,14 -2447,10 +2461,14 @@@ menuconfig NETDEV_1000
  
  if NETDEV_10000
  
 +config MDIO
 +      tristate
 +
  config CHELSIO_T1
          tristate "Chelsio 10Gb Ethernet support"
          depends on PCI
        select CRC32
 +      select MDIO
          help
            This driver supports Chelsio gigabit and 10-gigabit
            Ethernet cards. More information about adapter features and
@@@ -2500,7 -2483,6 +2501,7 @@@ config CHELSIO_T
        tristate "Chelsio Communications T3 10Gb Ethernet support"
        depends on CHELSIO_T3_DEPENDS
        select FW_LOADER
 +      select MDIO
        help
          This driver supports Chelsio T3-based gigabit and 10Gb Ethernet
          adapters.
@@@ -2536,7 -2518,6 +2537,7 @@@ config ENI
  config IXGBE
        tristate "Intel(R) 10GbE PCI Express adapters support"
        depends on PCI && INET
 +      select MDIO
        ---help---
          This driver supports Intel(R) 10GbE PCI Express family of
          adapters.  For more information on how to identify your adapter, go
@@@ -2699,7 -2680,6 +2700,7 @@@ config TEHUT
  config BNX2X
        tristate "Broadcom NetXtremeII 10Gb support"
        depends on PCI
 +      select FW_LOADER
        select ZLIB_INFLATE
        select LIBCRC32C
        help
@@@ -2736,8 -2716,6 +2737,8 @@@ source "drivers/net/wan/Kconfig
  
  source "drivers/atm/Kconfig"
  
 +source "drivers/ieee802154/Kconfig"
 +
  source "drivers/s390/net/Kconfig"
  
  config XEN_NETDEV_FRONTEND
index 35493a82d2a8accd43afb2fc2af0c43385d1df38,538c68dc7bb8f30df3798deb86c8afb7fb792f00..2f0705d76b7202095066be064232205b0373fb4e
@@@ -116,18 -116,17 +116,17 @@@ static void zfcp_wka_port_put(struct zf
  {
        if (atomic_dec_return(&wka_port->refcount) != 0)
                return;
 -      /* wait 10 miliseconds, other reqs might pop in */
 +      /* wait 10 milliseconds, other reqs might pop in */
        schedule_delayed_work(&wka_port->work, HZ / 100);
  }
  
- void zfcp_fc_nameserver_init(struct zfcp_adapter *adapter)
+ static void zfcp_fc_wka_port_init(struct zfcp_wka_port *wka_port, u32 d_id,
+                                 struct zfcp_adapter *adapter)
  {
-       struct zfcp_wka_port *wka_port = &adapter->nsp;
        init_waitqueue_head(&wka_port->completion_wq);
  
        wka_port->adapter = adapter;
-       wka_port->d_id = ZFCP_DID_DIRECTORY_SERVICE;
+       wka_port->d_id = d_id;
  
        wka_port->status = ZFCP_WKA_PORT_OFFLINE;
        atomic_set(&wka_port->refcount, 0);
@@@ -143,6 -142,17 +142,17 @@@ void zfcp_fc_wka_port_force_offline(str
        mutex_unlock(&wka->mutex);
  }
  
+ void zfcp_fc_wka_ports_init(struct zfcp_adapter *adapter)
+ {
+       struct zfcp_wka_ports *gs = adapter->gs;
+       zfcp_fc_wka_port_init(&gs->ms, FC_FID_MGMT_SERV, adapter);
+       zfcp_fc_wka_port_init(&gs->ts, FC_FID_TIME_SERV, adapter);
+       zfcp_fc_wka_port_init(&gs->ds, FC_FID_DIR_SERV, adapter);
+       zfcp_fc_wka_port_init(&gs->as, FC_FID_ALIASES, adapter);
+       zfcp_fc_wka_port_init(&gs->ks, FC_FID_SEC_KEY, adapter);
+ }
  static void _zfcp_fc_incoming_rscn(struct zfcp_fsf_req *fsf_req, u32 range,
                                   struct fcp_rscn_element *elem)
  {
@@@ -282,7 -292,7 +292,7 @@@ int static zfcp_fc_ns_gid_pn_request(st
  
        /* setup parameters for send generic command */
        gid_pn->port = erp_action->port;
-       gid_pn->ct.wka_port = &adapter->nsp;
+       gid_pn->ct.wka_port = &adapter->gs->ds;
        gid_pn->ct.handler = zfcp_fc_ns_handler;
        gid_pn->ct.handler_data = (unsigned long) &compl_rec;
        gid_pn->ct.timeout = ZFCP_NS_GID_PN_TIMEOUT;
@@@ -329,13 -339,13 +339,13 @@@ int zfcp_fc_ns_gid_pn(struct zfcp_erp_a
  
        memset(gid_pn, 0, sizeof(*gid_pn));
  
-       ret = zfcp_wka_port_get(&adapter->nsp);
+       ret = zfcp_wka_port_get(&adapter->gs->ds);
        if (ret)
                goto out;
  
        ret = zfcp_fc_ns_gid_pn_request(erp_action, gid_pn);
  
-       zfcp_wka_port_put(&adapter->nsp);
+       zfcp_wka_port_put(&adapter->gs->ds);
  out:
        mempool_free(gid_pn, adapter->pool.data_gid_pn);
        return ret;
@@@ -525,7 -535,7 +535,7 @@@ static int zfcp_scan_issue_gpn_ft(struc
        req->fc4_type = ZFCP_CT_SCSI_FCP;
  
        /* prepare zfcp_send_ct */
-       ct->wka_port = &adapter->nsp;
+       ct->wka_port = &adapter->gs->ds;
        ct->handler = zfcp_fc_ns_handler;
        ct->handler_data = (unsigned long)&compl_rec;
        ct->timeout = 10;
@@@ -644,7 -654,7 +654,7 @@@ int zfcp_scan_ports(struct zfcp_adapte
            fc_host_port_type(adapter->scsi_host) != FC_PORTTYPE_NPIV)
                return 0;
  
-       ret = zfcp_wka_port_get(&adapter->nsp);
+       ret = zfcp_wka_port_get(&adapter->gs->ds);
        if (ret)
                return ret;
  
        }
        zfcp_free_sg_env(gpn_ft, buf_num);
  out:
-       zfcp_wka_port_put(&adapter->nsp);
+       zfcp_wka_port_put(&adapter->gs->ds);
        return ret;
  }
  
@@@ -675,3 -685,158 +685,158 @@@ void _zfcp_scan_ports_later(struct work
  {
        zfcp_scan_ports(container_of(work, struct zfcp_adapter, scan_work));
  }
+ struct zfcp_els_fc_job {
+       struct zfcp_send_els els;
+       struct fc_bsg_job *job;
+ };
+ static void zfcp_fc_generic_els_handler(unsigned long data)
+ {
+       struct zfcp_els_fc_job *els_fc_job = (struct zfcp_els_fc_job *) data;
+       struct fc_bsg_job *job = els_fc_job->job;
+       struct fc_bsg_reply *reply = job->reply;
+       if (els_fc_job->els.status) {
+               /* request rejected or timed out */
+               reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_REJECT;
+               goto out;
+       }
+       reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
+       reply->reply_payload_rcv_len = job->reply_payload.payload_len;
+ out:
+       job->state_flags = FC_RQST_STATE_DONE;
+       job->job_done(job);
+       kfree(els_fc_job);
+ }
+ int zfcp_fc_execute_els_fc_job(struct fc_bsg_job *job)
+ {
+       struct zfcp_els_fc_job *els_fc_job;
+       struct fc_rport *rport = job->rport;
+       struct Scsi_Host *shost;
+       struct zfcp_adapter *adapter;
+       struct zfcp_port *port;
+       u8 *port_did;
+       shost = rport ? rport_to_shost(rport) : job->shost;
+       adapter = (struct zfcp_adapter *)shost->hostdata[0];
+       if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
+               return -EINVAL;
+       els_fc_job = kzalloc(sizeof(struct zfcp_els_fc_job), GFP_KERNEL);
+       if (!els_fc_job)
+               return -ENOMEM;
+       els_fc_job->els.adapter = adapter;
+       if (rport) {
+               read_lock_irq(&zfcp_data.config_lock);
+               port = rport->dd_data;
+               if (port)
+                       els_fc_job->els.d_id = port->d_id;
+               read_unlock_irq(&zfcp_data.config_lock);
+               if (!port) {
+                       kfree(els_fc_job);
+                       return -EINVAL;
+               }
+       } else {
+               port_did = job->request->rqst_data.h_els.port_id;
+               els_fc_job->els.d_id = (port_did[0] << 16) +
+                                       (port_did[1] << 8) + port_did[2];
+       }
+       els_fc_job->els.req = job->request_payload.sg_list;
+       els_fc_job->els.resp = job->reply_payload.sg_list;
+       els_fc_job->els.handler = zfcp_fc_generic_els_handler;
+       els_fc_job->els.handler_data = (unsigned long) els_fc_job;
+       els_fc_job->job = job;
+       return zfcp_fsf_send_els(&els_fc_job->els);
+ }
+ struct zfcp_ct_fc_job {
+       struct zfcp_send_ct ct;
+       struct fc_bsg_job *job;
+ };
+ static void zfcp_fc_generic_ct_handler(unsigned long data)
+ {
+       struct zfcp_ct_fc_job *ct_fc_job = (struct zfcp_ct_fc_job *) data;
+       struct fc_bsg_job *job = ct_fc_job->job;
+       job->reply->reply_data.ctels_reply.status = ct_fc_job->ct.status ?
+                               FC_CTELS_STATUS_REJECT : FC_CTELS_STATUS_OK;
+       job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
+       job->state_flags = FC_RQST_STATE_DONE;
+       job->job_done(job);
+       zfcp_wka_port_put(ct_fc_job->ct.wka_port);
+       kfree(ct_fc_job);
+ }
+ int zfcp_fc_execute_ct_fc_job(struct fc_bsg_job *job)
+ {
+       int ret;
+       u8 gs_type;
+       struct fc_rport *rport = job->rport;
+       struct Scsi_Host *shost;
+       struct zfcp_adapter *adapter;
+       struct zfcp_ct_fc_job *ct_fc_job;
+       u32 preamble_word1;
+       shost = rport ? rport_to_shost(rport) : job->shost;
+       adapter = (struct zfcp_adapter *)shost->hostdata[0];
+       if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
+               return -EINVAL;
+       ct_fc_job = kzalloc(sizeof(struct zfcp_ct_fc_job), GFP_KERNEL);
+       if (!ct_fc_job)
+               return -ENOMEM;
+       preamble_word1 = job->request->rqst_data.r_ct.preamble_word1;
+       gs_type = (preamble_word1 & 0xff000000) >> 24;
+       switch (gs_type) {
+       case FC_FST_ALIAS:
+               ct_fc_job->ct.wka_port = &adapter->gs->as;
+               break;
+       case FC_FST_MGMT:
+               ct_fc_job->ct.wka_port = &adapter->gs->ms;
+               break;
+       case FC_FST_TIME:
+               ct_fc_job->ct.wka_port = &adapter->gs->ts;
+               break;
+       case FC_FST_DIR:
+               ct_fc_job->ct.wka_port = &adapter->gs->ds;
+               break;
+       default:
+               kfree(ct_fc_job);
+               return -EINVAL; /* no such service */
+       }
+       ret = zfcp_wka_port_get(ct_fc_job->ct.wka_port);
+       if (ret) {
+               kfree(ct_fc_job);
+               return ret;
+       }
+       ct_fc_job->ct.req = job->request_payload.sg_list;
+       ct_fc_job->ct.resp = job->reply_payload.sg_list;
+       ct_fc_job->ct.timeout = ZFCP_FSF_REQUEST_TIMEOUT;
+       ct_fc_job->ct.handler = zfcp_fc_generic_ct_handler;
+       ct_fc_job->ct.handler_data = (unsigned long) ct_fc_job;
+       ct_fc_job->ct.completion = NULL;
+       ct_fc_job->job = job;
+       ret = zfcp_fsf_send_ct(&ct_fc_job->ct, NULL, NULL);
+       if (ret) {
+               kfree(ct_fc_job);
+               zfcp_wka_port_put(ct_fc_job->ct.wka_port);
+       }
+       return ret;
+ }
index 7991ba1980ae5d6475c4ab9c34578e9e534d2cf3,caaa209feca3df0f24eb180cd011e497040a9ba4..da59c4f0168f85bba62e203891ac11667a888e90
@@@ -115,6 -115,27 +115,27 @@@ lpfc_debug_save_dif(struct scsi_cmnd *c
        }
  }
  
+ /**
+  * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
+  * @phba: Pointer to HBA object.
+  * @lpfc_cmd: lpfc scsi command object pointer.
+  *
+  * This function is called from the lpfc_prep_task_mgmt_cmd function to
+  * set the last bit in the response sge entry.
+  **/
+ static void
+ lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
+                               struct lpfc_scsi_buf *lpfc_cmd)
+ {
+       struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
+       if (sgl) {
+               sgl += 1;
+               sgl->word2 = le32_to_cpu(sgl->word2);
+               bf_set(lpfc_sli4_sge_last, sgl, 1);
+               sgl->word2 = cpu_to_le32(sgl->word2);
+       }
+ }
  /**
   * lpfc_update_stats - Update statistical data for the command completion
   * @phba: Pointer to HBA object.
@@@ -1174,8 -1195,8 +1195,8 @@@ lpfc_cmd_blksize(struct scsi_cmnd *sc
   * @reftag:         out: ref tag (reference tag)
   *
   * Description:
 - *   Extract DIF paramters from the command if possible.  Otherwise,
 - *   use default paratmers.
 + *   Extract DIF parameters from the command if possible.  Otherwise,
 + *   use default parameters.
   *
   **/
  static inline void
@@@ -1978,7 -1999,7 +1999,7 @@@ lpfc_send_scsi_error_event(struct lpfc_
  }
  
  /**
-  * lpfc_scsi_unprep_dma_buf_s3 - Un-map DMA mapping of SG-list for SLI3 dev
+  * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
   * @phba: The HBA for which this call is being executed.
   * @psb: The scsi buffer which is going to be un-mapped.
   *
   * field of @lpfc_cmd for device with SLI-3 interface spec.
   **/
  static void
- lpfc_scsi_unprep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
+ lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  {
        /*
         * There are only two special cases to consider.  (1) the scsi command
                                psb->pCmd->sc_data_direction);
  }
  
- /**
-  * lpfc_scsi_unprep_dma_buf_s4 - Un-map DMA mapping of SG-list for SLI4 dev
-  * @phba: The Hba for which this call is being executed.
-  * @psb: The scsi buffer which is going to be un-mapped.
-  *
-  * This routine does DMA un-mapping of scatter gather list of scsi command
-  * field of @lpfc_cmd for device with SLI-4 interface spec. If we have to
-  * remove the sgl for this scsi buffer then we will do it here. For now
-  * we should be able to just call the sli3 unprep routine.
-  **/
- static void
- lpfc_scsi_unprep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
- {
-       lpfc_scsi_unprep_dma_buf_s3(phba, psb);
- }
- /**
-  * lpfc_scsi_unprep_dma_buf - Wrapper function for unmap DMA mapping of SG-list
-  * @phba: The Hba for which this call is being executed.
-  * @psb: The scsi buffer which is going to be un-mapped.
-  *
-  * This routine does DMA un-mapping of scatter gather list of scsi command
-  * field of @lpfc_cmd for device with SLI-4 interface spec.
-  **/
- static void
- lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
- {
-       phba->lpfc_scsi_unprep_dma_buf(phba, psb);
- }
  /**
   * lpfc_handler_fcp_err - FCP response handler
   * @vport: The virtual port for which this call is being executed.
@@@ -2461,7 -2452,7 +2452,7 @@@ lpfc_fcpcmd_to_iocb(uint8_t *data, stru
  }
  
  /**
-  * lpfc_scsi_prep_cmnd_s3 - Convert scsi cmnd to FCP infor unit for SLI3 dev
+  * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
   * @vport: The virtual port for which this call is being executed.
   * @lpfc_cmd: The scsi command which needs to send.
   * @pnode: Pointer to lpfc_nodelist.
   * to transfer for device with SLI3 interface spec.
   **/
  static void
- lpfc_scsi_prep_cmnd_s3(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
+ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
                    struct lpfc_nodelist *pnode)
  {
        struct lpfc_hba *phba = vport->phba;
  }
  
  /**
-  * lpfc_scsi_prep_cmnd_s4 - Convert scsi cmnd to FCP infor unit for SLI4 dev
-  * @vport: The virtual port for which this call is being executed.
-  * @lpfc_cmd: The scsi command which needs to send.
-  * @pnode: Pointer to lpfc_nodelist.
-  *
-  * This routine initializes fcp_cmnd and iocb data structure from scsi command
-  * to transfer for device with SLI4 interface spec.
-  **/
- static void
- lpfc_scsi_prep_cmnd_s4(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
-                      struct lpfc_nodelist *pnode)
- {
-       /*
-        * The prep cmnd routines do not touch the sgl or its
-        * entries. We may not have to do anything different.
-        * I will leave this function in place until we can
-        * run some IO through the driver and determine if changes
-        * are needed.
-        */
-       return lpfc_scsi_prep_cmnd_s3(vport, lpfc_cmd, pnode);
- }
- /**
-  * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
-  * @vport: The virtual port for which this call is being executed.
-  * @lpfc_cmd: The scsi command which needs to send.
-  * @pnode: Pointer to lpfc_nodelist.
-  *
-  * This routine wraps the actual convert SCSI cmnd function pointer from
-  * the lpfc_hba struct.
-  **/
- static inline void
- lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
-                   struct lpfc_nodelist *pnode)
- {
-       vport->phba->lpfc_scsi_prep_cmnd(vport, lpfc_cmd, pnode);
- }
- /**
-  * lpfc_scsi_prep_task_mgmt_cmnd_s3 - Convert SLI3 scsi TM cmd to FCP info unit
+  * lpfc_scsi_prep_task_mgmt_cmnd - Convert SLI3 scsi TM cmd to FCP info unit
   * @vport: The virtual port for which this call is being executed.
   * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
   * @lun: Logical unit number.
   *   1 - Success
   **/
  static int
- lpfc_scsi_prep_task_mgmt_cmd_s3(struct lpfc_vport *vport,
+ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
                             struct lpfc_scsi_buf *lpfc_cmd,
                             unsigned int lun,
                             uint8_t task_mgmt_cmd)
                 * The driver will provide the timeout mechanism.
                 */
                piocb->ulpTimeout = 0;
-       } else {
+       } else
                piocb->ulpTimeout = lpfc_cmd->timeout;
-       }
-       return 1;
- }
- /**
-  * lpfc_scsi_prep_task_mgmt_cmnd_s4 - Convert SLI4 scsi TM cmd to FCP info unit
-  * @vport: The virtual port for which this call is being executed.
-  * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
-  * @lun: Logical unit number.
-  * @task_mgmt_cmd: SCSI task management command.
-  *
-  * This routine creates FCP information unit corresponding to @task_mgmt_cmd
-  * for device with SLI-4 interface spec.
-  *
-  * Return codes:
-  *    0 - Error
-  *    1 - Success
-  **/
- static int
- lpfc_scsi_prep_task_mgmt_cmd_s4(struct lpfc_vport *vport,
-                               struct lpfc_scsi_buf *lpfc_cmd,
-                               unsigned int lun,
-                               uint8_t task_mgmt_cmd)
- {
-       /*
-        * The prep cmnd routines do not touch the sgl or its
-        * entries. We may not have to do anything different.
-        * I will leave this function in place until we can
-        * run some IO through the driver and determine if changes
-        * are needed.
-        */
-       return lpfc_scsi_prep_task_mgmt_cmd_s3(vport, lpfc_cmd, lun,
-                                               task_mgmt_cmd);
- }
  
- /**
-  * lpfc_scsi_prep_task_mgmt_cmnd - Wrapper func convert scsi TM cmd to FCP info
-  * @vport: The virtual port for which this call is being executed.
-  * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
-  * @lun: Logical unit number.
-  * @task_mgmt_cmd: SCSI task management command.
-  *
-  * This routine wraps the actual convert SCSI TM to FCP information unit
-  * function pointer from the lpfc_hba struct.
-  *
-  * Return codes:
-  *    0 - Error
-  *    1 - Success
-  **/
- static inline int
- lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
-                            struct lpfc_scsi_buf *lpfc_cmd,
-                            unsigned int lun,
-                            uint8_t task_mgmt_cmd)
- {
-       struct lpfc_hba *phba = vport->phba;
+       if (vport->phba->sli_rev == LPFC_SLI_REV4)
+               lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
  
-       return phba->lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
-                                                 task_mgmt_cmd);
+       return 1;
  }
  
  /**
  lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  {
  
+       phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
+       phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
+       phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf;
        switch (dev_grp) {
        case LPFC_PCI_DEV_LP:
                phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
                phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
-               phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd_s3;
-               phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf_s3;
-               phba->lpfc_scsi_prep_task_mgmt_cmd =
-                                       lpfc_scsi_prep_task_mgmt_cmd_s3;
                phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
                break;
        case LPFC_PCI_DEV_OC:
                phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
                phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
-               phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd_s4;
-               phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf_s4;
-               phba->lpfc_scsi_prep_task_mgmt_cmd =
-                                       lpfc_scsi_prep_task_mgmt_cmd_s4;
                phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
                break;
        default:
@@@ -2782,72 -2675,6 +2675,6 @@@ lpfc_tskmgmt_def_cmpl(struct lpfc_hba *
        return;
  }
  
- /**
-  * lpfc_scsi_tgt_reset - Target reset handler
-  * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure
-  * @vport: The virtual port for which this call is being executed.
-  * @tgt_id: Target ID.
-  * @lun: Lun number.
-  * @rdata: Pointer to lpfc_rport_data.
-  *
-  * This routine issues a TARGET RESET iocb to reset a target with @tgt_id ID.
-  *
-  * Return Code:
-  *   0x2003 - Error
-  *   0x2002 - Success.
-  **/
- static int
- lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
-                   unsigned  tgt_id, unsigned int lun,
-                   struct lpfc_rport_data *rdata)
- {
-       struct lpfc_hba   *phba = vport->phba;
-       struct lpfc_iocbq *iocbq;
-       struct lpfc_iocbq *iocbqrsp;
-       int ret;
-       int status;
-       if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
-               return FAILED;
-       lpfc_cmd->rdata = rdata;
-       status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
-                                          FCP_TARGET_RESET);
-       if (!status)
-               return FAILED;
-       iocbq = &lpfc_cmd->cur_iocbq;
-       iocbqrsp = lpfc_sli_get_iocbq(phba);
-       if (!iocbqrsp)
-               return FAILED;
-       /* Issue Target Reset to TGT <num> */
-       lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
-                        "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
-                        tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
-       status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
-                                         iocbq, iocbqrsp, lpfc_cmd->timeout);
-       if (status != IOCB_SUCCESS) {
-               if (status == IOCB_TIMEDOUT) {
-                       iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
-                       ret = TIMEOUT_ERROR;
-               } else
-                       ret = FAILED;
-               lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
-       } else {
-               ret = SUCCESS;
-               lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
-               lpfc_cmd->status = iocbqrsp->iocb.ulpStatus;
-               if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
-                       (lpfc_cmd->result & IOERR_DRVR_MASK))
-                               lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
-       }
-       lpfc_sli_release_iocbq(phba, iocbqrsp);
-       return ret;
- }
  /**
   * lpfc_info - Info entry point of scsi_host_template data structure
   * @host: The scsi host for which this call is being executed.
@@@ -3228,156 -3055,334 +3055,334 @@@ lpfc_abort_handler(struct scsi_cmnd *cm
        return ret;
  }
  
+ static char *
+ lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
+ {
+       switch (task_mgmt_cmd) {
+       case FCP_ABORT_TASK_SET:
+               return "ABORT_TASK_SET";
+       case FCP_CLEAR_TASK_SET:
+               return "FCP_CLEAR_TASK_SET";
+       case FCP_BUS_RESET:
+               return "FCP_BUS_RESET";
+       case FCP_LUN_RESET:
+               return "FCP_LUN_RESET";
+       case FCP_TARGET_RESET:
+               return "FCP_TARGET_RESET";
+       case FCP_CLEAR_ACA:
+               return "FCP_CLEAR_ACA";
+       case FCP_TERMINATE_TASK:
+               return "FCP_TERMINATE_TASK";
+       default:
+               return "unknown";
+       }
+ }
  /**
-  * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
-  * @cmnd: Pointer to scsi_cmnd data structure.
+  * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
+  * @vport: The virtual port for which this call is being executed.
+  * @rdata: Pointer to remote port local data
+  * @tgt_id: Target ID of remote device.
+  * @lun_id: Lun number for the TMF
+  * @task_mgmt_cmd: type of TMF to send
   *
-  * This routine does a device reset by sending a TARGET_RESET task management
-  * command.
+  * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
+  * a remote port.
   *
-  * Return code :
-  *  0x2003 - Error
-  *  0x2002 - Success
+  * Return Code:
+  *   0x2003 - Error
+  *   0x2002 - Success.
   **/
  static int
- lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
+ lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
+                   unsigned  tgt_id, unsigned int lun_id,
+                   uint8_t task_mgmt_cmd)
  {
-       struct Scsi_Host  *shost = cmnd->device->host;
-       struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
        struct lpfc_hba   *phba = vport->phba;
        struct lpfc_scsi_buf *lpfc_cmd;
-       struct lpfc_iocbq *iocbq, *iocbqrsp;
-       struct lpfc_rport_data *rdata = cmnd->device->hostdata;
-       struct lpfc_nodelist *pnode = rdata->pnode;
-       unsigned long later;
-       int ret = SUCCESS;
+       struct lpfc_iocbq *iocbq;
+       struct lpfc_iocbq *iocbqrsp;
+       int ret;
        int status;
-       int cnt;
-       struct lpfc_scsi_event_header scsi_event;
  
-       lpfc_block_error_handler(cmnd);
-       /*
-        * If target is not in a MAPPED state, delay the reset until
-        * target is rediscovered or devloss timeout expires.
-        */
-       later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
-       while (time_after(later, jiffies)) {
-               if (!pnode || !NLP_CHK_NODE_ACT(pnode))
-                       return FAILED;
-               if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
-                       break;
-               schedule_timeout_uninterruptible(msecs_to_jiffies(500));
-               rdata = cmnd->device->hostdata;
-               if (!rdata)
-                       break;
-               pnode = rdata->pnode;
-       }
-       scsi_event.event_type = FC_REG_SCSI_EVENT;
-       scsi_event.subcategory = LPFC_EVENT_TGTRESET;
-       scsi_event.lun = 0;
-       memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
-       memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
-       fc_host_post_vendor_event(shost,
-               fc_get_event_number(),
-               sizeof(scsi_event),
-               (char *)&scsi_event,
-               LPFC_NL_VENDOR_ID);
-       if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) {
-               lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
-                                "0721 LUN Reset rport "
-                                "failure: msec x%x rdata x%p\n",
-                                jiffies_to_msecs(jiffies - later), rdata);
+       if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
                return FAILED;
-       }
        lpfc_cmd = lpfc_get_scsi_buf(phba);
        if (lpfc_cmd == NULL)
                return FAILED;
        lpfc_cmd->timeout = 60;
        lpfc_cmd->rdata = rdata;
  
-       status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd,
-                                             cmnd->device->lun,
-                                             FCP_TARGET_RESET);
+       status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
+                                          task_mgmt_cmd);
        if (!status) {
                lpfc_release_scsi_buf(phba, lpfc_cmd);
                return FAILED;
        }
-       iocbq = &lpfc_cmd->cur_iocbq;
  
-       /* get a buffer for this IOCB command response */
+       iocbq = &lpfc_cmd->cur_iocbq;
        iocbqrsp = lpfc_sli_get_iocbq(phba);
        if (iocbqrsp == NULL) {
                lpfc_release_scsi_buf(phba, lpfc_cmd);
                return FAILED;
        }
        lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
-                        "0703 Issue target reset to TGT %d LUN %d "
-                        "rpi x%x nlp_flag x%x\n", cmnd->device->id,
-                        cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
+                        "0702 Issue %s to TGT %d LUN %d "
+                        "rpi x%x nlp_flag x%x\n",
+                        lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
+                        rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
        status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
                                          iocbq, iocbqrsp, lpfc_cmd->timeout);
-       if (status == IOCB_TIMEDOUT) {
-               iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
-               ret = TIMEOUT_ERROR;
-       } else {
-               if (status != IOCB_SUCCESS)
+       if (status != IOCB_SUCCESS) {
+               if (status == IOCB_TIMEDOUT) {
+                       iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
+                       ret = TIMEOUT_ERROR;
+               } else
                        ret = FAILED;
-               lpfc_release_scsi_buf(phba, lpfc_cmd);
-       }
-       lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
-                        "0713 SCSI layer issued device reset (%d, %d) "
-                        "return x%x status x%x result x%x\n",
-                        cmnd->device->id, cmnd->device->lun, ret,
-                        iocbqrsp->iocb.ulpStatus,
+               lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
+               lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
+                        "0727 TMF %s to TGT %d LUN %d failed (%d, %d)\n",
+                        lpfc_taskmgmt_name(task_mgmt_cmd),
+                        tgt_id, lun_id, iocbqrsp->iocb.ulpStatus,
                         iocbqrsp->iocb.un.ulpWord[4]);
+       } else
+               ret = SUCCESS;
        lpfc_sli_release_iocbq(phba, iocbqrsp);
-       cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun,
-                               LPFC_CTX_TGT);
+       if (ret != TIMEOUT_ERROR)
+               lpfc_release_scsi_buf(phba, lpfc_cmd);
+       return ret;
+ }
+ /**
+  * lpfc_chk_tgt_mapped -
+  * @vport: The virtual port to check on
+  * @cmnd: Pointer to scsi_cmnd data structure.
+  *
+  * This routine delays until the scsi target (aka rport) for the
+  * command exists (is present and logged in) or we declare it non-existent.
+  *
+  * Return code :
+  *  0x2003 - Error
+  *  0x2002 - Success
+  **/
+ static int
+ lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
+ {
+       struct lpfc_rport_data *rdata = cmnd->device->hostdata;
+       struct lpfc_nodelist *pnode = rdata->pnode;
+       unsigned long later;
+       /*
+        * If target is not in a MAPPED state, delay until
+        * target is rediscovered or devloss timeout expires.
+        */
+       later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
+       while (time_after(later, jiffies)) {
+               if (!pnode || !NLP_CHK_NODE_ACT(pnode))
+                       return FAILED;
+               if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
+                       return SUCCESS;
+               schedule_timeout_uninterruptible(msecs_to_jiffies(500));
+               rdata = cmnd->device->hostdata;
+               if (!rdata)
+                       return FAILED;
+               pnode = rdata->pnode;
+       }
+       if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
+           (pnode->nlp_state != NLP_STE_MAPPED_NODE))
+               return FAILED;
+       return SUCCESS;
+ }
+ /**
+  * lpfc_reset_flush_io_context -
+  * @vport: The virtual port (scsi_host) for the flush context
+  * @tgt_id: If aborting by Target contect - specifies the target id
+  * @lun_id: If aborting by Lun context - specifies the lun id
+  * @context: specifies the context level to flush at.
+  *
+  * After a reset condition via TMF, we need to flush orphaned i/o
+  * contexts from the adapter. This routine aborts any contexts
+  * outstanding, then waits for their completions. The wait is
+  * bounded by devloss_tmo though.
+  *
+  * Return code :
+  *  0x2003 - Error
+  *  0x2002 - Success
+  **/
+ static int
+ lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
+                       uint64_t lun_id, lpfc_ctx_cmd context)
+ {
+       struct lpfc_hba   *phba = vport->phba;
+       unsigned long later;
+       int cnt;
+       cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
        if (cnt)
                lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
-                                   cmnd->device->id, cmnd->device->lun,
-                                   LPFC_CTX_TGT);
+                                   tgt_id, lun_id, context);
        later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
        while (time_after(later, jiffies) && cnt) {
                schedule_timeout_uninterruptible(msecs_to_jiffies(20));
-               cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id,
-                                       cmnd->device->lun, LPFC_CTX_TGT);
+               cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
        }
        if (cnt) {
                lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
-                                "0719 device reset I/O flush failure: "
-                                "cnt x%x\n", cnt);
-               ret = FAILED;
+                       "0724 I/O flush failure for context %s : cnt x%x\n",
+                       ((context == LPFC_CTX_LUN) ? "LUN" :
+                        ((context == LPFC_CTX_TGT) ? "TGT" :
+                         ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
+                       cnt);
+               return FAILED;
        }
-       return ret;
+       return SUCCESS;
+ }
+ /**
+  * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
+  * @cmnd: Pointer to scsi_cmnd data structure.
+  *
+  * This routine does a device reset by sending a LUN_RESET task management
+  * command.
+  *
+  * Return code :
+  *  0x2003 - Error
+  *  0x2002 - Success
+  **/
+ static int
+ lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
+ {
+       struct Scsi_Host  *shost = cmnd->device->host;
+       struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
+       struct lpfc_rport_data *rdata = cmnd->device->hostdata;
+       struct lpfc_nodelist *pnode = rdata->pnode;
+       unsigned tgt_id = cmnd->device->id;
+       unsigned int lun_id = cmnd->device->lun;
+       struct lpfc_scsi_event_header scsi_event;
+       int status;
+       lpfc_block_error_handler(cmnd);
+       status = lpfc_chk_tgt_mapped(vport, cmnd);
+       if (status == FAILED) {
+               lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
+                       "0721 Device Reset rport failure: rdata x%p\n", rdata);
+               return FAILED;
+       }
+       scsi_event.event_type = FC_REG_SCSI_EVENT;
+       scsi_event.subcategory = LPFC_EVENT_LUNRESET;
+       scsi_event.lun = lun_id;
+       memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
+       memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
+       fc_host_post_vendor_event(shost, fc_get_event_number(),
+               sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
+       status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
+                                               FCP_LUN_RESET);
+       lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
+                        "0713 SCSI layer issued Device Reset (%d, %d) "
+                        "return x%x\n", tgt_id, lun_id, status);
+       /*
+        * We have to clean up i/o as : they may be orphaned by the TMF;
+        * or if the TMF failed, they may be in an indeterminate state.
+        * So, continue on.
+        * We will report success if all the i/o aborts successfully.
+        */
+       status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
+                                               LPFC_CTX_LUN);
+       return status;
+ }
+ /**
+  * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
+  * @cmnd: Pointer to scsi_cmnd data structure.
+  *
+  * This routine does a target reset by sending a TARGET_RESET task management
+  * command.
+  *
+  * Return code :
+  *  0x2003 - Error
+  *  0x2002 - Success
+  **/
+ static int
+ lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
+ {
+       struct Scsi_Host  *shost = cmnd->device->host;
+       struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
+       struct lpfc_rport_data *rdata = cmnd->device->hostdata;
+       struct lpfc_nodelist *pnode = rdata->pnode;
+       unsigned tgt_id = cmnd->device->id;
+       unsigned int lun_id = cmnd->device->lun;
+       struct lpfc_scsi_event_header scsi_event;
+       int status;
+       lpfc_block_error_handler(cmnd);
+       status = lpfc_chk_tgt_mapped(vport, cmnd);
+       if (status == FAILED) {
+               lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
+                       "0722 Target Reset rport failure: rdata x%p\n", rdata);
+               return FAILED;
+       }
+       scsi_event.event_type = FC_REG_SCSI_EVENT;
+       scsi_event.subcategory = LPFC_EVENT_TGTRESET;
+       scsi_event.lun = 0;
+       memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
+       memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
+       fc_host_post_vendor_event(shost, fc_get_event_number(),
+               sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
+       status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
+                                       FCP_TARGET_RESET);
+       lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
+                        "0723 SCSI layer issued Target Reset (%d, %d) "
+                        "return x%x\n", tgt_id, lun_id, status);
+       /*
+        * We have to clean up i/o as : they may be orphaned by the TMF;
+        * or if the TMF failed, they may be in an indeterminate state.
+        * So, continue on.
+        * We will report success if all the i/o aborts successfully.
+        */
+       status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
+                                       LPFC_CTX_TGT);
+       return status;
  }
  
  /**
   * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
   * @cmnd: Pointer to scsi_cmnd data structure.
   *
-  * This routine does target reset to all target on @cmnd->device->host.
+  * This routine does target reset to all targets on @cmnd->device->host.
+  * This emulates Parallel SCSI Bus Reset Semantics.
   *
-  * Return Code:
-  *   0x2003 - Error
-  *   0x2002 - Success
+  * Return code :
+  *  0x2003 - Error
+  *  0x2002 - Success
   **/
  static int
  lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
  {
        struct Scsi_Host  *shost = cmnd->device->host;
        struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
-       struct lpfc_hba   *phba = vport->phba;
        struct lpfc_nodelist *ndlp = NULL;
-       int match;
-       int ret = SUCCESS, status = SUCCESS, i;
-       int cnt;
-       struct lpfc_scsi_buf * lpfc_cmd;
-       unsigned long later;
        struct lpfc_scsi_event_header scsi_event;
+       int match;
+       int ret = SUCCESS, status, i;
  
        scsi_event.event_type = FC_REG_SCSI_EVENT;
        scsi_event.subcategory = LPFC_EVENT_BUSRESET;
        memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
        memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
  
-       fc_host_post_vendor_event(shost,
-               fc_get_event_number(),
-               sizeof(scsi_event),
-               (char *)&scsi_event,
-               LPFC_NL_VENDOR_ID);
+       fc_host_post_vendor_event(shost, fc_get_event_number(),
+               sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
  
        lpfc_block_error_handler(cmnd);
        /*
         * Since the driver manages a single bus device, reset all
         * targets known to the driver.  Should any target reset
                spin_unlock_irq(shost->host_lock);
                if (!match)
                        continue;
-               lpfc_cmd = lpfc_get_scsi_buf(phba);
-               if (lpfc_cmd) {
-                       lpfc_cmd->timeout = 60;
-                       status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
-                                                    cmnd->device->lun,
-                                                    ndlp->rport->dd_data);
-                       if (status != TIMEOUT_ERROR)
-                               lpfc_release_scsi_buf(phba, lpfc_cmd);
-               }
-               if (!lpfc_cmd || status != SUCCESS) {
+               status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
+                                       i, 0, FCP_TARGET_RESET);
+               if (status != SUCCESS) {
                        lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
                                         "0700 Bus Reset on target %d failed\n",
                                         i);
                }
        }
        /*
-        * All outstanding txcmplq I/Os should have been aborted by
-        * the targets.  Unfortunately, some targets do not abide by
-        * this forcing the driver to double check.
+        * We have to clean up i/o as : they may be orphaned by the TMFs
+        * above; or if any of the TMFs failed, they may be in an
+        * indeterminate state.
+        * We will report success if all the i/o aborts successfully.
         */
-       cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
-       if (cnt)
-               lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
-                                   0, 0, LPFC_CTX_HOST);
-       later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
-       while (time_after(later, jiffies) && cnt) {
-               schedule_timeout_uninterruptible(msecs_to_jiffies(20));
-               cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
-       }
-       if (cnt) {
-               lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
-                                "0715 Bus Reset I/O flush failure: "
-                                "cnt x%x left x%x\n", cnt, i);
+       status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
+       if (status != SUCCESS)
                ret = FAILED;
-       }
        lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
                         "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
        return ret;
@@@ -3582,7 -3571,8 +3571,8 @@@ struct scsi_host_template lpfc_templat
        .info                   = lpfc_info,
        .queuecommand           = lpfc_queuecommand,
        .eh_abort_handler       = lpfc_abort_handler,
-       .eh_device_reset_handler= lpfc_device_reset_handler,
+       .eh_device_reset_handler = lpfc_device_reset_handler,
+       .eh_target_reset_handler = lpfc_target_reset_handler,
        .eh_bus_reset_handler   = lpfc_bus_reset_handler,
        .slave_alloc            = lpfc_slave_alloc,
        .slave_configure        = lpfc_slave_configure,
@@@ -3602,7 -3592,8 +3592,8 @@@ struct scsi_host_template lpfc_vport_te
        .info                   = lpfc_info,
        .queuecommand           = lpfc_queuecommand,
        .eh_abort_handler       = lpfc_abort_handler,
-       .eh_device_reset_handler= lpfc_device_reset_handler,
+       .eh_device_reset_handler = lpfc_device_reset_handler,
+       .eh_target_reset_handler = lpfc_target_reset_handler,
        .eh_bus_reset_handler   = lpfc_bus_reset_handler,
        .slave_alloc            = lpfc_slave_alloc,
        .slave_configure        = lpfc_slave_configure,
diff --combined fs/compat_ioctl.c
index 0aac371bff0b4c2e20e6748fdde3d6edf0c5afea,905523cc281f52cbe84d9f75f546082cdeece237..c5ded5ff72b58b5c45e5e7cb1b5cd4d639dc4567
@@@ -788,12 -788,6 +788,6 @@@ static int sg_ioctl_trans(unsigned int 
        if (put_user(compat_ptr(data), &sgio->usr_ptr))
                return -EFAULT;
  
-       if (copy_in_user(&sgio->status, &sgio32->status,
-                        (4 * sizeof(unsigned char)) +
-                        (2 * sizeof(unsigned short)) +
-                        (3 * sizeof(int))))
-               return -EFAULT;
        err = sys_ioctl(fd, cmd, (unsigned long) sgio);
  
        if (err >= 0) {
@@@ -1765,7 -1759,7 +1759,7 @@@ static int do_i2c_smbus_ioctl(unsigned 
  
  /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
   * for some operations; this forces use of the newer bridge-utils that
 - * use compatiable ioctls
 + * use compatible ioctls
   */
  static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  {